Flutter Engine
 
Loading...
Searching...
No Matches
flutter::EmbedderLayers Class Reference

#include <embedder_layers.h>

Public Types

using PresentCallback = std::function< bool(FlutterViewId view_id, const std::vector< const FlutterLayer * > &layers)>
 

Public Member Functions

 EmbedderLayers (DlISize frame_size, double device_pixel_ratio, DlMatrix root_surface_transformation, uint64_t presentation_time)
 
 ~EmbedderLayers ()
 
void PushBackingStoreLayer (const FlutterBackingStore *store, const std::vector< DlIRect > &drawn_region)
 
void PushPlatformViewLayer (FlutterPlatformViewIdentifier identifier, const EmbeddedViewParams &params)
 
void InvokePresentCallback (FlutterViewId view_id, const PresentCallback &callback) const
 

Detailed Description

Definition at line 17 of file embedder_layers.h.

Member Typedef Documentation

◆ PresentCallback

using flutter::EmbedderLayers::PresentCallback = std::function<bool(FlutterViewId view_id, const std::vector<const FlutterLayer*>& layers)>

Definition at line 32 of file embedder_layers.h.

Constructor & Destructor Documentation

◆ EmbedderLayers()

flutter::EmbedderLayers::EmbedderLayers ( DlISize  frame_size,
double  device_pixel_ratio,
DlMatrix  root_surface_transformation,
uint64_t  presentation_time 
)

Definition at line 11 of file embedder_layers.cc.

15 : frame_size_(frame_size),
16 device_pixel_ratio_(device_pixel_ratio),
17 root_surface_transformation_(root_surface_transformation),
18 presentation_time_(presentation_time) {}

◆ ~EmbedderLayers()

flutter::EmbedderLayers::~EmbedderLayers ( )
default

Member Function Documentation

◆ InvokePresentCallback()

void flutter::EmbedderLayers::InvokePresentCallback ( FlutterViewId  view_id,
const PresentCallback callback 
) const

Definition at line 242 of file embedder_layers.cc.

244 {
245 std::vector<const FlutterLayer*> presented_layers_pointers;
246 presented_layers_pointers.reserve(presented_layers_.size());
247 for (const auto& layer : presented_layers_) {
248 presented_layers_pointers.push_back(&layer);
249 }
250 callback(view_id, presented_layers_pointers);
251}
G_BEGIN_DECLS FlutterViewId view_id
FlutterDesktopBinaryReply callback

References callback, and view_id.

◆ PushBackingStoreLayer()

void flutter::EmbedderLayers::PushBackingStoreLayer ( const FlutterBackingStore store,
const std::vector< DlIRect > &  drawn_region 
)

Definition at line 22 of file embedder_layers.cc.

24 {
25 FlutterLayer layer = {};
26
27 layer.struct_size = sizeof(FlutterLayer);
29 layer.backing_store = store;
30
31 const auto layer_bounds = DlRect::MakeSize(frame_size_);
32
33 const auto transformed_layer_bounds =
34 layer_bounds.TransformAndClipBounds(root_surface_transformation_);
35
36 layer.offset.x = transformed_layer_bounds.GetX();
37 layer.offset.y = transformed_layer_bounds.GetY();
38 layer.size.width = transformed_layer_bounds.GetWidth();
39 layer.size.height = transformed_layer_bounds.GetHeight();
40
41 auto paint_region_rects = std::make_unique<std::vector<FlutterRect>>();
42 paint_region_rects->reserve(paint_region_vec.size());
43
44 for (const auto& rect : paint_region_vec) {
45 auto transformed_rect =
46 DlRect::Make(rect).TransformAndClipBounds(root_surface_transformation_);
47 paint_region_rects->push_back(FlutterRect{
48 .left = transformed_rect.GetLeft(),
49 .top = transformed_rect.GetTop(),
50 .right = transformed_rect.GetRight(),
51 .bottom = transformed_rect.GetBottom(),
52 });
53 }
54
55 auto paint_region = std::make_unique<FlutterRegion>();
56 paint_region->struct_size = sizeof(FlutterRegion);
57 paint_region->rects = paint_region_rects->data();
58 paint_region->rects_count = paint_region_rects->size();
59 rects_referenced_.push_back(std::move(paint_region_rects));
60
61 auto present_info = std::make_unique<FlutterBackingStorePresentInfo>();
62 present_info->struct_size = sizeof(FlutterBackingStorePresentInfo);
63 present_info->paint_region = paint_region.get();
64 regions_referenced_.push_back(std::move(paint_region));
65 layer.backing_store_present_info = present_info.get();
66 layer.presentation_time = presentation_time_;
67
68 present_info_referenced_.push_back(std::move(present_info));
69 presented_layers_.push_back(layer);
70}
@ kFlutterLayerContentTypeBackingStore
Definition embedder.h:2102
FlutterPoint offset
Definition embedder.h:2145
FlutterLayerContentType type
Definition embedder.h:2134
const FlutterBackingStore * backing_store
Definition embedder.h:2138
FlutterBackingStorePresentInfo * backing_store_present_info
Definition embedder.h:2151
uint64_t presentation_time
Definition embedder.h:2155
size_t struct_size
This size of this struct. Must be sizeof(FlutterLayer).
Definition embedder.h:2131
FlutterSize size
The size of the layer (in physical pixels).
Definition embedder.h:2147
A structure to represent a rectangle.
Definition embedder.h:641
double left
Definition embedder.h:642
A region represented by a collection of non-overlapping rectangles.
Definition embedder.h:2108
double height
Definition embedder.h:629
double width
Definition embedder.h:628
static constexpr std::enable_if_t< std::is_floating_point_v< FT >, TRect > Make(const TRect< U > &rect)
Definition rect.h:157
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:150

References FlutterLayer::backing_store, FlutterLayer::backing_store_present_info, FlutterSize::height, kFlutterLayerContentTypeBackingStore, FlutterRect::left, impeller::TRect< Scalar >::Make(), impeller::TRect< Scalar >::MakeSize(), FlutterLayer::offset, FlutterLayer::presentation_time, FlutterLayer::size, FlutterLayer::struct_size, FlutterLayer::type, FlutterSize::width, FlutterPoint::x, and FlutterPoint::y.

◆ PushPlatformViewLayer()

void flutter::EmbedderLayers::PushPlatformViewLayer ( FlutterPlatformViewIdentifier  identifier,
const EmbeddedViewParams params 
)

Definition at line 135 of file embedder_layers.cc.

137 {
138 {
141 view.identifier = identifier;
142
143 const auto& mutators = params.mutatorsStack();
144
145 std::vector<const FlutterPlatformViewMutation*> mutations_array;
146
147 for (auto i = mutators.Bottom(); i != mutators.Top(); ++i) {
148 const auto& mutator = *i;
149 switch (mutator->GetType()) {
151 mutations_array.push_back(
152 mutations_referenced_
153 .emplace_back(ConvertMutation(mutator->GetRect()))
154 .get());
155 } break;
157 mutations_array.push_back(
158 mutations_referenced_
159 .emplace_back(ConvertMutation(mutator->GetRRect()))
160 .get());
161 } break;
163 mutations_array.push_back(
164 mutations_referenced_
165 .emplace_back(ConvertMutation(mutator->GetRSEApproximation()))
166 .get());
167 } break;
169 // Unsupported mutation.
170 } break;
172 const auto& matrix = mutator->GetMatrix();
173 if (!matrix.IsIdentity()) {
174 mutations_array.push_back(
175 mutations_referenced_.emplace_back(ConvertMutation(matrix))
176 .get());
177 }
178 } break;
180 const double opacity =
181 std::clamp(mutator->GetAlphaFloat(), 0.0f, 1.0f);
182 if (opacity < 1.0) {
183 mutations_array.push_back(
184 mutations_referenced_.emplace_back(ConvertMutation(opacity))
185 .get());
186 }
187 } break;
189 break;
190 }
191 }
192
193 if (!mutations_array.empty()) {
194 // If there are going to be any mutations, they must first take into
195 // account the root surface transformation.
196 if (!root_surface_transformation_.IsIdentity()) {
197 mutations_array.push_back(
198 mutations_referenced_
199 .emplace_back(ConvertMutation(root_surface_transformation_))
200 .get());
201 }
202
203 auto mutations =
204 std::make_unique<std::vector<const FlutterPlatformViewMutation*>>(
205 mutations_array.rbegin(), mutations_array.rend());
206 mutations_arrays_referenced_.emplace_back(std::move(mutations));
207
208 view.mutations_count = mutations_array.size();
209 view.mutations = mutations_arrays_referenced_.back().get()->data();
210 }
211
212 platform_views_referenced_.emplace_back(
213 std::make_unique<FlutterPlatformView>(view));
214 }
215
216 FlutterLayer layer = {};
217
218 layer.struct_size = sizeof(FlutterLayer);
220 layer.platform_view = platform_views_referenced_.back().get();
221
222 const auto layer_bounds =
223 DlRect::MakeXYWH(params.finalBoundingRect().GetX(), //
224 params.finalBoundingRect().GetY(), //
225 params.sizePoints().width * device_pixel_ratio_, //
226 params.sizePoints().height * device_pixel_ratio_ //
227 );
228
229 const auto transformed_layer_bounds =
230 layer_bounds.TransformAndClipBounds(root_surface_transformation_);
231
232 layer.offset.x = transformed_layer_bounds.GetX();
233 layer.offset.y = transformed_layer_bounds.GetY();
234 layer.size.width = transformed_layer_bounds.GetWidth();
235 layer.size.height = transformed_layer_bounds.GetHeight();
236
237 layer.presentation_time = presentation_time_;
238
239 presented_layers_.push_back(layer);
240}
@ kFlutterLayerContentTypePlatformView
Indicates that the contents of this layer are determined by the embedder.
Definition embedder.h:2104
const EmbeddedViewParams * params
FlView * view
static std::unique_ptr< FlutterPlatformViewMutation > ConvertMutation(double opacity)
const FlutterPlatformView * platform_view
Definition embedder.h:2141
size_t struct_size
The size of this struct. Must be sizeof(FlutterPlatformView).
Definition embedder.h:2025
constexpr bool IsIdentity() const
Definition matrix.h:467
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition rect.h:136

References flutter::ConvertMutation(), FlutterSize::height, i, impeller::Matrix::IsIdentity(), flutter::kBackdropFilter, flutter::kClipPath, flutter::kClipRect, flutter::kClipRRect, flutter::kClipRSE, kFlutterLayerContentTypePlatformView, flutter::kOpacity, flutter::kTransform, impeller::TRect< Scalar >::MakeXYWH(), FlutterLayer::offset, params, FlutterLayer::platform_view, FlutterLayer::presentation_time, FlutterLayer::size, FlutterPlatformView::struct_size, FlutterLayer::struct_size, FlutterLayer::type, view, FlutterSize::width, FlutterPoint::x, and FlutterPoint::y.


The documentation for this class was generated from the following files: