| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkView.h" | 9 #include "SkView.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkGraphics.h" | 11 #include "SkGraphics.h" |
| 12 #include "SkRandom.h" | 12 #include "SkRandom.h" |
| 13 #include "SkGradientShader.h" | 13 #include "SkGradientShader.h" |
| 14 #include "SkPicture.h" | 14 #include "SkPicture.h" |
| 15 | 15 |
| 16 static SkShader* make_linear() { | 16 static sk_sp<SkShader> make_linear() { |
| 17 SkPoint pts[] = { 0, 0, SK_Scalar1/500, SK_Scalar1/500 }; | 17 SkPoint pts[] = { 0, 0, SK_Scalar1/500, SK_Scalar1/500 }; |
| 18 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; | 18 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; |
| 19 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, | 19 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClam
p_TileMode); |
| 20 SkShader::kClamp_TileMode); | |
| 21 } | 20 } |
| 22 | 21 |
| 23 class ClampView : public SampleView { | 22 class ClampView : public SampleView { |
| 24 SkShader* fGrad; | 23 sk_sp<SkShader> fGrad; |
| 25 | 24 |
| 26 public: | 25 public: |
| 27 ClampView() { | 26 ClampView() { |
| 28 fGrad = make_linear(); | 27 fGrad = make_linear(); |
| 29 } | 28 } |
| 30 | 29 |
| 31 virtual ~ClampView() { | |
| 32 fGrad->unref(); | |
| 33 } | |
| 34 | |
| 35 protected: | 30 protected: |
| 36 // overrides from SkEventSink | 31 // overrides from SkEventSink |
| 37 virtual bool onQuery(SkEvent* evt) { | 32 virtual bool onQuery(SkEvent* evt) { |
| 38 if (SampleCode::TitleQ(*evt)) { | 33 if (SampleCode::TitleQ(*evt)) { |
| 39 SampleCode::TitleR(evt, "Clamp"); | 34 SampleCode::TitleR(evt, "Clamp"); |
| 40 return true; | 35 return true; |
| 41 } | 36 } |
| 42 return this->INHERITED::onQuery(evt); | 37 return this->INHERITED::onQuery(evt); |
| 43 } | 38 } |
| 44 | 39 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 58 } | 53 } |
| 59 | 54 |
| 60 private: | 55 private: |
| 61 typedef SampleView INHERITED; | 56 typedef SampleView INHERITED; |
| 62 }; | 57 }; |
| 63 | 58 |
| 64 ////////////////////////////////////////////////////////////////////////////// | 59 ////////////////////////////////////////////////////////////////////////////// |
| 65 | 60 |
| 66 static SkView* MyFactory() { return new ClampView; } | 61 static SkView* MyFactory() { return new ClampView; } |
| 67 static SkViewRegister reg(MyFactory); | 62 static SkViewRegister reg(MyFactory); |
| OLD | NEW |