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

Unified Diff: gm/alphagradients.cpp

Issue 15893002: Add flag to gradients to interpolate colors in premul space. Experimental API to encapsulate the sh… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 7 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 | gyp/gmslides.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/alphagradients.cpp
diff --git a/gm/alphagradients.cpp b/gm/alphagradients.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d335a9d7e5fbfe2b5f621942a6d7792e4954221a
--- /dev/null
+++ b/gm/alphagradients.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkCanvas.h"
+#include "SkGradientShader.h"
+
+class AlphaGradientsGM : public skiagm::GM {
+public:
+ AlphaGradientsGM() {}
+
+protected:
+ virtual SkString onShortName() SK_OVERRIDE {
+ return SkString("alphagradients");
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(640, 480);
+ }
+
+ static void draw_grad(SkCanvas* canvas, const SkRect& r,
+ SkColor c0, SkColor c1, bool doPreMul) {
+ SkColor colors[] = { c0, c1 };
+ SkPoint pts[] = { { r.fLeft, r.fTop }, { r.fRight, r.fBottom } };
+ SkPaint paint;
+ uint32_t flags = doPreMul ? SkGradientShader::kInterpolateColorsInPremul_Flag : 0;
+ SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 2,
+ SkShader::kClamp_TileMode,
+ NULL, flags);
+ paint.setShader(s)->unref();
+ canvas->drawRect(r, paint);
+
+ paint.setShader(NULL);
+ paint.setStyle(SkPaint::kStroke_Style);
+ canvas->drawRect(r, paint);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ static const struct {
+ SkColor fColor0;
+ SkColor fColor1;
+ } gRec[] = {
+ { 0xFFFFFFFF, 0x00000000 },
+ { 0xFFFFFFFF, 0x00FF0000 },
+ { 0xFFFFFFFF, 0x00FFFF00 },
+ { 0xFFFFFFFF, 0x00FFFFFF },
+ { 0xFFFF0000, 0x00000000 },
+ { 0xFFFF0000, 0x00FF0000 },
+ { 0xFFFF0000, 0x00FFFF00 },
+ { 0xFFFF0000, 0x00FFFFFF },
+ { 0xFF0000FF, 0x00000000 },
+ { 0xFF0000FF, 0x00FF0000 },
+ { 0xFF0000FF, 0x00FFFF00 },
+ { 0xFF0000FF, 0x00FFFFFF },
+ };
+
+ SkRect r = SkRect::MakeWH(300, 30);
+
+ canvas->translate(10, 10);
+
+ for (int doPreMul = 0; doPreMul <= 1; ++doPreMul) {
+ canvas->save();
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
+ draw_grad(canvas, r, gRec[i].fColor0, gRec[i].fColor1, SkToBool(doPreMul));
+ canvas->translate(0, r.height() + 8);
+ }
+ canvas->restore();
+ canvas->translate(r.width() + 10, 0);
+ }
+ }
+
+ virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; }
+
+private:
+ typedef skiagm::GM INHERITED;
+};
+
+DEF_GM( return SkNEW(AlphaGradientsGM); )
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698