Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Unified Diff: include/core/SkPicture.h

Issue 214953003: split SkPictureRecorder out of SkPicture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: yet more cleanup Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gm/pictureimagefilter.cpp ('k') | include/core/SkTileGridPicture.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkPicture.h
===================================================================
--- include/core/SkPicture.h (revision 13963)
+++ include/core/SkPicture.h (working copy)
@@ -384,4 +384,83 @@
virtual bool abortDrawing() = 0;
};
+class SkPictureFactory : public SkRefCnt {
+public:
+ /**
+ * Allocate a new SkPicture. Return NULL on failure.
+ */
+ virtual SkPicture* create(int width, int height) = 0;
+};
+
+class SK_API SkPictureRecorder : public SkRefCnt {
mtklein 2014/03/27 21:09:11 What's this extra level of indirection get us? I'
+public:
+ SK_DECLARE_INST_COUNT(SkPictureRecorder)
+
+ SkPictureRecorder(SkPictureFactory* factory = NULL) {
+ fFactory.reset(factory);
+ if (NULL != fFactory.get()) {
+ fFactory.get()->ref();
+ }
+ }
+
+ /** Returns the canvas that records the drawing commands.
+ @param width the base width for the picture, as if the recording
+ canvas' bitmap had this width.
+ @param height the base width for the picture, as if the recording
+ canvas' bitmap had this height.
+ @param recordFlags optional flags that control recording.
+ @return the canvas.
+ */
+ SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0) {
+ if (NULL != fFactory) {
+ fPicture.reset(fFactory->create(width, height));
+ } else {
+ fPicture.reset(SkNEW(SkPicture));
+ }
+
+ return fPicture->beginRecording(width, height, recordFlags);
+ }
+
+ /** Returns the recording canvas if one is active, or NULL if recording is
+ not active. This does not alter the refcnt on the canvas (if present).
+ */
+ SkCanvas* getRecordingCanvas() {
+ if (NULL != fPicture.get()) {
+ return fPicture->getRecordingCanvas();
+ }
+ return NULL;
+ }
+
+ /** Signal that the caller is done recording. This invalidates the canvas
+ returned by beginRecording/getRecordingCanvas, and returns the
+ created SkPicture. Note that the returned picture has its creation
+ ref which the caller must take ownership of.
+ */
+ SkPicture* endRecording() {
+ if (NULL != fPicture.get()) {
+ fPicture->endRecording();
+ return fPicture.detach();
+ }
+ return NULL;
+ }
+
+ /** Enable/disable all the picture recording optimizations (i.e.,
+ those in SkPictureRecord). It is mainly intended for testing the
+ existing optimizations (i.e., to actually have the pattern
+ appear in an .skp we have to disable the optimization). Call right
+ after 'beginRecording'.
+ */
+ void internalOnly_EnableOpts(bool enableOpts) {
+ if (NULL != fPicture.get()) {
+ fPicture->internalOnly_EnableOpts(enableOpts);
+ }
+ }
+
+private:
+ SkAutoTUnref<SkPictureFactory> fFactory;
+ SkAutoTUnref<SkPicture> fPicture;
+
+ typedef SkRefCnt INHERITED;
+};
+
#endif
« no previous file with comments | « gm/pictureimagefilter.cpp ('k') | include/core/SkTileGridPicture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698