[go: nahoru, domu]

First pass at GPU veto

As a short term solution this CL collects information during the recording process for use in suitableForGpuRasterization.

BUG=366495
R=bsalomon@google.com, reed@google.com, alokp@chromium.org

Author: robertphillips@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk/src@14368 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkPicture.cpp b/core/SkPicture.cpp
index 10cc14b..65f723e 100644
--- a/core/SkPicture.cpp
+++ b/core/SkPicture.cpp
@@ -122,17 +122,18 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkPicture::SkPicture() {
+SkPicture::SkPicture()
+    : fAccelData(NULL) {
     this->needsNewGenID();
     fRecord = NULL;
     fPlayback = NULL;
     fWidth = fHeight = 0;
-    fAccelData = NULL;
 }
 
 SkPicture::SkPicture(const SkPicture& src)
     : INHERITED()
-    , fAccelData(NULL) {
+    , fAccelData(NULL)
+    , fContentInfo(src.fContentInfo) {
     this->needsNewGenID();
     fWidth = src.fWidth;
     fHeight = src.fHeight;
@@ -207,6 +208,7 @@
     SkTSwap(fWidth, other.fWidth);
     SkTSwap(fHeight, other.fHeight);
     fPathHeap.swap(&other.fPathHeap);
+    fContentInfo.swap(&other.fContentInfo);
 }
 
 SkPicture* SkPicture::clone() const {
@@ -228,6 +230,7 @@
         clone->fHeight = fHeight;
         SkSafeSetNull(clone->fRecord);
         SkDELETE(clone->fPlayback);
+        clone->fContentInfo.set(fContentInfo);
 
         /*  We want to copy the src's playback. However, if that hasn't been built
             yet, we need to fake a call to endRecording() without actually calling
@@ -271,6 +274,7 @@
     }
     SkSafeUnref(fAccelData);
     SkSafeSetNull(fRecord);
+    fContentInfo.reset();
 
     this->needsNewGenID();
 
@@ -305,6 +309,7 @@
     SkSafeUnref(fAccelData);
     SkSafeSetNull(fRecord);
     SkASSERT(NULL == fPathHeap);
+    fContentInfo.reset();
 
     this->needsNewGenID();
 
@@ -602,8 +607,14 @@
 
 #if SK_SUPPORT_GPU
 bool SkPicture::suitableForGpuRasterization(GrContext* context) const {
-    // Stub for now; never veto GPu rasterization.
-    return true;
+    // TODO: the heuristic used here needs to be refined
+    static const int kNumPaintWithPathEffectUsesTol = 1;
+    static const int kNumAAConcavePaths = 5;
+
+    SkASSERT(this->numAAHairlineConcavePaths() <= this->numAAConcavePaths());
+
+    return this->numPaintWithPathEffectUses() < kNumPaintWithPathEffectUsesTol &&
+           (this->numAAConcavePaths()-this->numAAHairlineConcavePaths()) < kNumAAConcavePaths;
 }
 #endif