| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
| 10 | 10 |
| 11 typedef sk_sp<SkShader> (*MakeShaderProc)(const SkColor[], int count, const SkSi
ze&); | 11 typedef SkShader* (*MakeShaderProc)(const SkColor[], int count, const SkSize&); |
| 12 | 12 |
| 13 static sk_sp<SkShader> shader_linear(const SkColor colors[], int count, const Sk
Size& size) { | 13 static SkShader* shader_linear(const SkColor colors[], int count, const SkSize&
size) { |
| 14 SkPoint pts[] = { { 0, 0 }, { size.width(), size.height() } }; | 14 SkPoint pts[] = { { 0, 0 }, { size.width(), size.height() } }; |
| 15 return SkGradientShader::MakeLinear(pts, colors, nullptr, count, SkShader::k
Clamp_TileMode); | 15 return SkGradientShader::CreateLinear(pts, colors, nullptr, count, |
| 16 SkShader::kClamp_TileMode); |
| 16 } | 17 } |
| 17 | 18 |
| 18 static sk_sp<SkShader> shader_radial(const SkColor colors[], int count, const Sk
Size& size) { | 19 static SkShader* shader_radial(const SkColor colors[], int count, const SkSize&
size) { |
| 19 SkPoint center = { size.width()/2, size.height()/2 }; | 20 SkPoint center = { size.width()/2, size.height()/2 }; |
| 20 return SkGradientShader::MakeRadial(center, size.width()/2, colors, nullptr,
count, | 21 return SkGradientShader::CreateRadial(center, size.width()/2, colors, nullpt
r, count, |
| 21 SkShader::kClamp_TileMode); | 22 SkShader::kClamp_TileMode); |
| 22 } | 23 } |
| 23 | 24 |
| 24 static sk_sp<SkShader> shader_conical(const SkColor colors[], int count, const S
kSize& size) { | 25 static SkShader* shader_conical(const SkColor colors[], int count, const SkSize&
size) { |
| 25 SkPoint center = { size.width()/2, size.height()/2 }; | 26 SkPoint center = { size.width()/2, size.height()/2 }; |
| 26 return SkGradientShader::MakeTwoPointConical(center, size.width()/64, center
, size.width()/2, | 27 return SkGradientShader::CreateTwoPointConical(center, size.width()/64, |
| 27 colors, nullptr, count, SkShader
::kClamp_TileMode); | 28 center, size.width()/2, |
| 29 colors, nullptr, count, |
| 30 SkShader::kClamp_TileMode); |
| 28 } | 31 } |
| 29 | 32 |
| 30 static sk_sp<SkShader> shader_sweep(const SkColor colors[], int count, const SkS
ize& size) { | 33 static SkShader* shader_sweep(const SkColor colors[], int count, const SkSize& s
ize) { |
| 31 return SkGradientShader::MakeSweep(size.width()/2, size.height()/2, colors,
nullptr, count); | 34 return SkGradientShader::CreateSweep(size.width()/2, size.height()/2, |
| 35 colors, nullptr, count); |
| 32 } | 36 } |
| 33 | 37 |
| 34 class ShallowGradientGM : public skiagm::GM { | 38 class ShallowGradientGM : public skiagm::GM { |
| 35 public: | 39 public: |
| 36 ShallowGradientGM(MakeShaderProc proc, const char name[], bool dither) | 40 ShallowGradientGM(MakeShaderProc proc, const char name[], bool dither) |
| 37 : fProc(proc) | 41 : fProc(proc) |
| 38 , fDither(dither) { | 42 , fDither(dither) { |
| 39 fName.printf("shallow_gradient_%s", name); | 43 fName.printf("shallow_gradient_%s", name); |
| 40 } | 44 } |
| 41 | 45 |
| 42 protected: | 46 protected: |
| 43 | 47 |
| 44 SkString onShortName() override { | 48 SkString onShortName() override { |
| 45 return fName; | 49 return fName; |
| 46 } | 50 } |
| 47 | 51 |
| 48 SkISize onISize() override { | 52 SkISize onISize() override { |
| 49 return SkISize::Make(800, 800); | 53 return SkISize::Make(800, 800); |
| 50 } | 54 } |
| 51 | 55 |
| 52 void onDraw(SkCanvas* canvas) override { | 56 void onDraw(SkCanvas* canvas) override { |
| 53 const SkColor colors[] = { sk_tool_utils::color_to_565(0xFF555555), | 57 const SkColor colors[] = { sk_tool_utils::color_to_565(0xFF555555), |
| 54 sk_tool_utils::color_to_565(0xFF444444) }; | 58 sk_tool_utils::color_to_565(0xFF444444) }; |
| 55 const int colorCount = SK_ARRAY_COUNT(colors); | 59 const int colorCount = SK_ARRAY_COUNT(colors); |
| 56 | 60 |
| 57 SkRect r = { 0, 0, this->width(), this->height() }; | 61 SkRect r = { 0, 0, this->width(), this->height() }; |
| 58 SkSize size = SkSize::Make(r.width(), r.height()); | 62 SkSize size = SkSize::Make(r.width(), r.height()); |
| 59 | 63 |
| 60 SkPaint paint; | 64 SkPaint paint; |
| 61 paint.setShader(fProc(colors, colorCount, size)); | 65 paint.setShader(fProc(colors, colorCount, size))->unref(); |
| 62 paint.setDither(fDither); | 66 paint.setDither(fDither); |
| 63 canvas->drawRect(r, paint); | 67 canvas->drawRect(r, paint); |
| 64 } | 68 } |
| 65 | 69 |
| 66 private: | 70 private: |
| 67 MakeShaderProc fProc; | 71 MakeShaderProc fProc; |
| 68 SkString fName; | 72 SkString fName; |
| 69 bool fDither; | 73 bool fDither; |
| 70 | 74 |
| 71 typedef skiagm::GM INHERITED; | 75 typedef skiagm::GM INHERITED; |
| 72 }; | 76 }; |
| 73 | 77 |
| 74 /////////////////////////////////////////////////////////////////////////////// | 78 /////////////////////////////////////////////////////////////////////////////// |
| 75 | 79 |
| 76 DEF_GM( return new ShallowGradientGM(shader_linear, "linear", true); ) | 80 DEF_GM( return new ShallowGradientGM(shader_linear, "linear", true); ) |
| 77 DEF_GM( return new ShallowGradientGM(shader_radial, "radial", true); ) | 81 DEF_GM( return new ShallowGradientGM(shader_radial, "radial", true); ) |
| 78 DEF_GM( return new ShallowGradientGM(shader_conical, "conical", true); ) | 82 DEF_GM( return new ShallowGradientGM(shader_conical, "conical", true); ) |
| 79 DEF_GM( return new ShallowGradientGM(shader_sweep, "sweep", true); ) | 83 DEF_GM( return new ShallowGradientGM(shader_sweep, "sweep", true); ) |
| 80 | 84 |
| 81 DEF_GM( return new ShallowGradientGM(shader_linear, "linear_nodither", false); ) | 85 DEF_GM( return new ShallowGradientGM(shader_linear, "linear_nodither", false); ) |
| 82 DEF_GM( return new ShallowGradientGM(shader_radial, "radial_nodither", false); ) | 86 DEF_GM( return new ShallowGradientGM(shader_radial, "radial_nodither", false); ) |
| 83 DEF_GM( return new ShallowGradientGM(shader_conical, "conical_nodither", false);
) | 87 DEF_GM( return new ShallowGradientGM(shader_conical, "conical_nodither", false);
) |
| 84 DEF_GM( return new ShallowGradientGM(shader_sweep, "sweep_nodither", false); ) | 88 DEF_GM( return new ShallowGradientGM(shader_sweep, "sweep_nodither", false); ) |
| OLD | NEW |