The motivation for this CL is to de-clutter SkPicture's beginRecording method.
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 4 Mar 2014 19:08:57 +0000 (19:08 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 4 Mar 2014 19:08:57 +0000 (19:08 +0000)
R=reed@google.com

Author: robertphillips@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13658 2bbb7eff-a529-9590-31e7-b0007b416f81

gm/optimizations.cpp
include/core/SkPicture.h
src/core/SkPicture.cpp
src/core/SkPictureRecord.cpp
src/core/SkPictureRecord.h

index a404ad7..ff88e3d 100644 (file)
@@ -82,8 +82,8 @@ static SkPicture* create_save_layer_opt_1(SkTDArray<DrawType>* preOptPattern,
     SkPicture* result = new SkPicture;
 
     // have to disable the optimizations while generating the picture
-    SkCanvas* canvas = result->beginRecording(100, 100,
-                         SkPicture::kDisableRecordOptimizations_RecordingFlag);
+    SkCanvas* canvas = result->beginRecording(100, 100);
+    result->internalOnly_EnableOpts(false);
 
     SkPaint saveLayerPaint;
     saveLayerPaint.setColor(0xCC000000);
@@ -218,8 +218,8 @@ static SkPicture* create_save_layer_opt_2(SkTDArray<DrawType>* preOptPattern,
     SkPicture* result = new SkPicture;
 
     // have to disable the optimizations while generating the picture
-    SkCanvas* canvas = result->beginRecording(100, 100,
-                         SkPicture::kDisableRecordOptimizations_RecordingFlag);
+    SkCanvas* canvas = result->beginRecording(100, 100);
+    result->internalOnly_EnableOpts(false);
 
     SkPaint saveLayerPaint;
     saveLayerPaint.setColor(0xCC000000);
index 56596c4..2689ae0 100644 (file)
@@ -125,15 +125,6 @@ public:
             discarded if you serialize into a stream and then deserialize.
         */
         kOptimizeForClippedPlayback_RecordingFlag = 0x02,
-        /*
-            This flag disables all the picture recording optimizations (i.e.,
-            those in SkPictureRecord). It is mainly intended for testing the
-            existing optimizations (i.e., to actually have the pattern
-            appear in an .skp we have to disable the optimization). This
-            option doesn't affect the optimizations controlled by
-            'kOptimizeForClippedPlayback_RecordingFlag'.
-         */
-        kDisableRecordOptimizations_RecordingFlag = 0x04
     };
 
     /** Returns the canvas that records the drawing commands.
@@ -228,6 +219,14 @@ public:
     static bool InternalOnly_StreamIsSKP(SkStream*, SkPictInfo*);
     static bool InternalOnly_BufferIsSKP(SkReadBuffer&, SkPictInfo*);
 
+    /** Enable/disable all the picture recording optimizations (i.e.,
+        those in SkPictureRecord). It is mainly intended for testing the
+        existing optimizations (i.e., to actually have the pattern
+        appear in an .skp we have to disable the optimization). Call right
+        after 'beginRecording'.
+    */
+    void internalOnly_EnableOpts(bool enableOpts);
+
 protected:
     // V2 : adds SkPixelRef's generation ID.
     // V3 : PictInfo tag at beginning, and EOF tag at the end
index 2ea4641..f83a5fb 100644 (file)
@@ -143,6 +143,12 @@ SkPicture::~SkPicture() {
     SkDELETE(fPlayback);
 }
 
+void SkPicture::internalOnly_EnableOpts(bool enableOpts) {
+    if (NULL != fRecord) {
+        fRecord->internalOnly_EnableOpts(enableOpts);
+    }
+}
+
 void SkPicture::swap(SkPicture& other) {
     SkTSwap(fRecord, other.fRecord);
     SkTSwap(fPlayback, other.fPlayback);
index dda6f46..213d1aa 100644 (file)
@@ -34,7 +34,8 @@ SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags)
     , fStateTree(NULL)
     , fFlattenableHeap(HEAP_BLOCK_SIZE)
     , fPaints(&fFlattenableHeap)
-    , fRecordFlags(flags) {
+    , fRecordFlags(flags)
+    , fOptsEnabled(true) {
 #ifdef SK_DEBUG_SIZE
     fPointBytes = fRectBytes = fTextBytes = 0;
     fPointWrites = fRectWrites = fTextWrites = 0;
@@ -627,7 +628,7 @@ void SkPictureRecord::restore() {
     }
 
     size_t opt = 0;
-    if (!(fRecordFlags & SkPicture::kDisableRecordOptimizations_RecordingFlag)) {
+    if (fOptsEnabled) {
         for (opt = 0; opt < SK_ARRAY_COUNT(gPictureRecordOpts); ++opt) {
             if (0 != (gPictureRecordOpts[opt].fFlags & kSkipIfBBoxHierarchy_Flag)
                 && NULL != fBoundingHierarchy) {
@@ -642,8 +643,7 @@ void SkPictureRecord::restore() {
         }
     }
 
-    if ((fRecordFlags & SkPicture::kDisableRecordOptimizations_RecordingFlag) ||
-        SK_ARRAY_COUNT(gPictureRecordOpts) == opt) {
+    if (!fOptsEnabled || SK_ARRAY_COUNT(gPictureRecordOpts) == opt) {
         // No optimization fired so add the RESTORE
         this->recordRestore();
     }
index 1b62f3d..e7c6d7f 100644 (file)
@@ -103,6 +103,10 @@ public:
     void beginRecording();
     void endRecording();
 
+    void internalOnly_EnableOpts(bool optsEnabled) {
+        fOptsEnabled = optsEnabled;
+    }
+
 private:
     void handleOptimization(int opt);
     int recordRestoreOffsetPlaceholder(SkRegion::Op);
@@ -287,7 +291,8 @@ private:
     SkTDArray<SkPicture*> fPictureRefs;
 
     uint32_t fRecordFlags;
-    int fInitialSaveCount;
+    bool     fOptsEnabled;
+    int      fInitialSaveCount;
 
     friend class SkPicturePlayback;
     friend class SkPictureTester; // for unit testing