OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
6 #include "sky/engine/core/painting/CanvasGradient.h" | 6 #include "sky/engine/core/painting/CanvasGradient.h" |
7 | 7 |
8 namespace blink { | 8 namespace blink { |
9 | 9 |
10 PassRefPtr<CanvasGradient> CanvasGradient::create() { | 10 PassRefPtr<CanvasGradient> CanvasGradient::create() { |
11 return adoptRef(new CanvasGradient()); | 11 return adoptRef(new CanvasGradient()); |
12 } | 12 } |
13 | 13 |
14 void CanvasGradient::initLinear(const Vector<Point>& end_points, | 14 void CanvasGradient::initLinear(const Vector<Point>& end_points, |
15 const Vector<SkColor>& colors, | 15 const Vector<SkColor>& colors, |
16 const Vector<float>& color_stops, | 16 const Vector<float>& color_stops, |
17 SkShader::TileMode tile_mode) { | 17 SkShader::TileMode tile_mode) { |
18 ASSERT(end_points.size() == 2); | 18 ASSERT(end_points.size() == 2); |
19 ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); | 19 ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); |
20 SkPoint sk_end_points[2]; | 20 SkPoint sk_end_points[2]; |
21 for (int i = 0; i < 2; ++i) | 21 for (int i = 0; i < 2; ++i) |
22 sk_end_points[i] = end_points[i].sk_point; | 22 sk_end_points[i] = end_points[i].sk_point; |
23 | 23 |
24 // TODO(mpcomplete): allow setting the TileMode. | |
25 SkShader* shader = SkGradientShader::CreateLinear( | 24 SkShader* shader = SkGradientShader::CreateLinear( |
26 sk_end_points, colors.data(), color_stops.data(), colors.size(), | 25 sk_end_points, colors.data(), color_stops.data(), colors.size(), |
27 tile_mode); | 26 tile_mode); |
28 set_shader(adoptRef(shader)); | 27 set_shader(adoptRef(shader)); |
29 } | 28 } |
30 | 29 |
31 void CanvasGradient::initRadial(const Point& center, | 30 void CanvasGradient::initRadial(const Point& center, |
32 double radius, | 31 double radius, |
33 const Vector<SkColor>& colors, | 32 const Vector<SkColor>& colors, |
34 const Vector<float>& color_stops, | 33 const Vector<float>& color_stops, |
35 SkShader::TileMode tile_mode) { | 34 SkShader::TileMode tile_mode) { |
36 ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); | 35 ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); |
37 | 36 |
38 SkShader* shader = SkGradientShader::CreateRadial( | 37 SkShader* shader = SkGradientShader::CreateRadial( |
39 center.sk_point, radius, colors.data(), color_stops.data(), colors.size(), | 38 center.sk_point, radius, colors.data(), color_stops.data(), colors.size(), |
40 tile_mode); | 39 tile_mode); |
41 set_shader(adoptRef(shader)); | 40 set_shader(adoptRef(shader)); |
42 } | 41 } |
43 | 42 |
44 CanvasGradient::CanvasGradient() | 43 CanvasGradient::CanvasGradient() |
45 : Shader(nullptr) | 44 : Shader(nullptr) |
46 { | 45 { |
47 } | 46 } |
48 | 47 |
49 CanvasGradient::~CanvasGradient() | 48 CanvasGradient::~CanvasGradient() |
50 { | 49 { |
51 } | 50 } |
52 | 51 |
53 } // namespace blink | 52 } // namespace blink |
OLD | NEW |