Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 GrCCDrawPathsOp_DEFINED |
| 9 | #define GrCCDrawPathsOp_DEFINED |
| 10 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 11 | #include "GrShape.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 12 | #include "SkTInternalLList.h" |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 13 | #include "ccpr/GrCCSTLList.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 14 | #include "ops/GrDrawOp.h" |
| 15 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 16 | struct GrCCPerFlushResourceSpecs; |
Chris Dalton | b68bcc4 | 2018-09-14 00:44:22 -0600 | [diff] [blame^] | 17 | struct GrCCPerOpListPaths; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 18 | class GrCCAtlas; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 19 | class GrOnFlushResourceProvider; |
| 20 | class GrCCPathCache; |
| 21 | class GrCCPathCacheEntry; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 22 | class GrCCPerFlushResources; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * This is the Op that draws paths to the actual canvas, using atlases generated by CCPR. |
| 26 | */ |
| 27 | class GrCCDrawPathsOp : public GrDrawOp { |
| 28 | public: |
| 29 | DEFINE_OP_CLASS_ID |
| 30 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrCCDrawPathsOp); |
| 31 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 32 | static std::unique_ptr<GrCCDrawPathsOp> Make(GrContext*, const SkIRect& clipIBounds, |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 33 | const SkMatrix&, const GrShape&, GrPaint&&); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 34 | ~GrCCDrawPathsOp() override; |
| 35 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 36 | const char* name() const override { return "GrCCDrawPathsOp"; } |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 37 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 38 | RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 39 | CombineResult onCombineIfPossible(GrOp*, const GrCaps&) override; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 40 | void visitProxies(const VisitProxyFunc& fn) const override { fProcessors.visitProxies(fn); } |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 41 | void onPrepare(GrOpFlushState*) override {} |
| 42 | |
Chris Dalton | b68bcc4 | 2018-09-14 00:44:22 -0600 | [diff] [blame^] | 43 | void wasRecorded(sk_sp<GrCCPerOpListPaths> owningPerOpListPaths); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 44 | |
| 45 | // Makes decisions about how to draw each path (cached, copied, rendered, etc.), and |
| 46 | // increments/fills out the corresponding GrCCPerFlushResourceSpecs. 'stashedAtlasKey', if |
| 47 | // valid, references the mainline coverage count atlas from the previous flush. Paths found in |
| 48 | // this atlas will be copied to more permanent atlases in the resource cache. |
| 49 | void accountForOwnPaths(GrCCPathCache*, GrOnFlushResourceProvider*, |
| 50 | const GrUniqueKey& stashedAtlasKey, GrCCPerFlushResourceSpecs*); |
| 51 | |
| 52 | // Allows the caller to decide whether to copy paths out of the stashed atlas and into the |
| 53 | // resource cache, or to just re-render the paths from scratch. If there aren't many copies or |
| 54 | // the copies would only fill a small atlas, it's probably best to just re-render. |
| 55 | enum class DoCopiesToCache : bool { |
| 56 | kNo = false, |
| 57 | kYes = true |
| 58 | }; |
| 59 | |
| 60 | // Allocates the GPU resources indicated by accountForOwnPaths(), in preparation for drawing. If |
| 61 | // DoCopiesToCache is kNo, the paths slated for copy will instead be re-rendered from scratch. |
| 62 | // |
| 63 | // NOTE: If using DoCopiesToCache::kNo, it is the caller's responsibility to call |
| 64 | // convertCopiesToRenders() on the GrCCPerFlushResourceSpecs. |
| 65 | void setupResources(GrOnFlushResourceProvider*, GrCCPerFlushResources*, DoCopiesToCache); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 66 | |
| 67 | void onExecute(GrOpFlushState*) override; |
| 68 | |
| 69 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 70 | friend class GrOpMemoryPool; |
| 71 | |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 72 | static std::unique_ptr<GrCCDrawPathsOp> InternalMake(GrContext*, const SkIRect& clipIBounds, |
| 73 | const SkMatrix&, const GrShape&, |
| 74 | float strokeDevWidth, |
| 75 | const SkRect& conservativeDevBounds, |
| 76 | GrPaint&&); |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 77 | enum class Visibility { |
| 78 | kPartial, |
| 79 | kMostlyComplete, // (i.e., can we cache the whole path mask if we think it will be reused?) |
| 80 | kComplete |
| 81 | }; |
| 82 | |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 83 | GrCCDrawPathsOp(const SkMatrix&, const GrShape&, float strokeDevWidth, |
| 84 | const SkIRect& shapeConservativeIBounds, const SkIRect& maskDevIBounds, |
| 85 | Visibility maskVisibility, const SkRect& conservativeDevBounds, GrPaint&&); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 86 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 87 | void recordInstance(GrTextureProxy* atlasProxy, int instanceIdx); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 88 | |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 89 | const SkMatrix fViewMatrixIfUsingLocalCoords; |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 90 | |
| 91 | struct SingleDraw { |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 92 | SingleDraw(const SkMatrix&, const GrShape&, float strokeDevWidth, |
| 93 | const SkIRect& shapeConservativeIBounds, const SkIRect& maskDevIBounds, |
| 94 | Visibility maskVisibility, GrColor); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 95 | ~SingleDraw(); |
| 96 | |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 97 | SkMatrix fMatrix; |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 98 | GrShape fShape; |
| 99 | float fStrokeDevWidth; |
| 100 | const SkIRect fShapeConservativeIBounds; |
Chris Dalton | a8429cf | 2018-06-22 11:43:31 -0600 | [diff] [blame] | 101 | SkIRect fMaskDevIBounds; |
| 102 | Visibility fMaskVisibility; |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 103 | GrColor fColor; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 104 | |
| 105 | sk_sp<GrCCPathCacheEntry> fCacheEntry; |
| 106 | sk_sp<GrTextureProxy> fCachedAtlasProxy; |
| 107 | SkIVector fCachedMaskShift; |
| 108 | |
Chris Dalton | 644341a | 2018-06-18 19:14:16 -0600 | [diff] [blame] | 109 | SingleDraw* fNext = nullptr; |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | GrCCSTLList<SingleDraw> fDraws; |
| 113 | SkDEBUGCODE(int fNumDraws = 1); |
| 114 | |
Chris Dalton | b68bcc4 | 2018-09-14 00:44:22 -0600 | [diff] [blame^] | 115 | sk_sp<GrCCPerOpListPaths> fOwningPerOpListPaths; |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 116 | GrProcessorSet fProcessors; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 117 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 118 | struct InstanceRange { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 119 | GrTextureProxy* fAtlasProxy; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 120 | int fEndInstanceIdx; |
| 121 | }; |
| 122 | |
| 123 | SkSTArray<2, InstanceRange, true> fInstanceRanges; |
| 124 | int fBaseInstance SkDEBUGCODE(= -1); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | #endif |