Fixed up SkTimedPicturePlayback
authorrobertphillips <robertphillips@google.com>
Tue, 8 Jul 2014 20:07:57 +0000 (13:07 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 8 Jul 2014 20:07:57 +0000 (13:07 -0700)
This was more motivated to remove the preDraw and postDraw virtuals from SkPicturePlayback.

R=mtklein@google.com, reed@google.com

Author: robertphillips@google.com

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

debugger/QT/SkDebuggerGUI.cpp
src/core/SkPicturePlayback.cpp
src/core/SkPicturePlayback.h
src/core/SkPictureRangePlayback.cpp

index b6920a7..1a324fd 100644 (file)
@@ -156,9 +156,9 @@ void SkDebuggerGUI::showDeletes() {
     }
 }
 
-// The timed picture playback uses the SkPictureData's profiling stubs
-// to time individual commands. The offsets are needed to map SkPicture
-// offsets to individual commands.
+// 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:
 
@@ -172,6 +172,47 @@ public:
         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 (NULL != 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;
@@ -184,6 +225,7 @@ public:
 
     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; }
@@ -196,11 +238,11 @@ protected:
     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
 
-#ifdef SK_DEVELOPER
-    virtual bool preDraw(int opIndex, int type) SK_OVERRIDE {
+    bool preDraw(int opIndex, int type) {
         fCurCommand = opIndex;
 
         if (fSkipCommands[fCurCommand]) {
@@ -227,7 +269,7 @@ protected:
         return false;
     }
 
-    virtual void postDraw(int opIndex) SK_OVERRIDE {
+    void postDraw(int opIndex) {
 #if defined(SK_BUILD_FOR_WIN32)
         // CPU timer doesn't work well on Windows
         double time = fTimer.endWall();
@@ -242,7 +284,6 @@ protected:
         fTypeTimes[fCurType] += time;
         fTot += time;
     }
-#endif
 
 private:
     typedef SkPicturePlayback INHERITED;
index d8ed082..734a54a 100644 (file)
@@ -152,10 +152,6 @@ void SkPicturePlayback::draw(SkCanvas* canvas, SkDrawPictureCallback* callback)
 
     SkAutoCanvasRestore acr(canvas, false);
 
-#ifdef SK_DEVELOPER
-    int opIndex = -1;
-#endif
-
     while (!reader.eof()) {
         if (callback && callback->abortDrawing()) {
             return;
@@ -232,13 +228,6 @@ void SkPicturePlayback::draw(SkCanvas* canvas, SkDrawPictureCallback* callback)
         if (NOOP == op) {
             // NOOPs are to be ignored - do not propagate them any further
             skipTo = fCurOffset + size;
-#ifdef SK_DEVELOPER
-        } else {
-            opIndex++;
-            if (this->preDraw(opIndex, op)) {
-                skipTo = fCurOffset + size;
-            }
-#endif
         }
 
         if (0 != skipTo) {
@@ -260,10 +249,6 @@ void SkPicturePlayback::draw(SkCanvas* canvas, SkDrawPictureCallback* callback)
 
         this->handleOp(&reader, op, size, canvas, initialMatrix);
 
-#ifdef SK_DEVELOPER
-        this->postDraw(opIndex);
-#endif
-
         if (it.isValid()) {
             uint32_t skipTo = it.nextDraw();
             if (kDrawComplete == skipTo) {
index 7966670..4248e2d 100644 (file)
@@ -96,11 +96,6 @@ protected:
                   SkCanvas* canvas,
                   const SkMatrix& initialMatrix);
 
-#ifdef SK_DEVELOPER
-    virtual bool preDraw(int opIndex, int type) { return false; }
-    virtual void postDraw(int opIndex) { }
-#endif
-
     static DrawType ReadOpAndSize(SkReader32* reader, uint32_t* size);
 
     class AutoResetOpID {
index 16473db..b5e36d6 100644 (file)
@@ -29,7 +29,7 @@ void SkPictureRangePlayback::draw(SkCanvas* canvas, SkDrawPictureCallback* callb
     SkAutoCanvasRestore acr(canvas, false);
 
     while (!reader.eof()) {
-        if (callback && callback->abortDrawing()) {
+        if (NULL != callback && callback->abortDrawing()) {
             return;
         }