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 26 matching lines...) Expand all Loading... |
37 public: | 37 public: |
38 struct Key; | 38 struct Key; |
39 virtual ~Cache() {} | 39 virtual ~Cache() {} |
40 static Cache* Create(size_t maxBytes); | 40 static Cache* Create(size_t maxBytes); |
41 static Cache* Get(); | 41 static Cache* Get(); |
42 virtual bool get(const Key& key, SkBitmap* result, SkIPoint* offset) con
st = 0; | 42 virtual bool get(const Key& key, SkBitmap* result, SkIPoint* offset) con
st = 0; |
43 virtual void set(const Key& key, const SkBitmap& result, const SkIPoint&
offset) = 0; | 43 virtual void set(const Key& key, const SkBitmap& result, const SkIPoint&
offset) = 0; |
44 virtual void purge() {} | 44 virtual void purge() {} |
45 }; | 45 }; |
46 | 46 |
| 47 enum SizeConstraint { |
| 48 kExact_SizeConstraint, |
| 49 kApprox_SizeConstraint, |
| 50 }; |
| 51 |
47 class Context { | 52 class Context { |
48 public: | 53 public: |
49 Context(const SkMatrix& ctm, const SkIRect& clipBounds, Cache* cache) : | 54 Context(const SkMatrix& ctm, const SkIRect& clipBounds, Cache* cache, |
50 fCTM(ctm), fClipBounds(clipBounds), fCache(cache) { | 55 SizeConstraint constraint) |
51 } | 56 : fCTM(ctm) |
| 57 , fClipBounds(clipBounds) |
| 58 , fCache(cache) |
| 59 , fSizeConstraint(constraint) |
| 60 {} |
| 61 |
52 const SkMatrix& ctm() const { return fCTM; } | 62 const SkMatrix& ctm() const { return fCTM; } |
53 const SkIRect& clipBounds() const { return fClipBounds; } | 63 const SkIRect& clipBounds() const { return fClipBounds; } |
54 Cache* cache() const { return fCache; } | 64 Cache* cache() const { return fCache; } |
| 65 SizeConstraint sizeConstraint() const { return fSizeConstraint; } |
| 66 |
55 private: | 67 private: |
56 SkMatrix fCTM; | 68 SkMatrix fCTM; |
57 SkIRect fClipBounds; | 69 SkIRect fClipBounds; |
58 Cache* fCache; | 70 Cache* fCache; |
| 71 SizeConstraint fSizeConstraint; |
59 }; | 72 }; |
60 | 73 |
61 class CropRect { | 74 class CropRect { |
62 public: | 75 public: |
63 enum CropEdge { | 76 enum CropEdge { |
64 kHasLeft_CropEdge = 0x01, | 77 kHasLeft_CropEdge = 0x01, |
65 kHasTop_CropEdge = 0x02, | 78 kHasTop_CropEdge = 0x02, |
66 kHasWidth_CropEdge = 0x04, | 79 kHasWidth_CropEdge = 0x04, |
67 kHasHeight_CropEdge = 0x08, | 80 kHasHeight_CropEdge = 0x08, |
68 kHasAll_CropEdge = 0x0F, | 81 kHasAll_CropEdge = 0x0F, |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 */ | 261 */ |
249 static void WrapTexture(GrTexture* texture, int width, int height, SkBitmap*
result); | 262 static void WrapTexture(GrTexture* texture, int width, int height, SkBitmap*
result); |
250 | 263 |
251 // Helper function which invokes GPU filter processing on the | 264 // Helper function which invokes GPU filter processing on the |
252 // input at the specified "index". If the input is null, it leaves | 265 // input at the specified "index". If the input is null, it leaves |
253 // "result" and "offset" untouched, and returns true. If the input | 266 // "result" and "offset" untouched, and returns true. If the input |
254 // has a GPU implementation, it will be invoked directly. | 267 // has a GPU implementation, it will be invoked directly. |
255 // Otherwise, the filter will be processed in software and | 268 // Otherwise, the filter will be processed in software and |
256 // uploaded to the GPU. | 269 // uploaded to the GPU. |
257 bool filterInputGPU(int index, SkImageFilter::Proxy* proxy, const SkBitmap&
src, const Context&, | 270 bool filterInputGPU(int index, SkImageFilter::Proxy* proxy, const SkBitmap&
src, const Context&, |
258 SkBitmap* result, SkIPoint* offset) const; | 271 SkBitmap* result, SkIPoint* offset, bool relaxSizeConstr
aint = true) const; |
259 #endif | 272 #endif |
260 | 273 |
261 SK_TO_STRING_PUREVIRT() | 274 SK_TO_STRING_PUREVIRT() |
262 SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter) | 275 SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter) |
263 | 276 |
264 protected: | 277 protected: |
265 class Common { | 278 class Common { |
266 public: | 279 public: |
267 Common() {} | 280 Common() {} |
268 ~Common(); | 281 ~Common(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 // implementation recursively unions all input bounds, or returns false if | 351 // implementation recursively unions all input bounds, or returns false if |
339 // no inputs. | 352 // no inputs. |
340 virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) const
; | 353 virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*) const
; |
341 | 354 |
342 // Helper function which invokes filter processing on the input at the | 355 // Helper function which invokes filter processing on the input at the |
343 // specified "index". If the input is null, it leaves "result" and | 356 // specified "index". If the input is null, it leaves "result" and |
344 // "offset" untouched, and returns true. If the input is non-null, it | 357 // "offset" untouched, and returns true. If the input is non-null, it |
345 // calls filterImage() on that input, and returns true on success. | 358 // calls filterImage() on that input, and returns true on success. |
346 // i.e., return !getInput(index) || getInput(index)->filterImage(...); | 359 // i.e., return !getInput(index) || getInput(index)->filterImage(...); |
347 bool filterInput(int index, Proxy*, const SkBitmap& src, const Context&, | 360 bool filterInput(int index, Proxy*, const SkBitmap& src, const Context&, |
348 SkBitmap* result, SkIPoint* offset) const; | 361 SkBitmap* result, SkIPoint* offset, bool relaxSizeConstrain
t = true) const; |
349 | 362 |
350 /** | 363 /** |
351 * Return true (and return a ref'd colorfilter) if this node in the DAG is
just a | 364 * Return true (and return a ref'd colorfilter) if this node in the DAG is
just a |
352 * colorfilter w/o CropRect constraints. | 365 * colorfilter w/o CropRect constraints. |
353 */ | 366 */ |
354 virtual bool onIsColorFilterNode(SkColorFilter** /*filterPtr*/) const { | 367 virtual bool onIsColorFilterNode(SkColorFilter** /*filterPtr*/) const { |
355 return false; | 368 return false; |
356 } | 369 } |
357 | 370 |
358 /** Computes source bounds as the src bitmap bounds offset by srcOffset. | 371 /** Computes source bounds as the src bitmap bounds offset by srcOffset. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 */ | 433 */ |
421 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ | 434 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ |
422 Common localVar; \ | 435 Common localVar; \ |
423 do { \ | 436 do { \ |
424 if (!localVar.unflatten(buffer, expectedCount)) { \ | 437 if (!localVar.unflatten(buffer, expectedCount)) { \ |
425 return NULL; \ | 438 return NULL; \ |
426 } \ | 439 } \ |
427 } while (0) | 440 } while (0) |
428 | 441 |
429 #endif | 442 #endif |
OLD | NEW |