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

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

Powered by Google App Engine
This is Rietveld 408576698