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

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

Issue 1175553002: Make GrTextContext be owned by the GrDrawContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Added more dox Created 5 years, 6 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
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 "GrBatch.h" 9 #include "GrBatch.h"
10 #include "GrBatchFontCache.h" 10 #include "GrBatchFontCache.h"
11 #include "GrBatchTarget.h" 11 #include "GrBatchTarget.h"
12 #include "GrBatchTest.h" 12 #include "GrBatchTest.h"
13 #include "GrBlurUtils.h" 13 #include "GrBlurUtils.h"
14 #include "GrDefaultGeoProcFactory.h" 14 #include "GrDefaultGeoProcFactory.h"
15 #include "GrDrawContext.h" 15 #include "GrDrawContext.h"
16 #include "GrDrawTarget.h"
16 #include "GrFontScaler.h" 17 #include "GrFontScaler.h"
17 #include "GrIndexBuffer.h" 18 #include "GrIndexBuffer.h"
18 #include "GrResourceProvider.h" 19 #include "GrResourceProvider.h"
19 #include "GrStrokeInfo.h" 20 #include "GrStrokeInfo.h"
20 #include "GrTextBlobCache.h" 21 #include "GrTextBlobCache.h"
21 #include "GrTexturePriv.h" 22 #include "GrTexturePriv.h"
22 #include "GrVertexBuffer.h" 23 #include "GrVertexBuffer.h"
23 24
24 #include "SkAutoKern.h" 25 #include "SkAutoKern.h"
25 #include "SkColorPriv.h" 26 #include "SkColorPriv.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 unsigned b = SkColorGetB(c); 89 unsigned b = SkColorGetB(c);
89 return GrColorPackRGBA(r, g, b, 0xff); 90 return GrColorPackRGBA(r, g, b, 0xff);
90 } 91 }
91 92
92 }; 93 };
93 94
94 // TODO 95 // TODO
95 // Distance field text in textblobs 96 // Distance field text in textblobs
96 97
97 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, 98 GrAtlasTextContext::GrAtlasTextContext(GrContext* context,
99 GrDrawContext* drawContext,
98 const SkDeviceProperties& properties, 100 const SkDeviceProperties& properties,
99 bool enableDistanceFields) 101 bool useDFT)
100 : INHERITED(context, properties) 102 : INHERITED(context, drawContext, properties, useDFT)
101 , fDistanceAdjustTable(SkNEW_ARGS(DistanceAdjustTable, (properties.gamma())) ) { 103 , fDistanceAdjustTable(SkNEW_ARGS(DistanceAdjustTable, (properties.gamma())) ) {
102 // We overallocate vertices in our textblobs based on the assumption that A8 has the greatest 104 // We overallocate vertices in our textblobs based on the assumption that A8 has the greatest
103 // vertexStride 105 // vertexStride
104 SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >= kLCDTextVASize, 106 SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >= kLCDTextVASize,
105 vertex_attribute_changed); 107 vertex_attribute_changed);
106 fCurrStrike = NULL; 108 fCurrStrike = NULL;
107 fCache = context->getTextBlobCache(); 109 fCache = context->getTextBlobCache();
108 110
109 #if SK_FORCE_DISTANCE_FIELD_TEXT 111 #if SK_FORCE_DISTANCE_FIELD_TEXT
110 fEnableDFRendering = true; 112 fEnableDFRendering = true;
111 #else 113 #else
112 fEnableDFRendering = enableDistanceFields; 114 fEnableDFRendering = useDFT;
113 #endif 115 #endif
114 } 116 }
115 117
116 void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable(float gam ma) { 118 void GrAtlasTextContext::DistanceAdjustTable::buildDistanceAdjustTable(float gam ma) {
117 119
118 // This is used for an approximation of the mask gamma hack, used by raster and bitmap 120 // This is used for an approximation of the mask gamma hack, used by raster and bitmap
119 // text. The mask gamma hack is based off of guessing what the blend color i s going to 121 // text. The mask gamma hack is based off of guessing what the blend color i s going to
120 // be, and adjusting the mask so that when run through the linear blend will 122 // be, and adjusting the mask so that when run through the linear blend will
121 // produce the value closest to the desired result. However, in practice thi s means 123 // produce the value closest to the desired result. However, in practice thi s means
122 // that the 'adjusted' mask is just increasing or decreasing the coverage of 124 // that the 'adjusted' mask is just increasing or decreasing the coverage of
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 float d = 2.0f*kDistanceFieldAAFactor*t - kDistanceFieldAAFactor ; 191 float d = 2.0f*kDistanceFieldAAFactor*t - kDistanceFieldAAFactor ;
190 192
191 fTable[row] = d; 193 fTable[row] = d;
192 break; 194 break;
193 } 195 }
194 } 196 }
195 } 197 }
196 } 198 }
197 199
198 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context, 200 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context,
201 GrDrawContext* drawContext,
199 const SkDeviceProperties& props, 202 const SkDeviceProperties& props,
200 bool enableDistanceFields) { 203 bool useDFT) {
201 return SkNEW_ARGS(GrAtlasTextContext, (context, props, enableDistanceFields) ); 204 return SkNEW_ARGS(GrAtlasTextContext, (context, drawContext, props, useDFT)) ;
202 } 205 }
203 206
204 bool GrAtlasTextContext::canDraw(const GrRenderTarget*, 207 bool GrAtlasTextContext::canDraw(const GrRenderTarget*,
205 const GrClip&, 208 const GrClip&,
206 const GrPaint&, 209 const GrPaint&,
207 const SkPaint& skPaint, 210 const SkPaint& skPaint,
208 const SkMatrix& viewMatrix) { 211 const SkMatrix& viewMatrix) {
209 return this->canDrawAsDistanceFields(skPaint, viewMatrix) || 212 return this->canDrawAsDistanceFields(skPaint, viewMatrix) ||
210 !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); 213 !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix);
211 } 214 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt, 350 void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt,
348 const GrClip& clip, const SkPaint& skPaint , 351 const GrClip& clip, const SkPaint& skPaint ,
349 const SkMatrix& viewMatrix, const SkTextBl ob* blob, 352 const SkMatrix& viewMatrix, const SkTextBl ob* blob,
350 SkScalar x, SkScalar y, 353 SkScalar x, SkScalar y,
351 SkDrawFilter* drawFilter, const SkIRect& c lipBounds) { 354 SkDrawFilter* drawFilter, const SkIRect& c lipBounds) {
352 // If we have been abandoned, then don't draw 355 // If we have been abandoned, then don't draw
353 if (fContext->abandoned()) { 356 if (fContext->abandoned()) {
354 return; 357 return;
355 } 358 }
356 359
357 GrDrawContext* drawContext = fContext->drawContext();
358 if (!drawContext) {
359 return;
360 }
361
362 SkAutoTUnref<BitmapTextBlob> cacheBlob; 360 SkAutoTUnref<BitmapTextBlob> cacheBlob;
363 SkMaskFilter::BlurRec blurRec; 361 SkMaskFilter::BlurRec blurRec;
364 BitmapTextBlob::Key key; 362 BitmapTextBlob::Key key;
365 // It might be worth caching these things, but its not clear at this time 363 // It might be worth caching these things, but its not clear at this time
366 // TODO for animated mask filters, this will fill up our cache. We need a s afeguard here 364 // TODO for animated mask filters, this will fill up our cache. We need a s afeguard here
367 const SkMaskFilter* mf = skPaint.getMaskFilter(); 365 const SkMaskFilter* mf = skPaint.getMaskFilter();
368 bool canCache = !(skPaint.getPathEffect() || 366 bool canCache = !(skPaint.getPathEffect() ||
369 (mf && !mf->asABlur(&blurRec)) || 367 (mf && !mf->asABlur(&blurRec)) ||
370 drawFilter); 368 drawFilter);
371 369
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s kPaint, 424 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s kPaint,
427 kGrayTextVASize))); 425 kGrayTextVASize)));
428 } else { 426 } else {
429 cacheBlob.reset(fCache->createBlob(blob, kGrayTextVASize)); 427 cacheBlob.reset(fCache->createBlob(blob, kGrayTextVASize));
430 } 428 }
431 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMat rix, 429 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMat rix,
432 blob, x, y, drawFilter, clipRect, rt, clip, grP aint); 430 blob, x, y, drawFilter, clipRect, rt, clip, grP aint);
433 } 431 }
434 432
435 cacheBlob->fPaintColor = skPaint.getColor(); 433 cacheBlob->fPaintColor = skPaint.getColor();
436 this->flush(drawContext, blob, cacheBlob, rt, skPaint, grPaint, drawFilter, 434 this->flush(blob, cacheBlob, rt, skPaint, grPaint, drawFilter,
437 clip, viewMatrix, clipBounds, x, y, transX, transY); 435 clip, viewMatrix, clipBounds, x, y, transX, transY);
438 } 436 }
439 437
440 inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, 438 inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint,
441 const SkMatrix& viewMatr ix) { 439 const SkMatrix& viewMatr ix) {
442 // TODO: support perspective (need getMaxScale replacement) 440 // TODO: support perspective (need getMaxScale replacement)
443 if (viewMatrix.hasPerspective()) { 441 if (viewMatrix.hasPerspective()) {
444 return false; 442 return false;
445 } 443 }
446 444
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); 766 blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize);
769 blob->fViewMatrix = viewMatrix; 767 blob->fViewMatrix = viewMatrix;
770 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false); 768 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false);
771 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text, 769 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text,
772 byteLength, pos, scalarsPerPosition, offset , clipRect); 770 byteLength, pos, scalarsPerPosition, offset , clipRect);
773 SkGlyphCache::AttachCache(cache); 771 SkGlyphCache::AttachCache(cache);
774 } 772 }
775 return blob; 773 return blob;
776 } 774 }
777 775
778 void GrAtlasTextContext::onDrawText(GrDrawContext* drawContext, GrRenderTarget* rt, 776 void GrAtlasTextContext::onDrawText(GrRenderTarget* rt,
779 const GrClip& clip, 777 const GrClip& clip,
780 const GrPaint& paint, const SkPaint& skPaint , 778 const GrPaint& paint, const SkPaint& skPaint ,
781 const SkMatrix& viewMatrix, 779 const SkMatrix& viewMatrix,
782 const char text[], size_t byteLength, 780 const char text[], size_t byteLength,
783 SkScalar x, SkScalar y, const SkIRect& regio nClipBounds) { 781 SkScalar x, SkScalar y, const SkIRect& regio nClipBounds) {
784 if (drawContext) { 782 SkAutoTUnref<BitmapTextBlob> blob(
785 SkAutoTUnref<BitmapTextBlob> blob( 783 this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix,
786 this->createDrawTextBlob(rt, clip, paint, skPaint, viewMatrix, 784 text, byteLength, x, y, regionClipBounds));
787 text, byteLength, x, y, regionClipBounds)); 785 this->flush(blob, rt, skPaint, paint, clip, regionClipBounds);
788 this->flush(drawContext, blob, rt, skPaint, paint, clip, regionClipBound s);
789 }
790 } 786 }
791 787
792 void GrAtlasTextContext::onDrawPosText(GrDrawContext* drawContext, GrRenderTarge t* rt, 788 void GrAtlasTextContext::onDrawPosText(GrRenderTarget* rt,
793 const GrClip& clip, 789 const GrClip& clip,
794 const GrPaint& paint, const SkPaint& skPa int, 790 const GrPaint& paint, const SkPaint& skPa int,
795 const SkMatrix& viewMatrix, 791 const SkMatrix& viewMatrix,
796 const char text[], size_t byteLength, 792 const char text[], size_t byteLength,
797 const SkScalar pos[], int scalarsPerPosit ion, 793 const SkScalar pos[], int scalarsPerPosit ion,
798 const SkPoint& offset, const SkIRect& reg ionClipBounds) { 794 const SkPoint& offset, const SkIRect& reg ionClipBounds) {
799 if (drawContext) { 795 SkAutoTUnref<BitmapTextBlob> blob(
800 SkAutoTUnref<BitmapTextBlob> blob( 796 this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix,
801 this->createDrawPosTextBlob(rt, clip, paint, skPaint, viewMatrix, 797 text, byteLength,
802 text, byteLength, 798 pos, scalarsPerPosition,
803 pos, scalarsPerPosition, 799 offset, regionClipBounds));
804 offset, regionClipBounds));
805 800
806 this->flush(drawContext, blob, rt, skPaint, paint, clip, regionClipBound s); 801 this->flush(blob, rt, skPaint, paint, clip, regionClipBounds);
807 }
808 } 802 }
809 803
810 void GrAtlasTextContext::internalDrawBMPText(BitmapTextBlob* blob, int runIndex, 804 void GrAtlasTextContext::internalDrawBMPText(BitmapTextBlob* blob, int runIndex,
811 SkGlyphCache* cache, const SkPaint& skPaint, 805 SkGlyphCache* cache, const SkPaint& skPaint,
812 GrColor color, 806 GrColor color,
813 const SkMatrix& viewMatrix, 807 const SkMatrix& viewMatrix,
814 const char text[], size_t byteLengt h, 808 const char text[], size_t byteLengt h,
815 SkScalar x, SkScalar y, const SkIRe ct& clipRect) { 809 SkScalar x, SkScalar y, const SkIRe ct& clipRect) {
816 SkASSERT(byteLength == 0 || text != NULL); 810 SkASSERT(byteLength == 0 || text != NULL);
817 811
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2036 2030
2037 // Distance field properties 2031 // Distance field properties
2038 SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable; 2032 SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable;
2039 SkColor fFilteredColor; 2033 SkColor fFilteredColor;
2040 bool fUseDistanceFields; 2034 bool fUseDistanceFields;
2041 bool fUseLCDText; 2035 bool fUseLCDText;
2042 bool fUseBGR; 2036 bool fUseBGR;
2043 float fGamma; 2037 float fGamma;
2044 }; 2038 };
2045 2039
2046 void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* drawContext, 2040 void GrAtlasTextContext::flushRunAsPaths(GrRenderTarget* rt, const SkTextBlob::R unIterator& it,
2047 GrRenderTarget* rt, const SkTextBlob::R unIterator& it,
2048 const GrClip& clip, const SkPaint& skPa int, 2041 const GrClip& clip, const SkPaint& skPa int,
2049 SkDrawFilter* drawFilter, const SkMatri x& viewMatrix, 2042 SkDrawFilter* drawFilter, const SkMatri x& viewMatrix,
2050 const SkIRect& clipBounds, SkScalar x, SkScalar y) { 2043 const SkIRect& clipBounds, SkScalar x, SkScalar y) {
2051 SkPaint runPaint = skPaint; 2044 SkPaint runPaint = skPaint;
2052 2045
2053 size_t textLen = it.glyphCount() * sizeof(uint16_t); 2046 size_t textLen = it.glyphCount() * sizeof(uint16_t);
2054 const SkPoint& offset = it.offset(); 2047 const SkPoint& offset = it.offset();
2055 2048
2056 it.applyFontToPaint(&runPaint); 2049 it.applyFontToPaint(&runPaint);
2057 2050
2058 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) { 2051 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) {
2059 return; 2052 return;
2060 } 2053 }
2061 2054
2062 runPaint.setFlags(FilterTextFlags(fDeviceProperties, runPaint)); 2055 runPaint.setFlags(FilterTextFlags(fDeviceProperties, runPaint));
2063 2056
2064 switch (it.positioning()) { 2057 switch (it.positioning()) {
2065 case SkTextBlob::kDefault_Positioning: 2058 case SkTextBlob::kDefault_Positioning:
2066 this->drawTextAsPath(drawContext, rt, clip, runPaint, viewMatrix, 2059 this->drawTextAsPath(rt, clip, runPaint, viewMatrix,
2067 (const char *)it.glyphs(), 2060 (const char *)it.glyphs(),
2068 textLen, x + offset.x(), y + offset.y(), clipBo unds); 2061 textLen, x + offset.x(), y + offset.y(), clipBo unds);
2069 break; 2062 break;
2070 case SkTextBlob::kHorizontal_Positioning: 2063 case SkTextBlob::kHorizontal_Positioning:
2071 this->drawPosTextAsPath(drawContext, rt, clip, runPaint, viewMatrix, 2064 this->drawPosTextAsPath(rt, clip, runPaint, viewMatrix,
2072 (const char*)it.glyphs(), 2065 (const char*)it.glyphs(),
2073 textLen, it.pos(), 1, SkPoint::Make(x, y + o ffset.y()), 2066 textLen, it.pos(), 1, SkPoint::Make(x, y + o ffset.y()),
2074 clipBounds); 2067 clipBounds);
2075 break; 2068 break;
2076 case SkTextBlob::kFull_Positioning: 2069 case SkTextBlob::kFull_Positioning:
2077 this->drawPosTextAsPath(drawContext, rt, clip, runPaint, viewMatrix, 2070 this->drawPosTextAsPath(rt, clip, runPaint, viewMatrix,
2078 (const char*)it.glyphs(), 2071 (const char*)it.glyphs(),
2079 textLen, it.pos(), 2, SkPoint::Make(x, y), c lipBounds); 2072 textLen, it.pos(), 2, SkPoint::Make(x, y), c lipBounds);
2080 break; 2073 break;
2081 } 2074 }
2082 } 2075 }
2083 2076
2084 2077
2085 inline BitmapTextBatch* 2078 inline BitmapTextBatch*
2086 GrAtlasTextContext::createBatch(BitmapTextBlob* cacheBlob, const PerSubRunInfo& info, 2079 GrAtlasTextContext::createBatch(BitmapTextBlob* cacheBlob, const PerSubRunInfo& info,
2087 int glyphCount, int run, int subRun, 2080 int glyphCount, int run, int subRun,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 geometry.fRun = run; 2112 geometry.fRun = run;
2120 geometry.fSubRun = subRun; 2113 geometry.fSubRun = subRun;
2121 geometry.fColor = subRunColor; 2114 geometry.fColor = subRunColor;
2122 geometry.fTransX = transX; 2115 geometry.fTransX = transX;
2123 geometry.fTransY = transY; 2116 geometry.fTransY = transY;
2124 batch->init(); 2117 batch->init();
2125 2118
2126 return batch; 2119 return batch;
2127 } 2120 }
2128 2121
2129 inline void GrAtlasTextContext::flushRun(GrDrawContext* drawContext, 2122 inline void GrAtlasTextContext::flushRun(GrPipelineBuilder* pipelineBuilder,
2130 GrPipelineBuilder* pipelineBuilder,
2131 BitmapTextBlob* cacheBlob, int run, GrC olor color, 2123 BitmapTextBlob* cacheBlob, int run, GrC olor color,
2132 SkScalar transX, SkScalar transY, 2124 SkScalar transX, SkScalar transY,
2133 const SkPaint& skPaint) { 2125 const SkPaint& skPaint) {
2134 for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); sub Run++) { 2126 for (int subRun = 0; subRun < cacheBlob->fRuns[run].fSubRunInfo.count(); sub Run++) {
2135 const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun]; 2127 const PerSubRunInfo& info = cacheBlob->fRuns[run].fSubRunInfo[subRun];
2136 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; 2128 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex;
2137 if (0 == glyphCount) { 2129 if (0 == glyphCount) {
2138 continue; 2130 continue;
2139 } 2131 }
2140 2132
2141 SkAutoTUnref<BitmapTextBatch> batch(this->createBatch(cacheBlob, info, g lyphCount, run, 2133 SkAutoTUnref<BitmapTextBatch> batch(this->createBatch(cacheBlob, info, g lyphCount, run,
2142 subRun, color, tra nsX, transY, 2134 subRun, color, tra nsX, transY,
2143 skPaint)); 2135 skPaint));
2144 drawContext->drawText(pipelineBuilder, batch); 2136 fDrawContext->drawBatch(pipelineBuilder, batch);
2145 } 2137 }
2146 } 2138 }
2147 2139
2148 inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, 2140 inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRend erTarget* rt,
2149 GrDrawContext* drawContext, GrRen derTarget* rt,
2150 const GrClip& clip, const SkPaint & skPaint, 2141 const GrClip& clip, const SkPaint & skPaint,
2151 SkScalar transX, SkScalar transY, 2142 SkScalar transX, SkScalar transY,
2152 const SkIRect& clipBounds) { 2143 const SkIRect& clipBounds) {
2153 if (!cacheBlob->fBigGlyphs.count()) { 2144 if (!cacheBlob->fBigGlyphs.count()) {
2154 return; 2145 return;
2155 } 2146 }
2156 2147
2157 SkMatrix pathMatrix; 2148 SkMatrix pathMatrix;
2158 if (!cacheBlob->fViewMatrix.invert(&pathMatrix)) { 2149 if (!cacheBlob->fViewMatrix.invert(&pathMatrix)) {
2159 SkDebugf("could not invert viewmatrix\n"); 2150 SkDebugf("could not invert viewmatrix\n");
2160 return; 2151 return;
2161 } 2152 }
2162 2153
2163 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { 2154 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) {
2164 BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; 2155 BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i];
2165 bigGlyph.fVx += transX; 2156 bigGlyph.fVx += transX;
2166 bigGlyph.fVy += transY; 2157 bigGlyph.fVy += transY;
2167 SkMatrix translate = cacheBlob->fViewMatrix; 2158 SkMatrix translate = cacheBlob->fViewMatrix;
2168 translate.postTranslate(bigGlyph.fVx, bigGlyph.fVy); 2159 translate.postTranslate(bigGlyph.fVx, bigGlyph.fVy);
2169 2160
2170 GrBlurUtils::drawPathWithMaskFilter(fContext, drawContext, rt, clip, big Glyph.fPath, 2161 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, rt, clip, bi gGlyph.fPath,
2171 skPaint, translate, &pathMatrix, cli pBounds, false); 2162 skPaint, translate, &pathMatrix, cli pBounds, false);
2172 } 2163 }
2173 } 2164 }
2174 2165
2175 void GrAtlasTextContext::flush(GrDrawContext* drawContext, 2166 void GrAtlasTextContext::flush(const SkTextBlob* blob,
2176 const SkTextBlob* blob,
2177 BitmapTextBlob* cacheBlob, 2167 BitmapTextBlob* cacheBlob,
2178 GrRenderTarget* rt, 2168 GrRenderTarget* rt,
2179 const SkPaint& skPaint, 2169 const SkPaint& skPaint,
2180 const GrPaint& grPaint, 2170 const GrPaint& grPaint,
2181 SkDrawFilter* drawFilter, 2171 SkDrawFilter* drawFilter,
2182 const GrClip& clip, 2172 const GrClip& clip,
2183 const SkMatrix& viewMatrix, 2173 const SkMatrix& viewMatrix,
2184 const SkIRect& clipBounds, 2174 const SkIRect& clipBounds,
2185 SkScalar x, SkScalar y, 2175 SkScalar x, SkScalar y,
2186 SkScalar transX, SkScalar transY) { 2176 SkScalar transX, SkScalar transY) {
2187 // We loop through the runs of the blob, flushing each. If any run is too l arge, then we flush 2177 // We loop through the runs of the blob, flushing each. If any run is too l arge, then we flush
2188 // it as paths 2178 // it as paths
2189 GrPipelineBuilder pipelineBuilder; 2179 GrPipelineBuilder pipelineBuilder;
2190 pipelineBuilder.setFromPaint(grPaint, rt, clip); 2180 pipelineBuilder.setFromPaint(grPaint, rt, clip);
2191 2181
2192 GrColor color = grPaint.getColor(); 2182 GrColor color = grPaint.getColor();
2193 2183
2194 SkTextBlob::RunIterator it(blob); 2184 SkTextBlob::RunIterator it(blob);
2195 for (int run = 0; !it.done(); it.next(), run++) { 2185 for (int run = 0; !it.done(); it.next(), run++) {
2196 if (cacheBlob->fRuns[run].fDrawAsPaths) { 2186 if (cacheBlob->fRuns[run].fDrawAsPaths) {
2197 this->flushRunAsPaths(drawContext, rt, it, clip, skPaint, 2187 this->flushRunAsPaths(rt, it, clip, skPaint,
2198 drawFilter, viewMatrix, clipBounds, x, y); 2188 drawFilter, viewMatrix, clipBounds, x, y);
2199 continue; 2189 continue;
2200 } 2190 }
2201 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY); 2191 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY);
2202 this->flushRun(drawContext, &pipelineBuilder, cacheBlob, run, color, 2192 this->flushRun(&pipelineBuilder, cacheBlob, run, color,
2203 transX, transY, skPaint); 2193 transX, transY, skPaint);
2204 } 2194 }
2205 2195
2206 // Now flush big glyphs 2196 // Now flush big glyphs
2207 this->flushBigGlyphs(cacheBlob, drawContext, rt, clip, skPaint, transX, tran sY, clipBounds); 2197 this->flushBigGlyphs(cacheBlob, rt, clip, skPaint, transX, transY, clipBound s);
2208 } 2198 }
2209 2199
2210 void GrAtlasTextContext::flush(GrDrawContext* drawContext, 2200 void GrAtlasTextContext::flush(BitmapTextBlob* cacheBlob,
2211 BitmapTextBlob* cacheBlob,
2212 GrRenderTarget* rt, 2201 GrRenderTarget* rt,
2213 const SkPaint& skPaint, 2202 const SkPaint& skPaint,
2214 const GrPaint& grPaint, 2203 const GrPaint& grPaint,
2215 const GrClip& clip, 2204 const GrClip& clip,
2216 const SkIRect& clipBounds) { 2205 const SkIRect& clipBounds) {
2217 GrPipelineBuilder pipelineBuilder; 2206 GrPipelineBuilder pipelineBuilder;
2218 pipelineBuilder.setFromPaint(grPaint, rt, clip); 2207 pipelineBuilder.setFromPaint(grPaint, rt, clip);
2219 2208
2220 GrColor color = grPaint.getColor(); 2209 GrColor color = grPaint.getColor();
2221 for (int run = 0; run < cacheBlob->fRunCount; run++) { 2210 for (int run = 0; run < cacheBlob->fRunCount; run++) {
2222 this->flushRun(drawContext, &pipelineBuilder, cacheBlob, run, color, 0, 0, skPaint); 2211 this->flushRun(&pipelineBuilder, cacheBlob, run, color, 0, 0, skPaint);
2223 } 2212 }
2224 2213
2225 // Now flush big glyphs 2214 // Now flush big glyphs
2226 this->flushBigGlyphs(cacheBlob, drawContext, rt, clip, skPaint, 0, 0, clipBo unds); 2215 this->flushBigGlyphs(cacheBlob, rt, clip, skPaint, 0, 0, clipBounds);
2227 } 2216 }
2228 2217
2229 //////////////////////////////////////////////////////////////////////////////// /////////////////// 2218 //////////////////////////////////////////////////////////////////////////////// ///////////////////
2230 2219
2231 #ifdef GR_TEST_UTILS 2220 #ifdef GR_TEST_UTILS
2232 2221
2233 BATCH_TEST_DEFINE(TextBlobBatch) { 2222 BATCH_TEST_DEFINE(TextBlobBatch) {
2234 static uint32_t gContextID = SK_InvalidGenID; 2223 static uint32_t gContextID = SK_InvalidGenID;
2235 static GrAtlasTextContext* gTextContext = NULL; 2224 static GrAtlasTextContext* gTextContext = NULL;
2236 static SkDeviceProperties gDeviceProperties(SkDeviceProperties::kLegacyLCD_I nitType); 2225 static SkDeviceProperties gDevProperties;
2237 2226
2238 if (context->uniqueID() != gContextID) { 2227 if (context->uniqueID() != gContextID) {
2239 gContextID = context->uniqueID(); 2228 gContextID = context->uniqueID();
2240 SkDELETE(gTextContext); 2229 SkDELETE(gTextContext);
2230
2231 static const bool kUseDFT = false;
2241 // We don't yet test the fall back to paths in the GrTextContext base cl ass. This is mostly 2232 // 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. 2233 // because we don't really want to have a gpu device here.
2243 // We enable distance fields by twiddling a knob on the paint 2234 // We enable distance fields by twiddling a knob on the paint
2244 gTextContext = GrAtlasTextContext::Create(context, gDeviceProperties, fa lse); 2235 GrDrawContext* drawContext = context->drawContext(&gDevProperties, kUseD FT);
2236
2237 gTextContext = GrAtlasTextContext::Create(context, drawContext, gDevProp erties, kUseDFT);
2245 } 2238 }
2246 2239
2247 // create dummy render target 2240 // create dummy render target
2248 GrSurfaceDesc desc; 2241 GrSurfaceDesc desc;
2249 desc.fFlags = kRenderTarget_GrSurfaceFlag; 2242 desc.fFlags = kRenderTarget_GrSurfaceFlag;
2250 desc.fWidth = 1024; 2243 desc.fWidth = 1024;
2251 desc.fHeight = 1024; 2244 desc.fHeight = 1024;
2252 desc.fConfig = kRGBA_8888_GrPixelConfig; 2245 desc.fConfig = kRGBA_8888_GrPixelConfig;
2253 desc.fSampleCnt = 0; 2246 desc.fSampleCnt = 0;
2254 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de sc, true, NULL, 0)); 2247 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de sc, true, NULL, 0));
(...skipping 29 matching lines...) Expand all
2284 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat rix, text, 2277 gTextContext->createDrawTextBlob(rt, clip, grPaint, skPaint, viewMat rix, text,
2285 static_cast<size_t>(textLen), 0, 0, noClip)); 2278 static_cast<size_t>(textLen), 0, 0, noClip));
2286 2279
2287 SkScalar transX = static_cast<SkScalar>(random->nextU()); 2280 SkScalar transX = static_cast<SkScalar>(random->nextU());
2288 SkScalar transY = static_cast<SkScalar>(random->nextU()); 2281 SkScalar transY = static_cast<SkScalar>(random->nextU());
2289 const GrAtlasTextContext::BitmapTextBlob::Run::SubRunInfo& info = blob->fRun s[0].fSubRunInfo[0]; 2282 const GrAtlasTextContext::BitmapTextBlob::Run::SubRunInfo& info = blob->fRun s[0].fSubRunInfo[0];
2290 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint); 2283 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint);
2291 } 2284 }
2292 2285
2293 #endif 2286 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698