ccpr: Implement path mask caching
Implement caching as follows:
1) Instead of deleting the mainline ccpr atlas when finished, stash it
away from flush to flush.
2) On subsequent flushes, check the stashed atlas to see if we can
reuse any of its cachable paths. Copy reusable paths into 8-bit
literal coverage atlases and store them in the resource cache.
3) Recycle the stashed atlas texture for the remaining paths in the
flush.
Bug: skia:
Change-Id: I9b20fbea708646df1df3a5f9c044e2299706b989
Reviewed-on: https://skia-review.googlesource.com/134703
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/ccpr/GrCCAtlas.cpp b/src/gpu/ccpr/GrCCAtlas.cpp
index 94a37e8..4eeddea 100644
--- a/src/gpu/ccpr/GrCCAtlas.cpp
+++ b/src/gpu/ccpr/GrCCAtlas.cpp
@@ -137,9 +137,39 @@
fUserBatchID = id;
}
+static uint32_t next_atlas_unique_id() {
+ static int32_t nextID;
+ return sk_atomic_inc(&nextID);
+}
+
+const GrUniqueKey& GrCCAtlas::getOrAssignUniqueKey(GrOnFlushResourceProvider* onFlushRP) {
+ static const GrUniqueKey::Domain kAtlasDomain = GrUniqueKey::GenerateDomain();
+
+ if (!fUniqueKey.isValid()) {
+ GrUniqueKey::Builder builder(&fUniqueKey, kAtlasDomain, 1, "CCPR Atlas");
+ builder[0] = next_atlas_unique_id();
+ builder.finish();
+
+ if (fTextureProxy->priv().isInstantiated()) {
+ onFlushRP->assignUniqueKeyToProxy(fUniqueKey, fTextureProxy.get());
+ }
+ }
+ return fUniqueKey;
+}
+
+sk_sp<GrCCAtlas::CachedAtlasInfo> GrCCAtlas::refOrMakeCachedAtlasInfo() {
+ if (!fCachedAtlasInfo) {
+ fCachedAtlasInfo = sk_make_sp<CachedAtlasInfo>();
+ }
+ return fCachedAtlasInfo;
+}
+
sk_sp<GrRenderTargetContext> GrCCAtlas::makeRenderTargetContext(
GrOnFlushResourceProvider* onFlushRP) {
SkASSERT(!fTextureProxy->priv().isInstantiated()); // This method should only be called once.
+ // Caller should have cropped any paths to the destination render target instead of asking for
+ // an atlas larger than maxRenderTargetSize.
+ SkASSERT(SkTMax(fHeight, fWidth) <= fMaxTextureSize);
SkASSERT(fMaxTextureSize <= onFlushRP->caps()->maxRenderTargetSize());
sk_sp<GrRenderTargetContext> rtc =
@@ -150,6 +180,10 @@
return nullptr;
}
+ if (fUniqueKey.isValid()) {
+ onFlushRP->assignUniqueKeyToProxy(fUniqueKey, fTextureProxy.get());
+ }
+
SkIRect clearRect = SkIRect::MakeSize(fDrawBounds);
rtc->clear(&clearRect, 0, GrRenderTargetContext::CanClearFullscreen::kYes);
return rtc;