Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
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 (SkISize frame_size, double device_pixel_ratio, SkMatrix root_surface_transformation, uint64_t presentation_time)
 
 ~EmbedderLayers ()
 
void PushBackingStoreLayer (const FlutterBackingStore *store, const std::vector< SkIRect > &drawn_region)
 
void PushPlatformViewLayer (FlutterPlatformViewIdentifier identifier, const EmbeddedViewParams &params)
 
void InvokePresentCallback (FlutterViewId view_id, const PresentCallback &callback) const
 

Detailed Description

Definition at line 19 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 34 of file embedder_layers.h.

Constructor & Destructor Documentation

◆ EmbedderLayers()

flutter::EmbedderLayers::EmbedderLayers ( SkISize  frame_size,
double  device_pixel_ratio,
SkMatrix  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 236 of file embedder_layers.cc.

238 {
239 std::vector<const FlutterLayer*> presented_layers_pointers;
240 presented_layers_pointers.reserve(presented_layers_.size());
241 for (const auto& layer : presented_layers_) {
242 presented_layers_pointers.push_back(&layer);
243 }
244 callback(view_id, presented_layers_pointers);
245}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ PushBackingStoreLayer()

void flutter::EmbedderLayers::PushBackingStoreLayer ( const FlutterBackingStore store,
const std::vector< SkIRect > &  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 =
32 SkRect::MakeWH(frame_size_.width(), frame_size_.height());
33
34 const auto transformed_layer_bounds =
35 root_surface_transformation_.mapRect(layer_bounds);
36
37 layer.offset.x = transformed_layer_bounds.x();
38 layer.offset.y = transformed_layer_bounds.y();
39 layer.size.width = transformed_layer_bounds.width();
40 layer.size.height = transformed_layer_bounds.height();
41
42 auto paint_region_rects = std::make_unique<std::vector<FlutterRect>>();
43 paint_region_rects->reserve(paint_region_vec.size());
44
45 for (const auto& rect : paint_region_vec) {
46 auto transformed_rect =
47 root_surface_transformation_.mapRect(SkRect::Make(rect));
48 paint_region_rects->push_back(FlutterRect{
49 transformed_rect.x(),
50 transformed_rect.y(),
51 transformed_rect.right(),
52 transformed_rect.bottom(),
53 });
54 }
55
56 auto paint_region = std::make_unique<FlutterRegion>();
57 paint_region->struct_size = sizeof(FlutterRegion);
58 paint_region->rects = paint_region_rects->data();
59 paint_region->rects_count = paint_region_rects->size();
60 rects_referenced_.push_back(std::move(paint_region_rects));
61
62 auto present_info = std::make_unique<FlutterBackingStorePresentInfo>();
63 present_info->struct_size = sizeof(FlutterBackingStorePresentInfo);
64 present_info->paint_region = paint_region.get();
65 regions_referenced_.push_back(std::move(paint_region));
66 layer.backing_store_present_info = present_info.get();
67 layer.presentation_time = presentation_time_;
68
69 present_info_referenced_.push_back(std::move(present_info));
70 presented_layers_.push_back(layer);
71}
SI void store(P *ptr, const T &val)
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
@ kFlutterLayerContentTypeBackingStore
Definition embedder.h:1791
FlutterPoint offset
Definition embedder.h:1833
FlutterLayerContentType type
Definition embedder.h:1822
const FlutterBackingStore * backing_store
Definition embedder.h:1826
FlutterBackingStorePresentInfo * backing_store_present_info
Definition embedder.h:1839
uint64_t presentation_time
Definition embedder.h:1843
size_t struct_size
This size of this struct. Must be sizeof(FlutterLayer).
Definition embedder.h:1819
FlutterSize size
The size of the layer (in physical pixels).
Definition embedder.h:1835
A structure to represent a rectangle.
Definition embedder.h:435
double right
Definition embedder.h:438
A region represented by a collection of non-overlapping rectangles.
Definition embedder.h:1797
double height
Definition embedder.h:423
double width
Definition embedder.h:422
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37
static SkRect Make(const SkISize &size)
Definition SkRect.h:669
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609

◆ PushPlatformViewLayer()

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

Definition at line 135 of file embedder_layers.cc.

137 {
138 {
139 FlutterPlatformView view = {};
140 view.struct_size = sizeof(FlutterPlatformView);
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 // Unsupported mutation.
164 } break;
166 const auto& matrix = mutator->GetMatrix();
167 if (!matrix.isIdentity()) {
168 mutations_array.push_back(
169 mutations_referenced_.emplace_back(ConvertMutation(matrix))
170 .get());
171 }
172 } break;
174 const double opacity =
175 std::clamp(mutator->GetAlphaFloat(), 0.0f, 1.0f);
176 if (opacity < 1.0) {
177 mutations_array.push_back(
178 mutations_referenced_.emplace_back(ConvertMutation(opacity))
179 .get());
180 }
181 } break;
183 break;
184 }
185 }
186
187 if (!mutations_array.empty()) {
188 // If there are going to be any mutations, they must first take into
189 // account the root surface transformation.
190 if (!root_surface_transformation_.isIdentity()) {
191 mutations_array.push_back(
192 mutations_referenced_
193 .emplace_back(ConvertMutation(root_surface_transformation_))
194 .get());
195 }
196
197 auto mutations =
198 std::make_unique<std::vector<const FlutterPlatformViewMutation*>>(
199 mutations_array.rbegin(), mutations_array.rend());
200 mutations_arrays_referenced_.emplace_back(std::move(mutations));
201
202 view.mutations_count = mutations_array.size();
203 view.mutations = mutations_arrays_referenced_.back().get()->data();
204 }
205
206 platform_views_referenced_.emplace_back(
207 std::make_unique<FlutterPlatformView>(view));
208 }
209
210 FlutterLayer layer = {};
211
212 layer.struct_size = sizeof(FlutterLayer);
214 layer.platform_view = platform_views_referenced_.back().get();
215
216 const auto layer_bounds =
217 SkRect::MakeXYWH(params.finalBoundingRect().x(), //
218 params.finalBoundingRect().y(), //
219 params.sizePoints().width() * device_pixel_ratio_, //
220 params.sizePoints().height() * device_pixel_ratio_ //
221 );
222
223 const auto transformed_layer_bounds =
224 root_surface_transformation_.mapRect(layer_bounds);
225
226 layer.offset.x = transformed_layer_bounds.x();
227 layer.offset.y = transformed_layer_bounds.y();
228 layer.size.width = transformed_layer_bounds.width();
229 layer.size.height = transformed_layer_bounds.height();
230
231 layer.presentation_time = presentation_time_;
232
233 presented_layers_.push_back(layer);
234}
bool isIdentity() const
Definition SkMatrix.h:223
static SkString identifier(const FontFamilyDesc &family, const FontDesc &font)
@ kFlutterLayerContentTypePlatformView
Indicates that the contents of this layer are determined by the embedder.
Definition embedder.h:1793
const EmbeddedViewParams * params
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258
static std::unique_ptr< FlutterPlatformViewMutation > ConvertMutation(double opacity)
const myers::Point & get(const myers::Segment &)
const FlutterPlatformView * platform_view
Definition embedder.h:1829
size_t struct_size
The size of this struct. Must be sizeof(FlutterPlatformView).
Definition embedder.h:1714
const FlutterPlatformViewMutation ** mutations
Definition embedder.h:1734
FlutterPlatformViewIdentifier identifier
Definition embedder.h:1718
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

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