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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.get()); | 82 helper.recordDraw(target, gp.get()); |
83 } | 83 } |
84 | 84 |
85 GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie
wMatrix, | 85 GrDrawAtlasBatch::GrDrawAtlasBatch(GrColor color, const SkMatrix& viewMatrix, in
t spriteCount, |
86 int spriteCount, const SkRSXform* xforms, con
st SkRect* rects, | 86 const SkRSXform* xforms, const 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; |
93 Geometry& installedGeo = fGeoData.push_back(geometry); | 93 Geometry& installedGeo = fGeoData.push_back(); |
| 94 installedGeo.fColor = color; |
94 | 95 |
95 // Figure out stride and offsets | 96 // Figure out stride and offsets |
96 // Order within the vertex is: position [color] texCoord | 97 // Order within the vertex is: position [color] texCoord |
97 size_t texOffset = sizeof(SkPoint); | 98 size_t texOffset = sizeof(SkPoint); |
98 size_t vertexStride = 2*sizeof(SkPoint); | 99 size_t vertexStride = 2*sizeof(SkPoint); |
99 fHasColors = SkToBool(colors); | 100 fHasColors = SkToBool(colors); |
100 if (colors) { | 101 if (colors) { |
101 texOffset += sizeof(GrColor); | 102 texOffset += sizeof(GrColor); |
102 vertexStride += sizeof(GrColor); | 103 vertexStride += sizeof(GrColor); |
103 } | 104 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 return false; | 182 return false; |
182 } | 183 } |
183 | 184 |
184 if (!this->hasColors() && this->color() != that->color()) { | 185 if (!this->hasColors() && this->color() != that->color()) { |
185 return false; | 186 return false; |
186 } | 187 } |
187 | 188 |
188 if (this->color() != that->color()) { | 189 if (this->color() != that->color()) { |
189 fColor = GrColor_ILLEGAL; | 190 fColor = GrColor_ILLEGAL; |
190 } | 191 } |
191 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); | 192 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); |
192 fQuadCount += that->quadCount(); | 193 fQuadCount += that->quadCount(); |
193 | 194 |
194 this->joinBounds(that->bounds()); | 195 this->joinBounds(that->bounds()); |
195 return true; | 196 return true; |
196 } | 197 } |
197 | 198 |
198 #ifdef GR_TEST_UTILS | 199 #ifdef GR_TEST_UTILS |
199 | 200 |
200 static SkRSXform random_xform(SkRandom* random) { | 201 static SkRSXform random_xform(SkRandom* random) { |
201 static const SkScalar kMinExtent = -100.f; | 202 static const SkScalar kMinExtent = -100.f; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 bool hasColors = random->nextBool(); | 250 bool hasColors = random->nextBool(); |
250 | 251 |
251 randomize_params(spriteCount, | 252 randomize_params(spriteCount, |
252 random, | 253 random, |
253 &xforms, | 254 &xforms, |
254 &texRects, | 255 &texRects, |
255 &colors, hasColors); | 256 &colors, hasColors); |
256 | 257 |
257 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 258 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
258 | 259 |
259 GrDrawAtlasBatch::Geometry geometry; | 260 GrColor color = GrRandomColor(random); |
260 geometry.fColor = GrRandomColor(random); | 261 return new GrDrawAtlasBatch(color, viewMatrix, spriteCount, xforms.begin(),
texRects.begin(), |
261 return GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xforms.be
gin(), | 262 hasColors ? colors.begin() : nullptr); |
262 texRects.begin(), hasColors ? colors.begin()
: nullptr); | |
263 } | 263 } |
264 | 264 |
265 #endif | 265 #endif |
OLD | NEW |