More SkPicture cleanup
authormtklein <mtklein@chromium.org>
Mon, 17 Nov 2014 14:45:18 +0000 (06:45 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 17 Nov 2014 14:45:18 +0000 (06:45 -0800)
 - move field declarations together and pack them a little tighter
 - get rid of fData
 - remove dead code in debugger, including unused SkPicturePlayback subclass

There are now no more long-lived SkPictureData!  (Really, there never were,
but now we don't pretend to support them.)

BUG=skia:

No API changes.
TBR=reed@google.com

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

debugger/QT/SkDebuggerGUI.cpp
include/core/SkPicture.h
src/core/SkPicture.cpp
src/core/SkPicturePlayback.h

index 4901d62..4b87f0f 100644 (file)
@@ -155,192 +155,6 @@ void SkDebuggerGUI::showDeletes() {
         item->setHidden(fDebugger.isCommandVisible(row) && fDeletesActivated);
     }
 }
-
-// The timed picture playback just steps through every operation timing
-// each one individually. Note that each picture should be replayed multiple 
-// times (via calls to 'draw') before each command's time is accessed via 'time'.
-class SkTimedPicturePlayback : public SkPicturePlayback {
-public:
-
-    SkTimedPicturePlayback(const SkPicture* picture, const SkTDArray<bool>& deletedCommands)
-        : INHERITED(picture)
-        , fSkipCommands(deletedCommands)
-        , fTot(0.0)
-        , fCurCommand(0) {
-        fTimes.setCount(deletedCommands.count());
-        fTypeTimes.setCount(LAST_DRAWTYPE_ENUM+1);
-        this->resetTimes();
-    }
-
-    virtual void draw(SkCanvas* canvas, SkDrawPictureCallback* callback) SK_OVERRIDE {
-        AutoResetOpID aroi(this);
-        SkASSERT(0 == fCurOffset);
-
-        SkReader32 reader(fPictureData->opData()->bytes(), fPictureData->opData()->size());
-
-        // Record this, so we can concat w/ it if we encounter a setMatrix()
-        SkMatrix initialMatrix = canvas->getTotalMatrix();
-
-        SkAutoCanvasRestore acr(canvas, false);
-
-        int opIndex = -1;
-
-        while (!reader.eof()) {
-            if (callback && callback->abortDrawing()) {
-                return;
-            }
-
-            fCurOffset = reader.offset();
-            uint32_t size;
-            DrawType op = ReadOpAndSize(&reader, &size);
-            if (NOOP == op) {
-                // NOOPs are to be ignored - do not propagate them any further
-                reader.setOffset(fCurOffset + size);
-                continue;
-            }
-
-            opIndex++;
-
-            if (this->preDraw(opIndex, op)) {
-                // This operation is disabled in the debugger's GUI
-                reader.setOffset(fCurOffset + size);
-                continue;
-            }
-
-            this->handleOp(&reader, op, size, canvas, initialMatrix);
-
-            this->postDraw(opIndex);
-        }
-    }
-
-    void resetTimes() {
-        for (int i = 0; i < fTimes.count(); ++i) {
-            fTimes[i] = 0.0;
-        }
-        for (int i = 0; i < fTypeTimes.count(); ++i) {
-            fTypeTimes[i] = 0.0f;
-        }
-        fTot = 0.0;
-    }
-
-    int count() const { return fTimes.count(); }
-
-    // Return the fraction of the total time consumed by the index-th operation
-    double time(int index) const { return fTimes[index] / fTot; }
-
-    const SkTDArray<double>* typeTimes() const { return &fTypeTimes; }
-
-    double totTime() const { return fTot; }
-
-protected:
-    SysTimer fTimer;
-    SkTDArray<bool> fSkipCommands; // has the command been deleted in the GUI?
-    SkTDArray<double> fTimes;   // sum of time consumed for each command
-    SkTDArray<double> fTypeTimes; // sum of time consumed for each type of command (e.g., drawPath)
-    double fTot;                // total of all times in 'fTimes'
-
-    int fCurType;
-    int fCurCommand;            // the current command being executed/timed
-
-    bool preDraw(int opIndex, int type) {
-        fCurCommand = opIndex;
-
-        if (fSkipCommands[fCurCommand]) {
-            return true;
-        }
-
-        fCurType = type;
-        // The SkDebugCanvas doesn't recognize these types. This class needs to
-        // convert or else we'll wind up with a mismatch between the type counts
-        // the debugger displays and the profile times.
-        if (DRAW_POS_TEXT_TOP_BOTTOM == type) {
-            fCurType = DRAW_POS_TEXT;
-        } else if (DRAW_POS_TEXT_H_TOP_BOTTOM == type) {
-            fCurType = DRAW_POS_TEXT_H;
-        }
-
-#if defined(SK_BUILD_FOR_WIN32)
-        // CPU timer doesn't work well on Windows
-        fTimer.startWall();
-#else
-        fTimer.startCpu();
-#endif
-
-        return false;
-    }
-
-    void postDraw(int opIndex) {
-#if defined(SK_BUILD_FOR_WIN32)
-        // CPU timer doesn't work well on Windows
-        double time = fTimer.endWall();
-#else
-        double time = fTimer.endCpu();
-#endif
-
-        SkASSERT(opIndex == fCurCommand);
-        SkASSERT(fCurType <= LAST_DRAWTYPE_ENUM);
-
-        fTimes[fCurCommand] += time;
-        fTypeTimes[fCurType] += time;
-        fTot += time;
-    }
-
-private:
-    typedef SkPicturePlayback INHERITED;
-};
-
-#if 0
-// Wrap SkPicture to allow installation of an SkTimedPicturePlayback object
-class SkTimedPicture : public SkPicture {
-public:
-    static SkTimedPicture* CreateTimedPicture(SkStream* stream,
-                                              SkPicture::InstallPixelRefProc proc,
-                                              const SkTDArray<bool>& deletedCommands) {
-        SkPictInfo info;
-        if (!InternalOnly_StreamIsSKP(stream, &info)) {
-            return NULL;
-        }
-
-        // Check to see if there is a playback to recreate.
-        if (stream->readBool()) {
-            SkTimedPicturePlayback* playback = SkTimedPicturePlayback::CreateFromStream(
-                                                                stream,
-                                                                info, proc,
-                                                                deletedCommands);
-            if (NULL == playback) {
-                return NULL;
-            }
-
-            return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight));
-        }
-
-        return NULL;
-    }
-
-    void resetTimes() { ((SkTimedPicturePlayback*) fData.get())->resetTimes(); }
-
-    int count() const { return ((SkTimedPicturePlayback*) fData.get())->count(); }
-
-    // return the fraction of the total time this command consumed
-    double time(int index) const { return ((SkTimedPicturePlayback*) fData.get())->time(index); }
-
-    const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback*) fData.get())->typeTimes(); }
-
-    double totTime() const { return ((SkTimedPicturePlayback*) fData.get())->totTime(); }
-
-private:
-    // disallow default ctor b.c. we don't have a good way to setup the fData ptr
-    SkTimedPicture();
-    // Private ctor only used by CreateTimedPicture, which has created the playback.
-    SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
-        : INHERITED(playback, width, height) {}
-    // disallow the copy ctor - enabling would require copying code from SkPicture
-    SkTimedPicture(const SkTimedPicture& src);
-
-    typedef SkPicture INHERITED;
-};
-#endif
-
 // This is a simplification of PictureBenchmark's run with the addition of
 // clearing of the times after the first pass (in resetTimes)
 void SkDebuggerGUI::run(const SkPicture* pict,
@@ -362,11 +176,6 @@ void SkDebuggerGUI::run(const SkPicture* pict,
     renderer->render();
     renderer->resetState(true);    // flush, swapBuffers and Finish
 
-#if 0
-    // We throw this away the first batch of times to remove first time effects (such as paging in this program)
-    pict->resetTimes();
-#endif
-
     for (int i = 0; i < repeats; ++i) {
         renderer->setup();
         renderer->render();
@@ -399,60 +208,6 @@ void SkDebuggerGUI::actionProfile() {
     if (NULL == picture.get()) {
         return;
     }
-
-
-#if 0
-
-    // For now this #if allows switching between tiled and simple rendering
-    // modes. Eventually this will be accomplished via the GUI
-#if 0
-    // With the current batch of SysTimers, profiling in tiled mode
-    // gets swamped by the timing overhead:
-    //
-    //                       tile mode           simple mode
-    // debugger                64.2ms              12.8ms
-    // bench_pictures          16.9ms              12.4ms
-    //
-    // This is b.c. in tiled mode each command is called many more times
-    // but typically does less work on each invocation (due to clipping)
-    sk_tools::TiledPictureRenderer* renderer = NULL;
-
-    renderer = SkNEW(sk_tools::TiledPictureRenderer);
-    renderer->setTileWidth(256);
-    renderer->setTileHeight(256);
-#else
-    sk_tools::SimplePictureRenderer* renderer = NULL;
-
-    renderer = SkNEW(sk_tools::SimplePictureRenderer);
-
-#if SK_SUPPORT_GPU
-    if (fSettingsWidget.isGLActive()) {
-        renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
-        renderer->setSampleCount(fSettingsWidget.getGLSampleCount());
-    }
-#endif
-
-#endif
-
-    static const int kNumRepeats = 10;
-
-    run(picture.get(), renderer, kNumRepeats);
-
-    SkASSERT(picture->count() == fListWidget.count());
-
-    // extract the individual command times from the SkTimedPlaybackPicture
-    for (int i = 0; i < picture->count(); ++i) {
-        double temp = picture->time(i);
-
-        QListWidgetItem* item = fListWidget.item(i);
-
-        item->setData(Qt::UserRole + 4, 100.0*temp);
-    }
-
-    setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
-    setupClipStackText();
-
-#endif
 }
 
 void SkDebuggerGUI::actionCancel() {
index 4bef2b0..c4c6f20 100644 (file)
@@ -24,7 +24,6 @@ class SkBBoxHierarchy;
 class SkCanvas;
 class SkData;
 class SkPictureData;
-class SkPictureRecord;
 class SkStream;
 class SkWStream;
 
@@ -254,47 +253,24 @@ private:
     static const uint32_t MIN_PICTURE_VERSION = 19;
     static const uint32_t CURRENT_PICTURE_VERSION = 37;
 
-    mutable uint32_t      fUniqueID;
-
-    SkAutoTDelete<const SkPictureData>    fData;
-    const SkScalar                        fCullWidth;
-    const SkScalar                        fCullHeight;
-    mutable SkAutoTUnref<const AccelData> fAccelData;
-
-    mutable SkTDArray<DeletionListener*> fDeletionListeners;  // pointers are refed
-
     void needsNewGenID() { fUniqueID = SK_InvalidGenID; }
     void callDeletionListeners();
 
-    // Create a new SkPicture from an existing SkPictureData. The new picture
-    // takes ownership of 'data'.
-    SkPicture(SkPictureData* data, SkScalar width, SkScalar height);
-
-    SkPicture(SkScalar width, SkScalar height, const SkPictureRecord& record, bool deepCopyOps);
-
     void createHeader(SkPictInfo* info) const;
     static bool IsValidPictInfo(const SkPictInfo& info);
 
-    friend class SkPictureRecorder;            // SkRecord-based constructor.
-    friend class SkGpuDevice;                  // for fData access
-    friend class GrLayerHoister;               // access to fRecord
-    friend class SkPicturePlayback;            // to get fData
-    friend class ReplaceDraw;
-
-    typedef SkRefCnt INHERITED;
-
     // Takes ownership of the SkRecord, refs the (optional) BBH.
     SkPicture(SkScalar width, SkScalar height, SkRecord*, SkBBoxHierarchy*);
-    // Return as a new SkPicture that's backed by SkRecord.
-    static SkPicture* Forwardport(const SkPicture&);
-    // Return as a new SkPicture that's backed by the old backend.
-    static SkPicture* Backport(const SkRecord& src, const SkRect& cullRect);
 
+    static SkPicture* Forwardport(const SkPictInfo&, const SkPictureData*);
+    static SkPictureData* Backport(const SkRecord&, const SkPictInfo&);
+
+    const SkScalar                        fCullWidth;
+    const SkScalar                        fCullHeight;
+    mutable SkAutoTUnref<const AccelData> fAccelData;
+    mutable SkTDArray<DeletionListener*> fDeletionListeners;  // pointers are refed
     SkAutoTDelete<SkRecord>       fRecord;
     SkAutoTUnref<SkBBoxHierarchy> fBBH;
-
-    struct PathCounter;
-
     struct Analysis {
         Analysis() {}  // Only used by SkPictureData codepath.
         explicit Analysis(const SkRecord&);
@@ -309,6 +285,15 @@ private:
         int         fNumAAHairlineConcavePaths;
         int         fNumAADFEligibleConcavePaths;
     } fAnalysis;
+    mutable uint32_t fUniqueID;
+
+    struct PathCounter;
+
+    friend class SkPictureRecorder;            // SkRecord-based constructor.
+    friend class GrLayerHoister;               // access to fRecord
+    friend class ReplaceDraw;
+
+    typedef SkRefCnt INHERITED;
 };
 
 #endif
index 5231cb9..e2514c6 100644 (file)
@@ -257,41 +257,14 @@ bool SkPicture::Analysis::suitableForGpuRasterization(const char** reason,
 
 ///////////////////////////////////////////////////////////////////////////////
 
-// fRecord OK
-SkPicture::SkPicture(SkScalar width, SkScalar height,
-                     const SkPictureRecord& record,
-                     bool deepCopyOps)
-    : fCullWidth(width)
-    , fCullHeight(height)
-    , fAnalysis() {
-    this->needsNewGenID();
-
-    SkPictInfo info;
-    this->createHeader(&info);
-    fData.reset(SkNEW_ARGS(SkPictureData, (record, info, deepCopyOps)));
-}
-
-// Create an SkPictureData-backed SkPicture from an SkRecord.
-// This for compatibility with serialization code only.  This is not cheap.
-SkPicture* SkPicture::Backport(const SkRecord& src, const SkRect& cullRect) {
-    SkPictureRecord rec(SkISize::Make(cullRect.width(), cullRect.height()), 0/*flags*/);
-    rec.beginRecording();
-        SkRecordDraw(src, &rec, NULL/*bbh*/, NULL/*callback*/);
-    rec.endRecording();
-    return SkNEW_ARGS(SkPicture, (cullRect.width(), cullRect.height(), rec, false/*deepCopyOps*/));
-}
-
-// fRecord OK
 SkPicture::~SkPicture() {
     this->callDeletionListeners();
 }
 
-// fRecord OK
 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) const {
     fAccelData.reset(SkRef(data));
 }
 
-// fRecord OK
 const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData(
         SkPicture::AccelData::Key key) const {
     if (fAccelData.get() && fAccelData->getKey() == key) {
@@ -300,7 +273,6 @@ const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData(
     return NULL;
 }
 
-// fRecord OK
 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() {
     static int32_t gNextID = 0;
 
@@ -314,23 +286,15 @@ SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() {
 
 ///////////////////////////////////////////////////////////////////////////////
 
-// fRecord OK
 void SkPicture::playback(SkCanvas* canvas, SkDrawPictureCallback* callback) const {
     SkASSERT(canvas);
-    SkASSERT(fData.get() || fRecord.get());
 
-    if (fData.get()) {
-        SkPicturePlayback playback(this);
-        playback.draw(canvas, callback);
-    }
-    if (fRecord.get()) {
-        // If the query contains the whole picture, don't bother with the BBH.
-        SkRect clipBounds = { 0, 0, 0, 0 };
-        (void)canvas->getClipBounds(&clipBounds);
-        const bool useBBH = !clipBounds.contains(this->cullRect());
+    // If the query contains the whole picture, don't bother with the BBH.
+    SkRect clipBounds = { 0, 0, 0, 0 };
+    (void)canvas->getClipBounds(&clipBounds);
+    const bool useBBH = !clipBounds.contains(this->cullRect());
 
-        SkRecordDraw(*fRecord, canvas, useBBH ? fBBH.get() : NULL, callback);
-    }
+    SkRecordDraw(*fRecord, canvas, useBBH ? fBBH.get() : NULL, callback);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -339,7 +303,6 @@ void SkPicture::playback(SkCanvas* canvas, SkDrawPictureCallback* callback) cons
 
 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' };
 
-// fRecord OK
 bool SkPicture::IsValidPictInfo(const SkPictInfo& info) {
     if (0 != memcmp(info.fMagic, kMagic, sizeof(kMagic))) {
         return false;
@@ -353,7 +316,6 @@ bool SkPicture::IsValidPictInfo(const SkPictInfo& info) {
     return true;
 }
 
-// fRecord OK
 bool SkPicture::InternalOnly_StreamIsSKP(SkStream* stream, SkPictInfo* pInfo) {
     if (NULL == stream) {
         return false;
@@ -397,7 +359,6 @@ bool SkPicture::InternalOnly_StreamIsSKP(SkStream* stream, SkPictInfo* pInfo) {
     return true;
 }
 
-// fRecord OK
 bool SkPicture::InternalOnly_BufferIsSKP(SkReadBuffer* buffer, SkPictInfo* pInfo) {
     // Check magic bytes.
     SkPictInfo info;
@@ -434,66 +395,36 @@ bool SkPicture::InternalOnly_BufferIsSKP(SkReadBuffer* buffer, SkPictInfo* pInfo
     return true;
 }
 
-// fRecord OK
-SkPicture::SkPicture(SkPictureData* data, SkScalar width, SkScalar height)
-    : fData(data)
-    , fCullWidth(width)
-    , fCullHeight(height)
-    , fAnalysis() {
-    this->needsNewGenID();
-}
-
-SkPicture* SkPicture::Forwardport(const SkPicture& src) {
-    SkAutoTDelete<SkRecord> record(SkNEW(SkRecord));
-    SkRecorder canvas(record.get(), src.cullRect().width(), src.cullRect().height());
-    src.playback(&canvas);
-    return SkNEW_ARGS(SkPicture, (src.cullRect().width(), src.cullRect().height(),
-                                  record.detach(), NULL/*bbh*/));
+SkPicture* SkPicture::Forwardport(const SkPictInfo& info, const SkPictureData* data) {
+    if (!data) {
+        return NULL;
+    }
+    SkPicturePlayback playback(data);
+    SkPictureRecorder r;
+    playback.draw(r.beginRecording(SkScalarCeilToInt(info.fCullRect.width()),
+                                   SkScalarCeilToInt(info.fCullRect.height())),
+                  NULL/*no callback*/);
+    return r.endRecording();
 }
 
-// fRecord OK
 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc proc) {
     SkPictInfo info;
-
-    if (!InternalOnly_StreamIsSKP(stream, &info)) {
+    if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) {
         return NULL;
     }
-
-    // Check to see if there is a playback to recreate.
-    if (stream->readBool()) {
-        SkPictureData* data = SkPictureData::CreateFromStream(stream, info, proc);
-        if (NULL == data) {
-            return NULL;
-        }
-        const SkPicture src(data, info.fCullRect.width(), info.fCullRect.height());
-        return Forwardport(src);
-    }
-
-    return NULL;
+    SkAutoTDelete<SkPictureData> data(SkPictureData::CreateFromStream(stream, info, proc));
+    return Forwardport(info, data);
 }
 
-// fRecord OK
 SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) {
     SkPictInfo info;
-
-    if (!InternalOnly_BufferIsSKP(&buffer, &info)) {
+    if (!InternalOnly_BufferIsSKP(&buffer, &info) || !buffer.readBool()) {
         return NULL;
     }
-
-    // Check to see if there is a playback to recreate.
-    if (buffer.readBool()) {
-        SkPictureData* data = SkPictureData::CreateFromBuffer(buffer, info);
-        if (NULL == data) {
-            return NULL;
-        }
-        const SkPicture src(data, info.fCullRect.width(), info.fCullRect.height());
-        return Forwardport(src);
-    }
-
-    return NULL;
+    SkAutoTDelete<SkPictureData> data(SkPictureData::CreateFromBuffer(buffer, info));
+    return Forwardport(info, data);
 }
 
-// fRecord OK
 void SkPicture::createHeader(SkPictInfo* info) const {
     // Copy magic bytes at the beginning of the header
     SkASSERT(sizeof(kMagic) == 8);
@@ -512,23 +443,22 @@ void SkPicture::createHeader(SkPictInfo* info) const {
     }
 }
 
-// fRecord OK
-void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
-    const SkPictureData* data = fData.get();
+// This for compatibility with serialization code only.  This is not cheap.
+SkPictureData* SkPicture::Backport(const SkRecord& src, const SkPictInfo& info) {
+    SkPictureRecord rec(SkISize::Make(info.fCullRect.width(), info.fCullRect.height()), 0/*flags*/);
+    rec.beginRecording();
+        SkRecordDraw(src, &rec, NULL/*bbh*/, NULL/*callback*/);
+    rec.endRecording();
+    return SkNEW_ARGS(SkPictureData, (rec, info, false/*deep copy ops?*/));
+}
 
-    // If we're a new-format picture, backport to old format for serialization.
-    SkAutoTDelete<SkPicture> oldFormat;
-    if (NULL == data && fRecord.get()) {
-        oldFormat.reset(Backport(*fRecord, this->cullRect()));
-        data = oldFormat->fData.get();
-        SkASSERT(data);
-    }
 
+void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
     SkPictInfo info;
     this->createHeader(&info);
-    SkASSERT(sizeof(SkPictInfo) == 32);
-    stream->write(&info, sizeof(info));
+    SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info));
 
+    stream->write(&info, sizeof(info));
     if (data) {
         stream->writeBool(true);
         data->serialize(stream, encoder);
@@ -537,25 +467,15 @@ void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
     }
 }
 
-// fRecord OK
 void SkPicture::flatten(SkWriteBuffer& buffer) const {
-    const SkPictureData* data = fData.get();
-
-    // If we're a new-format picture, backport to old format for serialization.
-    SkAutoTDelete<SkPicture> oldFormat;
-    if (NULL == data && fRecord.get()) {
-        oldFormat.reset(Backport(*fRecord, this->cullRect()));
-        data = oldFormat->fData.get();
-        SkASSERT(data);
-    }
-
     SkPictInfo info;
     this->createHeader(&info);
+    SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info));
+
     buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic));
     buffer.writeUInt(info.fVersion);
     buffer.writeRect(info.fCullRect);
     buffer.writeUInt(info.fFlags);
-
     if (data) {
         buffer.writeBool(true);
         data->flatten(buffer);
@@ -565,51 +485,19 @@ void SkPicture::flatten(SkWriteBuffer& buffer) const {
 }
 
 #if SK_SUPPORT_GPU
-// fRecord OK
-bool SkPicture::suitableForGpuRasterization(GrContext* context, const char **reason) const {
-    if (fRecord.get()) {
-        return fAnalysis.suitableForGpuRasterization(reason, 0);
-    }
-    if (NULL == fData.get()) {
-        if (reason) {
-            *reason = "Missing internal data.";
-        }
-        return false;
-    }
-
-    return fData->suitableForGpuRasterization(context, reason);
+bool SkPicture::suitableForGpuRasterization(GrContext*, const char **reason) const {
+    return fAnalysis.suitableForGpuRasterization(reason, 0);
 }
 #endif
 
-// fRecord OK
-bool SkPicture::hasText() const {
-    if (fRecord.get()) {
-        return fAnalysis.fHasText;
-    }
-    if (fData.get()) {
-        return fData->hasText();
-    }
-    SkFAIL("Unreachable");
-    return false;
-}
+bool SkPicture::hasText()             const { return fAnalysis.fHasText; }
+bool SkPicture::willPlayBackBitmaps() const { return fAnalysis.fWillPlaybackBitmaps; }
+int  SkPicture::approximateOpCount()  const { return fRecord->count(); }
 
-// fRecord OK
-bool SkPicture::willPlayBackBitmaps() const {
-    if (fRecord.get()) {
-        return fAnalysis.fWillPlaybackBitmaps;
-    }
-    if (fData.get()) {
-        return fData->containsBitmaps();
-    }
-    SkFAIL("Unreachable");
-    return false;
-}
+static int32_t gPictureGenerationID = SK_InvalidGenID;  // This will be set at link time.
 
-// fRecord OK
 static int32_t next_picture_generation_id() {
-    static int32_t  gPictureGenerationID = 0;
-    // do a loop in case our global wraps around, as we never want to
-    // return a 0
+    // Loop in case our global wraps around.
     int32_t genID;
     do {
         genID = sk_atomic_inc(&gPictureGenerationID) + 1;
@@ -617,7 +505,6 @@ static int32_t next_picture_generation_id() {
     return genID;
 }
 
-// fRecord OK
 uint32_t SkPicture::uniqueID() const {
     if (SK_InvalidGenID == fUniqueID) {
         fUniqueID = next_picture_generation_id();
@@ -625,7 +512,6 @@ uint32_t SkPicture::uniqueID() const {
     return fUniqueID;
 }
 
-// fRecord OK
 SkPicture::SkPicture(SkScalar width, SkScalar height, SkRecord* record, SkBBoxHierarchy* bbh)
     : fCullWidth(width)
     , fCullHeight(height)
@@ -652,15 +538,3 @@ void SkPicture::callDeletionListeners() {
 
     fDeletionListeners.unrefAll();
 }
-
-// fRecord OK
-int SkPicture::approximateOpCount() const {
-    SkASSERT(fRecord.get() || fData.get());
-    if (fRecord.get()) {
-        return fRecord->count();
-    }
-    if (fData.get()) {
-        return fData->opCount();
-    }
-    return 0;
-}
index 9e5db08..32d8c16 100644 (file)
@@ -19,8 +19,8 @@ class SkPictureData;
 // The basic picture playback class replays the provided picture into a canvas.
 class SkPicturePlayback : SkNoncopyable {
 public:
-    SkPicturePlayback(const SkPicture* picture)
-        : fPictureData(picture->fData.get())
+    SkPicturePlayback(const SkPictureData* data)
+        : fPictureData(data)
         , fCurOffset(0) {
     }
     virtual ~SkPicturePlayback() { }