Refactoring RTree integration to support SkBBoxHierarchy polymorphism in SkPicture.
authorjunov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 1 Nov 2012 17:10:32 +0000 (17:10 +0000)
committerjunov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 1 Nov 2012 17:10:32 +0000 (17:10 +0000)
This moves the rtree creation into a virtual method.
Review URL: https://codereview.appspot.com/6811057

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

include/core/SkPicture.h
src/core/SkPicture.cpp

index 72e0f5c..06c99b1 100644 (file)
@@ -13,6 +13,7 @@
 #include "SkRefCnt.h"
 #include "SkSerializationHelpers.h"
 
+class SkBBoxHierarchy;
 class SkBitmap;
 class SkCanvas;
 class SkPicturePlayback;
@@ -154,16 +155,13 @@ protected:
     SkPictureRecord* fRecord;
     int fWidth, fHeight;
 
+    // For testing. Derived classes may instantiate an alternate
+    // SkBBoxHierarchy implementation
+    virtual SkBBoxHierarchy* createBBoxHierarchy() const;
+
 private:
     SkPicturePlayback* fPlayback;
 
-    /** Used by the R-Tree when kOptimizeForClippedPlayback_RecordingFlag is
-        set, these were empirically determined to produce reasonable performance
-        in most cases.
-    */
-    static const int kRTreeMinChildren = 6;
-    static const int kRTreeMaxChildren = 11;
-
     friend class SkFlatPicture;
     friend class SkPicturePlayback;
 
index cc73bda..ed3e9ce 100644 (file)
@@ -190,11 +190,12 @@ SkCanvas* SkPicture::beginRecording(int width, int height,
     bm.setConfig(SkBitmap::kNo_Config, width, height);
     SkAutoTUnref<SkDevice> dev(SkNEW_ARGS(SkDevice, (bm)));
 
+    // Must be set before calling createBBoxHierarchy
+    fWidth = width;
+    fHeight = height;
+
     if (recordingFlags & kOptimizeForClippedPlayback_RecordingFlag) {
-        SkScalar aspectRatio = SkScalarDiv(SkIntToScalar(width),
-                                           SkIntToScalar(height));
-        SkRTree* tree = SkRTree::Create(kRTreeMinChildren, kRTreeMaxChildren,
-                                        aspectRatio);
+        SkBBoxHierarchy* tree = this->createBBoxHierarchy();
         SkASSERT(NULL != tree);
         fRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (recordingFlags, tree, dev));
         tree->unref();
@@ -203,12 +204,21 @@ SkCanvas* SkPicture::beginRecording(int width, int height,
     }
     fRecord->beginRecording();
 
-    fWidth = width;
-    fHeight = height;
-
     return fRecord;
 }
 
+SkBBoxHierarchy* SkPicture::createBBoxHierarchy() const {
+    // These values were empirically determined to produce reasonable 
+    // performance in most cases.
+    static const int kRTreeMinChildren = 6;
+    static const int kRTreeMaxChildren = 11;
+
+    SkScalar aspectRatio = SkScalarDiv(SkIntToScalar(fWidth),
+                                       SkIntToScalar(fHeight));
+    return SkRTree::Create(kRTreeMinChildren, kRTreeMaxChildren,
+                           aspectRatio);
+}
+
 SkCanvas* SkPicture::getRecordingCanvas() const {
     // will be null if we are not recording
     return fRecord;