diff options
author | brianosman <brianosman@google.com> | 2016-06-02 05:49:21 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-02 05:49:21 -0700 |
commit | 33f6b3f6ee4de24282f5e7f2dc31a5f538bcf40c (patch) | |
tree | a42a432cb1d2460a2de870f4506271c720d5b0e7 /gm/gamma.cpp | |
parent | 0851d2d04716ad4a7c7a646a5846a81db3d5b925 (diff) |
Manually generated sRGB mipmaps, with successively smaller draws.
Dirty GL-generated mipmaps whenever an sRGB texture is used with a new
value for TEXTURE_SRGB_DECODE. Add a new test rectangle to the gamma GM
that tests that textures are correctly converted to linear before
filtering when generating mipmaps.
Added a new unit test that alternates how a texture is interpreted (sRGB
or not), to verify that we rebuild mipmaps when needed, and that we get
the correct results out in both modes.
This test originally failed on four of our bots producing incorrect mips
in three different ways. I'm not real surprised, but it looks like
we can't rely on glGenerateMipmap to do the right thing, in conjunction
with TEXTURE_SRGB_DECODE.
Instead, actually create mip-chains using a series of draw calls.
(My first attempt used glBlitFramebuffer, and that still had bugs on
several bots). This approach appears to work correctly on any device
that fully supports sRGB.
Because the mipmap draws are fairly destructive to state, I had to
hoist them out of bindTexture. That means adding a second pass over
the texture accesses in the processor, at the very beginning of flush.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1840473002
Review-Url: https://codereview.chromium.org/2007973002
Diffstat (limited to 'gm/gamma.cpp')
-rw-r--r-- | gm/gamma.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/gm/gamma.cpp b/gm/gamma.cpp index 5dbfb9425b..25608d26b3 100644 --- a/gm/gamma.cpp +++ b/gm/gamma.cpp @@ -10,7 +10,7 @@ #include "Resources.h" #include "SkGradientShader.h" -DEF_SIMPLE_GM(gamma, canvas, 500, 200) { +DEF_SIMPLE_GM(gamma, canvas, 560, 200) { SkPaint p; const SkScalar sz = 50.0f; const int szInt = SkScalarTruncToInt(sz); @@ -34,8 +34,19 @@ DEF_SIMPLE_GM(gamma, canvas, 500, 200) { SkImageInfo srgbGreyInfo = SkImageInfo::MakeN32(szInt, szInt, kOpaque_SkAlphaType, kSRGB_SkColorProfileType); srgbGreyBmp.allocPixels(srgbGreyInfo); + // 0xBC = 255 * linear_to_srgb(0.5f) srgbGreyBmp.eraseARGB(0xFF, 0xBC, 0xBC, 0xBC); + SkBitmap mipmapBmp; + SkImageInfo mipmapInfo = SkImageInfo::MakeN32(2, 2, kOpaque_SkAlphaType, + kSRGB_SkColorProfileType); + mipmapBmp.allocPixels(mipmapInfo); + SkPMColor* mipmapPixels = reinterpret_cast<SkPMColor*>(mipmapBmp.getPixels()); + // 0x89 = 255 * linear_to_srgb(0.25f) + mipmapPixels[0] = mipmapPixels[3] = SkPackARGB32(0xFF, 0x89, 0x89, 0x89); + // 0xE1 = 255 * linear_to_srgb(0.75f) + mipmapPixels[1] = mipmapPixels[2] = SkPackARGB32(0xFF, 0xE1, 0xE1, 0xE1); + SkPaint textPaint; textPaint.setColor(SK_ColorWHITE); @@ -107,6 +118,12 @@ DEF_SIMPLE_GM(gamma, canvas, 500, 200) { p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); nextRect("Dither", "Scale"); + // 25%/75% dither, scaled down by 2x. Tests ALL aspects of minification. Specifically, are + // sRGB sources decoded to linear before computing mipmaps? + p.setShader(SkShader::MakeBitmapShader(mipmapBmp, rpt, rpt, &scaleMatrix)); + p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); + nextRect("MipMaps", 0); + // 50% grey via paint color. p.setColor(0xff7f7f7f); nextRect("Color", 0); |