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

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

Issue 1320323004: Make GrTextContext no longer store a GrDrawContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add newline Created 5 years, 3 months 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') | src/gpu/GrDrawContext.cpp » ('j') | 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 "GrBatchFontCache.h" 9 #include "GrBatchFontCache.h"
10 #include "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { 90 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
91 unsigned r = SkColorGetR(c); 91 unsigned r = SkColorGetR(c);
92 unsigned g = SkColorGetG(c); 92 unsigned g = SkColorGetG(c);
93 unsigned b = SkColorGetB(c); 93 unsigned b = SkColorGetB(c);
94 return GrColorPackRGBA(r, g, b, 0xff); 94 return GrColorPackRGBA(r, g, b, 0xff);
95 } 95 }
96 96
97 }; 97 };
98 98
99 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, 99 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, const SkSurfaceProps& surfaceProps)
100 GrDrawContext* drawContext, 100 : INHERITED(context, surfaceProps)
101 const SkSurfaceProps& surfaceProps) 101 , fDistanceAdjustTable(new DistanceAdjustTable) {
102 : INHERITED(context, drawContext, surfaceProps), fDistanceAdjustTable(new Di stanceAdjustTable) {
103 // We overallocate vertices in our textblobs based on the assumption that A8 has the greatest 102 // We overallocate vertices in our textblobs based on the assumption that A8 has the greatest
104 // vertexStride 103 // vertexStride
105 static_assert(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >= kLCD TextVASize, 104 static_assert(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >= kLCD TextVASize,
106 "vertex_attribute_changed"); 105 "vertex_attribute_changed");
107 fCurrStrike = nullptr; 106 fCurrStrike = nullptr;
108 fCache = context->getTextBlobCache(); 107 fCache = context->getTextBlobCache();
109 } 108 }
110 109
111 void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable() { 110 void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable() {
112 111
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 float d = 2.0f*kDistanceFieldAAFactor*t - kDistanceFieldAAFactor ; 183 float d = 2.0f*kDistanceFieldAAFactor*t - kDistanceFieldAAFactor ;
185 184
186 fTable[row] = d; 185 fTable[row] = d;
187 break; 186 break;
188 } 187 }
189 } 188 }
190 } 189 }
191 } 190 }
192 191
193 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context, 192 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context,
194 GrDrawContext* drawContext,
195 const SkSurfaceProps& surfaceProp s) { 193 const SkSurfaceProps& surfaceProp s) {
196 return new GrAtlasTextContext(context, drawContext, surfaceProps); 194 return new GrAtlasTextContext(context, surfaceProps);
197 } 195 }
198 196
199 bool GrAtlasTextContext::canDraw(const GrRenderTarget*, 197 bool GrAtlasTextContext::canDraw(const GrRenderTarget*,
200 const GrClip&, 198 const GrClip&,
201 const GrPaint&, 199 const GrPaint&,
202 const SkPaint& skPaint, 200 const SkPaint& skPaint,
203 const SkMatrix& viewMatrix) { 201 const SkMatrix& viewMatrix) {
204 return this->canDrawAsDistanceFields(skPaint, viewMatrix) || 202 return this->canDrawAsDistanceFields(skPaint, viewMatrix) ||
205 !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); 203 !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix);
206 } 204 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 332
335 inline SkGlyphCache* GrAtlasTextContext::setupCache(GrAtlasTextBlob::Run* run, 333 inline SkGlyphCache* GrAtlasTextContext::setupCache(GrAtlasTextBlob::Run* run,
336 const SkPaint& skPaint, 334 const SkPaint& skPaint,
337 const SkMatrix* viewMatrix, 335 const SkMatrix* viewMatrix,
338 bool noGamma) { 336 bool noGamma) {
339 skPaint.getScalerContextDescriptor(&run->fDescriptor, fSurfaceProps, viewMat rix, noGamma); 337 skPaint.getScalerContextDescriptor(&run->fDescriptor, fSurfaceProps, viewMat rix, noGamma);
340 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface())); 338 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface()));
341 return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc()) ; 339 return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc()) ;
342 } 340 }
343 341
344 void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt, 342 void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc, GrRenderTarget* rt,
345 const GrClip& clip, const SkPaint& skPaint , 343 const GrClip& clip, const SkPaint& skPaint ,
346 const SkMatrix& viewMatrix, const SkTextBl ob* blob, 344 const SkMatrix& viewMatrix, const SkTextBl ob* blob,
347 SkScalar x, SkScalar y, 345 SkScalar x, SkScalar y,
348 SkDrawFilter* drawFilter, const SkIRect& c lipBounds) { 346 SkDrawFilter* drawFilter, const SkIRect& c lipBounds) {
349 // If we have been abandoned, then don't draw 347 // If we have been abandoned, then don't draw
350 if (fContext->abandoned()) { 348 if (fContext->abandoned()) {
351 return; 349 return;
352 } 350 }
353 351
354 SkAutoTUnref<GrAtlasTextBlob> cacheBlob; 352 SkAutoTUnref<GrAtlasTextBlob> cacheBlob;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 if (canCache) { 430 if (canCache) {
433 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s kPaint, 431 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s kPaint,
434 kGrayTextVASize))); 432 kGrayTextVASize)));
435 } else { 433 } else {
436 cacheBlob.reset(fCache->createBlob(blob, kGrayTextVASize)); 434 cacheBlob.reset(fCache->createBlob(blob, kGrayTextVASize));
437 } 435 }
438 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMat rix, 436 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMat rix,
439 blob, x, y, drawFilter, clipRect, rt, clip); 437 blob, x, y, drawFilter, clipRect, rt, clip);
440 } 438 }
441 439
442 this->flush(blob, cacheBlob, rt, skPaint, grPaint, drawFilter, 440 this->flush(blob, cacheBlob, dc, rt, skPaint, grPaint, drawFilter,
443 clip, viewMatrix, clipBounds, x, y, transX, transY); 441 clip, viewMatrix, clipBounds, x, y, transX, transY);
444 } 442 }
445 443
446 inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, 444 inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint,
447 const SkMatrix& viewMatr ix) { 445 const SkMatrix& viewMatr ix) {
448 // TODO: support perspective (need getMaxScale replacement) 446 // TODO: support perspective (need getMaxScale replacement)
449 if (viewMatrix.hasPerspective()) { 447 if (viewMatrix.hasPerspective()) {
450 return false; 448 return false;
451 } 449 }
452 450
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); 780 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize);
783 blob->fViewMatrix = viewMatrix; 781 blob->fViewMatrix = viewMatrix;
784 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false); 782 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false);
785 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text, 783 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text,
786 byteLength, pos, scalarsPerPosition, offset , clipRect); 784 byteLength, pos, scalarsPerPosition, offset , clipRect);
787 SkGlyphCache::AttachCache(cache); 785 SkGlyphCache::AttachCache(cache);
788 } 786 }
789 return blob; 787 return blob;
790 } 788 }
791 789
792 void GrAtlasTextContext::onDrawText(GrRenderTarget* rt, 790 void GrAtlasTextContext::onDrawText(GrDrawContext* dc, GrRenderTarget* rt,
793 const GrClip& clip, 791 const GrClip& clip,
794 const GrPaint& paint, const SkPaint& skPaint , 792 const GrPaint& paint, const SkPaint& skPaint ,
795 const SkMatrix& viewMatrix, 793 const SkMatrix& viewMatrix,
796 const char text[], size_t byteLength, 794 const char text[], size_t byteLength,
797 SkScalar x, SkScalar y, const SkIRect& regio nClipBounds) { 795 SkScalar x, SkScalar y, const SkIRect& regio nClipBounds) {
798 SkAutoTUnref<GrAtlasTextBlob> blob( 796 SkAutoTUnref<GrAtlasTextBlob> blob(
799 this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix, 797 this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix,
800 text, byteLength, x, y, regionClipBounds)); 798 text, byteLength, x, y, regionClipBounds));
801 this->flush(blob, rt, skPaint, paint, clip, regionClipBounds); 799 this->flush(blob, dc, rt, skPaint, paint, clip, regionClipBounds);
802 } 800 }
803 801
804 void GrAtlasTextContext::onDrawPosText(GrRenderTarget* rt, 802 void GrAtlasTextContext::onDrawPosText(GrDrawContext* dc, GrRenderTarget* rt,
805 const GrClip& clip, 803 const GrClip& clip,
806 const GrPaint& paint, const SkPaint& skPa int, 804 const GrPaint& paint, const SkPaint& skPa int,
807 const SkMatrix& viewMatrix, 805 const SkMatrix& viewMatrix,
808 const char text[], size_t byteLength, 806 const char text[], size_t byteLength,
809 const SkScalar pos[], int scalarsPerPosit ion, 807 const SkScalar pos[], int scalarsPerPosit ion,
810 const SkPoint& offset, const SkIRect& reg ionClipBounds) { 808 const SkPoint& offset, const SkIRect& reg ionClipBounds) {
811 SkAutoTUnref<GrAtlasTextBlob> blob( 809 SkAutoTUnref<GrAtlasTextBlob> blob(
812 this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix, 810 this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix,
813 text, byteLength, 811 text, byteLength,
814 pos, scalarsPerPosition, 812 pos, scalarsPerPosition,
815 offset, regionClipBounds)); 813 offset, regionClipBounds));
816 814
817 this->flush(blob, rt, skPaint, paint, clip, regionClipBounds); 815 this->flush(blob, dc, rt, skPaint, paint, clip, regionClipBounds);
818 } 816 }
819 817
820 void GrAtlasTextContext::internalDrawBMPText(GrAtlasTextBlob* blob, int runIndex , 818 void GrAtlasTextContext::internalDrawBMPText(GrAtlasTextBlob* blob, int runIndex ,
821 SkGlyphCache* cache, const SkPaint& skPaint, 819 SkGlyphCache* cache, const SkPaint& skPaint,
822 GrColor color, 820 GrColor color,
823 const SkMatrix& viewMatrix, 821 const SkMatrix& viewMatrix,
824 const char text[], size_t byteLengt h, 822 const char text[], size_t byteLengt h,
825 SkScalar x, SkScalar y, const SkIRe ct& clipRect) { 823 SkScalar x, SkScalar y, const SkIRe ct& clipRect) {
826 SkASSERT(byteLength == 0 || text != nullptr); 824 SkASSERT(byteLength == 0 || text != nullptr);
827 825
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 } 1470 }
1473 batch->fBatch.fNumGlyphs = glyphCount; 1471 batch->fBatch.fNumGlyphs = glyphCount;
1474 batch->fGeoCount = 1; 1472 batch->fGeoCount = 1;
1475 batch->fFilteredColor = 0; 1473 batch->fFilteredColor = 0;
1476 batch->fFontCache = fontCache; 1474 batch->fFontCache = fontCache;
1477 batch->fUseBGR = false; 1475 batch->fUseBGR = false;
1478 return batch; 1476 return batch;
1479 } 1477 }
1480 1478
1481 static TextBatch* CreateDistanceField(int glyphCount, GrBatchFontCache* font Cache, 1479 static TextBatch* CreateDistanceField(int glyphCount, GrBatchFontCache* font Cache,
1482 DistanceAdjustTable* distanceAdjustTab le, 1480 const DistanceAdjustTable* distanceAdj ustTable,
1483 SkColor filteredColor, bool isLCD, 1481 SkColor filteredColor, bool isLCD,
1484 bool useBGR) { 1482 bool useBGR) {
1485 TextBatch* batch = new TextBatch; 1483 TextBatch* batch = new TextBatch;
1486 batch->initClassID<TextBatch>(); 1484 batch->initClassID<TextBatch>();
1487 batch->fFontCache = fontCache; 1485 batch->fFontCache = fontCache;
1488 batch->fMaskType = isLCD ? kLCDDistanceField_MaskType : kGrayscaleDistan ceField_MaskType; 1486 batch->fMaskType = isLCD ? kLCDDistanceField_MaskType : kGrayscaleDistan ceField_MaskType;
1489 batch->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); 1487 batch->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable));
1490 batch->fFilteredColor = filteredColor; 1488 batch->fFilteredColor = filteredColor;
1491 batch->fUseBGR = useBGR; 1489 batch->fUseBGR = useBGR;
1492 batch->fBatch.fNumGlyphs = glyphCount; 1490 batch->fBatch.fNumGlyphs = glyphCount;
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
2047 } fMaskType; 2045 } fMaskType;
2048 bool fUseBGR; // fold this into the enum? 2046 bool fUseBGR; // fold this into the enum?
2049 2047
2050 GrBatchFontCache* fFontCache; 2048 GrBatchFontCache* fFontCache;
2051 2049
2052 // Distance field properties 2050 // Distance field properties
2053 SkAutoTUnref<const DistanceAdjustTable> fDistanceAdjustTable; 2051 SkAutoTUnref<const DistanceAdjustTable> fDistanceAdjustTable;
2054 SkColor fFilteredColor; 2052 SkColor fFilteredColor;
2055 }; 2053 };
2056 2054
2057 void GrAtlasTextContext::flushRunAsPaths(GrRenderTarget* rt, const SkTextBlob::R unIterator& it, 2055 void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc, GrRenderTarget* rt,
2056 const SkTextBlob::RunIterator& it,
2058 const GrClip& clip, const SkPaint& skPa int, 2057 const GrClip& clip, const SkPaint& skPa int,
2059 SkDrawFilter* drawFilter, const SkMatri x& viewMatrix, 2058 SkDrawFilter* drawFilter, const SkMatri x& viewMatrix,
2060 const SkIRect& clipBounds, SkScalar x, SkScalar y) { 2059 const SkIRect& clipBounds, SkScalar x, SkScalar y) {
2061 SkPaint runPaint = skPaint; 2060 SkPaint runPaint = skPaint;
2062 2061
2063 size_t textLen = it.glyphCount() * sizeof(uint16_t); 2062 size_t textLen = it.glyphCount() * sizeof(uint16_t);
2064 const SkPoint& offset = it.offset(); 2063 const SkPoint& offset = it.offset();
2065 2064
2066 it.applyFontToPaint(&runPaint); 2065 it.applyFontToPaint(&runPaint);
2067 2066
2068 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) { 2067 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) {
2069 return; 2068 return;
2070 } 2069 }
2071 2070
2072 runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint)); 2071 runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint));
2073 2072
2074 switch (it.positioning()) { 2073 switch (it.positioning()) {
2075 case SkTextBlob::kDefault_Positioning: 2074 case SkTextBlob::kDefault_Positioning:
2076 this->drawTextAsPath(rt, clip, runPaint, viewMatrix, 2075 this->drawTextAsPath(dc, rt, clip, runPaint, viewMatrix,
2077 (const char *)it.glyphs(), 2076 (const char *)it.glyphs(),
2078 textLen, x + offset.x(), y + offset.y(), clipBo unds); 2077 textLen, x + offset.x(), y + offset.y(), clipBo unds);
2079 break; 2078 break;
2080 case SkTextBlob::kHorizontal_Positioning: 2079 case SkTextBlob::kHorizontal_Positioning:
2081 this->drawPosTextAsPath(rt, clip, runPaint, viewMatrix, 2080 this->drawPosTextAsPath(dc, rt, clip, runPaint, viewMatrix,
2082 (const char*)it.glyphs(), 2081 (const char*)it.glyphs(),
2083 textLen, it.pos(), 1, SkPoint::Make(x, y + o ffset.y()), 2082 textLen, it.pos(), 1, SkPoint::Make(x, y + o ffset.y()),
2084 clipBounds); 2083 clipBounds);
2085 break; 2084 break;
2086 case SkTextBlob::kFull_Positioning: 2085 case SkTextBlob::kFull_Positioning:
2087 this->drawPosTextAsPath(rt, clip, runPaint, viewMatrix, 2086 this->drawPosTextAsPath(dc, rt, clip, runPaint, viewMatrix,
2088 (const char*)it.glyphs(), 2087 (const char*)it.glyphs(),
2089 textLen, it.pos(), 2, SkPoint::Make(x, y), c lipBounds); 2088 textLen, it.pos(), 2, SkPoint::Make(x, y), c lipBounds);
2090 break; 2089 break;
2091 } 2090 }
2092 } 2091 }
2093 2092
2094 inline GrDrawBatch* 2093 inline GrDrawBatch*
2095 GrAtlasTextContext::createBatch(GrAtlasTextBlob* cacheBlob, const PerSubRunInfo& info, 2094 GrAtlasTextContext::createBatch(GrAtlasTextBlob* cacheBlob, const PerSubRunInfo& info,
2096 int glyphCount, int run, int subRun, 2095 int glyphCount, int run, int subRun,
2097 GrColor color, SkScalar transX, SkScalar transY, 2096 GrColor color, SkScalar transX, SkScalar transY,
(...skipping 28 matching lines...) Expand all
2126 geometry.fRun = run; 2125 geometry.fRun = run;
2127 geometry.fSubRun = subRun; 2126 geometry.fSubRun = subRun;
2128 geometry.fColor = subRunColor; 2127 geometry.fColor = subRunColor;
2129 geometry.fTransX = transX; 2128 geometry.fTransX = transX;
2130 geometry.fTransY = transY; 2129 geometry.fTransY = transY;
2131 batch->init(); 2130 batch->init();
2132 2131
2133 return batch; 2132 return batch;
2134 } 2133 }
2135 2134
2136 inline void GrAtlasTextContext::flushRun(GrPipelineBuilder* pipelineBuilder, 2135 inline void GrAtlasTextContext::flushRun(GrDrawContext* dc, GrPipelineBuilder* p ipelineBuilder,
2137 GrAtlasTextBlob* cacheBlob, int run, Gr Color color, 2136 GrAtlasTextBlob* cacheBlob, int run, Gr Color color,
2138 SkScalar transX, SkScalar transY, 2137 SkScalar transX, SkScalar transY,
2139 const SkPaint& skPaint) { 2138 const SkPaint& skPaint) {
2140 for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); sub Run++) { 2139 for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); sub Run++) {
2141 const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun]; 2140 const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun];
2142 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; 2141 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex;
2143 if (0 == glyphCount) { 2142 if (0 == glyphCount) {
2144 continue; 2143 continue;
2145 } 2144 }
2146 2145
2147 SkAutoTUnref<GrDrawBatch> batch(this->createBatch(cacheBlob, info, glyph Count, run, 2146 SkAutoTUnref<GrDrawBatch> batch(this->createBatch(cacheBlob, info, glyph Count, run,
2148 subRun, color, transX, transY, 2147 subRun, color, transX, transY,
2149 skPaint)); 2148 skPaint));
2150 fDrawContext->drawBatch(pipelineBuilder, batch); 2149 dc->drawBatch(pipelineBuilder, batch);
2151 } 2150 }
2152 } 2151 }
2153 2152
2154 inline void GrAtlasTextContext::flushBigGlyphs(GrAtlasTextBlob* cacheBlob, GrRen derTarget* rt, 2153 inline void GrAtlasTextContext::flushBigGlyphs(GrAtlasTextBlob* cacheBlob,
2154 GrDrawContext* dc, GrRenderTarget * rt,
2155 const GrClip& clip, const SkPaint & skPaint, 2155 const GrClip& clip, const SkPaint & skPaint,
2156 SkScalar transX, SkScalar transY, 2156 SkScalar transX, SkScalar transY,
2157 const SkIRect& clipBounds) { 2157 const SkIRect& clipBounds) {
2158 if (!cacheBlob->fBigGlyphs.count()) { 2158 if (!cacheBlob->fBigGlyphs.count()) {
2159 return; 2159 return;
2160 } 2160 }
2161 2161
2162 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { 2162 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) {
2163 GrAtlasTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; 2163 GrAtlasTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i];
2164 bigGlyph.fVx += transX; 2164 bigGlyph.fVx += transX;
2165 bigGlyph.fVy += transY; 2165 bigGlyph.fVy += transY;
2166 SkMatrix ctm; 2166 SkMatrix ctm;
2167 ctm.setScale(bigGlyph.fScale, bigGlyph.fScale); 2167 ctm.setScale(bigGlyph.fScale, bigGlyph.fScale);
2168 ctm.postTranslate(bigGlyph.fVx, bigGlyph.fVy); 2168 ctm.postTranslate(bigGlyph.fVx, bigGlyph.fVy);
2169 if (bigGlyph.fApplyVM) { 2169 if (bigGlyph.fApplyVM) {
2170 ctm.postConcat(cacheBlob->fViewMatrix); 2170 ctm.postConcat(cacheBlob->fViewMatrix);
2171 } 2171 }
2172 2172
2173 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, rt, clip, bi gGlyph.fPath, 2173 GrBlurUtils::drawPathWithMaskFilter(fContext, dc, rt, clip, bigGlyph.fPa th,
2174 skPaint, ctm, nullptr, clipBounds, f alse); 2174 skPaint, ctm, nullptr, clipBounds, f alse);
2175 } 2175 }
2176 } 2176 }
2177 2177
2178 void GrAtlasTextContext::flush(const SkTextBlob* blob, 2178 void GrAtlasTextContext::flush(const SkTextBlob* blob,
2179 GrAtlasTextBlob* cacheBlob, 2179 GrAtlasTextBlob* cacheBlob,
2180 GrDrawContext* dc,
2180 GrRenderTarget* rt, 2181 GrRenderTarget* rt,
2181 const SkPaint& skPaint, 2182 const SkPaint& skPaint,
2182 const GrPaint& grPaint, 2183 const GrPaint& grPaint,
2183 SkDrawFilter* drawFilter, 2184 SkDrawFilter* drawFilter,
2184 const GrClip& clip, 2185 const GrClip& clip,
2185 const SkMatrix& viewMatrix, 2186 const SkMatrix& viewMatrix,
2186 const SkIRect& clipBounds, 2187 const SkIRect& clipBounds,
2187 SkScalar x, SkScalar y, 2188 SkScalar x, SkScalar y,
2188 SkScalar transX, SkScalar transY) { 2189 SkScalar transX, SkScalar transY) {
2189 // We loop through the runs of the blob, flushing each. If any run is too l arge, then we flush 2190 // We loop through the runs of the blob, flushing each. If any run is too l arge, then we flush
2190 // it as paths 2191 // it as paths
2191 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); 2192 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip);
2192 2193
2193 GrColor color = grPaint.getColor(); 2194 GrColor color = grPaint.getColor();
2194 2195
2195 SkTextBlob::RunIterator it(blob); 2196 SkTextBlob::RunIterator it(blob);
2196 for (int run = 0; !it.done(); it.next(), run++) { 2197 for (int run = 0; !it.done(); it.next(), run++) {
2197 if (cacheBlob->fRuns[run].fDrawAsPaths) { 2198 if (cacheBlob->fRuns[run].fDrawAsPaths) {
2198 this->flushRunAsPaths(rt, it, clip, skPaint, 2199 this->flushRunAsPaths(dc, rt, it, clip, skPaint,
2199 drawFilter, viewMatrix, clipBounds, x, y); 2200 drawFilter, viewMatrix, clipBounds, x, y);
2200 continue; 2201 continue;
2201 } 2202 }
2202 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY); 2203 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY);
2203 this->flushRun(&pipelineBuilder, cacheBlob, run, color, 2204 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color,
2204 transX, transY, skPaint); 2205 transX, transY, skPaint);
2205 } 2206 }
2206 2207
2207 // Now flush big glyphs 2208 // Now flush big glyphs
2208 this->flushBigGlyphs(cacheBlob, rt, clip, skPaint, transX, transY, clipBound s); 2209 this->flushBigGlyphs(cacheBlob, dc, rt, clip, skPaint, transX, transY, clipB ounds);
2209 } 2210 }
2210 2211
2211 void GrAtlasTextContext::flush(GrAtlasTextBlob* cacheBlob, 2212 void GrAtlasTextContext::flush(GrAtlasTextBlob* cacheBlob,
2213 GrDrawContext* dc,
2212 GrRenderTarget* rt, 2214 GrRenderTarget* rt,
2213 const SkPaint& skPaint, 2215 const SkPaint& skPaint,
2214 const GrPaint& grPaint, 2216 const GrPaint& grPaint,
2215 const GrClip& clip, 2217 const GrClip& clip,
2216 const SkIRect& clipBounds) { 2218 const SkIRect& clipBounds) {
2217 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); 2219 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip);
2218 2220
2219 GrColor color = grPaint.getColor(); 2221 GrColor color = grPaint.getColor();
2220 for (int run = 0; run < cacheBlob->fRunCount; run++) { 2222 for (int run = 0; run < cacheBlob->fRunCount; run++) {
2221 this->flushRun(&pipelineBuilder, cacheBlob, run, color, 0, 0, skPaint); 2223 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color, 0, 0, skPain t);
2222 } 2224 }
2223 2225
2224 // Now flush big glyphs 2226 // Now flush big glyphs
2225 this->flushBigGlyphs(cacheBlob, rt, clip, skPaint, 0, 0, clipBounds); 2227 this->flushBigGlyphs(cacheBlob, dc, rt, clip, skPaint, 0, 0, clipBounds);
2226 } 2228 }
2227 2229
2228 //////////////////////////////////////////////////////////////////////////////// /////////////////// 2230 //////////////////////////////////////////////////////////////////////////////// ///////////////////
2229 2231
2230 #ifdef GR_TEST_UTILS 2232 #ifdef GR_TEST_UTILS
2231 2233
2232 DRAW_BATCH_TEST_DEFINE(TextBlobBatch) { 2234 DRAW_BATCH_TEST_DEFINE(TextBlobBatch) {
2233 static uint32_t gContextID = SK_InvalidGenID; 2235 static uint32_t gContextID = SK_InvalidGenID;
2234 static GrAtlasTextContext* gTextContext = nullptr; 2236 static GrAtlasTextContext* gTextContext = nullptr;
2235 static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType ); 2237 static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType );
2236 2238
2237 if (context->uniqueID() != gContextID) { 2239 if (context->uniqueID() != gContextID) {
2238 gContextID = context->uniqueID(); 2240 gContextID = context->uniqueID();
2239 delete gTextContext; 2241 delete gTextContext;
2240 2242
2241 // We don't yet test the fall back to paths in the GrTextContext base cl ass. This is mostly 2243 // We don't yet test the fall back to paths in the GrTextContext base cl ass. This is mostly
2242 // because we don't really want to have a gpu device here. 2244 // because we don't really want to have a gpu device here.
2243 // We enable distance fields by twiddling a knob on the paint 2245 // We enable distance fields by twiddling a knob on the paint
2244 GrDrawContext* drawContext = context->drawContext(&gSurfaceProps); 2246 gTextContext = GrAtlasTextContext::Create(context, gSurfaceProps);
2245
2246 gTextContext = GrAtlasTextContext::Create(context, drawContext, gSurface Props);
2247 } 2247 }
2248 2248
2249 // create dummy render target 2249 // create dummy render target
2250 GrSurfaceDesc desc; 2250 GrSurfaceDesc desc;
2251 desc.fFlags = kRenderTarget_GrSurfaceFlag; 2251 desc.fFlags = kRenderTarget_GrSurfaceFlag;
2252 desc.fWidth = 1024; 2252 desc.fWidth = 1024;
2253 desc.fHeight = 1024; 2253 desc.fHeight = 1024;
2254 desc.fConfig = kRGBA_8888_GrPixelConfig; 2254 desc.fConfig = kRGBA_8888_GrPixelConfig;
2255 desc.fSampleCnt = 0; 2255 desc.fSampleCnt = 0;
2256 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de sc, true, nullptr, 0)); 2256 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de sc, true, nullptr, 0));
(...skipping 28 matching lines...) Expand all
2285 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat rix, text, 2285 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat rix, text,
2286 static_cast<size_t>(textLen), 0, 0, noClip)); 2286 static_cast<size_t>(textLen), 0, 0, noClip));
2287 2287
2288 SkScalar transX = static_cast<SkScalar>(random->nextU()); 2288 SkScalar transX = static_cast<SkScalar>(random->nextU());
2289 SkScalar transY = static_cast<SkScalar>(random->nextU()); 2289 SkScalar transY = static_cast<SkScalar>(random->nextU());
2290 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0] ; 2290 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0] ;
2291 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint); 2291 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint);
2292 } 2292 }
2293 2293
2294 #endif 2294 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | src/gpu/GrDrawContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698