| 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; | |
| 125 }; | 119 }; |
| 126 | 120 |
| 127 class DeviceProxy : public Proxy { | 121 class DeviceProxy : public Proxy { |
| 128 public: | 122 public: |
| 129 DeviceProxy(SkBaseDevice* device) : fDevice(device) {} | 123 DeviceProxy(SkBaseDevice* device) : fDevice(device) {} |
| 130 | 124 |
| 131 SkBaseDevice* createDevice(int width, int height, | 125 SkBaseDevice* createDevice(int width, int height, |
| 132 TileUsage usage = kNever_TileUsage) override; | 126 TileUsage usage = kNever_TileUsage) override; |
| 133 | 127 |
| 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 | |
| 139 private: | 128 private: |
| 140 SkBaseDevice* fDevice; | 129 SkBaseDevice* fDevice; |
| 141 }; | 130 }; |
| 142 | 131 |
| 143 /** | 132 /** |
| 144 * Request a new (result) image to be created from the src image. | 133 * Request a new (result) image to be created from the src image. |
| 145 * | 134 * |
| 146 * The context contains the environment in which the filter is occurring. | 135 * The context contains the environment in which the filter is occurring. |
| 147 * It includes the clip bounds, CTM and cache. | 136 * It includes the clip bounds, CTM and cache. |
| 148 * | 137 * |
| (...skipping 19 matching lines...) Expand all Loading... |
| 168 * kReverse_MapDirection is used to determine which rect of the source | 157 * kReverse_MapDirection is used to determine which rect of the source |
| 169 * image would be required to fill the given rect (typically, clip bounds). | 158 * image would be required to fill the given rect (typically, clip bounds). |
| 170 * Used for clipping and temp-buffer allocations, so the result need not | 159 * Used for clipping and temp-buffer allocations, so the result need not |
| 171 * be exact, but should never be smaller than the real answer. The default | 160 * be exact, but should never be smaller than the real answer. The default |
| 172 * implementation recursively unions all input bounds, or returns the | 161 * implementation recursively unions all input bounds, or returns the |
| 173 * source rect if no inputs. | 162 * source rect if no inputs. |
| 174 */ | 163 */ |
| 175 SkIRect filterBounds(const SkIRect& src, const SkMatrix& ctm, | 164 SkIRect filterBounds(const SkIRect& src, const SkMatrix& ctm, |
| 176 MapDirection = kReverse_MapDirection) const; | 165 MapDirection = kReverse_MapDirection) const; |
| 177 | 166 |
| 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 | |
| 203 #if SK_SUPPORT_GPU | 167 #if SK_SUPPORT_GPU |
| 204 static sk_sp<SkSpecialImage> DrawWithFP(GrContext* context, | 168 static sk_sp<SkSpecialImage> DrawWithFP(GrContext* context, |
| 205 sk_sp<GrFragmentProcessor> fp, | 169 sk_sp<GrFragmentProcessor> fp, |
| 206 const SkIRect& bounds, | 170 const SkIRect& bounds, |
| 207 SkImageFilter::Proxy* proxy); | 171 SkImageFilter::Proxy* proxy); |
| 208 #endif | 172 #endif |
| 209 | 173 |
| 210 /** | 174 /** |
| 211 * Returns whether this image filter is a color filter and puts the color f
ilter into the | 175 * Returns whether this image filter is a color filter and puts the color f
ilter into the |
| 212 * "filterPtr" parameter if it can. Does nothing otherwise. | 176 * "filterPtr" parameter if it can. Does nothing otherwise. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 return MakeMatrixFilter(matrix, filterQuality, sk_ref_sp<SkImageFilter>(
input)).release(); | 255 return MakeMatrixFilter(matrix, filterQuality, sk_ref_sp<SkImageFilter>(
input)).release(); |
| 292 } | 256 } |
| 293 #endif | 257 #endif |
| 294 | 258 |
| 295 | 259 |
| 296 sk_sp<SkSpecialImage> filterInput(int index, | 260 sk_sp<SkSpecialImage> filterInput(int index, |
| 297 SkSpecialImage* src, | 261 SkSpecialImage* src, |
| 298 const Context&, | 262 const Context&, |
| 299 SkIPoint* offset) const; | 263 SkIPoint* offset) const; |
| 300 | 264 |
| 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 | |
| 313 SK_TO_STRING_PUREVIRT() | 265 SK_TO_STRING_PUREVIRT() |
| 314 SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter) | 266 SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter) |
| 315 | 267 |
| 316 protected: | 268 protected: |
| 317 class Common { | 269 class Common { |
| 318 public: | 270 public: |
| 319 /** | 271 /** |
| 320 * Attempt to unflatten the cropRect and the expected number of input f
ilters. | 272 * Attempt to unflatten the cropRect and the expected number of input f
ilters. |
| 321 * If any number of input filters is valid, pass -1. | 273 * If any number of input filters is valid, pass -1. |
| 322 * If this fails (i.e. corrupt buffer or contents) then return false an
d common will | 274 * 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... |
| 433 | 385 |
| 434 /** A variant of the above call which takes the original source bitmap and | 386 /** A variant of the above call which takes the original source bitmap and |
| 435 * source offset. If the resulting crop rect is not entirely contained by | 387 * source offset. If the resulting crop rect is not entirely contained by |
| 436 * the source bitmap's bounds, it creates a new bitmap in "result" and | 388 * the source bitmap's bounds, it creates a new bitmap in "result" and |
| 437 * pads the edges with transparent black. In that case, the srcOffset is | 389 * pads the edges with transparent black. In that case, the srcOffset is |
| 438 * modified to be the same as the bounds, since no further adjustment is | 390 * modified to be the same as the bounds, since no further adjustment is |
| 439 * needed by the caller. This version should only be used by filters | 391 * needed by the caller. This version should only be used by filters |
| 440 * which are not capable of processing a smaller source bitmap into a | 392 * which are not capable of processing a smaller source bitmap into a |
| 441 * larger destination. | 393 * larger destination. |
| 442 */ | 394 */ |
| 443 bool applyCropRectDeprecated(const Context&, Proxy* proxy, const SkBitmap& s
rc, | |
| 444 SkIPoint* srcOffset, SkIRect* bounds, SkBitmap*
result) const; | |
| 445 | |
| 446 sk_sp<SkSpecialImage> applyCropRect(const Context&, SkSpecialImage* src, SkI
Point* srcOffset, | 395 sk_sp<SkSpecialImage> applyCropRect(const Context&, SkSpecialImage* src, SkI
Point* srcOffset, |
| 447 SkIRect* bounds) const; | 396 SkIRect* bounds) const; |
| 448 | 397 |
| 449 /** | 398 /** |
| 450 * Creates a modified Context for use when recursing up the image filter DA
G. | 399 * Creates a modified Context for use when recursing up the image filter DA
G. |
| 451 * The clip bounds are adjusted to accommodate any margins that this | 400 * The clip bounds are adjusted to accommodate any margins that this |
| 452 * filter requires by calling this node's | 401 * filter requires by calling this node's |
| 453 * onFilterNodeBounds(..., kReverse_MapDirection). | 402 * onFilterNodeBounds(..., kReverse_MapDirection). |
| 454 */ | 403 */ |
| 455 Context mapContext(const Context& ctx) const; | 404 Context mapContext(const Context& ctx) const; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 480 */ | 429 */ |
| 481 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ | 430 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ |
| 482 Common localVar; \ | 431 Common localVar; \ |
| 483 do { \ | 432 do { \ |
| 484 if (!localVar.unflatten(buffer, expectedCount)) { \ | 433 if (!localVar.unflatten(buffer, expectedCount)) { \ |
| 485 return NULL; \ | 434 return NULL; \ |
| 486 } \ | 435 } \ |
| 487 } while (0) | 436 } while (0) |
| 488 | 437 |
| 489 #endif | 438 #endif |
| OLD | NEW |