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

Side by Side Diff: src/gpu/text/GrTextUtils.cpp

Issue 1866293003: Decouple contrast boost from fake gamma. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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 7
8 #include "GrTextUtils.h" 8 #include "GrTextUtils.h"
9 9
10 #include "GrAtlasTextBlob.h" 10 #include "GrAtlasTextBlob.h"
(...skipping 22 matching lines...) Expand all
33 #ifdef SK_BUILD_FOR_ANDROID 33 #ifdef SK_BUILD_FOR_ANDROID
34 static const int kLargeDFFontLimit = 384; 34 static const int kLargeDFFontLimit = 384;
35 #else 35 #else
36 static const int kLargeDFFontLimit = 2 * kLargeDFFontSize; 36 static const int kLargeDFFontLimit = 2 * kLargeDFFontSize;
37 #endif 37 #endif
38 }; 38 };
39 39
40 void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex, 40 void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex,
41 GrBatchFontCache* fontCache, 41 GrBatchFontCache* fontCache,
42 const SkSurfaceProps& props, const SkPaint& skPain t, 42 const SkSurfaceProps& props, const SkPaint& skPain t,
43 GrColor color, SkPaint::FakeGamma fakeGamma, 43 GrColor color, uint32_t fontWeightFlags,
44 const SkMatrix& viewMatrix, 44 const SkMatrix& viewMatrix,
45 const char text[], size_t byteLength, 45 const char text[], size_t byteLength,
46 SkScalar x, SkScalar y) { 46 SkScalar x, SkScalar y) {
47 SkASSERT(byteLength == 0 || text != nullptr); 47 SkASSERT(byteLength == 0 || text != nullptr);
48 48
49 // nothing to draw 49 // nothing to draw
50 if (text == nullptr || byteLength == 0) { 50 if (text == nullptr || byteLength == 0) {
51 return; 51 return;
52 } 52 }
53 53
54 // Ensure the blob is set for bitmaptext 54 // Ensure the blob is set for bitmaptext
55 blob->setHasBitmap(); 55 blob->setHasBitmap();
56 56
57 GrBatchTextStrike* currStrike = nullptr; 57 GrBatchTextStrike* currStrike = nullptr;
58 58
59 // Get GrFontScaler from cache 59 // Get GrFontScaler from cache
60 SkGlyphCache* cache = blob->setupCache(runIndex, props, fakeGamma, 60 SkGlyphCache* cache = blob->setupCache(runIndex, props, fontWeightFlags, skP aint, &viewMatrix);
61 skPaint, &viewMatrix);
62 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); 61 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache);
63 62
64 SkFindAndPlaceGlyph::ProcessText( 63 SkFindAndPlaceGlyph::ProcessText(
65 skPaint.getTextEncoding(), text, byteLength, 64 skPaint.getTextEncoding(), text, byteLength,
66 {x, y}, viewMatrix, skPaint.getTextAlign(), 65 {x, y}, viewMatrix, skPaint.getTextAlign(),
67 cache, 66 cache,
68 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { 67 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
69 position += rounding; 68 position += rounding;
70 BmpAppendGlyph( 69 BmpAppendGlyph(
71 blob, runIndex, fontCache, &currStrike, glyph, 70 blob, runIndex, fontCache, &currStrike, glyph,
72 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY) , 71 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY) ,
73 color, fontScaler); 72 color, fontScaler);
74 } 73 }
75 ); 74 );
76 75
77 SkGlyphCache::AttachCache(cache); 76 SkGlyphCache::AttachCache(cache);
78 } 77 }
79 78
80 void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex, 79 void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex,
81 GrBatchFontCache* fontCache, 80 GrBatchFontCache* fontCache,
82 const SkSurfaceProps& props, const SkPaint& skP aint, 81 const SkSurfaceProps& props, const SkPaint& skP aint,
83 GrColor color, SkPaint::FakeGamma fakeGamma, 82 GrColor color, uint32_t fontWeightFlags,
84 const SkMatrix& viewMatrix, 83 const SkMatrix& viewMatrix,
85 const char text[], size_t byteLength, 84 const char text[], size_t byteLength,
86 const SkScalar pos[], int scalarsPerPosition, 85 const SkScalar pos[], int scalarsPerPosition,
87 const SkPoint& offset) { 86 const SkPoint& offset) {
88 SkASSERT(byteLength == 0 || text != nullptr); 87 SkASSERT(byteLength == 0 || text != nullptr);
89 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 88 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
90 89
91 // nothing to draw 90 // nothing to draw
92 if (text == nullptr || byteLength == 0) { 91 if (text == nullptr || byteLength == 0) {
93 return; 92 return;
94 } 93 }
95 94
96 // Ensure the blob is set for bitmaptext 95 // Ensure the blob is set for bitmaptext
97 blob->setHasBitmap(); 96 blob->setHasBitmap();
98 97
99 GrBatchTextStrike* currStrike = nullptr; 98 GrBatchTextStrike* currStrike = nullptr;
100 99
101 // Get GrFontScaler from cache 100 // Get GrFontScaler from cache
102 SkGlyphCache* cache = blob->setupCache(runIndex, props, fakeGamma, 101 SkGlyphCache* cache = blob->setupCache(runIndex, props, fontWeightFlags, skP aint, &viewMatrix);
103 skPaint, &viewMatrix);
104 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); 102 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache);
105 103
106 SkFindAndPlaceGlyph::ProcessPosText( 104 SkFindAndPlaceGlyph::ProcessPosText(
107 skPaint.getTextEncoding(), text, byteLength, 105 skPaint.getTextEncoding(), text, byteLength,
108 offset, viewMatrix, pos, scalarsPerPosition, 106 offset, viewMatrix, pos, scalarsPerPosition,
109 skPaint.getTextAlign(), cache, 107 skPaint.getTextAlign(), cache,
110 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { 108 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
111 position += rounding; 109 position += rounding;
112 BmpAppendGlyph( 110 BmpAppendGlyph(
113 blob, runIndex, fontCache, &currStrike, glyph, 111 blob, runIndex, fontCache, &currStrike, glyph,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil / scaledTextSize); 238 blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil / scaledTextSize);
241 239
242 skPaint->setLCDRenderText(false); 240 skPaint->setLCDRenderText(false);
243 skPaint->setAutohinted(false); 241 skPaint->setAutohinted(false);
244 skPaint->setHinting(SkPaint::kNormal_Hinting); 242 skPaint->setHinting(SkPaint::kNormal_Hinting);
245 skPaint->setSubpixelText(true); 243 skPaint->setSubpixelText(true);
246 } 244 }
247 245
248 void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex, 246 void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex,
249 GrBatchFontCache* fontCache, const SkSurfaceProps& props, 247 GrBatchFontCache* fontCache, const SkSurfaceProps& props,
250 const SkPaint& skPaint, GrColor color, SkPaint::Fak eGamma fakeGamma, 248 const SkPaint& skPaint, GrColor color, uint32_t fon tWeightFlags,
251 const SkMatrix& viewMatrix, 249 const SkMatrix& viewMatrix,
252 const char text[], size_t byteLength, 250 const char text[], size_t byteLength,
253 SkScalar x, SkScalar y) { 251 SkScalar x, SkScalar y) {
254 SkASSERT(byteLength == 0 || text != nullptr); 252 SkASSERT(byteLength == 0 || text != nullptr);
255 253
256 // nothing to draw 254 // nothing to draw
257 if (text == nullptr || byteLength == 0) { 255 if (text == nullptr || byteLength == 0) {
258 return; 256 return;
259 } 257 }
260 258
261 SkPaint::GlyphCacheProc glyphCacheProc = skPaint.getGlyphCacheProc(true); 259 SkPaint::GlyphCacheProc glyphCacheProc = skPaint.getGlyphCacheProc(true);
262 SkAutoDescriptor desc; 260 SkAutoDescriptor desc;
263 // We apply the fake-gamma by altering the distance in the shader, so we ign ore the 261 // We apply the fake-gamma by altering the distance in the shader, so we ign ore the
264 // fakeGamma parameter. (It's only used when we fall-back to bitmap text). 262 // passed-in font weight flags. (It's only used when we fall-back to bitmap text).
265 skPaint.getScalerContextDescriptor(&desc, props, SkPaint::FakeGamma::Off, nu llptr); 263 skPaint.getScalerContextDescriptor(&desc, props, SkPaint::kNone_FontWeightFl ag, nullptr);
266 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface (), 264 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface (),
267 desc.getDesc()); 265 desc.getDesc());
268 266
269 SkTArray<SkScalar> positions; 267 SkTArray<SkScalar> positions;
270 268
271 const char* textPtr = text; 269 const char* textPtr = text;
272 SkScalar stopX = 0; 270 SkScalar stopX = 0;
273 SkScalar stopY = 0; 271 SkScalar stopY = 0;
274 SkScalar origin = 0; 272 SkScalar origin = 0;
275 switch (skPaint.getTextAlign()) { 273 switch (skPaint.getTextAlign()) {
(...skipping 29 matching lines...) Expand all
305 alignX = SkScalarHalf(alignX); 303 alignX = SkScalarHalf(alignX);
306 alignY = SkScalarHalf(alignY); 304 alignY = SkScalarHalf(alignY);
307 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) { 305 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) {
308 alignX = 0; 306 alignX = 0;
309 alignY = 0; 307 alignY = 0;
310 } 308 }
311 x -= alignX; 309 x -= alignX;
312 y -= alignY; 310 y -= alignY;
313 SkPoint offset = SkPoint::Make(x, y); 311 SkPoint offset = SkPoint::Make(x, y);
314 312
315 DrawDFPosText(blob, runIndex, fontCache, props, skPaint, color, fakeGamma, v iewMatrix, 313 DrawDFPosText(blob, runIndex, fontCache, props, skPaint, color, fontWeightFl ags, viewMatrix,
316 text, byteLength, positions.begin(), 2, offset); 314 text, byteLength, positions.begin(), 2, offset);
317 } 315 }
318 316
319 void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex, 317 void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
320 GrBatchFontCache* fontCache, const SkSurfaceProp s& props, 318 GrBatchFontCache* fontCache, const SkSurfaceProp s& props,
321 const SkPaint& origPaint, 319 const SkPaint& origPaint,
322 GrColor color, SkPaint::FakeGamma fakeGamma, 320 GrColor color, uint32_t fontWeightFlags,
323 const SkMatrix& viewMatrix, 321 const SkMatrix& viewMatrix,
324 const char text[], size_t byteLength, 322 const char text[], size_t byteLength,
325 const SkScalar pos[], int scalarsPerPosition, 323 const SkScalar pos[], int scalarsPerPosition,
326 const SkPoint& offset) { 324 const SkPoint& offset) {
327 SkASSERT(byteLength == 0 || text != nullptr); 325 SkASSERT(byteLength == 0 || text != nullptr);
328 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 326 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
329 327
330 // nothing to draw 328 // nothing to draw
331 if (text == nullptr || byteLength == 0) { 329 if (text == nullptr || byteLength == 0) {
332 return; 330 return;
333 } 331 }
334 332
335 SkTDArray<char> fallbackTxt; 333 SkTDArray<char> fallbackTxt;
336 SkTDArray<SkScalar> fallbackPos; 334 SkTDArray<SkScalar> fallbackPos;
337 335
338 // Setup distance field paint and text ratio 336 // Setup distance field paint and text ratio
339 SkScalar textRatio; 337 SkScalar textRatio;
340 SkPaint dfPaint(origPaint); 338 SkPaint dfPaint(origPaint);
341 GrTextUtils::InitDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix); 339 GrTextUtils::InitDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix);
342 blob->setHasDistanceField(); 340 blob->setHasDistanceField();
343 blob->setSubRunHasDistanceFields(runIndex, origPaint.isLCDRenderText()); 341 blob->setSubRunHasDistanceFields(runIndex, origPaint.isLCDRenderText());
344 342
345 GrBatchTextStrike* currStrike = nullptr; 343 GrBatchTextStrike* currStrike = nullptr;
346 344
347 // We apply the fake-gamma by altering the distance in the shader, so we ign ore the 345 // We apply the fake-gamma by altering the distance in the shader, so we ign ore the
348 // fakeGamma parameter. (It's only used when we fall-back to bitmap text). 346 // passed-in font weight flags. (It's only used when we fall-back to bitmap text).
349 SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::FakeGamma:: Off, 347 SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::kNone_FontW eightFlag,
350 dfPaint, nullptr); 348 dfPaint, nullptr);
351 SkPaint::GlyphCacheProc glyphCacheProc = dfPaint.getGlyphCacheProc(true); 349 SkPaint::GlyphCacheProc glyphCacheProc = dfPaint.getGlyphCacheProc(true);
352 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); 350 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache);
353 351
354 const char* stop = text + byteLength; 352 const char* stop = text + byteLength;
355 353
356 if (SkPaint::kLeft_Align == dfPaint.getTextAlign()) { 354 if (SkPaint::kLeft_Align == dfPaint.getTextAlign()) {
357 while (text < stop) { 355 while (text < stop) {
358 const char* lastText = text; 356 const char* lastText = text;
359 // the last 2 parameters are ignored 357 // the last 2 parameters are ignored
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 } 411 }
414 } 412 }
415 pos += scalarsPerPosition; 413 pos += scalarsPerPosition;
416 } 414 }
417 } 415 }
418 416
419 SkGlyphCache::AttachCache(cache); 417 SkGlyphCache::AttachCache(cache);
420 if (fallbackTxt.count()) { 418 if (fallbackTxt.count()) {
421 blob->initOverride(runIndex); 419 blob->initOverride(runIndex);
422 GrTextUtils::DrawBmpPosText(blob, runIndex, fontCache, props, 420 GrTextUtils::DrawBmpPosText(blob, runIndex, fontCache, props,
423 origPaint, origPaint.getColor(), fakeGamma, viewMatrix, 421 origPaint, origPaint.getColor(), fontWeightF lags, viewMatrix,
424 fallbackTxt.begin(), fallbackTxt.count(), 422 fallbackTxt.begin(), fallbackTxt.count(),
425 fallbackPos.begin(), scalarsPerPosition, off set); 423 fallbackPos.begin(), scalarsPerPosition, off set);
426 } 424 }
427 } 425 }
428 426
429 bool GrTextUtils::DfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, GrBatchFont Cache* cache, 427 bool GrTextUtils::DfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, GrBatchFont Cache* cache,
430 GrBatchTextStrike** strike, const SkGlyph& skGly ph, 428 GrBatchTextStrike** strike, const SkGlyph& skGly ph,
431 SkScalar sx, SkScalar sy, GrColor color, 429 SkScalar sx, SkScalar sy, GrColor color,
432 GrFontScaler* scaler, 430 GrFontScaler* scaler,
433 SkScalar textRatio, const SkMatrix& viewMatrix) { 431 SkScalar textRatio, const SkMatrix& viewMatrix) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 if (cache->getAuxProcData(glyph_cache_aux_proc, &auxData)) { 578 if (cache->getAuxProcData(glyph_cache_aux_proc, &auxData)) {
581 scaler = (GrFontScaler*)auxData; 579 scaler = (GrFontScaler*)auxData;
582 } 580 }
583 if (nullptr == scaler) { 581 if (nullptr == scaler) {
584 scaler = new GrFontScaler(cache); 582 scaler = new GrFontScaler(cache);
585 cache->setAuxProc(glyph_cache_aux_proc, scaler); 583 cache->setAuxProc(glyph_cache_aux_proc, scaler);
586 } 584 }
587 585
588 return scaler; 586 return scaler;
589 } 587 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698