Change where layer hoisting data is gathered

This CL:
1) removes the EXPERIMENTAL_optimize on SkCanvas & SkDevice
2) moves the saveLayer gathering step to endRecording
3) Replaces GPUOptimize with SkRecordComputeLayers
4) Update bench_pictures & render_pictures to provide the new flag

#2 also necessitated moving the BBH computation (and record optimization) out of SkPicture's ctor (and into endRecording)

Review URL: https://codereview.chromium.org/718443002
diff --git a/src/gpu/GrPictureUtils.cpp b/src/gpu/GrPictureUtils.cpp
index e1a70ab..c0b53f9 100644
--- a/src/gpu/GrPictureUtils.cpp
+++ b/src/gpu/GrPictureUtils.cpp
@@ -7,6 +7,7 @@
 
 #include "GrPictureUtils.h"
 
+#include "SkBBoxHierarchy.h"
 #include "SkPaintPriv.h"
 #include "SkPatchUtils.h"
 #include "SkRecord.h"
@@ -61,6 +62,10 @@
             this->popSaveLayerInfo();
         }
         //--------- LAYER HOISTING
+
+        // Finally feed all stored bounds into the BBH.  They'll be returned in this order.
+        SkASSERT(bbh);
+        bbh->insert(&fBounds, record.count());
     }
 
     template <typename T> void operator()(const T& op) {
@@ -425,7 +430,13 @@
         const GrAccelData* childData = 
             static_cast<const GrAccelData*>(dp.picture->EXPERIMENTAL_getAccelData(key));
         if (!childData) {
-            childData = GPUOptimize(dp.picture);
+            // If the child layer hasn't been generated with saveLayer data we
+            // assume the worst (i.e., that it does contain layers which nest
+            // inside existing layers). Layers within sub-pictures that don't
+            // have saveLayer data cannot be hoisted.
+            // TODO: could the analysis data be use to fine tune this?
+            this->updateStackForSaveLayer();
+            return;
         }
 
         for (int i = 0; i < childData->numSaveLayers(); ++i) {
@@ -587,31 +598,9 @@
 
 } // namespace SkRecords
 
-
 void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record,
                            SkBBoxHierarchy* bbh, GrAccelData* data) {
-
     SkRecords::CollectLayers collector(cullRect, record, bbh, data);
 }
 
-const GrAccelData* GPUOptimize(const SkPicture* pict) {
-    if (NULL == pict || pict->cullRect().isEmpty()) {
-        return NULL;
-    }
 
-    SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey();
-
-    const GrAccelData* existing = 
-                            static_cast<const GrAccelData*>(pict->EXPERIMENTAL_getAccelData(key));
-    if (existing) {
-        return existing;
-    }
-
-    SkAutoTUnref<GrAccelData> data(SkNEW_ARGS(GrAccelData, (key)));
-
-    pict->EXPERIMENTAL_addAccelData(data);
-
-    SkRecordComputeLayers(pict->cullRect(), *pict->fRecord, NULL, data);
-
-    return data;
-}
diff --git a/src/gpu/GrPictureUtils.h b/src/gpu/GrPictureUtils.h
index 6aa277e..edd45db 100644
--- a/src/gpu/GrPictureUtils.h
+++ b/src/gpu/GrPictureUtils.h
@@ -79,6 +79,4 @@
 void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record,
                            SkBBoxHierarchy* bbh, GrAccelData* data);
 
-const GrAccelData* GPUOptimize(const SkPicture* pict);
-
 #endif // GrPictureUtils_DEFINED
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index b072142..06f6eb7 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1789,25 +1789,6 @@
     return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples(), &props);
 }
 
-void SkGpuDevice::EXPERIMENTAL_optimize(const SkPicture* picture) {
-    fContext->getLayerCache()->processDeletedPictures();
-
-    if (picture->fData.get() && !picture->fData->suitableForLayerOptimization()) {
-        return;
-    }
-
-    SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey();
-
-    const SkPicture::AccelData* existing = picture->EXPERIMENTAL_getAccelData(key);
-    if (existing) {
-        return;
-    }
-
-    GPUOptimize(picture);
-
-    fContext->getLayerCache()->trackPicture(picture);
-}
-
 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture* mainPicture,
                                            const SkMatrix* matrix, const SkPaint* paint) {
     // todo: should handle these natively
@@ -1815,6 +1796,13 @@
         return false;
     }
 
+    SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey();
+
+    const SkPicture::AccelData* data = mainPicture->EXPERIMENTAL_getAccelData(key);
+    if (!data) {
+        return false;
+    }
+
     SkRect clipBounds;
     if (!mainCanvas->getClipBounds(&clipBounds)) {
         return true;
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index 6bba974..f7ff8c8 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -121,8 +121,6 @@
     virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) SK_OVERRIDE;
 
     /**  PRIVATE / EXPERIMENTAL -- do not call */
-    virtual void EXPERIMENTAL_optimize(const SkPicture* picture) SK_OVERRIDE;
-    /**  PRIVATE / EXPERIMENTAL -- do not call */
     virtual bool EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* picture,
                                           const SkMatrix*, const SkPaint*) SK_OVERRIDE;