Staged removal of SkPicture-derived classes

This CL removes the SkPicture-derived classes (with a flag to keeps clients working). In the process it also lightens the recording factory function so it is no longer ref counted).

The only interesting bits are in SkPicture* and Sk*Picture.*

R=reed@google.com

Author: robertphillips@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@14251 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index 8aedc15..cd87f60 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -274,9 +274,10 @@
 void PictureRenderer::buildBBoxHierarchy() {
     SkASSERT(NULL != fPicture);
     if (kNone_BBoxHierarchyType != fBBoxHierarchyType && NULL != fPicture) {
-        SkAutoTUnref<SkPictureFactory> factory(this->getFactory());
-        SkPictureRecorder recorder(factory);
+        SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
+        SkPictureRecorder recorder;
         SkCanvas* canvas = recorder.beginRecording(fPicture->width(), fPicture->height(),
+                                                   factory.get(),
                                                    this->recordFlags());
         fPicture->draw(canvas);
         fPicture.reset(recorder.endRecording());
@@ -435,9 +436,10 @@
 }
 
 bool RecordPictureRenderer::render(SkBitmap** out) {
-    SkAutoTUnref<SkPictureFactory> factory(this->getFactory());
-    SkPictureRecorder recorder(factory);
+    SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
+    SkPictureRecorder recorder;
     SkCanvas* canvas = recorder.beginRecording(this->getViewWidth(), this->getViewHeight(),
+                                               factory.get(),
                                                this->recordFlags());
     this->scaleToScaleFactor(canvas);
     fPicture->draw(canvas);
@@ -954,9 +956,10 @@
 ///////////////////////////////////////////////////////////////////////////////////////////////
 
 void PlaybackCreationRenderer::setup() {
-    SkAutoTUnref<SkPictureFactory> factory(this->getFactory());
-    fRecorder.reset(SkNEW_ARGS(SkPictureRecorder, (factory)));
+    SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
+    fRecorder.reset(SkNEW(SkPictureRecorder));
     SkCanvas* canvas = fRecorder->beginRecording(this->getViewWidth(), this->getViewHeight(),
+                                                 factory.get(),
                                                  this->recordFlags());
     this->scaleToScaleFactor(canvas);
     canvas->drawPicture(*fPicture);
@@ -975,16 +978,16 @@
 ///////////////////////////////////////////////////////////////////////////////////////////////
 // SkPicture variants for each BBoxHierarchy type
 
-SkPictureFactory* PictureRenderer::getFactory() {
+SkBBHFactory* PictureRenderer::getFactory() {
     switch (fBBoxHierarchyType) {
         case kNone_BBoxHierarchyType:
             return NULL;
         case kQuadTree_BBoxHierarchyType:
-            return SkNEW(SkQuadTreePictureFactory);
+            return SkNEW(SkQuadTreeFactory);
         case kRTree_BBoxHierarchyType:
-            return SkNEW(SkRTreePictureFactory);
+            return SkNEW(SkRTreeFactory);
         case kTileGrid_BBoxHierarchyType:
-            return new SkTileGridPictureFactory(fGridInfo);
+            return SkNEW_ARGS(SkTileGridFactory, (fGridInfo));
     }
     SkASSERT(0); // invalid bbhType
     return NULL;
diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h
index 4c5b426..a8c0cc5 100644
--- a/tools/PictureRenderer.h
+++ b/tools/PictureRenderer.h
@@ -409,7 +409,7 @@
     SkString               fDrawFiltersConfig;
     SkString               fOutputDir;
     SkString               fInputFilename;
-    SkTileGridPicture::TileGridInfo fGridInfo; // used when fBBoxHierarchyType is TileGrid
+    SkTileGridFactory::TileGridInfo fGridInfo; // used when fBBoxHierarchyType is TileGrid
 
     void buildBBoxHierarchy();
 
@@ -430,7 +430,7 @@
      */
     void scaleToScaleFactor(SkCanvas*);
 
-    SkPictureFactory* getFactory();
+    SkBBHFactory* getFactory();
     uint32_t recordFlags();
     SkCanvas* setupCanvas();
     virtual SkCanvas* setupCanvas(int width, int height);
diff --git a/tools/PictureRenderingFlags.cpp b/tools/PictureRenderingFlags.cpp
index 0c4bc75..5acec26 100644
--- a/tools/PictureRenderingFlags.cpp
+++ b/tools/PictureRenderingFlags.cpp
@@ -135,7 +135,9 @@
         // Allow 'mode' to be set to 'simple', but do not create a renderer, so we can
         // ensure that pipe does not override a mode besides simple. The renderer will
         // be created below.
-        } else if (0 != strcmp(mode, "simple")) {
+        } else if (0 == strcmp(mode, "simple")) {
+            gridSupported = true;
+        } else {
             error.printf("%s is not a valid mode for --mode\n", mode);
             return NULL;
         }
diff --git a/tools/bench_record.cpp b/tools/bench_record.cpp
index 0798de2..65198fa 100644
--- a/tools/bench_record.cpp
+++ b/tools/bench_record.cpp
@@ -34,50 +34,29 @@
 DEFINE_string(bbh, "", "Turn on the bbh and select the type, one of rtree, tilegrid, quadtree");
 DEFINE_bool(skr, false, "Record SKR instead of SKP.");
 
-typedef SkPictureFactory* (*PictureFactory)();
-
-static SkPictureFactory* vanilla_factory() {
-    return NULL;
-}
-
-static SkPictureFactory* rtree_factory() {
-    return SkNEW(SkRTreePictureFactory);
-}
-
-static SkPictureFactory* tilegrid_factory() {
-    SkTileGridPicture::TileGridInfo info;
-    info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize);
-    info.fMargin.setEmpty();
-    info.fOffset.setZero();
-    return SkNEW_ARGS(SkTileGridPictureFactory, (info));
-}
-
-static SkPictureFactory* quadtree_factory() {
-    return SkNEW(SkQuadTreePictureFactory);
-}
-
-static PictureFactory parse_FLAGS_bbh() {
+static SkBBHFactory* parse_FLAGS_bbh() {
     if (FLAGS_bbh.isEmpty()) {
-        return &vanilla_factory;
-    }
-    if (FLAGS_bbh.count() != 1) {
-        SkDebugf("Multiple bbh arguments supplied.\n");
         return NULL;
     }
+
     if (FLAGS_bbh.contains("rtree")) {
-        return rtree_factory;
+        return SkNEW(SkRTreeFactory);
     }
     if (FLAGS_bbh.contains("tilegrid")) {
-        return tilegrid_factory;
+        SkTileGridFactory::TileGridInfo info;
+        info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize);
+        info.fMargin.setEmpty();
+        info.fOffset.setZero();
+        return SkNEW_ARGS(SkTileGridFactory, (info));
     }
     if (FLAGS_bbh.contains("quadtree")) {
-        return quadtree_factory;
+        return SkNEW(SkQuadTreeFactory);
     }
     SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n", FLAGS_bbh[0]);
     return NULL;
 }
 
-static void bench_record(SkPicture* src, const char* name, PictureFactory pictureFactory) {
+static void bench_record(SkPicture* src, const char* name, SkBBHFactory* bbhFactory) {
     const SkMSec start = SkTime::GetMSecs();
     const int width  = src ? src->width()  : FLAGS_nullSize;
     const int height = src ? src->height() : FLAGS_nullSize;
@@ -91,10 +70,8 @@
             }
             SkDELETE(SkRecording::Delete(recording));  // delete the SkPlayback*.
         } else {
-            int recordingFlags = FLAGS_flags;
-            SkAutoTUnref<SkPictureFactory> factory(pictureFactory());
-            SkPictureRecorder recorder(factory);
-            SkCanvas* canvas = recorder.beginRecording(width, height, recordingFlags);
+            SkPictureRecorder recorder;
+            SkCanvas* canvas = recorder.beginRecording(width, height, bbhFactory, FLAGS_flags);
             if (NULL != src) {
                 src->draw(canvas);
             }
@@ -114,11 +91,13 @@
     SkCommandLineFlags::Parse(argc, argv);
     SkAutoGraphics autoGraphics;
 
-    PictureFactory pictureFactory = parse_FLAGS_bbh();
-    if (pictureFactory == NULL) {
+    if (FLAGS_bbh.count() > 1) {
+        SkDebugf("Multiple bbh arguments supplied.\n");
         return 1;
     }
-    bench_record(NULL, "NULL", pictureFactory);
+
+    SkAutoTDelete<SkBBHFactory> bbhFactory(parse_FLAGS_bbh());
+    bench_record(NULL, "NULL", bbhFactory.get());
     if (FLAGS_skps.isEmpty()) {
         return 0;
     }
@@ -142,7 +121,7 @@
             failed = true;
             continue;
         }
-        bench_record(src, filename.c_str(), pictureFactory);
+        bench_record(src, filename.c_str(), bbhFactory.get());
     }
     return failed ? 1 : 0;
 }
diff --git a/tools/filtermain.cpp b/tools/filtermain.cpp
index b61e15d..ecd1eee 100644
--- a/tools/filtermain.cpp
+++ b/tools/filtermain.cpp
@@ -718,7 +718,7 @@
 
     if (!outFile.isEmpty()) {
         SkPictureRecorder recorder;
-        SkCanvas* canvas = recorder.beginRecording(inPicture->width(), inPicture->height());
+        SkCanvas* canvas = recorder.beginRecording(inPicture->width(), inPicture->height(), NULL, 0);
         debugCanvas.draw(canvas);
         SkAutoTUnref<SkPicture> outPicture(recorder.endRecording());
 
diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp
index 0e68117..444efd0 100644
--- a/tools/render_pictures_main.cpp
+++ b/tools/render_pictures_main.cpp
@@ -173,9 +173,8 @@
     }
 
     while (FLAGS_bench_record) {
-        const int kRecordFlags = 0;
         SkPictureRecorder recorder;
-        picture->draw(recorder.beginRecording(picture->width(), picture->height(), kRecordFlags));
+        picture->draw(recorder.beginRecording(picture->width(), picture->height(), NULL, 0));
         SkAutoTUnref<SkPicture> other(recorder.endRecording());
     }
 
diff --git a/tools/skpmaker.cpp b/tools/skpmaker.cpp
index 740d522..0d46d04 100644
--- a/tools/skpmaker.cpp
+++ b/tools/skpmaker.cpp
@@ -27,7 +27,7 @@
 static void skpmaker(int width, int height, int border, SkColor color,
                      const char *writePath) {
     SkPictureRecorder recorder;
-    SkCanvas* canvas = recorder.beginRecording(width, height);
+    SkCanvas* canvas = recorder.beginRecording(width, height, NULL, 0);
     SkPaint paint;
     paint.setStyle(SkPaint::kFill_Style);
     paint.setColor(SK_ColorBLACK);