blob: 14e3a1c667e02393d37c966b13928142cd13b4f1 [file] [log] [blame]
Chris Dalton5ba36ba2018-05-09 01:08:38 -06001/*
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 Daltond7e22272018-05-23 10:17:17 -060012#include "GrNonAtomicRef.h"
Chris Dalton5ba36ba2018-05-09 01:08:38 -060013#include "ccpr/GrCCAtlas.h"
14#include "ccpr/GrCCPathParser.h"
15#include "ccpr/GrCCPathProcessor.h"
16
17/**
Chris Dalton42c21152018-06-13 15:28:19 -060018 * This struct encapsulates the minimum and desired requirements for the GPU resources required by
19 * CCPR in a given flush.
20 */
21struct GrCCPerFlushResourceSpecs {
22 int fNumRenderedPaths = 0;
23 int fNumClipPaths = 0;
24 GrCCPathParser::PathStats fParsingPathStats;
25 GrCCAtlas::Specs fAtlasSpecs;
26
27 bool isEmpty() const { return 0 == fNumRenderedPaths + fNumClipPaths; }
28};
29
30/**
Chris Daltond7e22272018-05-23 10:17:17 -060031 * This class wraps all the GPU resources that CCPR builds at flush time. It is allocated in CCPR's
32 * preFlush() method, and referenced by all the GrCCPerOpListPaths objects that are being flushed.
33 * It is deleted in postFlush() once all the flushing GrCCPerOpListPaths objects are deleted.
Chris Dalton5ba36ba2018-05-09 01:08:38 -060034 */
Chris Daltond7e22272018-05-23 10:17:17 -060035class GrCCPerFlushResources : public GrNonAtomicRef<GrCCPerFlushResources> {
Chris Dalton5ba36ba2018-05-09 01:08:38 -060036public:
Chris Dalton42c21152018-06-13 15:28:19 -060037 GrCCPerFlushResources(GrOnFlushResourceProvider*, const GrCCPerFlushResourceSpecs&);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060038
39 bool isMapped() const { return SkToBool(fPathInstanceData); }
40
Chris Dalton42c21152018-06-13 15:28:19 -060041 GrCCAtlas* renderPathInAtlas(const SkIRect& clipIBounds, const SkMatrix&, const SkPath&,
42 SkRect* devBounds, SkRect* devBounds45, int16_t* offsetX,
43 int16_t* offsetY);
44 GrCCAtlas* renderDeviceSpacePathInAtlas(const SkIRect& clipIBounds, const SkPath& devPath,
45 const SkIRect& devPathIBounds, int16_t* atlasOffsetX,
46 int16_t* atlasOffsetY);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060047
Chris Dalton1c548942018-05-22 13:09:48 -060048 GrCCPathProcessor::Instance& appendDrawPathInstance() {
Chris Dalton5ba36ba2018-05-09 01:08:38 -060049 SkASSERT(this->isMapped());
Chris Daltondaef06a2018-05-23 17:11:09 -060050 SkASSERT(fNextPathInstanceIdx < fPathInstanceBufferCount);
51 return fPathInstanceData[fNextPathInstanceIdx++];
Chris Dalton5ba36ba2018-05-09 01:08:38 -060052 }
Chris Daltondaef06a2018-05-23 17:11:09 -060053 int nextPathInstanceIdx() const { return fNextPathInstanceIdx; }
Chris Dalton5ba36ba2018-05-09 01:08:38 -060054
Chris Daltondaef06a2018-05-23 17:11:09 -060055 bool finalize(GrOnFlushResourceProvider*, SkTArray<sk_sp<GrRenderTargetContext>>* atlasDraws);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060056
57 const GrBuffer* indexBuffer() const { SkASSERT(!this->isMapped()); return fIndexBuffer.get(); }
58 const GrBuffer* vertexBuffer() const { SkASSERT(!this->isMapped()); return fVertexBuffer.get();}
59 GrBuffer* instanceBuffer() const { SkASSERT(!this->isMapped()); return fInstanceBuffer.get(); }
60
61private:
Chris Dalton42c21152018-06-13 15:28:19 -060062 GrCCAtlas* placeParsedPathInAtlas(const SkIRect& clipIBounds, const SkIRect& pathIBounds,
63 int16_t* atlasOffsetX, int16_t* atlasOffsetY);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060064
65 const sk_sp<GrCCPathParser> fPathParser;
Chris Dalton42c21152018-06-13 15:28:19 -060066 const GrCCAtlas::Specs fAtlasSpecs;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060067
68 sk_sp<const GrBuffer> fIndexBuffer;
69 sk_sp<const GrBuffer> fVertexBuffer;
70 sk_sp<GrBuffer> fInstanceBuffer;
71
72 GrCCPathProcessor::Instance* fPathInstanceData = nullptr;
Chris Daltondaef06a2018-05-23 17:11:09 -060073 int fNextPathInstanceIdx = 0;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060074 SkDEBUGCODE(int fPathInstanceBufferCount);
75
76 GrSTAllocator<4, GrCCAtlas> fAtlases;
77};
78
79#endif