OLD | NEW |
| (Empty) |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/paint/paint_shader.h" | |
6 | |
7 #include "base/memory/ptr_util.h" | |
8 #include "cc/paint/paint_record.h" | |
9 #include "third_party/skia/include/effects/SkGradientShader.h" | |
10 | |
11 namespace cc { | |
12 | |
13 std::unique_ptr<PaintShader> PaintShader::MakeColor(SkColor color) { | |
14 return base::WrapUnique(new PaintShader(nullptr, color)); | |
15 } | |
16 | |
17 std::unique_ptr<PaintShader> PaintShader::MakeLinearGradient( | |
18 const SkPoint points[], | |
19 const SkColor colors[], | |
20 const SkScalar pos[], | |
21 int count, | |
22 SkShader::TileMode mode, | |
23 uint32_t flags, | |
24 const SkMatrix* local_matrix, | |
25 SkColor fallback_color) { | |
26 return base::WrapUnique( | |
27 new PaintShader(SkGradientShader::MakeLinear(points, colors, pos, count, | |
28 mode, flags, local_matrix), | |
29 fallback_color)); | |
30 } | |
31 | |
32 std::unique_ptr<PaintShader> PaintShader::MakeRadialGradient( | |
33 const SkPoint& center, | |
34 SkScalar radius, | |
35 const SkColor colors[], | |
36 const SkScalar pos[], | |
37 int color_count, | |
38 SkShader::TileMode mode, | |
39 uint32_t flags, | |
40 const SkMatrix* local_matrix, | |
41 SkColor fallback_color) { | |
42 return base::WrapUnique(new PaintShader( | |
43 SkGradientShader::MakeRadial(center, radius, colors, pos, color_count, | |
44 mode, flags, local_matrix), | |
45 fallback_color)); | |
46 } | |
47 | |
48 std::unique_ptr<PaintShader> PaintShader::MakeTwoPointConicalGradient( | |
49 const SkPoint& start, | |
50 SkScalar start_radius, | |
51 const SkPoint& end, | |
52 SkScalar end_radius, | |
53 const SkColor colors[], | |
54 const SkScalar pos[], | |
55 int color_count, | |
56 SkShader::TileMode mode, | |
57 uint32_t flags, | |
58 const SkMatrix* local_matrix, | |
59 SkColor fallback_color) { | |
60 return base::WrapUnique( | |
61 new PaintShader(SkGradientShader::MakeTwoPointConical( | |
62 start, start_radius, end, end_radius, colors, pos, | |
63 color_count, mode, flags, local_matrix), | |
64 fallback_color)); | |
65 } | |
66 | |
67 std::unique_ptr<PaintShader> PaintShader::MakeSweepGradient( | |
68 SkScalar cx, | |
69 SkScalar cy, | |
70 const SkColor colors[], | |
71 const SkScalar pos[], | |
72 int color_count, | |
73 uint32_t flags, | |
74 const SkMatrix* local_matrix, | |
75 SkColor fallback_color) { | |
76 return base::WrapUnique(new PaintShader( | |
77 SkGradientShader::MakeSweep(cx, cy, colors, pos, color_count, flags, | |
78 local_matrix), | |
79 fallback_color)); | |
80 } | |
81 | |
82 std::unique_ptr<PaintShader> PaintShader::MakeImage( | |
83 sk_sp<const SkImage> image, | |
84 SkShader::TileMode tx, | |
85 SkShader::TileMode ty, | |
86 const SkMatrix* local_matrix) { | |
87 return base::WrapUnique(new PaintShader( | |
88 image->makeShader(tx, ty, local_matrix), SK_ColorTRANSPARENT)); | |
89 } | |
90 | |
91 std::unique_ptr<PaintShader> PaintShader::MakePaintRecord( | |
92 sk_sp<PaintRecord> record, | |
93 const SkRect& tile, | |
94 SkShader::TileMode tx, | |
95 SkShader::TileMode ty, | |
96 const SkMatrix* local_matrix) { | |
97 return base::WrapUnique(new PaintShader( | |
98 SkShader::MakePictureShader(ToSkPicture(std::move(record), tile), tx, ty, | |
99 local_matrix, nullptr), | |
100 SK_ColorTRANSPARENT)); | |
101 } | |
102 | |
103 PaintShader::PaintShader(sk_sp<SkShader> shader, SkColor fallback_color) | |
104 : sk_shader_(shader ? std::move(shader) | |
105 : SkShader::MakeColorShader(fallback_color)) { | |
106 DCHECK(sk_shader_); | |
107 } | |
108 PaintShader::PaintShader(const PaintShader& other) = default; | |
109 PaintShader::PaintShader(PaintShader&& other) = default; | |
110 PaintShader::~PaintShader() = default; | |
111 | |
112 PaintShader& PaintShader::operator=(const PaintShader& other) = default; | |
113 PaintShader& PaintShader::operator=(PaintShader&& other) = default; | |
114 | |
115 } // namespace cc | |
OLD | NEW |