Reland "ccpr: Rework the path cache to support sporadic flushing"
This is a reland of d6fa45472cb82b7d8e58d0437f7723c672488b8b
Original change's description:
> ccpr: Rework the path cache to support sporadic flushing
>
> Removes the notion of a stashed atlas that we store from the previous
> flush. Now we just cache every atlas we ever render. Cached atlases
> can either be 16-bit or 8-bit.
>
> The "reuse" and "animation" cases should both behave exactly the same
> as before: Where before we would copy from the stashed atlas to 8-bit
> atlases, we now copy from a cached 16-bit atlas and then invalidate
> it. Where before we would recycle the stashed atlas's backing texture
> object, we now recycle this same texture object from an invalidated
> 16-bit cached atlas.
>
> The main difference is that cases like tiled rendering now work. If
> you draw your whole scene in one flush, you still get one big 16-bit
> cached atlas, just like the "stashed atlas" implementation. But if you
> draw your scene in tiles, you now get lots of little cached 16-bit
> atlases, which can be reused and eventually copied to 8-bit atlases.
>
> Bug: skia:8462
> Change-Id: Ibae65febb948230aaaf1f1361eef9c8f06ebef18
> Reviewed-on: https://skia-review.googlesource.com/c/179991
> Commit-Queue: Chris Dalton <csmartdalton@google.com>
> Reviewed-by: Robert Phillips <robertphillips@google.com>
Bug: skia:8462
Change-Id: I2f64b0c37e2cd644a202dfc786366dda5d238391
Reviewed-on: https://skia-review.googlesource.com/c/181450
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/ccpr/GrCCAtlas.h b/src/gpu/ccpr/GrCCAtlas.h
index 4a762bc..03eed8c 100644
--- a/src/gpu/ccpr/GrCCAtlas.h
+++ b/src/gpu/ccpr/GrCCAtlas.h
@@ -15,6 +15,7 @@
#include "SkRefCnt.h"
#include "SkSize.h"
+class GrCCCachedAtlas;
class GrOnFlushResourceProvider;
class GrRenderTargetContext;
class GrTextureProxy;
@@ -45,7 +46,12 @@
void accountForSpace(int width, int height);
};
- GrCCAtlas(GrPixelConfig, const Specs&, const GrCaps&);
+ enum class CoverageType : bool {
+ kFP16_CoverageCount,
+ kA8_LiteralCoverage
+ };
+
+ GrCCAtlas(CoverageType, const Specs&, const GrCaps&);
~GrCCAtlas();
GrTextureProxy* textureProxy() const { return fTextureProxy.get(); }
@@ -64,23 +70,7 @@
void setStrokeBatchID(int id);
int getStrokeBatchID() const { return fStrokeBatchID; }
- // 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> {
- CachedAtlasInfo(uint32_t contextUniqueID) : fContextUniqueID(contextUniqueID) {}
- const uint32_t fContextUniqueID;
- int fNumPathPixels = 0;
- int fNumInvalidatedPathPixels = 0;
- bool fIsPurgedFromResourceCache = false;
- };
- sk_sp<CachedAtlasInfo> refOrMakeCachedAtlasInfo(uint32_t contextUniqueID);
+ sk_sp<GrCCCachedAtlas> refOrMakeCachedAtlas(GrOnFlushResourceProvider*);
// 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
@@ -97,6 +87,7 @@
bool internalPlaceRect(int w, int h, SkIPoint16* loc);
+ const CoverageType fCoverageType;
const int fMaxTextureSize;
int fWidth, fHeight;
std::unique_ptr<Node> fTopNode;
@@ -105,11 +96,7 @@
int fFillBatchID;
int fStrokeBatchID;
- // 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<GrCCCachedAtlas> fCachedAtlas;
sk_sp<GrTextureProxy> fTextureProxy;
sk_sp<GrTexture> fBackingTexture;
};
@@ -120,8 +107,10 @@
*/
class GrCCAtlasStack {
public:
- GrCCAtlasStack(GrPixelConfig pixelConfig, const GrCCAtlas::Specs& specs, const GrCaps* caps)
- : fPixelConfig(pixelConfig), fSpecs(specs), fCaps(caps) {}
+ using CoverageType = GrCCAtlas::CoverageType;
+
+ GrCCAtlasStack(CoverageType coverageType, const GrCCAtlas::Specs& specs, const GrCaps* caps)
+ : fCoverageType(coverageType), fSpecs(specs), fCaps(caps) {}
bool empty() const { return fAtlases.empty(); }
const GrCCAtlas& front() const { SkASSERT(!this->empty()); return fAtlases.front(); }
@@ -147,7 +136,7 @@
GrCCAtlas* addRect(const SkIRect& devIBounds, SkIVector* devToAtlasOffset);
private:
- const GrPixelConfig fPixelConfig;
+ const CoverageType fCoverageType;
const GrCCAtlas::Specs fSpecs;
const GrCaps* const fCaps;
GrSTAllocator<4, GrCCAtlas> fAtlases;