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. |
34 * calls to next() until next() returns false. | 34 * |
| 35 * Subclasses of SkDrawLooper should create a subclass of this object to |
| 36 * hold state specific to their subclass. |
35 */ | 37 */ |
36 virtual void init(SkCanvas*) = 0; | 38 class SK_API Context : public SkNoncopyable { |
| 39 public: |
| 40 Context() {} |
| 41 virtual ~Context() {} |
| 42 |
| 43 /** |
| 44 * Called in a loop on objects returned by SkDrawLooper::createContext(
). |
| 45 * Each time true is returned, the object is drawn (possibly with a mod
ified |
| 46 * canvas and/or paint). When false is finally returned, drawing for th
e object |
| 47 * stops. |
| 48 * |
| 49 * On each call, the paint will be in its original state, but the |
| 50 * canvas will be as it was following the previous call to next() or |
| 51 * createContext(). |
| 52 * |
| 53 * The implementation must ensure that, when next() finally returns |
| 54 * false, the canvas has been restored to the state it was |
| 55 * initially, before createContext() was first called. |
| 56 */ |
| 57 virtual bool next(SkCanvas* canvas, SkPaint* paint) = 0; |
| 58 }; |
37 | 59 |
38 /** | 60 /** |
39 * Called in a loop (after init()). Each time true is returned, the object | 61 * Called right before something is being drawn. Returns a Context |
40 * is drawn (possibly with a modified canvas and/or paint). When false is | 62 * whose next() method should be called until it returns false. |
41 * finally returned, drawing for the object stops. | 63 * The caller has to ensure that the storage pointer provides enough |
42 * | 64 * memory for the Context. The required size can be queried by calling |
43 * On each call, the paint will be in its original state, but the canvas | 65 * contextSize(). It is also the caller's responsibility to destroy the |
44 * will be as it was following the previous call to next() or init(). | 66 * object after use. |
45 * | |
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 */ | 67 */ |
50 virtual bool next(SkCanvas*, SkPaint* paint) = 0; | 68 virtual Context* createContext(SkCanvas*, void* storage) const = 0; |
| 69 |
| 70 /** |
| 71 * Returns the number of bytes needed to store subclasses of Context (belo
nging to the |
| 72 * corresponding SkDrawLooper subclass). |
| 73 */ |
| 74 virtual size_t contextSize() const = 0; |
| 75 |
51 | 76 |
52 /** | 77 /** |
53 * The fast bounds functions are used to enable the paint to be culled early | 78 * 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 | 79 * in the drawing pipeline. If a subclass can support this feature it must |
55 * return true for the canComputeFastBounds() function. If that function | 80 * return true for the canComputeFastBounds() function. If that function |
56 * returns false then computeFastBounds behavior is undefined otherwise it | 81 * returns false then computeFastBounds behavior is undefined otherwise it |
57 * is expected to have the following behavior. Given the parent paint and | 82 * 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 | 83 * 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 | 84 * storage rect, where the storage rect is with the union of the src rect |
60 * and the looper's bounding rect. | 85 * and the looper's bounding rect. |
61 */ | 86 */ |
62 virtual bool canComputeFastBounds(const SkPaint& paint); | 87 virtual bool canComputeFastBounds(const SkPaint& paint) const; |
63 virtual void computeFastBounds(const SkPaint& paint, | 88 virtual void computeFastBounds(const SkPaint& paint, |
64 const SkRect& src, SkRect* dst); | 89 const SkRect& src, SkRect* dst) const; |
65 | 90 |
66 SkDEVCODE(virtual void toString(SkString* str) const = 0;) | 91 SkDEVCODE(virtual void toString(SkString* str) const = 0;) |
67 SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper) | 92 SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper) |
68 | 93 |
69 protected: | 94 protected: |
70 SkDrawLooper() {} | 95 SkDrawLooper() {} |
71 SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {} | 96 SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {} |
72 | 97 |
73 private: | 98 private: |
74 typedef SkFlattenable INHERITED; | 99 typedef SkFlattenable INHERITED; |
75 }; | 100 }; |
76 | 101 |
77 #endif | 102 #endif |
OLD | NEW |