Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(784)

Side by Side Diff: cc/output/filter_operation.h

Issue 21154002: Add support for converting cc::FilterOperations into an SkImageFilter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | cc/output/filter_operation.cc » ('j') | cc/output/filter_operation.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_OUTPUT_FILTER_OPERATION_H_ 5 #ifndef CC_OUTPUT_FILTER_OPERATION_H_
6 #define CC_OUTPUT_FILTER_OPERATION_H_ 6 #define CC_OUTPUT_FILTER_OPERATION_H_
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "cc/base/cc_export.h" 9 #include "cc/base/cc_export.h"
10 #include "skia/ext/refptr.h"
10 #include "third_party/skia/include/core/SkColor.h" 11 #include "third_party/skia/include/core/SkColor.h"
12 #include "third_party/skia/include/core/SkImageFilter.h"
11 #include "third_party/skia/include/core/SkScalar.h" 13 #include "third_party/skia/include/core/SkScalar.h"
12 #include "ui/gfx/point.h" 14 #include "ui/gfx/point.h"
13 15
14 namespace cc { 16 namespace cc {
15 17
16 class CC_EXPORT FilterOperation { 18 class CC_EXPORT FilterOperation {
17 public: 19 public:
18 enum FilterType { 20 enum FilterType {
19 GRAYSCALE, 21 GRAYSCALE,
20 SEPIA, 22 SEPIA,
21 SATURATE, 23 SATURATE,
22 HUE_ROTATE, 24 HUE_ROTATE,
23 INVERT, 25 INVERT,
24 BRIGHTNESS, 26 BRIGHTNESS,
25 CONTRAST, 27 CONTRAST,
26 OPACITY, 28 OPACITY,
27 BLUR, 29 BLUR,
28 DROP_SHADOW, 30 DROP_SHADOW,
29 COLOR_MATRIX, 31 COLOR_MATRIX,
30 ZOOM, 32 ZOOM,
33 REFERENCE,
31 SATURATING_BRIGHTNESS, // Not used in CSS/SVG. 34 SATURATING_BRIGHTNESS, // Not used in CSS/SVG.
32 }; 35 };
33 36
37 FilterOperation(const FilterOperation& other);
38
39 ~FilterOperation();
40
34 FilterType type() const { return type_; } 41 FilterType type() const { return type_; }
35 42
36 float amount() const { 43 float amount() const {
37 DCHECK_NE(type_, COLOR_MATRIX); 44 DCHECK_NE(type_, COLOR_MATRIX);
45 DCHECK_NE(type_, REFERENCE);
38 return amount_; 46 return amount_;
39 } 47 }
40 48
41 gfx::Point drop_shadow_offset() const { 49 gfx::Point drop_shadow_offset() const {
42 DCHECK_EQ(type_, DROP_SHADOW); 50 DCHECK_EQ(type_, DROP_SHADOW);
43 return drop_shadow_offset_; 51 return drop_shadow_offset_;
44 } 52 }
45 53
46 SkColor drop_shadow_color() const { 54 SkColor drop_shadow_color() const {
47 DCHECK_EQ(type_, DROP_SHADOW); 55 DCHECK_EQ(type_, DROP_SHADOW);
48 return drop_shadow_color_; 56 return drop_shadow_color_;
49 } 57 }
50 58
59 skia::RefPtr<SkImageFilter> image_filter() const {
60 DCHECK_EQ(type_, REFERENCE);
61 return image_filter_;
62 }
63
51 const SkScalar* matrix() const { 64 const SkScalar* matrix() const {
52 DCHECK_EQ(type_, COLOR_MATRIX); 65 DCHECK_EQ(type_, COLOR_MATRIX);
53 return matrix_; 66 return matrix_;
54 } 67 }
55 68
56 int zoom_inset() const { 69 int zoom_inset() const {
57 DCHECK_EQ(type_, ZOOM); 70 DCHECK_EQ(type_, ZOOM);
58 return zoom_inset_; 71 return zoom_inset_;
59 } 72 }
60 73
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 114 }
102 115
103 static FilterOperation CreateColorMatrixFilter(SkScalar matrix[20]) { 116 static FilterOperation CreateColorMatrixFilter(SkScalar matrix[20]) {
104 return FilterOperation(COLOR_MATRIX, matrix); 117 return FilterOperation(COLOR_MATRIX, matrix);
105 } 118 }
106 119
107 static FilterOperation CreateZoomFilter(float amount, int inset) { 120 static FilterOperation CreateZoomFilter(float amount, int inset) {
108 return FilterOperation(ZOOM, amount, inset); 121 return FilterOperation(ZOOM, amount, inset);
109 } 122 }
110 123
124 static FilterOperation CreateReferenceFilter(
125 const skia::RefPtr<SkImageFilter> image_filter) {
126 return FilterOperation(REFERENCE, image_filter);
127 }
128
111 static FilterOperation CreateSaturatingBrightnessFilter(float amount) { 129 static FilterOperation CreateSaturatingBrightnessFilter(float amount) {
112 return FilterOperation(SATURATING_BRIGHTNESS, amount); 130 return FilterOperation(SATURATING_BRIGHTNESS, amount);
113 } 131 }
114 132
115 bool operator==(const FilterOperation& other) const; 133 bool operator==(const FilterOperation& other) const;
116 134
117 bool operator!=(const FilterOperation& other) const { 135 bool operator!=(const FilterOperation& other) const {
118 return !(*this == other); 136 return !(*this == other);
119 } 137 }
120 138
121 // Methods for restoring a FilterOperation. 139 // Methods for restoring a FilterOperation.
122 static FilterOperation CreateEmptyFilter() { 140 static FilterOperation CreateEmptyFilter() {
123 return FilterOperation(GRAYSCALE, 0.f); 141 return FilterOperation(GRAYSCALE, 0.f);
124 } 142 }
125 143
126 void set_type(FilterType type) { type_ = type; } 144 void set_type(FilterType type) { type_ = type; }
127 145
128 void set_amount(float amount) { 146 void set_amount(float amount) {
129 DCHECK_NE(type_, COLOR_MATRIX); 147 DCHECK_NE(type_, COLOR_MATRIX);
148 DCHECK_NE(type_, REFERENCE);
130 amount_ = amount; 149 amount_ = amount;
131 } 150 }
132 151
133 void set_drop_shadow_offset(gfx::Point offset) { 152 void set_drop_shadow_offset(gfx::Point offset) {
134 DCHECK_EQ(type_, DROP_SHADOW); 153 DCHECK_EQ(type_, DROP_SHADOW);
135 drop_shadow_offset_ = offset; 154 drop_shadow_offset_ = offset;
136 } 155 }
137 156
138 void set_drop_shadow_color(SkColor color) { 157 void set_drop_shadow_color(SkColor color) {
139 DCHECK_EQ(type_, DROP_SHADOW); 158 DCHECK_EQ(type_, DROP_SHADOW);
140 drop_shadow_color_ = color; 159 drop_shadow_color_ = color;
141 } 160 }
142 161
162 void set_image_filter(const skia::RefPtr<SkImageFilter>& image_filter) {
163 DCHECK_EQ(type_, REFERENCE);
164 image_filter_ = image_filter;
165 }
166
143 void set_matrix(const SkScalar matrix[20]) { 167 void set_matrix(const SkScalar matrix[20]) {
144 DCHECK_EQ(type_, COLOR_MATRIX); 168 DCHECK_EQ(type_, COLOR_MATRIX);
145 for (unsigned i = 0; i < 20; ++i) 169 for (unsigned i = 0; i < 20; ++i)
146 matrix_[i] = matrix[i]; 170 matrix_[i] = matrix[i];
147 } 171 }
148 172
149 void set_zoom_inset(int inset) { 173 void set_zoom_inset(int inset) {
150 DCHECK_EQ(type_, ZOOM); 174 DCHECK_EQ(type_, ZOOM);
151 zoom_inset_ = inset; 175 zoom_inset_ = inset;
152 } 176 }
(...skipping 13 matching lines...) Expand all
166 190
167 FilterOperation(FilterType type, 191 FilterOperation(FilterType type,
168 gfx::Point offset, 192 gfx::Point offset,
169 float stdDeviation, 193 float stdDeviation,
170 SkColor color); 194 SkColor color);
171 195
172 FilterOperation(FilterType, SkScalar matrix[20]); 196 FilterOperation(FilterType, SkScalar matrix[20]);
173 197
174 FilterOperation(FilterType type, float amount, int inset); 198 FilterOperation(FilterType type, float amount, int inset);
175 199
200 FilterOperation(FilterType type,
201 const skia::RefPtr<SkImageFilter>& image_filter);
202
176 FilterType type_; 203 FilterType type_;
177 float amount_; 204 float amount_;
178 gfx::Point drop_shadow_offset_; 205 gfx::Point drop_shadow_offset_;
179 SkColor drop_shadow_color_; 206 SkColor drop_shadow_color_;
207 skia::RefPtr<SkImageFilter> image_filter_;
180 SkScalar matrix_[20]; 208 SkScalar matrix_[20];
181 int zoom_inset_; 209 int zoom_inset_;
182 }; 210 };
183 211
184 } // namespace cc 212 } // namespace cc
185 213
186 #endif // CC_OUTPUT_FILTER_OPERATION_H_ 214 #endif // CC_OUTPUT_FILTER_OPERATION_H_
OLDNEW
« no previous file with comments | « no previous file | cc/output/filter_operation.cc » ('j') | cc/output/filter_operation.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698