| 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 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 SkShader::kClamp_TileMode); | 30 SkShader::kClamp_TileMode); |
| 31 } | 31 } |
| 32 | 32 |
| 33 static SkShader* shader_sweep(const SkColor colors[], int count, const SkSize& s
ize) { | 33 static SkShader* shader_sweep(const SkColor colors[], int count, const SkSize& s
ize) { |
| 34 return SkGradientShader::CreateSweep(size.width()/2, size.height()/2, | 34 return SkGradientShader::CreateSweep(size.width()/2, size.height()/2, |
| 35 colors, nullptr, count); | 35 colors, nullptr, count); |
| 36 } | 36 } |
| 37 | 37 |
| 38 class ShallowGradientGM : public skiagm::GM { | 38 class ShallowGradientGM : public skiagm::GM { |
| 39 public: | 39 public: |
| 40 ShallowGradientGM(MakeShaderProc proc, const char name[]) : fProc(proc) { | 40 ShallowGradientGM(MakeShaderProc proc, const char name[], bool dither) |
| 41 : fProc(proc) |
| 42 , fDither(dither) { |
| 41 fName.printf("shallow_gradient_%s", name); | 43 fName.printf("shallow_gradient_%s", name); |
| 42 } | 44 } |
| 43 | 45 |
| 44 protected: | 46 protected: |
| 45 | 47 |
| 46 SkString onShortName() override { | 48 SkString onShortName() override { |
| 47 return fName; | 49 return fName; |
| 48 } | 50 } |
| 49 | 51 |
| 50 SkISize onISize() override { | 52 SkISize onISize() override { |
| 51 return SkISize::Make(800, 800); | 53 return SkISize::Make(800, 800); |
| 52 } | 54 } |
| 53 | 55 |
| 54 void onDraw(SkCanvas* canvas) override { | 56 void onDraw(SkCanvas* canvas) override { |
| 55 const SkColor colors[] = { sk_tool_utils::color_to_565(0xFF555555), | 57 const SkColor colors[] = { sk_tool_utils::color_to_565(0xFF555555), |
| 56 sk_tool_utils::color_to_565(0xFF444444) }; | 58 sk_tool_utils::color_to_565(0xFF444444) }; |
| 57 const int colorCount = SK_ARRAY_COUNT(colors); | 59 const int colorCount = SK_ARRAY_COUNT(colors); |
| 58 | 60 |
| 59 SkRect r = { 0, 0, this->width(), this->height() }; | 61 SkRect r = { 0, 0, this->width(), this->height() }; |
| 60 SkSize size = SkSize::Make(r.width(), r.height()); | 62 SkSize size = SkSize::Make(r.width(), r.height()); |
| 61 | 63 |
| 62 SkPaint paint; | 64 SkPaint paint; |
| 63 paint.setShader(fProc(colors, colorCount, size))->unref(); | 65 paint.setShader(fProc(colors, colorCount, size))->unref(); |
| 66 paint.setDither(fDither); |
| 64 canvas->drawRect(r, paint); | 67 canvas->drawRect(r, paint); |
| 65 } | 68 } |
| 66 | 69 |
| 67 private: | 70 private: |
| 68 MakeShaderProc fProc; | 71 MakeShaderProc fProc; |
| 69 SkString fName; | 72 SkString fName; |
| 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"); ) | 80 DEF_GM( return new ShallowGradientGM(shader_linear, "linear", true); ) |
| 77 DEF_GM( return new ShallowGradientGM(shader_radial, "radial"); ) | 81 DEF_GM( return new ShallowGradientGM(shader_radial, "radial", true); ) |
| 78 DEF_GM( return new ShallowGradientGM(shader_conical, "conical"); ) | 82 DEF_GM( return new ShallowGradientGM(shader_conical, "conical", true); ) |
| 79 DEF_GM( return new ShallowGradientGM(shader_sweep, "sweep"); ) | 83 DEF_GM( return new ShallowGradientGM(shader_sweep, "sweep", true); ) |
| 84 |
| 85 DEF_GM( return new ShallowGradientGM(shader_linear, "linear_nodither", false); ) |
| 86 DEF_GM( return new ShallowGradientGM(shader_radial, "radial_nodither", false); ) |
| 87 DEF_GM( return new ShallowGradientGM(shader_conical, "conical_nodither", false);
) |
| 88 DEF_GM( return new ShallowGradientGM(shader_sweep, "sweep_nodither", false); ) |
| OLD | NEW |