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

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

Issue 2748263002: Move cc::DisplayItemList and related classes into cc/paint/ (Closed)
Patch Set: Merge branch 'master' into ccpaint Created 3 years, 9 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
« no previous file with comments | « cc/output/direct_renderer.h ('k') | cc/output/filter_operation.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef CC_OUTPUT_FILTER_OPERATION_H_
6 #define CC_OUTPUT_FILTER_OPERATION_H_
7
8 #include <memory>
9
10 #include "base/logging.h"
11 #include "cc/base/cc_export.h"
12 #include "third_party/skia/include/core/SkColor.h"
13 #include "third_party/skia/include/core/SkImageFilter.h"
14 #include "third_party/skia/include/core/SkRegion.h"
15 #include "third_party/skia/include/core/SkScalar.h"
16 #include "ui/gfx/geometry/point.h"
17
18 namespace base {
19 namespace trace_event {
20 class TracedValue;
21 }
22 }
23
24 namespace gfx {
25 class Rect;
26 }
27
28 namespace cc {
29
30 class CC_EXPORT FilterOperation {
31 public:
32 enum FilterType {
33 GRAYSCALE,
34 SEPIA,
35 SATURATE,
36 HUE_ROTATE,
37 INVERT,
38 BRIGHTNESS,
39 CONTRAST,
40 OPACITY,
41 BLUR,
42 DROP_SHADOW,
43 COLOR_MATRIX,
44 ZOOM,
45 REFERENCE,
46 SATURATING_BRIGHTNESS, // Not used in CSS/SVG.
47 ALPHA_THRESHOLD, // Not used in CSS/SVG.
48 FILTER_TYPE_LAST = ALPHA_THRESHOLD
49 };
50
51 FilterOperation();
52
53 FilterOperation(const FilterOperation& other);
54
55 ~FilterOperation();
56
57 FilterType type() const { return type_; }
58
59 float amount() const {
60 DCHECK_NE(type_, COLOR_MATRIX);
61 DCHECK_NE(type_, REFERENCE);
62 return amount_;
63 }
64
65 float outer_threshold() const {
66 DCHECK_EQ(type_, ALPHA_THRESHOLD);
67 return outer_threshold_;
68 }
69
70 gfx::Point drop_shadow_offset() const {
71 DCHECK_EQ(type_, DROP_SHADOW);
72 return drop_shadow_offset_;
73 }
74
75 SkColor drop_shadow_color() const {
76 DCHECK_EQ(type_, DROP_SHADOW);
77 return drop_shadow_color_;
78 }
79
80 const sk_sp<SkImageFilter>& image_filter() const {
81 DCHECK_EQ(type_, REFERENCE);
82 return image_filter_;
83 }
84
85 const SkScalar* matrix() const {
86 DCHECK_EQ(type_, COLOR_MATRIX);
87 return matrix_;
88 }
89
90 int zoom_inset() const {
91 DCHECK_EQ(type_, ZOOM);
92 return zoom_inset_;
93 }
94
95 const SkRegion& region() const {
96 DCHECK_EQ(type_, ALPHA_THRESHOLD);
97 return region_;
98 }
99
100 static FilterOperation CreateGrayscaleFilter(float amount) {
101 return FilterOperation(GRAYSCALE, amount);
102 }
103
104 static FilterOperation CreateSepiaFilter(float amount) {
105 return FilterOperation(SEPIA, amount);
106 }
107
108 static FilterOperation CreateSaturateFilter(float amount) {
109 return FilterOperation(SATURATE, amount);
110 }
111
112 static FilterOperation CreateHueRotateFilter(float amount) {
113 return FilterOperation(HUE_ROTATE, amount);
114 }
115
116 static FilterOperation CreateInvertFilter(float amount) {
117 return FilterOperation(INVERT, amount);
118 }
119
120 static FilterOperation CreateBrightnessFilter(float amount) {
121 return FilterOperation(BRIGHTNESS, amount);
122 }
123
124 static FilterOperation CreateContrastFilter(float amount) {
125 return FilterOperation(CONTRAST, amount);
126 }
127
128 static FilterOperation CreateOpacityFilter(float amount) {
129 return FilterOperation(OPACITY, amount);
130 }
131
132 static FilterOperation CreateBlurFilter(float amount) {
133 return FilterOperation(BLUR, amount);
134 }
135
136 static FilterOperation CreateDropShadowFilter(const gfx::Point& offset,
137 float std_deviation,
138 SkColor color) {
139 return FilterOperation(DROP_SHADOW, offset, std_deviation, color);
140 }
141
142 static FilterOperation CreateColorMatrixFilter(SkScalar matrix[20]) {
143 return FilterOperation(COLOR_MATRIX, matrix);
144 }
145
146 static FilterOperation CreateZoomFilter(float amount, int inset) {
147 return FilterOperation(ZOOM, amount, inset);
148 }
149
150 static FilterOperation CreateReferenceFilter(
151 sk_sp<SkImageFilter> image_filter) {
152 return FilterOperation(REFERENCE, std::move(image_filter));
153 }
154
155 static FilterOperation CreateSaturatingBrightnessFilter(float amount) {
156 return FilterOperation(SATURATING_BRIGHTNESS, amount);
157 }
158
159 static FilterOperation CreateAlphaThresholdFilter(const SkRegion& region,
160 float inner_threshold,
161 float outer_threshold) {
162 return FilterOperation(ALPHA_THRESHOLD, region,
163 inner_threshold, outer_threshold);
164 }
165
166 bool operator==(const FilterOperation& other) const;
167
168 bool operator!=(const FilterOperation& other) const {
169 return !(*this == other);
170 }
171
172 // Methods for restoring a FilterOperation.
173 static FilterOperation CreateEmptyFilter() {
174 return FilterOperation(GRAYSCALE, 0.f);
175 }
176
177 void set_type(FilterType type) { type_ = type; }
178
179 void set_amount(float amount) {
180 DCHECK_NE(type_, COLOR_MATRIX);
181 DCHECK_NE(type_, REFERENCE);
182 amount_ = amount;
183 }
184
185 void set_outer_threshold(float outer_threshold) {
186 DCHECK_EQ(type_, ALPHA_THRESHOLD);
187 outer_threshold_ = outer_threshold;
188 }
189
190 void set_drop_shadow_offset(const gfx::Point& offset) {
191 DCHECK_EQ(type_, DROP_SHADOW);
192 drop_shadow_offset_ = offset;
193 }
194
195 void set_drop_shadow_color(SkColor color) {
196 DCHECK_EQ(type_, DROP_SHADOW);
197 drop_shadow_color_ = color;
198 }
199
200 void set_image_filter(sk_sp<SkImageFilter> image_filter) {
201 DCHECK_EQ(type_, REFERENCE);
202 image_filter_ = std::move(image_filter);
203 }
204
205 void set_matrix(const SkScalar matrix[20]) {
206 DCHECK_EQ(type_, COLOR_MATRIX);
207 for (unsigned i = 0; i < 20; ++i)
208 matrix_[i] = matrix[i];
209 }
210
211 void set_zoom_inset(int inset) {
212 DCHECK_EQ(type_, ZOOM);
213 zoom_inset_ = inset;
214 }
215
216 void set_region(const SkRegion& region) {
217 DCHECK_EQ(type_, ALPHA_THRESHOLD);
218 region_ = region;
219 }
220
221 // Given two filters of the same type, returns a filter operation created by
222 // linearly interpolating a |progress| fraction from |from| to |to|. If either
223 // |from| or |to| (but not both) is null, it is treated as a no-op filter of
224 // the same type as the other given filter. If both |from| and |to| are null,
225 // or if |from| and |to| are non-null but of different types, returns a
226 // no-op filter.
227 static FilterOperation Blend(const FilterOperation* from,
228 const FilterOperation* to,
229 double progress);
230
231 void AsValueInto(base::trace_event::TracedValue* value) const;
232
233 // Maps "forward" to determine which pixels in a destination rect are affected
234 // by pixels in the source rect.
235 gfx::Rect MapRect(const gfx::Rect& rect, const SkMatrix& matrix) const;
236
237 // Maps "backward" to determine which pixels in the source affect the pixels
238 // in the destination rect.
239 gfx::Rect MapRectReverse(const gfx::Rect& rect, const SkMatrix& matrix) const;
240
241 private:
242 FilterOperation(FilterType type, float amount);
243
244 FilterOperation(FilterType type,
245 const gfx::Point& offset,
246 float stdDeviation,
247 SkColor color);
248
249 FilterOperation(FilterType, SkScalar matrix[20]);
250
251 FilterOperation(FilterType type, float amount, int inset);
252
253 FilterOperation(FilterType type, sk_sp<SkImageFilter> image_filter);
254
255 FilterOperation(FilterType type,
256 const SkRegion& region,
257 float inner_threshold,
258 float outer_threshold);
259
260 FilterType type_;
261 float amount_;
262 float outer_threshold_;
263 gfx::Point drop_shadow_offset_;
264 SkColor drop_shadow_color_;
265 sk_sp<SkImageFilter> image_filter_;
266 SkScalar matrix_[20];
267 int zoom_inset_;
268 SkRegion region_;
269 };
270
271 } // namespace cc
272
273 #endif // CC_OUTPUT_FILTER_OPERATION_H_
OLDNEW
« no previous file with comments | « cc/output/direct_renderer.h ('k') | cc/output/filter_operation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698