aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/ccpr/GrCoverageCountingPathRenderer.h
diff options
context:
space:
mode:
authorGravatar Chris Dalton <csmartdalton@google.com>2018-05-09 01:08:38 -0600
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-09 18:14:05 +0000
commit5ba36ba9f5b414ffbe6f1a60598f47c5da57941f (patch)
tree6c614d2517b778b3666cefbfce3c6e24fcdfe4f9 /src/gpu/ccpr/GrCoverageCountingPathRenderer.h
parent969a738e7f7fe03832acb86362d133db40623c01 (diff)
ccpr: Clean up GrCoverageCountingPathRenderer
Extracts all the nested classes to their own files and detangles their interactions. Encapsulates the per-flush resources in their in their own separate class. Bug: skia: Change-Id: Ic134b627f6b66cb2ce1e5d6f896ac6b2f75f6fa2 Reviewed-on: https://skia-review.googlesource.com/126845 Commit-Queue: Chris Dalton <csmartdalton@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/ccpr/GrCoverageCountingPathRenderer.h')
-rw-r--r--src/gpu/ccpr/GrCoverageCountingPathRenderer.h243
1 files changed, 54 insertions, 189 deletions
diff --git a/src/gpu/ccpr/GrCoverageCountingPathRenderer.h b/src/gpu/ccpr/GrCoverageCountingPathRenderer.h
index 0e9ed7b8b1..2eac93369c 100644
--- a/src/gpu/ccpr/GrCoverageCountingPathRenderer.h
+++ b/src/gpu/ccpr/GrCoverageCountingPathRenderer.h
@@ -8,180 +8,55 @@
#ifndef GrCoverageCountingPathRenderer_DEFINED
#define GrCoverageCountingPathRenderer_DEFINED
-#include <map>
-#include "GrAllocator.h"
-#include "GrOnFlushResourceProvider.h"
#include "GrPathRenderer.h"
+#include "GrRenderTargetOpList.h"
#include "SkTInternalLList.h"
-#include "ccpr/GrCCAtlas.h"
-#include "ccpr/GrCCPathParser.h"
-#include "ccpr/GrCCPathProcessor.h"
-#include "ops/GrDrawOp.h"
+#include "ccpr/GrCCClipPath.h"
+#include "ccpr/GrCCDrawPathsOp.h"
+#include <map>
+
+class GrCCPerFlushResources;
+
+/**
+ * Tracks all the paths in a single render target that will be drawn at next flush.
+ */
+struct GrCCRTPendingPaths {
+ ~GrCCRTPendingPaths() {
+ // Ensure there are no surviving DrawPathsOps with a dangling pointer into this class.
+ if (!fDrawOps.isEmpty()) {
+ SK_ABORT("GrCCDrawPathsOp(s) not deleted during flush");
+ }
+ // Clip lazy proxies also reference this class from their callbacks, but those callbacks
+ // are only invoked at flush time while we are still alive. (Unlike DrawPathsOps, that
+ // unregister themselves upon destruction.) So it shouldn't matter if any clip proxies
+ // are still around.
+ }
+
+ SkTInternalLList<GrCCDrawPathsOp> fDrawOps;
+ std::map<uint32_t, GrCCClipPath> fClipPaths;
+ GrSTAllocator<256, GrCCDrawPathsOp::SingleDraw> fDrawsAllocator;
+};
/**
* This is a path renderer that draws antialiased paths by counting coverage in an offscreen
- * buffer. (See GrCCCoverageProcessor, GrCCPathProcessor)
+ * buffer. (See GrCCCoverageProcessor, GrCCPathProcessor.)
*
* It also serves as the per-render-target tracker for pending path draws, and at the start of
* flush, it compiles GPU buffers and renders a "coverage count atlas" for the upcoming paths.
*/
class GrCoverageCountingPathRenderer : public GrPathRenderer, public GrOnFlushCallbackObject {
- struct RTPendingPaths;
-
public:
static bool IsSupported(const GrCaps&);
static sk_sp<GrCoverageCountingPathRenderer> CreateIfSupported(const GrCaps&,
bool drawCachablePaths);
-
- ~GrCoverageCountingPathRenderer() override {
- // Ensure no Ops exist that could have a dangling pointer back into this class.
- SkASSERT(fRTPendingPathsMap.empty());
- SkASSERT(0 == fPendingDrawOpsCount);
- }
-
- // This is the Op that ultimately draws a path into its final destination, using the atlas we
- // generate at flush time.
- class DrawPathsOp : public GrDrawOp {
- public:
- DEFINE_OP_CLASS_ID
- SK_DECLARE_INTERNAL_LLIST_INTERFACE(DrawPathsOp);
-
- DrawPathsOp(GrCoverageCountingPathRenderer*, const DrawPathArgs&, GrColor);
- ~DrawPathsOp() override;
-
- struct SingleDraw {
- SkIRect fClipIBounds;
- SkMatrix fMatrix;
- SkPath fPath;
- GrColor fColor;
- SingleDraw* fNext = nullptr;
- };
-
- const SingleDraw* head() const {
- SkASSERT(fInstanceCount >= 1);
- return &fHeadDraw;
- }
-
- SkDEBUGCODE(int numSkippedInstances_debugOnly() const { return fNumSkippedInstances; })
-
- // GrDrawOp overrides.
- const char* name() const override { return "GrCoverageCountingPathRenderer::DrawPathsOp"; }
- FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
- RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*,
- GrPixelConfigIsClamped) override;
- void wasRecorded(GrRenderTargetOpList*) override;
- bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override;
- void visitProxies(const VisitProxyFunc& func) const override {
- fProcessors.visitProxies(func);
- }
- void onPrepare(GrOpFlushState*) override {}
- void onExecute(GrOpFlushState*) override;
-
- int setupResources(GrOnFlushResourceProvider*,
- GrCCPathProcessor::Instance* pathInstanceData, int pathInstanceIdx);
-
- private:
- SkPath::FillType getFillType() const {
- SkASSERT(fInstanceCount >= 1);
- return fHeadDraw.fPath.getFillType();
- }
-
- struct AtlasBatch {
- const GrCCAtlas* fAtlas;
- int fEndInstanceIdx;
- };
-
- void addAtlasBatch(const GrCCAtlas* atlas, int endInstanceIdx) {
- SkASSERT(endInstanceIdx > fBaseInstance);
- SkASSERT(fAtlasBatches.empty() ||
- endInstanceIdx > fAtlasBatches.back().fEndInstanceIdx);
- fAtlasBatches.push_back() = {atlas, endInstanceIdx};
- }
-
- GrCoverageCountingPathRenderer* const fCCPR;
- const uint32_t fSRGBFlags;
- GrProcessorSet fProcessors;
- SingleDraw fHeadDraw;
- SingleDraw* fTailDraw;
- RTPendingPaths* fOwningRTPendingPaths;
- int fBaseInstance;
- SkDEBUGCODE(int fInstanceCount);
- SkDEBUGCODE(int fNumSkippedInstances);
- SkSTArray<1, AtlasBatch, true> fAtlasBatches;
-
- typedef GrDrawOp INHERITED;
- };
+ ~GrCoverageCountingPathRenderer() override;
// GrPathRenderer overrides.
StencilSupport onGetStencilSupport(const GrShape&) const override {
return GrPathRenderer::kNoSupport_StencilSupport;
}
CanDrawPath onCanDrawPath(const CanDrawPathArgs& args) const override;
- bool onDrawPath(const DrawPathArgs&) final;
-
- // These are keyed by SkPath generation ID, and store which device-space paths are accessed and
- // where by clip FPs in a given opList. A single ClipPath can be referenced by multiple FPs. At
- // flush time their coverage count masks are packed into atlas(es) alongside normal DrawPathOps.
- class ClipPath {
- public:
- ClipPath() = default;
- ClipPath(const ClipPath&) = delete;
-
- ~ClipPath() {
- // Ensure no clip FPs exist with a dangling pointer back into this class.
- SkASSERT(!fAtlasLazyProxy || fAtlasLazyProxy->isUnique_debugOnly());
- // Ensure no lazy proxy callbacks exist with a dangling pointer back into this class.
- SkASSERT(fHasAtlasTransform);
- }
-
- bool isUninitialized() const { return !fAtlasLazyProxy; }
- void init(GrProxyProvider* proxyProvider,
- const SkPath& deviceSpacePath, const SkIRect& accessRect,
- int rtWidth, int rtHeight);
- void addAccess(const SkIRect& accessRect) {
- SkASSERT(!this->isUninitialized());
- fAccessRect.join(accessRect);
- }
-
- GrTextureProxy* atlasLazyProxy() const {
- SkASSERT(!this->isUninitialized());
- return fAtlasLazyProxy.get();
- }
- const SkPath& deviceSpacePath() const {
- SkASSERT(!this->isUninitialized());
- return fDeviceSpacePath;
- }
- const SkIRect& pathDevIBounds() const {
- SkASSERT(!this->isUninitialized());
- return fPathDevIBounds;
- }
- void placePathInAtlas(GrCoverageCountingPathRenderer*, GrOnFlushResourceProvider*,
- GrCCPathParser*);
-
- const SkVector& atlasScale() const {
- SkASSERT(fHasAtlasTransform);
- return fAtlasScale;
- }
- const SkVector& atlasTranslate() const {
- SkASSERT(fHasAtlasTransform);
- return fAtlasTranslate;
- }
-
- private:
- sk_sp<GrTextureProxy> fAtlasLazyProxy;
- SkPath fDeviceSpacePath;
- SkIRect fPathDevIBounds;
- SkIRect fAccessRect;
-
- const GrCCAtlas* fAtlas = nullptr;
- int16_t fAtlasOffsetX;
- int16_t fAtlasOffsetY;
- SkDEBUGCODE(bool fHasAtlas = false);
-
- SkVector fAtlasScale;
- SkVector fAtlasTranslate;
- SkDEBUGCODE(bool fHasAtlasTransform = false);
- };
+ bool onDrawPath(const DrawPathArgs&) override;
std::unique_ptr<GrFragmentProcessor> makeClipProcessor(GrProxyProvider*, uint32_t oplistID,
const SkPath& deviceSpacePath,
@@ -190,48 +65,38 @@ public:
// GrOnFlushCallbackObject overrides.
void preFlush(GrOnFlushResourceProvider*, const uint32_t* opListIDs, int numOpListIDs,
- SkTArray<sk_sp<GrRenderTargetContext>>* results) override;
+ SkTArray<sk_sp<GrRenderTargetContext>>* atlasDraws) override;
void postFlush(GrDeferredUploadToken, const uint32_t* opListIDs, int numOpListIDs) override;
+#ifdef SK_DEBUG
+ bool isFlushing_debugOnly() const { return fFlushing; }
+ void incrDrawOpCount_debugOnly() { ++fNumOutstandingDrawOps; }
+ void decrDrawOpCount_debugOnly() { --fNumOutstandingDrawOps; }
+#endif
+
private:
- GrCoverageCountingPathRenderer(bool drawCachablePaths)
- : fDrawCachablePaths(drawCachablePaths) {}
-
- GrCCAtlas* placeParsedPathInAtlas(GrOnFlushResourceProvider*, const SkIRect& accessRect,
- const SkIRect& pathIBounds, int16_t* atlasOffsetX,
- int16_t* atlasOffsetY);
-
- struct RTPendingPaths {
- ~RTPendingPaths() {
- // Ensure there are no surviving DrawPathsOps with a dangling pointer into this class.
- if (!fDrawOps.isEmpty()) {
- SK_ABORT("CCPR DrawPathsOp(s) not deleted during flush");
- }
- // Clip lazy proxies also reference this class from their callbacks, but those callbacks
- // are only invoked at flush time while we are still alive. (Unlike DrawPathsOps, that
- // unregister themselves upon destruction.) So it shouldn't matter if any clip proxies
- // are still around.
- }
+ GrCoverageCountingPathRenderer(bool drawCachablePaths);
- SkTInternalLList<DrawPathsOp> fDrawOps;
- std::map<uint32_t, ClipPath> fClipPaths;
- GrSTAllocator<256, DrawPathsOp::SingleDraw> fDrawsAllocator;
- };
-
- // A map from render target ID to the individual render target's pending paths.
- std::map<uint32_t, RTPendingPaths> fRTPendingPathsMap;
- SkSTArray<4, std::map<uint32_t, RTPendingPaths>::iterator> fFlushingRTPathIters;
- SkDEBUGCODE(int fPendingDrawOpsCount = 0);
-
- sk_sp<const GrBuffer> fPerFlushIndexBuffer;
- sk_sp<const GrBuffer> fPerFlushVertexBuffer;
- sk_sp<GrBuffer> fPerFlushInstanceBuffer;
- sk_sp<GrCCPathParser> fPerFlushPathParser;
- GrSTAllocator<4, GrCCAtlas> fPerFlushAtlases;
- bool fPerFlushResourcesAreValid;
+ GrCCRTPendingPaths* lookupRTPendingPaths(GrRenderTargetOpList* opList) {
+ SkASSERT(!fFlushing);
+ return &fRTPendingPathsMap[opList->uniqueID()];
+ }
+
+ const GrCCPerFlushResources* getPerFlushResources() const {
+ SkASSERT(fFlushing);
+ return fPerFlushResources.get();
+ }
+
+ std::map<uint32_t, GrCCRTPendingPaths> fRTPendingPathsMap;
+ SkSTArray<4, std::map<uint32_t, GrCCRTPendingPaths>::iterator> fFlushingRTPathIters;
+ std::unique_ptr<GrCCPerFlushResources> fPerFlushResources;
SkDEBUGCODE(bool fFlushing = false);
+ SkDEBUGCODE(int fNumOutstandingDrawOps = 0);
const bool fDrawCachablePaths;
+
+ friend void GrCCDrawPathsOp::wasRecorded(GrRenderTargetOpList*); // For lookupRTPendingPaths.
+ friend void GrCCDrawPathsOp::onExecute(GrOpFlushState*); // For getPerFlushResources.
};
#endif