| 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 auto dl_filter = flutter::DlColorSource::MakeLinear(start_point, //
17 end_point, //
18 stops.size(), //
19 colors.data(), //
20 stops.data(), //
21 tile_mode, //
22 &transformation //
23 );
24 if (!dl_filter) {
25 return nullptr;
26 }
27 return Create<ColorSource>(std::move(dl_filter));
28 }
29
30 ScopedObject<ColorSource> ColorSource::MakeRadialGradient(
31 const Point& center,
32 Scalar radius,
33 const std::vector<flutter::DlColor>& colors,
34 const std::vector<Scalar>& stops,
35 flutter::DlTileMode tile_mode,
36 const Matrix& transformation) {
37 auto dl_filter = flutter::DlColorSource::MakeRadial(center, //
38 radius, //
39 stops.size(), //
40 colors.data(), //
41 stops.data(), //
42 tile_mode, //
43 &transformation //
44 );
45 if (!dl_filter) {
46 return nullptr;
47 }
48 return Create<ColorSource>(std::move(dl_filter));
49 }
50
51 ScopedObject<ColorSource> ColorSource::MakeConicalGradient(
52 const Point& start_center,
53 Scalar start_radius,
54 const Point& end_center,
55 Scalar end_radius,
56 const std::vector<flutter::DlColor>& colors,
57 const std::vector<Scalar>& stops,
58 flutter::DlTileMode tile_mode,
59 const Matrix& transformation) {
60 auto dl_filter = flutter::DlColorSource::MakeConical(start_center, //
61 start_radius, //
62 end_center, //
63 end_radius, //
64 stops.size(), //
65 colors.data(), //
66 stops.data(), //
67 tile_mode, //
68 &transformation //
69 );
70 if (!dl_filter) {
71 return nullptr;
72 }
73 return Create<ColorSource>(std::move(dl_filter));
74 }
75
76 ScopedObject<ColorSource> ColorSource::MakeSweepGradient(
77 const Point& center,
78 Scalar start,
79 Scalar end,
80 const std::vector<flutter::DlColor>& colors,
81 const std::vector<Scalar>& stops,
82 flutter::DlTileMode tile_mode,
83 const Matrix& transformation) {
84 auto dl_filter = flutter::DlColorSource::MakeSweep(center, //
85 start, //
86 end, //
87 stops.size(), //
88 colors.data(), //
89 stops.data(), //
90 tile_mode, //
91 &transformation //
92 );
93 if (!dl_filter) {
94 return nullptr;
95 }
96 return Create<ColorSource>(std::move(dl_filter));
97 }
98
99 ScopedObject<ColorSource> ColorSource::MakeImage(
100 const Texture& image,
101 flutter::DlTileMode horizontal_tile_mode,
102 flutter::DlTileMode vertical_tile_mode,
103 flutter::DlImageSampling sampling,
104 const Matrix& transformation) {
105 auto dl_filter = flutter::DlColorSource::MakeImage(image.MakeImage(), //
106 horizontal_tile_mode, //
107 vertical_tile_mode, //
108 sampling, //
109 &transformation //
110 );
111 return Create<ColorSource>(std::move(dl_filter));
112 }
113
114 ColorSource::ColorSource(std::shared_ptr<flutter::DlColorSource> source)
115 : color_source_(std::move(source)) {}
116
117 ColorSource::~ColorSource() = default;
118
119 bool ColorSource::IsValid() const {
120 return !!color_source_;
121 }
122
123 const std::shared_ptr<flutter::DlColorSource>& ColorSource::GetColorSource()
124 const {
125 return color_source_;
126 }
127
128 } // namespace impeller::interop
impeller::interop::ColorSource::~ColorSource
~ColorSource() override
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:76
impeller::interop::ColorSource::GetColorSource
const std::shared_ptr< flutter::DlColorSource > & GetColorSource() const
Definition: color_source.cc:123
impeller::interop::ColorSource::ColorSource
ColorSource(std::shared_ptr< flutter::DlColorSource > source)
Definition: color_source.cc:114
impeller::interop::ColorSource::MakeImage
static ScopedObject< ColorSource > MakeImage(const Texture &image, flutter::DlTileMode horizontal_tile_mode, flutter::DlTileMode vertical_tile_mode, flutter::DlImageSampling sampling, const Matrix &transformation)
Definition: color_source.cc:99
impeller::interop::ColorSource::IsValid
bool IsValid() const
Definition: color_source.cc:119
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:30
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::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:51
impeller::interop::ScopedObject
Definition: object.h:67
impeller::interop::Texture
Definition: texture.h:17
impeller::interop::Texture::MakeImage
sk_sp< DlImageImpeller > MakeImage() const
Definition: texture.cc:47
color_source.h
impeller::interop
Definition: context_gles.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:18
std
Definition: comparable.h:95
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TPoint< Scalar >