[go: nahoru, domu]

Proposed SkCanvas API for preLoading textures to VRAM v2.0

This is an update to (Proposed SkCanvas API for preLoading textures to VRAM - https://codereview.chromium.org/192853002/). It takes into account in-person feedback on the initial proposal. The main feedback was to land this closer to where we will ultimately wind up with the reordered rendering capability (and don't have an SkCanvas entry point (yet)).

Committed: http://code.google.com/p/skia/source/detail?r=13810

R=reed@google.com, bsalomon@google.com

Author: robertphillips@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk/src@13822 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkPicture.cpp b/core/SkPicture.cpp
index 9270236..92311f3 100644
--- a/core/SkPicture.cpp
+++ b/core/SkPicture.cpp
@@ -117,9 +117,12 @@
     fRecord = NULL;
     fPlayback = NULL;
     fWidth = fHeight = 0;
+    fAccelData = NULL;
 }
 
-SkPicture::SkPicture(const SkPicture& src) : INHERITED() {
+SkPicture::SkPicture(const SkPicture& src) 
+    : INHERITED()
+    , fAccelData(NULL) {
     fWidth = src.fWidth;
     fHeight = src.fHeight;
     fRecord = NULL;
@@ -141,6 +144,7 @@
 SkPicture::~SkPicture() {
     SkSafeUnref(fRecord);
     SkDELETE(fPlayback);
+    SkSafeUnref(fAccelData);
 }
 
 void SkPicture::internalOnly_EnableOpts(bool enableOpts) {
@@ -152,6 +156,7 @@
 void SkPicture::swap(SkPicture& other) {
     SkTSwap(fRecord, other.fRecord);
     SkTSwap(fPlayback, other.fPlayback);
+    SkTSwap(fAccelData, other.fAccelData);
     SkTSwap(fWidth, other.fWidth);
     SkTSwap(fHeight, other.fHeight);
 }
@@ -188,6 +193,17 @@
     }
 }
 
+SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() {
+    static int32_t gNextID = 0;
+
+    int32_t id = sk_atomic_inc(&gNextID);
+    if (id >= 1 << (8 * sizeof(Domain))) {
+        SK_CRASH();
+    }
+
+    return static_cast<Domain>(id);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 SkCanvas* SkPicture::beginRecording(int width, int height,
@@ -196,7 +212,7 @@
         SkDELETE(fPlayback);
         fPlayback = NULL;
     }
-
+    SkSafeUnref(fAccelData);
     SkSafeSetNull(fRecord);
 
     // Must be set before calling createBBoxHierarchy
@@ -250,7 +266,7 @@
 
 void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) {
     this->endRecording();
-    if (fPlayback) {
+    if (NULL != fPlayback) {
         fPlayback->draw(*surface, callback);
     }
 }
@@ -310,7 +326,8 @@
     : fPlayback(playback)
     , fRecord(NULL)
     , fWidth(width)
-    , fHeight(height) {}
+    , fHeight(height)
+    , fAccelData(NULL) {}
 
 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc proc) {
     SkPictInfo info;
@@ -418,7 +435,9 @@
 }
 
 bool SkPicture::willPlayBackBitmaps() const {
-    if (!fPlayback) return false;
+    if (!fPlayback) {
+        return false;
+    }
     return fPlayback->containsBitmaps();
 }