diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index ba316ff66b..8053bb2405 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -348,12 +348,20 @@ private: */ const OperationList& EXPERIMENTAL_getActiveOps(const SkIRect& queryRect); + /** PRIVATE / EXPERIMENTAL -- do not call + Return the ID of the operation currently being executed when playing + back. 0 indicates no call is active. + */ + size_t EXPERIMENTAL_curOpID() const; + void createHeader(SkPictInfo* info) const; static bool IsValidPictInfo(const SkPictInfo& info); friend class SkFlatPicture; friend class SkPicturePlayback; friend class SkGpuDevice; + friend class GrGatherDevice; + friend class SkDebugCanvas; typedef SkRefCnt INHERITED; }; diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index 41fc374aae..ae0347cf25 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -281,6 +281,13 @@ const SkPicture::OperationList& SkPicture::EXPERIMENTAL_getActiveOps(const SkIRe return OperationList::InvalidList(); } +size_t SkPicture::EXPERIMENTAL_curOpID() const { + if (NULL != fPlayback) { + return fPlayback->curOpID(); + } + return 0; +} + void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) { this->endRecording(); if (NULL != fPlayback) { diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index a570c4c270..8320335e68 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -261,6 +261,7 @@ void SkPicturePlayback::init() { fBoundingHierarchy = NULL; fStateTree = NULL; fCachedActiveOps = NULL; + fCurOffset = 0; } SkPicturePlayback::~SkPicturePlayback() { @@ -838,7 +839,23 @@ const SkPicture::OperationList& SkPicturePlayback::getActiveOps(const SkIRect& q return *fCachedActiveOps; } +class SkAutoResetOpID { +public: + SkAutoResetOpID(SkPicturePlayback* playback) : fPlayback(playback) { } + ~SkAutoResetOpID() { + if (NULL != fPlayback) { + fPlayback->resetOpID(); + } + } + +private: + SkPicturePlayback* fPlayback; +}; + void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback) { + SkAutoResetOpID aroi(this); + SkASSERT(0 == fCurOffset); + #ifdef ENABLE_TIME_DRAW SkAutoTime at("SkPicture::draw", 50); #endif @@ -919,18 +936,18 @@ void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback) opCount++; #endif - size_t curOffset = reader.offset(); + fCurOffset = reader.offset(); uint32_t size; DrawType op = read_op_and_size(&reader, &size); size_t skipTo = 0; if (NOOP == op) { // NOOPs are to be ignored - do not propagate them any further - skipTo = curOffset + size; + skipTo = fCurOffset + size; #ifdef SK_DEVELOPER } else { opIndex++; if (this->preDraw(opIndex, op)) { - skipTo = curOffset + size; + skipTo = fCurOffset + size; } #endif } diff --git a/src/core/SkPicturePlayback.h b/src/core/SkPicturePlayback.h index 11624205d4..89d70a1739 100644 --- a/src/core/SkPicturePlayback.h +++ b/src/core/SkPicturePlayback.h @@ -102,6 +102,9 @@ public: void abort() { fAbortCurrentPlayback = true; } #endif + size_t curOpID() const { return fCurOffset; } + void resetOpID() { fCurOffset = 0; } + protected: bool parseStream(SkStream*, const SkPictInfo&, SkPicture::InstallPixelRefProc); @@ -264,6 +267,10 @@ private: SkTypefacePlayback fTFPlayback; SkFactoryPlayback* fFactoryPlayback; + + // The offset of the current operation when within the draw method + size_t fCurOffset; + #ifdef SK_BUILD_FOR_ANDROID SkMutex fDrawMutex; bool fAbortCurrentPlayback;