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 | |
| 11 | #include "GrAllocator.h" |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 12 | #include "GrNonAtomicRef.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 13 | #include "ccpr/GrCCAtlas.h" |
| 14 | #include "ccpr/GrCCPathParser.h" |
| 15 | #include "ccpr/GrCCPathProcessor.h" |
| 16 | |
| 17 | /** |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 18 | * This class wraps all the GPU resources that CCPR builds at flush time. It is allocated in CCPR's |
| 19 | * preFlush() method, and referenced by all the GrCCPerOpListPaths objects that are being flushed. |
| 20 | * 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] | 21 | */ |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 22 | class GrCCPerFlushResources : public GrNonAtomicRef<GrCCPerFlushResources> { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 23 | public: |
| 24 | GrCCPerFlushResources(GrOnFlushResourceProvider*, int numPathDraws, int numClipPaths, |
| 25 | const GrCCPathParser::PathStats&); |
| 26 | |
| 27 | bool isMapped() const { return SkToBool(fPathInstanceData); } |
| 28 | |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame^] | 29 | GrCCAtlas* renderPathInAtlas(const GrCaps&, const SkIRect& clipIBounds, const SkMatrix&, |
| 30 | const SkPath&, SkRect* devBounds, SkRect* devBounds45, |
| 31 | int16_t* offsetX, int16_t* offsetY); |
| 32 | GrCCAtlas* renderDeviceSpacePathInAtlas(const GrCaps&, const SkIRect& clipIBounds, |
| 33 | const SkPath& devPath, const SkIRect& devPathIBounds, |
| 34 | int16_t* atlasOffsetX, int16_t* atlasOffsetY); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 35 | |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 36 | GrCCPathProcessor::Instance& appendDrawPathInstance() { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 37 | SkASSERT(this->isMapped()); |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame^] | 38 | SkASSERT(fNextPathInstanceIdx < fPathInstanceBufferCount); |
| 39 | return fPathInstanceData[fNextPathInstanceIdx++]; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 40 | } |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame^] | 41 | int nextPathInstanceIdx() const { return fNextPathInstanceIdx; } |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 42 | |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame^] | 43 | bool finalize(GrOnFlushResourceProvider*, SkTArray<sk_sp<GrRenderTargetContext>>* atlasDraws); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 44 | |
| 45 | const GrBuffer* indexBuffer() const { SkASSERT(!this->isMapped()); return fIndexBuffer.get(); } |
| 46 | const GrBuffer* vertexBuffer() const { SkASSERT(!this->isMapped()); return fVertexBuffer.get();} |
| 47 | GrBuffer* instanceBuffer() const { SkASSERT(!this->isMapped()); return fInstanceBuffer.get(); } |
| 48 | |
| 49 | private: |
| 50 | GrCCAtlas* placeParsedPathInAtlas(const GrCaps&, const SkIRect& clipIBounds, |
| 51 | const SkIRect& pathIBounds, int16_t* atlasOffsetX, |
| 52 | int16_t* atlasOffsetY); |
| 53 | |
| 54 | const sk_sp<GrCCPathParser> fPathParser; |
| 55 | |
| 56 | sk_sp<const GrBuffer> fIndexBuffer; |
| 57 | sk_sp<const GrBuffer> fVertexBuffer; |
| 58 | sk_sp<GrBuffer> fInstanceBuffer; |
| 59 | |
| 60 | GrCCPathProcessor::Instance* fPathInstanceData = nullptr; |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame^] | 61 | int fNextPathInstanceIdx = 0; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 62 | SkDEBUGCODE(int fPathInstanceBufferCount); |
| 63 | |
| 64 | GrSTAllocator<4, GrCCAtlas> fAtlases; |
| 65 | }; |
| 66 | |
| 67 | #endif |