diff options
author | reed <reed@google.com> | 2014-08-22 08:30:20 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-22 08:30:20 -0700 |
commit | 8367b8cb7a6b2f163ee41365323cb219b7049b15 (patch) | |
tree | a9a6eca606018fce8729acec734985388ccfe428 /gm | |
parent | 5b2c2c6fd09752641b14766678d62fe50b4e3ef3 (diff) | |
download | skia-8367b8cb7a6b2f163ee41365323cb219b7049b15.tar.gz |
extend SkShader to report a luminance-color to be used for gamma correction
BUG=skia:590
R=bungeman@google.com
Author: reed@google.com
Review URL: https://codereview.chromium.org/492963002
Diffstat (limited to 'gm')
-rw-r--r-- | gm/gammatext.cpp | 87 |
1 files changed, 81 insertions, 6 deletions
diff --git a/gm/gammatext.cpp b/gm/gammatext.cpp index cdc37fac9..54b076578 100644 --- a/gm/gammatext.cpp +++ b/gm/gammatext.cpp @@ -99,8 +99,6 @@ static void cgDrawText(CGContextRef cg, const void* text, size_t len, } #endif -namespace skiagm { - /** Test a set of clipping problems discovered while writing blitAntiRect, and test all the code paths through the clipping blitters. @@ -110,7 +108,7 @@ namespace skiagm { #define HEIGHT 480 -class GammaTextGM : public GM { +class GammaTextGM : public skiagm::GM { public: GammaTextGM() { @@ -199,12 +197,89 @@ protected: } private: - typedef GM INHERITED; + typedef skiagm::GM INHERITED; }; +DEF_GM( return new GammaTextGM; ) + ////////////////////////////////////////////////////////////////////////////// -static GM* MyFactory(void*) { return new GammaTextGM; } -static GMRegistry reg(MyFactory); +static SkShader* make_gradient(SkColor c) { + const SkPoint pts[] = { { 0, 0 }, { 240, 0 } }; + SkColor colors[2]; + colors[0] = c; + colors[1] = SkColorSetA(c, 0); + return SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode); +} + +static void set_face(SkPaint* paint) { + SkTypeface* face = SkTypeface::CreateFromName("serif", SkTypeface::kItalic); + SkSafeUnref(paint->setTypeface(face)); +} +static void draw_pair(SkCanvas* canvas, SkPaint* paint, SkShader* shader) { + const char text[] = "Now is the time for all good"; + const size_t len = strlen(text); + + paint->setShader(NULL); + canvas->drawText(text, len, 10, 20, *paint); + paint->setShader(SkShader::CreateColorShader(paint->getColor()))->unref(); + canvas->drawText(text, len, 10, 40, *paint); + paint->setShader(shader); + canvas->drawText(text, len, 10, 60, *paint); } + +class GammaShaderTextGM : public skiagm::GM { + SkShader* fShaders[3]; + SkColor fColors[3]; + +public: + GammaShaderTextGM() { + const SkColor colors[] = { SK_ColorBLACK, SK_ColorRED, SK_ColorBLUE }; + for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { + fShaders[i] = NULL; + fColors[i] = colors[i]; + } + } + + virtual ~GammaShaderTextGM() { + for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { + SkSafeUnref(fShaders[i]); + } + } + +protected: + virtual SkString onShortName() { + return SkString("gammagradienttext"); + } + + virtual SkISize onISize() { + return SkISize::Make(300, 300); + } + + virtual void onOnceBeforeDraw() { + for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { + fShaders[i] = make_gradient(fColors[i]); + } + } + + virtual void onDraw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setLCDRenderText(true); + paint.setTextSize(18); + set_face(&paint); + + for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { + paint.setColor(fColors[i]); + draw_pair(canvas, &paint, fShaders[i]); + canvas->translate(0, 80); + } + } + +private: + typedef skiagm::GM INHERITED; +}; + +DEF_GM( return new GammaShaderTextGM; ) + |