blob: e70a15a6bce0a1e2ba5a4608d34f2b3b5611888f [file] [log] [blame]
Chris Dalton1a325d22017-07-14 15:17:41 -06001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrCoverageCountingPathRenderer_DEFINED
9#define GrCoverageCountingPathRenderer_DEFINED
10
Brian Salomon653f42f2018-07-10 10:07:31 -040011#include <map>
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/GrOnFlushResourceProvider.h"
Greg Danielf41b2bd2019-08-22 16:19:24 -040013#include "src/gpu/GrOpsTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrPathRenderer.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/ccpr/GrCCPerFlushResources.h"
Greg Danielf41b2bd2019-08-22 16:19:24 -040016#include "src/gpu/ccpr/GrCCPerOpsTaskPaths.h"
Chris Dalton5ba36ba2018-05-09 01:08:38 -060017
Chris Daltond7e22272018-05-23 10:17:17 -060018class GrCCDrawPathsOp;
Chris Daltona2b5b642018-06-24 13:08:57 -060019class GrCCPathCache;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060020
21/**
Chris Dalton1a325d22017-07-14 15:17:41 -060022 * This is a path renderer that draws antialiased paths by counting coverage in an offscreen
Chris Dalton5ba36ba2018-05-09 01:08:38 -060023 * buffer. (See GrCCCoverageProcessor, GrCCPathProcessor.)
Chris Dalton1a325d22017-07-14 15:17:41 -060024 *
25 * It also serves as the per-render-target tracker for pending path draws, and at the start of
26 * flush, it compiles GPU buffers and renders a "coverage count atlas" for the upcoming paths.
27 */
Chris Dalton383a2ef2018-01-08 17:21:41 -050028class GrCoverageCountingPathRenderer : public GrPathRenderer, public GrOnFlushCallbackObject {
Chris Dalton1a325d22017-07-14 15:17:41 -060029public:
Chris Daltonc3318f02019-07-19 14:20:53 -060030 using CoverageType = GrCCAtlas::CoverageType;
31
32 static bool IsSupported(const GrCaps&, CoverageType* = nullptr);
Chris Daltona2b5b642018-06-24 13:08:57 -060033
34 enum class AllowCaching : bool {
35 kNo = false,
36 kYes = true
37 };
38
Chris Daltonc3318f02019-07-19 14:20:53 -060039 static sk_sp<GrCoverageCountingPathRenderer> CreateIfSupported(
40 const GrCaps&, AllowCaching, uint32_t contextUniqueID);
41
42 CoverageType coverageType() const { return fCoverageType; }
Chris Daltona2b5b642018-06-24 13:08:57 -060043
Greg Danielf41b2bd2019-08-22 16:19:24 -040044 using PendingPathsMap = std::map<uint32_t, sk_sp<GrCCPerOpsTaskPaths>>;
Chris Daltona71305c2018-05-23 12:00:07 -060045
Greg Danielf41b2bd2019-08-22 16:19:24 -040046 // In DDL mode, Ganesh needs to be able to move the pending GrCCPerOpsTaskPaths to the DDL
47 // object (detachPendingPaths) and then return them upon replay (mergePendingPaths).
Chris Daltona71305c2018-05-23 12:00:07 -060048 PendingPathsMap detachPendingPaths() { return std::move(fPendingPaths); }
49
Robert Phillips774168e2018-05-31 12:43:27 -040050 void mergePendingPaths(const PendingPathsMap& paths) {
51#ifdef SK_DEBUG
Greg Danielf41b2bd2019-08-22 16:19:24 -040052 // Ensure there are no duplicate opsTask IDs between the incoming path map and ours.
53 // This should always be true since opsTask IDs are globally unique and these are coming
Robert Phillips774168e2018-05-31 12:43:27 -040054 // from different DDL recordings.
55 for (const auto& it : paths) {
56 SkASSERT(!fPendingPaths.count(it.first));
57 }
58#endif
59
60 fPendingPaths.insert(paths.begin(), paths.end());
Chris Daltona71305c2018-05-23 12:00:07 -060061 }
62
Chris Daltonc3318f02019-07-19 14:20:53 -060063 std::unique_ptr<GrFragmentProcessor> makeClipProcessor(
64 uint32_t oplistID, const SkPath& deviceSpacePath, const SkIRect& accessRect,
65 const GrCaps&);
Chris Daltona32a3c32017-12-05 10:05:21 -070066
67 // GrOnFlushCallbackObject overrides.
Chris Daltonc4b47352019-08-23 10:10:36 -060068 void preFlush(GrOnFlushResourceProvider*, const uint32_t* opsTaskIDs,
69 int numOpsTaskIDs) override;
Greg Danielf41b2bd2019-08-22 16:19:24 -040070 void postFlush(GrDeferredUploadToken, const uint32_t* opsTaskIDs, int numOpsTaskIDs) override;
Chris Daltona32a3c32017-12-05 10:05:21 -070071
Chris Dalton351e80c2019-01-06 22:51:00 -070072 void purgeCacheEntriesOlderThan(GrProxyProvider*, const GrStdSteadyClock::time_point&);
Chris Dalton4da70192018-06-18 09:51:36 -060073
Chris Dalton09a7bb22018-08-31 19:53:15 +080074 // If a path spans more pixels than this, we need to crop it or else analytic AA can run out of
75 // fp32 precision.
76 static constexpr float kPathCropThreshold = 1 << 16;
77
78 static void CropPath(const SkPath&, const SkIRect& cropbox, SkPath* out);
79
Chris Dalton82de18f2018-09-12 17:24:09 -060080 // Maximum inflation of path bounds due to stroking (from width, miter, caps). Strokes wider
81 // than this will be converted to fill paths and drawn by the CCPR filler instead.
82 static constexpr float kMaxBoundsInflationFromStroke = 4096;
83
84 static float GetStrokeDevWidth(const SkMatrix&, const SkStrokeRec&,
85 float* inflationRadius = nullptr);
86
Chris Dalton1a325d22017-07-14 15:17:41 -060087private:
Chris Daltonc3318f02019-07-19 14:20:53 -060088 GrCoverageCountingPathRenderer(CoverageType, AllowCaching, uint32_t contextUniqueID);
Chris Daltona2b5b642018-06-24 13:08:57 -060089
90 // GrPathRenderer overrides.
91 StencilSupport onGetStencilSupport(const GrShape&) const override {
92 return GrPathRenderer::kNoSupport_StencilSupport;
93 }
94 CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override;
95 bool onDrawPath(const DrawPathArgs&) override;
Chris Dalton1a325d22017-07-14 15:17:41 -060096
Greg Danielf41b2bd2019-08-22 16:19:24 -040097 GrCCPerOpsTaskPaths* lookupPendingPaths(uint32_t opsTaskID);
Chris Dalton42c21152018-06-13 15:28:19 -060098 void recordOp(std::unique_ptr<GrCCDrawPathsOp>, const DrawPathArgs&);
Chris Daltonc1e59632017-09-05 00:30:07 -060099
Chris Daltonc3318f02019-07-19 14:20:53 -0600100 const CoverageType fCoverageType;
101
Greg Danielf41b2bd2019-08-22 16:19:24 -0400102 // fPendingPaths holds the GrCCPerOpsTaskPaths objects that have already been created, but not
103 // flushed, and those that are still being created. All GrCCPerOpsTaskPaths objects will first
Chris Daltond7e22272018-05-23 10:17:17 -0600104 // reside in fPendingPaths, then be moved to fFlushingPaths during preFlush().
Chris Daltona71305c2018-05-23 12:00:07 -0600105 PendingPathsMap fPendingPaths;
Chris Daltona32a3c32017-12-05 10:05:21 -0700106
Greg Danielf41b2bd2019-08-22 16:19:24 -0400107 // fFlushingPaths holds the GrCCPerOpsTaskPaths objects that are currently being flushed.
Chris Daltond7e22272018-05-23 10:17:17 -0600108 // (It will only contain elements when fFlushing is true.)
Greg Danielf41b2bd2019-08-22 16:19:24 -0400109 SkSTArray<4, sk_sp<GrCCPerOpsTaskPaths>> fFlushingPaths;
Chris Dalton4da70192018-06-18 09:51:36 -0600110
Chris Daltona2b5b642018-06-24 13:08:57 -0600111 std::unique_ptr<GrCCPathCache> fPathCache;
Chris Dalton4da70192018-06-18 09:51:36 -0600112
Chris Dalton383a2ef2018-01-08 17:21:41 -0500113 SkDEBUGCODE(bool fFlushing = false);
Chris Dalton351e80c2019-01-06 22:51:00 -0700114
115public:
116 void testingOnly_drawPathDirectly(const DrawPathArgs&);
117 const GrCCPerFlushResources* testingOnly_getCurrentFlushResources();
118 const GrCCPathCache* testingOnly_getPathCache() const;
Chris Dalton1a325d22017-07-14 15:17:41 -0600119};
120
121#endif