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 #include "GrAAStrokeRectBatch.h" | 8 #include "GrAAStrokeRectBatch.h" |
9 | 9 |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 116 } |
117 | 117 |
118 static const int kMiterIndexCnt = 3 * 24; | 118 static const int kMiterIndexCnt = 3 * 24; |
119 static const int kMiterVertexCnt = 16; | 119 static const int kMiterVertexCnt = 16; |
120 static const int kNumMiterRectsInIndexBuffer = 256; | 120 static const int kNumMiterRectsInIndexBuffer = 256; |
121 | 121 |
122 static const int kBevelIndexCnt = 48 + 36 + 24; | 122 static const int kBevelIndexCnt = 48 + 36 + 24; |
123 static const int kBevelVertexCnt = 24; | 123 static const int kBevelVertexCnt = 24; |
124 static const int kNumBevelRectsInIndexBuffer = 256; | 124 static const int kNumBevelRectsInIndexBuffer = 256; |
125 | 125 |
126 static const GrIndexBuffer* GetIndexBuffer(GrResourceProvider* resourceProvi
der, | 126 static const GrBuffer* GetIndexBuffer(GrResourceProvider* resourceProvider,
bool miterStroke); |
127 bool miterStroke); | |
128 | 127 |
129 GrColor color() const { return fBatch.fColor; } | 128 GrColor color() const { return fBatch.fColor; } |
130 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 129 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
131 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } | 130 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } |
132 bool colorIgnored() const { return fBatch.fColorIgnored; } | 131 bool colorIgnored() const { return fBatch.fColorIgnored; } |
133 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } | 132 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } |
134 const Geometry& geometry() const { return fGeoData[0]; } | 133 const Geometry& geometry() const { return fGeoData[0]; } |
135 const SkMatrix& viewMatrix() const { return fViewMatrix; } | 134 const SkMatrix& viewMatrix() const { return fViewMatrix; } |
136 bool miterStroke() const { return fMiterStroke; } | 135 bool miterStroke() const { return fMiterStroke; } |
137 | 136 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 198 |
200 SkASSERT(canTweakAlphaForCoverage ? | 199 SkASSERT(canTweakAlphaForCoverage ? |
201 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr)
: | 200 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr)
: |
202 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCovera
geAttr)); | 201 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCovera
geAttr)); |
203 int innerVertexNum = 4; | 202 int innerVertexNum = 4; |
204 int outerVertexNum = this->miterStroke() ? 4 : 8; | 203 int outerVertexNum = this->miterStroke() ? 4 : 8; |
205 int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2; | 204 int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2; |
206 int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIndexC
nt; | 205 int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIndexC
nt; |
207 int instanceCount = fGeoData.count(); | 206 int instanceCount = fGeoData.count(); |
208 | 207 |
209 const SkAutoTUnref<const GrIndexBuffer> indexBuffer( | 208 const SkAutoTUnref<const GrBuffer> indexBuffer( |
210 GetIndexBuffer(target->resourceProvider(), this->miterStroke())); | 209 GetIndexBuffer(target->resourceProvider(), this->miterStroke())); |
211 InstancedHelper helper; | 210 InstancedHelper helper; |
212 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStrid
e, | 211 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStrid
e, |
213 indexBuffer, verticesPerInstance, indicesPerIns
tance, | 212 indexBuffer, verticesPerInstance, indicesPerIns
tance, |
214 instanceCount); | 213 instanceCount); |
215 if (!vertices || !indexBuffer) { | 214 if (!vertices || !indexBuffer) { |
216 SkDebugf("Could not allocate vertices\n"); | 215 SkDebugf("Could not allocate vertices\n"); |
217 return; | 216 return; |
218 } | 217 } |
219 | 218 |
220 for (int i = 0; i < instanceCount; i++) { | 219 for (int i = 0; i < instanceCount; i++) { |
221 const Geometry& args = fGeoData[i]; | 220 const Geometry& args = fGeoData[i]; |
222 this->generateAAStrokeRectGeometry(vertices, | 221 this->generateAAStrokeRectGeometry(vertices, |
223 i * verticesPerInstance * vertexStrid
e, | 222 i * verticesPerInstance * vertexStrid
e, |
224 vertexStride, | 223 vertexStride, |
225 outerVertexNum, | 224 outerVertexNum, |
226 innerVertexNum, | 225 innerVertexNum, |
227 args.fColor, | 226 args.fColor, |
228 args.fDevOutside, | 227 args.fDevOutside, |
229 args.fDevOutsideAssist, | 228 args.fDevOutsideAssist, |
230 args.fDevInside, | 229 args.fDevInside, |
231 fMiterStroke, | 230 fMiterStroke, |
232 args.fDegenerate, | 231 args.fDegenerate, |
233 canTweakAlphaForCoverage); | 232 canTweakAlphaForCoverage); |
234 } | 233 } |
235 helper.recordDraw(target); | 234 helper.recordDraw(target); |
236 } | 235 } |
237 | 236 |
238 const GrIndexBuffer* AAStrokeRectBatch::GetIndexBuffer(GrResourceProvider* resou
rceProvider, | 237 const GrBuffer* AAStrokeRectBatch::GetIndexBuffer(GrResourceProvider* resourcePr
ovider, |
239 bool miterStroke) { | 238 bool miterStroke) { |
240 | 239 |
241 if (miterStroke) { | 240 if (miterStroke) { |
242 static const uint16_t gMiterIndices[] = { | 241 static const uint16_t gMiterIndices[] = { |
243 0 + 0, 1 + 0, 5 + 0, 5 + 0, 4 + 0, 0 + 0, | 242 0 + 0, 1 + 0, 5 + 0, 5 + 0, 4 + 0, 0 + 0, |
244 1 + 0, 2 + 0, 6 + 0, 6 + 0, 5 + 0, 1 + 0, | 243 1 + 0, 2 + 0, 6 + 0, 6 + 0, 5 + 0, 1 + 0, |
245 2 + 0, 3 + 0, 7 + 0, 7 + 0, 6 + 0, 2 + 0, | 244 2 + 0, 3 + 0, 7 + 0, 7 + 0, 6 + 0, 2 + 0, |
246 3 + 0, 0 + 0, 4 + 0, 4 + 0, 7 + 0, 3 + 0, | 245 3 + 0, 0 + 0, 4 + 0, 4 + 0, 7 + 0, 3 + 0, |
247 | 246 |
248 0 + 4, 1 + 4, 5 + 4, 5 + 4, 4 + 4, 0 + 4, | 247 0 + 4, 1 + 4, 5 + 4, 5 + 4, 4 + 4, 0 + 4, |
249 1 + 4, 2 + 4, 6 + 4, 6 + 4, 5 + 4, 1 + 4, | 248 1 + 4, 2 + 4, 6 + 4, 6 + 4, 5 + 4, 1 + 4, |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 SkRect inside = outside; | 654 SkRect inside = outside; |
656 inside.inset(strokeWidth, strokeWidth); | 655 inside.inset(strokeWidth, strokeWidth); |
657 | 656 |
658 GrColor color = GrRandomColor(random); | 657 GrColor color = GrRandomColor(random); |
659 | 658 |
660 return GrAAStrokeRectBatch::Create(color, GrTest::TestMatrix(random), outsid
e, outsideAssist, | 659 return GrAAStrokeRectBatch::Create(color, GrTest::TestMatrix(random), outsid
e, outsideAssist, |
661 inside, miterStroke, inside.isFinite() &&
inside.isEmpty()); | 660 inside, miterStroke, inside.isFinite() &&
inside.isEmpty()); |
662 } | 661 } |
663 | 662 |
664 #endif | 663 #endif |
OLD | NEW |