| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 const SkRect& rect() const { return fRect; } | 79 const SkRect& rect() const { return fRect; } |
| 80 #ifndef SK_IGNORE_TO_STRING | 80 #ifndef SK_IGNORE_TO_STRING |
| 81 void toString(SkString* str) const; | 81 void toString(SkString* str) const; |
| 82 #endif | 82 #endif |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * Apply this cropRect to the imageBounds. If a given edge of the cropR
ect is not | 85 * Apply this cropRect to the imageBounds. If a given edge of the cropR
ect is not |
| 86 * set, then the corresponding edge from imageBounds will be used. | 86 * set, then the corresponding edge from imageBounds will be used. |
| 87 * | 87 * |
| 88 * Note: imageBounds is in "device" space, as the output cropped rectan
gle will be, | 88 * Note: imageBounds is in "device" space, as the output cropped rectan
gle will be, |
| 89 * so the context's CTM is ignore for those. It is only applied the cro
prect's bounds. | 89 * so the matrix is ignored for those. It is only applied the croprect'
s bounds. |
| 90 * | |
| 91 * The resulting rect will be intersected with the context's clip. If t
hat intersection is | |
| 92 * empty, then this returns false and cropped is unmodified. | |
| 93 */ | 90 */ |
| 94 bool applyTo(const SkIRect& imageBounds, const Context&, SkIRect* croppe
d) const; | 91 void applyTo(const SkIRect& imageBounds, const SkMatrix&, SkIRect* cropp
ed) const; |
| 95 | 92 |
| 96 private: | 93 private: |
| 97 SkRect fRect; | 94 SkRect fRect; |
| 98 uint32_t fFlags; | 95 uint32_t fFlags; |
| 99 }; | 96 }; |
| 100 | 97 |
| 101 enum TileUsage { | 98 enum TileUsage { |
| 102 kPossible_TileUsage, //!< the created device may be drawn tiled | 99 kPossible_TileUsage, //!< the created device may be drawn tiled |
| 103 kNever_TileUsage, //!< the created device will never be drawn tile
d | 100 kNever_TileUsage, //!< the created device will never be drawn tile
d |
| 104 }; | 101 }; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 * | 139 * |
| 143 * Offset is the amount to translate the resulting image relative to the | 140 * Offset is the amount to translate the resulting image relative to the |
| 144 * src when it is drawn. This is an out-param. | 141 * src when it is drawn. This is an out-param. |
| 145 * | 142 * |
| 146 * If the result image cannot be created, return false, in which case both | 143 * If the result image cannot be created, return false, in which case both |
| 147 * the result and offset parameters will be ignored by the caller. | 144 * the result and offset parameters will be ignored by the caller. |
| 148 */ | 145 */ |
| 149 bool filterImage(Proxy*, const SkBitmap& src, const Context&, | 146 bool filterImage(Proxy*, const SkBitmap& src, const Context&, |
| 150 SkBitmap* result, SkIPoint* offset) const; | 147 SkBitmap* result, SkIPoint* offset) const; |
| 151 | 148 |
| 149 enum MapDirection { |
| 150 kForward_MapDirection, |
| 151 kReverse_MapDirection |
| 152 }; |
| 152 /** | 153 /** |
| 153 * Given the src bounds of an image, this returns the bounds of the result | 154 * Map a device-space rect recursively forward or backward through the |
| 154 * image after the filter has been applied. | 155 * filter DAG. kForward_MapDirection is used to determine which pixels of |
| 156 * the destination canvas a source image rect would touch after filtering. |
| 157 * kBackward_MapDirection is used to determine which rect of the source |
| 158 * 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 |
| 160 * be exact, but should never be smaller than the real answer. The default |
| 161 * implementation recursively unions all input bounds, or returns false if |
| 162 * no inputs. |
| 155 */ | 163 */ |
| 156 bool filterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst) con
st; | 164 bool filterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst, |
| 165 MapDirection = kReverse_MapDirection) const; |
| 157 | 166 |
| 158 /** | 167 /** |
| 159 * Returns true if the filter can be processed on the GPU. This is most | 168 * Returns true if the filter can be processed on the GPU. This is most |
| 160 * often used for multi-pass effects, where intermediate results must be | 169 * often used for multi-pass effects, where intermediate results must be |
| 161 * rendered to textures. For single-pass effects, use asFragmentProcessor(
). | 170 * rendered to textures. For single-pass effects, use asFragmentProcessor(
). |
| 162 * The default implementation returns asFragmentProcessor(NULL, NULL, SkMat
rix::I(), | 171 * The default implementation returns asFragmentProcessor(NULL, NULL, SkMat
rix::I(), |
| 163 * SkIRect()). | 172 * SkIRect()). |
| 164 */ | 173 */ |
| 165 virtual bool canFilterImageGPU() const; | 174 virtual bool canFilterImageGPU() const; |
| 166 | 175 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 * | 334 * |
| 326 * Offset is the amount to translate the resulting image relative to the | 335 * Offset is the amount to translate the resulting image relative to the |
| 327 * src when it is drawn. This is an out-param. | 336 * src when it is drawn. This is an out-param. |
| 328 * | 337 * |
| 329 * If the result image cannot be created, this should false, in which | 338 * If the result image cannot be created, this should false, in which |
| 330 * case both the result and offset parameters will be ignored by the | 339 * case both the result and offset parameters will be ignored by the |
| 331 * caller. | 340 * caller. |
| 332 */ | 341 */ |
| 333 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 342 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
| 334 SkBitmap* result, SkIPoint* offset) const; | 343 SkBitmap* result, SkIPoint* offset) const; |
| 335 // Given the bounds of the destination rect to be filled in device | 344 |
| 336 // coordinates (first parameter), and the CTM, compute (conservatively) | 345 /** |
| 337 // which rect of the source image would be required (third parameter). | 346 * This function recurses into its inputs with the given clip rect (first |
| 338 // Used for clipping and temp-buffer allocations, so the result need not | 347 * argument), calls filterBounds() with the given map direction on each, |
| 339 // be exact, but should never be smaller than the real answer. The default | 348 * and unions the result (third argument). If the rect cannot be mapped, |
| 340 // implementation recursively unions all input bounds, or returns false if | 349 * false is returned and the destination rect is left unchanged. |
| 341 // no inputs. | 350 * If a derived class has special recursion requirements (e.g., it has an |
| 342 virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) const
; | 351 * input which does not participate in bounds computation), it can be |
| 343 enum MapDirection { | 352 * overridden here. |
| 344 kForward_MapDirection, | 353 * |
| 345 kReverse_MapDirection | 354 * Note that this function is *not* responsible for mapping the rect for |
| 346 }; | 355 * this node's filter bounds requirements (i.e., calling |
| 356 * onFilterNodeBounds()); that is handled by filterBounds(). |
| 357 */ |
| 358 virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*, MapDi
rection) const; |
| 347 | 359 |
| 348 /** | 360 /** |
| 349 * Performs a forwards or reverse mapping of the given rect to accommodate | 361 * Performs a forwards or reverse mapping of the given rect to accommodate |
| 350 * this filter's margin requirements. kForward_MapDirection is used to | 362 * this filter's margin requirements. kForward_MapDirection is used to |
| 351 * determine the destination pixels which would be touched by filtering | 363 * determine the destination pixels which would be touched by filtering |
| 352 * the given given source rect (e.g., given source bitmap bounds, | 364 * the given given source rect (e.g., given source bitmap bounds, |
| 353 * determine the optimal bounds of the filtered offscreen bitmap). | 365 * determine the optimal bounds of the filtered offscreen bitmap). |
| 354 * kReverse_MapDirection is used to determine which pixels of the | 366 * kReverse_MapDirection is used to determine which pixels of the |
| 355 * input(s) would be required to fill the given destination rect | 367 * input(s) would be required to fill the given destination rect |
| 356 * (e.g., clip bounds). NOTE: these operations may not be the | 368 * (e.g., clip bounds). NOTE: these operations may not be the |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 */ | 457 */ |
| 446 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ | 458 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ |
| 447 Common localVar; \ | 459 Common localVar; \ |
| 448 do { \ | 460 do { \ |
| 449 if (!localVar.unflatten(buffer, expectedCount)) { \ | 461 if (!localVar.unflatten(buffer, expectedCount)) { \ |
| 450 return NULL; \ | 462 return NULL; \ |
| 451 } \ | 463 } \ |
| 452 } while (0) | 464 } while (0) |
| 453 | 465 |
| 454 #endif | 466 #endif |
| OLD | NEW |