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

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

Issue 1888473003: Simplify gamma-correctness for text rendering. (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
« no previous file with comments | « src/gpu/text/GrAtlasTextContext.h ('k') | no next file » | 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 "GrContext.h" 9 #include "GrContext.h"
10 #include "GrDrawContext.h" 10 #include "GrDrawContext.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // gamma corrected masks anyways, nor color 46 // gamma corrected masks anyways, nor color
47 U8CPU lum = SkComputeLuminance(SkColorGetR(canonicalColor), 47 U8CPU lum = SkComputeLuminance(SkColorGetR(canonicalColor),
48 SkColorGetG(canonicalColor), 48 SkColorGetG(canonicalColor),
49 SkColorGetB(canonicalColor)); 49 SkColorGetB(canonicalColor));
50 // reduce to our finite number of bits 50 // reduce to our finite number of bits
51 canonicalColor = SkMaskGamma::CanonicalColor(SkColorSetRGB(lum, lum, lum )); 51 canonicalColor = SkMaskGamma::CanonicalColor(SkColorSetRGB(lum, lum, lum ));
52 } 52 }
53 return canonicalColor; 53 return canonicalColor;
54 } 54 }
55 55
56 uint32_t GrAtlasTextContext::ComputeScalerContextFlags(GrDrawContext* dc, const GrPaint& grPaint) { 56 uint32_t GrAtlasTextContext::ComputeScalerContextFlags(GrDrawContext* dc) {
57 // If we're rendering to an sRGB render target, and we aren't forcing sRGB b lending off, 57 // If we're doing gamma-correct rendering, then we can disable the gamma hac ks.
58 // then we can disable the gamma hacks. Otherwise, leave them on. In either case, we still 58 // Otherwise, leave them on. In either case, we still want the contrast boos t:
59 // want the contrast boost: 59 if (dc->isGammaCorrect()) {
60 if (GrPixelConfigIsSRGB(dc->accessRenderTarget()->config()) &&
61 !grPaint.getDisableOutputConversionToSRGB()) {
62 return SkPaint::kBoostContrast_ScalerContextFlag; 60 return SkPaint::kBoostContrast_ScalerContextFlag;
63 } else { 61 } else {
64 return SkPaint::kFakeGammaAndBoostContrast_ScalerContextFlags; 62 return SkPaint::kFakeGammaAndBoostContrast_ScalerContextFlags;
65 } 63 }
66 } 64 }
67 65
68 // TODO if this function ever shows up in profiling, then we can compute this va lue when the 66 // TODO if this function ever shows up in profiling, then we can compute this va lue when the
69 // textblob is being built and cache it. However, for the time being textblobs mostly only have 1 67 // textblob is being built and cache it. However, for the time being textblobs mostly only have 1
70 // run so this is not a big deal to compute here. 68 // run so this is not a big deal to compute here.
71 bool GrAtlasTextContext::HasLCD(const SkTextBlob* blob) { 69 bool GrAtlasTextContext::HasLCD(const SkTextBlob* blob) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 cacheBlob.reset(SkSafeRef(cache->find(key))); 119 cacheBlob.reset(SkSafeRef(cache->find(key)));
122 } 120 }
123 121
124 // Though for the time being runs in the textblob can override the paint, th ey only touch font 122 // Though for the time being runs in the textblob can override the paint, th ey only touch font
125 // info. 123 // info.
126 GrPaint grPaint; 124 GrPaint grPaint;
127 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, props.isGammaCorrect(), &grPaint)) { 125 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, props.isGammaCorrect(), &grPaint)) {
128 return; 126 return;
129 } 127 }
130 128
131 uint32_t scalerContextFlags = ComputeScalerContextFlags(dc, grPaint); 129 uint32_t scalerContextFlags = ComputeScalerContextFlags(dc);
132 130
133 if (cacheBlob) { 131 if (cacheBlob) {
134 if (cacheBlob->mustRegenerate(skPaint, grPaint.getColor(), blurRec, view Matrix, x, y)) { 132 if (cacheBlob->mustRegenerate(skPaint, grPaint.getColor(), blurRec, view Matrix, x, y)) {
135 // We have to remake the blob because changes may invalidate our mas ks. 133 // We have to remake the blob because changes may invalidate our mas ks.
136 // TODO we could probably get away reuse most of the time if the poi nter is unique, 134 // TODO we could probably get away reuse most of the time if the poi nter is unique,
137 // but we'd have to clear the subrun information 135 // but we'd have to clear the subrun information
138 cache->remove(cacheBlob); 136 cache->remove(cacheBlob);
139 cacheBlob.reset(SkRef(cache->createCachedBlob(blob, key, blurRec, sk Paint))); 137 cacheBlob.reset(SkRef(cache->createCachedBlob(blob, key, blurRec, sk Paint)));
140 RegenerateTextBlob(cacheBlob, context->getBatchFontCache(), 138 RegenerateTextBlob(cacheBlob, context->getBatchFontCache(),
141 *context->caps()->shaderCaps(), skPaint, grPaint. getColor(), 139 *context->caps()->shaderCaps(), skPaint, grPaint. getColor(),
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 const SkSurfaceProps& props, 320 const SkSurfaceProps& props,
323 const char text[], size_t byteLength, 321 const char text[], size_t byteLength,
324 SkScalar x, SkScalar y, const SkIRect& regionC lipBounds) { 322 SkScalar x, SkScalar y, const SkIRect& regionC lipBounds) {
325 if (context->abandoned()) { 323 if (context->abandoned()) {
326 return; 324 return;
327 } else if (this->canDraw(skPaint, viewMatrix, props, *context->caps()->shade rCaps())) { 325 } else if (this->canDraw(skPaint, viewMatrix, props, *context->caps()->shade rCaps())) {
328 SkAutoTUnref<GrAtlasTextBlob> blob( 326 SkAutoTUnref<GrAtlasTextBlob> blob(
329 CreateDrawTextBlob(context->getTextBlobCache(), context->getBatchFon tCache(), 327 CreateDrawTextBlob(context->getTextBlobCache(), context->getBatchFon tCache(),
330 *context->caps()->shaderCaps(), 328 *context->caps()->shaderCaps(),
331 paint, skPaint, 329 paint, skPaint,
332 ComputeScalerContextFlags(dc, paint), 330 ComputeScalerContextFlags(dc),
333 viewMatrix, props, 331 viewMatrix, props,
334 text, byteLength, x, y)); 332 text, byteLength, x, y));
335 blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint, paint, 333 blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint, paint,
336 clip, viewMatrix, regionClipBounds, x, y); 334 clip, viewMatrix, regionClipBounds, x, y);
337 return; 335 return;
338 } 336 }
339 337
340 // fall back to drawing as a path 338 // fall back to drawing as a path
341 GrTextUtils::DrawTextAsPath(context, dc, clip, skPaint, viewMatrix, text, by teLength, x, y, 339 GrTextUtils::DrawTextAsPath(context, dc, clip, skPaint, viewMatrix, text, by teLength, x, y,
342 regionClipBounds); 340 regionClipBounds);
343 } 341 }
344 342
345 void GrAtlasTextContext::drawPosText(GrContext* context, 343 void GrAtlasTextContext::drawPosText(GrContext* context,
346 GrDrawContext* dc, 344 GrDrawContext* dc,
347 const GrClip& clip, 345 const GrClip& clip,
348 const GrPaint& paint, const SkPaint& skPain t, 346 const GrPaint& paint, const SkPaint& skPain t,
349 const SkMatrix& viewMatrix, 347 const SkMatrix& viewMatrix,
350 const SkSurfaceProps& props, 348 const SkSurfaceProps& props,
351 const char text[], size_t byteLength, 349 const char text[], size_t byteLength,
352 const SkScalar pos[], int scalarsPerPositio n, 350 const SkScalar pos[], int scalarsPerPositio n,
353 const SkPoint& offset, const SkIRect& regio nClipBounds) { 351 const SkPoint& offset, const SkIRect& regio nClipBounds) {
354 if (context->abandoned()) { 352 if (context->abandoned()) {
355 return; 353 return;
356 } else if (this->canDraw(skPaint, viewMatrix, props, *context->caps()->shade rCaps())) { 354 } else if (this->canDraw(skPaint, viewMatrix, props, *context->caps()->shade rCaps())) {
357 SkAutoTUnref<GrAtlasTextBlob> blob( 355 SkAutoTUnref<GrAtlasTextBlob> blob(
358 CreateDrawPosTextBlob(context->getTextBlobCache(), 356 CreateDrawPosTextBlob(context->getTextBlobCache(),
359 context->getBatchFontCache(), 357 context->getBatchFontCache(),
360 *context->caps()->shaderCaps(), 358 *context->caps()->shaderCaps(),
361 paint, skPaint, 359 paint, skPaint,
362 ComputeScalerContextFlags(dc, paint), 360 ComputeScalerContextFlags(dc),
363 viewMatrix, props, 361 viewMatrix, props,
364 text, byteLength, 362 text, byteLength,
365 pos, scalarsPerPosition, 363 pos, scalarsPerPosition,
366 offset)); 364 offset));
367 blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint, paint, 365 blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint, paint,
368 clip, viewMatrix, regionClipBounds, offset.fX, offs et.fY); 366 clip, viewMatrix, regionClipBounds, offset.fX, offs et.fY);
369 return; 367 return;
370 } 368 }
371 369
372 // fall back to drawing as a path 370 // fall back to drawing as a path
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 viewMatrix, 425 viewMatrix,
428 gSurfaceProps, text, 426 gSurfaceProps, text,
429 static_cast<size_t>(textLen), x, y)); 427 static_cast<size_t>(textLen), x, y));
430 428
431 return blob->test_createBatch(textLen, 0, 0, viewMatrix, x, y, color, skPain t, 429 return blob->test_createBatch(textLen, 0, 0, viewMatrix, x, y, color, skPain t,
432 gSurfaceProps, gTextContext->dfAdjustTable(), 430 gSurfaceProps, gTextContext->dfAdjustTable(),
433 context->getBatchFontCache()); 431 context->getBatchFontCache());
434 } 432 }
435 433
436 #endif 434 #endif
OLDNEW
« no previous file with comments | « src/gpu/text/GrAtlasTextContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698