Reduce sizeof(SkPicture::Analysis) from 24 bytes to 2 bytes.
authorjbroman <jbroman@chromium.org>
Mon, 27 Apr 2015 14:55:33 +0000 (07:55 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 27 Apr 2015 14:55:34 +0000 (07:55 -0700)
This saves "up to" 22 bytes per SkPicture.

Due to alignment, this reduces sizeof(SkPicture):
- from 88 to 72 bytes on Linux x64
- from 68 to 48 bytes on Android
(with Chrome's build settings)

It also somewhat simplifies the GPU veto logic.

BUG=skia:

[mtklein] No public API changes.
TBR=reed@google.com

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

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

index 2d782a5..fba0a35 100644 (file)
@@ -292,13 +292,9 @@ private:
 
         bool suitableForGpuRasterization(const char** reason, int sampleCount) const;
 
-        bool        fWillPlaybackBitmaps;
-        bool        fHasText;
-        int         fNumPaintWithPathEffectUses;
-        int         fNumFastPathDashEffects;
-        int         fNumAAConcavePaths;
-        int         fNumAAHairlineConcavePaths;
-        int         fNumAADFEligibleConcavePaths;
+        uint8_t     fNumSlowPathsAndDashEffects;
+        bool        fWillPlaybackBitmaps : 1;
+        bool        fHasText             : 1;
     } fAnalysis;
 
     friend class SkPictureRecorder;            // SkRecord-based constructor.
@@ -307,6 +303,6 @@ private:
     friend class SkPictureUtils;
     friend class SkRecordedDrawable;
 };
-SK_COMPILE_ASSERT(sizeof(SkPicture) <= 104, SkPictureSize);
+SK_COMPILE_ASSERT(sizeof(SkPicture) <= 88, SkPictureSize);
 
 #endif
index 37bf921..4d4364a 100644 (file)
@@ -133,27 +133,18 @@ struct TextHunter {
 struct SkPicture::PathCounter {
     SK_CREATE_MEMBER_DETECTOR(paint);
 
-    PathCounter()
-        : numPaintWithPathEffectUses (0)
-        , numFastPathDashEffects (0)
-        , numAAConcavePaths (0)
-        , numAAHairlineConcavePaths (0)
-        , numAADFEligibleConcavePaths(0) {
-    }
+    PathCounter() : fNumSlowPathsAndDashEffects(0) {}
 
     // Recurse into nested pictures.
     void operator()(const SkRecords::DrawPicture& op) {
         const SkPicture::Analysis& analysis = op.picture->fAnalysis;
-        numPaintWithPathEffectUses += analysis.fNumPaintWithPathEffectUses;
-        numFastPathDashEffects     += analysis.fNumFastPathDashEffects;
-        numAAConcavePaths          += analysis.fNumAAConcavePaths;
-        numAAHairlineConcavePaths  += analysis.fNumAAHairlineConcavePaths;
-        numAADFEligibleConcavePaths  += analysis.fNumAADFEligibleConcavePaths;
+        fNumSlowPathsAndDashEffects += analysis.fNumSlowPathsAndDashEffects;
     }
 
     void checkPaint(const SkPaint* paint) {
         if (paint && paint->getPathEffect()) {
-            numPaintWithPathEffectUses++;
+            // Initially assume it's slow.
+            fNumSlowPathsAndDashEffects++;
         }
     }
 
@@ -165,7 +156,7 @@ struct SkPicture::PathCounter {
             SkPathEffect::DashType dashType = effect->asADash(&info);
             if (2 == op.count && SkPaint::kRound_Cap != op.paint.getStrokeCap() &&
                 SkPathEffect::kDash_DashType == dashType && 2 == info.fCount) {
-                numFastPathDashEffects++;
+                fNumSlowPathsAndDashEffects--;
             }
         }
     }
@@ -173,16 +164,16 @@ struct SkPicture::PathCounter {
     void operator()(const SkRecords::DrawPath& op) {
         this->checkPaint(&op.paint);
         if (op.paint.isAntiAlias() && !op.path.isConvex()) {
-            numAAConcavePaths++;
-
             SkPaint::Style paintStyle = op.paint.getStyle();
             const SkRect& pathBounds = op.path.getBounds();
             if (SkPaint::kStroke_Style == paintStyle &&
                 0 == op.paint.getStrokeWidth()) {
-                numAAHairlineConcavePaths++;
+                // AA hairline concave path is not slow.
             } else if (SkPaint::kFill_Style == paintStyle && pathBounds.width() < 64.f &&
                        pathBounds.height() < 64.f && !op.path.isVolatile()) {
-                numAADFEligibleConcavePaths++;
+                // AADF eligible concave path is not slow.
+            } else {
+                fNumSlowPathsAndDashEffects++;
             }
         }
     }
@@ -195,11 +186,7 @@ struct SkPicture::PathCounter {
     template <typename T>
     SK_WHEN(!HasMember_paint<T>, void) operator()(const T& op) { /* do nothing */ }
 
-    int numPaintWithPathEffectUses;
-    int numFastPathDashEffects;
-    int numAAConcavePaths;
-    int numAAHairlineConcavePaths;
-    int numAADFEligibleConcavePaths;
+    int fNumSlowPathsAndDashEffects;
 };
 
 SkPicture::Analysis::Analysis(const SkRecord& record) {
@@ -209,11 +196,7 @@ SkPicture::Analysis::Analysis(const SkRecord& record) {
     for (unsigned i = 0; i < record.count(); i++) {
         record.visit<void>(i, counter);
     }
-    fNumPaintWithPathEffectUses = counter.numPaintWithPathEffectUses;
-    fNumFastPathDashEffects     = counter.numFastPathDashEffects;
-    fNumAAConcavePaths          = counter.numAAConcavePaths;
-    fNumAAHairlineConcavePaths  = counter.numAAHairlineConcavePaths;
-    fNumAADFEligibleConcavePaths  = counter.numAADFEligibleConcavePaths;
+    fNumSlowPathsAndDashEffects = SkTMin<int>(counter.fNumSlowPathsAndDashEffects, 255);
 
     fHasText = false;
     TextHunter text;
@@ -230,13 +213,7 @@ bool SkPicture::Analysis::suitableForGpuRasterization(const char** reason,
     // TODO: the heuristic used here needs to be refined
     static const int kNumSlowPathsTol = 6;
 
-    int numSlowPathDashedPaths = fNumPaintWithPathEffectUses - fNumFastPathDashEffects;
-
-    int numSlowPaths = fNumAAConcavePaths -
-                       fNumAAHairlineConcavePaths -
-                       fNumAADFEligibleConcavePaths;
-
-    bool ret = numSlowPathDashedPaths + numSlowPaths < kNumSlowPathsTol;
+    bool ret = fNumSlowPathsAndDashEffects < kNumSlowPathsTol;
 
     if (!ret && reason) {
         *reason = "Too many slow paths (either concave or dashed).";