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