Add EXPERIMENTAL_beginRecording() for SkRecord-based recording.
authormtklein <mtklein@chromium.org>
Tue, 17 Jun 2014 19:08:15 +0000 (12:08 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 17 Jun 2014 19:08:16 +0000 (12:08 -0700)
The interesting stuff is in SkPictureRecorder.{h,cpp}.  The rest is mostly moving SkRecord from its own directories into core to avoid circular dependencies in GYP.

After plumbing SkRecord all the way through in Picture, I'll delete its old entry point include/record/SkRecording.h.  For now it and record.gypi need to stay where they are to keep Chrome building.

BUG=skia:
R=reed@google.com, mtklein@google.com

Author: mtklein@chromium.org

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

22 files changed:
gyp/core.gyp
gyp/core.gypi
gyp/dm.gyp
gyp/record.gyp [deleted file]
gyp/record.gypi
gyp/tests.gypi
gyp/tools.gyp
include/core/SkPictureRecorder.h
src/core/SkPictureRecorder.cpp
src/core/SkRecord.h [moved from src/record/SkRecord.h with 100% similarity]
src/core/SkRecordDraw.cpp [moved from src/record/SkRecordDraw.cpp with 100% similarity]
src/core/SkRecordDraw.h [moved from src/record/SkRecordDraw.h with 100% similarity]
src/core/SkRecordOpts.cpp [moved from src/record/SkRecordOpts.cpp with 100% similarity]
src/core/SkRecordOpts.h [moved from src/record/SkRecordOpts.h with 100% similarity]
src/core/SkRecordPattern.h [moved from src/record/SkRecordPattern.h with 100% similarity]
src/core/SkRecorder.cpp [moved from src/record/SkRecorder.cpp with 100% similarity]
src/core/SkRecorder.h [moved from src/record/SkRecorder.h with 100% similarity]
src/core/SkRecording.cpp [moved from src/record/SkRecording.cpp with 95% similarity]
src/core/SkRecords.h [moved from src/record/SkRecords.h with 100% similarity]
tests/RecordingTest.cpp
tools/bench_playback.cpp
tools/bench_record.cpp

index 8c5270e..b4f0579 100644 (file)
@@ -21,8 +21,9 @@
         '../include/utils',
         '../include/xml',
         '../src/core',
-        '../src/opts',
         '../src/image',
+        '../src/opts',
+        '../src/utils',
       ],
       'sources': [
         'core.gypi', # Makes the gypi appear in IDEs (but does not modify the build).
index e14fba7..e1bdbd5 100644 (file)
         '<(skia_src_path)/core/SkRasterClip.cpp',
         '<(skia_src_path)/core/SkRasterizer.cpp',
         '<(skia_src_path)/core/SkReadBuffer.cpp',
+        '<(skia_src_path)/core/SkRecordDraw.cpp',
+        '<(skia_src_path)/core/SkRecordOpts.cpp',
+        '<(skia_src_path)/core/SkRecorder.cpp',
+        '<(skia_src_path)/core/SkRecording.cpp',
         '<(skia_src_path)/core/SkRect.cpp',
         '<(skia_src_path)/core/SkRefDict.cpp',
         '<(skia_src_path)/core/SkRegion.cpp',
index 26d14db..a849e54 100644 (file)
@@ -59,7 +59,6 @@
             'flags.gyp:flags',
             'jsoncpp.gyp:jsoncpp',
             'gputest.gyp:skgputest',
-            'record.gyp:*',
             'etc1.gyp:libetc1',
         ],
         'conditions': [
diff --git a/gyp/record.gyp b/gyp/record.gyp
deleted file mode 100644 (file)
index 5fa7f81..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-# An experimental library for faster recording of SkCanvas commands.
-{
-    'targets': [{
-        'target_name': 'record',
-        'type': 'static_library',
-        'includes': [ 'record.gypi' ],
-        'include_dirs': [
-            '../include/config',
-            '../include/core',
-            '../include/record',
-            '../src/utils',
-        ],
-        'direct_dependent_settings': {
-            'include_dirs': [
-                '../include/record',  # Public headers.
-            ],
-        },
-    }]
-}
index adfd462..9415a57 100644 (file)
@@ -1,12 +1,3 @@
-# Source list for SkRecord
-# The parent gyp/gypi file must define
-#       'skia_src_path'     e.g. skia/trunk/src
-# The Skia build defines this in common_variables.gypi.
+# TODO: cleanup references in Chrome build and remove
 {
-    'sources': [
-        '<(skia_src_path)/record/SkRecordDraw.cpp',
-        '<(skia_src_path)/record/SkRecordOpts.cpp',
-        '<(skia_src_path)/record/SkRecorder.cpp',
-        '<(skia_src_path)/record/SkRecording.cpp',
-    ]
 }
index cf56d53..556143f 100644 (file)
@@ -9,7 +9,6 @@
     '../src/pathops',
     '../src/pdf',
     '../src/pipe/utils',
-    '../src/record',
     '../src/utils',
     '../src/utils/debugger',
     '../tools/',
@@ -24,7 +23,6 @@
     'flags.gyp:flags',
     'pdf.gyp:pdf',
     'tools.gyp:picture_utils',
-    'record.gyp:record',
   ],
   'sources': [
     '../tests/Test.cpp',
index b72b209..9e1cf05 100644 (file)
         'bench.gyp:bench_timer',
         'flags.gyp:flags',
         'skia_lib.gyp:skia_lib',
-        'record.gyp:*',
       ],
     },
     {
       'include_dirs': [
         '../src/core/',
         '../src/images',
-        '../src/record',
       ],
       'dependencies': [
         'bench.gyp:bench_timer',
         'flags.gyp:flags',
         'skia_lib.gyp:skia_lib',
-        'record.gyp:*',
       ],
     },
     {
         '../src/core/',
         '../src/images',
         '../src/lazy',
-        '../src/record',
       ],
       'dependencies': [
         'bench.gyp:bench_timer',
         'flags.gyp:flags',
-        'record.gyp:*',
         'skia_lib.gyp:skia_lib',
       ],
     },
index 8d29ff3..b13b8a8 100644 (file)
 
 class SkCanvas;
 class SkPictureRecord;
+class SkRecord;
+class SkRecorder;
 
 class SK_API SkPictureRecorder : SkNoncopyable {
 public:
-    SkPictureRecorder() : fCanvas(NULL) { }
+    SkPictureRecorder() : fPictureRecord(NULL), fRecorder(NULL), fRecord(NULL) { }
     ~SkPictureRecorder();
 
     /** Returns the canvas that records the drawing commands.
@@ -33,6 +35,10 @@ public:
                              SkBBHFactory* bbhFactory = NULL,
                              uint32_t recordFlags = 0);
 
+    /** Same as beginRecording(), using a new faster backend. */
+    SkCanvas* EXPERIMENTAL_beginRecording(int width, int height,
+                                          SkBBHFactory* bbhFactory = NULL);
+
     /** Returns the recording canvas if one is active, or NULL if recording is
         not active. This does not alter the refcnt on the canvas (if present).
     */
@@ -54,6 +60,8 @@ public:
     void internalOnly_EnableOpts(bool enableOpts);
 
 private:
+    void reset();
+
     /** Replay the current (partially recorded) operation stream into
         canvas. This call doesn't close the current recording.
     */
@@ -63,7 +71,13 @@ private:
 
     int                     fWidth;
     int                     fHeight;
-    SkPictureRecord*        fCanvas;   // ref counted
+
+    // Both ref counted.  One of these two will be non-null:
+    SkPictureRecord*        fPictureRecord;   // beginRecording()
+    SkRecorder*             fRecorder;        // EXPERIMENTAL_beginRecording()
+
+    // Not refcounted.  Used by EXPERIMENTAL_beginRecording().
+    SkRecord* fRecord;
 
     typedef SkNoncopyable INHERITED;
 };
index 3abd08e..f1423e3 100644 (file)
@@ -9,17 +9,26 @@
 #include "SkPicturePlayback.h"
 #include "SkPictureRecord.h"
 #include "SkPictureRecorder.h"
-#include "SkTypes.h" 
+#include "SkRecord.h"
+#include "SkRecordDraw.h"
+#include "SkRecorder.h"
+#include "SkTypes.h"
 
 SkPictureRecorder::~SkPictureRecorder() {
-    SkSafeSetNull(fCanvas);
+    this->reset();
+}
+
+void SkPictureRecorder::reset() {
+    SkSafeSetNull(fPictureRecord);
+    SkSafeSetNull(fRecorder);
+    SkDELETE(fRecord);
+    fRecord = NULL;
 }
 
 SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
                                             SkBBHFactory* bbhFactory /* = NULL */,
                                             uint32_t recordFlags /* = 0 */) {
-    SkSafeSetNull(fCanvas); // terminate any prior recording(s)
-
+    this->reset();  // terminate any prior recording(s)
     fWidth = width;
     fHeight = height;
 
@@ -28,49 +37,70 @@ SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
     if (NULL != bbhFactory) {
         SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height));
         SkASSERT(NULL != tree);
-        fCanvas = SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, tree.get()));
+        fPictureRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, tree.get()));
     } else {
-        fCanvas = SkNEW_ARGS(SkPictureRecord, (size, recordFlags));
+        fPictureRecord = SkNEW_ARGS(SkPictureRecord, (size, recordFlags));
     }
 
-    fCanvas->beginRecording();
+    fPictureRecord->beginRecording();
+    return this->getRecordingCanvas();
+}
+
+SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(int width, int height,
+                                                         SkBBHFactory* bbhFactory /* = NULL */) {
+    this->reset();
+    fWidth = width;
+    fHeight = height;
 
-    return fCanvas;
+    // TODO: plumb bbhFactory through
+    fRecord   = SkNEW(SkRecord);
+    fRecorder = SkNEW_ARGS(SkRecorder, (fRecord, width, height));
+    return this->getRecordingCanvas();
 }
 
 SkCanvas* SkPictureRecorder::getRecordingCanvas() {
-    return fCanvas;
+    if (NULL != fRecorder) {
+        return fRecorder;
+    }
+    return fPictureRecord;
 }
 
 SkPicture* SkPictureRecorder::endRecording() {
-    if (NULL == fCanvas) {
-        return NULL;
-    }
+    SkPicture* picture = NULL;
 
-    fCanvas->endRecording();
+    if (NULL != fRecorder) {
+        // TODO: picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, fRecord));
+        //       fRecord = NULL;
+    }
 
-    const bool deepCopyOps = false;
-    SkAutoTUnref<SkPicture> picture(SkNEW_ARGS(SkPicture, (fWidth, fHeight, 
-                                                           *fCanvas, deepCopyOps)));
-    SkSafeSetNull(fCanvas);
+    if (NULL != fPictureRecord) {
+        fPictureRecord->endRecording();
+        const bool deepCopyOps = false;
+        picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, *fPictureRecord, deepCopyOps));
+    }
 
-    return picture.detach();
+    this->reset();
+    return picture;
 }
 
 void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) {
-    if (NULL != fCanvas) {
-        fCanvas->internalOnly_EnableOpts(enableOpts);
+    if (NULL != fPictureRecord) {
+        fPictureRecord->internalOnly_EnableOpts(enableOpts);
     }
 }
 
 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
-    if (NULL == fCanvas || NULL == canvas) {
-        // Not recording or nothing to replay into
+    if (NULL == canvas) {
         return;
     }
 
-    const bool deepCopyOps = true;
-    SkAutoTUnref<SkPicture> picture(SkNEW_ARGS(SkPicture, (fWidth, fHeight, 
-                                                           *fCanvas, deepCopyOps)));
-    picture->draw(canvas);
+    if (NULL != fRecorder) {
+        SkRecordDraw(*fRecord, canvas);
+    }
+
+    if (NULL != fPictureRecord) {
+        const bool deepCopyOps = true;
+        SkPicture picture(fWidth, fHeight, *fPictureRecord, deepCopyOps);
+        picture.draw(canvas);
+    }
 }
similarity index 100%
rename from src/record/SkRecord.h
rename to src/core/SkRecord.h
similarity index 95%
rename from src/record/SkRecording.cpp
rename to src/core/SkRecording.cpp
index ad57aa2..94fabce 100644 (file)
@@ -5,7 +5,7 @@
  * found in the LICENSE file.
  */
 
-#include "SkRecording.h"
+#include "../../include/record/SkRecording.h"
 
 #include "SkRecord.h"
 #include "SkRecordOpts.h"
similarity index 100%
rename from src/record/SkRecords.h
rename to src/core/SkRecords.h
index fbe8448..8de52da 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "Test.h"
 
-#include "SkRecording.h"
+#include "../include/record/SkRecording.h"
 
 // Minimally exercise the public SkRecording API.
 
index f07fa8e..26fa1c7 100644 (file)
 #include "SkOSFile.h"
 #include "SkPicture.h"
 #include "SkPictureRecorder.h"
-#include "SkRecording.h"
 #include "SkStream.h"
 #include "SkString.h"
 
+#include "../include/record/SkRecording.h"
+
 #include "BenchTimer.h"
 #include "Stats.h"
 
index a8d7a8a..0024c2c 100644 (file)
@@ -11,7 +11,6 @@
 #include "SkOSFile.h"
 #include "SkPicture.h"
 #include "SkPictureRecorder.h"
-#include "SkRecording.h"
 #include "SkStream.h"
 #include "SkString.h"
 
@@ -65,16 +64,13 @@ static SkBBHFactory* parse_FLAGS_bbh() {
 }
 
 static void rerecord(const SkPicture& src, SkBBHFactory* bbhFactory) {
+    SkPictureRecorder recorder;
     if (FLAGS_skr) {
-        EXPERIMENTAL::SkRecording recording(src.width(), src.height());
-        src.draw(recording.canvas());
-        // Release and delete the SkPlayback so that recording optimizes its SkRecord.
-        SkDELETE(recording.releasePlayback());
+        src.draw(recorder.EXPERIMENTAL_beginRecording(src.width(), src.height(), bbhFactory));
     } else {
-        SkPictureRecorder recorder;
         src.draw(recorder.beginRecording(src.width(), src.height(), bbhFactory));
-        SkAutoTUnref<SkPicture> dst(recorder.endRecording());
     }
+    SkAutoTUnref<SkPicture> pic(recorder.endRecording());
 }
 
 static void bench_record(const SkPicture& src,