Perform SkPicture analysis lazily.
I realized when writing the comment on https://crrev.com/1135363002/
that I'd really just sketched out the entire thing, so I couldn't help
but actually write up a working CL. How does this do for your benchmark?
BUG=chromium:487075
Review URL: https://codereview.chromium.org/1130123006
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index 88dfdf1..9a2b65b 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -10,6 +10,7 @@
#define SkPicture_DEFINED
#include "SkImageDecoder.h"
+#include "SkLazyPtr.h"
#include "SkRefCnt.h"
#include "SkTDArray.h"
@@ -293,7 +294,9 @@
uint8_t fNumSlowPathsAndDashEffects;
bool fWillPlaybackBitmaps : 1;
bool fHasText : 1;
- } fAnalysis;
+ };
+ SkLazyPtr<Analysis> fAnalysis;
+ const Analysis& analysis() const;
friend class SkPictureRecorder; // SkRecord-based constructor.
friend class GrLayerHoister; // access to fRecord
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index c014879..0145cbe 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -137,7 +137,7 @@
// Recurse into nested pictures.
void operator()(const SkRecords::DrawPicture& op) {
- const SkPicture::Analysis& analysis = op.picture->fAnalysis;
+ const SkPicture::Analysis& analysis = op.picture->analysis();
fNumSlowPathsAndDashEffects += analysis.fNumSlowPathsAndDashEffects;
}
@@ -438,14 +438,19 @@
}
}
+const SkPicture::Analysis& SkPicture::analysis() const {
+ auto create = [&](){ return SkNEW_ARGS(Analysis, (*fRecord)); };
+ return *fAnalysis.get(create);
+}
+
#if SK_SUPPORT_GPU
bool SkPicture::suitableForGpuRasterization(GrContext*, const char **reason) const {
- return fAnalysis.suitableForGpuRasterization(reason, 0);
+ return this->analysis().suitableForGpuRasterization(reason, 0);
}
#endif
-bool SkPicture::hasText() const { return fAnalysis.fHasText; }
-bool SkPicture::willPlayBackBitmaps() const { return fAnalysis.fWillPlaybackBitmaps; }
+bool SkPicture::hasText() const { return this->analysis().fHasText; }
+bool SkPicture::willPlayBackBitmaps() const { return this->analysis().fWillPlaybackBitmaps; }
int SkPicture::approximateOpCount() const { return fRecord->count(); }
SkPicture::SkPicture(const SkRect& cullRect,
@@ -461,7 +466,6 @@
, fBBH(bbh) // Take ownership of caller's ref.
, fAccelData(accelData) // Take ownership of caller's ref.
, fApproxBytesUsedBySubPictures(approxBytesUsedBySubPictures)
- , fAnalysis(*fRecord)
{}