add SkDrawPictureCallback optional parameter to drawPicture(), which can abort the picture drawing.

R=bsalomon@google.com

Review URL: https://codereview.chromium.org/14598023

git-svn-id: http://skia.googlecode.com/svn/trunk@9197 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2013-05-20 17:02:41 +00:00
parent 67882ddc0e
commit 74babdfce5
4 changed files with 29 additions and 6 deletions

View File

@ -15,6 +15,7 @@
class SkBBoxHierarchy;
class SkCanvas;
class SkDrawPictureCallback;
class SkPicturePlayback;
class SkPictureRecord;
class SkStream;
@ -150,9 +151,9 @@ public:
/** 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
@ -246,5 +247,22 @@ private:
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

View File

@ -253,10 +253,10 @@ void SkPicture::endRecording() {
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);
}
}

View File

@ -656,7 +656,7 @@ static DrawType read_op_and_size(SkReader32* reader, uint32_t* size) {
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
@ -706,12 +706,17 @@ void SkPicturePlayback::draw(SkCanvas& canvas) {
// 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;

View File

@ -66,7 +66,7 @@ public:
virtual ~SkPicturePlayback();
void draw(SkCanvas& canvas);
void draw(SkCanvas& canvas, SkDrawPictureCallback*);
void serialize(SkWStream*, SkPicture::EncodeBitmap) const;