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

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: Improve ignorePreBlend API, add storage type to enum 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
« no previous file with comments | « src/gpu/text/GrTextUtils.h ('k') | src/ports/SkFontHost_FreeType.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 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 scalerContextFlags,
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, scalerContextFlags, skPaint,
61 skPaint, &viewMatrix); 61 &viewMatrix);
62 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); 62 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache);
63 63
64 SkFindAndPlaceGlyph::ProcessText( 64 SkFindAndPlaceGlyph::ProcessText(
65 skPaint.getTextEncoding(), text, byteLength, 65 skPaint.getTextEncoding(), text, byteLength,
66 {x, y}, viewMatrix, skPaint.getTextAlign(), 66 {x, y}, viewMatrix, skPaint.getTextAlign(),
67 cache, 67 cache,
68 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { 68 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
69 position += rounding; 69 position += rounding;
70 BmpAppendGlyph( 70 BmpAppendGlyph(
71 blob, runIndex, fontCache, &currStrike, glyph, 71 blob, runIndex, fontCache, &currStrike, glyph,
72 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY) , 72 SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY) ,
73 color, fontScaler); 73 color, fontScaler);
74 } 74 }
75 ); 75 );
76 76
77 SkGlyphCache::AttachCache(cache); 77 SkGlyphCache::AttachCache(cache);
78 } 78 }
79 79
80 void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex, 80 void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex,
81 GrBatchFontCache* fontCache, 81 GrBatchFontCache* fontCache,
82 const SkSurfaceProps& props, const SkPaint& skP aint, 82 const SkSurfaceProps& props, const SkPaint& skP aint,
83 GrColor color, SkPaint::FakeGamma fakeGamma, 83 GrColor color, uint32_t scalerContextFlags,
84 const SkMatrix& viewMatrix, 84 const SkMatrix& viewMatrix,
85 const char text[], size_t byteLength, 85 const char text[], size_t byteLength,
86 const SkScalar pos[], int scalarsPerPosition, 86 const SkScalar pos[], int scalarsPerPosition,
87 const SkPoint& offset) { 87 const SkPoint& offset) {
88 SkASSERT(byteLength == 0 || text != nullptr); 88 SkASSERT(byteLength == 0 || text != nullptr);
89 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 89 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
90 90
91 // nothing to draw 91 // nothing to draw
92 if (text == nullptr || byteLength == 0) { 92 if (text == nullptr || byteLength == 0) {
93 return; 93 return;
94 } 94 }
95 95
96 // Ensure the blob is set for bitmaptext 96 // Ensure the blob is set for bitmaptext
97 blob->setHasBitmap(); 97 blob->setHasBitmap();
98 98
99 GrBatchTextStrike* currStrike = nullptr; 99 GrBatchTextStrike* currStrike = nullptr;
100 100
101 // Get GrFontScaler from cache 101 // Get GrFontScaler from cache
102 SkGlyphCache* cache = blob->setupCache(runIndex, props, fakeGamma, 102 SkGlyphCache* cache = blob->setupCache(runIndex, props, scalerContextFlags, skPaint,
103 skPaint, &viewMatrix); 103 &viewMatrix);
104 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); 104 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache);
105 105
106 SkFindAndPlaceGlyph::ProcessPosText( 106 SkFindAndPlaceGlyph::ProcessPosText(
107 skPaint.getTextEncoding(), text, byteLength, 107 skPaint.getTextEncoding(), text, byteLength,
108 offset, viewMatrix, pos, scalarsPerPosition, 108 offset, viewMatrix, pos, scalarsPerPosition,
109 skPaint.getTextAlign(), cache, 109 skPaint.getTextAlign(), cache,
110 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { 110 [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
111 position += rounding; 111 position += rounding;
112 BmpAppendGlyph( 112 BmpAppendGlyph(
113 blob, runIndex, fontCache, &currStrike, glyph, 113 blob, runIndex, fontCache, &currStrike, glyph,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil / scaledTextSize); 240 blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil / scaledTextSize);
241 241
242 skPaint->setLCDRenderText(false); 242 skPaint->setLCDRenderText(false);
243 skPaint->setAutohinted(false); 243 skPaint->setAutohinted(false);
244 skPaint->setHinting(SkPaint::kNormal_Hinting); 244 skPaint->setHinting(SkPaint::kNormal_Hinting);
245 skPaint->setSubpixelText(true); 245 skPaint->setSubpixelText(true);
246 } 246 }
247 247
248 void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex, 248 void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex,
249 GrBatchFontCache* fontCache, const SkSurfaceProps& props, 249 GrBatchFontCache* fontCache, const SkSurfaceProps& props,
250 const SkPaint& skPaint, GrColor color, SkPaint::Fak eGamma fakeGamma, 250 const SkPaint& skPaint, GrColor color, uint32_t sca lerContextFlags,
251 const SkMatrix& viewMatrix, 251 const SkMatrix& viewMatrix,
252 const char text[], size_t byteLength, 252 const char text[], size_t byteLength,
253 SkScalar x, SkScalar y) { 253 SkScalar x, SkScalar y) {
254 SkASSERT(byteLength == 0 || text != nullptr); 254 SkASSERT(byteLength == 0 || text != nullptr);
255 255
256 // nothing to draw 256 // nothing to draw
257 if (text == nullptr || byteLength == 0) { 257 if (text == nullptr || byteLength == 0) {
258 return; 258 return;
259 } 259 }
260 260
261 SkPaint::GlyphCacheProc glyphCacheProc = skPaint.getGlyphCacheProc(true); 261 SkPaint::GlyphCacheProc glyphCacheProc = skPaint.getGlyphCacheProc(true);
262 SkAutoDescriptor desc; 262 SkAutoDescriptor desc;
263 // We apply the fake-gamma by altering the distance in the shader, so we ign ore the 263 // 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). 264 // passed-in scaler context flags. (It's only used when we fall-back to bitm ap text).
265 skPaint.getScalerContextDescriptor(&desc, props, SkPaint::FakeGamma::Off, nu llptr); 265 skPaint.getScalerContextDescriptor(&desc, props, SkPaint::kNone_ScalerContex tFlags, nullptr);
266 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface (), 266 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface (),
267 desc.getDesc()); 267 desc.getDesc());
268 268
269 SkTArray<SkScalar> positions; 269 SkTArray<SkScalar> positions;
270 270
271 const char* textPtr = text; 271 const char* textPtr = text;
272 SkScalar stopX = 0; 272 SkScalar stopX = 0;
273 SkScalar stopY = 0; 273 SkScalar stopY = 0;
274 SkScalar origin = 0; 274 SkScalar origin = 0;
275 switch (skPaint.getTextAlign()) { 275 switch (skPaint.getTextAlign()) {
(...skipping 29 matching lines...) Expand all
305 alignX = SkScalarHalf(alignX); 305 alignX = SkScalarHalf(alignX);
306 alignY = SkScalarHalf(alignY); 306 alignY = SkScalarHalf(alignY);
307 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) { 307 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) {
308 alignX = 0; 308 alignX = 0;
309 alignY = 0; 309 alignY = 0;
310 } 310 }
311 x -= alignX; 311 x -= alignX;
312 y -= alignY; 312 y -= alignY;
313 SkPoint offset = SkPoint::Make(x, y); 313 SkPoint offset = SkPoint::Make(x, y);
314 314
315 DrawDFPosText(blob, runIndex, fontCache, props, skPaint, color, fakeGamma, v iewMatrix, 315 DrawDFPosText(blob, runIndex, fontCache, props, skPaint, color, scalerContex tFlags, viewMatrix,
316 text, byteLength, positions.begin(), 2, offset); 316 text, byteLength, positions.begin(), 2, offset);
317 } 317 }
318 318
319 void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex, 319 void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
320 GrBatchFontCache* fontCache, const SkSurfaceProp s& props, 320 GrBatchFontCache* fontCache, const SkSurfaceProp s& props,
321 const SkPaint& origPaint, 321 const SkPaint& origPaint,
322 GrColor color, SkPaint::FakeGamma fakeGamma, 322 GrColor color, uint32_t scalerContextFlags,
323 const SkMatrix& viewMatrix, 323 const SkMatrix& viewMatrix,
324 const char text[], size_t byteLength, 324 const char text[], size_t byteLength,
325 const SkScalar pos[], int scalarsPerPosition, 325 const SkScalar pos[], int scalarsPerPosition,
326 const SkPoint& offset) { 326 const SkPoint& offset) {
327 SkASSERT(byteLength == 0 || text != nullptr); 327 SkASSERT(byteLength == 0 || text != nullptr);
328 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 328 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
329 329
330 // nothing to draw 330 // nothing to draw
331 if (text == nullptr || byteLength == 0) { 331 if (text == nullptr || byteLength == 0) {
332 return; 332 return;
333 } 333 }
334 334
335 SkTDArray<char> fallbackTxt; 335 SkTDArray<char> fallbackTxt;
336 SkTDArray<SkScalar> fallbackPos; 336 SkTDArray<SkScalar> fallbackPos;
337 337
338 // Setup distance field paint and text ratio 338 // Setup distance field paint and text ratio
339 SkScalar textRatio; 339 SkScalar textRatio;
340 SkPaint dfPaint(origPaint); 340 SkPaint dfPaint(origPaint);
341 GrTextUtils::InitDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix); 341 GrTextUtils::InitDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix);
342 blob->setHasDistanceField(); 342 blob->setHasDistanceField();
343 blob->setSubRunHasDistanceFields(runIndex, origPaint.isLCDRenderText()); 343 blob->setSubRunHasDistanceFields(runIndex, origPaint.isLCDRenderText());
344 344
345 GrBatchTextStrike* currStrike = nullptr; 345 GrBatchTextStrike* currStrike = nullptr;
346 346
347 // We apply the fake-gamma by altering the distance in the shader, so we ign ore the 347 // 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). 348 // passed-in scaler context flags. (It's only used when we fall-back to bitm ap text).
349 SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::FakeGamma:: Off, 349 SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::kNone_Scale rContextFlags,
350 dfPaint, nullptr); 350 dfPaint, nullptr);
351 SkPaint::GlyphCacheProc glyphCacheProc = dfPaint.getGlyphCacheProc(true); 351 SkPaint::GlyphCacheProc glyphCacheProc = dfPaint.getGlyphCacheProc(true);
352 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); 352 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache);
353 353
354 const char* stop = text + byteLength; 354 const char* stop = text + byteLength;
355 355
356 if (SkPaint::kLeft_Align == dfPaint.getTextAlign()) { 356 if (SkPaint::kLeft_Align == dfPaint.getTextAlign()) {
357 while (text < stop) { 357 while (text < stop) {
358 const char* lastText = text; 358 const char* lastText = text;
359 // the last 2 parameters are ignored 359 // the last 2 parameters are ignored
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 } 413 }
414 } 414 }
415 pos += scalarsPerPosition; 415 pos += scalarsPerPosition;
416 } 416 }
417 } 417 }
418 418
419 SkGlyphCache::AttachCache(cache); 419 SkGlyphCache::AttachCache(cache);
420 if (fallbackTxt.count()) { 420 if (fallbackTxt.count()) {
421 blob->initOverride(runIndex); 421 blob->initOverride(runIndex);
422 GrTextUtils::DrawBmpPosText(blob, runIndex, fontCache, props, 422 GrTextUtils::DrawBmpPosText(blob, runIndex, fontCache, props,
423 origPaint, origPaint.getColor(), fakeGamma, viewMatrix, 423 origPaint, origPaint.getColor(), scalerConte xtFlags, viewMatrix,
424 fallbackTxt.begin(), fallbackTxt.count(), 424 fallbackTxt.begin(), fallbackTxt.count(),
425 fallbackPos.begin(), scalarsPerPosition, off set); 425 fallbackPos.begin(), scalarsPerPosition, off set);
426 } 426 }
427 } 427 }
428 428
429 bool GrTextUtils::DfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, GrBatchFont Cache* cache, 429 bool GrTextUtils::DfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, GrBatchFont Cache* cache,
430 GrBatchTextStrike** strike, const SkGlyph& skGly ph, 430 GrBatchTextStrike** strike, const SkGlyph& skGly ph,
431 SkScalar sx, SkScalar sy, GrColor color, 431 SkScalar sx, SkScalar sy, GrColor color,
432 GrFontScaler* scaler, 432 GrFontScaler* scaler,
433 SkScalar textRatio, const SkMatrix& viewMatrix) { 433 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)) { 580 if (cache->getAuxProcData(glyph_cache_aux_proc, &auxData)) {
581 scaler = (GrFontScaler*)auxData; 581 scaler = (GrFontScaler*)auxData;
582 } 582 }
583 if (nullptr == scaler) { 583 if (nullptr == scaler) {
584 scaler = new GrFontScaler(cache); 584 scaler = new GrFontScaler(cache);
585 cache->setAuxProc(glyph_cache_aux_proc, scaler); 585 cache->setAuxProc(glyph_cache_aux_proc, scaler);
586 } 586 }
587 587
588 return scaler; 588 return scaler;
589 } 589 }
OLDNEW
« no previous file with comments | « src/gpu/text/GrTextUtils.h ('k') | src/ports/SkFontHost_FreeType.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698