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

Unified Diff: src/gpu/effects/GrDistanceFieldTextureEffect.cpp

Issue 1042373002: Emulate gamma fix by making glyphs thicker or thinner (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase to ToT 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/effects/GrDistanceFieldTextureEffect.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/effects/GrDistanceFieldTextureEffect.cpp
diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
index 0acf1f324a09a152611ee025057f6f6c8ee0eac6..85c561d9339601ee3d08aeeb7e84c012cb372fa4 100755
--- a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
+++ b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
@@ -9,7 +9,11 @@
#include "GrFontAtlasSizes.h"
#include "GrInvariantOutput.h"
#include "GrTexture.h"
+
#include "SkDistanceFieldGen.h"
+
+#include "../utils/SkCamera.h"
bungeman-skia 2015/04/01 15:38:56 Seems like you can remove this?
jvanverth1 2015/04/01 15:42:13 Done.
+
#include "gl/GrGLProcessor.h"
#include "gl/GrGLSL.h"
#include "gl/GrGLTexture.h"
@@ -31,7 +35,7 @@ public:
const GrBatchTracker&)
: fColor(GrColor_ILLEGAL)
#ifdef SK_GAMMA_APPLY_TO_A8
- , fLuminance(-1.0f)
+ , fWidthAdjust(-1.0f)
#endif
{}
@@ -59,6 +63,14 @@ public:
vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", "
GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(),
dfTexEffect.inTextureCoords()->fName);
+#ifdef SK_GAMMA_APPLY_TO_A8
+ // adjust based on gamma
+ const char* widthAdjustUniName = NULL;
+ // width, height, 1/(3*width)
+ fWidthAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ kFloat_GrSLType, kDefault_GrSLPrecision,
+ "WidthAdjust", &widthAdjustUniName);
+#endif
// Setup pass through color
this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor,
@@ -83,6 +95,10 @@ public:
fsBuilder->codeAppend(".r;\n");
fsBuilder->codeAppend("\tfloat distance = "
SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");");
+#ifdef SK_GAMMA_APPLY_TO_A8
+ // adjust width based on gamma
+ fsBuilder->codeAppendf("distance -= %s;", widthAdjustUniName);
+#endif
fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision,
pb->ctxInfo().standard()));
@@ -119,21 +135,6 @@ public:
}
fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distance);");
-#ifdef SK_GAMMA_APPLY_TO_A8
- // adjust based on gamma
- const char* luminanceUniName = NULL;
- // width, height, 1/(3*width)
- fLuminanceUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType, kDefault_GrSLPrecision,
- "Luminance", &luminanceUniName);
-
- fsBuilder->codeAppendf("\tuv = vec2(val, %s);\n", luminanceUniName);
- fsBuilder->codeAppend("\tvec4 gammaColor = ");
- fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType);
- fsBuilder->codeAppend(";\n");
- fsBuilder->codeAppend("\tval = gammaColor.r;\n");
-#endif
-
fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage);
}
@@ -143,10 +144,10 @@ public:
#ifdef SK_GAMMA_APPLY_TO_A8
const GrDistanceFieldTextureEffect& dfTexEffect =
proc.cast<GrDistanceFieldTextureEffect>();
- float luminance = dfTexEffect.getLuminance();
- if (luminance != fLuminance) {
- pdman.set1f(fLuminanceUni, luminance);
- fLuminance = luminance;
+ float widthAdjust = dfTexEffect.getWidthAdjust();
+ if (widthAdjust != fWidthAdjust) {
+ pdman.set1f(fWidthAdjustUni, widthAdjust);
+ fWidthAdjust = widthAdjust;
}
#endif
@@ -178,8 +179,8 @@ private:
GrColor fColor;
UniformHandle fColorUniform;
#ifdef SK_GAMMA_APPLY_TO_A8
- UniformHandle fLuminanceUni;
- float fLuminance;
+ float fWidthAdjust;
+ UniformHandle fWidthAdjustUni;
#endif
typedef GrGLGeometryProcessor INHERITED;
@@ -192,16 +193,13 @@ GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrColor color,
GrTexture* texture,
const GrTextureParams& params,
#ifdef SK_GAMMA_APPLY_TO_A8
- GrTexture* gamma,
- const GrTextureParams& gammaParams,
- float luminance,
+ float widthAdjust,
#endif
uint32_t flags, bool opaqueVertexColors)
: INHERITED(color, viewMatrix, SkMatrix::I(), opaqueVertexColors)
, fTextureAccess(texture, params)
#ifdef SK_GAMMA_APPLY_TO_A8
- , fGammaTextureAccess(gamma, gammaParams)
- , fLuminance(luminance)
+ , fWidthAdjust(widthAdjust)
#endif
, fFlags(flags & kNonLCD_DistanceFieldEffectMask)
, fInColor(NULL) {
@@ -215,16 +213,13 @@ GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrColor color,
fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
kVec2s_GrVertexAttribType));
this->addTextureAccess(&fTextureAccess);
-#ifdef SK_GAMMA_APPLY_TO_A8
- this->addTextureAccess(&fGammaTextureAccess);
-#endif
}
bool GrDistanceFieldTextureEffect::onIsEqual(const GrGeometryProcessor& other) const {
const GrDistanceFieldTextureEffect& cte = other.cast<GrDistanceFieldTextureEffect>();
return
#ifdef SK_GAMMA_APPLY_TO_A8
- fLuminance == cte.fLuminance &&
+ fWidthAdjust == cte.fWidthAdjust &&
#endif
fFlags == cte.fFlags;
}
@@ -273,10 +268,6 @@ GrGeometryProcessor* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random,
GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
GrProcessorUnitTest::kAlphaTextureIdx;
-#ifdef SK_GAMMA_APPLY_TO_A8
- int texIdx2 = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
- GrProcessorUnitTest::kAlphaTextureIdx;
-#endif
static const SkShader::TileMode kTileModes[] = {
SkShader::kClamp_TileMode,
SkShader::kRepeat_TileMode,
@@ -288,16 +279,11 @@ GrGeometryProcessor* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random,
};
GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
GrTextureParams::kNone_FilterMode);
-#ifdef SK_GAMMA_APPLY_TO_A8
- GrTextureParams params2(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
- GrTextureParams::kNone_FilterMode);
-#endif
return GrDistanceFieldTextureEffect::Create(GrRandomColor(random),
GrProcessorUnitTest::TestMatrix(random),
textures[texIdx], params,
#ifdef SK_GAMMA_APPLY_TO_A8
- textures[texIdx2], params2,
random->nextF(),
#endif
random->nextBool() ?
@@ -563,8 +549,9 @@ class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor {
public:
GrGLDistanceFieldLCDTextureEffect(const GrGeometryProcessor&,
const GrBatchTracker&)
- : fColor(GrColor_ILLEGAL)
- , fTextColor(GrColor_ILLEGAL) {}
+ : fColor(GrColor_ILLEGAL) {
+ fWidthAdjust = GrDistanceFieldLCDTextureEffect::WidthAdjust::Make(1.0f, 1.0f, 1.0f);
+ }
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
const GrDistanceFieldLCDTextureEffect& dfTexEffect =
@@ -650,6 +637,13 @@ public:
fsBuilder->codeAppend("\tdistance = "
"vec3(" SK_DistanceFieldMultiplier ")*(distance - vec3(" SK_DistanceFieldThreshold"));");
+ // adjust width based on gamma
+ const char* widthAdjustUniName = NULL;
+ fWidthAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ kVec3f_GrSLType, kDefault_GrSLPrecision,
+ "WidthAdjust", &widthAdjustUniName);
+ fsBuilder->codeAppendf("distance -= %s;", widthAdjustUniName);
+
// To be strictly correct, we should compute the anti-aliasing factor separately
// for each color component. However, this is only important when using perspective
// transformations, and even then using a single factor seems like a reasonable
@@ -684,48 +678,24 @@ public:
fsBuilder->codeAppend("vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), distance), 1.0);");
- // adjust based on gamma
- const char* textColorUniName = NULL;
- fTextColorUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kVec3f_GrSLType, kDefault_GrSLPrecision,
- "TextColor", &textColorUniName);
-
- fsBuilder->codeAppendf("\tuv = vec2(val.x, %s.x);\n", textColorUniName);
- fsBuilder->codeAppend("float gammaColor = ");
- fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType);
- fsBuilder->codeAppend(".r;\n");
- fsBuilder->codeAppend("\tval.x = gammaColor;\n");
-
- fsBuilder->codeAppendf("\tuv = vec2(val.y, %s.y);\n", textColorUniName);
- fsBuilder->codeAppend("\tgammaColor = ");
- fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType);
- fsBuilder->codeAppend(".r;\n");
- fsBuilder->codeAppend("\tval.y = gammaColor;\n");
-
- fsBuilder->codeAppendf("\tuv = vec2(val.z, %s.z);\n", textColorUniName);
- fsBuilder->codeAppend("\tgammaColor = ");
- fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType);
- fsBuilder->codeAppend(".r;\n");
- fsBuilder->codeAppend("\tval.z = gammaColor;\n");
-
fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage);
}
virtual void setData(const GrGLProgramDataManager& pdman,
const GrPrimitiveProcessor& processor,
const GrBatchTracker& bt) override {
- SkASSERT(fTextColorUni.isValid());
+ SkASSERT(fWidthAdjustUni.isValid());
const GrDistanceFieldLCDTextureEffect& dfTexEffect =
processor.cast<GrDistanceFieldLCDTextureEffect>();
- GrColor textColor = dfTexEffect.getTextColor();
- if (textColor != fTextColor) {
+ GrDistanceFieldLCDTextureEffect::WidthAdjust wa = dfTexEffect.getWidthAdjust();
+ if (wa != fWidthAdjust) {
static const float ONE_OVER_255 = 1.f / 255.f;
- pdman.set3f(fTextColorUni,
- GrColorUnpackR(textColor) * ONE_OVER_255,
- GrColorUnpackG(textColor) * ONE_OVER_255,
- GrColorUnpackB(textColor) * ONE_OVER_255);
- fTextColor = textColor;
+ pdman.set3f(fWidthAdjustUni,
+ wa.fR,
+ wa.fG,
+ wa.fB);
+ fWidthAdjust = wa;
}
this->setUniformViewMatrix(pdman, processor.viewMatrix());
@@ -755,10 +725,10 @@ public:
}
private:
- GrColor fColor;
- UniformHandle fColorUniform;
- UniformHandle fTextColorUni;
- SkColor fTextColor;
+ GrColor fColor;
+ UniformHandle fColorUniform;
+ GrDistanceFieldLCDTextureEffect::WidthAdjust fWidthAdjust;
+ UniformHandle fWidthAdjustUni;
typedef GrGLGeometryProcessor INHERITED;
};
@@ -768,13 +738,11 @@ private:
GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect(
GrColor color, const SkMatrix& viewMatrix,
GrTexture* texture, const GrTextureParams& params,
- GrTexture* gamma, const GrTextureParams& gParams,
- SkColor textColor,
+ WidthAdjust widthAdjust,
uint32_t flags)
: INHERITED(color, viewMatrix, SkMatrix::I())
, fTextureAccess(texture, params)
- , fGammaTextureAccess(gamma, gParams)
- , fTextColor(textColor)
+ , fWidthAdjust(widthAdjust)
, fFlags(flags & kLCD_DistanceFieldEffectMask){
SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_DistanceFieldEffectFlag));
this->initClassID<GrDistanceFieldLCDTextureEffect>();
@@ -782,12 +750,11 @@ GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect(
fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
kVec2s_GrVertexAttribType));
this->addTextureAccess(&fTextureAccess);
- this->addTextureAccess(&fGammaTextureAccess);
}
bool GrDistanceFieldLCDTextureEffect::onIsEqual(const GrGeometryProcessor& other) const {
const GrDistanceFieldLCDTextureEffect& cte = other.cast<GrDistanceFieldLCDTextureEffect>();
- return (fTextColor == cte.fTextColor &&
+ return (fWidthAdjust == cte.fWidthAdjust &&
fFlags == cte.fFlags);
}
@@ -836,8 +803,6 @@ GrGeometryProcessor* GrDistanceFieldLCDTextureEffect::TestCreate(SkRandom* rando
GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
GrProcessorUnitTest::kAlphaTextureIdx;
- int texIdx2 = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
- GrProcessorUnitTest::kAlphaTextureIdx;
static const SkShader::TileMode kTileModes[] = {
SkShader::kClamp_TileMode,
SkShader::kRepeat_TileMode,
@@ -849,19 +814,13 @@ GrGeometryProcessor* GrDistanceFieldLCDTextureEffect::TestCreate(SkRandom* rando
};
GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
GrTextureParams::kNone_FilterMode);
- GrTextureParams params2(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
- GrTextureParams::kNone_FilterMode);
- GrColor textColor = GrColorPackRGBA(random->nextULessThan(256),
- random->nextULessThan(256),
- random->nextULessThan(256),
- random->nextULessThan(256));
+ WidthAdjust wa = { 0.0f, 0.1f, -0.1f };
uint32_t flags = kUseLCD_DistanceFieldEffectFlag;
flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0;
flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random),
GrProcessorUnitTest::TestMatrix(random),
textures[texIdx], params,
- textures[texIdx2], params2,
- textColor,
+ wa,
flags);
}
« no previous file with comments | « src/gpu/effects/GrDistanceFieldTextureEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698