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 GrCCPerFlushResources_DEFINED |
| 9 | #define GrCCPerFlushResources_DEFINED |
| 10 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 11 | #include "GrNonAtomicRef.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 12 | #include "ccpr/GrCCAtlas.h" |
| 13 | #include "ccpr/GrCCPathParser.h" |
| 14 | #include "ccpr/GrCCPathProcessor.h" |
| 15 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame^] | 16 | class GrCCPathCacheEntry; |
| 17 | class GrOnFlushResourceProvider; |
| 18 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 19 | /** |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 20 | * This struct encapsulates the minimum and desired requirements for the GPU resources required by |
| 21 | * CCPR in a given flush. |
| 22 | */ |
| 23 | struct GrCCPerFlushResourceSpecs { |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame^] | 24 | int fNumCachedPaths = 0; |
| 25 | |
| 26 | int fNumCopiedPaths = 0; |
| 27 | GrCCPathParser::PathStats fCopyPathStats; |
| 28 | GrCCAtlas::Specs fCopyAtlasSpecs; |
| 29 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 30 | int fNumRenderedPaths = 0; |
| 31 | int fNumClipPaths = 0; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame^] | 32 | GrCCPathParser::PathStats fRenderedPathStats; |
| 33 | GrCCAtlas::Specs fRenderedAtlasSpecs; |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 34 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame^] | 35 | bool isEmpty() const { |
| 36 | return 0 == fNumCachedPaths + fNumCopiedPaths + fNumRenderedPaths + fNumClipPaths; |
| 37 | } |
| 38 | void convertCopiesToRenders(); |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | /** |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 42 | * This class wraps all the GPU resources that CCPR builds at flush time. It is allocated in CCPR's |
| 43 | * preFlush() method, and referenced by all the GrCCPerOpListPaths objects that are being flushed. |
| 44 | * It is deleted in postFlush() once all the flushing GrCCPerOpListPaths objects are deleted. |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 45 | */ |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 46 | class GrCCPerFlushResources : public GrNonAtomicRef<GrCCPerFlushResources> { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 47 | public: |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 48 | GrCCPerFlushResources(GrOnFlushResourceProvider*, const GrCCPerFlushResourceSpecs&); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 49 | |
| 50 | bool isMapped() const { return SkToBool(fPathInstanceData); } |
| 51 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame^] | 52 | // Copies a path out of the the previous flush's stashed mainline coverage count atlas, and into |
| 53 | // a cached, 8-bit, literal-coverage atlas. The actual source texture to copy from will be |
| 54 | // provided at the time finalize() is called. |
| 55 | GrCCAtlas* copyPathToCachedAtlas(const GrCCPathCacheEntry&, GrCCPathProcessor::DoEvenOddFill, |
| 56 | SkIVector* newAtlasOffset); |
| 57 | |
| 58 | // These two methods render a path into a temporary coverage count atlas. See GrCCPathParser for |
| 59 | // a description of the arguments. The returned atlases are "const" to prevent the caller from |
| 60 | // assigning a unique key. |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 61 | const GrCCAtlas* renderPathInAtlas(const SkIRect& clipIBounds, const SkMatrix&, const SkPath&, |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame^] | 62 | SkRect* devBounds, SkRect* devBounds45, SkIRect* devIBounds, |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 63 | SkIVector* devToAtlasOffset); |
| 64 | const GrCCAtlas* renderDeviceSpacePathInAtlas(const SkIRect& clipIBounds, const SkPath& devPath, |
| 65 | const SkIRect& devPathIBounds, |
| 66 | SkIVector* devToAtlasOffset); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 67 | |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 68 | // Returns the index in instanceBuffer() of the next instance that will be added by |
| 69 | // appendDrawPathInstance(). |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame] | 70 | int nextPathInstanceIdx() const { return fNextPathInstanceIdx; } |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 71 | |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 72 | // Appends an instance to instanceBuffer() that will draw a path to the destination render |
| 73 | // target. The caller is responsible to call set() on the returned instance, to keep track of |
| 74 | // its atlas and index (see nextPathInstanceIdx()), and to issue the actual draw call. |
| 75 | GrCCPathProcessor::Instance& appendDrawPathInstance() { |
| 76 | SkASSERT(this->isMapped()); |
| 77 | SkASSERT(fNextPathInstanceIdx < fEndPathInstance); |
| 78 | return fPathInstanceData[fNextPathInstanceIdx++]; |
| 79 | } |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 80 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame^] | 81 | // Finishes off the GPU buffers and renders the atlas(es). 'stashedAtlasProxy', if provided, is |
| 82 | // the mainline coverage count atlas from the previous flush. It will be used as the source |
| 83 | // texture for any copies setup by copyStashedPathToAtlas(). |
| 84 | bool finalize(GrOnFlushResourceProvider*, sk_sp<GrTextureProxy> stashedAtlasProxy, |
| 85 | SkTArray<sk_sp<GrRenderTargetContext>>* out); |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 86 | |
| 87 | // Accessors used by draw calls, once the resources have been finalized. |
| 88 | const GrCCPathParser& pathParser() const { SkASSERT(!this->isMapped()); return fPathParser; } |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 89 | const GrBuffer* indexBuffer() const { SkASSERT(!this->isMapped()); return fIndexBuffer.get(); } |
| 90 | const GrBuffer* vertexBuffer() const { SkASSERT(!this->isMapped()); return fVertexBuffer.get();} |
| 91 | GrBuffer* instanceBuffer() const { SkASSERT(!this->isMapped()); return fInstanceBuffer.get(); } |
| 92 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame^] | 93 | // Returns the mainline coverage count atlas that the client may stash for next flush, if any. |
| 94 | // The caller is responsible to call getOrAssignUniqueKey() on this atlas if they wish to |
| 95 | // actually stash it in order to copy paths into cached atlases. |
| 96 | GrCCAtlas* nextAtlasToStash() { |
| 97 | return fRenderedAtlasStack.empty() ? nullptr : &fRenderedAtlasStack.front(); |
| 98 | } |
| 99 | |
| 100 | // Returs true if the client has called getOrAssignUniqueKey() on our nextAtlasToStash(). |
| 101 | bool hasStashedAtlas() const { |
| 102 | return !fRenderedAtlasStack.empty() && fRenderedAtlasStack.front().uniqueKey().isValid(); |
| 103 | } |
| 104 | const GrUniqueKey& stashedAtlasKey() const { |
| 105 | SkASSERT(this->hasStashedAtlas()); |
| 106 | return fRenderedAtlasStack.front().uniqueKey(); |
| 107 | } |
| 108 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 109 | private: |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 110 | bool placeParsedPathInAtlas(const SkIRect& clipIBounds, const SkIRect& pathIBounds, |
| 111 | SkIVector* devToAtlasOffset); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 112 | |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 113 | GrCCPathParser fPathParser; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame^] | 114 | GrCCAtlasStack fCopyAtlasStack; |
| 115 | GrCCAtlasStack fRenderedAtlasStack; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 116 | |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 117 | const sk_sp<const GrBuffer> fIndexBuffer; |
| 118 | const sk_sp<const GrBuffer> fVertexBuffer; |
| 119 | const sk_sp<GrBuffer> fInstanceBuffer; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 120 | |
| 121 | GrCCPathProcessor::Instance* fPathInstanceData = nullptr; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame^] | 122 | int fNextCopyInstanceIdx; |
| 123 | SkDEBUGCODE(int fEndCopyInstance); |
| 124 | int fNextPathInstanceIdx; |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 125 | SkDEBUGCODE(int fEndPathInstance); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | #endif |