| 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 "GrBatchTest.h" | 10 #include "GrBatchTest.h" |
| 10 #include "SkGr.h" | 11 #include "SkGr.h" |
| 11 #include "SkRandom.h" | 12 #include "SkRandom.h" |
| 12 #include "SkRSXform.h" | 13 #include "SkRSXform.h" |
| 13 | 14 |
| 14 void GrDrawAtlasBatch::initBatchTracker(const GrPipelineOptimizations& opt) { | 15 void GrDrawAtlasBatch::initBatchTracker(const GrPipelineOptimizations& opt) { |
| 15 // Handle any color overrides | 16 // Handle any color overrides |
| 16 if (!opt.readsColor()) { | 17 if (!opt.readsColor()) { |
| 17 fGeoData[0].fColor = GrColor_ILLEGAL; | 18 fGeoData[0].fColor = GrColor_ILLEGAL; |
| 18 } | 19 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 34 Color gpColor(color); | 35 Color gpColor(color); |
| 35 if (hasColors) { | 36 if (hasColors) { |
| 36 gpColor.fType = Color::kAttribute_Type; | 37 gpColor.fType = Color::kAttribute_Type; |
| 37 } | 38 } |
| 38 | 39 |
| 39 Coverage coverage(coverageIgnored ? Coverage::kNone_Type : Coverage::kSolid_
Type); | 40 Coverage coverage(coverageIgnored ? Coverage::kNone_Type : Coverage::kSolid_
Type); |
| 40 LocalCoords localCoords(LocalCoords::kHasExplicit_Type); | 41 LocalCoords localCoords(LocalCoords::kHasExplicit_Type); |
| 41 return GrDefaultGeoProcFactory::Create(gpColor, coverage, localCoords, viewM
atrix); | 42 return GrDefaultGeoProcFactory::Create(gpColor, coverage, localCoords, viewM
atrix); |
| 42 } | 43 } |
| 43 | 44 |
| 44 void GrDrawAtlasBatch::generateGeometry(GrBatchTarget* batchTarget) { | 45 void GrDrawAtlasBatch::onPrepareDraws(Target* target) { |
| 45 // Setup geometry processor | 46 // Setup geometry processor |
| 46 SkAutoTUnref<const GrGeometryProcessor> gp(set_vertex_attributes(this->hasCo
lors(), | 47 SkAutoTUnref<const GrGeometryProcessor> gp(set_vertex_attributes(this->hasCo
lors(), |
| 47 this->color
(), | 48 this->color
(), |
| 48 this->viewM
atrix(), | 49 this->viewM
atrix(), |
| 49 this->cover
ageIgnored())); | 50 this->cover
ageIgnored())); |
| 50 | 51 |
| 51 batchTarget->initDraw(gp, this->pipeline()); | 52 target->initDraw(gp, this->pipeline()); |
| 52 | 53 |
| 53 int instanceCount = fGeoData.count(); | 54 int instanceCount = fGeoData.count(); |
| 54 size_t vertexStride = gp->getVertexStride(); | 55 size_t vertexStride = gp->getVertexStride(); |
| 55 SkASSERT(vertexStride == sizeof(SkPoint) + sizeof(SkPoint) | 56 SkASSERT(vertexStride == sizeof(SkPoint) + sizeof(SkPoint) |
| 56 + (this->hasColors() ? sizeof(GrColor) : 0)); | 57 + (this->hasColors() ? sizeof(GrColor) : 0)); |
| 57 | 58 |
| 58 QuadHelper helper; | 59 QuadHelper helper; |
| 59 int numQuads = this->quadCount(); | 60 int numQuads = this->quadCount(); |
| 60 void* verts = helper.init(batchTarget, vertexStride, numQuads); | 61 void* verts = helper.init(target, vertexStride, numQuads); |
| 61 if (!verts) { | 62 if (!verts) { |
| 62 SkDebugf("Could not allocate vertices\n"); | 63 SkDebugf("Could not allocate vertices\n"); |
| 63 return; | 64 return; |
| 64 } | 65 } |
| 65 | 66 |
| 66 uint8_t* vertPtr = reinterpret_cast<uint8_t*>(verts); | 67 uint8_t* vertPtr = reinterpret_cast<uint8_t*>(verts); |
| 67 for (int i = 0; i < instanceCount; i++) { | 68 for (int i = 0; i < instanceCount; i++) { |
| 68 const Geometry& args = fGeoData[i]; | 69 const Geometry& args = fGeoData[i]; |
| 69 | 70 |
| 70 size_t allocSize = args.fVerts.count(); | 71 size_t allocSize = args.fVerts.count(); |
| 71 memcpy(vertPtr, args.fVerts.begin(), allocSize); | 72 memcpy(vertPtr, args.fVerts.begin(), allocSize); |
| 72 vertPtr += allocSize; | 73 vertPtr += allocSize; |
| 73 } | 74 } |
| 74 helper.issueDraw(batchTarget); | 75 helper.recordDraw(target); |
| 75 } | 76 } |
| 76 | 77 |
| 77 GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie
wMatrix, | 78 GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie
wMatrix, |
| 78 int spriteCount, const SkRSXform* xforms, con
st SkRect* rects, | 79 int spriteCount, const SkRSXform* xforms, con
st SkRect* rects, |
| 79 const SkColor* colors) { | 80 const SkColor* colors) { |
| 80 this->initClassID<GrDrawAtlasBatch>(); | 81 this->initClassID<GrDrawAtlasBatch>(); |
| 81 SkASSERT(xforms); | 82 SkASSERT(xforms); |
| 82 SkASSERT(rects); | 83 SkASSERT(rects); |
| 83 | 84 |
| 84 fViewMatrix = viewMatrix; | 85 fViewMatrix = viewMatrix; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 249 |
| 249 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 250 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 250 | 251 |
| 251 GrDrawAtlasBatch::Geometry geometry; | 252 GrDrawAtlasBatch::Geometry geometry; |
| 252 geometry.fColor = GrRandomColor(random); | 253 geometry.fColor = GrRandomColor(random); |
| 253 return GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xforms.be
gin(), | 254 return GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xforms.be
gin(), |
| 254 texRects.begin(), hasColors ? colors.begin()
: nullptr); | 255 texRects.begin(), hasColors ? colors.begin()
: nullptr); |
| 255 } | 256 } |
| 256 | 257 |
| 257 #endif | 258 #endif |
| OLD | NEW |