OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrDrawPathBatch_DEFINED | 8 #ifndef GrDrawPathBatch_DEFINED |
9 #define GrDrawPathBatch_DEFINED | 9 #define GrDrawPathBatch_DEFINED |
10 | 10 |
| 11 #include "GrBatchFlushState.h" |
11 #include "GrDrawBatch.h" | 12 #include "GrDrawBatch.h" |
12 #include "GrGpu.h" | 13 #include "GrGpu.h" |
13 #include "GrPath.h" | 14 #include "GrPath.h" |
14 #include "GrPathRendering.h" | 15 #include "GrPathRendering.h" |
15 #include "GrPathProcessor.h" | 16 #include "GrPathProcessor.h" |
16 | 17 |
17 class GrDrawPathBatch final : public GrDrawBatch { | 18 #include "SkTLList.h" |
| 19 |
| 20 class GrDrawPathBatchBase : public GrDrawBatch { |
18 public: | 21 public: |
19 // This must return the concrete type because we install the stencil setting
s late :( | 22 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
20 static GrDrawPathBatch* Create(const GrPathProcessor* primProc, const GrPath
* path) { | 23 this->pathProcessor()->getInvariantOutputColor(out); |
| 24 } |
| 25 |
| 26 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 27 this->pathProcessor()->getInvariantOutputCoverage(out); |
| 28 } |
| 29 |
| 30 void setStencilSettings(const GrStencilSettings& stencil) { fStencilSettings
= stencil; } |
| 31 |
| 32 protected: |
| 33 GrDrawPathBatchBase(const GrPathProcessor* pathProc) : fPrimitiveProcessor(p
athProc) {} |
| 34 |
| 35 GrBatchTracker* tracker() { return reinterpret_cast<GrBatchTracker*>(&fWhatc
hamacallit); } |
| 36 const GrPathProcessor* pathProcessor() const { return fPrimitiveProcessor.ge
t(); } |
| 37 const GrStencilSettings& stencilSettings() const { return fStencilSettings;
} |
| 38 const GrPipelineOptimizations& opts() const { return fOpts; } |
| 39 |
| 40 private: |
| 41 void initBatchTracker(const GrPipelineOptimizations& opts) override { |
| 42 this->pathProcessor()->initBatchTracker(this->tracker(), opts); |
| 43 fOpts = opts; |
| 44 } |
| 45 |
| 46 GrPendingProgramElement<const GrPathProcessor> fPrimitiveProcessor; |
| 47 PathBatchTracker fWhatchamacallit; //
TODO: delete this |
| 48 GrStencilSettings fStencilSettings; |
| 49 GrPipelineOptimizations fOpts; |
| 50 |
| 51 typedef GrDrawBatch INHERITED; |
| 52 }; |
| 53 |
| 54 class GrDrawPathBatch final : public GrDrawPathBatchBase { |
| 55 public: |
| 56 // This can't return a more abstract type because we install the stencil set
tings late :( |
| 57 static GrDrawPathBatchBase* Create(const GrPathProcessor* primProc, const Gr
Path* path) { |
21 return new GrDrawPathBatch(primProc, path); | 58 return new GrDrawPathBatch(primProc, path); |
22 } | 59 } |
23 | 60 |
24 const char* name() const override { return "DrawPath"; } | 61 const char* name() const override { return "DrawPath"; } |
25 | 62 |
26 SkString dumpInfo() const override { | 63 SkString dumpInfo() const override; |
27 SkString string; | |
28 string.printf("PATH: 0x%p", fPath.get()); | |
29 return string; | |
30 } | |
31 | |
32 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | |
33 fPrimitiveProcessor->getInvariantOutputColor(out); | |
34 } | |
35 | |
36 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | |
37 fPrimitiveProcessor->getInvariantOutputCoverage(out); | |
38 } | |
39 | |
40 void setStencilSettings(const GrStencilSettings& stencil) { fStencilSettings
= stencil; } | |
41 | 64 |
42 private: | 65 private: |
43 GrBatchTracker* tracker() { return reinterpret_cast<GrBatchTracker*>(&fWhatc
hamacallit); } | 66 GrDrawPathBatch(const GrPathProcessor* pathProc, const GrPath* path) |
44 GrDrawPathBatch(const GrPathProcessor* primProc, const GrPath* path) | 67 : INHERITED(pathProc) |
45 : fPrimitiveProcessor(primProc) | 68 , fPath(path) { |
46 , fPath(path) { | |
47 fBounds = path->getBounds(); | 69 fBounds = path->getBounds(); |
48 primProc->viewMatrix().mapRect(&fBounds); | 70 this->pathProcessor()->viewMatrix().mapRect(&fBounds); |
49 this->initClassID<GrDrawPathBatch>(); | 71 this->initClassID<GrDrawPathBatch>(); |
50 } | 72 } |
51 | 73 |
52 void initBatchTracker(const GrPipelineOptimizations& opts) override { | |
53 fPrimitiveProcessor->initBatchTracker(this->tracker(), opts); | |
54 } | |
55 | |
56 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return f
alse; } | 74 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return f
alse; } |
57 | 75 |
58 void onPrepare(GrBatchFlushState*) override {} | 76 void onPrepare(GrBatchFlushState*) override {} |
59 | 77 |
60 void onDraw(GrBatchFlushState* state) override { | 78 void onDraw(GrBatchFlushState* state) override; |
61 GrProgramDesc desc; | 79 |
62 state->gpu()->buildProgramDesc(&desc, *fPrimitiveProcessor.get(), | 80 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
63 *this->pipeline(), *this->tracker()); | 81 |
64 GrPathRendering::DrawPathArgs args(fPrimitiveProcessor.get(), this->pipe
line(), | 82 typedef GrDrawPathBatchBase INHERITED; |
65 &desc, this->tracker(), &fStencilSett
ings); | 83 }; |
66 state->gpu()->pathRendering()->drawPath(args, fPath.get()); | 84 |
| 85 /** |
| 86 * This could be nested inside the batch class, but for now it must be declarabl
e in a public |
| 87 * header (GrDrawContext) |
| 88 */ |
| 89 class GrPathRangeDraw : public GrNonAtomicRef { |
| 90 public: |
| 91 typedef GrPathRendering::PathTransformType TransformType; |
| 92 |
| 93 static GrPathRangeDraw* Create(GrPathRange* range, TransformType transformTy
pe, |
| 94 int reserveCnt) { |
| 95 return SkNEW_ARGS(GrPathRangeDraw, (range, transformType, reserveCnt)); |
67 } | 96 } |
68 | 97 |
69 GrPendingProgramElement<const GrPathProcessor> fPrimitiveProcessor; | 98 void append(uint16_t index, float transform[]) { |
70 PathBatchTracker fWhatchamacallit; // TOD
O: delete this | 99 fTransforms.push_back_n(GrPathRendering::PathTransformSize(fTransformTyp
e), transform); |
71 GrStencilSettings fStencilSettings; | 100 fIndices.push_back(index); |
72 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 101 } |
| 102 |
| 103 int count() const { return fIndices.count(); } |
| 104 |
| 105 TransformType transformType() const { return fTransformType; } |
| 106 |
| 107 const float* transforms() const { return fTransforms.begin(); } |
| 108 |
| 109 const uint16_t* indices() const { return fIndices.begin(); } |
| 110 |
| 111 const GrPathRange* range() const { return fPathRange.get(); } |
| 112 |
| 113 static bool CanMerge(const GrPathRangeDraw& a, const GrPathRangeDraw& b) { |
| 114 return a.transformType() == b.transformType() && a.range() == b.range(); |
| 115 } |
| 116 |
| 117 private: |
| 118 GrPathRangeDraw(GrPathRange* range, TransformType transformType, int reserve
Cnt) |
| 119 : fPathRange(SkRef(range)) |
| 120 , fTransformType(transformType) |
| 121 , fIndices(reserveCnt) |
| 122 , fTransforms(reserveCnt * GrPathRendering::PathTransformSize(transformT
ype)) { |
| 123 SkDEBUGCODE(fUsedInBatch = false;) |
| 124 } |
| 125 |
| 126 // Reserve space for 64 paths where indices are 16 bit and transforms are tr
anslations. |
| 127 static const int kIndexReserveCnt = 64; |
| 128 static const int kTransformBufferReserveCnt = 2 * 64; |
| 129 |
| 130 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; |
| 131 GrPathRendering::PathTransformType fTransformType; |
| 132 SkSTArray<kIndexReserveCnt, uint16_t, true> fIndices; |
| 133 SkSTArray<kTransformBufferReserveCnt, float, true> fTransforms; |
| 134 |
| 135 // To ensure we don't reuse these across batches. |
| 136 #ifdef SK_DEBUG |
| 137 bool fUsedInBatch; |
| 138 friend class GrDrawPathRangeBatch; |
| 139 #endif |
| 140 |
| 141 typedef GrNonAtomicRef INHERITED; |
| 142 }; |
| 143 |
| 144 // Template this if we decide to support index types other than 16bit |
| 145 class GrDrawPathRangeBatch final : public GrDrawPathBatchBase { |
| 146 public: |
| 147 // This can't return a more abstracet type because we install the stencil se
ttings late :( |
| 148 static GrDrawPathBatchBase* Create(const GrPathProcessor* pathProc, |
| 149 GrPathRangeDraw* pathRangeDraw) { |
| 150 return SkNEW_ARGS(GrDrawPathRangeBatch, (pathProc, pathRangeDraw)); |
| 151 } |
| 152 |
| 153 ~GrDrawPathRangeBatch() override; |
| 154 |
| 155 const char* name() const override { return "DrawPathRange"; } |
| 156 |
| 157 SkString dumpInfo() const override; |
| 158 |
| 159 private: |
| 160 inline bool isWinding() const; |
| 161 |
| 162 GrDrawPathRangeBatch(const GrPathProcessor* pathProc, GrPathRangeDraw* pathR
angeDraw); |
| 163 |
| 164 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override; |
| 165 |
| 166 void onPrepare(GrBatchFlushState*) override {} |
| 167 |
| 168 void onDraw(GrBatchFlushState* state) override; |
| 169 |
| 170 typedef SkTLList<GrPathRangeDraw*> DrawList; |
| 171 DrawList fDraws; |
| 172 int fTotalPathCount; |
| 173 |
| 174 typedef GrDrawPathBatchBase INHERITED; |
73 }; | 175 }; |
74 | 176 |
75 #endif | 177 #endif |
OLD | NEW |