Flutter iOS Embedder
FlutterPlatformViewsController.mm
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 #include "display_list/geometry/dl_geometry_types.h"
7 #include "impeller/geometry/rounding_radii.h"
8 
9 #include "flutter/display_list/effects/image_filters/dl_blur_image_filter.h"
10 #include "flutter/display_list/utils/dl_matrix_clip_tracker.h"
11 #include "flutter/flow/surface_frame.h"
12 #include "flutter/flow/view_slicer.h"
13 #include "flutter/fml/logging.h"
14 #include "flutter/fml/make_copyable.h"
15 #include "flutter/fml/synchronization/count_down_latch.h"
16 #import "flutter/shell/platform/darwin/common/InternalFlutterSwiftCommon/InternalFlutterSwiftCommon.h"
21 
22 using flutter::DlISize;
23 using flutter::DlMatrix;
24 using flutter::DlRect;
25 using flutter::DlRoundRect;
26 
27 static constexpr NSUInteger kFlutterClippingMaskViewPoolCapacity = 5;
28 
29 static NSString* const kGestureBlockingPolicyEagerValue = @"eager";
30 static NSString* const kGestureBlockingPolicyWaitUntilTouchesEndedValue = @"waitUntilTouchesEnded";
31 static NSString* const kGestureBlockingPolicyDoNotBlockGesture = @"doNotBlockGesture";
32 static NSString* const kGestureBlockingPolicyFallbackToPluginDefault = @"fallbackToPluginDefault";
33 
34 struct LayerData {
35  DlRect rect;
36  int64_t view_id;
37  int64_t overlay_id;
38  std::shared_ptr<flutter::OverlayLayer> layer;
39 };
40 using LayersMap = std::unordered_map<int64_t, LayerData>;
41 
42 /// Each of the following structs stores part of the platform view hierarchy according to its
43 /// ID.
44 ///
45 /// This data must only be accessed on the platform thread.
47  NSObject<FlutterPlatformView>* view;
49  UIView* root_view;
50 };
51 
52 // Converts a DlMatrix to CATransform3D.
53 static CATransform3D GetCATransform3DFromDlMatrix(const DlMatrix& matrix) {
54  CATransform3D transform = CATransform3DIdentity;
55  transform.m11 = matrix.m[0];
56  transform.m12 = matrix.m[1];
57  transform.m13 = matrix.m[2];
58  transform.m14 = matrix.m[3];
59 
60  transform.m21 = matrix.m[4];
61  transform.m22 = matrix.m[5];
62  transform.m23 = matrix.m[6];
63  transform.m24 = matrix.m[7];
64 
65  transform.m31 = matrix.m[8];
66  transform.m32 = matrix.m[9];
67  transform.m33 = matrix.m[10];
68  transform.m34 = matrix.m[11];
69 
70  transform.m41 = matrix.m[12];
71  transform.m42 = matrix.m[13];
72  transform.m43 = matrix.m[14];
73  transform.m44 = matrix.m[15];
74  return transform;
75 }
76 
77 // Reset the anchor of `layer` to match the transform operation from flow.
78 //
79 // The position of the `layer` should be unchanged after resetting the anchor.
80 static void ResetAnchor(CALayer* layer) {
81  // Flow uses (0, 0) to apply transform matrix so we need to match that in Quartz.
82  layer.anchorPoint = CGPointZero;
83  layer.position = CGPointZero;
84 }
85 
86 static CGRect GetCGRectFromDlRect(const DlRect& clipDlRect) {
87  return CGRectMake(clipDlRect.GetLeft(), //
88  clipDlRect.GetTop(), //
89  clipDlRect.GetWidth(), //
90  clipDlRect.GetHeight());
91 }
92 
94 
95 // The pool of reusable view layers. The pool allows to recycle layer in each frame.
96 @property(nonatomic, readonly) flutter::OverlayLayerPool* layerPool;
97 
98 // The platform view's |EmbedderViewSlice| keyed off the view id, which contains any subsequent
99 // operation until the next platform view or the end of the last leaf node in the layer tree.
100 //
101 // The Slices are deleted by the PlatformViewsController.reset().
102 @property(nonatomic, readonly)
103  std::unordered_map<int64_t, std::unique_ptr<flutter::EmbedderViewSlice>>& slices;
104 
105 @property(nonatomic, readonly) FlutterClippingMaskViewPool* maskViewPool;
106 
107 @property(nonatomic, readonly)
108  NSMutableDictionary<NSString*, NSObject<FlutterPlatformViewFactory>*>* factories;
109 
110 // The FlutterPlatformViewGestureRecognizersBlockingPolicy for each type of platform view, boxed in
111 // an NSNumber.
112 @property(nonatomic, readonly)
113  NSMutableDictionary<NSString*, NSNumber*>* gestureRecognizersBlockingPoliciesByType;
114 
115 /// The size of the current onscreen surface in physical pixels.
116 @property(nonatomic, assign) DlISize frameSize;
117 
118 /// The task runner for posting tasks to the platform thread.
119 @property(nonatomic, readonly) FlutterFMLTaskRunner* platformTaskRunner;
120 
121 /// This data must only be accessed on the platform thread.
122 @property(nonatomic, readonly) std::unordered_map<int64_t, PlatformViewData>& platformViews;
123 
124 /// The composition parameters for each platform view.
125 ///
126 /// This state is only modified on the raster thread.
127 @property(nonatomic, readonly)
128  std::unordered_map<int64_t, flutter::EmbeddedViewParams>& currentCompositionParams;
129 
130 /// Method channel `OnDispose` calls adds the views to be disposed to this set to be disposed on
131 /// the next frame.
132 ///
133 /// This state is modified on both the platform and raster thread.
134 @property(nonatomic, readonly) std::unordered_set<int64_t>& viewsToDispose;
135 
136 /// view IDs in composition order.
137 ///
138 /// This state is only modified on the raster thread.
139 @property(nonatomic, readonly) std::vector<int64_t>& compositionOrder;
140 
141 /// platform view IDs visited during layer tree composition.
142 ///
143 /// This state is only modified on the raster thread.
144 @property(nonatomic, readonly) std::vector<int64_t>& visitedPlatformViews;
145 
146 /// Only composite platform views in this set.
147 ///
148 /// This state is only modified on the raster thread.
149 @property(nonatomic, readonly) std::unordered_set<int64_t>& viewsToRecomposite;
150 
151 /// Whether the previous frame had any platform views in active composition order.
152 ///
153 /// This state is tracked so that the first frame after removing the last platform view
154 /// runs through the platform view rendering code path, giving us a chance to remove the
155 /// platform view from the UIView hierarchy.
156 ///
157 /// Only accessed from the raster thread.
158 @property(nonatomic, assign) BOOL hadPlatformViews;
159 
160 /// Whether blurred backdrop filters can be applied.
161 ///
162 /// Defaults to YES, but becomes NO if blurred backdrop filters cannot be applied.
163 @property(nonatomic, assign) BOOL canApplyBlurBackdrop;
164 
165 /// Populate any missing overlay layers.
166 ///
167 /// This requires posting a task to the platform thread and blocking on its completion.
168 - (void)createMissingOverlays:(size_t)requiredOverlayLayers
169  withIosContext:(const std::shared_ptr<flutter::IOSContext>&)iosContext;
170 
171 /// Update the buffers and mutate the platform views in CATransaction on the platform thread.
172 - (void)performSubmit:(const LayersMap&)platformViewLayers
173  currentCompositionParams:
174  (std::unordered_map<int64_t, flutter::EmbeddedViewParams>&)currentCompositionParams
175  viewsToRecomposite:(const std::unordered_set<int64_t>&)viewsToRecomposite
176  compositionOrder:(const std::vector<int64_t>&)compositionOrder
177  unusedLayers:
178  (const std::vector<std::shared_ptr<flutter::OverlayLayer>>&)unusedLayers
179  surfaceFrames:
180  (const std::vector<std::unique_ptr<flutter::SurfaceFrame>>&)surfaceFrames;
181 
182 - (void)onCreate:(FlutterMethodCall*)call result:(FlutterResult)result;
183 - (void)onDispose:(FlutterMethodCall*)call result:(FlutterResult)result;
184 - (void)onAcceptGesture:(FlutterMethodCall*)call result:(FlutterResult)result;
185 - (void)onRejectGesture:(FlutterMethodCall*)call result:(FlutterResult)result;
186 
187 - (void)clipViewSetMaskView:(UIView*)clipView;
188 
189 // Applies the mutators in the mutatorsStack to the UIView chain that was constructed by
190 // `ReconstructClipViewsChain`
191 //
192 // Clips are applied to the `embeddedView`'s super view(|ChildClippingView|) using a
193 // |FlutterClippingMaskView|. Transforms are applied to `embeddedView`
194 //
195 // The `boundingRect` is the final bounding rect of the PlatformView
196 // (EmbeddedViewParams::finalBoundingRect). If a clip mutator's rect contains the final bounding
197 // rect of the PlatformView, the clip mutator is not applied for performance optimization.
198 //
199 // This method is only called when the `embeddedView` needs to be re-composited at the current
200 // frame. See: `compositeView:withParams:` for details.
201 - (void)applyMutators:(const flutter::MutatorsStack&)mutatorsStack
202  embeddedView:(UIView*)embeddedView
203  boundingRect:(const DlRect&)boundingRect;
204 
205 // Appends the overlay views and platform view and sets their z index based on the composition
206 // order.
207 - (void)bringLayersIntoView:(const LayersMap&)layerMap
208  withCompositionOrder:(const std::vector<int64_t>&)compositionOrder;
209 
210 - (std::shared_ptr<flutter::OverlayLayer>)nextLayerInPool;
211 
212 /// Runs on the platform thread.
213 - (void)createLayerWithIosContext:(const std::shared_ptr<flutter::IOSContext>&)iosContext
214  pixelFormat:(MTLPixelFormat)pixelFormat;
215 
216 /// Removes overlay views and platform views that aren't needed in the current frame.
217 /// Must run on the platform thread.
218 - (void)removeUnusedLayers:(const std::vector<std::shared_ptr<flutter::OverlayLayer>>&)unusedLayers
219  withCompositionOrder:(const std::vector<int64_t>&)compositionOrder;
220 
221 /// Computes and returns all views to be disposed on the platform thread, removes them from
222 /// self.platformViews, self.viewsToRecomposite, and self.currentCompositionParams. Any views that
223 /// still require compositing are not returned, but instead added to `viewsToDelayDispose` for
224 /// disposal on the next call.
225 - (std::vector<UIView*>)computeViewsToDispose;
226 
227 /// Resets the state of the frame.
228 - (void)resetFrameState;
229 @end
230 
231 @implementation FlutterPlatformViewsController {
232  // TODO(cbracken): Replace with Obj-C types and use @property declarations to automatically
233  // synthesize the ivars.
234  //
235  // These ivars are required because we're transitioning the previous C++ implementation to Obj-C.
236  // We require ivars to declare the concrete types and then wrap with @property declarations that
237  // return a reference to the ivar, allowing for use like `self.layerPool` and
238  // `self.slices[viewId] = x`.
239  std::unique_ptr<flutter::OverlayLayerPool> _layerPool;
240  std::unordered_map<int64_t, std::unique_ptr<flutter::EmbedderViewSlice>> _slices;
241  NSMutableDictionary<NSString*, NSObject<FlutterPlatformViewFactory>*>* _factories;
242  NSMutableDictionary<NSString*, NSNumber*>* _gestureRecognizersBlockingPoliciesByType;
244  std::unordered_map<int64_t, PlatformViewData> _platformViews;
245  std::unordered_map<int64_t, flutter::EmbeddedViewParams> _currentCompositionParams;
246  std::unordered_set<int64_t> _viewsToDispose;
247  std::vector<int64_t> _compositionOrder;
248  std::vector<int64_t> _visitedPlatformViews;
249  std::unordered_set<int64_t> _viewsToRecomposite;
250  std::vector<int64_t> _previousCompositionOrder;
251 }
252 
253 - (id)init {
254  if (self = [super init]) {
255  _layerPool = std::make_unique<flutter::OverlayLayerPool>();
256  _factories = [[NSMutableDictionary alloc] init];
257  _gestureRecognizersBlockingPoliciesByType = [[NSMutableDictionary alloc] init];
258  _maskViewPool =
259  [[FlutterClippingMaskViewPool alloc] initWithCapacity:kFlutterClippingMaskViewPoolCapacity];
260  _hadPlatformViews = NO;
261  _canApplyBlurBackdrop = YES;
262  }
263  return self;
264 }
265 
266 - (FlutterFMLTaskRunner*)taskRunner {
267  return _platformTaskRunner;
268 }
269 
270 - (void)setTaskRunner:(FlutterFMLTaskRunner*)platformTaskRunner {
271  _platformTaskRunner = platformTaskRunner;
272 }
273 
274 - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
275  if ([[call method] isEqualToString:@"create"]) {
276  [self onCreate:call result:result];
277  } else if ([[call method] isEqualToString:@"dispose"]) {
278  [self onDispose:call result:result];
279  } else if ([[call method] isEqualToString:@"acceptGesture"]) {
280  [self onAcceptGesture:call result:result];
281  } else if ([[call method] isEqualToString:@"rejectGesture"]) {
282  [self onRejectGesture:call result:result];
283  } else {
285  }
286 }
287 
288 - (void)onCreate:(FlutterMethodCall*)call result:(FlutterResult)result {
289  NSDictionary<NSString*, id>* args = [call arguments];
290 
291  int64_t viewId = [args[@"id"] longLongValue];
292  // A missing argument arrives as nil and an explicit Dart null as NSNull, neither of which can be
293  // converted to a view type.
294  NSString* viewTypeString = args[@"viewType"];
295  if (![viewTypeString isKindOfClass:[NSString class]]) {
296  result([FlutterError
297  errorWithCode:@"unknown_view"
298  message:@"'viewType' argument must be a string to create a platform view."
299  details:nil]);
300  return;
301  }
302  if (self.platformViews.count(viewId) != 0) {
303  result([FlutterError errorWithCode:@"recreating_view"
304  message:@"trying to create an already created view"
305  details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
306  return;
307  }
308 
309  NSObject<FlutterPlatformViewFactory>* factory = self.factories[viewTypeString];
310  if (factory == nil) {
311  result([FlutterError
312  errorWithCode:@"unregistered_view_type"
313  message:[NSString stringWithFormat:@"A UIKitView widget is trying to create a "
314  @"PlatformView with an unregistered type: < %@ >",
315  viewTypeString]
316  details:@"If you are the author of the PlatformView, make sure `registerViewFactory` "
317  @"is invoked.\n"
318  @"See: "
319  @"https://docs.flutter.cn/development/platform-integration/"
320  @"platform-views#on-the-platform-side-1 for more details.\n"
321  @"If you are not the author of the PlatformView, make sure to call "
322  @"`GeneratedPluginRegistrant.register`."]);
323  return;
324  }
325 
326  id params = nil;
327  if ([factory respondsToSelector:@selector(createArgsCodec)]) {
328  NSObject<FlutterMessageCodec>* codec = [factory createArgsCodec];
329  if (codec != nil && args[@"params"] != nil) {
330  FlutterStandardTypedData* paramsData = args[@"params"];
331  params = [codec decode:paramsData.data];
332  }
333  }
334 
335  NSObject<FlutterPlatformView>* embeddedView = [factory createWithFrame:CGRectZero
336  viewIdentifier:viewId
337  arguments:params];
338  UIView* platformView = [embeddedView view];
339  // Set a unique view identifier, so the platform view can be identified in unit tests.
340  platformView.accessibilityIdentifier = [NSString stringWithFormat:@"platform_view[%lld]", viewId];
341 
342  NSString* gestureBlockingPolicyValue = args[@"gestureBlockingPolicy"];
344  if ([gestureBlockingPolicyValue isEqualToString:kGestureBlockingPolicyDoNotBlockGesture]) {
346  } else if ([gestureBlockingPolicyValue isEqualToString:kGestureBlockingPolicyEagerValue]) {
348  } else if ([gestureBlockingPolicyValue
350  gestureBlockingPolicy =
352  } else if ([gestureBlockingPolicyValue
354  gestureBlockingPolicy = static_cast<FlutterPlatformViewGestureRecognizersBlockingPolicy>(
355  self.gestureRecognizersBlockingPoliciesByType[viewTypeString].integerValue);
356  } else {
357  result([FlutterError
358  errorWithCode:@"unknown_gesture_blocking_policy"
359  message:@"Trying to create a platform view with an unknown gesture blocking policy"
360  details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
361  return;
362  }
363 
364  FlutterTouchInterceptingView* touchInterceptor =
365  [[FlutterTouchInterceptingView alloc] initWithEmbeddedView:platformView
366  platformViewsController:self
367  gestureRecognizersBlockingPolicy:gestureBlockingPolicy];
368 
369  ChildClippingView* clippingView = [[ChildClippingView alloc] initWithFrame:CGRectZero];
370  [clippingView addSubview:touchInterceptor];
371 
372  self.platformViews.emplace(viewId, PlatformViewData{
373  .view = embeddedView, //
374  .touch_interceptor = touchInterceptor, //
375  .root_view = clippingView //
376  });
377 
378  result(nil);
379 }
380 
381 - (void)onDispose:(FlutterMethodCall*)call result:(FlutterResult)result {
382  NSNumber* arg = [call arguments];
383  int64_t viewId = [arg longLongValue];
384 
385  if (self.platformViews.count(viewId) == 0) {
386  result([FlutterError errorWithCode:@"unknown_view"
387  message:@"trying to dispose an unknown"
388  details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
389  return;
390  }
391  // We wait for next submitFrame to dispose views.
392  self.viewsToDispose.insert(viewId);
393  result(nil);
394 }
395 
396 - (void)onAcceptGesture:(FlutterMethodCall*)call result:(FlutterResult)result {
397  NSDictionary<NSString*, id>* args = [call arguments];
398  int64_t viewId = [args[@"id"] longLongValue];
399 
400  if (self.platformViews.count(viewId) == 0) {
401  result([FlutterError errorWithCode:@"unknown_view"
402  message:@"trying to set gesture state for an unknown view"
403  details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
404  return;
405  }
406 
407  FlutterTouchInterceptingView* view = self.platformViews[viewId].touch_interceptor;
408  [view releaseGesture];
409 
410  result(nil);
411 }
412 
413 - (void)onRejectGesture:(FlutterMethodCall*)call result:(FlutterResult)result {
414  NSDictionary<NSString*, id>* args = [call arguments];
415  int64_t viewId = [args[@"id"] longLongValue];
416 
417  if (self.platformViews.count(viewId) == 0) {
418  result([FlutterError errorWithCode:@"unknown_view"
419  message:@"trying to set gesture state for an unknown view"
420  details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
421  return;
422  }
423 
424  FlutterTouchInterceptingView* view = self.platformViews[viewId].touch_interceptor;
425  [view blockGesture];
426 
427  result(nil);
428 }
429 
430 - (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
431  withId:(NSString*)factoryId
432  gestureRecognizersBlockingPolicy:
433  (FlutterPlatformViewGestureRecognizersBlockingPolicy)gestureRecognizerBlockingPolicy {
434  FML_CHECK(self.factories[factoryId] == nil);
435  self.factories[factoryId] = factory;
436  self.gestureRecognizersBlockingPoliciesByType[factoryId] = @(gestureRecognizerBlockingPolicy);
437 }
438 
439 - (void)beginFrameWithSize:(DlISize)frameSize {
440  [self resetFrameState];
441  self.frameSize = frameSize;
442 }
443 
444 - (void)cancelFrame {
445  [self resetFrameState];
446 }
447 
448 - (void)pushFilterToVisitedPlatformViews:(const std::shared_ptr<flutter::DlImageFilter>&)filter
449  withRect:(const flutter::DlRect&)filterRect {
450  for (int64_t id : self.visitedPlatformViews) {
451  flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
452  params.PushImageFilter(filter, filterRect);
453  self.currentCompositionParams[id] = params;
454  }
455 }
456 
457 - (void)prerollCompositeEmbeddedView:(int64_t)viewId
458  withParams:(std::unique_ptr<flutter::EmbeddedViewParams>)params {
459  DlRect viewBounds = DlRect::MakeSize(self.frameSize);
460  std::unique_ptr<flutter::EmbedderViewSlice> view;
461  view = std::make_unique<flutter::DisplayListEmbedderViewSlice>(viewBounds);
462  self.slices.insert_or_assign(viewId, std::move(view));
463 
464  self.compositionOrder.push_back(viewId);
465 
466  if (self.currentCompositionParams.count(viewId) == 1 &&
467  self.currentCompositionParams[viewId] == *params.get()) {
468  // Do nothing if the params didn't change.
469  return;
470  }
471  self.currentCompositionParams[viewId] = flutter::EmbeddedViewParams(*params.get());
472  self.viewsToRecomposite.insert(viewId);
473 }
474 
475 - (size_t)embeddedViewCount {
476  return self.compositionOrder.size();
477 }
478 
479 - (UIView*)platformViewForId:(int64_t)viewId {
480  return [self flutterTouchInterceptingViewForId:viewId].embeddedView;
481 }
482 
483 - (FlutterTouchInterceptingView*)flutterTouchInterceptingViewForId:(int64_t)viewId {
484  if (self.platformViews.empty()) {
485  return nil;
486  }
487  return self.platformViews[viewId].touch_interceptor;
488 }
489 
490 - (long)firstResponderPlatformViewId {
491  for (auto const& [id, platformViewData] : self.platformViews) {
492  UIView* rootView = platformViewData.root_view;
493  if (rootView.flt_hasFirstResponderInViewHierarchySubtree) {
494  return id;
495  }
496  }
497  return -1;
498 }
499 
500 - (void)clipViewSetMaskView:(UIView*)clipView {
501  FML_DCHECK([[NSThread currentThread] isMainThread]);
502  if (clipView.maskView) {
503  return;
504  }
505  CGRect frame =
506  CGRectMake(-clipView.frame.origin.x, -clipView.frame.origin.y,
507  CGRectGetWidth(self.flutterView.bounds), CGRectGetHeight(self.flutterView.bounds));
508  clipView.maskView = [self.maskViewPool getMaskViewWithFrame:frame];
509 }
510 
511 - (void)applyMutators:(const flutter::MutatorsStack&)mutatorsStack
512  embeddedView:(UIView*)embeddedView
513  boundingRect:(const DlRect&)boundingRect {
514  if (self.flutterView == nil) {
515  return;
516  }
517 
518  ResetAnchor(embeddedView.layer);
519  ChildClippingView* clipView = (ChildClippingView*)embeddedView.superview;
520 
521  DlMatrix transformMatrix;
522  NSMutableArray* blurFilters = [[NSMutableArray alloc] init];
523  NSMutableArray<PendingRRectClip*>* pendingClipRRects = [[NSMutableArray alloc] init];
524 
525  FML_DCHECK(!clipView.maskView ||
526  [clipView.maskView isKindOfClass:[FlutterClippingMaskView class]]);
527  if (clipView.maskView) {
528  [self.maskViewPool insertViewToPoolIfNeeded:(FlutterClippingMaskView*)(clipView.maskView)];
529  clipView.maskView = nil;
530  }
531  CGFloat screenScale = [UIScreen mainScreen].scale;
532  auto iter = mutatorsStack.Begin();
533  while (iter != mutatorsStack.End()) {
534  switch ((*iter)->GetType()) {
535  case flutter::MutatorType::kTransform: {
536  transformMatrix = transformMatrix * (*iter)->GetMatrix();
537  break;
538  }
539  case flutter::MutatorType::kClipRect: {
540  if (flutter::DisplayListMatrixClipState::TransformedRectCoversBounds(
541  (*iter)->GetRect(), transformMatrix, boundingRect)) {
542  break;
543  }
544  [self clipViewSetMaskView:clipView];
545  [(FlutterClippingMaskView*)clipView.maskView clipRect:(*iter)->GetRect()
546  matrix:transformMatrix];
547  break;
548  }
549  case flutter::MutatorType::kClipRRect: {
550  if (flutter::DisplayListMatrixClipState::TransformedRRectCoversBounds(
551  (*iter)->GetRRect(), transformMatrix, boundingRect)) {
552  break;
553  }
554  [self clipViewSetMaskView:clipView];
555  [(FlutterClippingMaskView*)clipView.maskView clipRRect:(*iter)->GetRRect()
556  matrix:transformMatrix];
557  break;
558  }
559  case flutter::MutatorType::kClipRSE: {
560  if (flutter::DisplayListMatrixClipState::TransformedRoundSuperellipseCoversBounds(
561  (*iter)->GetRSE(), transformMatrix, boundingRect)) {
562  break;
563  }
564  [self clipViewSetMaskView:clipView];
565  [(FlutterClippingMaskView*)clipView.maskView clipRRect:(*iter)->GetRSEApproximation()
566  matrix:transformMatrix];
567  break;
568  }
569  case flutter::MutatorType::kClipPath: {
570  // TODO(cyanglaz): Find a way to pre-determine if path contains the PlatformView boudning
571  // rect. See `ClipRRectContainsPlatformViewBoundingRect`.
572  // https://github.com/flutter/flutter/issues/118650
573  [self clipViewSetMaskView:clipView];
574  [(FlutterClippingMaskView*)clipView.maskView clipPath:(*iter)->GetPath()
575  matrix:transformMatrix];
576  break;
577  }
578  case flutter::MutatorType::kOpacity:
579  embeddedView.alpha = (*iter)->GetAlphaFloat() * embeddedView.alpha;
580  break;
581  case flutter::MutatorType::kBackdropFilter: {
582  // Only support DlBlurImageFilter for BackdropFilter.
583  if (!self.canApplyBlurBackdrop || !(*iter)->GetFilterMutation().GetFilter().asBlur()) {
584  break;
585  }
586  CGRect filterRect = GetCGRectFromDlRect((*iter)->GetFilterMutation().GetFilterRect());
587  // `filterRect` is in global coordinates. We need to convert to local space.
588  filterRect = CGRectApplyAffineTransform(
589  filterRect, CGAffineTransformMakeScale(1 / screenScale, 1 / screenScale));
590  // `filterRect` reprents the rect that should be filtered inside the `_flutterView`.
591  // The `PlatformViewFilter` needs the frame inside the `clipView` that needs to be
592  // filtered.
593  if (CGRectIsNull(CGRectIntersection(filterRect, clipView.frame))) {
594  break;
595  }
596  CGRect intersection = CGRectIntersection(filterRect, clipView.frame);
597  CGRect frameInClipView = [self.flutterView convertRect:intersection toView:clipView];
598  // sigma_x is arbitrarily chosen as the radius value because Quartz sets
599  // sigma_x and sigma_y equal to each other. DlBlurImageFilter's Tile Mode
600  // is not supported in Quartz's gaussianBlur CAFilter, so it is not used
601  // to blur the PlatformView.
602  CGFloat blurRadius = (*iter)->GetFilterMutation().GetFilter().asBlur()->sigma_x();
603  UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc]
604  initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
605 
606  // TODO(https://github.com/flutter/flutter/issues/179126)
607  CGFloat cornerRadius = 0.0;
608  BOOL isRoundedSuperellipse = NO;
609  // If there's multiple clips, this uses the innermost to decide if its
610  // rse or not. The assumption being the innermost will be the tightest
611  if ([pendingClipRRects count] > 0) {
612  cornerRadius = pendingClipRRects.lastObject.topLeftRadius;
613  isRoundedSuperellipse = pendingClipRRects.lastObject.isRoundedSuperellipse;
614  [pendingClipRRects removeAllObjects];
615  }
616  visualEffectView.layer.cornerRadius = cornerRadius;
617  visualEffectView.layer.cornerCurve =
618  isRoundedSuperellipse ? kCACornerCurveContinuous : kCACornerCurveCircular;
619  visualEffectView.clipsToBounds = YES;
620 
621  PlatformViewFilter* filter = [[PlatformViewFilter alloc] initWithFrame:frameInClipView
622  blurRadius:blurRadius
623  cornerRadius:cornerRadius
624  isRoundedSuperellipse:isRoundedSuperellipse
625  visualEffectView:visualEffectView];
626  if (!filter) {
627  self.canApplyBlurBackdrop = NO;
628  } else {
629  [blurFilters addObject:filter];
630  }
631  break;
632  }
633  case flutter::MutatorType::kBackdropClipRect: {
634  // The frame already handles cropping into the rect so this can
635  // no-op
636  break;
637  }
638  case flutter::MutatorType::kBackdropClipRRect: {
639  PendingRRectClip* clip = [[PendingRRectClip alloc] init];
640  DlRoundRect rrect = (*iter)->GetBackdropClipRRect().rrect;
641 
642  clip.rect = boundingRect;
643  impeller::RoundingRadii radii = rrect.GetRadii();
644  clip.topLeftRadius = radii.top_left.width;
645  clip.topRightRadius = radii.top_right.width;
646  clip.bottomLeftRadius = radii.bottom_left.width;
647  clip.bottomRightRadius = radii.bottom_right.width;
648  [pendingClipRRects addObject:clip];
649  break;
650  }
651  case flutter::MutatorType::kBackdropClipRSuperellipse: {
652  PendingRRectClip* clip = [[PendingRRectClip alloc] init];
653  flutter::DlRoundSuperellipse rse = (*iter)->GetBackdropClipRSuperellipse().rse;
654 
655  clip.rect = boundingRect;
656  impeller::RoundingRadii radii = rse.GetRadii();
657  clip.topLeftRadius = radii.top_left.width;
658  clip.topRightRadius = radii.top_right.width;
659  clip.bottomLeftRadius = radii.bottom_left.width;
660  clip.bottomRightRadius = radii.bottom_right.width;
661  clip.isRoundedSuperellipse = YES;
662  [pendingClipRRects addObject:clip];
663  break;
664  }
665  case flutter::MutatorType::kBackdropClipPath: {
666  // TODO(https://github.com/flutter/flutter/issues/179127)
667  break;
668  }
669  }
670  ++iter;
671  }
672 
673  if (self.canApplyBlurBackdrop) {
674  [clipView applyBlurBackdropFilters:blurFilters];
675  }
676 
677  // The UIKit frame is set based on the logical resolution (points) instead of physical.
678  // (https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Displays/Displays.html).
679  // However, flow is based on the physical resolution. For example, 1000 pixels in flow equals
680  // 500 points in UIKit for devices that has screenScale of 2. We need to scale the transformMatrix
681  // down to the logical resoltion before applying it to the layer of PlatformView.
682  flutter::DlScalar pointScale = 1.0 / screenScale;
683  transformMatrix = DlMatrix::MakeScale({pointScale, pointScale, 1}) * transformMatrix;
684 
685  // Reverse the offset of the clipView.
686  // The clipView's frame includes the final translate of the final transform matrix.
687  // Thus, this translate needs to be reversed so the platform view can layout at the correct
688  // offset.
689  //
690  // Note that the transforms are not applied to the clipping paths because clipping paths happen on
691  // the mask view, whose origin is always (0,0) to the _flutterView.
692  impeller::Vector3 origin = impeller::Vector3(clipView.frame.origin.x, clipView.frame.origin.y);
693  transformMatrix = DlMatrix::MakeTranslation(-origin) * transformMatrix;
694 
695  embeddedView.layer.transform = GetCATransform3DFromDlMatrix(transformMatrix);
696 }
697 
698 - (void)compositeView:(int64_t)viewId withParams:(const flutter::EmbeddedViewParams&)params {
699  // TODO(https://github.com/flutter/flutter/issues/109700)
700  CGRect frame = CGRectMake(0, 0, params.sizePoints().width, params.sizePoints().height);
701  FlutterTouchInterceptingView* touchInterceptor = self.platformViews[viewId].touch_interceptor;
702  touchInterceptor.layer.transform = CATransform3DIdentity;
703  touchInterceptor.frame = frame;
704  touchInterceptor.alpha = 1;
705 
706  const flutter::MutatorsStack& mutatorStack = params.mutatorsStack();
707  UIView* clippingView = self.platformViews[viewId].root_view;
708  // The frame of the clipping view should be the final bounding rect.
709  // Because the translate matrix in the Mutator Stack also includes the offset,
710  // when we apply the transforms matrix in |applyMutators:embeddedView:boundingRect|, we need
711  // to remember to do a reverse translate.
712  const DlRect& rect = params.finalBoundingRect();
713  CGFloat screenScale = [UIScreen mainScreen].scale;
714  clippingView.frame = CGRectMake(rect.GetX() / screenScale, rect.GetY() / screenScale,
715  rect.GetWidth() / screenScale, rect.GetHeight() / screenScale);
716  [self applyMutators:mutatorStack embeddedView:touchInterceptor boundingRect:rect];
717 }
718 
719 - (flutter::DlCanvas*)compositeEmbeddedViewWithId:(int64_t)viewId {
720  FML_DCHECK(self.slices.find(viewId) != self.slices.end());
721  return self.slices[viewId]->canvas();
722 }
723 
724 - (void)reset {
725  // Reset will only be called from the raster thread or a merged raster/platform thread.
726  // _platformViews must only be modified on the platform thread, and any operations that
727  // read or modify platform views should occur there.
728  std::vector<int64_t> compositionOrder = self.compositionOrder;
729  [self.taskRunner runNowOrPostTask:^{
730  for (int64_t viewId : compositionOrder) {
731  [self.platformViews[viewId].root_view removeFromSuperview];
732  }
733  self.platformViews.clear();
734  _previousCompositionOrder.clear();
735  }];
736 
737  self.compositionOrder.clear();
738  self.slices.clear();
739  self.currentCompositionParams.clear();
740  self.viewsToRecomposite.clear();
741  self.layerPool->RecycleLayers();
742  self.visitedPlatformViews.clear();
743 }
744 
745 - (BOOL)submitFrame:(std::unique_ptr<flutter::SurfaceFrame>)background_frame
746  withIosContext:(const std::shared_ptr<flutter::IOSContext>&)iosContext {
747  TRACE_EVENT0("flutter", "PlatformViewsController::SubmitFrame");
748 
749  // No platform views to render.
750  if (self.flutterView == nil || (self.compositionOrder.empty() && !self.hadPlatformViews)) {
751  // No platform views to render but the FlutterView may need to be resized.
752  __weak FlutterPlatformViewsController* weakSelf = self;
753  if (self.flutterView != nil) {
754  // Pass frameSize by value since self.frameSize is mutated both here (on the platform
755  // thread) and in beginFrameWithSize: (on the raster thread).
756  const flutter::DlISize frameSize = self.frameSize;
757  [self.taskRunner runNowOrPostTask:^{
758  FlutterPlatformViewsController* strongSelf = weakSelf;
759  if (!strongSelf) {
760  return;
761  }
762  [strongSelf performResize:frameSize];
763  }];
764  }
765 
766  self.hadPlatformViews = NO;
767  return background_frame->Submit();
768  }
769  self.hadPlatformViews = !self.compositionOrder.empty();
770 
771  bool didEncode = true;
772  LayersMap platformViewLayers;
773  std::vector<std::unique_ptr<flutter::SurfaceFrame>> surfaceFrames;
774  surfaceFrames.reserve(self.compositionOrder.size());
775  std::unordered_map<int64_t, DlRect> viewRects;
776 
777  for (int64_t viewId : self.compositionOrder) {
778  viewRects[viewId] = self.currentCompositionParams[viewId].finalBoundingRect();
779  }
780 
781  std::unordered_map<int64_t, DlRect> overlayLayers =
782  SliceViews(background_frame->Canvas(), self.compositionOrder, self.slices, viewRects);
783 
784  size_t requiredOverlayLayers = 0;
785  for (int64_t viewId : self.compositionOrder) {
786  std::unordered_map<int64_t, DlRect>::const_iterator overlay = overlayLayers.find(viewId);
787  if (overlay == overlayLayers.end()) {
788  continue;
789  }
790  requiredOverlayLayers++;
791  }
792 
793  // If there are not sufficient overlay layers, we must construct them on the platform
794  // thread, at least until we've refactored iOS surface creation to use IOSurfaces
795  // instead of CALayers.
796  [self createMissingOverlays:requiredOverlayLayers withIosContext:iosContext];
797 
798  int64_t overlayId = 0;
799  for (int64_t viewId : self.compositionOrder) {
800  std::unordered_map<int64_t, DlRect>::const_iterator overlay = overlayLayers.find(viewId);
801  if (overlay == overlayLayers.end()) {
802  continue;
803  }
804  std::shared_ptr<flutter::OverlayLayer> layer = self.nextLayerInPool;
805  if (!layer) {
806  continue;
807  }
808 
809  std::unique_ptr<flutter::SurfaceFrame> frame = layer->surface->AcquireFrame(self.frameSize);
810  // If frame is null, AcquireFrame already printed out an error message.
811  if (!frame) {
812  continue;
813  }
814  flutter::DlCanvas* overlayCanvas = frame->Canvas();
815  int restoreCount = overlayCanvas->GetSaveCount();
816  overlayCanvas->Save();
817  overlayCanvas->ClipRect(overlay->second);
818  overlayCanvas->Clear(flutter::DlColor::kTransparent());
819  self.slices[viewId]->render_into(overlayCanvas);
820  overlayCanvas->RestoreToCount(restoreCount);
821 
822  // This flutter view is never the last in a frame, since we always submit the
823  // underlay view last.
824  frame->set_submit_info({.frame_boundary = false, .present_with_transaction = true});
825  layer->did_submit_last_frame = frame->Encode();
826 
827  didEncode &= layer->did_submit_last_frame;
828  platformViewLayers[viewId] = LayerData{
829  .rect = overlay->second, //
830  .view_id = viewId, //
831  .overlay_id = overlayId, //
832  .layer = layer //
833  };
834  surfaceFrames.push_back(std::move(frame));
835  overlayId++;
836  }
837 
838  auto previousSubmitInfo = background_frame->submit_info();
839  background_frame->set_submit_info({
840  .frame_damage = previousSubmitInfo.frame_damage,
841  .buffer_damage = previousSubmitInfo.buffer_damage,
842  .present_with_transaction = true,
843  });
844  background_frame->Encode();
845  surfaceFrames.push_back(std::move(background_frame));
846 
847  // Mark all layers as available, so they can be used in the next frame.
848  std::vector<std::shared_ptr<flutter::OverlayLayer>> unusedLayers =
849  self.layerPool->RemoveUnusedLayers();
850  self.layerPool->RecycleLayers();
851  auto task = fml::MakeCopyable([self, //
852  platformViewLayers = std::move(platformViewLayers), //
853  currentCompositionParams = self.currentCompositionParams, //
854  viewsToRecomposite = self.viewsToRecomposite, //
855  compositionOrder = self.compositionOrder, //
856  unusedLayers = std::move(unusedLayers), //
857  surfaceFrames = std::move(surfaceFrames)]() mutable {
858  [self performSubmit:platformViewLayers
859  currentCompositionParams:currentCompositionParams
860  viewsToRecomposite:viewsToRecomposite
861  compositionOrder:compositionOrder
862  unusedLayers:unusedLayers
863  surfaceFrames:surfaceFrames];
864  });
865 
866  [self.taskRunner runNowOrPostTask:^{
867  task();
868  }];
869  return didEncode;
870 }
871 
872 - (void)createMissingOverlays:(size_t)requiredOverlayLayers
873  withIosContext:(const std::shared_ptr<flutter::IOSContext>&)iosContext {
874  TRACE_EVENT0("flutter", "PlatformViewsController::CreateMissingLayers");
875 
876  if (requiredOverlayLayers <= self.layerPool->size()) {
877  return;
878  }
879  auto missingLayerCount = requiredOverlayLayers - self.layerPool->size();
880 
881  // If the raster thread isn't merged, create layers on the platform thread and block until
882  // complete. The self-capture here is fine since this is effectively synchronous (we block on the
883  // latch right below).
884  auto latch = std::make_shared<fml::CountDownLatch>(1u);
885  [self.taskRunner runNowOrPostTask:^{
886  for (auto i = 0u; i < missingLayerCount; i++) {
887  [self createLayerWithIosContext:iosContext
888  pixelFormat:((FlutterView*)self.flutterView).pixelFormat];
889  }
890  latch->CountDown();
891  }];
892  if (![[NSThread currentThread] isMainThread]) {
893  latch->Wait();
894  }
895 }
896 
897 - (void)performResize:(const flutter::DlISize&)frameSize {
898  TRACE_EVENT0("flutter", "PlatformViewsController::PerformResize");
899  FML_DCHECK([[NSThread currentThread] isMainThread]);
900 
901  if (self.flutterView != nil) {
902  [(FlutterView*)self.flutterView
903  setIntrinsicContentSize:CGSizeMake(frameSize.width, frameSize.height)];
904  }
905 }
906 
907 - (void)performSubmit:(const LayersMap&)platformViewLayers
908  currentCompositionParams:
909  (std::unordered_map<int64_t, flutter::EmbeddedViewParams>&)currentCompositionParams
910  viewsToRecomposite:(const std::unordered_set<int64_t>&)viewsToRecomposite
911  compositionOrder:(const std::vector<int64_t>&)compositionOrder
912  unusedLayers:
913  (const std::vector<std::shared_ptr<flutter::OverlayLayer>>&)unusedLayers
914  surfaceFrames:
915  (const std::vector<std::unique_ptr<flutter::SurfaceFrame>>&)surfaceFrames {
916  TRACE_EVENT0("flutter", "PlatformViewsController::PerformSubmit");
917  FML_DCHECK([[NSThread currentThread] isMainThread]);
918 
919  [CATransaction begin];
920 
921  // Configure Flutter overlay views.
922  for (const auto& [viewId, layerData] : platformViewLayers) {
923  layerData.layer->UpdateViewState(self.flutterView, //
924  layerData.rect, //
925  layerData.view_id, //
926  layerData.overlay_id //
927  );
928  }
929 
930  // Dispose unused Flutter Views.
931  for (auto& view : [self computeViewsToDispose]) {
932  [view removeFromSuperview];
933  }
934 
935  // Composite Platform Views.
936  for (int64_t viewId : viewsToRecomposite) {
937  [self compositeView:viewId withParams:currentCompositionParams[viewId]];
938  }
939 
940  // Present callbacks.
941  for (const auto& frame : surfaceFrames) {
942  frame->Submit();
943  }
944 
945  // If a layer was allocated in the previous frame, but it's not used in the current frame,
946  // then it can be removed from the scene.
947  [self removeUnusedLayers:unusedLayers withCompositionOrder:compositionOrder];
948 
949  // Organize the layers by their z indexes.
950  [self bringLayersIntoView:platformViewLayers withCompositionOrder:compositionOrder];
951 
952  [CATransaction commit];
953 }
954 
955 - (void)bringLayersIntoView:(const LayersMap&)layerMap
956  withCompositionOrder:(const std::vector<int64_t>&)compositionOrder {
957  UIView* flutterView = self.flutterView;
958  if (flutterView == nil) {
959  return;
960  }
961 
963  NSMutableArray* desiredPlatformSubviews = [NSMutableArray array];
964  for (int64_t platformViewId : compositionOrder) {
965  _previousCompositionOrder.push_back(platformViewId);
966  UIView* platformViewRoot = self.platformViews[platformViewId].root_view;
967  if (platformViewRoot != nil) {
968  [desiredPlatformSubviews addObject:platformViewRoot];
969  }
970 
971  auto maybeLayerData = layerMap.find(platformViewId);
972  if (maybeLayerData != layerMap.end()) {
973  auto view = maybeLayerData->second.layer->overlay_view_wrapper;
974  if (view != nil) {
975  [desiredPlatformSubviews addObject:view];
976  }
977  }
978  }
979 
980  NSSet* desiredPlatformSubviewsSet = [NSSet setWithArray:desiredPlatformSubviews];
981  NSArray* existingPlatformSubviews = [flutterView.subviews
982  filteredArrayUsingPredicate:[NSPredicate
983  predicateWithBlock:^BOOL(id object, NSDictionary* bindings) {
984  return [desiredPlatformSubviewsSet containsObject:object];
985  }]];
986 
987  // Manipulate view hierarchy only if needed, to address a performance issue where
988  // this method is called even when view hierarchy stays the same.
989  // See: https://github.com/flutter/flutter/issues/121833
990  // TODO(hellohuanlin): investigate if it is possible to skip unnecessary bringLayersIntoView.
991  if (![desiredPlatformSubviews isEqualToArray:existingPlatformSubviews]) {
992  for (UIView* subview in desiredPlatformSubviews) {
993  // `addSubview` will automatically reorder subview if it is already added.
994  [flutterView addSubview:subview];
995  }
996  }
997 }
998 
999 - (std::shared_ptr<flutter::OverlayLayer>)nextLayerInPool {
1000  return self.layerPool->GetNextLayer();
1001 }
1002 
1003 - (void)createLayerWithIosContext:(const std::shared_ptr<flutter::IOSContext>&)iosContext
1004  pixelFormat:(MTLPixelFormat)pixelFormat {
1005  self.layerPool->CreateLayer(iosContext, pixelFormat);
1006 }
1007 
1008 - (void)removeUnusedLayers:(const std::vector<std::shared_ptr<flutter::OverlayLayer>>&)unusedLayers
1009  withCompositionOrder:(const std::vector<int64_t>&)compositionOrder {
1010  for (const std::shared_ptr<flutter::OverlayLayer>& layer : unusedLayers) {
1011  [layer->overlay_view_wrapper removeFromSuperview];
1012  }
1013 
1014  std::unordered_set<int64_t> compositionOrderSet;
1015  for (int64_t viewId : compositionOrder) {
1016  compositionOrderSet.insert(viewId);
1017  }
1018  // Remove unused platform views.
1019  for (int64_t viewId : _previousCompositionOrder) {
1020  if (compositionOrderSet.find(viewId) == compositionOrderSet.end()) {
1021  UIView* platformViewRoot = self.platformViews[viewId].root_view;
1022  [platformViewRoot removeFromSuperview];
1023  }
1024  }
1025 }
1026 
1027 - (std::vector<UIView*>)computeViewsToDispose {
1028  std::vector<UIView*> views;
1029  if (self.viewsToDispose.empty()) {
1030  return views;
1031  }
1032 
1033  std::unordered_set<int64_t> viewsToComposite(self.compositionOrder.begin(),
1034  self.compositionOrder.end());
1035  std::unordered_set<int64_t> viewsToDelayDispose;
1036  for (int64_t viewId : self.viewsToDispose) {
1037  if (viewsToComposite.count(viewId)) {
1038  viewsToDelayDispose.insert(viewId);
1039  continue;
1040  }
1041  UIView* rootView = self.platformViews[viewId].root_view;
1042  views.push_back(rootView);
1043  self.currentCompositionParams.erase(viewId);
1044  self.viewsToRecomposite.erase(viewId);
1045  self.platformViews.erase(viewId);
1046  }
1047  self.viewsToDispose = std::move(viewsToDelayDispose);
1048  return views;
1049 }
1050 
1051 - (void)resetFrameState {
1052  self.slices.clear();
1053  self.compositionOrder.clear();
1054  self.visitedPlatformViews.clear();
1055 }
1056 
1057 - (void)pushVisitedPlatformViewId:(int64_t)viewId {
1058  self.visitedPlatformViews.push_back(viewId);
1059 }
1060 
1061 - (void)pushClipRectToVisitedPlatformViews:(const flutter::DlRect&)clipRect {
1062  for (int64_t id : self.visitedPlatformViews) {
1063  flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
1064  params.PushPlatformViewClipRect(clipRect);
1065  self.currentCompositionParams[id] = params;
1066  }
1067 }
1068 
1069 - (void)pushClipRRectToVisitedPlatformViews:(const flutter::DlRoundRect&)clipRRect {
1070  for (int64_t id : self.visitedPlatformViews) {
1071  flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
1072  params.PushPlatformViewClipRRect(clipRRect);
1073  self.currentCompositionParams[id] = params;
1074  }
1075 }
1076 
1077 - (void)pushClipRSuperellipseToVisitedPlatformViews:(const flutter::DlRoundSuperellipse&)clipRse {
1078  for (int64_t id : self.visitedPlatformViews) {
1079  flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
1080  params.PushPlatformViewClipRSuperellipse(clipRse);
1081  self.currentCompositionParams[id] = params;
1082  }
1083 }
1084 
1085 - (void)pushClipPathToVisitedPlatformViews:(const flutter::DlPath&)clipPath {
1086  for (int64_t id : self.visitedPlatformViews) {
1087  flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
1088  params.PushPlatformViewClipPath(clipPath);
1089  self.currentCompositionParams[id] = params;
1090  }
1091 }
1092 
1093 - (const flutter::EmbeddedViewParams&)compositionParamsForView:(int64_t)viewId {
1094  return self.currentCompositionParams.find(viewId)->second;
1095 }
1096 
1097 #pragma mark - Properties
1098 
1099 - (flutter::OverlayLayerPool*)layerPool {
1100  return _layerPool.get();
1101 }
1102 
1103 - (std::unordered_map<int64_t, std::unique_ptr<flutter::EmbedderViewSlice>>&)slices {
1104  return _slices;
1105 }
1106 
1107 - (std::unordered_map<int64_t, PlatformViewData>&)platformViews {
1108  return _platformViews;
1109 }
1110 
1111 - (std::unordered_map<int64_t, flutter::EmbeddedViewParams>&)currentCompositionParams {
1113 }
1114 
1115 - (std::unordered_set<int64_t>&)viewsToDispose {
1116  return _viewsToDispose;
1117 }
1118 
1119 - (std::vector<int64_t>&)compositionOrder {
1120  return _compositionOrder;
1121 }
1122 
1123 - (std::vector<int64_t>&)visitedPlatformViews {
1124  return _visitedPlatformViews;
1125 }
1126 
1127 - (std::unordered_set<int64_t>&)viewsToRecomposite {
1128  return _viewsToRecomposite;
1129 }
1130 
1131 - (NSArray<NSNumber*>*)previousCompositionOrder {
1132  // TODO(cbracken): Migrate to Obj-C types. https://github.com/flutter/flutter/issues/185139
1133  NSMutableArray* array = [NSMutableArray arrayWithCapacity:_previousCompositionOrder.size()];
1134  for (int64_t viewId : _previousCompositionOrder) {
1135  [array addObject:@(viewId)];
1136  }
1137  return array;
1138 }
1139 
1140 @end
void(^ FlutterResult)(id _Nullable result)
FLUTTER_DARWIN_EXPORT NSObject const * FlutterMethodNotImplemented
std::unordered_map< int64_t, LayerData > LayersMap
NSMutableDictionary< NSString *, NSNumber * > * _gestureRecognizersBlockingPoliciesByType
std::vector< int64_t > _compositionOrder
std::unordered_set< int64_t > _viewsToRecomposite
static NSString *const kGestureBlockingPolicyFallbackToPluginDefault
static NSString *const kGestureBlockingPolicyWaitUntilTouchesEndedValue
std::vector< int64_t > _previousCompositionOrder
FlutterFMLTaskRunner * _platformTaskRunner
static constexpr NSUInteger kFlutterClippingMaskViewPoolCapacity
std::unordered_map< int64_t, PlatformViewData > _platformViews
std::unordered_map< int64_t, std::unique_ptr< flutter::EmbedderViewSlice > > _slices
std::vector< int64_t > _visitedPlatformViews
std::unordered_map< int64_t, flutter::EmbeddedViewParams > _currentCompositionParams
static void ResetAnchor(CALayer *layer)
static NSString *const kGestureBlockingPolicyDoNotBlockGesture
static CATransform3D GetCATransform3DFromDlMatrix(const DlMatrix &matrix)
NSMutableDictionary< NSString *, NSObject< FlutterPlatformViewFactory > * > * _factories
static NSString *const kGestureBlockingPolicyEagerValue
static CGRect GetCGRectFromDlRect(const DlRect &clipDlRect)
std::unordered_set< int64_t > _viewsToDispose
FlutterPlatformViewGestureRecognizersBlockingPolicy
@ FlutterPlatformViewGestureRecognizersBlockingPolicyEager
@ FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded
@ FlutterPlatformViewGestureRecognizersBlockingPolicyDoNotBlockGesture
void applyBlurBackdropFilters:(NSArray< PlatformViewFilter * > *filters)
Storage for Overlay layers across frames.
std::shared_ptr< flutter::OverlayLayer > layer
FlutterTouchInterceptingView * touch_interceptor
NSObject< FlutterPlatformView > * view