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

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

Issue 678163002: Oilpan: move SVG property hierarchy to the heap. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased upto r185213 Created 6 years, 1 month 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
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 13 matching lines...) Expand all
24 */ 24 */
25 25
26 #ifndef FilterOperation_h 26 #ifndef FilterOperation_h
27 #define FilterOperation_h 27 #define FilterOperation_h
28 28
29 #include "platform/Length.h" 29 #include "platform/Length.h"
30 #include "platform/PlatformExport.h" 30 #include "platform/PlatformExport.h"
31 #include "platform/graphics/Color.h" 31 #include "platform/graphics/Color.h"
32 #include "platform/graphics/filters/Filter.h" 32 #include "platform/graphics/filters/Filter.h"
33 #include "platform/graphics/filters/ReferenceFilter.h" 33 #include "platform/graphics/filters/ReferenceFilter.h"
34 #include "platform/heap/Handle.h"
34 #include "wtf/OwnPtr.h" 35 #include "wtf/OwnPtr.h"
35 #include "wtf/PassOwnPtr.h" 36 #include "wtf/PassOwnPtr.h"
36 #include "wtf/RefCounted.h" 37 #include "wtf/RefCounted.h"
37 #include "wtf/text/WTFString.h" 38 #include "wtf/text/WTFString.h"
38 39
39 namespace blink { 40 namespace blink {
40 41
41 // CSS Filters 42 // CSS Filters
42 43
43 class PLATFORM_EXPORT FilterOperation : public RefCounted<FilterOperation> { 44 class PLATFORM_EXPORT FilterOperation : public RefCountedWillBeGarbageCollectedF inalized<FilterOperation> {
44 public: 45 public:
45 enum OperationType { 46 enum OperationType {
46 REFERENCE, // url(#somefilter) 47 REFERENCE, // url(#somefilter)
47 GRAYSCALE, 48 GRAYSCALE,
48 SEPIA, 49 SEPIA,
49 SATURATE, 50 SATURATE,
50 HUE_ROTATE, 51 HUE_ROTATE,
51 INVERT, 52 INVERT,
52 OPACITY, 53 OPACITY,
53 BRIGHTNESS, 54 BRIGHTNESS,
(...skipping 20 matching lines...) Expand all
74 case REFERENCE: 75 case REFERENCE:
75 return false; 76 return false;
76 case NONE: 77 case NONE:
77 break; 78 break;
78 } 79 }
79 ASSERT_NOT_REACHED(); 80 ASSERT_NOT_REACHED();
80 return false; 81 return false;
81 } 82 }
82 83
83 virtual ~FilterOperation() { } 84 virtual ~FilterOperation() { }
85 virtual void trace(Visitor*) { }
84 86
85 static PassRefPtr<FilterOperation> blend(const FilterOperation* from, const FilterOperation* to, double progress); 87 static PassRefPtrWillBeRawPtr<FilterOperation> blend(const FilterOperation* from, const FilterOperation* to, double progress);
86 virtual bool operator==(const FilterOperation&) const = 0; 88 virtual bool operator==(const FilterOperation&) const = 0;
87 bool operator!=(const FilterOperation& o) const { return !(*this == o); } 89 bool operator!=(const FilterOperation& o) const { return !(*this == o); }
88 90
89 OperationType type() const { return m_type; } 91 OperationType type() const { return m_type; }
90 virtual bool isSameType(const FilterOperation& o) const { return o.type() == m_type; } 92 virtual bool isSameType(const FilterOperation& o) const { return o.type() == m_type; }
91 93
92 // True if the alpha channel of any pixel can change under this operation. 94 // True if the alpha channel of any pixel can change under this operation.
93 virtual bool affectsOpacity() const { return false; } 95 virtual bool affectsOpacity() const { return false; }
94 // True if the the value of one pixel can affect the value of another pixel under this operation, such as blur. 96 // True if the the value of one pixel can affect the value of another pixel under this operation, such as blur.
95 virtual bool movesPixels() const { return false; } 97 virtual bool movesPixels() const { return false; }
96 98
97 protected: 99 protected:
98 FilterOperation(OperationType type) 100 FilterOperation(OperationType type)
99 : m_type(type) 101 : m_type(type)
100 { 102 {
101 } 103 }
102 104
103 OperationType m_type; 105 OperationType m_type;
104 106
105 private: 107 private:
106 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, doubl e progress) const = 0; 108 virtual PassRefPtrWillBeRawPtr<FilterOperation> blend(const FilterOperation* from, double progress) const = 0;
107 }; 109 };
108 110
109 #define DEFINE_FILTER_OPERATION_TYPE_CASTS(thisType, operationType) \ 111 #define DEFINE_FILTER_OPERATION_TYPE_CASTS(thisType, operationType) \
110 DEFINE_TYPE_CASTS(thisType, FilterOperation, op, op->type() == FilterOperati on::operationType, op.type() == FilterOperation::operationType); 112 DEFINE_TYPE_CASTS(thisType, FilterOperation, op, op->type() == FilterOperati on::operationType, op.type() == FilterOperation::operationType);
111 113
112 class PLATFORM_EXPORT ReferenceFilterOperation : public FilterOperation { 114 class PLATFORM_EXPORT ReferenceFilterOperation : public FilterOperation {
113 public: 115 public:
114 static PassRefPtr<ReferenceFilterOperation> create(const String& url, const AtomicString& fragment) 116 static PassRefPtrWillBeRawPtr<ReferenceFilterOperation> create(const String& url, const AtomicString& fragment)
115 { 117 {
116 return adoptRef(new ReferenceFilterOperation(url, fragment)); 118 return adoptRefWillBeNoop(new ReferenceFilterOperation(url, fragment));
117 } 119 }
118 120
119 virtual bool affectsOpacity() const override { return true; } 121 virtual bool affectsOpacity() const override { return true; }
120 virtual bool movesPixels() const override { return true; } 122 virtual bool movesPixels() const override { return true; }
121 123
122 const String& url() const { return m_url; } 124 const String& url() const { return m_url; }
123 const AtomicString& fragment() const { return m_fragment; } 125 const AtomicString& fragment() const { return m_fragment; }
124 126
125 ReferenceFilter* filter() const { return m_filter.get(); } 127 ReferenceFilter* filter() const { return m_filter.get(); }
126 void setFilter(PassRefPtr<ReferenceFilter> filter) { m_filter = filter; } 128 void setFilter(PassRefPtrWillBeRawPtr<ReferenceFilter> filter) { m_filter = filter; }
129
130 virtual void trace(Visitor*) override;
127 131
128 private: 132 private:
129 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, doubl e progress) const override 133 virtual PassRefPtrWillBeRawPtr<FilterOperation> blend(const FilterOperation* from, double progress) const override
130 { 134 {
131 ASSERT_NOT_REACHED(); 135 ASSERT_NOT_REACHED();
132 return nullptr; 136 return nullptr;
133 } 137 }
134 138
135 virtual bool operator==(const FilterOperation& o) const override 139 virtual bool operator==(const FilterOperation& o) const override
136 { 140 {
137 if (!isSameType(o)) 141 if (!isSameType(o))
138 return false; 142 return false;
139 const ReferenceFilterOperation* other = static_cast<const ReferenceFilte rOperation*>(&o); 143 const ReferenceFilterOperation* other = static_cast<const ReferenceFilte rOperation*>(&o);
140 return m_url == other->m_url; 144 return m_url == other->m_url;
141 } 145 }
142 146
143 ReferenceFilterOperation(const String& url, const AtomicString& fragment) 147 ReferenceFilterOperation(const String& url, const AtomicString& fragment)
144 : FilterOperation(REFERENCE) 148 : FilterOperation(REFERENCE)
145 , m_url(url) 149 , m_url(url)
146 , m_fragment(fragment) 150 , m_fragment(fragment)
147 { 151 {
148 } 152 }
149 153
150 String m_url; 154 String m_url;
151 AtomicString m_fragment; 155 AtomicString m_fragment;
152 RefPtr<ReferenceFilter> m_filter; 156 RefPtrWillBeMember<ReferenceFilter> m_filter;
153 }; 157 };
154 158
155 DEFINE_FILTER_OPERATION_TYPE_CASTS(ReferenceFilterOperation, REFERENCE); 159 DEFINE_FILTER_OPERATION_TYPE_CASTS(ReferenceFilterOperation, REFERENCE);
156 160
157 // GRAYSCALE, SEPIA, SATURATE and HUE_ROTATE are variations on a basic color mat rix effect. 161 // GRAYSCALE, SEPIA, SATURATE and HUE_ROTATE are variations on a basic color mat rix effect.
158 // For HUE_ROTATE, the angle of rotation is stored in m_amount. 162 // For HUE_ROTATE, the angle of rotation is stored in m_amount.
159 class PLATFORM_EXPORT BasicColorMatrixFilterOperation : public FilterOperation { 163 class PLATFORM_EXPORT BasicColorMatrixFilterOperation : public FilterOperation {
160 public: 164 public:
161 static PassRefPtr<BasicColorMatrixFilterOperation> create(double amount, Ope rationType type) 165 static PassRefPtrWillBeRawPtr<BasicColorMatrixFilterOperation> create(double amount, OperationType type)
162 { 166 {
163 return adoptRef(new BasicColorMatrixFilterOperation(amount, type)); 167 return adoptRefWillBeNoop(new BasicColorMatrixFilterOperation(amount, ty pe));
164 } 168 }
165 169
166 double amount() const { return m_amount; } 170 double amount() const { return m_amount; }
167 171
168 172
169 private: 173 private:
170 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, doubl e progress) const override; 174 virtual PassRefPtrWillBeRawPtr<FilterOperation> blend(const FilterOperation* from, double progress) const override;
171 virtual bool operator==(const FilterOperation& o) const override 175 virtual bool operator==(const FilterOperation& o) const override
172 { 176 {
173 if (!isSameType(o)) 177 if (!isSameType(o))
174 return false; 178 return false;
175 const BasicColorMatrixFilterOperation* other = static_cast<const BasicCo lorMatrixFilterOperation*>(&o); 179 const BasicColorMatrixFilterOperation* other = static_cast<const BasicCo lorMatrixFilterOperation*>(&o);
176 return m_amount == other->m_amount; 180 return m_amount == other->m_amount;
177 } 181 }
178 182
179 BasicColorMatrixFilterOperation(double amount, OperationType type) 183 BasicColorMatrixFilterOperation(double amount, OperationType type)
180 : FilterOperation(type) 184 : FilterOperation(type)
181 , m_amount(amount) 185 , m_amount(amount)
182 { 186 {
183 } 187 }
184 188
185 double m_amount; 189 double m_amount;
186 }; 190 };
187 191
188 inline bool isBasicColorMatrixFilterOperation(const FilterOperation& operation) 192 inline bool isBasicColorMatrixFilterOperation(const FilterOperation& operation)
189 { 193 {
190 FilterOperation::OperationType type = operation.type(); 194 FilterOperation::OperationType type = operation.type();
191 return type == FilterOperation::GRAYSCALE || type == FilterOperation::SEPIA || type == FilterOperation::SATURATE || type == FilterOperation::HUE_ROTATE; 195 return type == FilterOperation::GRAYSCALE || type == FilterOperation::SEPIA || type == FilterOperation::SATURATE || type == FilterOperation::HUE_ROTATE;
192 } 196 }
193 197
194 DEFINE_TYPE_CASTS(BasicColorMatrixFilterOperation, FilterOperation, op, isBasicC olorMatrixFilterOperation(*op), isBasicColorMatrixFilterOperation(op)); 198 DEFINE_TYPE_CASTS(BasicColorMatrixFilterOperation, FilterOperation, op, isBasicC olorMatrixFilterOperation(*op), isBasicColorMatrixFilterOperation(op));
195 199
196 // INVERT, BRIGHTNESS, CONTRAST and OPACITY are variations on a basic component transfer effect. 200 // INVERT, BRIGHTNESS, CONTRAST and OPACITY are variations on a basic component transfer effect.
197 class PLATFORM_EXPORT BasicComponentTransferFilterOperation : public FilterOpera tion { 201 class PLATFORM_EXPORT BasicComponentTransferFilterOperation : public FilterOpera tion {
198 public: 202 public:
199 static PassRefPtr<BasicComponentTransferFilterOperation> create(double amoun t, OperationType type) 203 static PassRefPtrWillBeRawPtr<BasicComponentTransferFilterOperation> create( double amount, OperationType type)
200 { 204 {
201 return adoptRef(new BasicComponentTransferFilterOperation(amount, type)) ; 205 return adoptRefWillBeNoop(new BasicComponentTransferFilterOperation(amou nt, type));
202 } 206 }
203 207
204 double amount() const { return m_amount; } 208 double amount() const { return m_amount; }
205 209
206 virtual bool affectsOpacity() const override { return m_type == OPACITY; } 210 virtual bool affectsOpacity() const override { return m_type == OPACITY; }
207 211
208 212
209 private: 213 private:
210 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, doubl e progress) const override; 214 virtual PassRefPtrWillBeRawPtr<FilterOperation> blend(const FilterOperation* from, double progress) const override;
211 virtual bool operator==(const FilterOperation& o) const override 215 virtual bool operator==(const FilterOperation& o) const override
212 { 216 {
213 if (!isSameType(o)) 217 if (!isSameType(o))
214 return false; 218 return false;
215 const BasicComponentTransferFilterOperation* other = static_cast<const B asicComponentTransferFilterOperation*>(&o); 219 const BasicComponentTransferFilterOperation* other = static_cast<const B asicComponentTransferFilterOperation*>(&o);
216 return m_amount == other->m_amount; 220 return m_amount == other->m_amount;
217 } 221 }
218 222
219 BasicComponentTransferFilterOperation(double amount, OperationType type) 223 BasicComponentTransferFilterOperation(double amount, OperationType type)
220 : FilterOperation(type) 224 : FilterOperation(type)
221 , m_amount(amount) 225 , m_amount(amount)
222 { 226 {
223 } 227 }
224 228
225 double m_amount; 229 double m_amount;
226 }; 230 };
227 231
228 inline bool isBasicComponentTransferFilterOperation(const FilterOperation& opera tion) 232 inline bool isBasicComponentTransferFilterOperation(const FilterOperation& opera tion)
229 { 233 {
230 FilterOperation::OperationType type = operation.type(); 234 FilterOperation::OperationType type = operation.type();
231 return type == FilterOperation::INVERT || type == FilterOperation::OPACITY | | type == FilterOperation::BRIGHTNESS || type == FilterOperation::CONTRAST; 235 return type == FilterOperation::INVERT || type == FilterOperation::OPACITY | | type == FilterOperation::BRIGHTNESS || type == FilterOperation::CONTRAST;
232 } 236 }
233 237
234 DEFINE_TYPE_CASTS(BasicComponentTransferFilterOperation, FilterOperation, op, is BasicComponentTransferFilterOperation(*op), isBasicComponentTransferFilterOperat ion(op)); 238 DEFINE_TYPE_CASTS(BasicComponentTransferFilterOperation, FilterOperation, op, is BasicComponentTransferFilterOperation(*op), isBasicComponentTransferFilterOperat ion(op));
235 239
236 class PLATFORM_EXPORT BlurFilterOperation : public FilterOperation { 240 class PLATFORM_EXPORT BlurFilterOperation : public FilterOperation {
237 public: 241 public:
238 static PassRefPtr<BlurFilterOperation> create(const Length& stdDeviation) 242 static PassRefPtrWillBeRawPtr<BlurFilterOperation> create(const Length& stdD eviation)
239 { 243 {
240 return adoptRef(new BlurFilterOperation(stdDeviation)); 244 return adoptRefWillBeNoop(new BlurFilterOperation(stdDeviation));
241 } 245 }
242 246
243 const Length& stdDeviation() const { return m_stdDeviation; } 247 const Length& stdDeviation() const { return m_stdDeviation; }
244 248
245 virtual bool affectsOpacity() const override { return true; } 249 virtual bool affectsOpacity() const override { return true; }
246 virtual bool movesPixels() const override { return true; } 250 virtual bool movesPixels() const override { return true; }
247 251
248 252
249 private: 253 private:
250 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, doubl e progress) const override; 254 virtual PassRefPtrWillBeRawPtr<FilterOperation> blend(const FilterOperation* from, double progress) const override;
251 virtual bool operator==(const FilterOperation& o) const override 255 virtual bool operator==(const FilterOperation& o) const override
252 { 256 {
253 if (!isSameType(o)) 257 if (!isSameType(o))
254 return false; 258 return false;
255 const BlurFilterOperation* other = static_cast<const BlurFilterOperation *>(&o); 259 const BlurFilterOperation* other = static_cast<const BlurFilterOperation *>(&o);
256 return m_stdDeviation == other->m_stdDeviation; 260 return m_stdDeviation == other->m_stdDeviation;
257 } 261 }
258 262
259 BlurFilterOperation(const Length& stdDeviation) 263 BlurFilterOperation(const Length& stdDeviation)
260 : FilterOperation(BLUR) 264 : FilterOperation(BLUR)
261 , m_stdDeviation(stdDeviation) 265 , m_stdDeviation(stdDeviation)
262 { 266 {
263 } 267 }
264 268
265 Length m_stdDeviation; 269 Length m_stdDeviation;
266 }; 270 };
267 271
268 DEFINE_FILTER_OPERATION_TYPE_CASTS(BlurFilterOperation, BLUR); 272 DEFINE_FILTER_OPERATION_TYPE_CASTS(BlurFilterOperation, BLUR);
269 273
270 class PLATFORM_EXPORT DropShadowFilterOperation : public FilterOperation { 274 class PLATFORM_EXPORT DropShadowFilterOperation : public FilterOperation {
271 public: 275 public:
272 static PassRefPtr<DropShadowFilterOperation> create(const IntPoint& location , int stdDeviation, Color color) 276 static PassRefPtrWillBeRawPtr<DropShadowFilterOperation> create(const IntPoi nt& location, int stdDeviation, Color color)
273 { 277 {
274 return adoptRef(new DropShadowFilterOperation(location, stdDeviation, co lor)); 278 return adoptRefWillBeNoop(new DropShadowFilterOperation(location, stdDev iation, color));
275 } 279 }
276 280
277 int x() const { return m_location.x(); } 281 int x() const { return m_location.x(); }
278 int y() const { return m_location.y(); } 282 int y() const { return m_location.y(); }
279 IntPoint location() const { return m_location; } 283 IntPoint location() const { return m_location; }
280 int stdDeviation() const { return m_stdDeviation; } 284 int stdDeviation() const { return m_stdDeviation; }
281 Color color() const { return m_color; } 285 Color color() const { return m_color; }
282 286
283 virtual bool affectsOpacity() const override { return true; } 287 virtual bool affectsOpacity() const override { return true; }
284 virtual bool movesPixels() const override { return true; } 288 virtual bool movesPixels() const override { return true; }
285 289
286 290
287 private: 291 private:
288 virtual PassRefPtr<FilterOperation> blend(const FilterOperation* from, doubl e progress) const override; 292 virtual PassRefPtrWillBeRawPtr<FilterOperation> blend(const FilterOperation* from, double progress) const override;
289 virtual bool operator==(const FilterOperation& o) const override 293 virtual bool operator==(const FilterOperation& o) const override
290 { 294 {
291 if (!isSameType(o)) 295 if (!isSameType(o))
292 return false; 296 return false;
293 const DropShadowFilterOperation* other = static_cast<const DropShadowFil terOperation*>(&o); 297 const DropShadowFilterOperation* other = static_cast<const DropShadowFil terOperation*>(&o);
294 return m_location == other->m_location && m_stdDeviation == other->m_std Deviation && m_color == other->m_color; 298 return m_location == other->m_location && m_stdDeviation == other->m_std Deviation && m_color == other->m_color;
295 } 299 }
296 300
297 DropShadowFilterOperation(const IntPoint& location, int stdDeviation, Color color) 301 DropShadowFilterOperation(const IntPoint& location, int stdDeviation, Color color)
298 : FilterOperation(DROP_SHADOW) 302 : FilterOperation(DROP_SHADOW)
299 , m_location(location) 303 , m_location(location)
300 , m_stdDeviation(stdDeviation) 304 , m_stdDeviation(stdDeviation)
301 , m_color(color) 305 , m_color(color)
302 { 306 {
303 } 307 }
304 308
305 IntPoint m_location; // FIXME: should location be in Lengths? 309 IntPoint m_location; // FIXME: should location be in Lengths?
306 int m_stdDeviation; 310 int m_stdDeviation;
307 Color m_color; 311 Color m_color;
308 }; 312 };
309 313
310 DEFINE_FILTER_OPERATION_TYPE_CASTS(DropShadowFilterOperation, DROP_SHADOW); 314 DEFINE_FILTER_OPERATION_TYPE_CASTS(DropShadowFilterOperation, DROP_SHADOW);
311 315
312 } // namespace blink 316 } // namespace blink
313 317
314 318
315 #endif // FilterOperation_h 319 #endif // FilterOperation_h
OLDNEW
« no previous file with comments | « Source/platform/graphics/filters/FilterEffect.cpp ('k') | Source/platform/graphics/filters/FilterOperation.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698