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 "GrDrawAtlasBatch.h" | 8 #include "GrDrawAtlasBatch.h" |
9 #include "GrBatchFlushState.h" | 9 #include "GrBatchFlushState.h" |
10 #include "GrBatchTest.h" | 10 #include "GrBatchTest.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 return GrDefaultGeoProcFactory::Create(gpColor, coverage, localCoords, viewM
atrix); | 51 return GrDefaultGeoProcFactory::Create(gpColor, coverage, localCoords, viewM
atrix); |
52 } | 52 } |
53 | 53 |
54 void GrDrawAtlasBatch::onPrepareDraws(Target* target) const { | 54 void GrDrawAtlasBatch::onPrepareDraws(Target* target) const { |
55 // Setup geometry processor | 55 // Setup geometry processor |
56 SkAutoTUnref<const GrGeometryProcessor> gp(set_vertex_attributes(this->hasCo
lors(), | 56 SkAutoTUnref<const GrGeometryProcessor> gp(set_vertex_attributes(this->hasCo
lors(), |
57 this->color
(), | 57 this->color
(), |
58 this->viewM
atrix(), | 58 this->viewM
atrix(), |
59 this->cover
ageIgnored())); | 59 this->cover
ageIgnored())); |
60 | 60 |
61 target->initDraw(gp); | |
62 | |
63 int instanceCount = fGeoData.count(); | 61 int instanceCount = fGeoData.count(); |
64 size_t vertexStride = gp->getVertexStride(); | 62 size_t vertexStride = gp->getVertexStride(); |
65 SkASSERT(vertexStride == sizeof(SkPoint) + sizeof(SkPoint) | 63 SkASSERT(vertexStride == sizeof(SkPoint) + sizeof(SkPoint) |
66 + (this->hasColors() ? sizeof(GrColor) : 0)); | 64 + (this->hasColors() ? sizeof(GrColor) : 0)); |
67 | 65 |
68 QuadHelper helper; | 66 QuadHelper helper; |
69 int numQuads = this->quadCount(); | 67 int numQuads = this->quadCount(); |
70 void* verts = helper.init(target, vertexStride, numQuads); | 68 void* verts = helper.init(target, vertexStride, numQuads); |
71 if (!verts) { | 69 if (!verts) { |
72 SkDebugf("Could not allocate vertices\n"); | 70 SkDebugf("Could not allocate vertices\n"); |
73 return; | 71 return; |
74 } | 72 } |
75 | 73 |
76 uint8_t* vertPtr = reinterpret_cast<uint8_t*>(verts); | 74 uint8_t* vertPtr = reinterpret_cast<uint8_t*>(verts); |
77 for (int i = 0; i < instanceCount; i++) { | 75 for (int i = 0; i < instanceCount; i++) { |
78 const Geometry& args = fGeoData[i]; | 76 const Geometry& args = fGeoData[i]; |
79 | 77 |
80 size_t allocSize = args.fVerts.count(); | 78 size_t allocSize = args.fVerts.count(); |
81 memcpy(vertPtr, args.fVerts.begin(), allocSize); | 79 memcpy(vertPtr, args.fVerts.begin(), allocSize); |
82 vertPtr += allocSize; | 80 vertPtr += allocSize; |
83 } | 81 } |
84 helper.recordDraw(target); | 82 helper.recordDraw(target, gp); |
85 } | 83 } |
86 | 84 |
87 GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie
wMatrix, | 85 GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie
wMatrix, |
88 int spriteCount, const SkRSXform* xforms, con
st SkRect* rects, | 86 int spriteCount, const SkRSXform* xforms, con
st SkRect* rects, |
89 const SkColor* colors) | 87 const SkColor* colors) |
90 : INHERITED(ClassID()) { | 88 : INHERITED(ClassID()) { |
91 SkASSERT(xforms); | 89 SkASSERT(xforms); |
92 SkASSERT(rects); | 90 SkASSERT(rects); |
93 | 91 |
94 fViewMatrix = viewMatrix; | 92 fViewMatrix = viewMatrix; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 256 |
259 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 257 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
260 | 258 |
261 GrDrawAtlasBatch::Geometry geometry; | 259 GrDrawAtlasBatch::Geometry geometry; |
262 geometry.fColor = GrRandomColor(random); | 260 geometry.fColor = GrRandomColor(random); |
263 return GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xforms.be
gin(), | 261 return GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xforms.be
gin(), |
264 texRects.begin(), hasColors ? colors.begin()
: nullptr); | 262 texRects.begin(), hasColors ? colors.begin()
: nullptr); |
265 } | 263 } |
266 | 264 |
267 #endif | 265 #endif |
OLD | NEW |