aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-02-06 08:02:57 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-06 08:02:57 -0800
commit4ae9eb7463cf2160723407359608f221c0d5e2a6 (patch)
tree3c7e641468bf30b164888c00fc3a64e3d2d82a68 /include
parent7fa87cd09f49f1ee9bc27e263038d0f0ae706241 (diff)
rename SkCanvasDrawable to SkDrawable, and make public
BUG=skia: NOTRY=True ... winbuilder flake Review URL: https://codereview.chromium.org/903993002
Diffstat (limited to 'include')
-rw-r--r--include/core/SkCanvas.h14
-rw-r--r--include/core/SkDrawable.h76
-rw-r--r--include/core/SkPictureRecorder.h4
3 files changed, 89 insertions, 5 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 53ca92ee95..0ec167e116 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -21,8 +21,8 @@
class SkBaseDevice;
class SkCanvasClipVisitor;
-class SkCanvasDrawable;
class SkDraw;
+class SkDrawable;
class SkDrawFilter;
class SkImage;
class SkMetaData;
@@ -1018,7 +1018,15 @@ public:
void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
- void EXPERIMENTAL_drawDrawable(SkCanvasDrawable*);
+ /**
+ * Draw the contents of this drawable into the canvas. If the canvas is async
+ * (e.g. it is recording into a picture) then the drawable will be referenced instead,
+ * to have its draw() method called when the picture is finalized.
+ *
+ * If the intent is to force the contents of the drawable into this canvas immediately,
+ * then drawable->draw(canvas) may be called.
+ */
+ void drawDrawable(SkDrawable* drawable);
/** Add comments. beginCommentGroup/endCommentGroup open/close a new group.
Each comment added via addComment is notionally attached to its
@@ -1188,7 +1196,7 @@ protected:
virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
- virtual void onDrawDrawable(SkCanvasDrawable*);
+ virtual void onDrawDrawable(SkDrawable*);
virtual void onDrawPaint(const SkPaint&);
virtual void onDrawRect(const SkRect&, const SkPaint&);
diff --git a/include/core/SkDrawable.h b/include/core/SkDrawable.h
new file mode 100644
index 0000000000..15bb0bbe0f
--- /dev/null
+++ b/include/core/SkDrawable.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkDrawable_DEFINED
+#define SkDrawable_DEFINED
+
+#include "SkRefCnt.h"
+
+class SkCanvas;
+class SkPicture;
+struct SkRect;
+
+/**
+ * Base-class for objects that draw into SkCanvas.
+ *
+ * The object has a generation ID, which is guaranteed to be unique across all drawables. To
+ * allow for clients of the drawable that may want to cache the results, the drawable must
+ * change its generation ID whenever its internal state changes such that it will draw differently.
+ */
+class SkDrawable : public SkRefCnt {
+public:
+ SkDrawable();
+
+ /**
+ * Draws into the specified content. The drawing sequence will be balanced upon return
+ * (i.e. the saveLevel() on the canvas will match what it was when draw() was called,
+ * and the current matrix and clip settings will not be changed.
+ */
+ void draw(SkCanvas*);
+
+ SkPicture* newPictureSnapshot();
+
+ /**
+ * Return a unique value for this instance. If two calls to this return the same value,
+ * it is presumed that calling the draw() method will render the same thing as well.
+ *
+ * Subclasses that change their state should call notifyDrawingChanged() to ensure that
+ * a new value will be returned the next time it is called.
+ */
+ uint32_t getGenerationID();
+
+ /**
+ * Return the (conservative) bounds of what the drawable will draw. If the drawable can
+ * change what it draws (e.g. animation or in response to some external change), then this
+ * must return a bounds that is always valid for all possible states.
+ */
+ SkRect getBounds();
+
+ /**
+ * Calling this invalidates the previous generation ID, and causes a new one to be computed
+ * the next time getGenerationID() is called. Typically this is called by the object itself,
+ * in response to its internal state changing.
+ */
+ void notifyDrawingChanged();
+
+protected:
+ virtual SkRect onGetBounds() = 0;
+ virtual void onDraw(SkCanvas*) = 0;
+
+ /**
+ * Default implementation calls onDraw() with a canvas that records into a picture. Subclasses
+ * may override if they have a more efficient way to return a picture for the current state
+ * of their drawable. Note: this picture must draw the same as what would be drawn from
+ * onDraw().
+ */
+ virtual SkPicture* onNewPictureSnapshot();
+
+private:
+ int32_t fGenerationID;
+};
+
+#endif
diff --git a/include/core/SkPictureRecorder.h b/include/core/SkPictureRecorder.h
index 14443b23d8..b25e26b26a 100644
--- a/include/core/SkPictureRecorder.h
+++ b/include/core/SkPictureRecorder.h
@@ -19,7 +19,7 @@ namespace android {
#endif
class SkCanvas;
-class SkCanvasDrawable;
+class SkDrawable;
class SkPictureRecord;
class SkRecord;
class SkRecorder;
@@ -79,7 +79,7 @@ public:
* and therefore this drawable will reflect the current state of those nested drawables anytime
* it is drawn or a new picture is snapped from it (by calling drawable->newPictureSnapshot()).
*/
- SkCanvasDrawable* EXPERIMENTAL_endRecordingAsDrawable();
+ SkDrawable* endRecordingAsDrawable();
// Legacy API -- use endRecordingAsPicture instead.
SkPicture* endRecording() { return this->endRecordingAsPicture(); }