aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/shallowgradient.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-04 16:56:15 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-04 16:56:15 +0000
commit83f7c659461d602e498569dab63f04b1b578b742 (patch)
tree45950f79b37420470088bd038bb70f954a524ddd /gm/shallowgradient.cpp
parent5b7bac5ce162eee6d73c33373029a4e5a9f94683 (diff)
add new gms for shallow_gradient, in preparation for improving their quality
git-svn-id: http://skia.googlecode.com/svn/trunk@7544 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/shallowgradient.cpp')
-rw-r--r--gm/shallowgradient.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/gm/shallowgradient.cpp b/gm/shallowgradient.cpp
new file mode 100644
index 0000000000..672193d956
--- /dev/null
+++ b/gm/shallowgradient.cpp
@@ -0,0 +1,77 @@
+/*
+ * 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 "SkGradientShader.h"
+
+typedef SkShader* (*MakeShaderProc)(const SkColor[], int count, const SkSize&);
+
+static SkShader* shader_linear(const SkColor colors[], int count, const SkSize& size) {
+ SkPoint pts[] = { { 0, 0 }, { size.width(), size.height() } };
+ return SkGradientShader::CreateLinear(pts, colors, NULL, count,
+ SkShader::kClamp_TileMode);
+}
+
+static SkShader* shader_radial(const SkColor colors[], int count, const SkSize& size) {
+ SkPoint center = { size.width()/2, size.height()/2 };
+ return SkGradientShader::CreateRadial(center, size.width()/2, colors, NULL, count,
+ SkShader::kClamp_TileMode);
+}
+
+static SkShader* shader_conical(const SkColor colors[], int count, const SkSize& size) {
+ SkPoint center = { size.width()/2, size.height()/2 };
+ return SkGradientShader::CreateTwoPointConical(center, size.width()/64,
+ center, size.width()/2,
+ colors, NULL, count,
+ SkShader::kClamp_TileMode);
+}
+
+static SkShader* shader_sweep(const SkColor colors[], int count, const SkSize& size) {
+ return SkGradientShader::CreateSweep(size.width()/2, size.height()/2,
+ colors, NULL, count);
+}
+
+class ShallowGradientGM : public skiagm::GM {
+public:
+ ShallowGradientGM(MakeShaderProc proc, const char name[]) : fProc(proc) {
+ fName.printf("shallow_gradient_%s", name);
+ }
+
+protected:
+ virtual SkString onShortName() SK_OVERRIDE {
+ return fName;
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(800, 800);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ const SkColor colors[] = { 0xFF555555, 0xFF444444 };
+ const int colorCount = SK_ARRAY_COUNT(colors);
+
+ SkRect r = { 0, 0, this->width(), this->height() };
+ SkSize size = SkSize::Make(r.width(), r.height());
+
+ SkPaint paint;
+ paint.setShader(fProc(colors, colorCount, size));
+ canvas->drawRect(r, paint);
+ }
+
+private:
+ MakeShaderProc fProc;
+ SkString fName;
+
+ typedef skiagm::GM INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+DEF_GM( return new ShallowGradientGM(shader_linear, "linear"); )
+DEF_GM( return new ShallowGradientGM(shader_radial, "radial"); )
+DEF_GM( return new ShallowGradientGM(shader_conical, "conical"); )
+DEF_GM( return new ShallowGradientGM(shader_sweep, "sweep"); )