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

Side by Side Diff: src/gpu/GrAtlasTextContext.cpp

Issue 1502323002: A small cleanup of GrAtlasTextContext (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanuptext
Patch Set: fix refcount issue 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
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "GrAtlasTextContext.h" 7 #include "GrAtlasTextContext.h"
8 8
9 #include "GrBlurUtils.h" 9 #include "GrBlurUtils.h"
10 #include "GrDrawContext.h" 10 #include "GrDrawContext.h"
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 it.applyFontToPaint(&runPaint); 454 it.applyFontToPaint(&runPaint);
455 455
456 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ e)) { 456 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ e)) {
457 // A false return from filter() means we should abort the current dr aw. 457 // A false return from filter() means we should abort the current dr aw.
458 runPaint = skPaint; 458 runPaint = skPaint;
459 continue; 459 continue;
460 } 460 }
461 461
462 runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint)); 462 runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint));
463 463
464 // setup vertex / glyphIndex for the new run 464 cacheBlob->push_back_run(run);
465 if (run > 0) {
466 PerSubRunInfo& newRun = cacheBlob->fRuns[run].fSubRunInfo.back();
467 PerSubRunInfo& lastRun = cacheBlob->fRuns[run - 1].fSubRunInfo.back( );
468
469 newRun.setVertexStartIndex(lastRun.vertexEndIndex());
470 newRun.setVertexEndIndex(lastRun.vertexEndIndex());
471
472 newRun.setGlyphStartIndex(lastRun.glyphEndIndex());
473 newRun.setGlyphEndIndex(lastRun.glyphEndIndex());
474 }
475 465
476 if (this->canDrawAsDistanceFields(runPaint, viewMatrix)) { 466 if (this->canDrawAsDistanceFields(runPaint, viewMatrix)) {
477 cacheBlob->setHasDistanceField(); 467 cacheBlob->setHasDistanceField();
478 SkPaint dfPaint = runPaint; 468 SkPaint dfPaint = runPaint;
479 SkScalar textRatio; 469 SkScalar textRatio;
480 this->initDistanceFieldPaint(cacheBlob, &dfPaint, &textRatio, viewMa trix); 470 this->initDistanceFieldPaint(cacheBlob, &dfPaint, &textRatio, viewMa trix);
481 Run& runIdx = cacheBlob->fRuns[run]; 471 Run& runIdx = cacheBlob->fRuns[run];
482 PerSubRunInfo& subRun = runIdx.fSubRunInfo.back(); 472 PerSubRunInfo& subRun = runIdx.fSubRunInfo.back();
483 subRun.setUseLCDText(runPaint.isLCDRenderText()); 473 subRun.setUseLCDText(runPaint.isLCDRenderText());
484 subRun.setDrawAsDistanceFields(); 474 subRun.setDrawAsDistanceFields();
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 return; 994 return;
1005 } 995 }
1006 996
1007 GrMaskFormat format = glyph->fMaskFormat; 997 GrMaskFormat format = glyph->fMaskFormat;
1008 998
1009 PerSubRunInfo* subRun = &run.fSubRunInfo.back(); 999 PerSubRunInfo* subRun = &run.fSubRunInfo.back();
1010 if (run.fInitialized && subRun->maskFormat() != format) { 1000 if (run.fInitialized && subRun->maskFormat() != format) {
1011 subRun = &run.push_back(); 1001 subRun = &run.push_back();
1012 subRun->setStrike(fCurrStrike); 1002 subRun->setStrike(fCurrStrike);
1013 } else if (!run.fInitialized) { 1003 } else if (!run.fInitialized) {
1014 subRun->setStrike(SkRef(fCurrStrike)); 1004 subRun->setStrike(fCurrStrike);
1015 } 1005 }
1016 1006
1017 run.fInitialized = true; 1007 run.fInitialized = true;
1018 1008
1019 size_t vertexStride = GrAtlasTextBatch::GetVertexStride(format); 1009 size_t vertexStride = GrAtlasTextBatch::GetVertexStride(format);
1020 1010
1021 SkRect r; 1011 SkRect r;
1022 r.fLeft = SkIntToScalar(x); 1012 r.fLeft = SkIntToScalar(x);
1023 r.fTop = SkIntToScalar(y); 1013 r.fTop = SkIntToScalar(y);
1024 r.fRight = r.fLeft + SkIntToScalar(width); 1014 r.fRight = r.fLeft + SkIntToScalar(width);
1025 r.fBottom = r.fTop + SkIntToScalar(height); 1015 r.fBottom = r.fTop + SkIntToScalar(height);
1026 subRun->setMaskFormat(format); 1016 subRun->setMaskFormat(format);
1027 this->appendGlyphCommon(blob, &run, subRun, r, color, vertexStride, kA8_GrMa skFormat == format, 1017 blob->appendGlyph(&run, subRun, r, color, vertexStride, kA8_GrMaskFormat == format, glyph);
1028 glyph);
1029 } 1018 }
1030 1019
1031 bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, 1020 bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
1032 const SkGlyph& skGlyph, 1021 const SkGlyph& skGlyph,
1033 SkScalar sx, SkScalar sy, GrColor color, 1022 SkScalar sx, SkScalar sy, GrColor color,
1034 GrFontScaler* scaler, 1023 GrFontScaler* scaler,
1035 SkScalar textRatio, const SkMatrix& viewM atrix) { 1024 SkScalar textRatio, const SkMatrix& viewM atrix) {
1036 Run& run = blob->fRuns[runIndex]; 1025 Run& run = blob->fRuns[runIndex];
1037 if (!fCurrStrike) { 1026 if (!fCurrStrike) {
1038 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); 1027 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 subRun->setStrike(fCurrStrike); 1067 subRun->setStrike(fCurrStrike);
1079 } 1068 }
1080 run.fInitialized = true; 1069 run.fInitialized = true;
1081 SkASSERT(glyph->fMaskFormat == kA8_GrMaskFormat); 1070 SkASSERT(glyph->fMaskFormat == kA8_GrMaskFormat);
1082 subRun->setMaskFormat(kA8_GrMaskFormat); 1071 subRun->setMaskFormat(kA8_GrMaskFormat);
1083 1072
1084 size_t vertexStride = GrAtlasTextBatch::GetVertexStrideDf(kA8_GrMaskFormat, 1073 size_t vertexStride = GrAtlasTextBatch::GetVertexStrideDf(kA8_GrMaskFormat,
1085 subRun->hasUseLCDT ext()); 1074 subRun->hasUseLCDT ext());
1086 1075
1087 bool useColorVerts = !subRun->hasUseLCDText(); 1076 bool useColorVerts = !subRun->hasUseLCDText();
1088 this->appendGlyphCommon(blob, &run, subRun, glyphRect, color, vertexStride, useColorVerts, 1077 blob->appendGlyph(&run, subRun, glyphRect, color, vertexStride, useColorVert s, glyph);
1089 glyph);
1090 return true; 1078 return true;
1091 } 1079 }
1092 1080
1093 inline void GrAtlasTextContext::appendGlyphPath(GrAtlasTextBlob* blob, GrGlyph* glyph, 1081 inline void GrAtlasTextContext::appendGlyphPath(GrAtlasTextBlob* blob, GrGlyph* glyph,
1094 GrFontScaler* scaler, const SkGl yph& skGlyph, 1082 GrFontScaler* scaler, const SkGl yph& skGlyph,
1095 SkScalar x, SkScalar y, SkScalar scale, 1083 SkScalar x, SkScalar y, SkScalar scale,
1096 bool applyVM) { 1084 bool applyVM) {
1097 if (nullptr == glyph->fPath) { 1085 if (nullptr == glyph->fPath) {
1098 const SkPath* glyphPath = scaler->getGlyphPath(skGlyph); 1086 const SkPath* glyphPath = scaler->getGlyphPath(skGlyph);
1099 if (!glyphPath) { 1087 if (!glyphPath) {
1100 return; 1088 return;
1101 } 1089 }
1102 1090
1103 glyph->fPath = new SkPath(*glyphPath); 1091 glyph->fPath = new SkPath(*glyphPath);
1104 } 1092 }
1105 blob->fBigGlyphs.push_back(GrAtlasTextBlob::BigGlyph(*glyph->fPath, x, y, sc ale, applyVM)); 1093 blob->fBigGlyphs.push_back(GrAtlasTextBlob::BigGlyph(*glyph->fPath, x, y, sc ale, applyVM));
1106 } 1094 }
1107 1095
1108 inline void GrAtlasTextContext::appendGlyphCommon(GrAtlasTextBlob* blob, Run* ru n,
1109 Run::SubRunInfo* subRun,
1110 const SkRect& positions, GrCol or color,
1111 size_t vertexStride, bool useV ertexColor,
1112 GrGlyph* glyph) {
1113 blob->appendGlyph(subRun, glyph);
1114 run->fVertexBounds.joinNonEmptyArg(positions);
1115 run->fColor = color;
1116
1117 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices + subRun->verte xEndIndex());
1118
1119 if (useVertexColor) {
1120 // V0
1121 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
1122 position->set(positions.fLeft, positions.fTop);
1123 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)) ;
1124 *colorPtr = color;
1125 vertex += vertexStride;
1126
1127 // V1
1128 position = reinterpret_cast<SkPoint*>(vertex);
1129 position->set(positions.fLeft, positions.fBottom);
1130 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
1131 *colorPtr = color;
1132 vertex += vertexStride;
1133
1134 // V2
1135 position = reinterpret_cast<SkPoint*>(vertex);
1136 position->set(positions.fRight, positions.fBottom);
1137 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
1138 *colorPtr = color;
1139 vertex += vertexStride;
1140
1141 // V3
1142 position = reinterpret_cast<SkPoint*>(vertex);
1143 position->set(positions.fRight, positions.fTop);
1144 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
1145 *colorPtr = color;
1146 } else {
1147 // V0
1148 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
1149 position->set(positions.fLeft, positions.fTop);
1150 vertex += vertexStride;
1151
1152 // V1
1153 position = reinterpret_cast<SkPoint*>(vertex);
1154 position->set(positions.fLeft, positions.fBottom);
1155 vertex += vertexStride;
1156
1157 // V2
1158 position = reinterpret_cast<SkPoint*>(vertex);
1159 position->set(positions.fRight, positions.fBottom);
1160 vertex += vertexStride;
1161
1162 // V3
1163 position = reinterpret_cast<SkPoint*>(vertex);
1164 position->set(positions.fRight, positions.fTop);
1165 }
1166 subRun->appendVertices(vertexStride);
1167 }
1168
1169 void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc, 1096 void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc,
1170 const SkTextBlobRunIterator& it, 1097 const SkTextBlobRunIterator& it,
1171 const GrClip& clip, const SkPaint& skPa int, 1098 const GrClip& clip, const SkPaint& skPa int,
1172 SkDrawFilter* drawFilter, const SkMatri x& viewMatrix, 1099 SkDrawFilter* drawFilter, const SkMatri x& viewMatrix,
1173 const SkIRect& clipBounds, SkScalar x, SkScalar y) { 1100 const SkIRect& clipBounds, SkScalar x, SkScalar y) {
1174 SkPaint runPaint = skPaint; 1101 SkPaint runPaint = skPaint;
1175 1102
1176 size_t textLen = it.glyphCount() * sizeof(uint16_t); 1103 size_t textLen = it.glyphCount() * sizeof(uint16_t);
1177 const SkPoint& offset = it.offset(); 1104 const SkPoint& offset = it.offset();
1178 1105
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 gTextContext->createDrawTextBlob(clip, grPaint, skPaint, viewMatrix, text, 1312 gTextContext->createDrawTextBlob(clip, grPaint, skPaint, viewMatrix, text,
1386 static_cast<size_t>(textLen), 0, 0, noClip)); 1313 static_cast<size_t>(textLen), 0, 0, noClip));
1387 1314
1388 SkScalar transX = static_cast<SkScalar>(random->nextU()); 1315 SkScalar transX = static_cast<SkScalar>(random->nextU());
1389 SkScalar transY = static_cast<SkScalar>(random->nextU()); 1316 SkScalar transY = static_cast<SkScalar>(random->nextU());
1390 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0] ; 1317 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0] ;
1391 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint); 1318 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint);
1392 } 1319 }
1393 1320
1394 #endif 1321 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698