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.h b/src/gpu/ccpr/GrCCAtlas.h
index 6d82728..76d2a98 100644
--- a/src/gpu/ccpr/GrCCAtlas.h
+++ b/src/gpu/ccpr/GrCCAtlas.h
@@ -9,6 +9,8 @@
#define GrCCAtlas_DEFINED
#include "GrAllocator.h"
+#include "GrNonAtomicRef.h"
+#include "GrResourceKey.h"
#include "GrTypes.h"
#include "GrTypesPriv.h"
#include "SkRefCnt.h"
@@ -18,6 +20,7 @@
class GrRenderTargetContext;
class GrTextureProxy;
struct SkIPoint16;
+struct SkIRect;
/**
* This class implements a dynamic size GrRectanizer that grows until it reaches the implementation-
@@ -58,6 +61,22 @@
void setUserBatchID(int id);
int getUserBatchID() const { return fUserBatchID; }
+ // Manages a unique resource cache key that gets assigned to the atlas texture. The unique key
+ // does not get assigned to the texture proxy until it is instantiated.
+ const GrUniqueKey& getOrAssignUniqueKey(GrOnFlushResourceProvider*);
+ const GrUniqueKey& uniqueKey() const { return fUniqueKey; }
+
+ // An object for simple bookkeeping on the atlas texture once it has a unique key. In practice,
+ // we use it to track the percentage of the original atlas pixels that could still ever
+ // potentially be reused (i.e., those which still represent an extant path). When the percentage
+ // of useful pixels drops below 50%, the entire texture is purged from the resource cache.
+ struct CachedAtlasInfo : public GrNonAtomicRef<CachedAtlasInfo> {
+ int fNumPathPixels = 0;
+ int fNumInvalidatedPathPixels = 0;
+ bool fIsPurgedFromResourceCache = false;
+ };
+ sk_sp<CachedAtlasInfo> refOrMakeCachedAtlasInfo();
+
// Instantiates our texture proxy for the atlas and returns a pre-cleared GrRenderTargetContext
// that the caller may use to render the content. After this call, it is no longer valid to call
// addRect(), setUserBatchID(), or this method again.
@@ -74,6 +93,12 @@
SkISize fDrawBounds = {0, 0};
int fUserBatchID;
+
+ // Not every atlas will have a unique key -- a mainline CCPR one won't if we don't stash any
+ // paths, and only the first atlas in the stack is eligible to be stashed.
+ GrUniqueKey fUniqueKey;
+
+ sk_sp<CachedAtlasInfo> fCachedAtlasInfo;
sk_sp<GrTextureProxy> fTextureProxy;
};