OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorMatrixFilter.h" | 10 #include "SkColorMatrixFilter.h" |
11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
12 | 12 |
13 static SkShader* make_shader(const SkRect& bounds) { | 13 static sk_sp<SkShader> make_shader(const SkRect& bounds) { |
14 const SkPoint pts[] = { | 14 const SkPoint pts[] = { |
15 { bounds.left(), bounds.top() }, | 15 { bounds.left(), bounds.top() }, |
16 { bounds.right(), bounds.bottom() }, | 16 { bounds.right(), bounds.bottom() }, |
17 }; | 17 }; |
18 const SkColor colors[] = { | 18 const SkColor colors[] = { |
19 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK, | 19 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK, |
20 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, | 20 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, |
21 }; | 21 }; |
22 return SkGradientShader::CreateLinear(pts, | 22 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(col
ors), |
23 colors, nullptr, SK_ARRAY_COUNT(colors
), | 23 SkShader::kClamp_TileMode); |
24 SkShader::kClamp_TileMode); | |
25 } | 24 } |
26 | 25 |
27 typedef void (*InstallPaint)(SkPaint*, uint32_t, uint32_t); | 26 typedef void (*InstallPaint)(SkPaint*, uint32_t, uint32_t); |
28 | 27 |
29 static void install_nothing(SkPaint* paint, uint32_t, uint32_t) { | 28 static void install_nothing(SkPaint* paint, uint32_t, uint32_t) { |
30 paint->setColorFilter(nullptr); | 29 paint->setColorFilter(nullptr); |
31 } | 30 } |
32 | 31 |
33 static void install_lighting(SkPaint* paint, uint32_t mul, uint32_t add) { | 32 static void install_lighting(SkPaint* paint, uint32_t mul, uint32_t add) { |
34 paint->setColorFilter(SkColorMatrixFilter::CreateLightingFilter(mul, add))->
unref(); | 33 paint->setColorFilter(SkColorMatrixFilter::CreateLightingFilter(mul, add))->
unref(); |
(...skipping 11 matching lines...) Expand all Loading... |
46 } | 45 } |
47 | 46 |
48 virtual SkISize onISize() override { | 47 virtual SkISize onISize() override { |
49 return SkISize::Make(640, 480); | 48 return SkISize::Make(640, 480); |
50 } | 49 } |
51 | 50 |
52 void onDraw(SkCanvas* canvas) override { | 51 void onDraw(SkCanvas* canvas) override { |
53 SkPaint paint; | 52 SkPaint paint; |
54 SkRect r; | 53 SkRect r; |
55 r.setWH(600, 50); | 54 r.setWH(600, 50); |
56 paint.setShader(make_shader(r))->unref(); | 55 paint.setShader(make_shader(r)); |
57 | 56 |
58 const struct { | 57 const struct { |
59 InstallPaint fProc; | 58 InstallPaint fProc; |
60 uint32_t fData0, fData1; | 59 uint32_t fData0, fData1; |
61 } rec[] = { | 60 } rec[] = { |
62 { install_nothing, 0, 0 }, | 61 { install_nothing, 0, 0 }, |
63 { install_lighting, 0xFF0000, 0 }, | 62 { install_lighting, 0xFF0000, 0 }, |
64 { install_lighting, 0x00FF00, 0 }, | 63 { install_lighting, 0x00FF00, 0 }, |
65 { install_lighting, 0x0000FF, 0 }, | 64 { install_lighting, 0x0000FF, 0 }, |
66 { install_lighting, 0x000000, 0xFF0000 }, | 65 { install_lighting, 0x000000, 0xFF0000 }, |
(...skipping 11 matching lines...) Expand all Loading... |
78 | 77 |
79 private: | 78 private: |
80 SkString fName; | 79 SkString fName; |
81 typedef GM INHERITED; | 80 typedef GM INHERITED; |
82 }; | 81 }; |
83 | 82 |
84 | 83 |
85 ////////////////////////////////////////////////////////////////////////////// | 84 ////////////////////////////////////////////////////////////////////////////// |
86 | 85 |
87 DEF_GM(return new ColorFiltersGM;) | 86 DEF_GM(return new ColorFiltersGM;) |
OLD | NEW |