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 "GrAtlasTextBatch.h" | 8 #include "GrAtlasTextBatch.h" |
9 | 9 |
10 #include "GrBatchFontCache.h" | 10 #include "GrBatchFontCache.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 typedef GrAtlasTextBlob Blob; | 124 typedef GrAtlasTextBlob Blob; |
125 typedef Blob::Run Run; | 125 typedef Blob::Run Run; |
126 typedef Run::SubRunInfo TextInfo; | 126 typedef Run::SubRunInfo TextInfo; |
127 | 127 |
128 template <bool regenPos, bool regenCol, bool regenTexCoords, bool regenGlyphs> | 128 template <bool regenPos, bool regenCol, bool regenTexCoords, bool regenGlyphs> |
129 inline void GrAtlasTextBatch::regenBlob(Target* target, FlushInfo* flushInfo, Bl
ob* blob, Run* run, | 129 inline void GrAtlasTextBatch::regenBlob(Target* target, FlushInfo* flushInfo, Bl
ob* blob, Run* run, |
130 TextInfo* info, SkGlyphCache** cache, | 130 TextInfo* info, SkGlyphCache** cache, |
131 SkTypeface** typeface, GrFontScaler** sc
aler, | 131 SkTypeface** typeface, GrFontScaler** sc
aler, |
132 const SkDescriptor** desc, const GrGeome
tryProcessor* gp, | 132 const SkDescriptor** desc, const GrGeome
tryProcessor* gp, |
133 int glyphCount, size_t vertexStride, | 133 int glyphCount, size_t vertexStride, |
134 GrColor color, SkScalar transX, SkScalar
transY) { | 134 GrColor color, SkScalar transX, SkScalar
transY) const { |
135 static_assert(!regenGlyphs || regenTexCoords, "must regenTexCoords along reg
enGlyphs"); | 135 static_assert(!regenGlyphs || regenTexCoords, "must regenTexCoords along reg
enGlyphs"); |
136 GrBatchTextStrike* strike = nullptr; | 136 GrBatchTextStrike* strike = nullptr; |
137 if (regenTexCoords) { | 137 if (regenTexCoords) { |
138 info->fBulkUseToken.reset(); | 138 info->fBulkUseToken.reset(); |
139 | 139 |
140 // We can reuse if we have a valid strike and our descriptors / typeface
are the | 140 // We can reuse if we have a valid strike and our descriptors / typeface
are the |
141 // same. The override descriptor is only for the non distance field tex
t within | 141 // same. The override descriptor is only for the non distance field tex
t within |
142 // a run | 142 // a run |
143 const SkDescriptor* newDesc = (run->fOverrideDescriptor && !this->usesDi
stanceFields()) ? | 143 const SkDescriptor* newDesc = (run->fOverrideDescriptor && !this->usesDi
stanceFields()) ? |
144 run->fOverrideDescriptor->getDesc() : | 144 run->fOverrideDescriptor->getDesc() : |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 kRegenPosTexGlyph = kRegenPos | kRegenGlyph, | 290 kRegenPosTexGlyph = kRegenPos | kRegenGlyph, |
291 kRegenPosColTex = kRegenPos | kRegenCol | kRegenTex, | 291 kRegenPosColTex = kRegenPos | kRegenCol | kRegenTex, |
292 kRegenPosColTexGlyph = kRegenPos | kRegenCol | kRegenGlyph, | 292 kRegenPosColTexGlyph = kRegenPos | kRegenCol | kRegenGlyph, |
293 kRegenColTex = kRegenCol | kRegenTex, | 293 kRegenColTex = kRegenCol | kRegenTex, |
294 kRegenColTexGlyph = kRegenCol | kRegenGlyph, | 294 kRegenColTexGlyph = kRegenCol | kRegenGlyph, |
295 }; | 295 }; |
296 | 296 |
297 #define REGEN_ARGS target, &flushInfo, blob, &run, &info, &cache, &typeface, &sc
aler, &desc, gp, \ | 297 #define REGEN_ARGS target, &flushInfo, blob, &run, &info, &cache, &typeface, &sc
aler, &desc, gp, \ |
298 glyphCount, vertexStride, args.fColor, args.fTransX, args.fTr
ansY | 298 glyphCount, vertexStride, args.fColor, args.fTransX, args.fTr
ansY |
299 | 299 |
300 void GrAtlasTextBatch::onPrepareDraws(Target* target) { | 300 void GrAtlasTextBatch::onPrepareDraws(Target* target) const { |
301 // if we have RGB, then we won't have any SkShaders so no need to use a loca
lmatrix. | 301 // if we have RGB, then we won't have any SkShaders so no need to use a loca
lmatrix. |
302 // TODO actually only invert if we don't have RGBA | 302 // TODO actually only invert if we don't have RGBA |
303 SkMatrix localMatrix; | 303 SkMatrix localMatrix; |
304 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) { | 304 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) { |
305 SkDebugf("Cannot invert viewmatrix\n"); | 305 SkDebugf("Cannot invert viewmatrix\n"); |
306 return; | 306 return; |
307 } | 307 } |
308 | 308 |
309 GrTexture* texture = fFontCache->getTexture(this->maskFormat()); | 309 GrTexture* texture = fFontCache->getTexture(this->maskFormat()); |
310 if (!texture) { | 310 if (!texture) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices); | 356 unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices); |
357 | 357 |
358 // We cache some values to avoid going to the glyphcache for the same fontSc
aler twice | 358 // We cache some values to avoid going to the glyphcache for the same fontSc
aler twice |
359 // in a row | 359 // in a row |
360 const SkDescriptor* desc = nullptr; | 360 const SkDescriptor* desc = nullptr; |
361 SkGlyphCache* cache = nullptr; | 361 SkGlyphCache* cache = nullptr; |
362 GrFontScaler* scaler = nullptr; | 362 GrFontScaler* scaler = nullptr; |
363 SkTypeface* typeface = nullptr; | 363 SkTypeface* typeface = nullptr; |
364 | 364 |
365 for (int i = 0; i < fGeoCount; i++) { | 365 for (int i = 0; i < fGeoCount; i++) { |
366 Geometry& args = fGeoData[i]; | 366 const Geometry& args = fGeoData[i]; |
367 Blob* blob = args.fBlob; | 367 Blob* blob = args.fBlob; |
368 Run& run = blob->fRuns[args.fRun]; | 368 Run& run = blob->fRuns[args.fRun]; |
369 TextInfo& info = run.fSubRunInfo[args.fSubRun]; | 369 TextInfo& info = run.fSubRunInfo[args.fSubRun]; |
370 | 370 |
371 uint64_t currentAtlasGen = fFontCache->atlasGeneration(maskFormat); | 371 uint64_t currentAtlasGen = fFontCache->atlasGeneration(maskFormat); |
372 | 372 |
373 // Because the GrBatchFontCache may evict the strike a blob depends on u
sing for | 373 // Because the GrBatchFontCache may evict the strike a blob depends on u
sing for |
374 // generating its texture coords, we have to track whether or not the st
rike has | 374 // generating its texture coords, we have to track whether or not the st
rike has |
375 // been abandoned. If it hasn't been abandoned, then we can use the GrG
lyph*s as is | 375 // been abandoned. If it hasn't been abandoned, then we can use the GrG
lyph*s as is |
376 // otherwise we have to get the new strike, and use that to get the corr
ect glyphs. | 376 // otherwise we have to get the new strike, and use that to get the corr
ect glyphs. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 currVertex += byteCount; | 427 currVertex += byteCount; |
428 } | 428 } |
429 | 429 |
430 // Make sure to attach the last cache if applicable | 430 // Make sure to attach the last cache if applicable |
431 if (cache) { | 431 if (cache) { |
432 SkGlyphCache::AttachCache(cache); | 432 SkGlyphCache::AttachCache(cache); |
433 } | 433 } |
434 this->flush(target, &flushInfo); | 434 this->flush(target, &flushInfo); |
435 } | 435 } |
436 | 436 |
437 void GrAtlasTextBatch::flush(GrVertexBatch::Target* target, FlushInfo* flushInfo
) { | 437 void GrAtlasTextBatch::flush(GrVertexBatch::Target* target, FlushInfo* flushInfo
) const { |
438 GrVertices vertices; | 438 GrVertices vertices; |
439 int maxGlyphsPerDraw = flushInfo->fIndexBuffer->maxQuads(); | 439 int maxGlyphsPerDraw = flushInfo->fIndexBuffer->maxQuads(); |
440 vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, | 440 vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, |
441 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, | 441 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, |
442 kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyp
hsToFlush, | 442 kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyp
hsToFlush, |
443 maxGlyphsPerDraw); | 443 maxGlyphsPerDraw); |
444 target->draw(vertices); | 444 target->draw(vertices); |
445 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush; | 445 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush; |
446 flushInfo->fGlyphsToFlush = 0; | 446 flushInfo->fGlyphsToFlush = 0; |
447 } | 447 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 fGeoCount = newGeoCount; | 511 fGeoCount = newGeoCount; |
512 | 512 |
513 this->joinBounds(that->bounds()); | 513 this->joinBounds(that->bounds()); |
514 return true; | 514 return true; |
515 } | 515 } |
516 | 516 |
517 // TODO just use class params | 517 // TODO just use class params |
518 // TODO trying to figure out why lcd is so whack | 518 // TODO trying to figure out why lcd is so whack |
519 GrGeometryProcessor* GrAtlasTextBatch::setupDfProcessor(const SkMatrix& viewMatr
ix, | 519 GrGeometryProcessor* GrAtlasTextBatch::setupDfProcessor(const SkMatrix& viewMatr
ix, |
520 SkColor filteredColor, | 520 SkColor filteredColor, |
521 GrColor color, GrTexture
* texture) { | 521 GrColor color, GrTexture
* texture) const { |
522 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_F
ilterMode); | 522 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_F
ilterMode); |
523 bool isLCD = this->isLCD(); | 523 bool isLCD = this->isLCD(); |
524 // set up any flags | 524 // set up any flags |
525 uint32_t flags = viewMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffect
Flag : 0; | 525 uint32_t flags = viewMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffect
Flag : 0; |
526 | 526 |
527 // see if we need to create a new effect | 527 // see if we need to create a new effect |
528 if (isLCD) { | 528 if (isLCD) { |
529 flags |= kUseLCD_DistanceFieldEffectFlag; | 529 flags |= kUseLCD_DistanceFieldEffectFlag; |
530 flags |= viewMatrix.rectStaysRect() ? kRectToRect_DistanceFieldEffectFla
g : 0; | 530 flags |= viewMatrix.rectStaysRect() ? kRectToRect_DistanceFieldEffectFla
g : 0; |
531 flags |= fUseBGR ? kBGR_DistanceFieldEffectFlag : 0; | 531 flags |= fUseBGR ? kBGR_DistanceFieldEffectFlag : 0; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 return GrDistanceFieldA8TextGeoProc::Create(color, | 566 return GrDistanceFieldA8TextGeoProc::Create(color, |
567 viewMatrix, | 567 viewMatrix, |
568 texture, | 568 texture, |
569 params, | 569 params, |
570 flags, | 570 flags, |
571 this->usesLocalCoords()); | 571 this->usesLocalCoords()); |
572 #endif | 572 #endif |
573 } | 573 } |
574 | 574 |
575 } | 575 } |
OLD | NEW |