Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 1 | /* |
| 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 Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 11 | #include <map> |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/GrOnFlushResourceProvider.h" |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrOpsTask.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrPathRenderer.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/ccpr/GrCCPerFlushResources.h" |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 16 | #include "src/gpu/ccpr/GrCCPerOpsTaskPaths.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 17 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 18 | class GrCCDrawPathsOp; |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 19 | class GrCCPathCache; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 20 | |
| 21 | /** |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 22 | * This is a path renderer that draws antialiased paths by counting coverage in an offscreen |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 23 | * buffer. (See GrCCCoverageProcessor, GrCCPathProcessor.) |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 24 | * |
| 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 Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 28 | class GrCoverageCountingPathRenderer : public GrPathRenderer, public GrOnFlushCallbackObject { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 29 | public: |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 30 | using CoverageType = GrCCAtlas::CoverageType; |
| 31 | |
Robert Phillips | a628605 | 2020-04-13 10:55:08 -0400 | [diff] [blame] | 32 | const char* name() const final { return "CCPR"; } |
| 33 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 34 | static bool IsSupported(const GrCaps&, CoverageType* = nullptr); |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 35 | |
| 36 | enum class AllowCaching : bool { |
| 37 | kNo = false, |
| 38 | kYes = true |
| 39 | }; |
| 40 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 41 | static sk_sp<GrCoverageCountingPathRenderer> CreateIfSupported( |
| 42 | const GrCaps&, AllowCaching, uint32_t contextUniqueID); |
| 43 | |
| 44 | CoverageType coverageType() const { return fCoverageType; } |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 45 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 46 | using PendingPathsMap = std::map<uint32_t, sk_sp<GrCCPerOpsTaskPaths>>; |
Chris Dalton | a71305c | 2018-05-23 12:00:07 -0600 | [diff] [blame] | 47 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 48 | // In DDL mode, Ganesh needs to be able to move the pending GrCCPerOpsTaskPaths to the DDL |
| 49 | // object (detachPendingPaths) and then return them upon replay (mergePendingPaths). |
Chris Dalton | a71305c | 2018-05-23 12:00:07 -0600 | [diff] [blame] | 50 | PendingPathsMap detachPendingPaths() { return std::move(fPendingPaths); } |
| 51 | |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 52 | void mergePendingPaths(const PendingPathsMap& paths) { |
| 53 | #ifdef SK_DEBUG |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 54 | // Ensure there are no duplicate opsTask IDs between the incoming path map and ours. |
| 55 | // This should always be true since opsTask IDs are globally unique and these are coming |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 56 | // from different DDL recordings. |
| 57 | for (const auto& it : paths) { |
| 58 | SkASSERT(!fPendingPaths.count(it.first)); |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | fPendingPaths.insert(paths.begin(), paths.end()); |
Chris Dalton | a71305c | 2018-05-23 12:00:07 -0600 | [diff] [blame] | 63 | } |
| 64 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 65 | std::unique_ptr<GrFragmentProcessor> makeClipProcessor( |
John Stiles | 956ec8a | 2020-06-19 15:32:16 -0400 | [diff] [blame] | 66 | std::unique_ptr<GrFragmentProcessor> inputFP, uint32_t opsTaskID, |
| 67 | const SkPath& deviceSpacePath, const SkIRect& accessRect, const GrCaps& caps); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 68 | |
| 69 | // GrOnFlushCallbackObject overrides. |
Adlai Holler | 9902cff | 2020-11-11 08:51:25 -0500 | [diff] [blame^] | 70 | void preFlush(GrOnFlushResourceProvider*, SkSpan<const uint32_t> taskIDs) override; |
| 71 | void postFlush(GrDeferredUploadToken, SkSpan<const uint32_t> taskIDs) override; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 72 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 73 | void purgeCacheEntriesOlderThan(GrProxyProvider*, const GrStdSteadyClock::time_point&); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 74 | |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 75 | // If a path spans more pixels than this, we need to crop it or else analytic AA can run out of |
| 76 | // fp32 precision. |
| 77 | static constexpr float kPathCropThreshold = 1 << 16; |
| 78 | |
| 79 | static void CropPath(const SkPath&, const SkIRect& cropbox, SkPath* out); |
| 80 | |
Chris Dalton | 82de18f | 2018-09-12 17:24:09 -0600 | [diff] [blame] | 81 | // Maximum inflation of path bounds due to stroking (from width, miter, caps). Strokes wider |
| 82 | // than this will be converted to fill paths and drawn by the CCPR filler instead. |
| 83 | static constexpr float kMaxBoundsInflationFromStroke = 4096; |
| 84 | |
Jiulong Wang | df5739c | 2020-10-13 15:09:09 -0700 | [diff] [blame] | 85 | static constexpr int kDoCopiesThreshold = 100; |
| 86 | |
Chris Dalton | 82de18f | 2018-09-12 17:24:09 -0600 | [diff] [blame] | 87 | static float GetStrokeDevWidth(const SkMatrix&, const SkStrokeRec&, |
| 88 | float* inflationRadius = nullptr); |
| 89 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 90 | private: |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 91 | GrCoverageCountingPathRenderer(CoverageType, AllowCaching, uint32_t contextUniqueID); |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 92 | |
| 93 | // GrPathRenderer overrides. |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 94 | StencilSupport onGetStencilSupport(const GrStyledShape&) const override { |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 95 | return GrPathRenderer::kNoSupport_StencilSupport; |
| 96 | } |
| 97 | CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override; |
| 98 | bool onDrawPath(const DrawPathArgs&) override; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 99 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 100 | GrCCPerOpsTaskPaths* lookupPendingPaths(uint32_t opsTaskID); |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 101 | void recordOp(GrOp::Owner, const DrawPathArgs&); |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 102 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 103 | const CoverageType fCoverageType; |
| 104 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 105 | // fPendingPaths holds the GrCCPerOpsTaskPaths objects that have already been created, but not |
| 106 | // flushed, and those that are still being created. All GrCCPerOpsTaskPaths objects will first |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 107 | // reside in fPendingPaths, then be moved to fFlushingPaths during preFlush(). |
Chris Dalton | a71305c | 2018-05-23 12:00:07 -0600 | [diff] [blame] | 108 | PendingPathsMap fPendingPaths; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 109 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 110 | // fFlushingPaths holds the GrCCPerOpsTaskPaths objects that are currently being flushed. |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 111 | // (It will only contain elements when fFlushing is true.) |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 112 | SkSTArray<4, sk_sp<GrCCPerOpsTaskPaths>> fFlushingPaths; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 113 | |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 114 | std::unique_ptr<GrCCPathCache> fPathCache; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 115 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 116 | SkDEBUGCODE(bool fFlushing = false); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 117 | |
| 118 | public: |
| 119 | void testingOnly_drawPathDirectly(const DrawPathArgs&); |
| 120 | const GrCCPerFlushResources* testingOnly_getCurrentFlushResources(); |
| 121 | const GrCCPathCache* testingOnly_getPathCache() const; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | #endif |