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

Side by Side Diff: Source/core/platform/graphics/filters/FilterOperation.h

Issue 99103006: Moving GraphicsContext and dependencies from core to platform. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Final patch - fixes Android Created 7 years 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
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef FilterOperation_h
27 #define FilterOperation_h
28
29 #include "core/platform/graphics/filters/Filter.h"
30 #include "core/platform/graphics/filters/ReferenceFilter.h"
31 #include "platform/Length.h"
32 #include "platform/graphics/Color.h"
33 #include "wtf/OwnPtr.h"
34 #include "wtf/PassOwnPtr.h"
35 #include "wtf/RefCounted.h"
36 #include "wtf/text/WTFString.h"
37
38 namespace WebCore {
39
40 // CSS Filters
41
42 class FilterOperation : public RefCounted<FilterOperation> {
43 public:
44 enum OperationType {
45 REFERENCE, // url(#somefilter)
46 GRAYSCALE,
47 SEPIA,
48 SATURATE,
49 HUE_ROTATE,
50 INVERT,
51 OPACITY,
52 BRIGHTNESS,
53 CONTRAST,
54 BLUR,
55 DROP_SHADOW,
56 CUSTOM,
57 VALIDATED_CUSTOM,
58 NONE
59 };
60
61 static bool canInterpolate(FilterOperation::OperationType type)
62 {
63 switch (type) {
64 case GRAYSCALE:
65 case SEPIA:
66 case SATURATE:
67 case HUE_ROTATE:
68 case INVERT:
69 case OPACITY:
70 case BRIGHTNESS:
71 case CONTRAST:
72 case BLUR:
73 case DROP_SHADOW:
74 case CUSTOM:
75 case VALIDATED_CUSTOM:
76 return true;
77 case REFERENCE:
78 return false;
79 case NONE:
80 break;
81 }
82 ASSERT_NOT_REACHED();
83 return false;
84 }
85
86 virtual ~FilterOperation() { }
87
88 static PassRefPtr<FilterOperation> blend(const FilterOperation* from, const FilterOperation* to, double progress);
89 virtual bool operator==(const FilterOperation&) const = 0;
90 bool operator!=(const FilterOperation& o) const { return !(*this == o); }
91
92 OperationType type() const { return m_type; }
93 virtual bool isSameType(const FilterOperation& o) const { return o.type() == m_type; }
94
95 // True if the alpha channel of any pixel can change under this operation.
96 virtual bool affectsOpacity() const { return false; }
97 // True if the the value of one pixel can affect the value of another pixel under this operation, such as blur.
98 virtual bool movesPixels() const { return false; }
99
100 protected:
101 FilterOperation(OperationType type)
102 : m_type(type)
103 {
104 }
105
106 OperationType m_type;
107
108 private:
109 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, doubl e progress) const = 0;
110 };
111
112 #define DEFINE_FILTER_OPERATION_TYPE_CASTS(thisType, operationType) \
113 DEFINE_TYPE_CASTS(thisType, FilterOperation, op, op->type() == FilterOperati on::operationType, op.type() == FilterOperation::operationType);
114
115 class ReferenceFilterOperation : public FilterOperation {
116 public:
117 static PassRefPtr<ReferenceFilterOperation> create(const String& url, const String& fragment)
118 {
119 return adoptRef(new ReferenceFilterOperation(url, fragment));
120 }
121
122 virtual bool affectsOpacity() const { return true; }
123 virtual bool movesPixels() const { return true; }
124
125 const String& url() const { return m_url; }
126 const String& fragment() const { return m_fragment; }
127
128 ReferenceFilter* filter() const { return m_filter.get(); }
129 void setFilter(PassRefPtr<ReferenceFilter> filter) { m_filter = filter; }
130
131 private:
132 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, doubl e progress) const OVERRIDE
133 {
134 ASSERT_NOT_REACHED();
135 return 0;
136 }
137
138 virtual bool operator==(const FilterOperation& o) const
139 {
140 if (!isSameType(o))
141 return false;
142 const ReferenceFilterOperation* other = static_cast<const ReferenceFilte rOperation*>(&o);
143 return m_url == other->m_url;
144 }
145
146 ReferenceFilterOperation(const String& url, const String& fragment)
147 : FilterOperation(REFERENCE)
148 , m_url(url)
149 , m_fragment(fragment)
150 {
151 }
152
153 String m_url;
154 String m_fragment;
155 RefPtr<ReferenceFilter> m_filter;
156 };
157
158 DEFINE_FILTER_OPERATION_TYPE_CASTS(ReferenceFilterOperation, REFERENCE);
159
160 // GRAYSCALE, SEPIA, SATURATE and HUE_ROTATE are variations on a basic color mat rix effect.
161 // For HUE_ROTATE, the angle of rotation is stored in m_amount.
162 class BasicColorMatrixFilterOperation : public FilterOperation {
163 public:
164 static PassRefPtr<BasicColorMatrixFilterOperation> create(double amount, Ope rationType type)
165 {
166 return adoptRef(new BasicColorMatrixFilterOperation(amount, type));
167 }
168
169 double amount() const { return m_amount; }
170
171
172 private:
173 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, doubl e progress) const OVERRIDE;
174 virtual bool operator==(const FilterOperation& o) const
175 {
176 if (!isSameType(o))
177 return false;
178 const BasicColorMatrixFilterOperation* other = static_cast<const BasicCo lorMatrixFilterOperation*>(&o);
179 return m_amount == other->m_amount;
180 }
181
182 BasicColorMatrixFilterOperation(double amount, OperationType type)
183 : FilterOperation(type)
184 , m_amount(amount)
185 {
186 }
187
188 double m_amount;
189 };
190
191 inline bool isBasicColorMatrixFilterOperation(const FilterOperation& operation)
192 {
193 FilterOperation::OperationType type = operation.type();
194 return type == FilterOperation::GRAYSCALE || type == FilterOperation::SEPIA || type == FilterOperation::SATURATE || type == FilterOperation::HUE_ROTATE;
195 }
196
197 DEFINE_TYPE_CASTS(BasicColorMatrixFilterOperation, FilterOperation, op, isBasicC olorMatrixFilterOperation(*op), isBasicColorMatrixFilterOperation(op));
198
199 // INVERT, BRIGHTNESS, CONTRAST and OPACITY are variations on a basic component transfer effect.
200 class BasicComponentTransferFilterOperation : public FilterOperation {
201 public:
202 static PassRefPtr<BasicComponentTransferFilterOperation> create(double amoun t, OperationType type)
203 {
204 return adoptRef(new BasicComponentTransferFilterOperation(amount, type)) ;
205 }
206
207 double amount() const { return m_amount; }
208
209 virtual bool affectsOpacity() const { return m_type == OPACITY; }
210
211
212 private:
213 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, doubl e progress) const OVERRIDE;
214 virtual bool operator==(const FilterOperation& o) const
215 {
216 if (!isSameType(o))
217 return false;
218 const BasicComponentTransferFilterOperation* other = static_cast<const B asicComponentTransferFilterOperation*>(&o);
219 return m_amount == other->m_amount;
220 }
221
222 BasicComponentTransferFilterOperation(double amount, OperationType type)
223 : FilterOperation(type)
224 , m_amount(amount)
225 {
226 }
227
228 double m_amount;
229 };
230
231 inline bool isBasicComponentTransferFilterOperation(const FilterOperation& opera tion)
232 {
233 FilterOperation::OperationType type = operation.type();
234 return type == FilterOperation::INVERT || type == FilterOperation::OPACITY | | type == FilterOperation::BRIGHTNESS || type == FilterOperation::CONTRAST;
235 }
236
237 DEFINE_TYPE_CASTS(BasicComponentTransferFilterOperation, FilterOperation, op, is BasicComponentTransferFilterOperation(*op), isBasicComponentTransferFilterOperat ion(op));
238
239 class BlurFilterOperation : public FilterOperation {
240 public:
241 static PassRefPtr<BlurFilterOperation> create(Length stdDeviation)
242 {
243 return adoptRef(new BlurFilterOperation(stdDeviation));
244 }
245
246 Length stdDeviation() const { return m_stdDeviation; }
247
248 virtual bool affectsOpacity() const { return true; }
249 virtual bool movesPixels() const { return true; }
250
251
252 private:
253 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, doubl e progress) const OVERRIDE;
254 virtual bool operator==(const FilterOperation& o) const
255 {
256 if (!isSameType(o))
257 return false;
258 const BlurFilterOperation* other = static_cast<const BlurFilterOperation *>(&o);
259 return m_stdDeviation == other->m_stdDeviation;
260 }
261
262 BlurFilterOperation(Length stdDeviation)
263 : FilterOperation(BLUR)
264 , m_stdDeviation(stdDeviation)
265 {
266 }
267
268 Length m_stdDeviation;
269 };
270
271 DEFINE_FILTER_OPERATION_TYPE_CASTS(BlurFilterOperation, BLUR);
272
273 class DropShadowFilterOperation : public FilterOperation {
274 public:
275 static PassRefPtr<DropShadowFilterOperation> create(const IntPoint& location , int stdDeviation, Color color)
276 {
277 return adoptRef(new DropShadowFilterOperation(location, stdDeviation, co lor));
278 }
279
280 int x() const { return m_location.x(); }
281 int y() const { return m_location.y(); }
282 IntPoint location() const { return m_location; }
283 int stdDeviation() const { return m_stdDeviation; }
284 Color color() const { return m_color; }
285
286 virtual bool affectsOpacity() const { return true; }
287 virtual bool movesPixels() const { return true; }
288
289
290 private:
291 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, doubl e progress) const OVERRIDE;
292 virtual bool operator==(const FilterOperation& o) const
293 {
294 if (!isSameType(o))
295 return false;
296 const DropShadowFilterOperation* other = static_cast<const DropShadowFil terOperation*>(&o);
297 return m_location == other->m_location && m_stdDeviation == other->m_std Deviation && m_color == other->m_color;
298 }
299
300 DropShadowFilterOperation(const IntPoint& location, int stdDeviation, Color color)
301 : FilterOperation(DROP_SHADOW)
302 , m_location(location)
303 , m_stdDeviation(stdDeviation)
304 , m_color(color)
305 {
306 }
307
308 IntPoint m_location; // FIXME: should location be in Lengths?
309 int m_stdDeviation;
310 Color m_color;
311 };
312
313 DEFINE_FILTER_OPERATION_TYPE_CASTS(DropShadowFilterOperation, DROP_SHADOW);
314
315 } // namespace WebCore
316
317
318 #endif // FilterOperation_h
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/filters/FilterEffect.cpp ('k') | Source/core/platform/graphics/filters/FilterOperation.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698