Flutter Engine
 
Loading...
Searching...
No Matches
external_view_embedder.h
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
5#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_EXTERNAL_VIEW_EMBEDDER_EXTERNAL_VIEW_EMBEDDER_H_
6#define FLUTTER_SHELL_PLATFORM_ANDROID_EXTERNAL_VIEW_EMBEDDER_EXTERNAL_VIEW_EMBEDDER_H_
7
8#include <unordered_map>
9
16
17namespace flutter {
18
19//------------------------------------------------------------------------------
20/// Allows to embed Android views into a Flutter application.
21///
22/// This class calls Java methods via |PlatformViewAndroidJNI| to manage the
23/// lifecycle of the Android view corresponding to |flutter::PlatformViewLayer|.
24///
25/// It also orchestrates overlay surfaces. These are Android views
26/// that render above (by Z order) the Android view corresponding to
27/// |flutter::PlatformViewLayer|.
28///
30 public:
32 const AndroidContext& android_context,
33 std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
34 std::shared_ptr<AndroidSurfaceFactory> surface_factory,
35 const TaskRunners& task_runners);
36
37 // |ExternalViewEmbedder|
39 int64_t view_id,
40 std::unique_ptr<flutter::EmbeddedViewParams> params) override;
41
42 // |ExternalViewEmbedder|
43 DlCanvas* CompositeEmbeddedView(int64_t view_id) override;
44
45 // |ExternalViewEmbedder|
47 int64_t flutter_view_id,
48 GrDirectContext* context,
49 const std::shared_ptr<impeller::AiksContext>& aiks_context,
50 std::unique_ptr<SurfaceFrame> frame) override;
51
52 // |ExternalViewEmbedder|
54 const fml::RefPtr<fml::RasterThreadMerger>& raster_thread_merger)
55 override;
56
57 // |ExternalViewEmbedder|
58 DlCanvas* GetRootCanvas() override;
59
60 // |ExternalViewEmbedder|
61 void BeginFrame(GrDirectContext* context,
63 raster_thread_merger) override;
64
65 // |ExternalViewEmbedder|
66 void PrepareFlutterView(DlISize frame_size,
67 double device_pixel_ratio) override;
68
69 // |ExternalViewEmbedder|
70 void CancelFrame() override;
71
72 // |ExternalViewEmbedder|
73 void EndFrame(bool should_resubmit_frame,
75 raster_thread_merger) override;
76
77 // |ExternalViewEmbedder|
78 bool SupportsDynamicThreadMerging() override;
79
80 // |ExternalViewEmbedder|
81 void Teardown() override;
82
83 // Gets the rect based on the device pixel ratio of a platform view displayed
84 // on the screen.
85 DlRect GetViewRect(int64_t view_id) const;
86
87 private:
88 // The number of frames the rasterizer task runner will continue
89 // to run on the platform thread after no platform view is rendered.
90 //
91 // Note: this is an arbitrary number that attempts to account for cases
92 // where the platform view might be momentarily off the screen.
93 static const int kDefaultMergedLeaseDuration = 10;
94
95 // Provides metadata to the Android surfaces.
96 const AndroidContext& android_context_;
97
98 // Allows to call methods in Java.
99 const std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
100
101 // Allows to create surfaces.
102 const std::shared_ptr<AndroidSurfaceFactory> surface_factory_;
103
104 // Holds surfaces. Allows to recycle surfaces or allocate new ones.
105 const std::unique_ptr<SurfacePool> surface_pool_;
106
107 // The task runners.
108 const TaskRunners task_runners_;
109
110 // The size of the root canvas.
111 DlISize frame_size_;
112
113 // The pixel ratio used to determinate the size of a platform view layer
114 // relative to the device layout system.
115 double device_pixel_ratio_;
116
117 // The order of composition. Each entry contains a unique id for the platform
118 // view.
119 std::vector<int64_t> composition_order_;
120
121 // The |EmbedderViewSlice| implementation keyed off the platform view id,
122 // which contains any subsequent operations until the next platform view or
123 // the end of the last leaf node in the layer tree.
124 std::unordered_map<int64_t, std::unique_ptr<EmbedderViewSlice>> slices_;
125
126 // The params for a platform view, which contains the size, position and
127 // mutation stack.
128 std::unordered_map<int64_t, EmbeddedViewParams> view_params_;
129
130 // The number of platform views in the previous frame.
131 int64_t previous_frame_view_count_;
132
133 // Destroys the surfaces created from the surface factory.
134 // This method schedules a task on the platform thread, and waits for
135 // the task until it completes.
136 void DestroySurfaces();
137
138 // Resets the state.
139 void Reset();
140
141 // Whether the layer tree in the current frame has platform layers.
142 bool FrameHasPlatformLayers();
143
144 // Creates a Surface when needed or recycles an existing one.
145 // Finally, draws the picture on the frame's canvas.
146 std::unique_ptr<SurfaceFrame> CreateSurfaceIfNeeded(GrDirectContext* context,
147 int64_t view_id,
148 EmbedderViewSlice* slice,
149 const DlRect& rect);
150};
151
152} // namespace flutter
153
154#endif // FLUTTER_SHELL_PLATFORM_ANDROID_EXTERNAL_VIEW_EMBEDDER_EXTERNAL_VIEW_EMBEDDER_H_
Holds state that is shared across Android surfaces.
void EndFrame(bool should_resubmit_frame, const fml::RefPtr< fml::RasterThreadMerger > &raster_thread_merger) override
PostPrerollResult PostPrerollAction(const fml::RefPtr< fml::RasterThreadMerger > &raster_thread_merger) override
void PrerollCompositeEmbeddedView(int64_t view_id, std::unique_ptr< flutter::EmbeddedViewParams > params) override
void SubmitFlutterView(int64_t flutter_view_id, GrDirectContext *context, const std::shared_ptr< impeller::AiksContext > &aiks_context, std::unique_ptr< SurfaceFrame > frame) override
DlCanvas * CompositeEmbeddedView(int64_t view_id) override
void BeginFrame(GrDirectContext *context, const fml::RefPtr< fml::RasterThreadMerger > &raster_thread_merger) override
void PrepareFlutterView(DlISize frame_size, double device_pixel_ratio) override
DlRect GetViewRect(int64_t view_id) const
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
const EmbeddedViewParams * params
G_BEGIN_DECLS FlutterViewId view_id