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 18 matching lines...) Expand all Loading... |
29 } | 29 } |
30 | 30 |
31 // setup batch properties | 31 // setup batch properties |
32 fColorIgnored = !overrides.readsColor(); | 32 fColorIgnored = !overrides.readsColor(); |
33 fColor = fGeoData[0].fColor; | 33 fColor = fGeoData[0].fColor; |
34 // We'd like to assert this, but we can't because of GLPrograms test | 34 // We'd like to assert this, but we can't because of GLPrograms test |
35 //SkASSERT(init.readsLocalCoords()); | 35 //SkASSERT(init.readsLocalCoords()); |
36 fCoverageIgnored = !overrides.readsCoverage(); | 36 fCoverageIgnored = !overrides.readsCoverage(); |
37 } | 37 } |
38 | 38 |
39 static const GrGeometryProcessor* set_vertex_attributes(bool hasColors, | 39 static sk_sp<GrGeometryProcessor> set_vertex_attributes(bool hasColors, |
40 GrColor color, | 40 GrColor color, |
41 const SkMatrix& viewMatr
ix, | 41 const SkMatrix& viewMatr
ix, |
42 bool coverageIgnored) { | 42 bool coverageIgnored) { |
43 using namespace GrDefaultGeoProcFactory; | 43 using namespace GrDefaultGeoProcFactory; |
44 Color gpColor(color); | 44 Color gpColor(color); |
45 if (hasColors) { | 45 if (hasColors) { |
46 gpColor.fType = Color::kAttribute_Type; | 46 gpColor.fType = Color::kAttribute_Type; |
47 } | 47 } |
48 | 48 |
49 Coverage coverage(coverageIgnored ? Coverage::kNone_Type : Coverage::kSolid_
Type); | 49 Coverage coverage(coverageIgnored ? Coverage::kNone_Type : Coverage::kSolid_
Type); |
50 LocalCoords localCoords(LocalCoords::kHasExplicit_Type); | 50 LocalCoords localCoords(LocalCoords::kHasExplicit_Type); |
51 return GrDefaultGeoProcFactory::Create(gpColor, coverage, localCoords, viewM
atrix); | 51 return GrDefaultGeoProcFactory::Make(gpColor, coverage, localCoords, viewMat
rix); |
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 sk_sp<GrGeometryProcessor> gp(set_vertex_attributes(this->hasColors(), |
57 this->color
(), | 57 this->color(), |
58 this->viewM
atrix(), | 58 this->viewMatrix(), |
59 this->cover
ageIgnored())); | 59 this->coverageIgnored())
); |
60 | 60 |
61 int instanceCount = fGeoData.count(); | 61 int instanceCount = fGeoData.count(); |
62 size_t vertexStride = gp->getVertexStride(); | 62 size_t vertexStride = gp->getVertexStride(); |
63 SkASSERT(vertexStride == sizeof(SkPoint) + sizeof(SkPoint) | 63 SkASSERT(vertexStride == sizeof(SkPoint) + sizeof(SkPoint) |
64 + (this->hasColors() ? sizeof(GrColor) : 0)); | 64 + (this->hasColors() ? sizeof(GrColor) : 0)); |
65 | 65 |
66 QuadHelper helper; | 66 QuadHelper helper; |
67 int numQuads = this->quadCount(); | 67 int numQuads = this->quadCount(); |
68 void* verts = helper.init(target, vertexStride, numQuads); | 68 void* verts = helper.init(target, vertexStride, numQuads); |
69 if (!verts) { | 69 if (!verts) { |
70 SkDebugf("Could not allocate vertices\n"); | 70 SkDebugf("Could not allocate vertices\n"); |
71 return; | 71 return; |
72 } | 72 } |
73 | 73 |
74 uint8_t* vertPtr = reinterpret_cast<uint8_t*>(verts); | 74 uint8_t* vertPtr = reinterpret_cast<uint8_t*>(verts); |
75 for (int i = 0; i < instanceCount; i++) { | 75 for (int i = 0; i < instanceCount; i++) { |
76 const Geometry& args = fGeoData[i]; | 76 const Geometry& args = fGeoData[i]; |
77 | 77 |
78 size_t allocSize = args.fVerts.count(); | 78 size_t allocSize = args.fVerts.count(); |
79 memcpy(vertPtr, args.fVerts.begin(), allocSize); | 79 memcpy(vertPtr, args.fVerts.begin(), allocSize); |
80 vertPtr += allocSize; | 80 vertPtr += allocSize; |
81 } | 81 } |
82 helper.recordDraw(target, gp); | 82 helper.recordDraw(target, gp.get()); |
83 } | 83 } |
84 | 84 |
85 GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie
wMatrix, | 85 GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie
wMatrix, |
86 int spriteCount, const SkRSXform* xforms, con
st SkRect* rects, | 86 int spriteCount, const SkRSXform* xforms, con
st SkRect* rects, |
87 const SkColor* colors) | 87 const SkColor* colors) |
88 : INHERITED(ClassID()) { | 88 : INHERITED(ClassID()) { |
89 SkASSERT(xforms); | 89 SkASSERT(xforms); |
90 SkASSERT(rects); | 90 SkASSERT(rects); |
91 | 91 |
92 fViewMatrix = viewMatrix; | 92 fViewMatrix = viewMatrix; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 256 |
257 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 257 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
258 | 258 |
259 GrDrawAtlasBatch::Geometry geometry; | 259 GrDrawAtlasBatch::Geometry geometry; |
260 geometry.fColor = GrRandomColor(random); | 260 geometry.fColor = GrRandomColor(random); |
261 return GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xforms.be
gin(), | 261 return GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xforms.be
gin(), |
262 texRects.begin(), hasColors ? colors.begin()
: nullptr); | 262 texRects.begin(), hasColors ? colors.begin()
: nullptr); |
263 } | 263 } |
264 | 264 |
265 #endif | 265 #endif |
OLD | NEW |