OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrBitmapTextContext.h" | 8 #include "GrBitmapTextContext.h" |
9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
10 #include "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe
rtexAttribBinding} | 47 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe
rtexAttribBinding} |
48 }; | 48 }; |
49 | 49 |
50 }; | 50 }; |
51 | 51 |
52 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, | 52 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, |
53 const SkDeviceProperties& properties) | 53 const SkDeviceProperties& properties) |
54 : GrTextContext(context, properties) { | 54 : GrTextContext(context, properties) { |
55 fStrike = NULL; | 55 fStrike = NULL; |
56 | 56 |
| 57 fCurrTexture = NULL; |
57 fCurrVertex = 0; | 58 fCurrVertex = 0; |
58 fEffectTextureUniqueID = SK_InvalidUniqueID; | 59 fEffectTextureUniqueID = SK_InvalidUniqueID; |
59 | 60 |
60 fVertices = NULL; | 61 fVertices = NULL; |
| 62 fMaxVertices = 0; |
61 | 63 |
62 fVertexBounds.setLargestInverted(); | 64 fVertexBounds.setLargestInverted(); |
63 } | 65 } |
64 | 66 |
65 GrBitmapTextContext::~GrBitmapTextContext() { | 67 GrBitmapTextContext::~GrBitmapTextContext() { |
66 this->flushGlyphs(); | 68 this->flushGlyphs(); |
67 } | 69 } |
68 | 70 |
69 bool GrBitmapTextContext::canDraw(const SkPaint& paint) { | 71 bool GrBitmapTextContext::canDraw(const SkPaint& paint) { |
70 return !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix()); | 72 return !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix()); |
(...skipping 11 matching lines...) Expand all Loading... |
82 return; | 84 return; |
83 } | 85 } |
84 | 86 |
85 GrDrawState* drawState = fDrawTarget->drawState(); | 87 GrDrawState* drawState = fDrawTarget->drawState(); |
86 GrDrawState::AutoRestoreEffects are(drawState); | 88 GrDrawState::AutoRestoreEffects are(drawState); |
87 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); | 89 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); |
88 | 90 |
89 if (fCurrVertex > 0) { | 91 if (fCurrVertex > 0) { |
90 // setup our sampler state for our text texture/atlas | 92 // setup our sampler state for our text texture/atlas |
91 SkASSERT(SkIsAlign4(fCurrVertex)); | 93 SkASSERT(SkIsAlign4(fCurrVertex)); |
| 94 SkASSERT(fCurrTexture); |
92 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); | 95 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon
e_FilterMode); |
93 | 96 |
94 GrTexture* currTexture = fStrike->getTexture(); | 97 uint32_t textureUniqueID = fCurrTexture->getUniqueID(); |
95 SkASSERT(currTexture); | |
96 uint32_t textureUniqueID = currTexture->getUniqueID(); | |
97 | 98 |
98 if (textureUniqueID != fEffectTextureUniqueID) { | 99 if (textureUniqueID != fEffectTextureUniqueID) { |
99 fCachedEffect.reset(GrCustomCoordsTextureEffect::Create(currTexture,
params)); | 100 fCachedEffect.reset(GrCustomCoordsTextureEffect::Create(fCurrTexture
, params)); |
100 fEffectTextureUniqueID = textureUniqueID; | 101 fEffectTextureUniqueID = textureUniqueID; |
101 } | 102 } |
102 | 103 |
103 // This effect could be stored with one of the cache objects (atlas?) | 104 // This effect could be stored with one of the cache objects (atlas?) |
104 int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithC
olorAttributeIndex : | 105 int coordsIdx = drawState->hasColorVertexAttribute() ? kGlyphCoordsWithC
olorAttributeIndex : |
105 kGlyphCoordsNoCol
orAttributeIndex; | 106 kGlyphCoordsNoCol
orAttributeIndex; |
106 drawState->addCoverageEffect(fCachedEffect.get(), coordsIdx); | 107 drawState->addCoverageEffect(fCachedEffect.get(), coordsIdx); |
107 SkASSERT(NULL != fStrike); | 108 SkASSERT(NULL != fStrike); |
108 switch (fStrike->getMaskFormat()) { | 109 switch (fStrike->getMaskFormat()) { |
109 // Color bitmap text | 110 // Color bitmap text |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 break; | 145 break; |
145 default: | 146 default: |
146 SkFAIL("Unexepected mask format."); | 147 SkFAIL("Unexepected mask format."); |
147 } | 148 } |
148 int nGlyphs = fCurrVertex / 4; | 149 int nGlyphs = fCurrVertex / 4; |
149 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 150 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
150 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, | 151 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, |
151 nGlyphs, | 152 nGlyphs, |
152 4, 6, &fVertexBounds); | 153 4, 6, &fVertexBounds); |
153 | 154 |
| 155 fDrawTarget->resetVertexSource(); |
| 156 fVertices = NULL; |
| 157 fMaxVertices = 0; |
154 fCurrVertex = 0; | 158 fCurrVertex = 0; |
155 fVertexBounds.setLargestInverted(); | 159 fVertexBounds.setLargestInverted(); |
| 160 SkSafeSetNull(fCurrTexture); |
156 } | 161 } |
157 | |
158 fDrawTarget->resetVertexSource(); | |
159 fVertices = NULL; | |
160 } | 162 } |
161 | 163 |
162 inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPai
nt) { | 164 inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPai
nt) { |
163 GrTextContext::init(paint, skPaint); | 165 GrTextContext::init(paint, skPaint); |
164 | 166 |
165 fStrike = NULL; | 167 fStrike = NULL; |
166 | 168 |
| 169 fCurrTexture = NULL; |
167 fCurrVertex = 0; | 170 fCurrVertex = 0; |
168 | 171 |
169 fVertices = NULL; | 172 fVertices = NULL; |
| 173 fMaxVertices = 0; |
170 } | 174 } |
171 | 175 |
172 inline void GrBitmapTextContext::finish() { | 176 inline void GrBitmapTextContext::finish() { |
173 this->flushGlyphs(); | 177 this->flushGlyphs(); |
174 | 178 |
175 GrTextContext::finish(); | 179 GrTextContext::finish(); |
176 } | 180 } |
177 | 181 |
178 void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint, | 182 void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint, |
179 const char text[], size_t byteLength, | 183 const char text[], size_t byteLength, |
180 SkScalar x, SkScalar y) { | 184 SkScalar x, SkScalar y) { |
181 SkASSERT(byteLength == 0 || text != NULL); | 185 SkASSERT(byteLength == 0 || text != NULL); |
182 | 186 |
183 // nothing to draw | 187 // nothing to draw |
184 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { | 188 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { |
185 return; | 189 return; |
186 } | 190 } |
187 | 191 |
188 this->init(paint, skPaint); | 192 this->init(paint, skPaint); |
189 | 193 |
190 if (NULL == fDrawTarget) { | |
191 return; | |
192 } | |
193 | |
194 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 194 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
195 | 195 |
196 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); | 196 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); |
197 SkGlyphCache* cache = autoCache.getCache(); | 197 SkGlyphCache* cache = autoCache.getCache(); |
198 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 198 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
199 if (NULL == fStrike) { | |
200 fStrike = fContext->getFontCache()->getStrike(fontScaler, false); | |
201 } | |
202 | 199 |
203 // transform our starting point | 200 // transform our starting point |
204 { | 201 { |
205 SkPoint loc; | 202 SkPoint loc; |
206 fContext->getMatrix().mapXY(x, y, &loc); | 203 fContext->getMatrix().mapXY(x, y, &loc); |
207 x = loc.fX; | 204 x = loc.fX; |
208 y = loc.fY; | 205 y = loc.fY; |
209 } | 206 } |
210 | 207 |
211 // need to measure first | 208 // need to measure first |
212 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { | 209 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { |
213 SkVector stop; | 210 SkVector stop; |
214 | 211 |
215 MeasureText(cache, glyphCacheProc, text, byteLength, &stop); | 212 MeasureText(cache, glyphCacheProc, text, byteLength, &stop); |
216 | 213 |
217 SkScalar stopX = stop.fX; | 214 SkScalar stopX = stop.fX; |
218 SkScalar stopY = stop.fY; | 215 SkScalar stopY = stop.fY; |
219 | 216 |
220 if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) { | 217 if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) { |
221 stopX = SkScalarHalf(stopX); | 218 stopX = SkScalarHalf(stopX); |
222 stopY = SkScalarHalf(stopY); | 219 stopY = SkScalarHalf(stopY); |
223 } | 220 } |
224 x -= stopX; | 221 x -= stopX; |
225 y -= stopY; | 222 y -= stopY; |
226 } | 223 } |
227 | 224 |
228 const char* stop = text + byteLength; | 225 const char* stop = text + byteLength; |
229 | 226 |
230 // allocate vertices | |
231 SkASSERT(NULL == fVertices); | |
232 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); | |
233 if (useColorVerts) { | |
234 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>( | |
235 SK_ARRAY_COUNT(gTextVertexWi
thColorAttribs)); | |
236 } else { | |
237 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( | |
238 SK_ARRAY_COUNT(gTextVertexAt
tribs)); | |
239 } | |
240 int numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL); | |
241 bool success = fDrawTarget->reserveVertexAndIndexSpace(4*numGlyphs, | |
242 0, | |
243 &fVertices, | |
244 NULL); | |
245 GrAlwaysAssert(success); | |
246 | |
247 SkAutoKern autokern; | 227 SkAutoKern autokern; |
248 | 228 |
249 SkFixed fxMask = ~0; | 229 SkFixed fxMask = ~0; |
250 SkFixed fyMask = ~0; | 230 SkFixed fyMask = ~0; |
251 SkFixed halfSampleX, halfSampleY; | 231 SkFixed halfSampleX, halfSampleY; |
252 if (cache->isSubpixel()) { | 232 if (cache->isSubpixel()) { |
253 halfSampleX = halfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits); | 233 halfSampleX = halfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits); |
254 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(fContext->getM
atrix()); | 234 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(fContext->getM
atrix()); |
255 if (kX_SkAxisAlignment == baseline) { | 235 if (kX_SkAxisAlignment == baseline) { |
256 fyMask = 0; | 236 fyMask = 0; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 SkASSERT(byteLength == 0 || text != NULL); | 277 SkASSERT(byteLength == 0 || text != NULL); |
298 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 278 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
299 | 279 |
300 // nothing to draw | 280 // nothing to draw |
301 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { | 281 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { |
302 return; | 282 return; |
303 } | 283 } |
304 | 284 |
305 this->init(paint, skPaint); | 285 this->init(paint, skPaint); |
306 | 286 |
307 if (NULL == fDrawTarget) { | |
308 return; | |
309 } | |
310 | |
311 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 287 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
312 | 288 |
313 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); | 289 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); |
314 SkGlyphCache* cache = autoCache.getCache(); | 290 SkGlyphCache* cache = autoCache.getCache(); |
315 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 291 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
316 | |
317 if (NULL == fStrike) { | |
318 fStrike = fContext->getFontCache()->getStrike(fontScaler, false); | |
319 } | |
320 | 292 |
321 // store original matrix before we reset, so we can use it to transform posi
tions | 293 // store original matrix before we reset, so we can use it to transform posi
tions |
322 SkMatrix ctm = fContext->getMatrix(); | 294 SkMatrix ctm = fContext->getMatrix(); |
323 GrContext::AutoMatrix autoMatrix; | 295 GrContext::AutoMatrix autoMatrix; |
324 autoMatrix.setIdentity(fContext, &fPaint); | 296 autoMatrix.setIdentity(fContext, &fPaint); |
325 | 297 |
326 // allocate vertices | |
327 SkASSERT(NULL == fVertices); | |
328 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); | |
329 if (useColorVerts) { | |
330 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>( | |
331 SK_ARRAY_COUNT(gTextVertexWi
thColorAttribs)); | |
332 } else { | |
333 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( | |
334 SK_ARRAY_COUNT(gTextVertexAt
tribs)); | |
335 } | |
336 int numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL); | |
337 bool success = fDrawTarget->reserveVertexAndIndexSpace(4*numGlyphs, | |
338 0, | |
339 &fVertices, | |
340 NULL); | |
341 GrAlwaysAssert(success); | |
342 | |
343 const char* stop = text + byteLength; | 298 const char* stop = text + byteLength; |
344 SkTextAlignProc alignProc(fSkPaint.getTextAlign()); | 299 SkTextAlignProc alignProc(fSkPaint.getTextAlign()); |
345 SkTextMapStateProc tmsProc(ctm, constY, scalarsPerPosition); | 300 SkTextMapStateProc tmsProc(ctm, constY, scalarsPerPosition); |
346 SkFixed halfSampleX = 0, halfSampleY = 0; | 301 SkFixed halfSampleX = 0, halfSampleY = 0; |
347 | 302 |
348 if (cache->isSubpixel()) { | 303 if (cache->isSubpixel()) { |
349 // maybe we should skip the rounding if linearText is set | 304 // maybe we should skip the rounding if linearText is set |
350 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(ctm); | 305 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(ctm); |
351 | 306 |
352 SkFixed fxMask = ~0; | 307 SkFixed fxMask = ~0; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 419 } |
465 } | 420 } |
466 } | 421 } |
467 | 422 |
468 this->finish(); | 423 this->finish(); |
469 } | 424 } |
470 | 425 |
471 void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed, | 426 void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed, |
472 SkFixed vx, SkFixed vy, | 427 SkFixed vx, SkFixed vy, |
473 GrFontScaler* scaler) { | 428 GrFontScaler* scaler) { |
| 429 if (NULL == fDrawTarget) { |
| 430 return; |
| 431 } |
| 432 |
| 433 if (NULL == fStrike) { |
| 434 fStrike = fContext->getFontCache()->getStrike(scaler, false); |
| 435 } |
| 436 |
474 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); | 437 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); |
475 if (NULL == glyph || glyph->fBounds.isEmpty()) { | 438 if (NULL == glyph || glyph->fBounds.isEmpty()) { |
476 return; | 439 return; |
477 } | 440 } |
478 | 441 |
479 vx += SkIntToFixed(glyph->fBounds.fLeft); | 442 vx += SkIntToFixed(glyph->fBounds.fLeft); |
480 vy += SkIntToFixed(glyph->fBounds.fTop); | 443 vy += SkIntToFixed(glyph->fBounds.fTop); |
481 | 444 |
482 // keep them as ints until we've done the clip-test | 445 // keep them as ints until we've done the clip-test |
483 SkFixed width = glyph->fBounds.width(); | 446 SkFixed width = glyph->fBounds.width(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); | 509 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); |
547 glyph->fPlot->setDrawToken(drawToken); | 510 glyph->fPlot->setDrawToken(drawToken); |
548 | 511 |
549 // now promote them to fixed (TODO: Rethink using fixed pt). | 512 // now promote them to fixed (TODO: Rethink using fixed pt). |
550 width = SkIntToFixed(width); | 513 width = SkIntToFixed(width); |
551 height = SkIntToFixed(height); | 514 height = SkIntToFixed(height); |
552 | 515 |
553 GrTexture* texture = glyph->fPlot->texture(); | 516 GrTexture* texture = glyph->fPlot->texture(); |
554 SkASSERT(texture); | 517 SkASSERT(texture); |
555 | 518 |
| 519 if (fCurrTexture != texture || fCurrVertex + 4 > fMaxVertices) { |
| 520 this->flushGlyphs(); |
| 521 fCurrTexture = texture; |
| 522 fCurrTexture->ref(); |
| 523 } |
| 524 |
| 525 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); |
| 526 |
| 527 if (NULL == fVertices) { |
| 528 // If we need to reserve vertices allow the draw target to suggest |
| 529 // a number of verts to reserve and whether to perform a flush. |
| 530 fMaxVertices = kMinRequestedVerts; |
| 531 if (useColorVerts) { |
| 532 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttri
bs>( |
| 533 SK_ARRAY_COUNT(gTextVertexWithColorAttribs)); |
| 534 } else { |
| 535 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
| 536 SK_ARRAY_COUNT(gTextVertexAttribs)); |
| 537 } |
| 538 bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 539 if (flush) { |
| 540 this->flushGlyphs(); |
| 541 fContext->flush(); |
| 542 if (useColorVerts) { |
| 543 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorA
ttribs>( |
| 544 SK_ARRAY_COUNT(gTextVertexWithColorAttribs)); |
| 545 } else { |
| 546 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
| 547 SK_ARRAY_COUNT(gTextVertexAttribs)); |
| 548 } |
| 549 } |
| 550 fMaxVertices = kDefaultRequestedVerts; |
| 551 // ignore return, no point in flushing again. |
| 552 fDrawTarget->geometryHints(&fMaxVertices, NULL); |
| 553 |
| 554 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); |
| 555 if (fMaxVertices < kMinRequestedVerts) { |
| 556 fMaxVertices = kDefaultRequestedVerts; |
| 557 } else if (fMaxVertices > maxQuadVertices) { |
| 558 // don't exceed the limit of the index buffer |
| 559 fMaxVertices = maxQuadVertices; |
| 560 } |
| 561 bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices, |
| 562 0, |
| 563 &fVertices, |
| 564 NULL); |
| 565 GrAlwaysAssert(success); |
| 566 } |
| 567 |
556 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); | 568 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); |
557 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); | 569 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); |
558 | 570 |
559 SkRect r; | 571 SkRect r; |
560 r.fLeft = SkFixedToFloat(vx); | 572 r.fLeft = SkFixedToFloat(vx); |
561 r.fTop = SkFixedToFloat(vy); | 573 r.fTop = SkFixedToFloat(vy); |
562 r.fRight = SkFixedToFloat(vx + width); | 574 r.fRight = SkFixedToFloat(vx + width); |
563 r.fBottom = SkFixedToFloat(vy + height); | 575 r.fBottom = SkFixedToFloat(vy + height); |
564 | 576 |
565 fVertexBounds.growToInclude(r); | 577 fVertexBounds.growToInclude(r); |
566 | 578 |
567 bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat(); | |
568 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : | 579 size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) : |
569 (2 * sizeof(SkPoint)); | 580 (2 * sizeof(SkPoint)); |
570 | 581 |
571 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize()); | 582 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize()); |
572 | 583 |
573 SkPoint* positions = reinterpret_cast<SkPoint*>( | 584 SkPoint* positions = reinterpret_cast<SkPoint*>( |
574 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); | 585 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); |
575 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); | 586 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); |
576 | 587 |
577 // The texture coords are last in both the with and without color vertex lay
outs. | 588 // The texture coords are last in both the with and without color vertex lay
outs. |
578 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( | 589 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( |
579 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint))
; | 590 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint))
; |
580 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), | 591 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), |
581 SkFixedToFloat(texture->normalizeFixedY(ty)), | 592 SkFixedToFloat(texture->normalizeFixedY(ty)), |
582 SkFixedToFloat(texture->normalizeFixedX(tx + width
)), | 593 SkFixedToFloat(texture->normalizeFixedX(tx + width
)), |
583 SkFixedToFloat(texture->normalizeFixedY(ty + heigh
t)), | 594 SkFixedToFloat(texture->normalizeFixedY(ty + heigh
t)), |
584 vertSize); | 595 vertSize); |
585 if (useColorVerts) { | 596 if (useColorVerts) { |
586 // color comes after position. | 597 // color comes after position. |
587 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); | 598 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); |
588 for (int i = 0; i < 4; ++i) { | 599 for (int i = 0; i < 4; ++i) { |
589 *colors = fPaint.getColor(); | 600 *colors = fPaint.getColor(); |
590 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors
) + vertSize); | 601 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(colors
) + vertSize); |
591 } | 602 } |
592 } | 603 } |
593 fCurrVertex += 4; | 604 fCurrVertex += 4; |
594 } | 605 } |
OLD | NEW |