OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 case NONE: | 81 case NONE: |
82 break; | 82 break; |
83 } | 83 } |
84 ASSERT_NOT_REACHED(); | 84 ASSERT_NOT_REACHED(); |
85 return false; | 85 return false; |
86 } | 86 } |
87 | 87 |
88 virtual ~FilterOperation() { } | 88 virtual ~FilterOperation() { } |
89 DEFINE_INLINE_VIRTUAL_TRACE() { } | 89 DEFINE_INLINE_VIRTUAL_TRACE() { } |
90 | 90 |
91 static RawPtr<FilterOperation> blend(const FilterOperation* from, const Filt
erOperation* to, double progress); | 91 static FilterOperation* blend(const FilterOperation* from, const FilterOpera
tion* to, double progress); |
92 virtual bool operator==(const FilterOperation&) const = 0; | 92 virtual bool operator==(const FilterOperation&) const = 0; |
93 bool operator!=(const FilterOperation& o) const { return !(*this == o); } | 93 bool operator!=(const FilterOperation& o) const { return !(*this == o); } |
94 | 94 |
95 OperationType type() const { return m_type; } | 95 OperationType type() const { return m_type; } |
96 virtual bool isSameType(const FilterOperation& o) const { return o.type() ==
m_type; } | 96 virtual bool isSameType(const FilterOperation& o) const { return o.type() ==
m_type; } |
97 | 97 |
98 // True if the alpha channel of any pixel can change under this operation. | 98 // True if the alpha channel of any pixel can change under this operation. |
99 virtual bool affectsOpacity() const { return false; } | 99 virtual bool affectsOpacity() const { return false; } |
100 // True if the the value of one pixel can affect the value of another pixel
under this operation, such as blur. | 100 // True if the the value of one pixel can affect the value of another pixel
under this operation, such as blur. |
101 virtual bool movesPixels() const { return false; } | 101 virtual bool movesPixels() const { return false; } |
102 | 102 |
103 protected: | 103 protected: |
104 FilterOperation(OperationType type) | 104 FilterOperation(OperationType type) |
105 : m_type(type) | 105 : m_type(type) |
106 { | 106 { |
107 } | 107 } |
108 | 108 |
109 OperationType m_type; | 109 OperationType m_type; |
110 | 110 |
111 private: | 111 private: |
112 virtual RawPtr<FilterOperation> blend(const FilterOperation* from, double pr
ogress) const = 0; | 112 virtual FilterOperation* blend(const FilterOperation* from, double progress)
const = 0; |
113 }; | 113 }; |
114 | 114 |
115 #define DEFINE_FILTER_OPERATION_TYPE_CASTS(thisType, operationType) \ | 115 #define DEFINE_FILTER_OPERATION_TYPE_CASTS(thisType, operationType) \ |
116 DEFINE_TYPE_CASTS(thisType, FilterOperation, op, op->type() == FilterOperati
on::operationType, op.type() == FilterOperation::operationType); | 116 DEFINE_TYPE_CASTS(thisType, FilterOperation, op, op->type() == FilterOperati
on::operationType, op.type() == FilterOperation::operationType); |
117 | 117 |
118 class PLATFORM_EXPORT ReferenceFilterOperation : public FilterOperation { | 118 class PLATFORM_EXPORT ReferenceFilterOperation : public FilterOperation { |
119 public: | 119 public: |
120 static RawPtr<ReferenceFilterOperation> create(const String& url, const Atom
icString& fragment) | 120 static ReferenceFilterOperation* create(const String& url, const AtomicStrin
g& fragment) |
121 { | 121 { |
122 return new ReferenceFilterOperation(url, fragment); | 122 return new ReferenceFilterOperation(url, fragment); |
123 } | 123 } |
124 | 124 |
125 bool affectsOpacity() const override { return true; } | 125 bool affectsOpacity() const override { return true; } |
126 bool movesPixels() const override { return true; } | 126 bool movesPixels() const override { return true; } |
127 | 127 |
128 const String& url() const { return m_url; } | 128 const String& url() const { return m_url; } |
129 const AtomicString& fragment() const { return m_fragment; } | 129 const AtomicString& fragment() const { return m_fragment; } |
130 | 130 |
131 Filter* getFilter() const { return m_filter.get(); } | 131 Filter* getFilter() const { return m_filter.get(); } |
132 void setFilter(RawPtr<Filter> filter) { m_filter = filter; } | 132 void setFilter(Filter* filter) { m_filter = filter; } |
133 | 133 |
134 DECLARE_VIRTUAL_TRACE(); | 134 DECLARE_VIRTUAL_TRACE(); |
135 | 135 |
136 private: | 136 private: |
137 RawPtr<FilterOperation> blend(const FilterOperation* from, double progress)
const override | 137 FilterOperation* blend(const FilterOperation* from, double progress) const o
verride |
138 { | 138 { |
139 ASSERT_NOT_REACHED(); | 139 ASSERT_NOT_REACHED(); |
140 return nullptr; | 140 return nullptr; |
141 } | 141 } |
142 | 142 |
143 bool operator==(const FilterOperation& o) const override | 143 bool operator==(const FilterOperation& o) const override |
144 { | 144 { |
145 if (!isSameType(o)) | 145 if (!isSameType(o)) |
146 return false; | 146 return false; |
147 const ReferenceFilterOperation* other = static_cast<const ReferenceFilte
rOperation*>(&o); | 147 const ReferenceFilterOperation* other = static_cast<const ReferenceFilte
rOperation*>(&o); |
(...skipping 11 matching lines...) Expand all Loading... |
159 AtomicString m_fragment; | 159 AtomicString m_fragment; |
160 Member<Filter> m_filter; | 160 Member<Filter> m_filter; |
161 }; | 161 }; |
162 | 162 |
163 DEFINE_FILTER_OPERATION_TYPE_CASTS(ReferenceFilterOperation, REFERENCE); | 163 DEFINE_FILTER_OPERATION_TYPE_CASTS(ReferenceFilterOperation, REFERENCE); |
164 | 164 |
165 // GRAYSCALE, SEPIA, SATURATE and HUE_ROTATE are variations on a basic color mat
rix effect. | 165 // GRAYSCALE, SEPIA, SATURATE and HUE_ROTATE are variations on a basic color mat
rix effect. |
166 // For HUE_ROTATE, the angle of rotation is stored in m_amount. | 166 // For HUE_ROTATE, the angle of rotation is stored in m_amount. |
167 class PLATFORM_EXPORT BasicColorMatrixFilterOperation : public FilterOperation { | 167 class PLATFORM_EXPORT BasicColorMatrixFilterOperation : public FilterOperation { |
168 public: | 168 public: |
169 static RawPtr<BasicColorMatrixFilterOperation> create(double amount, Operati
onType type) | 169 static BasicColorMatrixFilterOperation* create(double amount, OperationType
type) |
170 { | 170 { |
171 return new BasicColorMatrixFilterOperation(amount, type); | 171 return new BasicColorMatrixFilterOperation(amount, type); |
172 } | 172 } |
173 | 173 |
174 double amount() const { return m_amount; } | 174 double amount() const { return m_amount; } |
175 | 175 |
176 | 176 |
177 private: | 177 private: |
178 RawPtr<FilterOperation> blend(const FilterOperation* from, double progress)
const override; | 178 FilterOperation* blend(const FilterOperation* from, double progress) const o
verride; |
179 bool operator==(const FilterOperation& o) const override | 179 bool operator==(const FilterOperation& o) const override |
180 { | 180 { |
181 if (!isSameType(o)) | 181 if (!isSameType(o)) |
182 return false; | 182 return false; |
183 const BasicColorMatrixFilterOperation* other = static_cast<const BasicCo
lorMatrixFilterOperation*>(&o); | 183 const BasicColorMatrixFilterOperation* other = static_cast<const BasicCo
lorMatrixFilterOperation*>(&o); |
184 return m_amount == other->m_amount; | 184 return m_amount == other->m_amount; |
185 } | 185 } |
186 | 186 |
187 BasicColorMatrixFilterOperation(double amount, OperationType type) | 187 BasicColorMatrixFilterOperation(double amount, OperationType type) |
188 : FilterOperation(type) | 188 : FilterOperation(type) |
189 , m_amount(amount) | 189 , m_amount(amount) |
190 { | 190 { |
191 } | 191 } |
192 | 192 |
193 double m_amount; | 193 double m_amount; |
194 }; | 194 }; |
195 | 195 |
196 inline bool isBasicColorMatrixFilterOperation(const FilterOperation& operation) | 196 inline bool isBasicColorMatrixFilterOperation(const FilterOperation& operation) |
197 { | 197 { |
198 FilterOperation::OperationType type = operation.type(); | 198 FilterOperation::OperationType type = operation.type(); |
199 return type == FilterOperation::GRAYSCALE || type == FilterOperation::SEPIA
|| type == FilterOperation::SATURATE || type == FilterOperation::HUE_ROTATE; | 199 return type == FilterOperation::GRAYSCALE || type == FilterOperation::SEPIA
|| type == FilterOperation::SATURATE || type == FilterOperation::HUE_ROTATE; |
200 } | 200 } |
201 | 201 |
202 DEFINE_TYPE_CASTS(BasicColorMatrixFilterOperation, FilterOperation, op, isBasicC
olorMatrixFilterOperation(*op), isBasicColorMatrixFilterOperation(op)); | 202 DEFINE_TYPE_CASTS(BasicColorMatrixFilterOperation, FilterOperation, op, isBasicC
olorMatrixFilterOperation(*op), isBasicColorMatrixFilterOperation(op)); |
203 | 203 |
204 // INVERT, BRIGHTNESS, CONTRAST and OPACITY are variations on a basic component
transfer effect. | 204 // INVERT, BRIGHTNESS, CONTRAST and OPACITY are variations on a basic component
transfer effect. |
205 class PLATFORM_EXPORT BasicComponentTransferFilterOperation : public FilterOpera
tion { | 205 class PLATFORM_EXPORT BasicComponentTransferFilterOperation : public FilterOpera
tion { |
206 public: | 206 public: |
207 static RawPtr<BasicComponentTransferFilterOperation> create(double amount, O
perationType type) | 207 static BasicComponentTransferFilterOperation* create(double amount, Operatio
nType type) |
208 { | 208 { |
209 return new BasicComponentTransferFilterOperation(amount, type); | 209 return new BasicComponentTransferFilterOperation(amount, type); |
210 } | 210 } |
211 | 211 |
212 double amount() const { return m_amount; } | 212 double amount() const { return m_amount; } |
213 | 213 |
214 bool affectsOpacity() const override { return m_type == OPACITY; } | 214 bool affectsOpacity() const override { return m_type == OPACITY; } |
215 | 215 |
216 | 216 |
217 private: | 217 private: |
218 RawPtr<FilterOperation> blend(const FilterOperation* from, double progress)
const override; | 218 FilterOperation* blend(const FilterOperation* from, double progress) const o
verride; |
219 bool operator==(const FilterOperation& o) const override | 219 bool operator==(const FilterOperation& o) const override |
220 { | 220 { |
221 if (!isSameType(o)) | 221 if (!isSameType(o)) |
222 return false; | 222 return false; |
223 const BasicComponentTransferFilterOperation* other = static_cast<const B
asicComponentTransferFilterOperation*>(&o); | 223 const BasicComponentTransferFilterOperation* other = static_cast<const B
asicComponentTransferFilterOperation*>(&o); |
224 return m_amount == other->m_amount; | 224 return m_amount == other->m_amount; |
225 } | 225 } |
226 | 226 |
227 BasicComponentTransferFilterOperation(double amount, OperationType type) | 227 BasicComponentTransferFilterOperation(double amount, OperationType type) |
228 : FilterOperation(type) | 228 : FilterOperation(type) |
229 , m_amount(amount) | 229 , m_amount(amount) |
230 { | 230 { |
231 } | 231 } |
232 | 232 |
233 double m_amount; | 233 double m_amount; |
234 }; | 234 }; |
235 | 235 |
236 inline bool isBasicComponentTransferFilterOperation(const FilterOperation& opera
tion) | 236 inline bool isBasicComponentTransferFilterOperation(const FilterOperation& opera
tion) |
237 { | 237 { |
238 FilterOperation::OperationType type = operation.type(); | 238 FilterOperation::OperationType type = operation.type(); |
239 return type == FilterOperation::INVERT || type == FilterOperation::OPACITY |
| type == FilterOperation::BRIGHTNESS || type == FilterOperation::CONTRAST; | 239 return type == FilterOperation::INVERT || type == FilterOperation::OPACITY |
| type == FilterOperation::BRIGHTNESS || type == FilterOperation::CONTRAST; |
240 } | 240 } |
241 | 241 |
242 DEFINE_TYPE_CASTS(BasicComponentTransferFilterOperation, FilterOperation, op, is
BasicComponentTransferFilterOperation(*op), isBasicComponentTransferFilterOperat
ion(op)); | 242 DEFINE_TYPE_CASTS(BasicComponentTransferFilterOperation, FilterOperation, op, is
BasicComponentTransferFilterOperation(*op), isBasicComponentTransferFilterOperat
ion(op)); |
243 | 243 |
244 class PLATFORM_EXPORT BlurFilterOperation : public FilterOperation { | 244 class PLATFORM_EXPORT BlurFilterOperation : public FilterOperation { |
245 public: | 245 public: |
246 static RawPtr<BlurFilterOperation> create(const Length& stdDeviation) | 246 static BlurFilterOperation* create(const Length& stdDeviation) |
247 { | 247 { |
248 return new BlurFilterOperation(stdDeviation); | 248 return new BlurFilterOperation(stdDeviation); |
249 } | 249 } |
250 | 250 |
251 const Length& stdDeviation() const { return m_stdDeviation; } | 251 const Length& stdDeviation() const { return m_stdDeviation; } |
252 | 252 |
253 bool affectsOpacity() const override { return true; } | 253 bool affectsOpacity() const override { return true; } |
254 bool movesPixels() const override { return true; } | 254 bool movesPixels() const override { return true; } |
255 | 255 |
256 | 256 |
257 private: | 257 private: |
258 RawPtr<FilterOperation> blend(const FilterOperation* from, double progress)
const override; | 258 FilterOperation* blend(const FilterOperation* from, double progress) const o
verride; |
259 bool operator==(const FilterOperation& o) const override | 259 bool operator==(const FilterOperation& o) const override |
260 { | 260 { |
261 if (!isSameType(o)) | 261 if (!isSameType(o)) |
262 return false; | 262 return false; |
263 const BlurFilterOperation* other = static_cast<const BlurFilterOperation
*>(&o); | 263 const BlurFilterOperation* other = static_cast<const BlurFilterOperation
*>(&o); |
264 return m_stdDeviation == other->m_stdDeviation; | 264 return m_stdDeviation == other->m_stdDeviation; |
265 } | 265 } |
266 | 266 |
267 BlurFilterOperation(const Length& stdDeviation) | 267 BlurFilterOperation(const Length& stdDeviation) |
268 : FilterOperation(BLUR) | 268 : FilterOperation(BLUR) |
269 , m_stdDeviation(stdDeviation) | 269 , m_stdDeviation(stdDeviation) |
270 { | 270 { |
271 } | 271 } |
272 | 272 |
273 Length m_stdDeviation; | 273 Length m_stdDeviation; |
274 }; | 274 }; |
275 | 275 |
276 DEFINE_FILTER_OPERATION_TYPE_CASTS(BlurFilterOperation, BLUR); | 276 DEFINE_FILTER_OPERATION_TYPE_CASTS(BlurFilterOperation, BLUR); |
277 | 277 |
278 class PLATFORM_EXPORT DropShadowFilterOperation : public FilterOperation { | 278 class PLATFORM_EXPORT DropShadowFilterOperation : public FilterOperation { |
279 public: | 279 public: |
280 static RawPtr<DropShadowFilterOperation> create(const IntPoint& location, in
t stdDeviation, Color color) | 280 static DropShadowFilterOperation* create(const IntPoint& location, int stdDe
viation, Color color) |
281 { | 281 { |
282 return new DropShadowFilterOperation(location, stdDeviation, color); | 282 return new DropShadowFilterOperation(location, stdDeviation, color); |
283 } | 283 } |
284 | 284 |
285 int x() const { return m_location.x(); } | 285 int x() const { return m_location.x(); } |
286 int y() const { return m_location.y(); } | 286 int y() const { return m_location.y(); } |
287 IntPoint location() const { return m_location; } | 287 IntPoint location() const { return m_location; } |
288 int stdDeviation() const { return m_stdDeviation; } | 288 int stdDeviation() const { return m_stdDeviation; } |
289 Color getColor() const { return m_color; } | 289 Color getColor() const { return m_color; } |
290 | 290 |
291 bool affectsOpacity() const override { return true; } | 291 bool affectsOpacity() const override { return true; } |
292 bool movesPixels() const override { return true; } | 292 bool movesPixels() const override { return true; } |
293 | 293 |
294 | 294 |
295 private: | 295 private: |
296 RawPtr<FilterOperation> blend(const FilterOperation* from, double progress)
const override; | 296 FilterOperation* blend(const FilterOperation* from, double progress) const o
verride; |
297 bool operator==(const FilterOperation& o) const override | 297 bool operator==(const FilterOperation& o) const override |
298 { | 298 { |
299 if (!isSameType(o)) | 299 if (!isSameType(o)) |
300 return false; | 300 return false; |
301 const DropShadowFilterOperation* other = static_cast<const DropShadowFil
terOperation*>(&o); | 301 const DropShadowFilterOperation* other = static_cast<const DropShadowFil
terOperation*>(&o); |
302 return m_location == other->m_location && m_stdDeviation == other->m_std
Deviation && m_color == other->m_color; | 302 return m_location == other->m_location && m_stdDeviation == other->m_std
Deviation && m_color == other->m_color; |
303 } | 303 } |
304 | 304 |
305 DropShadowFilterOperation(const IntPoint& location, int stdDeviation, Color
color) | 305 DropShadowFilterOperation(const IntPoint& location, int stdDeviation, Color
color) |
306 : FilterOperation(DROP_SHADOW) | 306 : FilterOperation(DROP_SHADOW) |
307 , m_location(location) | 307 , m_location(location) |
308 , m_stdDeviation(stdDeviation) | 308 , m_stdDeviation(stdDeviation) |
309 , m_color(color) | 309 , m_color(color) |
310 { | 310 { |
311 } | 311 } |
312 | 312 |
313 IntPoint m_location; // FIXME: should location be in Lengths? | 313 IntPoint m_location; // FIXME: should location be in Lengths? |
314 int m_stdDeviation; | 314 int m_stdDeviation; |
315 Color m_color; | 315 Color m_color; |
316 }; | 316 }; |
317 | 317 |
318 DEFINE_FILTER_OPERATION_TYPE_CASTS(DropShadowFilterOperation, DROP_SHADOW); | 318 DEFINE_FILTER_OPERATION_TYPE_CASTS(DropShadowFilterOperation, DROP_SHADOW); |
319 | 319 |
320 class PLATFORM_EXPORT BoxReflectFilterOperation : public FilterOperation { | 320 class PLATFORM_EXPORT BoxReflectFilterOperation : public FilterOperation { |
321 public: | 321 public: |
322 static RawPtr<BoxReflectFilterOperation> create(ReflectionDirection directio
n, float offset) | 322 static BoxReflectFilterOperation* create(ReflectionDirection direction, floa
t offset) |
323 { | 323 { |
324 return new BoxReflectFilterOperation(direction, offset); | 324 return new BoxReflectFilterOperation(direction, offset); |
325 } | 325 } |
326 | 326 |
327 ReflectionDirection direction() const { return m_direction; } | 327 ReflectionDirection direction() const { return m_direction; } |
328 float offset() const { return m_offset; } | 328 float offset() const { return m_offset; } |
329 | 329 |
330 bool affectsOpacity() const override { return true; } | 330 bool affectsOpacity() const override { return true; } |
331 bool movesPixels() const override { return true; } | 331 bool movesPixels() const override { return true; } |
332 | 332 |
333 private: | 333 private: |
334 RawPtr<FilterOperation> blend(const FilterOperation* from, double progress)
const override; | 334 FilterOperation* blend(const FilterOperation* from, double progress) const o
verride; |
335 bool operator==(const FilterOperation&) const override; | 335 bool operator==(const FilterOperation&) const override; |
336 | 336 |
337 BoxReflectFilterOperation(ReflectionDirection direction, float offset) | 337 BoxReflectFilterOperation(ReflectionDirection direction, float offset) |
338 : FilterOperation(BOX_REFLECT) | 338 : FilterOperation(BOX_REFLECT) |
339 , m_direction(direction) | 339 , m_direction(direction) |
340 , m_offset(offset) | 340 , m_offset(offset) |
341 { | 341 { |
342 } | 342 } |
343 | 343 |
344 ReflectionDirection m_direction; | 344 ReflectionDirection m_direction; |
345 float m_offset; | 345 float m_offset; |
346 }; | 346 }; |
347 DEFINE_FILTER_OPERATION_TYPE_CASTS(BoxReflectFilterOperation, BOX_REFLECT); | 347 DEFINE_FILTER_OPERATION_TYPE_CASTS(BoxReflectFilterOperation, BOX_REFLECT); |
348 | 348 |
349 } // namespace blink | 349 } // namespace blink |
350 | 350 |
351 #endif // FilterOperation_h | 351 #endif // FilterOperation_h |
OLD | NEW |