From 490452ec4743813b9508e6fe78755ae9e006dbe2 Mon Sep 17 00:00:00 2001 From: brianosman Date: Tue, 13 Sep 2016 08:24:56 -0700 Subject: Add tests for gamma correction of gradient stops to gamma GM Includes three different cases to exercise different cases in Ganesh. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2336973003 Review-Url: https://codereview.chromium.org/2336973003 --- gm/gamma.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 11 deletions(-) (limited to 'gm/gamma.cpp') diff --git a/gm/gamma.cpp b/gm/gamma.cpp index d484aae0af..f6b4a9ceed 100644 --- a/gm/gamma.cpp +++ b/gm/gamma.cpp @@ -11,7 +11,7 @@ #include "SkGradientShader.h" #include "SkPM4fPriv.h" -DEF_SIMPLE_GM(gamma, canvas, 650, 200) { +DEF_SIMPLE_GM(gamma, canvas, 850, 200) { SkPaint p; const SkScalar sz = 50.0f; const int szInt = SkScalarTruncToInt(sz); @@ -131,16 +131,57 @@ DEF_SIMPLE_GM(gamma, canvas, 650, 200) { p.setColor(0xffbcbcbc); nextRect("Color", 0); - // Black -> White gradient, scaled to sample just the middle. - // Tests gradient interpolation. - SkPoint points[2] = { - SkPoint::Make(0 - (sz * 10), 0), - SkPoint::Make(sz + (sz * 10), 0) - }; - SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE }; - p.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2, - SkShader::kClamp_TileMode)); - nextRect("Gradient", 0); + { + // Black -> White gradient, scaled to sample just the middle. + // Tests gradient interpolation. + SkPoint points[2] = { + SkPoint::Make(0 - (sz * 10), 0), + SkPoint::Make(sz + (sz * 10), 0) + }; + SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE }; + p.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2, + SkShader::kClamp_TileMode)); + nextRect("Gradient", "Interpolation"); + } + + { + // Shallow gradient around 50% (perceptual) gray. Endpoints are SkColor, so sRGB. + // Tests gamma-correction of gradient stops before interpolation in two-stop case + SkPoint points[2] = { + SkPoint::Make(0, 0), + SkPoint::Make(sz, 0) + }; + SkColor colors[2] = { 0xffbbbbbb, 0xffbdbdbd }; + p.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2, + SkShader::kClamp_TileMode)); + nextRect("Gradient", "Endpoints"); + } + + { + // Shallow 3-stop gradient around 50% (perceptual) gray. Endpoints are SkColor, so sRGB. + // Tests gamma-correction of gradient stops before interpolation in three-stop case + SkPoint points[2] = { + SkPoint::Make(0, 0), + SkPoint::Make(sz, 0) + }; + SkColor colors[3] = { 0xffbbbbbb, 0xffbdbdbd, 0xffbbbbbb }; + p.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 3, + SkShader::kClamp_TileMode)); + nextRect("Gradient", "3-Stop"); + } + + { + // Shallow N-stop gradient around 50% (perceptual) gray. Endpoints are SkColor, so sRGB. + // Tests gamma-correction of gradient stops before interpolation in texture implementation + SkPoint points[2] = { + SkPoint::Make(0, 0), + SkPoint::Make(sz, 0) + }; + SkColor colors[5] = { 0xffbbbbbb, 0xffbdbdbd, 0xffbbbbbb, 0xffbdbdbd, 0xffbbbbbb }; + p.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 5, + SkShader::kClamp_TileMode)); + nextRect("Gradient", "Texture"); + } // 50% grey from linear bitmap, with drawBitmap nextBitmap(linearGreyBmp, "Lnr BMP"); -- cgit v1.2.3