Index: include/core/SkDrawLooper.h |
diff --git a/include/core/SkDrawLooper.h b/include/core/SkDrawLooper.h |
index 4609c1dcf90ddb67a4708909ea209b5063fcfe18..74830bbb046f2e3c9e47aa1a30f57862310cb9be 100644 |
--- a/include/core/SkDrawLooper.h |
+++ b/include/core/SkDrawLooper.h |
@@ -11,6 +11,7 @@ |
#define SkDrawLooper_DEFINED |
#include "SkFlattenable.h" |
+#include "SkSmallAllocator.h" |
class SkCanvas; |
class SkPaint; |
@@ -30,24 +31,46 @@ public: |
SK_DECLARE_INST_COUNT(SkDrawLooper) |
/** |
- * Called right before something is being drawn. This will be followed by |
- * calls to next() until next() returns false. |
+ * Holds state during a draw. Users call next() until it returns false. |
+ * When the context is no longer needed, call cleanup() to ensure memory |
+ * is released correctly. |
+ * |
+ * Subclasses of SkDrawLooper should create a subclass of this object to |
+ * hold state specific to their subclass. |
*/ |
- virtual void init(SkCanvas*) = 0; |
+ class SK_API Context : public SkNoncopyable { |
+ public: |
+ Context() {} |
+ virtual ~Context() {} |
+ |
+ /** |
+ * Called in a loop (after init()). Each time true is returned, the |
+ * object is drawn (possibly with a modified canvas and/or paint). When |
+ * false is finally returned, drawing for the object stops. |
+ * |
+ * On each call, the paint will be in its original state, but the |
+ * canvas will be as it was following the previous call to next() or |
+ * init(). |
+ * |
+ * The implementation must ensure that, when next() finally returns |
+ * false, that the canvas has been restored to the state it was |
+ * initially, before init() was first called. |
+ */ |
+ virtual bool next(SkCanvas* canvas, SkPaint* paint) = 0; |
+ }; |
/** |
- * Called in a loop (after init()). Each time true is returned, the object |
- * is drawn (possibly with a modified canvas and/or paint). When false is |
- * finally returned, drawing for the object stops. |
- * |
- * On each call, the paint will be in its original state, but the canvas |
- * will be as it was following the previous call to next() or init(). |
- * |
- * The implementation must ensure that, when next() finally returns false, |
- * that the canvas has been restored to the state it was initially, before |
- * init() was first called. |
+ * Provide enough space for largest draw looper context. |
+ */ |
+ typedef SkSmallAllocator<1, 2 * SkAlign8(sizeof(void*) + sizeof(int))> ContextAllocator; |
Dominik Grewe
2014/03/10 18:52:03
This isn't particularly elegant because of the fix
|
+ |
+ /** |
+ * Called right before something is being drawn. Returns a Context |
+ * whose next() method should be called until it returns false. |
*/ |
- virtual bool next(SkCanvas*, SkPaint* paint) = 0; |
+ virtual Context* init(SkCanvas*, ContextAllocator*) |
+ const = 0; |
+ |
/** |
* The fast bounds functions are used to enable the paint to be culled early |