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 |
11 #include "SkFlattenable.h" | 11 #include "SkFlattenable.h" |
12 #include "SkMatrix.h" | 12 #include "SkMatrix.h" |
13 #include "SkRect.h" | 13 #include "SkRect.h" |
14 #include "SkTemplates.h" | 14 #include "SkTemplates.h" |
15 | 15 |
16 class SkBitmap; | 16 class SkBitmap; |
17 class SkColorFilter; | 17 class SkColorFilter; |
18 class SkBaseDevice; | 18 class SkBaseDevice; |
19 struct SkIPoint; | 19 struct SkIPoint; |
20 class GrEffect; | 20 class GrFragmentProcessor; |
21 class GrTexture; | 21 class GrTexture; |
22 | 22 |
23 /** | 23 /** |
24 * Base class for image filters. If one is installed in the paint, then | 24 * Base class for image filters. If one is installed in the paint, then |
25 * all drawing occurs as usual, but it is as if the drawing happened into an | 25 * all drawing occurs as usual, but it is as if the drawing happened into an |
26 * offscreen (before the xfermode is applied). This offscreen bitmap will | 26 * offscreen (before the xfermode is applied). This offscreen bitmap will |
27 * then be handed to the imagefilter, who in turn creates a new bitmap which | 27 * then be handed to the imagefilter, who in turn creates a new bitmap which |
28 * is what will finally be drawn to the device (using the original xfermode). | 28 * is what will finally be drawn to the device (using the original xfermode). |
29 */ | 29 */ |
30 class SK_API SkImageFilter : public SkFlattenable { | 30 class SK_API SkImageFilter : public SkFlattenable { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 /** | 108 /** |
109 * Given the src bounds of an image, this returns the bounds of the result | 109 * Given the src bounds of an image, this returns the bounds of the result |
110 * image after the filter has been applied. | 110 * image after the filter has been applied. |
111 */ | 111 */ |
112 bool filterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst) con
st; | 112 bool filterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst) con
st; |
113 | 113 |
114 /** | 114 /** |
115 * Returns true if the filter can be processed on the GPU. This is most | 115 * Returns true if the filter can be processed on the GPU. This is most |
116 * often used for multi-pass effects, where intermediate results must be | 116 * often used for multi-pass effects, where intermediate results must be |
117 * rendered to textures. For single-pass effects, use asNewEffect(). | 117 * rendered to textures. For single-pass effects, use asFragmentProcessor(
). |
118 * The default implementation returns asNewEffect(NULL, NULL, SkMatrix::I()
, | 118 * The default implementation returns asFragmentProcessor(NULL, NULL, SkMat
rix::I(), |
119 * SkIRect()). | 119 * SkIRect()). |
120 */ | 120 */ |
121 virtual bool canFilterImageGPU() const; | 121 virtual bool canFilterImageGPU() const; |
122 | 122 |
123 /** | 123 /** |
124 * Process this image filter on the GPU. This is most often used for | 124 * Process this image filter on the GPU. This is most often used for |
125 * multi-pass effects, where intermediate results must be rendered to | 125 * multi-pass effects, where intermediate results must be rendered to |
126 * textures. For single-pass effects, use asNewEffect(). src is the | 126 * textures. For single-pass effects, use asFragmentProcessor(). src is t
he |
127 * source image for processing, as a texture-backed bitmap. result is | 127 * source image for processing, as a texture-backed bitmap. result is |
128 * the destination bitmap, which should contain a texture-backed pixelref | 128 * the destination bitmap, which should contain a texture-backed pixelref |
129 * on success. offset is the amount to translate the resulting image | 129 * on success. offset is the amount to translate the resulting image |
130 * relative to the src when it is drawn. The default implementation does | 130 * relative to the src when it is drawn. The default implementation does |
131 * single-pass processing using asNewEffect(). | 131 * single-pass processing using asFragmentProcessor(). |
132 */ | 132 */ |
133 virtual bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&, | 133 virtual bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&, |
134 SkBitmap* result, SkIPoint* offset) const; | 134 SkBitmap* result, SkIPoint* offset) const; |
135 | 135 |
136 /** | 136 /** |
137 * Returns whether this image filter is a color filter and puts the color f
ilter into the | 137 * Returns whether this image filter is a color filter and puts the color f
ilter into the |
138 * "filterPtr" parameter if it can. Does nothing otherwise. | 138 * "filterPtr" parameter if it can. Does nothing otherwise. |
139 * If this returns false, then the filterPtr is unchanged. | 139 * If this returns false, then the filterPtr is unchanged. |
140 * If this returns true, then if filterPtr is not null, it must be set to a
ref'd colorfitler | 140 * If this returns true, then if filterPtr is not null, it must be set to a
ref'd colorfitler |
141 * (i.e. it may not be set to NULL). | 141 * (i.e. it may not be set to NULL). |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 * case, the srcOffset is modified to be the same as the bounds, since no | 283 * case, the srcOffset is modified to be the same as the bounds, since no |
284 * further adjustment is needed by the caller. This version should only | 284 * further adjustment is needed by the caller. This version should only |
285 * be used by filters which are not capable of processing a smaller | 285 * be used by filters which are not capable of processing a smaller |
286 * source bitmap into a larger destination. | 286 * source bitmap into a larger destination. |
287 */ | 287 */ |
288 bool applyCropRect(const Context&, Proxy* proxy, const SkBitmap& src, SkIPoi
nt* srcOffset, | 288 bool applyCropRect(const Context&, Proxy* proxy, const SkBitmap& src, SkIPoi
nt* srcOffset, |
289 SkIRect* bounds, SkBitmap* result) const; | 289 SkIRect* bounds, SkBitmap* result) const; |
290 | 290 |
291 /** | 291 /** |
292 * Returns true if the filter can be expressed a single-pass | 292 * Returns true if the filter can be expressed a single-pass |
293 * GrEffect, used to process this filter on the GPU, or false if | 293 * GrProcessor, used to process this filter on the GPU, or false if |
294 * not. | 294 * not. |
295 * | 295 * |
296 * If effect is non-NULL, a new GrEffect instance is stored | 296 * If effect is non-NULL, a new GrProcessor instance is stored |
297 * in it. The caller assumes ownership of the stage, and it is up to the | 297 * in it. The caller assumes ownership of the stage, and it is up to the |
298 * caller to unref it. | 298 * caller to unref it. |
299 * | 299 * |
300 * The effect can assume its vertexCoords space maps 1-to-1 with texels | 300 * The effect can assume its vertexCoords space maps 1-to-1 with texels |
301 * in the texture. "matrix" is a transformation to apply to filter | 301 * in the texture. "matrix" is a transformation to apply to filter |
302 * parameters before they are used in the effect. Note that this function | 302 * parameters before they are used in the effect. Note that this function |
303 * will be called with (NULL, NULL, SkMatrix::I()) to query for support, | 303 * will be called with (NULL, NULL, SkMatrix::I()) to query for support, |
304 * so returning "true" indicates support for all possible matrices. | 304 * so returning "true" indicates support for all possible matrices. |
305 */ | 305 */ |
306 virtual bool asNewEffect(GrEffect** effect, | 306 virtual bool asFragmentProcessor(GrFragmentProcessor**, GrTexture*, const Sk
Matrix&, |
307 GrTexture*, | 307 const SkIRect& bounds) const; |
308 const SkMatrix& matrix, | |
309 const SkIRect& bounds) const; | |
310 | 308 |
311 private: | 309 private: |
312 bool usesSrcInput() const { return fUsesSrcInput; } | 310 bool usesSrcInput() const { return fUsesSrcInput; } |
313 | 311 |
314 typedef SkFlattenable INHERITED; | 312 typedef SkFlattenable INHERITED; |
315 int fInputCount; | 313 int fInputCount; |
316 SkImageFilter** fInputs; | 314 SkImageFilter** fInputs; |
317 bool fUsesSrcInput; | 315 bool fUsesSrcInput; |
318 CropRect fCropRect; | 316 CropRect fCropRect; |
319 uint32_t fUniqueID; // Globally unique | 317 uint32_t fUniqueID; // Globally unique |
320 }; | 318 }; |
321 | 319 |
322 /** | 320 /** |
323 * Helper to unflatten the common data, and return NULL if we fail. | 321 * Helper to unflatten the common data, and return NULL if we fail. |
324 */ | 322 */ |
325 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ | 323 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ |
326 Common localVar; \ | 324 Common localVar; \ |
327 do { \ | 325 do { \ |
328 if (!localVar.unflatten(buffer, expectedCount)) { \ | 326 if (!localVar.unflatten(buffer, expectedCount)) { \ |
329 return NULL; \ | 327 return NULL; \ |
330 } \ | 328 } \ |
331 } while (0) | 329 } while (0) |
332 | 330 |
333 #endif | 331 #endif |
OLD | NEW |