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 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 }; | 88 }; |
89 | 89 |
90 /** | 90 /** |
91 * This could be nested inside the batch class, but for now it must be declarabl
e in a public | 91 * This could be nested inside the batch class, but for now it must be declarabl
e in a public |
92 * header (GrDrawContext) | 92 * header (GrDrawContext) |
93 */ | 93 */ |
94 class GrPathRangeDraw : public GrNonAtomicRef { | 94 class GrPathRangeDraw : public GrNonAtomicRef { |
95 public: | 95 public: |
96 typedef GrPathRendering::PathTransformType TransformType; | 96 typedef GrPathRendering::PathTransformType TransformType; |
97 | 97 |
98 static GrPathRangeDraw* Create(GrPathRange* range, TransformType transformTy
pe, | 98 static GrPathRangeDraw* Create(TransformType transformType, int reserveCnt)
{ |
99 int reserveCnt) { | 99 return new GrPathRangeDraw(transformType, reserveCnt); |
100 return new GrPathRangeDraw(range, transformType, reserveCnt); | |
101 } | 100 } |
102 | 101 |
103 void append(uint16_t index, float transform[]) { | 102 void append(uint16_t index, float transform[]) { |
104 fTransforms.push_back_n(GrPathRendering::PathTransformSize(fTransformTyp
e), transform); | 103 fTransforms.push_back_n(GrPathRendering::PathTransformSize(fTransformTyp
e), transform); |
105 fIndices.push_back(index); | 104 fIndices.push_back(index); |
106 } | 105 } |
107 | 106 |
108 int count() const { return fIndices.count(); } | 107 int count() const { return fIndices.count(); } |
109 | 108 |
110 TransformType transformType() const { return fTransformType; } | 109 TransformType transformType() const { return fTransformType; } |
111 | 110 |
112 const float* transforms() const { return fTransforms.begin(); } | 111 const float* transforms() const { return fTransforms.begin(); } |
113 | 112 |
114 const uint16_t* indices() const { return fIndices.begin(); } | 113 const uint16_t* indices() const { return fIndices.begin(); } |
115 | 114 |
116 const GrPathRange* range() const { return fPathRange.get(); } | |
117 | |
118 void loadGlyphPathsIfNeeded() { | |
119 fPathRange.get()->loadPathsIfNeeded<uint16_t>(fIndices.begin(), fIndices
.count()); | |
120 } | |
121 | |
122 static bool CanMerge(const GrPathRangeDraw& a, const GrPathRangeDraw& b) { | 115 static bool CanMerge(const GrPathRangeDraw& a, const GrPathRangeDraw& b) { |
123 return a.transformType() == b.transformType() && a.range() == b.range(); | 116 return a.transformType() == b.transformType(); |
124 } | 117 } |
125 | 118 |
126 private: | 119 private: |
127 GrPathRangeDraw(GrPathRange* range, TransformType transformType, int reserve
Cnt) | 120 GrPathRangeDraw(TransformType transformType, int reserveCnt) |
128 : fPathRange(range) | 121 : fTransformType(transformType) |
129 , fTransformType(transformType) | |
130 , fIndices(reserveCnt) | 122 , fIndices(reserveCnt) |
131 , fTransforms(reserveCnt * GrPathRendering::PathTransformSize(transformT
ype)) { | 123 , fTransforms(reserveCnt * GrPathRendering::PathTransformSize(transformT
ype)) { |
132 SkDEBUGCODE(fUsedInBatch = false;) | 124 SkDEBUGCODE(fUsedInBatch = false;) |
133 } | 125 } |
134 | 126 |
135 // Reserve space for 64 paths where indices are 16 bit and transforms are tr
anslations. | 127 // Reserve space for 64 paths where indices are 16 bit and transforms are tr
anslations. |
136 static const int kIndexReserveCnt = 64; | 128 static const int kIndexReserveCnt = 64; |
137 static const int kTransformBufferReserveCnt = 2 * 64; | 129 static const int kTransformBufferReserveCnt = 2 * 64; |
138 | 130 |
139 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; | |
140 GrPathRendering::PathTransformType fTransformType; | 131 GrPathRendering::PathTransformType fTransformType; |
141 SkSTArray<kIndexReserveCnt, uint16_t, true> fIndices; | 132 SkSTArray<kIndexReserveCnt, uint16_t, true> fIndices; |
142 SkSTArray<kTransformBufferReserveCnt, float, true> fTransforms; | 133 SkSTArray<kTransformBufferReserveCnt, float, true> fTransforms; |
143 | 134 |
144 // To ensure we don't reuse these across batches. | 135 // To ensure we don't reuse these across batches. |
145 #ifdef SK_DEBUG | 136 #ifdef SK_DEBUG |
146 bool fUsedInBatch; | 137 bool fUsedInBatch; |
147 friend class GrDrawPathRangeBatch; | 138 friend class GrDrawPathRangeBatch; |
148 #endif | 139 #endif |
149 | 140 |
150 typedef GrNonAtomicRef INHERITED; | 141 typedef GrNonAtomicRef INHERITED; |
151 }; | 142 }; |
152 | 143 |
153 // Template this if we decide to support index types other than 16bit | 144 // Template this if we decide to support index types other than 16bit |
154 class GrDrawPathRangeBatch final : public GrDrawPathBatchBase { | 145 class GrDrawPathRangeBatch final : public GrDrawPathBatchBase { |
155 public: | 146 public: |
156 DEFINE_BATCH_CLASS_ID | 147 DEFINE_BATCH_CLASS_ID |
157 | 148 |
158 // This can't return a more abstract type because we install the stencil set
tings late :( | 149 // This can't return a more abstract type because we install the stencil set
tings late :( |
159 static GrDrawPathBatchBase* Create(const SkMatrix& viewMatrix, const SkMatri
x& localMatrix, | 150 static GrDrawPathBatchBase* Create(const SkMatrix& viewMatrix, const SkMatri
x& localMatrix, |
160 GrColor color, GrPathRangeDraw* pathRange
Draw) { | 151 GrColor color, GrPathRange* range, GrPath
RangeDraw* draw) { |
161 return new GrDrawPathRangeBatch(viewMatrix, localMatrix, color, pathRang
eDraw); | 152 return new GrDrawPathRangeBatch(viewMatrix, localMatrix, color, range, d
raw); |
162 } | 153 } |
163 | 154 |
164 ~GrDrawPathRangeBatch() override; | 155 ~GrDrawPathRangeBatch() override; |
165 | 156 |
166 const char* name() const override { return "DrawPathRange"; } | 157 const char* name() const override { return "DrawPathRange"; } |
167 | 158 |
168 SkString dumpInfo() const override; | 159 SkString dumpInfo() const override; |
169 | 160 |
170 private: | 161 private: |
171 inline bool isWinding() const; | 162 inline bool isWinding() const; |
172 | 163 |
173 GrDrawPathRangeBatch(const SkMatrix& viewMatrix, const SkMatrix& localMatrix
, GrColor color, | 164 GrDrawPathRangeBatch(const SkMatrix& viewMatrix, const SkMatrix& localMatrix
, GrColor color, |
174 GrPathRangeDraw* pathRangeDraw); | 165 GrPathRange* range, GrPathRangeDraw* draw); |
175 | 166 |
176 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override; | 167 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override; |
177 | 168 |
178 void onPrepare(GrBatchFlushState*) override {} | 169 void onPrepare(GrBatchFlushState*) override {} |
179 | 170 |
180 void onDraw(GrBatchFlushState* state) override; | 171 void onDraw(GrBatchFlushState* state) override; |
181 | 172 |
| 173 typedef GrPendingIOResource<const GrPathRange, kRead_GrIOType> PendingPathRa
nge; |
182 typedef SkTLList<GrPathRangeDraw*> DrawList; | 174 typedef SkTLList<GrPathRangeDraw*> DrawList; |
183 DrawList fDraws; | 175 PendingPathRange fPathRange; |
184 int fTotalPathCount; | 176 DrawList fDraws; |
185 SkMatrix fLocalMatrix; | 177 int fTotalPathCount; |
| 178 SkMatrix fLocalMatrix; |
186 | 179 |
187 typedef GrDrawPathBatchBase INHERITED; | 180 typedef GrDrawPathBatchBase INHERITED; |
188 }; | 181 }; |
189 | 182 |
190 #endif | 183 #endif |
OLD | NEW |