Add return value on GrRecordReplaceDraw
authorrobertphillips <robertphillips@google.com>
Thu, 30 Oct 2014 18:54:31 +0000 (11:54 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 30 Oct 2014 18:54:31 +0000 (11:54 -0700)
This assists debugging layer hoisting errors (e.g., when a layer is hoisted but not actually used in subsequent rendering).

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

src/gpu/GrRecordReplaceDraw.cpp
src/gpu/GrRecordReplaceDraw.h

index b069e60f6e98a4c15639043b1513d414c98f0ac4..e4cc00696def6efc77a18ec282c8cbe6ae275642 100644 (file)
@@ -66,16 +66,19 @@ public:
         , fReplacements(replacements)
         , fInitialMatrix(initialMatrix)
         , fCallback(callback)
-        , fIndex(0) {
+        , fIndex(0)
+        , fNumReplaced(0) {
     }
 
-    void draw() {
+    int draw() {
         const SkBBoxHierarchy* bbh = fPicture->fBBH.get();
         const SkRecord* record = fPicture->fRecord.get();
         if (NULL == record) {
-            return;
+            return 0;
         }
 
+        fNumReplaced = 0;
+
         fOps.rewind();
 
         if (bbh) {
@@ -91,7 +94,7 @@ public:
 
             for (fIndex = 0; fIndex < fOps.count(); ++fIndex) {
                 if (fCallback && fCallback->abortDrawing()) {
-                    return;
+                    return fNumReplaced;
                 }
 
                 record->visit<void>(fOps[fIndex], *this);
@@ -100,12 +103,14 @@ public:
         } else {
             for (fIndex = 0; fIndex < (int) record->count(); ++fIndex) {
                 if (fCallback && fCallback->abortDrawing()) {
-                    return;
+                    return fNumReplaced;
                 }
 
                 record->visit<void>(fIndex, *this);
             }
         }
+
+        return fNumReplaced;
     }
 
     // Same as Draw for all ops except DrawPicture and SaveLayer.
@@ -118,7 +123,7 @@ public:
         // Draw sub-pictures with the same replacement list but a different picture
         ReplaceDraw draw(fCanvas, dp.picture, fReplacements, fInitialMatrix, fCallback);
 
-        draw.draw();
+        fNumReplaced += draw.draw();
     }
     void operator()(const SkRecords::SaveLayer& sl) {
 
@@ -131,12 +136,14 @@ public:
             startOffset = fIndex;
         }
 
+        const SkMatrix& ctm = fCanvas->getTotalMatrix();
         const GrReplacements::ReplacementInfo* ri = fReplacements->lookupByStart(
                                                             fPicture->uniqueID(),
                                                             startOffset,
-                                                            fCanvas->getTotalMatrix());
+                                                            ctm);
 
         if (ri) {
+            fNumReplaced++;
             draw_replacement_bitmap(ri, fCanvas, fInitialMatrix);
 
             if (fPicture->fBBH.get()) {
@@ -163,18 +170,19 @@ private:
 
     SkTDArray<unsigned>    fOps;
     int                    fIndex;
+    int                    fNumReplaced;
 
     typedef Draw INHERITED;
 };
 
-void GrRecordReplaceDraw(const SkPicture* picture,
-                         SkCanvas* canvas,
-                         const GrReplacements* replacements,
-                         const SkMatrix& initialMatrix,
-                         SkDrawPictureCallback* callback) {
+int GrRecordReplaceDraw(const SkPicture* picture,
+                        SkCanvas* canvas,
+                        const GrReplacements* replacements,
+                        const SkMatrix& initialMatrix,
+                        SkDrawPictureCallback* callback) {
     SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
 
     ReplaceDraw draw(canvas, picture, replacements, initialMatrix, callback);
 
-    draw.draw();
+    return draw.draw();
 }
index b47b0774155aa62847150deab85330da686640a1..9110ac82f9e09884b355cf7a2ba2b0d472fa61d4 100644 (file)
@@ -101,10 +101,11 @@ private:
 
 // Draw an SkPicture into an SkCanvas replacing saveLayer/restore blocks with
 // drawBitmap calls.  A convenience wrapper around SkRecords::Draw.
-void GrRecordReplaceDraw(const SkPicture*,
-                         SkCanvas*,
-                         const GrReplacements*,
-                         const SkMatrix& initialMatrix,
-                         SkDrawPictureCallback*);
+// It returns the number of saveLayer/restore blocks replaced with drawBitmap calls.
+int GrRecordReplaceDraw(const SkPicture*,
+                        SkCanvas*,
+                        const GrReplacements*,
+                        const SkMatrix& initialMatrix,
+                        SkDrawPictureCallback*);
 
 #endif // GrRecordReplaceDraw_DEFINED