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 | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 18 | /** |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 19 | * 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] | 20 | * buffer. (See GrCCCoverageProcessor, GrCCPathProcessor.) |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 21 | * |
| 22 | * It also serves as the per-render-target tracker for pending path draws, and at the start of |
| 23 | * flush, it compiles GPU buffers and renders a "coverage count atlas" for the upcoming paths. |
| 24 | */ |
Chris Dalton | 03730e6 | 2021-03-11 19:41:40 -0700 | [diff] [blame] | 25 | class GrCoverageCountingPathRenderer : public GrOnFlushCallbackObject { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 26 | public: |
Chris Dalton | 03730e6 | 2021-03-11 19:41:40 -0700 | [diff] [blame] | 27 | static bool IsSupported(const GrCaps&); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 28 | |
Chris Dalton | 03730e6 | 2021-03-11 19:41:40 -0700 | [diff] [blame] | 29 | static std::unique_ptr<GrCoverageCountingPathRenderer> CreateIfSupported(const GrCaps&); |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 30 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 31 | using PendingPathsMap = std::map<uint32_t, sk_sp<GrCCPerOpsTaskPaths>>; |
Chris Dalton | a71305c | 2018-05-23 12:00:07 -0600 | [diff] [blame] | 32 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 33 | // In DDL mode, Ganesh needs to be able to move the pending GrCCPerOpsTaskPaths to the DDL |
| 34 | // object (detachPendingPaths) and then return them upon replay (mergePendingPaths). |
Chris Dalton | a71305c | 2018-05-23 12:00:07 -0600 | [diff] [blame] | 35 | PendingPathsMap detachPendingPaths() { return std::move(fPendingPaths); } |
| 36 | |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 37 | void mergePendingPaths(const PendingPathsMap& paths) { |
| 38 | #ifdef SK_DEBUG |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 39 | // Ensure there are no duplicate opsTask IDs between the incoming path map and ours. |
| 40 | // 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] | 41 | // from different DDL recordings. |
| 42 | for (const auto& it : paths) { |
| 43 | SkASSERT(!fPendingPaths.count(it.first)); |
| 44 | } |
| 45 | #endif |
| 46 | |
| 47 | fPendingPaths.insert(paths.begin(), paths.end()); |
Chris Dalton | a71305c | 2018-05-23 12:00:07 -0600 | [diff] [blame] | 48 | } |
| 49 | |
Chris Dalton | 1e7b2e5 | 2021-03-09 21:29:32 -0700 | [diff] [blame] | 50 | // The atlas can take up a lot of memory. We should only use clip processors for small paths. |
| 51 | // Large clip paths should consider a different method, like MSAA stencil. |
| 52 | constexpr static int64_t kMaxClipPathArea = 256 * 256; |
| 53 | |
Chris Dalton | bf9c63b | 2021-03-19 15:44:18 -0600 | [diff] [blame] | 54 | GrFPResult makeClipProcessor(std::unique_ptr<GrFragmentProcessor> inputFP, uint32_t opsTaskID, |
| 55 | const SkPath& deviceSpacePath, const SkIRect& accessRect, |
| 56 | const GrCaps& caps); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 57 | |
| 58 | // GrOnFlushCallbackObject overrides. |
Adlai Holler | 9902cff | 2020-11-11 08:51:25 -0500 | [diff] [blame] | 59 | void preFlush(GrOnFlushResourceProvider*, SkSpan<const uint32_t> taskIDs) override; |
| 60 | void postFlush(GrDeferredUploadToken, SkSpan<const uint32_t> taskIDs) override; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 61 | |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 62 | // If a path spans more pixels than this, we need to crop it or else analytic AA can run out of |
| 63 | // fp32 precision. |
| 64 | static constexpr float kPathCropThreshold = 1 << 16; |
| 65 | |
Chris Dalton | 82de18f | 2018-09-12 17:24:09 -0600 | [diff] [blame] | 66 | // Maximum inflation of path bounds due to stroking (from width, miter, caps). Strokes wider |
| 67 | // than this will be converted to fill paths and drawn by the CCPR filler instead. |
| 68 | static constexpr float kMaxBoundsInflationFromStroke = 4096; |
| 69 | |
Jiulong Wang | df5739c | 2020-10-13 15:09:09 -0700 | [diff] [blame] | 70 | static constexpr int kDoCopiesThreshold = 100; |
| 71 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 72 | private: |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 73 | GrCCPerOpsTaskPaths* lookupPendingPaths(uint32_t opsTaskID); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 74 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 75 | // fPendingPaths holds the GrCCPerOpsTaskPaths objects that have already been created, but not |
| 76 | // 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] | 77 | // reside in fPendingPaths, then be moved to fFlushingPaths during preFlush(). |
Chris Dalton | a71305c | 2018-05-23 12:00:07 -0600 | [diff] [blame] | 78 | PendingPathsMap fPendingPaths; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 79 | |
Chris Dalton | 7d592cd | 2021-03-11 22:49:33 -0700 | [diff] [blame] | 80 | SkDEBUGCODE(bool fFlushing = false); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | #endif |