OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkImageFilter_DEFINED | 8 #ifndef SkImageFilter_DEFINED |
9 #define SkImageFilter_DEFINED | 9 #define SkImageFilter_DEFINED |
10 | 10 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 kPossible_TileUsage, //!< the created device may be drawn tiled | 109 kPossible_TileUsage, //!< the created device may be drawn tiled |
110 kNever_TileUsage, //!< the created device will never be drawn tile
d | 110 kNever_TileUsage, //!< the created device will never be drawn tile
d |
111 }; | 111 }; |
112 | 112 |
113 class Proxy { | 113 class Proxy { |
114 public: | 114 public: |
115 virtual ~Proxy() {} | 115 virtual ~Proxy() {} |
116 | 116 |
117 virtual SkBaseDevice* createDevice(int width, int height, | 117 virtual SkBaseDevice* createDevice(int width, int height, |
118 TileUsage usage = kNever_TileUsage) =
0; | 118 TileUsage usage = kNever_TileUsage) =
0; |
| 119 |
| 120 // Returns true if the proxy handled the filter itself. If this returns |
| 121 // false then the filter's code will be called. |
| 122 virtual bool filterImage(const SkImageFilter*, const SkBitmap& src, |
| 123 const SkImageFilter::Context&, |
| 124 SkBitmap* result, SkIPoint* offset) = 0; |
119 }; | 125 }; |
120 | 126 |
121 class DeviceProxy : public Proxy { | 127 class DeviceProxy : public Proxy { |
122 public: | 128 public: |
123 DeviceProxy(SkBaseDevice* device) : fDevice(device) {} | 129 DeviceProxy(SkBaseDevice* device) : fDevice(device) {} |
124 | 130 |
125 SkBaseDevice* createDevice(int width, int height, | 131 SkBaseDevice* createDevice(int width, int height, |
126 TileUsage usage = kNever_TileUsage) override; | 132 TileUsage usage = kNever_TileUsage) override; |
127 | 133 |
| 134 // Returns true if the proxy handled the filter itself. If this returns |
| 135 // false then the filter's code will be called. |
| 136 bool filterImage(const SkImageFilter*, const SkBitmap& src, const SkImag
eFilter::Context&, |
| 137 SkBitmap* result, SkIPoint* offset) override; |
| 138 |
128 private: | 139 private: |
129 SkBaseDevice* fDevice; | 140 SkBaseDevice* fDevice; |
130 }; | 141 }; |
131 | 142 |
132 /** | 143 /** |
133 * Request a new (result) image to be created from the src image. | 144 * Request a new (result) image to be created from the src image. |
134 * | 145 * |
135 * The context contains the environment in which the filter is occurring. | 146 * The context contains the environment in which the filter is occurring. |
136 * It includes the clip bounds, CTM and cache. | 147 * It includes the clip bounds, CTM and cache. |
137 * | 148 * |
(...skipping 19 matching lines...) Expand all Loading... |
157 * kReverse_MapDirection is used to determine which rect of the source | 168 * kReverse_MapDirection is used to determine which rect of the source |
158 * image would be required to fill the given rect (typically, clip bounds). | 169 * image would be required to fill the given rect (typically, clip bounds). |
159 * Used for clipping and temp-buffer allocations, so the result need not | 170 * Used for clipping and temp-buffer allocations, so the result need not |
160 * be exact, but should never be smaller than the real answer. The default | 171 * be exact, but should never be smaller than the real answer. The default |
161 * implementation recursively unions all input bounds, or returns the | 172 * implementation recursively unions all input bounds, or returns the |
162 * source rect if no inputs. | 173 * source rect if no inputs. |
163 */ | 174 */ |
164 SkIRect filterBounds(const SkIRect& src, const SkMatrix& ctm, | 175 SkIRect filterBounds(const SkIRect& src, const SkMatrix& ctm, |
165 MapDirection = kReverse_MapDirection) const; | 176 MapDirection = kReverse_MapDirection) const; |
166 | 177 |
| 178 /** |
| 179 * Returns true if the filter can be processed on the GPU. This is most |
| 180 * often used for multi-pass effects, where intermediate results must be |
| 181 * rendered to textures. For single-pass effects, use asFragmentProcessor(
). |
| 182 * The default implementation returns asFragmentProcessor(NULL, NULL, SkMat
rix::I(), |
| 183 * SkIRect()). |
| 184 */ |
| 185 virtual bool canFilterImageGPU() const { return false; } |
| 186 |
| 187 /** |
| 188 * Process this image filter on the GPU. This is most often used for |
| 189 * multi-pass effects, where intermediate results must be rendered to |
| 190 * textures. For single-pass effects, use asFragmentProcessor(). src is t
he |
| 191 * source image for processing, as a texture-backed bitmap. result is |
| 192 * the destination bitmap, which should contain a texture-backed pixelref |
| 193 * on success. offset is the amount to translate the resulting image |
| 194 * relative to the src when it is drawn. The default implementation does |
| 195 * single-pass processing using asFragmentProcessor(). |
| 196 */ |
| 197 virtual bool filterImageGPUDeprecated(Proxy*, const SkBitmap&, const Context
&, |
| 198 SkBitmap*, SkIPoint*) const { |
| 199 SkASSERT(false); |
| 200 return false; |
| 201 } |
| 202 |
167 #if SK_SUPPORT_GPU | 203 #if SK_SUPPORT_GPU |
168 static sk_sp<SkSpecialImage> DrawWithFP(GrContext* context, | 204 static sk_sp<SkSpecialImage> DrawWithFP(GrContext* context, |
169 sk_sp<GrFragmentProcessor> fp, | 205 sk_sp<GrFragmentProcessor> fp, |
170 const SkIRect& bounds, | 206 const SkIRect& bounds, |
171 SkImageFilter::Proxy* proxy); | 207 SkImageFilter::Proxy* proxy); |
172 #endif | 208 #endif |
173 | 209 |
174 /** | 210 /** |
175 * Returns whether this image filter is a color filter and puts the color f
ilter into the | 211 * Returns whether this image filter is a color filter and puts the color f
ilter into the |
176 * "filterPtr" parameter if it can. Does nothing otherwise. | 212 * "filterPtr" parameter if it can. Does nothing otherwise. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 return MakeMatrixFilter(matrix, filterQuality, sk_ref_sp<SkImageFilter>(
input)).release(); | 291 return MakeMatrixFilter(matrix, filterQuality, sk_ref_sp<SkImageFilter>(
input)).release(); |
256 } | 292 } |
257 #endif | 293 #endif |
258 | 294 |
259 | 295 |
260 sk_sp<SkSpecialImage> filterInput(int index, | 296 sk_sp<SkSpecialImage> filterInput(int index, |
261 SkSpecialImage* src, | 297 SkSpecialImage* src, |
262 const Context&, | 298 const Context&, |
263 SkIPoint* offset) const; | 299 SkIPoint* offset) const; |
264 | 300 |
| 301 #if SK_SUPPORT_GPU |
| 302 // Helper function which invokes GPU filter processing on the |
| 303 // input at the specified "index". If the input is null, it leaves |
| 304 // "result" and "offset" untouched, and returns true. If the input |
| 305 // has a GPU implementation, it will be invoked directly. |
| 306 // Otherwise, the filter will be processed in software and |
| 307 // uploaded to the GPU. |
| 308 bool filterInputGPUDeprecated(int index, SkImageFilter::Proxy* proxy, |
| 309 const SkBitmap& src, const Context&, |
| 310 SkBitmap* result, SkIPoint* offset) const; |
| 311 #endif |
| 312 |
265 SK_TO_STRING_PUREVIRT() | 313 SK_TO_STRING_PUREVIRT() |
266 SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter) | 314 SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter) |
267 | 315 |
268 protected: | 316 protected: |
269 class Common { | 317 class Common { |
270 public: | 318 public: |
271 /** | 319 /** |
272 * Attempt to unflatten the cropRect and the expected number of input f
ilters. | 320 * Attempt to unflatten the cropRect and the expected number of input f
ilters. |
273 * If any number of input filters is valid, pass -1. | 321 * If any number of input filters is valid, pass -1. |
274 * If this fails (i.e. corrupt buffer or contents) then return false an
d common will | 322 * If this fails (i.e. corrupt buffer or contents) then return false an
d common will |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 433 |
386 /** A variant of the above call which takes the original source bitmap and | 434 /** A variant of the above call which takes the original source bitmap and |
387 * source offset. If the resulting crop rect is not entirely contained by | 435 * source offset. If the resulting crop rect is not entirely contained by |
388 * the source bitmap's bounds, it creates a new bitmap in "result" and | 436 * the source bitmap's bounds, it creates a new bitmap in "result" and |
389 * pads the edges with transparent black. In that case, the srcOffset is | 437 * pads the edges with transparent black. In that case, the srcOffset is |
390 * modified to be the same as the bounds, since no further adjustment is | 438 * modified to be the same as the bounds, since no further adjustment is |
391 * needed by the caller. This version should only be used by filters | 439 * needed by the caller. This version should only be used by filters |
392 * which are not capable of processing a smaller source bitmap into a | 440 * which are not capable of processing a smaller source bitmap into a |
393 * larger destination. | 441 * larger destination. |
394 */ | 442 */ |
| 443 bool applyCropRectDeprecated(const Context&, Proxy* proxy, const SkBitmap& s
rc, |
| 444 SkIPoint* srcOffset, SkIRect* bounds, SkBitmap*
result) const; |
| 445 |
395 sk_sp<SkSpecialImage> applyCropRect(const Context&, SkSpecialImage* src, SkI
Point* srcOffset, | 446 sk_sp<SkSpecialImage> applyCropRect(const Context&, SkSpecialImage* src, SkI
Point* srcOffset, |
396 SkIRect* bounds) const; | 447 SkIRect* bounds) const; |
397 | 448 |
398 /** | 449 /** |
399 * Creates a modified Context for use when recursing up the image filter DA
G. | 450 * Creates a modified Context for use when recursing up the image filter DA
G. |
400 * The clip bounds are adjusted to accommodate any margins that this | 451 * The clip bounds are adjusted to accommodate any margins that this |
401 * filter requires by calling this node's | 452 * filter requires by calling this node's |
402 * onFilterNodeBounds(..., kReverse_MapDirection). | 453 * onFilterNodeBounds(..., kReverse_MapDirection). |
403 */ | 454 */ |
404 Context mapContext(const Context& ctx) const; | 455 Context mapContext(const Context& ctx) const; |
(...skipping 24 matching lines...) Expand all Loading... |
429 */ | 480 */ |
430 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ | 481 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ |
431 Common localVar; \ | 482 Common localVar; \ |
432 do { \ | 483 do { \ |
433 if (!localVar.unflatten(buffer, expectedCount)) { \ | 484 if (!localVar.unflatten(buffer, expectedCount)) { \ |
434 return NULL; \ | 485 return NULL; \ |
435 } \ | 486 } \ |
436 } while (0) | 487 } while (0) |
437 | 488 |
438 #endif | 489 #endif |
OLD | NEW |