| 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 #include "flutter/impeller/display_list/dl_runtime_effect_impeller.h"
8
9 namespace impeller::interop {
10
11 ScopedObject<ColorSource> ColorSource::MakeLinearGradient(
12 const Point& start_point,
13 const Point& end_point,
14 const std::vector<flutter::DlColor>& colors,
15 const std::vector<Scalar>& stops,
16 flutter::DlTileMode tile_mode,
17 const Matrix& transformation) {
18 auto dl_filter = flutter::DlColorSource::MakeLinear(start_point, //
19 end_point, //
20 stops.size(), //
21 colors.data(), //
22 stops.data(), //
23 tile_mode, //
24 &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 auto dl_filter = flutter::DlColorSource::MakeRadial(center, //
40 radius, //
41 stops.size(), //
42 colors.data(), //
43 stops.data(), //
44 tile_mode, //
45 &transformation //
46 );
47 if (!dl_filter) {
48 return nullptr;
49 }
50 return Create<ColorSource>(std::move(dl_filter));
51 }
52
53 ScopedObject<ColorSource> ColorSource::MakeConicalGradient(
54 const Point& start_center,
55 Scalar start_radius,
56 const Point& end_center,
57 Scalar end_radius,
58 const std::vector<flutter::DlColor>& colors,
59 const std::vector<Scalar>& stops,
60 flutter::DlTileMode tile_mode,
61 const Matrix& transformation) {
62 auto dl_filter = flutter::DlColorSource::MakeConical(start_center, //
63 start_radius, //
64 end_center, //
65 end_radius, //
66 stops.size(), //
67 colors.data(), //
68 stops.data(), //
69 tile_mode, //
70 &transformation //
71 );
72 if (!dl_filter) {
73 return nullptr;
74 }
75 return Create<ColorSource>(std::move(dl_filter));
76 }
77
78 ScopedObject<ColorSource> ColorSource::MakeSweepGradient(
79 const Point& center,
80 Scalar start,
81 Scalar end,
82 const std::vector<flutter::DlColor>& colors,
83 const std::vector<Scalar>& stops,
84 flutter::DlTileMode tile_mode,
85 const Matrix& transformation) {
86 auto dl_filter = flutter::DlColorSource::MakeSweep(center, //
87 start, //
88 end, //
89 stops.size(), //
90 colors.data(), //
91 stops.data(), //
92 tile_mode, //
93 &transformation //
94 );
95 if (!dl_filter) {
96 return nullptr;
97 }
98 return Create<ColorSource>(std::move(dl_filter));
99 }
100
101 ScopedObject<ColorSource> ColorSource::MakeImage(
102 const Texture& image,
103 flutter::DlTileMode horizontal_tile_mode,
104 flutter::DlTileMode vertical_tile_mode,
105 flutter::DlImageSampling sampling,
106 const Matrix& transformation) {
107 auto dl_filter = flutter::DlColorSource::MakeImage(image.MakeImage(), //
108 horizontal_tile_mode, //
109 vertical_tile_mode, //
110 sampling, //
111 &transformation //
112 );
113 return Create<ColorSource>(std::move(dl_filter));
114 }
115
116 ScopedObject<ColorSource> ColorSource::MakeFragmentProgram(
117 const Context& context,
118 const FragmentProgram& program,
119 std::vector<std::shared_ptr<flutter::DlColorSource>> samplers,
120 std::shared_ptr<std::vector<uint8_t>> uniform_data) {
121 auto runtime_stage =
122 program.FindRuntimeStage(context.GetContext()->GetRuntimeStageBackend());
123 if (!runtime_stage) {
124 VALIDATION_LOG << "Could not find runtime stage for backend.";
125 return nullptr;
126 }
127 auto runtime_effect =
128 flutter::DlRuntimeEffectImpeller::Make(std::move(runtime_stage));
129 if (!runtime_effect) {
130 VALIDATION_LOG << "Could not make runtime effect.";
131 return nullptr;
132 }
133
134 auto dl_filter =
135 flutter::DlColorSource::MakeRuntimeEffect(std::move(runtime_effect), //
136 std::move(samplers), //
137 std::move(uniform_data) //
138 );
139 if (!dl_filter) {
140 VALIDATION_LOG << "Could not create runtime effect color source.";
141 return nullptr;
142 }
143 return Create<ColorSource>(std::move(dl_filter));
144 }
145
146 ColorSource::ColorSource(std::shared_ptr<flutter::DlColorSource> source)
147 : color_source_(std::move(source)) {}
148
149 ColorSource::~ColorSource() = default;
150
151 bool ColorSource::IsValid() const {
152 return !!color_source_;
153 }
154
155 const std::shared_ptr<flutter::DlColorSource>& ColorSource::GetColorSource()
156 const {
157 return color_source_;
158 }
159
160 } // namespace impeller::interop
flutter::DlRuntimeEffectImpeller::Make
static sk_sp< DlRuntimeEffect > Make(std::shared_ptr< impeller::RuntimeStage > runtime_stage)
Definition: dl_runtime_effect_impeller.cc:14
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:78
impeller::interop::ColorSource::GetColorSource
const std::shared_ptr< flutter::DlColorSource > & GetColorSource() const
Definition: color_source.cc:155
impeller::interop::ColorSource::ColorSource
ColorSource(std::shared_ptr< flutter::DlColorSource > source)
Definition: color_source.cc:146
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:116
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:101
impeller::interop::ColorSource::IsValid
bool IsValid() const
Definition: color_source.cc:151
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::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:11
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:53
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:57
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
dl_runtime_effect_impeller.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