Flutter iOS Embedder
ios_external_view_embedder.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 "fml/task_runner.h"
7 
8 #include "flutter/common/constants.h"
9 
11 
12 namespace flutter {
13 
15  __weak FlutterPlatformViewsController* platform_views_controller,
16  const std::shared_ptr<IOSContext>& context)
17  : platform_views_controller_(platform_views_controller), ios_context_(context) {
18  FML_CHECK(ios_context_);
19 }
20 
22 
23 // |ExternalViewEmbedder|
24 DlCanvas* IOSExternalViewEmbedder::GetRootCanvas() {
25  // On iOS, the root surface is created from the on-screen render target. Only the surfaces for the
26  // various overlays are controlled by this class.
27  return nullptr;
28 }
29 
30 // |ExternalViewEmbedder|
31 void IOSExternalViewEmbedder::CancelFrame() {
32  TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::CancelFrame");
33  FML_CHECK(platform_views_controller_);
34  [platform_views_controller_ cancelFrame];
35 }
36 
37 // |ExternalViewEmbedder|
38 void IOSExternalViewEmbedder::BeginFrame(
39  GrDirectContext* context,
40  const fml::RefPtr<fml::RasterThreadMerger>& raster_thread_merger) {}
41 
42 // |ExternalViewEmbedder|
43 void IOSExternalViewEmbedder::PrepareFlutterView(DlISize frame_size, double device_pixel_ratio) {
44  FML_CHECK(platform_views_controller_);
45  [platform_views_controller_ beginFrameWithSize:frame_size];
46 }
47 
48 // |ExternalViewEmbedder|
49 void IOSExternalViewEmbedder::PrerollCompositeEmbeddedView(
50  int64_t view_id,
51  std::unique_ptr<EmbeddedViewParams> params) {
52  TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::PrerollCompositeEmbeddedView");
53  FML_CHECK(platform_views_controller_);
54  [platform_views_controller_ prerollCompositeEmbeddedView:view_id withParams:std::move(params)];
55 }
56 
57 // |ExternalViewEmbedder|
58 DlCanvas* IOSExternalViewEmbedder::CompositeEmbeddedView(int64_t view_id) {
59  TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::CompositeEmbeddedView");
60  FML_CHECK(platform_views_controller_);
61  return [platform_views_controller_ compositeEmbeddedViewWithId:view_id];
62 }
63 
64 // |ExternalViewEmbedder|
65 void IOSExternalViewEmbedder::SubmitFlutterView(
66  int64_t flutter_view_id,
67  GrDirectContext* context,
68  const std::shared_ptr<impeller::AiksContext>& aiks_context,
69  std::unique_ptr<SurfaceFrame> frame) {
70  TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::SubmitFlutterView");
71 
72  // TODO(dkwingsmt): This class only supports rendering into the implicit view.
73  // Properly support multi-view in the future.
74  FML_DCHECK(flutter_view_id == kFlutterImplicitViewId);
75  FML_CHECK(platform_views_controller_);
76  [platform_views_controller_ submitFrame:std::move(frame) withIosContext:ios_context_];
77  TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::DidSubmitFrame");
78 }
79 
80 // |ExternalViewEmbedder|
81 bool IOSExternalViewEmbedder::SupportsDynamicThreadMerging() {
82  return false;
83 }
84 
85 // |ExternalViewEmbedder|
86 void IOSExternalViewEmbedder::PushFilterToVisitedPlatformViews(
87  const std::shared_ptr<DlImageFilter>& filter,
88  const DlRect& filter_rect) {
89  [platform_views_controller_ pushFilterToVisitedPlatformViews:filter withRect:filter_rect];
90 }
91 
92 // |ExternalViewEmbedder|
93 void IOSExternalViewEmbedder::PushVisitedPlatformView(int64_t view_id) {
94  [platform_views_controller_ pushVisitedPlatformViewId:view_id];
95 }
96 
97 // |ExternalViewEmbedder|
98 void IOSExternalViewEmbedder::PushClipRectToVisitedPlatformViews(const DlRect& clip_rect) {
99  [platform_views_controller_ pushClipRectToVisitedPlatformViews:clip_rect];
100 }
101 
102 // |ExternalViewEmbedder|
103 void IOSExternalViewEmbedder::PushClipRRectToVisitedPlatformViews(const DlRoundRect& clip_rrect) {
104  [platform_views_controller_ pushClipRRectToVisitedPlatformViews:clip_rrect];
105 }
106 
107 // |ExternalViewEmbedder|
108 void IOSExternalViewEmbedder::PushClipRSuperellipseToVisitedPlatformViews(
109  const DlRoundSuperellipse& clip_rse) {
110  [platform_views_controller_ pushClipRSuperellipseToVisitedPlatformViews:clip_rse];
111 }
112 
113 // |ExternalViewEmbedder|
114 void IOSExternalViewEmbedder::PushClipPathToVisitedPlatformViews(const DlPath& clip_path) {
115  [platform_views_controller_ pushClipPathToVisitedPlatformViews:clip_path];
116 }
117 
118 } // namespace flutter
IOSExternalViewEmbedder(__weak FlutterPlatformViewsController *platform_views_controller, const std::shared_ptr< IOSContext > &context)
virtual ~IOSExternalViewEmbedder() override