Flutter Engine
flutter::EmbedderLayers Class Reference

#include <embedder_layers.h>

Public Types

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

Public Member Functions

 EmbedderLayers (SkISize frame_size, double device_pixel_ratio, SkMatrix root_surface_transformation)
 
 ~EmbedderLayers ()
 
void PushBackingStoreLayer (const FlutterBackingStore *store)
 
void PushPlatformViewLayer (FlutterPlatformViewIdentifier identifier, const EmbeddedViewParams &params)
 
void InvokePresentCallback (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(const std::vector<const FlutterLayer*>& layers)>

Definition at line 33 of file embedder_layers.h.

Constructor & Destructor Documentation

◆ EmbedderLayers()

flutter::EmbedderLayers::EmbedderLayers ( SkISize  frame_size,
double  device_pixel_ratio,
SkMatrix  root_surface_transformation 
)

Definition at line 11 of file embedder_layers.cc.

References ~EmbedderLayers().

14  : frame_size_(frame_size),
15  device_pixel_ratio_(device_pixel_ratio),
16  root_surface_transformation_(root_surface_transformation) {}

◆ ~EmbedderLayers()

flutter::EmbedderLayers::~EmbedderLayers ( )
default

Referenced by EmbedderLayers().

Member Function Documentation

◆ InvokePresentCallback()

void flutter::EmbedderLayers::InvokePresentCallback ( const PresentCallback callback) const

Definition at line 200 of file embedder_layers.cc.

Referenced by flutter::MakeBackingStoreConfig().

201  {
202  std::vector<const FlutterLayer*> presented_layers_pointers;
203  presented_layers_pointers.reserve(presented_layers_.size());
204  for (const auto& layer : presented_layers_) {
205  presented_layers_pointers.push_back(&layer);
206  }
207  callback(std::move(presented_layers_pointers));
208 }

◆ PushBackingStoreLayer()

void flutter::EmbedderLayers::PushBackingStoreLayer ( const FlutterBackingStore store)

Definition at line 20 of file embedder_layers.cc.

References FlutterLayer::backing_store, FlutterSize::height, kFlutterLayerContentTypeBackingStore, FlutterLayer::offset, FlutterLayer::size, FlutterLayer::struct_size, FlutterLayer::type, FlutterSize::width, FlutterPoint::x, and FlutterPoint::y.

Referenced by flutter::MakeBackingStoreConfig().

20  {
21  FlutterLayer layer = {};
22 
23  layer.struct_size = sizeof(FlutterLayer);
25  layer.backing_store = store;
26 
27  const auto layer_bounds =
28  SkRect::MakeWH(frame_size_.width(), frame_size_.height());
29 
30  const auto transformed_layer_bounds =
31  root_surface_transformation_.mapRect(layer_bounds);
32 
33  layer.offset.x = transformed_layer_bounds.x();
34  layer.offset.y = transformed_layer_bounds.y();
35  layer.size.width = transformed_layer_bounds.width();
36  layer.size.height = transformed_layer_bounds.height();
37 
38  presented_layers_.push_back(layer);
39 }
double y
Definition: embedder.h:334
const FlutterBackingStore * backing_store
Definition: embedder.h:893
FlutterSize size
The size of the layer (in physical pixels).
Definition: embedder.h:902
FlutterPoint offset
Definition: embedder.h:900
double x
Definition: embedder.h:333
FlutterLayerContentType type
Definition: embedder.h:889
double width
Definition: embedder.h:311
double height
Definition: embedder.h:312
size_t struct_size
This size of this struct. Must be sizeof(FlutterLayer).
Definition: embedder.h:886

◆ PushPlatformViewLayer()

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

Definition at line 103 of file embedder_layers.cc.

References flutter::clip_path, flutter::clip_rect, flutter::clip_rrect, flutter::ConvertMutation(), flutter::EmbeddedViewParams::finalBoundingRect(), FlutterSize::height, FlutterPlatformView::identifier, kFlutterLayerContentTypePlatformView, FlutterPlatformView::mutations, FlutterPlatformView::mutations_count, flutter::EmbeddedViewParams::mutatorsStack(), FlutterLayer::offset, flutter::opacity, FlutterLayer::platform_view, FlutterLayer::size, flutter::EmbeddedViewParams::sizePoints(), FlutterPlatformView::struct_size, FlutterLayer::struct_size, flutter::transform, FlutterLayer::type, FlutterSize::width, FlutterPoint::x, and FlutterPoint::y.

Referenced by flutter::MakeBackingStoreConfig().

105  {
106  {
107  FlutterPlatformView view = {};
108  view.struct_size = sizeof(FlutterPlatformView);
109  view.identifier = identifier;
110 
111  const auto& mutators = params.mutatorsStack();
112 
113  std::vector<const FlutterPlatformViewMutation*> mutations_array;
114 
115  for (auto i = mutators.Bottom(); i != mutators.Top(); ++i) {
116  const auto& mutator = *i;
117  switch (mutator->GetType()) {
118  case MutatorType::clip_rect: {
119  mutations_array.push_back(
120  mutations_referenced_
121  .emplace_back(ConvertMutation(mutator->GetRect()))
122  .get());
123  } break;
125  mutations_array.push_back(
126  mutations_referenced_
127  .emplace_back(ConvertMutation(mutator->GetRRect()))
128  .get());
129  } break;
130  case MutatorType::clip_path: {
131  // Unsupported mutation.
132  } break;
133  case MutatorType::transform: {
134  const auto& matrix = mutator->GetMatrix();
135  if (!matrix.isIdentity()) {
136  mutations_array.push_back(
137  mutations_referenced_.emplace_back(ConvertMutation(matrix))
138  .get());
139  }
140  } break;
141  case MutatorType::opacity: {
142  const double opacity =
143  std::clamp(mutator->GetAlphaFloat(), 0.0f, 1.0f);
144  if (opacity < 1.0) {
145  mutations_array.push_back(
146  mutations_referenced_.emplace_back(ConvertMutation(opacity))
147  .get());
148  }
149  } break;
150  }
151  }
152 
153  if (!mutations_array.empty()) {
154  // If there are going to be any mutations, they must first take into
155  // account the root surface transformation.
156  if (!root_surface_transformation_.isIdentity()) {
157  mutations_array.push_back(
158  mutations_referenced_
159  .emplace_back(ConvertMutation(root_surface_transformation_))
160  .get());
161  }
162 
163  auto mutations =
164  std::make_unique<std::vector<const FlutterPlatformViewMutation*>>(
165  mutations_array.rbegin(), mutations_array.rend());
166  mutations_arrays_referenced_.emplace_back(std::move(mutations));
167 
168  view.mutations_count = mutations_array.size();
169  view.mutations = mutations_arrays_referenced_.back().get()->data();
170  }
171 
172  platform_views_referenced_.emplace_back(
173  std::make_unique<FlutterPlatformView>(view));
174  }
175 
176  FlutterLayer layer = {};
177 
178  layer.struct_size = sizeof(FlutterLayer);
180  layer.platform_view = platform_views_referenced_.back().get();
181 
182  const auto layer_bounds =
183  SkRect::MakeXYWH(params.finalBoundingRect().x(), //
184  params.finalBoundingRect().y(), //
185  params.sizePoints().width() * device_pixel_ratio_, //
186  params.sizePoints().height() * device_pixel_ratio_ //
187  );
188 
189  const auto transformed_layer_bounds =
190  root_surface_transformation_.mapRect(layer_bounds);
191 
192  layer.offset.x = transformed_layer_bounds.x();
193  layer.offset.y = transformed_layer_bounds.y();
194  layer.size.width = transformed_layer_bounds.width();
195  layer.size.height = transformed_layer_bounds.height();
196 
197  presented_layers_.push_back(layer);
198 }
double y
Definition: embedder.h:334
FlutterPlatformViewIdentifier identifier
Definition: embedder.h:822
FlutterSize size
The size of the layer (in physical pixels).
Definition: embedder.h:902
FlutterPoint offset
Definition: embedder.h:900
Indicates that the contents of this layer are determined by the embedder.
Definition: embedder.h:881
double x
Definition: embedder.h:333
const FlutterPlatformView * platform_view
Definition: embedder.h:896
FlutterLayerContentType type
Definition: embedder.h:889
size_t mutations_count
Definition: embedder.h:825
double width
Definition: embedder.h:311
const FlutterPlatformViewMutation ** mutations
Definition: embedder.h:838
double height
Definition: embedder.h:312
size_t struct_size
The size of this struct. Must be sizeof(FlutterPlatformView).
Definition: embedder.h:818
static std::unique_ptr< FlutterPlatformViewMutation > ConvertMutation(double opacity)
size_t struct_size
This size of this struct. Must be sizeof(FlutterLayer).
Definition: embedder.h:886

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