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

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

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