Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 The Android Open Source Project | 3 * Copyright 2011 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkDrawLooper_DEFINED | 10 #ifndef SkDrawLooper_DEFINED |
| 11 #define SkDrawLooper_DEFINED | 11 #define SkDrawLooper_DEFINED |
| 12 | 12 |
| 13 #include "SkFlattenable.h" | 13 #include "SkFlattenable.h" |
| 14 #include "SkSmallAllocator.h" | |
| 14 | 15 |
| 15 class SkCanvas; | 16 class SkCanvas; |
| 16 class SkPaint; | 17 class SkPaint; |
| 17 struct SkRect; | 18 struct SkRect; |
| 18 class SkString; | 19 class SkString; |
| 19 | 20 |
| 20 /** \class SkDrawLooper | 21 /** \class SkDrawLooper |
| 21 Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are, | 22 Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are, |
| 22 and something is drawn to a canvas with that paint, the looper subclass will | 23 and something is drawn to a canvas with that paint, the looper subclass will |
| 23 be called, allowing it to modify the canvas and/or paint for that draw call. | 24 be called, allowing it to modify the canvas and/or paint for that draw call. |
| 24 More than that, via the next() method, the looper can modify the draw to be | 25 More than that, via the next() method, the looper can modify the draw to be |
| 25 invoked multiple times (hence the name loop-er), allow it to perform effects | 26 invoked multiple times (hence the name loop-er), allow it to perform effects |
| 26 like shadows or frame/fills, that require more than one pass. | 27 like shadows or frame/fills, that require more than one pass. |
| 27 */ | 28 */ |
| 28 class SK_API SkDrawLooper : public SkFlattenable { | 29 class SK_API SkDrawLooper : public SkFlattenable { |
| 29 public: | 30 public: |
| 30 SK_DECLARE_INST_COUNT(SkDrawLooper) | 31 SK_DECLARE_INST_COUNT(SkDrawLooper) |
| 31 | 32 |
| 32 /** | 33 /** |
| 33 * Called right before something is being drawn. This will be followed by | 34 * Holds state during a draw. Users call next() until it returns false. |
| 34 * calls to next() until next() returns false. | 35 * When the context is no longer needed, call cleanup() to ensure memory |
| 36 * is released correctly. | |
| 37 * | |
| 38 * Subclasses of SkDrawLooper should create a subclass of this object to | |
| 39 * hold state specific to their subclass. | |
| 35 */ | 40 */ |
| 36 virtual void init(SkCanvas*) = 0; | 41 class SK_API Context : public SkNoncopyable { |
| 42 public: | |
| 43 Context() {} | |
| 44 virtual ~Context() {} | |
| 45 | |
| 46 /** | |
| 47 * Called in a loop (after init()). Each time true is returned, the | |
| 48 * object is drawn (possibly with a modified canvas and/or paint). When | |
| 49 * false is finally returned, drawing for the object stops. | |
| 50 * | |
| 51 * On each call, the paint will be in its original state, but the | |
| 52 * canvas will be as it was following the previous call to next() or | |
| 53 * init(). | |
| 54 * | |
| 55 * The implementation must ensure that, when next() finally returns | |
| 56 * false, that the canvas has been restored to the state it was | |
| 57 * initially, before init() was first called. | |
| 58 */ | |
| 59 virtual bool next(SkCanvas* canvas, SkPaint* paint) = 0; | |
| 60 }; | |
| 37 | 61 |
| 38 /** | 62 /** |
| 39 * Called in a loop (after init()). Each time true is returned, the object | 63 * Provide enough space for largest draw looper context. |
| 40 * is drawn (possibly with a modified canvas and/or paint). When false is | 64 */ |
| 41 * finally returned, drawing for the object stops. | 65 typedef SkSmallAllocator<1, 2 * SkAlign8(sizeof(void*) + sizeof(int))> Conte xtAllocator; |
|
Dominik Grewe
2014/03/10 18:52:03
This isn't particularly elegant because of the fix
| |
| 42 * | 66 |
| 43 * On each call, the paint will be in its original state, but the canvas | 67 /** |
| 44 * will be as it was following the previous call to next() or init(). | 68 * Called right before something is being drawn. Returns a Context |
| 45 * | 69 * whose next() method should be called until it returns false. |
| 46 * The implementation must ensure that, when next() finally returns false, | |
| 47 * that the canvas has been restored to the state it was initially, before | |
| 48 * init() was first called. | |
| 49 */ | 70 */ |
| 50 virtual bool next(SkCanvas*, SkPaint* paint) = 0; | 71 virtual Context* init(SkCanvas*, ContextAllocator*) |
| 72 const = 0; | |
| 73 | |
| 51 | 74 |
| 52 /** | 75 /** |
| 53 * The fast bounds functions are used to enable the paint to be culled early | 76 * The fast bounds functions are used to enable the paint to be culled early |
| 54 * in the drawing pipeline. If a subclass can support this feature it must | 77 * in the drawing pipeline. If a subclass can support this feature it must |
| 55 * return true for the canComputeFastBounds() function. If that function | 78 * return true for the canComputeFastBounds() function. If that function |
| 56 * returns false then computeFastBounds behavior is undefined otherwise it | 79 * returns false then computeFastBounds behavior is undefined otherwise it |
| 57 * is expected to have the following behavior. Given the parent paint and | 80 * is expected to have the following behavior. Given the parent paint and |
| 58 * the parent's bounding rect the subclass must fill in and return the | 81 * the parent's bounding rect the subclass must fill in and return the |
| 59 * storage rect, where the storage rect is with the union of the src rect | 82 * storage rect, where the storage rect is with the union of the src rect |
| 60 * and the looper's bounding rect. | 83 * and the looper's bounding rect. |
| 61 */ | 84 */ |
| 62 virtual bool canComputeFastBounds(const SkPaint& paint); | 85 virtual bool canComputeFastBounds(const SkPaint& paint); |
| 63 virtual void computeFastBounds(const SkPaint& paint, | 86 virtual void computeFastBounds(const SkPaint& paint, |
| 64 const SkRect& src, SkRect* dst); | 87 const SkRect& src, SkRect* dst); |
| 65 | 88 |
| 66 SkDEVCODE(virtual void toString(SkString* str) const = 0;) | 89 SkDEVCODE(virtual void toString(SkString* str) const = 0;) |
| 67 SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper) | 90 SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper) |
| 68 | 91 |
| 69 protected: | 92 protected: |
| 70 SkDrawLooper() {} | 93 SkDrawLooper() {} |
| 71 SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {} | 94 SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {} |
| 72 | 95 |
| 73 private: | 96 private: |
| 74 typedef SkFlattenable INHERITED; | 97 typedef SkFlattenable INHERITED; |
| 75 }; | 98 }; |
| 76 | 99 |
| 77 #endif | 100 #endif |
| OLD | NEW |