class SkBBoxHierarchy;
class SkCanvas;
+class SkDrawPictureCallback;
class SkPicturePlayback;
class SkPictureRecord;
class SkStream;
/** Replays the drawing commands on the specified canvas. This internally
calls endRecording() if that has not already been called.
- @param surface the canvas receiving the drawing commands.
+ @param canvas the canvas receiving the drawing commands.
*/
- void draw(SkCanvas* surface);
+ void draw(SkCanvas* canvas, SkDrawPictureCallback* = NULL);
/** Return the width of the picture's recording canvas. This
value reflects what was passed to setSize(), and does not necessarily
SkCanvas* fCanvas;
};
+/**
+ * Subclasses of this can be passed to canvas.drawPicture. During the drawing
+ * of the picture, this callback will periodically be invoked. If its
+ * abortDrawing() returns true, then picture playback will be interrupted.
+ *
+ * The resulting drawing is undefined, as there is no guarantee how often the
+ * callback will be invoked. If the abort happens inside some level of nested
+ * calls to save(), restore will automatically be called to return the state
+ * to the same level it was before the drawPicture call was made.
+ */
+class SkDrawPictureCallback {
+public:
+ SkDrawPictureCallback() {}
+ virtual ~SkDrawPictureCallback() {}
+
+ virtual bool abortDrawing() = 0;
+};
#endif
SkASSERT(NULL == fRecord);
}
-void SkPicture::draw(SkCanvas* surface) {
+void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) {
this->endRecording();
if (fPlayback) {
- fPlayback->draw(*surface);
+ fPlayback->draw(*surface, callback);
}
}
return (DrawType) op;
}
-void SkPicturePlayback::draw(SkCanvas& canvas) {
+void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback) {
#ifdef ENABLE_TIME_DRAW
SkAutoTime at("SkPicture::draw", 50);
#endif
// Record this, so we can concat w/ it if we encounter a setMatrix()
SkMatrix initialMatrix = canvas.getTotalMatrix();
+ int originalSaveCount = canvas.getSaveCount();
#ifdef SK_BUILD_FOR_ANDROID
fAbortCurrentPlayback = false;
#endif
while (!reader.eof()) {
+ if (callback && callback->abortDrawing()) {
+ canvas.restoreToCount(originalSaveCount);
+ return;
+ }
#ifdef SK_BUILD_FOR_ANDROID
if (fAbortCurrentPlayback) {
return;
virtual ~SkPicturePlayback();
- void draw(SkCanvas& canvas);
+ void draw(SkCanvas& canvas, SkDrawPictureCallback*);
void serialize(SkWStream*, SkPicture::EncodeBitmap) const;