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

Unified Diff: gm/gammatext.cpp

Issue 492963002: extend SkShader to report a luminance-color to be used for gamma correction (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase, add SkShader::CreateColorShader(c) Created 6 years, 4 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 | « no previous file | include/core/SkColorShader.h » ('j') | src/effects/gradients/SkGradientShader.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/gammatext.cpp
diff --git a/gm/gammatext.cpp b/gm/gammatext.cpp
index cdc37fac93534555607f4f4b6b3acfe9ad8f704a..54b0765783866de0522cdcaafa6bf36645ef0551 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; )
+
« no previous file with comments | « no previous file | include/core/SkColorShader.h » ('j') | src/effects/gradients/SkGradientShader.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698