Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Instance Methods | List of all members
flutter::FlutterPlatformViewsController Class Reference

#include <FlutterPlatformViews_Internal.h>

Instance Methods

() - FlutterPlatformViewsController
 
() - ~FlutterPlatformViewsController
 
(fml::WeakPtr< flutter::FlutterPlatformViewsController >) - GetWeakPtr
 
(void) - SetFlutterView
 
(void) - SetFlutterViewController
 
(UIViewController< FlutterViewResponder > *) - getFlutterViewController
 
(void) - RegisterViewFactory
 
(void) - BeginFrame
 
(void) - CancelFrame
 
(void) - PrerollCompositeEmbeddedView
 
(size_t) - EmbeddedViewCount
 
(UIView *) - GetPlatformViewByID
 
(FlutterTouchInterceptingView *) - GetFlutterTouchInterceptingViewByID
 
(PostPrerollResult- PostPrerollAction
 
(void) - EndFrame
 
(DlCanvas *) - CompositeEmbeddedView
 
(SkRect- GetPlatformViewRect
 
(void) - Reset
 
(bool) - SubmitFrame
 
(void) - OnMethodCall
 
(long) - FindFirstResponderPlatformViewId
 
(void) - PushFilterToVisitedPlatformViews
 
(void) - PushVisitedPlatformView
 

Detailed Description

Definition at line 205 of file FlutterPlatformViews_Internal.h.

Constructor & Destructor Documentation

◆ FlutterPlatformViewsController

- FlutterPlatformViewsController:

Definition at line 28 of file FlutterPlatformViews_Internal.mm.

29 : layer_pool_(std::make_unique<FlutterPlatformViewLayerPool>()),
30 weak_factory_(std::make_unique<fml::WeakPtrFactory<FlutterPlatformViewsController>>(this)) {
31 mask_view_pool_.reset(
33};
static constexpr NSUInteger kFlutterClippingMaskViewPoolCapacity
void reset(NST *object=Traits::InvalidValue(), scoped_policy::OwnershipPolicy policy=scoped_policy::OwnershipPolicy::kAssume)

◆ ~FlutterPlatformViewsController

- FlutterPlatformViewsController:

Method Documentation

◆ BeginFrame

- (void) FlutterPlatformViewsController: (SkISize frame_size

Definition at line 315 of file FlutterPlatformViews.mm.

315 {
316 ResetFrameState();
317 frame_size_ = frame_size;
318}

◆ CancelFrame

- (void) FlutterPlatformViewsController:

Definition at line 320 of file FlutterPlatformViews.mm.

320 {
321 ResetFrameState();
322}

◆ CompositeEmbeddedView

- (DlCanvas *) FlutterPlatformViewsController: (int64_t)  view_id

Definition at line 620 of file FlutterPlatformViews.mm.

620 {
621 // Any UIKit related code has to run on main thread.
622 FML_DCHECK([[NSThread currentThread] isMainThread]);
623 // Do nothing if the view doesn't need to be composited.
624 if (views_to_recomposite_.count(view_id) == 0) {
625 return slices_[view_id]->canvas();
626 }
627 CompositeWithParams(view_id, current_composition_params_[view_id]);
628 views_to_recomposite_.erase(view_id);
629 return slices_[view_id]->canvas();
630}
#define FML_DCHECK(condition)
Definition logging.h:103

◆ EmbeddedViewCount

- (size_t) FlutterPlatformViewsController:

Definition at line 402 of file FlutterPlatformViews.mm.

402 {
403 return composition_order_.size();
404}

◆ EndFrame

- (void) FlutterPlatformViewsController: (bool)  should_resubmit_frame
(const fml::RefPtr< fml::RasterThreadMerger > &)  raster_thread_merger 

Definition at line 361 of file FlutterPlatformViews.mm.

363 {
364 if (should_resubmit_frame) {
365 raster_thread_merger->MergeWithLease(kDefaultMergedLeaseDuration);
366 }
367}
void MergeWithLease(size_t lease_term)

◆ FindFirstResponderPlatformViewId

- (long) FlutterPlatformViewsController:

Definition at line 418 of file FlutterPlatformViews.mm.

418 {
419 for (auto const& [id, root_view] : root_views_) {
420 if ((UIView*)(root_view.get()).flt_hasFirstResponderInViewHierarchySubtree) {
421 return id;
422 }
423 }
424 return -1;
425}
const uintptr_t id

◆ GetFlutterTouchInterceptingViewByID

- (FlutterTouchInterceptingView *) FlutterPlatformViewsController: (int64_t)  view_id

Definition at line 410 of file FlutterPlatformViews.mm.

411 {
412 if (views_.empty()) {
413 return nil;
414 }
415 return touch_interceptors_[view_id].get();
416}

◆ getFlutterViewController

- (UIViewController< FlutterViewResponder > *) FlutterPlatformViewsController:

Definition at line 170 of file FlutterPlatformViews.mm.

170 {
171 return flutter_view_controller_.get();
172}
T get() const __attribute((ns_returns_not_retained))

◆ GetPlatformViewByID

- (UIView *) FlutterPlatformViewsController: (int64_t)  view_id

Definition at line 406 of file FlutterPlatformViews.mm.

406 {
407 return [GetFlutterTouchInterceptingViewByID(view_id) embeddedView];
408}

◆ GetPlatformViewRect

- (SkRect) FlutterPlatformViewsController: (int64_t)  view_id

Definition at line 650 of file FlutterPlatformViews.mm.

650 {
651 UIView* platform_view = GetPlatformViewByID(view_id);
652 UIScreen* screen = [UIScreen mainScreen];
653 CGRect platform_view_cgrect = [platform_view convertRect:platform_view.bounds
654 toView:flutter_view_];
655 return SkRect::MakeXYWH(platform_view_cgrect.origin.x * screen.scale, //
656 platform_view_cgrect.origin.y * screen.scale, //
657 platform_view_cgrect.size.width * screen.scale, //
658 platform_view_cgrect.size.height * screen.scale //
659 );
660}
std::unique_ptr< flutter::PlatformViewIOS > platform_view
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

◆ GetWeakPtr

- (WeakPtr<) flutter:

Definition at line 37 of file FlutterPlatformViews_Internal.mm.

37 {
38 return weak_factory_->GetWeakPtr();
39}

◆ OnMethodCall

- (void) FlutterPlatformViewsController: (FlutterMethodCall *)  call
(FlutterResult result 

Definition at line 174 of file FlutterPlatformViews.mm.

174 {
175 if ([[call method] isEqualToString:@"create"]) {
176 OnCreate(call, result);
177 } else if ([[call method] isEqualToString:@"dispose"]) {
178 OnDispose(call, result);
179 } else if ([[call method] isEqualToString:@"acceptGesture"]) {
180 OnAcceptGesture(call, result);
181 } else if ([[call method] isEqualToString:@"rejectGesture"]) {
182 OnRejectGesture(call, result);
183 } else {
185 }
186}
FLUTTER_DARWIN_EXPORT NSObject const * FlutterMethodNotImplemented
GAsyncResult * result

◆ PostPrerollAction

- (PostPrerollResult) FlutterPlatformViewsController: (const fml::RefPtr< fml::RasterThreadMerger > &)  raster_thread_merger

Definition at line 333 of file FlutterPlatformViews.mm.

334 {
335 // TODO(cyanglaz): https://github.com/flutter/flutter/issues/56474
336 // Rename `has_platform_view` to `view_mutated` when the above issue is resolved.
337 if (!HasPlatformViewThisOrNextFrame()) {
339 }
340 if (!raster_thread_merger->IsMerged()) {
341 // The raster thread merger may be disabled if the rasterizer is being
342 // created or teared down.
343 //
344 // In such cases, the current frame is dropped, and a new frame is attempted
345 // with the same layer tree.
346 //
347 // Eventually, the frame is submitted once this method returns `kSuccess`.
348 // At that point, the raster tasks are handled on the platform thread.
349 CancelFrame();
351 }
352 // If the post preroll action is successful, we will display platform views in the current frame.
353 // In order to sync the rendering of the platform views (quartz) with skia's rendering,
354 // We need to begin an explicit CATransaction. This transaction needs to be submitted
355 // after the current frame is submitted.
356 BeginCATransaction();
357 raster_thread_merger->ExtendLeaseTo(kDefaultMergedLeaseDuration);
359}
void ExtendLeaseTo(size_t lease_term)

◆ PrerollCompositeEmbeddedView

- (void) FlutterPlatformViewsController: (int64_t)  view_id
(std::unique_ptr< flutter::EmbeddedViewParams >)  params 

Definition at line 379 of file FlutterPlatformViews.mm.

381 {
382 // All the CATransactions should be committed by the end of the last frame,
383 // so catransaction_added_ must be false.
384 FML_DCHECK(!catransaction_added_);
385
386 SkRect view_bounds = SkRect::Make(frame_size_);
387 std::unique_ptr<EmbedderViewSlice> view;
388 view = std::make_unique<DisplayListEmbedderViewSlice>(view_bounds);
389 slices_.insert_or_assign(view_id, std::move(view));
390
391 composition_order_.push_back(view_id);
392
393 if (current_composition_params_.count(view_id) == 1 &&
394 current_composition_params_[view_id] == *params.get()) {
395 // Do nothing if the params didn't change.
396 return;
397 }
398 current_composition_params_[view_id] = EmbeddedViewParams(*params.get());
399 views_to_recomposite_.insert(view_id);
400}
const EmbeddedViewParams * params
static SkRect Make(const SkISize &size)
Definition SkRect.h:669

◆ PushFilterToVisitedPlatformViews

- (void) FlutterPlatformViewsController: (const std::shared_ptr< const DlImageFilter > &)  filter
(const SkRect &)  filter_rect 

Definition at line 369 of file FlutterPlatformViews.mm.

371 {
372 for (int64_t id : visited_platform_views_) {
373 EmbeddedViewParams params = current_composition_params_[id];
374 params.PushImageFilter(filter, filter_rect);
375 current_composition_params_[id] = params;
376 }
377}

◆ PushVisitedPlatformView

- (void) FlutterPlatformViewsController: (int64_t)  view_id

Definition at line 280 of file FlutterPlatformViews_Internal.h.

280{ visited_platform_views_.push_back(view_id); }

◆ RegisterViewFactory

- (void) FlutterPlatformViewsController: (NSObject< FlutterPlatformViewFactory > *)  factory
(NSString *)  factoryId
(FlutterPlatformViewGestureRecognizersBlockingPolicy gestureRecognizerBlockingPolicy 

Definition at line 304 of file FlutterPlatformViews.mm.

307 {
308 std::string idString([factoryId UTF8String]);
309 FML_CHECK(factories_.count(idString) == 0);
310 factories_[idString] =
312 gesture_recognizers_blocking_policies_[idString] = gestureRecognizerBlockingPolicy;
313}
#define FML_CHECK(condition)
Definition logging.h:85

◆ Reset

- (void) FlutterPlatformViewsController:

Definition at line 632 of file FlutterPlatformViews.mm.

632 {
633 for (int64_t view_id : active_composition_order_) {
634 UIView* sub_view = root_views_[view_id].get();
635 [sub_view removeFromSuperview];
636 }
637 root_views_.clear();
638 touch_interceptors_.clear();
639 views_.clear();
640 composition_order_.clear();
641 active_composition_order_.clear();
642 slices_.clear();
643 current_composition_params_.clear();
644 clip_count_.clear();
645 views_to_recomposite_.clear();
646 layer_pool_->RecycleLayers();
647 visited_platform_views_.clear();
648}

◆ SetFlutterView

- (void) FlutterPlatformViewsController: (UIView *)  flutter_view

Definition at line 161 of file FlutterPlatformViews.mm.

161 {
162 flutter_view_.reset([flutter_view retain]);
163}

◆ SetFlutterViewController

- (void) FlutterPlatformViewsController: (UIViewController< FlutterViewResponder > *)  flutter_view_controller

Definition at line 165 of file FlutterPlatformViews.mm.

166 {
167 flutter_view_controller_.reset([flutter_view_controller retain]);
168}

◆ SubmitFrame

- (bool) FlutterPlatformViewsController: (GrDirectContext *)  gr_context
(const std::shared_ptr< IOSContext > &)  ios_context
(std::unique_ptr< SurfaceFrame >)  frame 

Definition at line 662 of file FlutterPlatformViews.mm.

664 {
665 TRACE_EVENT0("flutter", "FlutterPlatformViewsController::SubmitFrame");
666
667 // Any UIKit related code has to run on main thread.
668 FML_DCHECK([[NSThread currentThread] isMainThread]);
669 if (flutter_view_ == nullptr) {
670 return frame->Submit();
671 }
672
673 DisposeViews();
674
675 DlCanvas* background_canvas = frame->Canvas();
676
677 // Resolve all pending GPU operations before allocating a new surface.
678 background_canvas->Flush();
679
680 // Clipping the background canvas before drawing the picture recorders requires
681 // saving and restoring the clip context.
682 DlAutoCanvasRestore save(background_canvas, /*do_save=*/true);
683
684 // Maps a platform view id to a vector of `FlutterPlatformViewLayer`.
685 LayersMap platform_view_layers;
686
687 auto did_submit = true;
688 auto num_platform_views = composition_order_.size();
689
690 // TODO(hellohuanlin) this double for-loop is expensive with wasted computations.
691 // See: https://github.com/flutter/flutter/issues/145802
692 for (size_t i = 0; i < num_platform_views; i++) {
693 int64_t platform_view_id = composition_order_[i];
694 EmbedderViewSlice* slice = slices_[platform_view_id].get();
695 slice->end_recording();
696
697 // Check if the current picture contains overlays that intersect with the
698 // current platform view or any of the previous platform views.
699 for (size_t j = i + 1; j > 0; j--) {
700 int64_t current_platform_view_id = composition_order_[j - 1];
701 SkRect platform_view_rect = GetPlatformViewRect(current_platform_view_id);
702 std::vector<SkIRect> intersection_rects = slice->region(platform_view_rect).getRects();
703 const SkIRect rounded_in_platform_view_rect = platform_view_rect.roundIn();
704 // Ignore intersections of single width/height on the edge of the platform view.
705 // This is to address the following performance issue when interleaving adjacent
706 // platform views and layers:
707 // Since we `roundOut` both platform view rects and the layer rects, as long as
708 // the coordinate is fractional, there will be an intersection of a single pixel width
709 // (or height) after rounding out, even if they do not intersect before rounding out.
710 // We have to round out both platform view rect and the layer rect.
711 // Rounding in platform view rect will result in missing pixel on the intersection edge.
712 // Rounding in layer rect will result in missing pixel on the edge of the layer on top
713 // of the platform view.
714 for (auto it = intersection_rects.begin(); it != intersection_rects.end(); /*no-op*/) {
715 // If intersection_rect does not intersect with the *rounded in* platform
716 // view rect, then the intersection must be a single pixel width (or height) on edge.
717 if (!SkIRect::Intersects(*it, rounded_in_platform_view_rect)) {
718 it = intersection_rects.erase(it);
719 } else {
720 ++it;
721 }
722 }
723
724 auto allocation_size = intersection_rects.size();
725
726 // For testing purposes, the overlay id is used to find the overlay view.
727 // This is the index of the layer for the current platform view.
728 auto overlay_id = platform_view_layers[current_platform_view_id].size();
729
730 // If the max number of allocations per platform view is exceeded,
731 // then join all the rects into a single one.
732 //
733 // TODO(egarciad): Consider making this configurable.
734 // https://github.com/flutter/flutter/issues/52510
735 if (allocation_size > kMaxLayerAllocations) {
736 SkIRect joined_rect = SkIRect::MakeEmpty();
737 for (const SkIRect& rect : intersection_rects) {
738 joined_rect.join(rect);
739 }
740 // Replace the rects in the intersection rects list for a single rect that is
741 // the union of all the rects in the list.
742 intersection_rects.clear();
743 intersection_rects.push_back(joined_rect);
744 }
745 for (SkIRect& joined_rect : intersection_rects) {
746 // Get the intersection rect between the current rect
747 // and the platform view rect.
748 joined_rect.intersect(platform_view_rect.roundOut());
749 // Clip the background canvas, so it doesn't contain any of the pixels drawn
750 // on the overlay layer.
751 background_canvas->ClipRect(SkRect::Make(joined_rect), DlCanvas::ClipOp::kDifference);
752 // Get a new host layer.
753 std::shared_ptr<FlutterPlatformViewLayer> layer =
754 GetLayer(gr_context, //
755 ios_context, //
756 slice, //
757 joined_rect, //
758 current_platform_view_id, //
759 overlay_id, //
760 ((FlutterView*)flutter_view_.get()).pixelFormat //
761 );
762 did_submit &= layer->did_submit_last_frame;
763 platform_view_layers[current_platform_view_id].push_back(layer);
764 overlay_id++;
765 }
766 }
767 slice->render_into(background_canvas);
768 }
769
770 // Manually trigger the SkAutoCanvasRestore before we submit the frame
771 save.Restore();
772
773 // If a layer was allocated in the previous frame, but it's not used in the current frame,
774 // then it can be removed from the scene.
775 RemoveUnusedLayers();
776 // Organize the layers by their z indexes.
777 BringLayersIntoView(platform_view_layers);
778 // Mark all layers as available, so they can be used in the next frame.
779 layer_pool_->RecycleLayers();
780
781 did_submit &= frame->Submit();
782
783 // If the frame is submitted with embedded platform views,
784 // there should be a |[CATransaction begin]| call in this frame prior to all the drawing.
785 // If that case, we need to commit the transaction.
786 CommitCATransactionIfNeeded();
787 return did_submit;
788}
double frame
Definition examples.cpp:31
bool intersect(const SkIRect &r)
Definition SkRect.h:513
static bool Intersects(const SkIRect &a, const SkIRect &b)
Definition SkRect.h:535
void join(const SkIRect &r)
Definition SkRect.cpp:31
static constexpr SkIRect MakeEmpty()
Definition SkRect.h:45
void roundIn(SkIRect *dst) const
Definition SkRect.h:1266
void roundOut(SkIRect *dst) const
Definition SkRect.h:1241
#define TRACE_EVENT0(category_group, name)

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