Fix unbound memory consumption problem with run away deferred canvases.

With this CL, deferred canvases will trigger a flush when then the 
memory allocated for recording commands (including flattened objects)
exceeds 64MB.

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

git-svn-id: http://skia.googlecode.com/svn/trunk@4714 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/utils/SkDeferredCanvas.h b/include/utils/SkDeferredCanvas.h
index 38ee678..5f4e992 100644
--- a/include/utils/SkDeferredCanvas.h
+++ b/include/utils/SkDeferredCanvas.h
@@ -85,6 +85,14 @@
      */
     void setDeferredDrawing(bool deferred);
 
+    /**
+     *  Specify the maximum number of bytes to be allocated for the purpose
+     *  of recording draw commands to this canvas.  The default limit, is
+     *  64MB.
+     *  @param maxStorage The maximum number of bytes to be allocated.
+     */
+    void setMaxRecordingStorage(size_t maxStorage);
+
     // Overrides of the SkCanvas interface
     virtual int save(SaveFlags flags) SK_OVERRIDE;
     virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
@@ -171,6 +179,7 @@
         void playback();
         void reset();
         bool hasRecorded() {return fAllocator.blockCount() != 0;}
+        size_t storageAllocatedForRecording() {return fAllocator.totalCapacity();}
     private:
         enum {
             kMinBlockSize = 4096
@@ -212,7 +221,7 @@
         /**
          *  Returns the recording canvas.
          */
-        SkCanvas* recordingCanvas() const {return fRecordingCanvas;}
+        SkCanvas* recordingCanvas();
 
         /**
          *  Returns the immediate (non deferred) canvas.
@@ -233,6 +242,7 @@
         void flushPending();
         void contentsCleared();
         void flushIfNeeded(const SkBitmap& bitmap);
+        void setMaxRecordingStorage(size_t);
 
         virtual uint32_t getDeviceCapabilities() SK_OVERRIDE;
         virtual int width() const SK_OVERRIDE;
@@ -330,6 +340,7 @@
         SkCanvas* fRecordingCanvas;
         DeviceContext* fDeviceContext;
         bool fFreshFrame;
+        size_t fMaxRecordingStorageBytes;
     };
 
     DeferredDevice* getDeferredDevice() const;