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 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 be called, allowing it to modify the canvas and/or paint for that draw call. | 23 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 | 24 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 | 25 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. | 26 like shadows or frame/fills, that require more than one pass. |
| 27 */ | 27 */ |
| 28 class SK_API SkDrawLooper : public SkFlattenable { | 28 class SK_API SkDrawLooper : public SkFlattenable { |
| 29 public: | 29 public: |
| 30 SK_DECLARE_INST_COUNT(SkDrawLooper) | 30 SK_DECLARE_INST_COUNT(SkDrawLooper) |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Called right before something is being drawn. This will be followed by | 33 * Holds state during a draw. Users call next() until it returns false. The |
| 34 * calls to next() until next() returns false. | 34 * final call to next() will also delete the context. |
|
scroggo
2014/02/11 15:51:29
nit: The word delete is no longer necessarily accu
Dominik Grewe
2014/02/11 16:04:31
Good point. Actually the last call to next() doesn
| |
| 35 * | |
| 36 * Subclasses of SkDrawLooper should create a subclass of this object to | |
| 37 * hold state specific to their subclass. | |
| 35 */ | 38 */ |
| 36 virtual void init(SkCanvas*) = 0; | 39 class SK_API DrawContext { |
| 40 public: | |
| 41 DrawContext() {} | |
| 42 virtual ~DrawContext() {} | |
| 43 | |
| 44 /** | |
| 45 * Called in a loop (after init()). Each time true is returned, the | |
| 46 * object is drawn (possibly with a modified canvas and/or paint). When | |
| 47 * false is finally returned, drawing for the object stops. When the | |
| 48 * context is no longer in use, call cleanup(). | |
| 49 * | |
| 50 * On each call, the paint will be in its original state, but the | |
| 51 * canvas will be as it was following the previous call to next() or | |
| 52 * init(). | |
| 53 * | |
| 54 * The implementation must ensure that, when next() finally returns | |
| 55 * false, that the canvas has been restored to the state it was | |
| 56 * initially, before init() was first called. | |
| 57 */ | |
| 58 virtual bool next(SkCanvas* canvas, SkPaint* paint) = 0; | |
| 59 | |
| 60 /** | |
| 61 * Destroys the object and frees memory if the object was dynamically | |
| 62 * allocated. To work correctly, pass in the same pointer that was | |
| 63 * passed to SkDrawLooper::init() for creating this object. | |
| 64 * | |
| 65 * Call this method instead of 'delete' (or similar) to ensure the | |
| 66 * object is destroyed correctly. | |
| 67 */ | |
| 68 void cleanup(void* storage); | |
| 69 }; | |
| 37 | 70 |
| 38 /** | 71 /** |
| 39 * Called in a loop (after init()). Each time true is returned, the object | 72 * Called right before something is being drawn. Returns a DrawContext |
| 40 * is drawn (possibly with a modified canvas and/or paint). When false is | 73 * whose next() method should be called until it returns false. |
| 41 * finally returned, drawing for the object stops. | |
| 42 * | 74 * |
| 43 * On each call, the paint will be in its original state, but the canvas | 75 * Pass a pointer to pre-allocated memory to avoid dynamic memory |
| 44 * will be as it was following the previous call to next() or init(). | 76 * allocation. If the storage size is too small, the object will be |
| 45 * | 77 * dynamically allocated. |
| 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 */ | 78 */ |
| 50 virtual bool next(SkCanvas*, SkPaint* paint) = 0; | 79 virtual DrawContext* init(SkCanvas*, void* storage, size_t storageSize) |
| 80 const = 0; | |
| 81 | |
| 51 | 82 |
| 52 /** | 83 /** |
| 53 * The fast bounds functions are used to enable the paint to be culled early | 84 * 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 | 85 * in the drawing pipeline. If a subclass can support this feature it must |
| 55 * return true for the canComputeFastBounds() function. If that function | 86 * return true for the canComputeFastBounds() function. If that function |
| 56 * returns false then computeFastBounds behavior is undefined otherwise it | 87 * returns false then computeFastBounds behavior is undefined otherwise it |
| 57 * is expected to have the following behavior. Given the parent paint and | 88 * 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 | 89 * 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 | 90 * storage rect, where the storage rect is with the union of the src rect |
| 60 * and the looper's bounding rect. | 91 * and the looper's bounding rect. |
| 61 */ | 92 */ |
| 62 virtual bool canComputeFastBounds(const SkPaint& paint); | 93 virtual bool canComputeFastBounds(const SkPaint& paint); |
| 63 virtual void computeFastBounds(const SkPaint& paint, | 94 virtual void computeFastBounds(const SkPaint& paint, |
| 64 const SkRect& src, SkRect* dst); | 95 const SkRect& src, SkRect* dst); |
| 65 | 96 |
| 66 SkDEVCODE(virtual void toString(SkString* str) const = 0;) | 97 SkDEVCODE(virtual void toString(SkString* str) const = 0;) |
| 67 SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper) | 98 SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper) |
| 68 | 99 |
| 69 protected: | 100 protected: |
| 70 SkDrawLooper() {} | 101 SkDrawLooper() {} |
| 71 SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {} | 102 SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {} |
| 72 | 103 |
| 73 private: | 104 private: |
| 74 typedef SkFlattenable INHERITED; | 105 typedef SkFlattenable INHERITED; |
| 75 }; | 106 }; |
| 76 | 107 |
| 77 #endif | 108 #endif |
| OLD | NEW |