| Flutter Impeller |

color_source.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 "impeller/toolkit/interop/color_source.h"
6
7 namespace impeller::interop {
8
9 ScopedObject<ColorSource> ColorSource::MakeLinearGradient(
10 const Point& start_point,
11 const Point& end_point,
12 const std::vector<flutter::DlColor>& colors,
13 const std::vector<Scalar>& stops,
14 flutter::DlTileMode tile_mode,
15 const Matrix& transformation) {
16 const auto sk_transformation = ToSkMatrix(transformation);
17 auto dl_filter =
18 flutter::DlColorSource::MakeLinear(ToSkiaType(start_point), //
19 ToSkiaType(end_point), //
20 stops.size(), //
21 colors.data(), //
22 stops.data(), //
23 tile_mode, //
24 &sk_transformation //
25 );
26 if (!dl_filter) {
27 return nullptr;
28 }
29 return Create<ColorSource>(std::move(dl_filter));
30 }
31
32 ScopedObject<ColorSource> ColorSource::MakeRadialGradient(
33 const Point& center,
34 Scalar radius,
35 const std::vector<flutter::DlColor>& colors,
36 const std::vector<Scalar>& stops,
37 flutter::DlTileMode tile_mode,
38 const Matrix& transformation) {
39 const auto sk_transformation = ToSkMatrix(transformation);
40 auto dl_filter = flutter::DlColorSource::MakeRadial(ToSkiaType(center), //
41 radius, //
42 stops.size(), //
43 colors.data(), //
44 stops.data(), //
45 tile_mode, //
46 &sk_transformation //
47 );
48 if (!dl_filter) {
49 return nullptr;
50 }
51 return Create<ColorSource>(std::move(dl_filter));
52 }
53
54 ScopedObject<ColorSource> ColorSource::MakeConicalGradient(
55 const Point& start_center,
56 Scalar start_radius,
57 const Point& end_center,
58 Scalar end_radius,
59 const std::vector<flutter::DlColor>& colors,
60 const std::vector<Scalar>& stops,
61 flutter::DlTileMode tile_mode,
62 const Matrix& transformation) {
63 const auto sk_transformation = ToSkMatrix(transformation);
64 auto dl_filter =
65 flutter::DlColorSource::MakeConical(ToSkiaType(start_center), //
66 start_radius, //
67 ToSkiaType(end_center), //
68 end_radius, //
69 stops.size(), //
70 colors.data(), //
71 stops.data(), //
72 tile_mode, //
73 &sk_transformation //
74 );
75 if (!dl_filter) {
76 return nullptr;
77 }
78 return Create<ColorSource>(std::move(dl_filter));
79 }
80
81 ScopedObject<ColorSource> ColorSource::MakeSweepGradient(
82 const Point& center,
83 Scalar start,
84 Scalar end,
85 const std::vector<flutter::DlColor>& colors,
86 const std::vector<Scalar>& stops,
87 flutter::DlTileMode tile_mode,
88 const Matrix& transformation) {
89 const auto sk_transformation = ToSkMatrix(transformation);
90 auto dl_filter = flutter::DlColorSource::MakeSweep(ToSkiaType(center), //
91 start, //
92 end, //
93 stops.size(), //
94 colors.data(), //
95 stops.data(), //
96 tile_mode, //
97 &sk_transformation //
98 );
99 if (!dl_filter) {
100 return nullptr;
101 }
102 return Create<ColorSource>(std::move(dl_filter));
103 }
104
105 ColorSource::ColorSource(std::shared_ptr<flutter::DlColorSource> source)
106 : color_source_(std::move(source)) {}
107
108 ColorSource::~ColorSource() = default;
109
110 bool ColorSource::IsValid() const {
111 return !!color_source_;
112 }
113
114 const std::shared_ptr<flutter::DlColorSource>& ColorSource::GetColorSource()
115 const {
116 return color_source_;
117 }
118
119 } // namespace impeller::interop
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::interop::ScopedObject
Definition: object.h:67
impeller::interop::ColorSource::ColorSource
ColorSource(std::shared_ptr< flutter::DlColorSource > source)
Definition: color_source.cc:105
impeller::interop::ColorSource::~ColorSource
~ColorSource() override
impeller::interop::ColorSource::MakeRadialGradient
static ScopedObject< ColorSource > MakeRadialGradient(const Point &center, Scalar radius, const std::vector< flutter::DlColor > &colors, const std::vector< Scalar > &stops, flutter::DlTileMode tile_mode, const Matrix &transformation)
Definition: color_source.cc:32
impeller::interop
Definition: color_filter.cc:7
color_source.h
impeller::interop::ToSkiaType
constexpr std::optional< SkRect > ToSkiaType(const ImpellerRect *rect)
Definition: formats.h:26
impeller::interop::ColorSource::MakeSweepGradient
static ScopedObject< ColorSource > MakeSweepGradient(const Point &center, Scalar start, Scalar end, const std::vector< flutter::DlColor > &colors, const std::vector< Scalar > &stops, flutter::DlTileMode tile_mode, const Matrix &transformation)
Definition: color_source.cc:81
impeller::interop::ColorSource::MakeConicalGradient
static ScopedObject< ColorSource > MakeConicalGradient(const Point &start_center, Scalar start_radius, const Point &end_center, Scalar end_radius, const std::vector< flutter::DlColor > &colors, const std::vector< Scalar > &stops, flutter::DlTileMode tile_mode, const Matrix &transformation)
Definition: color_source.cc:54
impeller::interop::ColorSource::GetColorSource
const std::shared_ptr< flutter::DlColorSource > & GetColorSource() const
Definition: color_source.cc:114
std
Definition: comparable.h:95
impeller::TPoint< Scalar >
impeller::interop::ColorSource::IsValid
bool IsValid() const
Definition: color_source.cc:110
impeller::interop::ColorSource::MakeLinearGradient
static ScopedObject< ColorSource > MakeLinearGradient(const Point &start_point, const Point &end_point, const std::vector< flutter::DlColor > &colors, const std::vector< Scalar > &stops, flutter::DlTileMode tile_mode, const Matrix &transformation)
Definition: color_source.cc:9
impeller::interop::ToSkMatrix
constexpr SkMatrix ToSkMatrix(const Matrix &matrix)
Definition: formats.h:81
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37