aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/gpu/text/GrAtlasTextContext.cpp49
-rw-r--r--src/gpu/text/GrAtlasTextContext.h11
-rw-r--r--src/gpu/text/GrTextUtils.cpp23
-rw-r--r--src/gpu/text/GrTextUtils.h10
4 files changed, 61 insertions, 32 deletions
diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp
index 918d6d29f7..574993a3ca 100644
--- a/src/gpu/text/GrAtlasTextContext.cpp
+++ b/src/gpu/text/GrAtlasTextContext.cpp
@@ -53,6 +53,17 @@ GrColor GrAtlasTextContext::ComputeCanonicalColor(const SkPaint& paint, bool lcd
return canonicalColor;
}
+SkPaint::FakeGamma GrAtlasTextContext::ComputeFakeGamma(GrDrawContext* dc, const GrPaint& grPaint) {
+ // If we're rendering to an sRGB render target, and we aren't forcing sRGB blending off,
+ // then we can disable the gamma hacks. Otherwise, leave them on:
+ if (GrPixelConfigIsSRGB(dc->accessRenderTarget()->config()) &&
+ !grPaint.getDisableOutputConversionToSRGB()) {
+ return SkPaint::FakeGamma::Off;
+ } else {
+ return SkPaint::FakeGamma::On;
+ }
+}
+
// TODO if this function ever shows up in profiling, then we can compute this value when the
// textblob is being built and cache it. However, for the time being textblobs mostly only have 1
// run so this is not a big deal to compute here.
@@ -116,6 +127,8 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrDrawContext* dc,
return;
}
+ SkPaint::FakeGamma fakeGamma = ComputeFakeGamma(dc, grPaint);
+
if (cacheBlob) {
if (cacheBlob->mustRegenerate(skPaint, grPaint.getColor(), blurRec, viewMatrix, x, y)) {
// We have to remake the blob because changes may invalidate our masks.
@@ -125,7 +138,7 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrDrawContext* dc,
cacheBlob.reset(SkRef(cache->createCachedBlob(blob, key, blurRec, skPaint)));
RegenerateTextBlob(cacheBlob, context->getBatchFontCache(),
*context->caps()->shaderCaps(), skPaint, grPaint.getColor(),
- viewMatrix, props,
+ fakeGamma, viewMatrix, props,
blob, x, y, drawFilter);
} else {
cache->makeMRU(cacheBlob);
@@ -138,7 +151,7 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrDrawContext* dc,
sanityBlob->setupKey(key, blurRec, skPaint);
RegenerateTextBlob(sanityBlob, context->getBatchFontCache(),
*context->caps()->shaderCaps(), skPaint,
- grPaint.getColor(), viewMatrix, props,
+ grPaint.getColor(), fakeGamma, viewMatrix, props,
blob, x, y, drawFilter);
GrAtlasTextBlob::AssertEqual(*sanityBlob, *cacheBlob);
}
@@ -151,7 +164,7 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrDrawContext* dc,
}
RegenerateTextBlob(cacheBlob, context->getBatchFontCache(),
*context->caps()->shaderCaps(), skPaint, grPaint.getColor(),
- viewMatrix, props,
+ fakeGamma, viewMatrix, props,
blob, x, y, drawFilter);
}
@@ -163,6 +176,7 @@ void GrAtlasTextContext::RegenerateTextBlob(GrAtlasTextBlob* cacheBlob,
GrBatchFontCache* fontCache,
const GrShaderCaps& shaderCaps,
const SkPaint& skPaint, GrColor color,
+ SkPaint::FakeGamma fakeGamma,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
const SkTextBlob* blob, SkScalar x, SkScalar y,
@@ -194,7 +208,7 @@ void GrAtlasTextContext::RegenerateTextBlob(GrAtlasTextBlob* cacheBlob,
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning: {
GrTextUtils::DrawDFText(cacheBlob, run, fontCache,
- props, runPaint, color, viewMatrix,
+ props, runPaint, color, fakeGamma, viewMatrix,
(const char *)it.glyphs(), textLen,
x + offset.x(), y + offset.y());
break;
@@ -202,7 +216,7 @@ void GrAtlasTextContext::RegenerateTextBlob(GrAtlasTextBlob* cacheBlob,
case SkTextBlob::kHorizontal_Positioning: {
SkPoint dfOffset = SkPoint::Make(x, y + offset.y());
GrTextUtils::DrawDFPosText(cacheBlob, run, fontCache,
- props, runPaint, color, viewMatrix,
+ props, runPaint, color, fakeGamma, viewMatrix,
(const char*)it.glyphs(), textLen, it.pos(),
1, dfOffset);
break;
@@ -210,7 +224,7 @@ void GrAtlasTextContext::RegenerateTextBlob(GrAtlasTextBlob* cacheBlob,
case SkTextBlob::kFull_Positioning: {
SkPoint dfOffset = SkPoint::Make(x, y);
GrTextUtils::DrawDFPosText(cacheBlob, run, fontCache,
- props, runPaint, color, viewMatrix,
+ props, runPaint, color, fakeGamma, viewMatrix,
(const char*)it.glyphs(), textLen, it.pos(),
2, dfOffset);
break;
@@ -222,19 +236,19 @@ void GrAtlasTextContext::RegenerateTextBlob(GrAtlasTextBlob* cacheBlob,
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning:
GrTextUtils::DrawBmpText(cacheBlob, run, fontCache,
- props, runPaint, color, viewMatrix,
+ props, runPaint, color, fakeGamma, viewMatrix,
(const char *)it.glyphs(), textLen,
x + offset.x(), y + offset.y());
break;
case SkTextBlob::kHorizontal_Positioning:
GrTextUtils::DrawBmpPosText(cacheBlob, run, fontCache,
- props, runPaint, color, viewMatrix,
+ props, runPaint, color, fakeGamma, viewMatrix,
(const char*)it.glyphs(), textLen, it.pos(), 1,
SkPoint::Make(x, y + offset.y()));
break;
case SkTextBlob::kFull_Positioning:
GrTextUtils::DrawBmpPosText(cacheBlob, run, fontCache,
- props, runPaint, color, viewMatrix,
+ props, runPaint, color, fakeGamma, viewMatrix,
(const char*)it.glyphs(), textLen, it.pos(), 2,
SkPoint::Make(x, y));
break;
@@ -254,6 +268,7 @@ GrAtlasTextContext::CreateDrawTextBlob(GrTextBlobCache* blobCache,
const GrShaderCaps& shaderCaps,
const GrPaint& paint,
const SkPaint& skPaint,
+ SkPaint::FakeGamma fakeGamma,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
const char text[], size_t byteLength,
@@ -265,11 +280,11 @@ GrAtlasTextContext::CreateDrawTextBlob(GrTextBlobCache* blobCache,
if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, props, shaderCaps)) {
GrTextUtils::DrawDFText(blob, 0, fontCache, props,
- skPaint, paint.getColor(), viewMatrix, text,
+ skPaint, paint.getColor(), fakeGamma, viewMatrix, text,
byteLength, x, y);
} else {
GrTextUtils::DrawBmpText(blob, 0, fontCache, props, skPaint,
- paint.getColor(), viewMatrix, text, byteLength, x, y);
+ paint.getColor(), fakeGamma, viewMatrix, text, byteLength, x, y);
}
return blob;
}
@@ -277,7 +292,7 @@ GrAtlasTextContext::CreateDrawTextBlob(GrTextBlobCache* blobCache,
inline GrAtlasTextBlob*
GrAtlasTextContext::CreateDrawPosTextBlob(GrTextBlobCache* blobCache, GrBatchFontCache* fontCache,
const GrShaderCaps& shaderCaps, const GrPaint& paint,
- const SkPaint& skPaint,
+ const SkPaint& skPaint, SkPaint::FakeGamma fakeGamma,
const SkMatrix& viewMatrix, const SkSurfaceProps& props,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
@@ -289,11 +304,11 @@ GrAtlasTextContext::CreateDrawPosTextBlob(GrTextBlobCache* blobCache, GrBatchFon
if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, props, shaderCaps)) {
GrTextUtils::DrawDFPosText(blob, 0, fontCache, props,
- skPaint, paint.getColor(), viewMatrix, text,
+ skPaint, paint.getColor(), fakeGamma, viewMatrix, text,
byteLength, pos, scalarsPerPosition, offset);
} else {
GrTextUtils::DrawBmpPosText(blob, 0, fontCache, props, skPaint,
- paint.getColor(), viewMatrix, text,
+ paint.getColor(), fakeGamma, viewMatrix, text,
byteLength, pos, scalarsPerPosition, offset);
}
return blob;
@@ -314,6 +329,7 @@ void GrAtlasTextContext::drawText(GrContext* context,
CreateDrawTextBlob(context->getTextBlobCache(), context->getBatchFontCache(),
*context->caps()->shaderCaps(),
paint, skPaint,
+ ComputeFakeGamma(dc, paint),
viewMatrix, props,
text, byteLength, x, y));
blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint, paint,
@@ -342,7 +358,9 @@ void GrAtlasTextContext::drawPosText(GrContext* context,
CreateDrawPosTextBlob(context->getTextBlobCache(),
context->getBatchFontCache(),
*context->caps()->shaderCaps(),
- paint, skPaint, viewMatrix, props,
+ paint, skPaint,
+ ComputeFakeGamma(dc, paint),
+ viewMatrix, props,
text, byteLength,
pos, scalarsPerPosition,
offset));
@@ -405,6 +423,7 @@ DRAW_BATCH_TEST_DEFINE(TextBlobBatch) {
GrAtlasTextContext::CreateDrawTextBlob(context->getTextBlobCache(),
context->getBatchFontCache(),
*context->caps()->shaderCaps(), grPaint, skPaint,
+ GrAtlasTextContext::kTextBlobBatchFakeGamma,
viewMatrix,
gSurfaceProps, text,
static_cast<size_t>(textLen), x, y));
diff --git a/src/gpu/text/GrAtlasTextContext.h b/src/gpu/text/GrAtlasTextContext.h
index edc157552a..a784acb72c 100644
--- a/src/gpu/text/GrAtlasTextContext.h
+++ b/src/gpu/text/GrAtlasTextContext.h
@@ -52,10 +52,12 @@ private:
// sets up the descriptor on the blob and returns a detached cache. Client must attach
inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd);
+ // Determines if we need to use FakeGamma:
+ inline static SkPaint::FakeGamma ComputeFakeGamma(GrDrawContext*, const GrPaint&);
static void RegenerateTextBlob(GrAtlasTextBlob* bmp,
GrBatchFontCache*,
const GrShaderCaps&,
- const SkPaint& skPaint, GrColor,
+ const SkPaint& skPaint, GrColor, SkPaint::FakeGamma,
const SkMatrix& viewMatrix,
const SkSurfaceProps&,
const SkTextBlob* blob, SkScalar x, SkScalar y,
@@ -65,14 +67,16 @@ private:
static inline GrAtlasTextBlob* CreateDrawTextBlob(GrTextBlobCache*,
GrBatchFontCache*, const GrShaderCaps&,
const GrPaint&,
- const SkPaint&, const SkMatrix& viewMatrix,
+ const SkPaint&, SkPaint::FakeGamma,
+ const SkMatrix& viewMatrix,
const SkSurfaceProps&,
const char text[], size_t byteLength,
SkScalar x, SkScalar y);
static inline GrAtlasTextBlob* CreateDrawPosTextBlob(GrTextBlobCache*, GrBatchFontCache*,
const GrShaderCaps&,
const GrPaint&,
- const SkPaint&, const SkMatrix& viewMatrix,
+ const SkPaint&, SkPaint::FakeGamma,
+ const SkMatrix& viewMatrix,
const SkSurfaceProps&,
const char text[], size_t byteLength,
const SkScalar pos[],
@@ -83,6 +87,7 @@ private:
SkAutoTUnref<const GrDistanceFieldAdjustTable> fDistanceAdjustTable;
#ifdef GR_TEST_UTILS
+ static const SkPaint::FakeGamma kTextBlobBatchFakeGamma = SkPaint::FakeGamma::On;
DRAW_BATCH_TEST_FRIEND(TextBlobBatch);
#endif
};
diff --git a/src/gpu/text/GrTextUtils.cpp b/src/gpu/text/GrTextUtils.cpp
index 0b26c84168..ad5c040977 100644
--- a/src/gpu/text/GrTextUtils.cpp
+++ b/src/gpu/text/GrTextUtils.cpp
@@ -40,7 +40,7 @@ static const int kLargeDFFontLimit = 2 * kLargeDFFontSize;
void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex,
GrBatchFontCache* fontCache,
const SkSurfaceProps& props, const SkPaint& skPaint,
- GrColor color,
+ GrColor color, SkPaint::FakeGamma fakeGamma,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
@@ -57,7 +57,7 @@ void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex,
GrBatchTextStrike* currStrike = nullptr;
// Get GrFontScaler from cache
- SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::FakeGamma::On,
+ SkGlyphCache* cache = blob->setupCache(runIndex, props, fakeGamma,
skPaint, &viewMatrix);
GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache);
@@ -80,7 +80,7 @@ void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex,
void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex,
GrBatchFontCache* fontCache,
const SkSurfaceProps& props, const SkPaint& skPaint,
- GrColor color,
+ GrColor color, SkPaint::FakeGamma fakeGamma,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
@@ -99,7 +99,7 @@ void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex,
GrBatchTextStrike* currStrike = nullptr;
// Get GrFontScaler from cache
- SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::FakeGamma::On,
+ SkGlyphCache* cache = blob->setupCache(runIndex, props, fakeGamma,
skPaint, &viewMatrix);
GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache);
@@ -247,7 +247,7 @@ void GrTextUtils::InitDistanceFieldPaint(GrAtlasTextBlob* blob,
void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex,
GrBatchFontCache* fontCache, const SkSurfaceProps& props,
- const SkPaint& skPaint, GrColor color,
+ const SkPaint& skPaint, GrColor color, SkPaint::FakeGamma fakeGamma,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
@@ -260,6 +260,8 @@ void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex,
SkPaint::GlyphCacheProc glyphCacheProc = skPaint.getGlyphCacheProc(true);
SkAutoDescriptor desc;
+ // We apply the fake-gamma by altering the distance in the shader, so we ignore the
+ // fakeGamma parameter. (It's only used when we fall-back to bitmap text).
skPaint.getScalerContextDescriptor(&desc, props, SkPaint::FakeGamma::Off, nullptr);
SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface(),
desc.getDesc());
@@ -310,14 +312,15 @@ void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex,
y -= alignY;
SkPoint offset = SkPoint::Make(x, y);
- DrawDFPosText(blob, runIndex, fontCache, props, skPaint, color, viewMatrix, text, byteLength,
- positions.begin(), 2, offset);
+ DrawDFPosText(blob, runIndex, fontCache, props, skPaint, color, fakeGamma, viewMatrix,
+ text, byteLength, positions.begin(), 2, offset);
}
void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
GrBatchFontCache* fontCache, const SkSurfaceProps& props,
const SkPaint& origPaint,
- GrColor color, const SkMatrix& viewMatrix,
+ GrColor color, SkPaint::FakeGamma fakeGamma,
+ const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) {
@@ -341,6 +344,8 @@ void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
GrBatchTextStrike* currStrike = nullptr;
+ // We apply the fake-gamma by altering the distance in the shader, so we ignore the
+ // fakeGamma parameter. (It's only used when we fall-back to bitmap text).
SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::FakeGamma::Off,
dfPaint, nullptr);
SkPaint::GlyphCacheProc glyphCacheProc = dfPaint.getGlyphCacheProc(true);
@@ -415,7 +420,7 @@ void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
if (fallbackTxt.count()) {
blob->initOverride(runIndex);
GrTextUtils::DrawBmpPosText(blob, runIndex, fontCache, props,
- origPaint, origPaint.getColor(), viewMatrix,
+ origPaint, origPaint.getColor(), fakeGamma, viewMatrix,
fallbackTxt.begin(), fallbackTxt.count(),
fallbackPos.begin(), scalarsPerPosition, offset);
}
diff --git a/src/gpu/text/GrTextUtils.h b/src/gpu/text/GrTextUtils.h
index 096434b69f..52b3ab4c54 100644
--- a/src/gpu/text/GrTextUtils.h
+++ b/src/gpu/text/GrTextUtils.h
@@ -9,6 +9,7 @@
#define GrTextUtils_DEFINED
#include "GrColor.h"
+#include "SkPaint.h"
#include "SkScalar.h"
class GrAtlasTextBlob;
@@ -22,7 +23,6 @@ class GrShaderCaps;
class SkGlyph;
class SkMatrix;
struct SkIRect;
-class SkPaint;
struct SkPoint;
class SkGlyphCache;
class SkSurfaceProps;
@@ -38,13 +38,13 @@ public:
static void DrawBmpText(GrAtlasTextBlob*, int runIndex,
GrBatchFontCache*, const SkSurfaceProps&,
const SkPaint&,
- GrColor, const SkMatrix& viewMatrix,
+ GrColor, SkPaint::FakeGamma, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y);
static void DrawBmpPosText(GrAtlasTextBlob*, int runIndex,
GrBatchFontCache*, const SkSurfaceProps&, const SkPaint&,
- GrColor, const SkMatrix& viewMatrix,
+ GrColor, SkPaint::FakeGamma, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset);
@@ -55,14 +55,14 @@ public:
static void DrawDFText(GrAtlasTextBlob* blob, int runIndex,
GrBatchFontCache*, const SkSurfaceProps&,
- const SkPaint& skPaint, GrColor color,
+ const SkPaint& skPaint, GrColor color, SkPaint::FakeGamma,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y);
static void DrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
GrBatchFontCache*, const SkSurfaceProps&, const SkPaint&,
- GrColor color, const SkMatrix& viewMatrix,
+ GrColor color, SkPaint::FakeGamma, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset);