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

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

Issue 1015173002: Let text contexts fall back directly to paths (Closed) Base URL: https://skia.googlesource.com/skia.git@text-blob-to-context
Patch Set: move createTextContext to private Created 5 years, 9 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/GrDistanceFieldTextContext.h ('k') | src/gpu/GrStencilAndCoverTextContext.h » ('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 2013 Google Inc. 2 * Copyright 2013 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 7
8 #include "GrDistanceFieldTextContext.h" 8 #include "GrDistanceFieldTextContext.h"
9 #include "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "GrBitmapTextContext.h" 10 #include "GrBitmapTextContext.h"
(...skipping 24 matching lines...) Expand all
35 static const int kSmallDFFontSize = 32; 35 static const int kSmallDFFontSize = 32;
36 static const int kSmallDFFontLimit = 32; 36 static const int kSmallDFFontLimit = 32;
37 static const int kMediumDFFontSize = 72; 37 static const int kMediumDFFontSize = 72;
38 static const int kMediumDFFontLimit = 72; 38 static const int kMediumDFFontLimit = 72;
39 static const int kLargeDFFontSize = 162; 39 static const int kLargeDFFontSize = 162;
40 40
41 static const int kVerticesPerGlyph = 4; 41 static const int kVerticesPerGlyph = 4;
42 static const int kIndicesPerGlyph = 6; 42 static const int kIndicesPerGlyph = 6;
43 43
44 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, 44 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
45 SkGpuDevice* gpuDevice,
45 const SkDeviceProperties& properties, 46 const SkDeviceProperties& properties,
46 bool enable) 47 bool enable)
47 : GrTextContext(context, pro perties) { 48 : GrTextContext(context, gpuDevice, properties) {
48 #if SK_FORCE_DISTANCE_FIELD_TEXT 49 #if SK_FORCE_DISTANCE_FIELD_TEXT
49 fEnableDFRendering = true; 50 fEnableDFRendering = true;
50 #else 51 #else
51 fEnableDFRendering = enable; 52 fEnableDFRendering = enable;
52 #endif 53 #endif
53 fStrike = NULL; 54 fStrike = NULL;
54 fGammaTexture = NULL; 55 fGammaTexture = NULL;
55 56
56 fEffectTextureUniqueID = SK_InvalidUniqueID; 57 fEffectTextureUniqueID = SK_InvalidUniqueID;
57 fEffectColor = GrColor_ILLEGAL; 58 fEffectColor = GrColor_ILLEGAL;
58 fEffectFlags = kInvalid_DistanceFieldEffectFlag; 59 fEffectFlags = kInvalid_DistanceFieldEffectFlag;
59 60
60 fVertices = NULL; 61 fVertices = NULL;
61 fCurrVertex = 0; 62 fCurrVertex = 0;
62 fAllocVertexCount = 0; 63 fAllocVertexCount = 0;
63 fTotalVertexCount = 0; 64 fTotalVertexCount = 0;
64 fCurrTexture = NULL; 65 fCurrTexture = NULL;
65 66
66 fVertexBounds.setLargestInverted(); 67 fVertexBounds.setLargestInverted();
67 } 68 }
68 69
69 GrDistanceFieldTextContext* GrDistanceFieldTextContext::Create(GrContext* contex t, 70 GrDistanceFieldTextContext* GrDistanceFieldTextContext::Create(GrContext* contex t,
71 SkGpuDevice* gpuD evice,
70 const SkDevicePro perties& props, 72 const SkDevicePro perties& props,
71 bool enable) { 73 bool enable) {
72 GrDistanceFieldTextContext* textContext = SkNEW_ARGS(GrDistanceFieldTextCont ext, 74 GrDistanceFieldTextContext* textContext = SkNEW_ARGS(GrDistanceFieldTextCont ext,
73 (context, props, enable )); 75 (context, gpuDevice, pr ops, enable));
74 textContext->fFallbackTextContext = GrBitmapTextContext::Create(context, pro ps); 76 textContext->fFallbackTextContext = GrBitmapTextContext::Create(context, gpu Device, props);
75 77
76 return textContext; 78 return textContext;
77 } 79 }
78 80
79 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { 81 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
80 SkSafeSetNull(fGammaTexture); 82 SkSafeSetNull(fGammaTexture);
81 } 83 }
82 84
83 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint, const SkMatrix& v iewMatrix) { 85 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint, const SkMatrix& v iewMatrix) {
84 // TODO: support perspective (need getMaxScale replacement) 86 // TODO: support perspective (need getMaxScale replacement)
(...skipping 22 matching lines...) Expand all
107 109
108 // TODO: add some stroking support 110 // TODO: add some stroking support
109 if (paint.getStyle() != SkPaint::kFill_Style) { 111 if (paint.getStyle() != SkPaint::kFill_Style) {
110 return false; 112 return false;
111 } 113 }
112 114
113 return true; 115 return true;
114 } 116 }
115 117
116 inline void GrDistanceFieldTextContext::init(GrRenderTarget* rt, const GrClip& c lip, 118 inline void GrDistanceFieldTextContext::init(GrRenderTarget* rt, const GrClip& c lip,
117 const GrPaint& paint, const SkPaint & skPaint) { 119 const GrPaint& paint, const SkPaint & skPaint,
118 GrTextContext::init(rt, clip, paint, skPaint); 120 const SkIRect& regionClipBounds) {
121 GrTextContext::init(rt, clip, paint, skPaint, regionClipBounds);
119 122
120 fStrike = NULL; 123 fStrike = NULL;
121 124
122 const SkMatrix& ctm = fViewMatrix; 125 const SkMatrix& ctm = fViewMatrix;
123 126
124 // getMaxScale doesn't support perspective, so neither do we at the moment 127 // getMaxScale doesn't support perspective, so neither do we at the moment
125 SkASSERT(!ctm.hasPerspective()); 128 SkASSERT(!ctm.hasPerspective());
126 SkScalar maxScale = ctm.getMaxScale(); 129 SkScalar maxScale = ctm.getMaxScale();
127 SkScalar textSize = fSkPaint.getTextSize(); 130 SkScalar textSize = fSkPaint.getTextSize();
128 SkScalar scaledTextSize = textSize; 131 SkScalar scaledTextSize = textSize;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 (*gammaTexture)->writePixels(0, 0, width, height, 208 (*gammaTexture)->writePixels(0, 0, width, height,
206 (*gammaTexture)->config(), data.get(), 0, 209 (*gammaTexture)->config(), data.get(), 0,
207 GrContext::kDontFlush_PixelOpsFlag); 210 GrContext::kDontFlush_PixelOpsFlag);
208 } 211 }
209 } 212 }
210 213
211 void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrClip& cl ip, 214 void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrClip& cl ip,
212 const GrPaint& paint, 215 const GrPaint& paint,
213 const SkPaint& skPaint, const SkMatr ix& viewMatrix, 216 const SkPaint& skPaint, const SkMatr ix& viewMatrix,
214 const char text[], size_t byteLength , 217 const char text[], size_t byteLength ,
215 SkScalar x, SkScalar y) { 218 SkScalar x, SkScalar y,
219 const SkIRect& regionClipBounds) {
216 SkASSERT(byteLength == 0 || text != NULL); 220 SkASSERT(byteLength == 0 || text != NULL);
217 221
218 // nothing to draw 222 // nothing to draw
219 if (text == NULL || byteLength == 0) { 223 if (text == NULL || byteLength == 0) {
220 return; 224 return;
221 } 225 }
222 226
223 fViewMatrix = viewMatrix; 227 fViewMatrix = viewMatrix;
224 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); 228 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc();
225 SkAutoGlyphCache autoCache(skPaint, &fDeviceProperties, NULL); 229 SkAutoGlyphCache autoCache(skPaint, &fDeviceProperties, NULL);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 alignX = SkScalarHalf(alignX); 267 alignX = SkScalarHalf(alignX);
264 alignY = SkScalarHalf(alignY); 268 alignY = SkScalarHalf(alignY);
265 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) { 269 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) {
266 alignX = 0; 270 alignX = 0;
267 alignY = 0; 271 alignY = 0;
268 } 272 }
269 x -= alignX; 273 x -= alignX;
270 y -= alignY; 274 y -= alignY;
271 SkPoint offset = SkPoint::Make(x, y); 275 SkPoint offset = SkPoint::Make(x, y);
272 276
273 this->drawPosText(rt, clip, paint, skPaint, viewMatrix, text, byteLength, po sitions.begin(), 2, 277 this->onDrawPosText(rt, clip, paint, skPaint, viewMatrix, text, byteLength, positions.begin(),
274 offset); 278 2, offset, regionClipBounds);
275 } 279 }
276 280
277 void GrDistanceFieldTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip, 281 void GrDistanceFieldTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip,
278 const GrPaint& paint, 282 const GrPaint& paint,
279 const SkPaint& skPaint, const SkM atrix& viewMatrix, 283 const SkPaint& skPaint, const SkM atrix& viewMatrix,
280 const char text[], size_t byteLen gth, 284 const char text[], size_t byteLen gth,
281 const SkScalar pos[], int scalars PerPosition, 285 const SkScalar pos[], int scalars PerPosition,
282 const SkPoint& offset) { 286 const SkPoint& offset,
287 const SkIRect& regionClipBounds) {
283 288
284 SkASSERT(byteLength == 0 || text != NULL); 289 SkASSERT(byteLength == 0 || text != NULL);
285 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 290 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
286 291
287 // nothing to draw 292 // nothing to draw
288 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) { 293 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) {
289 return; 294 return;
290 } 295 }
291 296
292 fViewMatrix = viewMatrix; 297 fViewMatrix = viewMatrix;
293 this->init(rt, clip, paint, skPaint); 298 this->init(rt, clip, paint, skPaint, regionClipBounds);
294 299
295 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); 300 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
296 301
297 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); 302 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL);
298 SkGlyphCache* cache = autoCache.getCache(); 303 SkGlyphCache* cache = autoCache.getCache();
299 GrFontScaler* fontScaler = GetGrFontScaler(cache); 304 GrFontScaler* fontScaler = GetGrFontScaler(cache);
300 305
301 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); 306 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture);
302 307
303 int numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL); 308 int numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } 365 }
361 } 366 }
362 } 367 }
363 pos += scalarsPerPosition; 368 pos += scalarsPerPosition;
364 } 369 }
365 } 370 }
366 371
367 this->finish(); 372 this->finish();
368 373
369 if (fallbackTxt.count() > 0) { 374 if (fallbackTxt.count() > 0) {
370 fFallbackTextContext->drawPosText(rt, clip, paint, skPaint, viewMatrix, fallbackTxt.begin(), 375 fFallbackTextContext->drawPosText(rt, clip, paint, skPaint, viewMatrix,
371 fallbackTxt.count(), fallbackPos.begin (), 376 fallbackTxt.begin(), fallbackTxt.count (),
372 scalarsPerPosition, offset); 377 fallbackPos.begin(), scalarsPerPositio n, offset,
378 regionClipBounds);
373 } 379 }
374 } 380 }
375 381
376 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { 382 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
377 unsigned r = SkColorGetR(c); 383 unsigned r = SkColorGetR(c);
378 unsigned g = SkColorGetG(c); 384 unsigned g = SkColorGetG(c);
379 unsigned b = SkColorGetB(c); 385 unsigned b = SkColorGetB(c);
380 return GrColorPackRGBA(r, g, b, 0xff); 386 return GrColorPackRGBA(r, g, b, 0xff);
381 } 387 }
382 388
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 } 726 }
721 } 727 }
722 728
723 inline void GrDistanceFieldTextContext::finish() { 729 inline void GrDistanceFieldTextContext::finish() {
724 this->flush(); 730 this->flush();
725 fTotalVertexCount = 0; 731 fTotalVertexCount = 0;
726 732
727 GrTextContext::finish(); 733 GrTextContext::finish();
728 } 734 }
729 735
OLDNEW
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.h ('k') | src/gpu/GrStencilAndCoverTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698