Index: include/core/SkPicture.h |
=================================================================== |
--- include/core/SkPicture.h (revision 13963) |
+++ include/core/SkPicture.h (working copy) |
@@ -164,6 +164,13 @@ |
kOptimizeForClippedPlayback_RecordingFlag = 0x02, |
}; |
+#ifndef SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD |
+private: |
+ friend class SkPictureRecorder; |
+ friend class SkImage_Picture; |
+ friend class SkSurface_Picture; |
+#endif |
+ |
/** 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. |
@@ -185,6 +192,10 @@ |
*/ |
void endRecording(); |
+#ifndef SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD |
+public: |
+#endif |
+ |
/** Replays the drawing commands on the specified canvas. This internally |
calls endRecording() if that has not already been called. |
@param canvas the canvas receiving the drawing commands. |
@@ -384,4 +395,81 @@ |
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; |
mtklein
2014/04/07 15:18:12
If you keep factories, it might be less obtrusive
robertphillips
2014/04/07 16:26:56
The TileGrid ctor requires extra parameters.
mtklein
2014/04/07 16:29:43
OK then, pass as a functor?
|
+}; |
+ |
+class SK_API SkPictureRecorder : public SkNoncopyable { |
mtklein
2014/04/07 15:18:12
For SkNoncopyable to work, it's got to be private
mtklein
2014/04/07 15:18:12
I'm still somewhat surprised that SkPictureRecorde
robertphillips
2014/04/07 16:26:56
If that's true we're doing it wrong all over the p
mtklein
2014/04/07 16:29:43
Gross.
|
+public: |
+ SkPictureRecorder(SkPictureFactory* factory = NULL) { |
reed1
2014/04/07 14:49:57
icky icky factory. why is this here? Is it just fo
robertphillips
2014/04/07 15:05:37
Yes. Ultimately this should change to "SkAccelFact
|
+ 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) { |
mtklein
2014/04/07 15:18:12
Can we just pass in the SkPicture to record into?
|
+ 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 SkNoncopyable INHERITED; |
+}; |
+ |
#endif |