Flutter Engine
 
Loading...
Searching...
No Matches
embedder_layers.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
6
7#include <algorithm>
8
9namespace flutter {
10
12 double device_pixel_ratio,
13 DlMatrix root_surface_transformation,
14 uint64_t presentation_time)
15 : frame_size_(frame_size),
16 device_pixel_ratio_(device_pixel_ratio),
17 root_surface_transformation_(root_surface_transformation),
18 presentation_time_(presentation_time) {}
19
21
23 const FlutterBackingStore* store,
24 const std::vector<DlIRect>& paint_region_vec) {
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}
71
72static std::unique_ptr<FlutterPlatformViewMutation> ConvertMutation(
73 double opacity) {
74 FlutterPlatformViewMutation mutation = {};
76 mutation.opacity = opacity;
77 return std::make_unique<FlutterPlatformViewMutation>(mutation);
78}
79
80static std::unique_ptr<FlutterPlatformViewMutation> ConvertMutation(
81 const DlRect& rect) {
82 FlutterPlatformViewMutation mutation = {};
84 mutation.clip_rect.left = rect.GetLeft();
85 mutation.clip_rect.top = rect.GetTop();
86 mutation.clip_rect.right = rect.GetRight();
87 mutation.clip_rect.bottom = rect.GetBottom();
88 return std::make_unique<FlutterPlatformViewMutation>(mutation);
89}
90
91static FlutterSize ConvertSize(const DlSize& vector) {
92 FlutterSize size = {};
93 size.width = vector.width;
94 size.height = vector.height;
95 return size;
96}
97
98static std::unique_ptr<FlutterPlatformViewMutation> ConvertMutation(
99 const DlRoundRect& rrect) {
100 FlutterPlatformViewMutation mutation = {};
102 const auto& rect = rrect.GetBounds();
103 mutation.clip_rounded_rect.rect.left = rect.GetLeft();
104 mutation.clip_rounded_rect.rect.top = rect.GetTop();
105 mutation.clip_rounded_rect.rect.right = rect.GetRight();
106 mutation.clip_rounded_rect.rect.bottom = rect.GetBottom();
107 const auto& radii = rrect.GetRadii();
109 ConvertSize(radii.top_left);
111 ConvertSize(radii.top_right);
113 ConvertSize(radii.bottom_right);
115 ConvertSize(radii.bottom_left);
116 return std::make_unique<FlutterPlatformViewMutation>(mutation);
117}
118
119static std::unique_ptr<FlutterPlatformViewMutation> ConvertMutation(
120 const DlMatrix& matrix) {
121 FlutterPlatformViewMutation mutation = {};
123 mutation.transformation.scaleX = matrix.m[0];
124 mutation.transformation.skewX = matrix.m[4];
125 mutation.transformation.transX = matrix.m[12];
126 mutation.transformation.skewY = matrix.m[1];
127 mutation.transformation.scaleY = matrix.m[5];
128 mutation.transformation.transY = matrix.m[13];
129 mutation.transformation.pers0 = matrix.m[3];
130 mutation.transformation.pers1 = matrix.m[7];
131 mutation.transformation.pers2 = matrix.m[15];
132 return std::make_unique<FlutterPlatformViewMutation>(mutation);
133}
134
137 const EmbeddedViewParams& params) {
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}
241
244 const PresentCallback& callback) const {
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}
252
253} // namespace flutter
void PushPlatformViewLayer(FlutterPlatformViewIdentifier identifier, const EmbeddedViewParams &params)
EmbedderLayers(DlISize frame_size, double device_pixel_ratio, DlMatrix root_surface_transformation, uint64_t presentation_time)
void InvokePresentCallback(FlutterViewId view_id, const PresentCallback &callback) const
void PushBackingStoreLayer(const FlutterBackingStore *store, const std::vector< DlIRect > &drawn_region)
std::function< bool(FlutterViewId view_id, const std::vector< const FlutterLayer * > &layers)> PresentCallback
int64_t FlutterPlatformViewIdentifier
Definition embedder.h:1460
@ kFlutterLayerContentTypePlatformView
Indicates that the contents of this layer are determined by the embedder.
Definition embedder.h:2104
@ kFlutterLayerContentTypeBackingStore
Definition embedder.h:2102
@ kFlutterPlatformViewMutationTypeClipRoundedRect
Definition embedder.h:2006
@ kFlutterPlatformViewMutationTypeClipRect
Definition embedder.h:2003
@ kFlutterPlatformViewMutationTypeTransformation
Definition embedder.h:2009
@ kFlutterPlatformViewMutationTypeOpacity
Definition embedder.h:2000
const EmbeddedViewParams * params
FlView * view
G_BEGIN_DECLS FlutterViewId view_id
FlutterDesktopBinaryReply callback
static FlutterSize ConvertSize(const DlSize &vector)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
int64_t FlutterViewId
static std::unique_ptr< FlutterPlatformViewMutation > ConvertMutation(double opacity)
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
const FlutterPlatformView * platform_view
Definition embedder.h:2141
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
size_t struct_size
The size of this struct. Must be sizeof(FlutterPlatformView).
Definition embedder.h:2025
FlutterTransformation transformation
Definition embedder.h:2019
FlutterPlatformViewMutationType type
The type of the mutation described by the subsequent union.
Definition embedder.h:2014
FlutterRoundedRect clip_rounded_rect
Definition embedder.h:2018
A structure to represent a rectangle.
Definition embedder.h:641
double bottom
Definition embedder.h:645
double top
Definition embedder.h:643
double left
Definition embedder.h:642
double right
Definition embedder.h:644
A region represented by a collection of non-overlapping rectangles.
Definition embedder.h:2108
FlutterRect rect
Definition embedder.h:656
FlutterSize upper_left_corner_radius
Definition embedder.h:657
FlutterSize lower_left_corner_radius
Definition embedder.h:660
FlutterSize upper_right_corner_radius
Definition embedder.h:658
FlutterSize lower_right_corner_radius
Definition embedder.h:659
A structure to represent the width and height.
Definition embedder.h:627
double height
Definition embedder.h:629
double width
Definition embedder.h:628
double transY
vertical translation
Definition embedder.h:400
double pers2
perspective scale factor
Definition embedder.h:406
double skewX
horizontal skew factor
Definition embedder.h:392
double pers0
input x-axis perspective factor
Definition embedder.h:402
double scaleX
horizontal scale factor
Definition embedder.h:390
double skewY
vertical skew factor
Definition embedder.h:396
double scaleY
vertical scale factor
Definition embedder.h:398
double pers1
input y-axis perspective factor
Definition embedder.h:404
double transX
horizontal translation
Definition embedder.h:394
A 4x4 matrix using column-major storage.
Definition matrix.h:37
constexpr bool IsIdentity() const
Definition matrix.h:467
Scalar m[16]
Definition matrix.h:39
constexpr const RoundingRadii & GetRadii() const
Definition round_rect.h:55
constexpr const Rect & GetBounds() const
Definition round_rect.h:53
constexpr auto GetBottom() const
Definition rect.h:357
constexpr auto GetTop() const
Definition rect.h:353
static constexpr std::enable_if_t< std::is_floating_point_v< FT >, TRect > Make(const TRect< U > &rect)
Definition rect.h:157
constexpr auto GetLeft() const
Definition rect.h:351
constexpr auto GetRight() const
Definition rect.h:355
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition rect.h:136
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:150
Type height
Definition size.h:29
Type width
Definition size.h:28