1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_OUTPUT_FILTER_OPERATION_H_
6 #define CC_OUTPUT_FILTER_OPERATION_H_
8 #include "base/logging.h"
9 #include "cc/base/cc_export.h"
10 #include "third_party/skia/include/core/SkColor.h"
11 #include "third_party/skia/include/core/SkScalar.h"
12 #include "ui/gfx/point.h"
16 class CC_EXPORT FilterOperation
{
31 SATURATING_BRIGHTNESS
, // Not used in CSS/SVG.
34 FilterType
type() const { return type_
; }
36 float amount() const {
37 DCHECK_NE(type_
, COLOR_MATRIX
);
41 gfx::Point
drop_shadow_offset() const {
42 DCHECK_EQ(type_
, DROP_SHADOW
);
43 return drop_shadow_offset_
;
46 SkColor
drop_shadow_color() const {
47 DCHECK_EQ(type_
, DROP_SHADOW
);
48 return drop_shadow_color_
;
51 const SkScalar
* matrix() const {
52 DCHECK_EQ(type_
, COLOR_MATRIX
);
56 int zoom_inset() const {
57 DCHECK_EQ(type_
, ZOOM
);
61 static FilterOperation
CreateGrayscaleFilter(float amount
) {
62 return FilterOperation(GRAYSCALE
, amount
);
65 static FilterOperation
CreateSepiaFilter(float amount
) {
66 return FilterOperation(SEPIA
, amount
);
69 static FilterOperation
CreateSaturateFilter(float amount
) {
70 return FilterOperation(SATURATE
, amount
);
73 static FilterOperation
CreateHueRotateFilter(float amount
) {
74 return FilterOperation(HUE_ROTATE
, amount
);
77 static FilterOperation
CreateInvertFilter(float amount
) {
78 return FilterOperation(INVERT
, amount
);
81 static FilterOperation
CreateBrightnessFilter(float amount
) {
82 return FilterOperation(BRIGHTNESS
, amount
);
85 static FilterOperation
CreateContrastFilter(float amount
) {
86 return FilterOperation(CONTRAST
, amount
);
89 static FilterOperation
CreateOpacityFilter(float amount
) {
90 return FilterOperation(OPACITY
, amount
);
93 static FilterOperation
CreateBlurFilter(float amount
) {
94 return FilterOperation(BLUR
, amount
);
97 static FilterOperation
CreateDropShadowFilter(gfx::Point offset
,
100 return FilterOperation(DROP_SHADOW
, offset
, std_deviation
, color
);
103 static FilterOperation
CreateColorMatrixFilter(SkScalar matrix
[20]) {
104 return FilterOperation(COLOR_MATRIX
, matrix
);
107 static FilterOperation
CreateZoomFilter(float amount
, int inset
) {
108 return FilterOperation(ZOOM
, amount
, inset
);
111 static FilterOperation
CreateSaturatingBrightnessFilter(float amount
) {
112 return FilterOperation(SATURATING_BRIGHTNESS
, amount
);
115 bool operator==(const FilterOperation
& other
) const;
117 bool operator!=(const FilterOperation
& other
) const {
118 return !(*this == other
);
121 // Methods for restoring a FilterOperation.
122 static FilterOperation
CreateEmptyFilter() {
123 return FilterOperation(GRAYSCALE
, 0.f
);
126 void set_type(FilterType type
) { type_
= type
; }
128 void set_amount(float amount
) {
129 DCHECK_NE(type_
, COLOR_MATRIX
);
133 void set_drop_shadow_offset(gfx::Point offset
) {
134 DCHECK_EQ(type_
, DROP_SHADOW
);
135 drop_shadow_offset_
= offset
;
138 void set_drop_shadow_color(SkColor color
) {
139 DCHECK_EQ(type_
, DROP_SHADOW
);
140 drop_shadow_color_
= color
;
143 void set_matrix(const SkScalar matrix
[20]) {
144 DCHECK_EQ(type_
, COLOR_MATRIX
);
145 for (unsigned i
= 0; i
< 20; ++i
)
146 matrix_
[i
] = matrix
[i
];
149 void set_zoom_inset(int inset
) {
150 DCHECK_EQ(type_
, ZOOM
);
154 // Given two filters of the same type, returns a filter operation created by
155 // linearly interpolating a |progress| fraction from |from| to |to|. If either
156 // |from| or |to| (but not both) is null, it is treated as a no-op filter of
157 // the same type as the other given filter. If both |from| and |to| are null,
158 // or if |from| and |to| are non-null but of different types, returns a
160 static FilterOperation
Blend(const FilterOperation
* from
,
161 const FilterOperation
* to
,
165 FilterOperation(FilterType type
, float amount
);
167 FilterOperation(FilterType type
,
172 FilterOperation(FilterType
, SkScalar matrix
[20]);
174 FilterOperation(FilterType type
, float amount
, int inset
);
178 gfx::Point drop_shadow_offset_
;
179 SkColor drop_shadow_color_
;
180 SkScalar matrix_
[20];
186 #endif // CC_OUTPUT_FILTER_OPERATION_H_