| 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 ScopedObject<ColorSource> ColorSource::MakeFragmentProgram(
115 const Context& context,
116 const FragmentProgram& program,
117 std::vector<std::shared_ptr<flutter::DlColorSource>> samplers,
118 std::shared_ptr<std::vector<uint8_t>> uniform_data) {
119 auto runtime_stage =
120 program.FindRuntimeStage(context.GetContext()->GetRuntimeStageBackend());
121 if (!runtime_stage) {
122 VALIDATION_LOG << "Could not find runtime stage for backend.";
123 return nullptr;
124 }
125 auto runtime_effect =
126 flutter::DlRuntimeEffect::MakeImpeller(std::move(runtime_stage));
127 if (!runtime_effect) {
128 VALIDATION_LOG << "Could not make runtime effect.";
129 return nullptr;
130 }
131
132 auto dl_filter =
133 flutter::DlColorSource::MakeRuntimeEffect(std::move(runtime_effect), //
134 std::move(samplers), //
135 std::move(uniform_data) //
136 );
137 if (!dl_filter) {
138 VALIDATION_LOG << "Could not create runtime effect color source.";
139 return nullptr;
140 }
141 return Create<ColorSource>(std::move(dl_filter));
142 }
143
144 ColorSource::ColorSource(std::shared_ptr<flutter::DlColorSource> source)
145 : color_source_(std::move(source)) {}
146
147 ColorSource::~ColorSource() = default;
148
149 bool ColorSource::IsValid() const {
150 return !!color_source_;
151 }
152
153 const std::shared_ptr<flutter::DlColorSource>& ColorSource::GetColorSource()
154 const {
155 return color_source_;
156 }
157
158 } // 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:153
impeller::interop::ColorSource::ColorSource
ColorSource(std::shared_ptr< flutter::DlColorSource > source)
Definition: color_source.cc:144
impeller::interop::ColorSource::MakeFragmentProgram
static ScopedObject< ColorSource > MakeFragmentProgram(const Context &context, const FragmentProgram &program, std::vector< std::shared_ptr< flutter::DlColorSource >> samplers, std::shared_ptr< std::vector< uint8_t >> uniform_data)
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:149
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::Context
Definition: context.h:16
impeller::interop::Context::GetContext
std::shared_ptr< impeller::Context > GetContext() const
Definition: context.cc:20
impeller::interop::FragmentProgram
Definition: fragment_program.h:17
impeller::interop::FragmentProgram::FindRuntimeStage
std::shared_ptr< RuntimeStage > FindRuntimeStage(RuntimeStageBackend backend) const
Definition: fragment_program.cc:53
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:19
std
Definition: comparable.h:95
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TPoint< Scalar >
start
const size_t start
Definition: tessellator_libtess.cc:62
end
const size_t end
Definition: tessellator_libtess.cc:63
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91