Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: sky/engine/core/painting/CanvasGradient.cpp

Issue 1169863002: Sky: Added radial gradients. (Closed) Base URL: git@github.com:/domokit/mojo.git@master
Patch Set: rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/core/painting/CanvasGradient.h ('k') | sky/engine/core/painting/Gradient.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/logging.h"
9 #include "sky/engine/core/painting/Picture.h"
10
11 namespace blink { 8 namespace blink {
12 9
13 PassRefPtr<CanvasGradient> CanvasGradient::create( 10 PassRefPtr<CanvasGradient> CanvasGradient::create() {
14 int type, 11 return adoptRef(new CanvasGradient());
15 const Vector<Point>& end_points, 12 }
16 const Vector<SkColor>& colors, 13
17 const Vector<float>& color_stops) { 14 void CanvasGradient::initLinear(const Vector<Point>& end_points,
18 ASSERT(type == 0); // Only 1 supported type so far. 15 const Vector<SkColor>& colors,
16 const Vector<float>& color_stops) {
19 ASSERT(end_points.size() == 2); 17 ASSERT(end_points.size() == 2);
20 ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); 18 ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr);
21 SkPoint sk_end_points[2]; 19 SkPoint sk_end_points[2];
22 for (int i = 0; i < 2; ++i) 20 for (int i = 0; i < 2; ++i)
23 sk_end_points[i] = end_points[i].sk_point; 21 sk_end_points[i] = end_points[i].sk_point;
24 22
23 // 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 SkShader::kClamp_TileMode); 26 SkShader::kClamp_TileMode);
28 return adoptRef(new CanvasGradient(adoptRef(shader))); 27 set_shader(adoptRef(shader));
29 } 28 }
30 29
31 CanvasGradient::CanvasGradient(PassRefPtr<SkShader> shader) 30 void CanvasGradient::initRadial(const Point& center,
32 : Shader(shader) 31 double radius,
32 const Vector<SkColor>& colors,
33 const Vector<float>& color_stops) {
34 ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr);
35
36 SkShader* shader = SkGradientShader::CreateRadial(
37 center.sk_point, radius, colors.data(), color_stops.data(), colors.size(),
38 SkShader::kClamp_TileMode);
39 set_shader(adoptRef(shader));
40 }
41
42 CanvasGradient::CanvasGradient()
43 : Shader(nullptr)
33 { 44 {
34 } 45 }
35 46
36 CanvasGradient::~CanvasGradient() 47 CanvasGradient::~CanvasGradient()
37 { 48 {
38 } 49 }
39 50
40 } // namespace blink 51 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/painting/CanvasGradient.h ('k') | sky/engine/core/painting/Gradient.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698