Refactoring how SkDeferredCanvas manages mutable bitmaps

This CL makes the SkGPipe flavor of SkDeferredCanvas properly
decide whether to flush or record mutable bitmaps.  The flushing
is now managed by conditionally switching the canvas to non-deferred
mode, which avoids an unnecessary transient copy of the bitmap.

BUG=http://code.google.com/p/chromium/issues/detail?id=137884
TEST=DeferredCanvas unit test, sub test TestDeferredCanvasMemoryLimit
Review URL: https://codereview.appspot.com/6421060

git-svn-id: http://skia.googlecode.com/svn/trunk@4756 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/utils/SkDeferredCanvas.h b/include/utils/SkDeferredCanvas.h
index 829a72f..9adc332 100644
--- a/include/utils/SkDeferredCanvas.h
+++ b/include/utils/SkDeferredCanvas.h
@@ -86,6 +86,11 @@
     void setDeferredDrawing(bool deferred);
 
     /**
+     *  Returns true if deferred drawing is currenlty enabled.
+     */
+    bool isDeferredDrawing();
+
+    /**
      *  Specify the maximum number of bytes to be allocated for the purpose
      *  of recording draw commands to this canvas.  The default limit, is
      *  64MB.
@@ -153,9 +158,6 @@
     virtual SkBounder* setBounder(SkBounder* bounder) SK_OVERRIDE;
     virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE;
 
-private:
-    void flushIfNeeded(const SkBitmap& bitmap);
-
 public:
     class DeviceContext : public SkRefCnt {
     public:
@@ -241,9 +243,14 @@
 
         void flushPending();
         void contentsCleared();
-        void flushIfNeeded(const SkBitmap& bitmap);
         void setMaxRecordingStorage(size_t);
 
+        // FIXME: Temporary solution for tracking memory usage, pending
+        // resolution of http://code.google.com/p/skia/issues/detail?id=738
+#if SK_DEFERRED_CANVAS_USES_GPIPE
+        void accountForTempBitmapStorage(const SkBitmap& bitmap);
+#endif
+
         virtual uint32_t getDeviceCapabilities() SK_OVERRIDE;
         virtual int width() const SK_OVERRIDE;
         virtual int height() const SK_OVERRIDE;
@@ -332,6 +339,9 @@
 #if SK_DEFERRED_CANVAS_USES_GPIPE
         DeferredPipeController fPipeController;
         SkGPipeWriter  fPipeWriter;
+        // FIXME: Temporary solution for tracking memory usage, pending
+        // resolution of http://code.google.com/p/skia/issues/detail?id=738
+        size_t fTempBitmapStorage;
 #else
         SkPicture fPicture;
 #endif
@@ -349,6 +359,13 @@
     virtual SkCanvas* canvasForDrawIter();
 
 private:
+    // FIXME: Temporary solution for tracking memory usage, pending
+    // resolution of http://code.google.com/p/skia/issues/detail?id=738
+#if SK_DEFERRED_CANVAS_USES_GPIPE
+    friend class AutoImmediateDrawIfNeeded;
+    void accountForTempBitmapStorage(const SkBitmap& bitmap) const;
+#endif
+
     SkCanvas* drawingCanvas() const;
     bool isFullFrame(const SkRect*, const SkPaint*) const;
     void validate() const;