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" |
| 12 | #include "ccpr/GrCCAtlas.h" |
| 13 | #include "ccpr/GrCCPathParser.h" |
| 14 | #include "ccpr/GrCCPathProcessor.h" |
| 15 | |
| 16 | /** |
| 17 | * This class wraps all the GPU resources that CCPR builds at flush time. |
| 18 | */ |
| 19 | class GrCCPerFlushResources { |
| 20 | public: |
| 21 | GrCCPerFlushResources(GrOnFlushResourceProvider*, int numPathDraws, int numClipPaths, |
| 22 | const GrCCPathParser::PathStats&); |
| 23 | |
| 24 | bool isMapped() const { return SkToBool(fPathInstanceData); } |
| 25 | |
| 26 | GrCCAtlas* addPathToAtlas(const GrCaps&, const SkIRect& clipIBounds, const SkMatrix&, |
| 27 | const SkPath&, SkRect* devBounds, SkRect* devBounds45, |
| 28 | int16_t* offsetX, int16_t* offsetY); |
| 29 | GrCCAtlas* addDeviceSpacePathToAtlas(const GrCaps&, const SkIRect& clipIBounds, |
| 30 | const SkPath& devPath, const SkIRect& devPathIBounds, |
| 31 | int16_t* atlasOffsetX, int16_t* atlasOffsetY); |
| 32 | |
| 33 | // See GrCCPathProcessor::Instance. |
| 34 | int appendDrawPathInstance(const SkRect& devBounds, const SkRect& devBounds45, |
| 35 | const std::array<float, 4>& viewMatrix, |
| 36 | const std::array<float, 2>& viewTranslate, |
| 37 | const std::array<int16_t, 2>& atlasOffset, uint32_t color) { |
| 38 | SkASSERT(this->isMapped()); |
| 39 | SkASSERT(fPathInstanceCount < fPathInstanceBufferCount); |
| 40 | fPathInstanceData[fPathInstanceCount] = {devBounds, devBounds45, viewMatrix, viewTranslate, |
| 41 | atlasOffset, color}; |
| 42 | return fPathInstanceCount++; |
| 43 | } |
| 44 | int pathInstanceCount() const { return fPathInstanceCount; } |
| 45 | |
| 46 | bool finalize(GrOnFlushResourceProvider*, |
| 47 | SkTArray<sk_sp<GrRenderTargetContext>>* atlasDraws); |
| 48 | |
| 49 | const GrBuffer* indexBuffer() const { SkASSERT(!this->isMapped()); return fIndexBuffer.get(); } |
| 50 | const GrBuffer* vertexBuffer() const { SkASSERT(!this->isMapped()); return fVertexBuffer.get();} |
| 51 | GrBuffer* instanceBuffer() const { SkASSERT(!this->isMapped()); return fInstanceBuffer.get(); } |
| 52 | |
| 53 | private: |
| 54 | GrCCAtlas* placeParsedPathInAtlas(const GrCaps&, const SkIRect& clipIBounds, |
| 55 | const SkIRect& pathIBounds, int16_t* atlasOffsetX, |
| 56 | int16_t* atlasOffsetY); |
| 57 | |
| 58 | const sk_sp<GrCCPathParser> fPathParser; |
| 59 | |
| 60 | sk_sp<const GrBuffer> fIndexBuffer; |
| 61 | sk_sp<const GrBuffer> fVertexBuffer; |
| 62 | sk_sp<GrBuffer> fInstanceBuffer; |
| 63 | |
| 64 | GrCCPathProcessor::Instance* fPathInstanceData = nullptr; |
| 65 | int fPathInstanceCount = 0; |
| 66 | SkDEBUGCODE(int fPathInstanceBufferCount); |
| 67 | |
| 68 | GrSTAllocator<4, GrCCAtlas> fAtlases; |
| 69 | }; |
| 70 | |
| 71 | #endif |