diff options
author | joshualitt <joshualitt@chromium.org> | 2015-08-07 09:55:23 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-07 09:55:23 -0700 |
commit | 922c8b13c512c3287509936795735c1b31bedba9 (patch) | |
tree | d1824fc7a51ddbccfb74f26d8c933457f8b0be9c | |
parent | 469a3fe6edb3fb29acf6c03de662a6f00f6804b8 (diff) |
Break LCD and Bitmap text dependency on hardcoded atlas values
BUG=skia:
Committed: https://skia.googlesource.com/skia/+/846b022f6b469cfde285372f26e0d5c593d122ac
Review URL: https://codereview.chromium.org/1271873002
-rw-r--r-- | include/core/SkFloatingPoint.h | 9 | ||||
-rw-r--r-- | src/gpu/GrFontAtlasSizes.h | 18 | ||||
-rw-r--r-- | src/gpu/effects/GrBitmapTextGeoProc.cpp | 28 | ||||
-rwxr-xr-x | src/gpu/effects/GrDistanceFieldGeoProc.cpp | 46 |
4 files changed, 65 insertions, 36 deletions
diff --git a/include/core/SkFloatingPoint.h b/include/core/SkFloatingPoint.h index 7427562323..f7ee816b12 100644 --- a/include/core/SkFloatingPoint.h +++ b/include/core/SkFloatingPoint.h @@ -158,4 +158,13 @@ static inline float sk_float_rsqrt(const float x) { #endif } +// This is the number of significant digits we can print in a string such that when we read that +// string back we get the floating point number we expect. The minimum value C requires is 6, but +// most compilers support 9 +#ifdef FLT_DECIMAL_DIG +#define SK_FLT_DECIMAL_DIG FLT_DECIMAL_DIG +#else +#define SK_FLT_DECIMAL_DIG 9 +#endif + #endif diff --git a/src/gpu/GrFontAtlasSizes.h b/src/gpu/GrFontAtlasSizes.h index 8a3091c6c7..8722ca1a60 100644 --- a/src/gpu/GrFontAtlasSizes.h +++ b/src/gpu/GrFontAtlasSizes.h @@ -23,15 +23,6 @@ #define GR_FONT_ATLAS_NUM_PLOTS_X (GR_FONT_ATLAS_TEXTURE_WIDTH / GR_FONT_ATLAS_PLOT_WIDTH) #define GR_FONT_ATLAS_A8_NUM_PLOTS_X (GR_FONT_ATLAS_A8_TEXTURE_WIDTH / GR_FONT_ATLAS_A8_PLOT_WIDTH) #define GR_FONT_ATLAS_NUM_PLOTS_Y (GR_FONT_ATLAS_TEXTURE_HEIGHT / GR_FONT_ATLAS_PLOT_HEIGHT) - -// one over width and height -#define GR_FONT_ATLAS_RECIP_WIDTH "0.00390625"//"0.0009765625" -#define GR_FONT_ATLAS_A8_RECIP_WIDTH "0.00390625"//"0.00048828125" -#define GR_FONT_ATLAS_RECIP_HEIGHT "0.00390625"//"0.00048828125" - -// 1/(3*width) -// only used for distance fields, which are A8 -#define GR_FONT_ATLAS_LCD_DELTA "0.001302083"//"0.000162760417" #else #define GR_FONT_ATLAS_TEXTURE_WIDTH 1024 #define GR_FONT_ATLAS_A8_TEXTURE_WIDTH 2048 @@ -44,14 +35,5 @@ #define GR_FONT_ATLAS_NUM_PLOTS_X (GR_FONT_ATLAS_TEXTURE_WIDTH / GR_FONT_ATLAS_PLOT_WIDTH) #define GR_FONT_ATLAS_A8_NUM_PLOTS_X (GR_FONT_ATLAS_A8_TEXTURE_WIDTH / GR_FONT_ATLAS_A8_PLOT_WIDTH) #define GR_FONT_ATLAS_NUM_PLOTS_Y (GR_FONT_ATLAS_TEXTURE_HEIGHT / GR_FONT_ATLAS_PLOT_HEIGHT) - -// one over width and height -#define GR_FONT_ATLAS_RECIP_WIDTH "0.0009765625" -#define GR_FONT_ATLAS_A8_RECIP_WIDTH "0.00048828125" -#define GR_FONT_ATLAS_RECIP_HEIGHT "0.00048828125" - -// 1/(3*width) -// only used for distance fields, which are A8 -#define GR_FONT_ATLAS_LCD_DELTA "0.000162760417" #endif #endif diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp index a0350e99f5..9496dbffc3 100644 --- a/src/gpu/effects/GrBitmapTextGeoProc.cpp +++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp @@ -28,18 +28,19 @@ public: // emit attributes vsBuilder->emitAttributes(cte); + // compute numbers to be hardcoded to convert texture coordinates from int to float + SkASSERT(cte.numTextures() == 1); + GrTexture* atlas = cte.textureAccess(0).getTexture(); + SkASSERT(atlas); + SkScalar recipWidth = 1.0f / atlas->width(); + SkScalar recipHeight = 1.0f / atlas->height(); + GrGLVertToFrag v(kVec2f_GrSLType); pb->addVarying("TextureCoords", &v); - // this is only used with text, so our texture bounds always match the glyph atlas - if (cte.maskFormat() == kA8_GrMaskFormat) { - vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", " - GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", v.vsOut(), - cte.inTextureCoords()->fName); - } else { - vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_RECIP_WIDTH ", " - GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", v.vsOut(), - cte.inTextureCoords()->fName); - } + vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", v.vsOut(), + SK_FLT_DECIMAL_DIG, recipWidth, + SK_FLT_DECIMAL_DIG, recipHeight, + cte.inTextureCoords()->fName); // Setup pass through color if (!cte.colorIgnored()) { @@ -102,6 +103,13 @@ public: key |= gp.colorIgnored() ? 0x2 : 0x0; key |= gp.maskFormat() << 3; b->add32(key); + + // Currently we hardcode numbers to convert atlas coordinates to normalized floating point + SkASSERT(gp.numTextures() == 1); + GrTexture* atlas = gp.textureAccess(0).getTexture(); + SkASSERT(atlas); + b->add32(atlas->width()); + b->add32(atlas->height()); } private: diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp index 8af5631cc5..0b97bb2b94 100755 --- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp +++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp @@ -77,11 +77,18 @@ public: args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoords()->fName); + // compute numbers to be hardcoded to convert texture coordinates from int to float + SkASSERT(dfTexEffect.numTextures() == 1); + GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); + SkASSERT(atlas); + SkScalar recipWidth = 1.0f / atlas->width(); + SkScalar recipHeight = 1.0f / atlas->height(); + GrGLVertToFrag uv(kVec2f_GrSLType); args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); - // this is only used with text, so our texture bounds always match the glyph atlas - vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", " - GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(), + vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), + SK_FLT_DECIMAL_DIG, recipWidth, + SK_FLT_DECIMAL_DIG, recipHeight, dfTexEffect.inTextureCoords()->fName); // Use highp to work around aliasing issues @@ -176,6 +183,13 @@ public: key |= dfTexEffect.colorIgnored() << 17; key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; b->add32(key); + + // Currently we hardcode numbers to convert atlas coordinates to normalized floating point + SkASSERT(gp.numTextures() == 1); + GrTexture* atlas = gp.textureAccess(0).getTexture(); + SkASSERT(atlas); + b->add32(atlas->width()); + b->add32(atlas->height()); } private: @@ -525,11 +539,18 @@ public: args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoords()->fName); + // compute numbers to be hardcoded to convert texture coordinates from int to float + SkASSERT(dfTexEffect.numTextures() == 1); + GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); + SkASSERT(atlas); + SkScalar recipWidth = 1.0f / atlas->width(); + SkScalar recipHeight = 1.0f / atlas->height(); + GrGLVertToFrag uv(kVec2f_GrSLType); args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); - // this is only used with text, so our texture bounds always match the glyph atlas - vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", " - GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(), + vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), + SK_FLT_DECIMAL_DIG, recipWidth, + SK_FLT_DECIMAL_DIG, recipHeight, dfTexEffect.inTextureCoords()->fName); // add frag shader code @@ -545,10 +566,12 @@ public: fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, pb->ctxInfo().standard())); + + SkScalar lcdDelta = 1.0f / (3.0f * atlas->width()); if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { - fsBuilder->codeAppend("float delta = -" GR_FONT_ATLAS_LCD_DELTA ";\n"); + fsBuilder->codeAppendf("float delta = -%.*f;\n", SK_FLT_DECIMAL_DIG, lcdDelta); } else { - fsBuilder->codeAppend("float delta = " GR_FONT_ATLAS_LCD_DELTA ";\n"); + fsBuilder->codeAppendf("float delta = %.*f;\n", SK_FLT_DECIMAL_DIG, lcdDelta); } if (isUniformScale) { fsBuilder->codeAppendf("float dy = abs(dFdy(%s.y));", st.fsIn()); @@ -668,6 +691,13 @@ public: key |= dfTexEffect.colorIgnored() << 16; key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; b->add32(key); + + // Currently we hardcode numbers to convert atlas coordinates to normalized floating point + SkASSERT(gp.numTextures() == 1); + GrTexture* atlas = gp.textureAccess(0).getTexture(); + SkASSERT(atlas); + b->add32(atlas->width()); + b->add32(atlas->height()); } private: |