Index: include/core/SkDrawLooper.h |
diff --git a/include/core/SkDrawLooper.h b/include/core/SkDrawLooper.h |
index 4609c1dcf90ddb67a4708909ea209b5063fcfe18..d5a5cb7f0efaba4d88a1673cc94ecd1edbc9187f 100644 |
--- a/include/core/SkDrawLooper.h |
+++ b/include/core/SkDrawLooper.h |
@@ -12,6 +12,8 @@ |
#include "SkFlattenable.h" |
+#define kDrawLooperContextStorageLongCount (sizeof(void*) + sizeof(int)) |
Dominik Grewe
2014/02/07 11:57:15
It's not particularly nice to hardcode the size of
reed1
2014/02/07 14:46:02
1. I think callers have to be able to survive subc
Dominik Grewe
2014/02/07 16:59:17
I'll move it into the cpp files instead.
|
+ |
class SkCanvas; |
class SkPaint; |
struct SkRect; |
@@ -30,24 +32,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. The |
+ * final call to next() will also delete the context. |
+ * |
+ * 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 DrawContext { |
+ public: |
+ DrawContext() {} |
+ virtual ~DrawContext() {} |
+ |
+ /** |
+ * 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. When the |
+ * context is no longer in use, call cleanup(). |
+ * |
+ * 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; |
+ |
+ void cleanup(void* storage); |
Dominik Grewe
2014/02/07 11:57:15
I've added this so the user is in charge of when t
|
+ }; |
/** |
- * 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(). |
+ * Called right before something is being drawn. Returns a DrawContext |
+ * whose next() method should be called until it returns false. |
* |
- * 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. |
+ * Pass a pointer to pre-allocated memory to avoid dynamic memory |
+ * allocation. |
*/ |
- virtual bool next(SkCanvas*, SkPaint* paint) = 0; |
+ virtual DrawContext* init(SkCanvas*, void* storage, size_t storageSize) |
+ const = 0; |
+ |
/** |
* The fast bounds functions are used to enable the paint to be culled early |