Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: src/gpu/batches/GrAtlasTextBatch.cpp

Issue 1483103003: Make onPrepareDraws const (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 kRegenPosTexGlyph = kRegenPos | kRegenGlyph, 291 kRegenPosTexGlyph = kRegenPos | kRegenGlyph,
292 kRegenPosColTex = kRegenPos | kRegenCol | kRegenTex, 292 kRegenPosColTex = kRegenPos | kRegenCol | kRegenTex,
293 kRegenPosColTexGlyph = kRegenPos | kRegenCol | kRegenGlyph, 293 kRegenPosColTexGlyph = kRegenPos | kRegenCol | kRegenGlyph,
294 kRegenColTex = kRegenCol | kRegenTex, 294 kRegenColTex = kRegenCol | kRegenTex,
295 kRegenColTexGlyph = kRegenCol | kRegenGlyph, 295 kRegenColTexGlyph = kRegenCol | kRegenGlyph,
296 }; 296 };
297 297
298 #define REGEN_ARGS target, &flushInfo, blob, &run, &info, &cache, &typeface, &sc aler, &desc, gp, \ 298 #define REGEN_ARGS target, &flushInfo, blob, &run, &info, &cache, &typeface, &sc aler, &desc, gp, \
299 glyphCount, vertexStride, args.fColor, args.fTransX, args.fTr ansY 299 glyphCount, vertexStride, args.fColor, args.fTransX, args.fTr ansY
300 300
301 void GrAtlasTextBatch::onPrepareDraws(Target* target) { 301 void GrAtlasTextBatch::onPrepareDraws(Target* target) const {
302 // if we have RGB, then we won't have any SkShaders so no need to use a loca lmatrix. 302 // if we have RGB, then we won't have any SkShaders so no need to use a loca lmatrix.
303 // TODO actually only invert if we don't have RGBA 303 // TODO actually only invert if we don't have RGBA
304 SkMatrix localMatrix; 304 SkMatrix localMatrix;
305 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) { 305 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) {
306 SkDebugf("Cannot invert viewmatrix\n"); 306 SkDebugf("Cannot invert viewmatrix\n");
307 return; 307 return;
308 } 308 }
309 309
310 GrTexture* texture = fFontCache->getTexture(this->maskFormat()); 310 GrTexture* texture = fFontCache->getTexture(this->maskFormat());
311 if (!texture) { 311 if (!texture) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices); 357 unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices);
358 358
359 // We cache some values to avoid going to the glyphcache for the same fontSc aler twice 359 // We cache some values to avoid going to the glyphcache for the same fontSc aler twice
360 // in a row 360 // in a row
361 const SkDescriptor* desc = nullptr; 361 const SkDescriptor* desc = nullptr;
362 SkGlyphCache* cache = nullptr; 362 SkGlyphCache* cache = nullptr;
363 GrFontScaler* scaler = nullptr; 363 GrFontScaler* scaler = nullptr;
364 SkTypeface* typeface = nullptr; 364 SkTypeface* typeface = nullptr;
365 365
366 for (int i = 0; i < fGeoCount; i++) { 366 for (int i = 0; i < fGeoCount; i++) {
367 Geometry& args = fGeoData[i]; 367 const Geometry& args = fGeoData[i];
368 Blob* blob = args.fBlob; 368 Blob* blob = args.fBlob;
369 Run& run = blob->fRuns[args.fRun]; 369 Run& run = blob->fRuns[args.fRun];
370 TextInfo& info = run.fSubRunInfo[args.fSubRun]; 370 TextInfo& info = run.fSubRunInfo[args.fSubRun];
371 371
372 uint64_t currentAtlasGen = fFontCache->atlasGeneration(maskFormat); 372 uint64_t currentAtlasGen = fFontCache->atlasGeneration(maskFormat);
373 373
374 // Because the GrBatchFontCache may evict the strike a blob depends on u sing for 374 // Because the GrBatchFontCache may evict the strike a blob depends on u sing for
375 // generating its texture coords, we have to track whether or not the st rike has 375 // generating its texture coords, we have to track whether or not the st rike has
376 // been abandoned. If it hasn't been abandoned, then we can use the GrG lyph*s as is 376 // been abandoned. If it hasn't been abandoned, then we can use the GrG lyph*s as is
377 // otherwise we have to get the new strike, and use that to get the corr ect glyphs. 377 // 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
428 currVertex += byteCount; 428 currVertex += byteCount;
429 } 429 }
430 430
431 // Make sure to attach the last cache if applicable 431 // Make sure to attach the last cache if applicable
432 if (cache) { 432 if (cache) {
433 SkGlyphCache::AttachCache(cache); 433 SkGlyphCache::AttachCache(cache);
434 } 434 }
435 this->flush(target, &flushInfo); 435 this->flush(target, &flushInfo);
436 } 436 }
437 437
438 void GrAtlasTextBatch::flush(GrVertexBatch::Target* target, FlushInfo* flushInfo ) { 438 void GrAtlasTextBatch::flush(GrVertexBatch::Target* target, FlushInfo* flushInfo ) const {
439 GrVertices vertices; 439 GrVertices vertices;
440 int maxGlyphsPerDraw = flushInfo->fIndexBuffer->maxQuads(); 440 int maxGlyphsPerDraw = flushInfo->fIndexBuffer->maxQuads();
441 vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, 441 vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer,
442 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, 442 flushInfo->fIndexBuffer, flushInfo->fVertexOffset,
443 kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyp hsToFlush, 443 kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyp hsToFlush,
444 maxGlyphsPerDraw); 444 maxGlyphsPerDraw);
445 target->draw(vertices); 445 target->draw(vertices);
446 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush; 446 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush;
447 flushInfo->fGlyphsToFlush = 0; 447 flushInfo->fGlyphsToFlush = 0;
448 } 448 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 fGeoCount = newGeoCount; 512 fGeoCount = newGeoCount;
513 513
514 this->joinBounds(that->bounds()); 514 this->joinBounds(that->bounds());
515 return true; 515 return true;
516 } 516 }
517 517
518 // TODO just use class params 518 // TODO just use class params
519 // TODO trying to figure out why lcd is so whack 519 // TODO trying to figure out why lcd is so whack
520 GrGeometryProcessor* GrAtlasTextBatch::setupDfProcessor(const SkMatrix& viewMatr ix, 520 GrGeometryProcessor* GrAtlasTextBatch::setupDfProcessor(const SkMatrix& viewMatr ix,
521 SkColor filteredColor, 521 SkColor filteredColor,
522 GrColor color, GrTexture * texture) { 522 GrColor color, GrTexture * texture) const {
523 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_F ilterMode); 523 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_F ilterMode);
524 bool isLCD = this->isLCD(); 524 bool isLCD = this->isLCD();
525 // set up any flags 525 // set up any flags
526 uint32_t flags = viewMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffect Flag : 0; 526 uint32_t flags = viewMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffect Flag : 0;
527 527
528 // see if we need to create a new effect 528 // see if we need to create a new effect
529 if (isLCD) { 529 if (isLCD) {
530 flags |= kUseLCD_DistanceFieldEffectFlag; 530 flags |= kUseLCD_DistanceFieldEffectFlag;
531 flags |= viewMatrix.rectStaysRect() ? kRectToRect_DistanceFieldEffectFla g : 0; 531 flags |= viewMatrix.rectStaysRect() ? kRectToRect_DistanceFieldEffectFla g : 0;
532 flags |= fUseBGR ? kBGR_DistanceFieldEffectFlag : 0; 532 flags |= fUseBGR ? kBGR_DistanceFieldEffectFlag : 0;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 return GrDistanceFieldA8TextGeoProc::Create(color, 567 return GrDistanceFieldA8TextGeoProc::Create(color,
568 viewMatrix, 568 viewMatrix,
569 texture, 569 texture,
570 params, 570 params,
571 flags, 571 flags,
572 this->usesLocalCoords()); 572 this->usesLocalCoords());
573 #endif 573 #endif
574 } 574 }
575 575
576 } 576 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698