Flutter Engine
 
Loading...
Searching...
No Matches
android_shell_holder.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_ANDROID_SHELL_HOLDER_H_
6#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SHELL_HOLDER_H_
7
8#include <memory>
9
10#include "flutter/fml/macros.h"
18
19namespace flutter {
20
21//----------------------------------------------------------------------------
22/// @brief This is the Android owner of the core engine Shell.
23///
24/// @details This is the top orchestrator class on the C++ side for the
25/// Android embedding. It corresponds to a FlutterEngine on the
26/// Java side. This class is in C++ because the Shell is in
27/// C++ and an Android orchestrator needs to exist to
28/// compose it with other Android specific C++ components such as
29/// the PlatformViewAndroid. This composition of many-to-one
30/// C++ components would be difficult to do through JNI whereas
31/// a FlutterEngine and AndroidShellHolder has a 1:1 relationship.
32///
33/// Technically, the FlutterJNI class owns this AndroidShellHolder
34/// class instance, but the FlutterJNI class is meant to be mostly
35/// static and has minimal state to perform the C++ pointer <->
36/// Java class instance translation.
37///
39 public:
41 std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
42 AndroidRenderingAPI android_rendering_api);
43
45
46 bool IsValid() const;
47
48 //----------------------------------------------------------------------------
49 /// @brief This is a factory for a derived AndroidShellHolder from an
50 /// existing AndroidShellHolder.
51 ///
52 /// @details Creates one Shell from another Shell where the created
53 /// Shell takes the opportunity to share any internal components
54 /// it can. This results is a Shell that has a smaller startup
55 /// time cost and a smaller memory footprint than an Shell created
56 /// with a Create function.
57 ///
58 /// The new Shell is returned in a new AndroidShellHolder
59 /// instance.
60 ///
61 /// The new Shell's flutter::Settings cannot be changed from that
62 /// of the initial Shell. The RunConfiguration subcomponent can
63 /// be changed however in the spawned Shell to run a different
64 /// entrypoint than the existing shell.
65 ///
66 /// Since the AndroidShellHolder both binds downwards to a Shell
67 /// and also upwards to JNI callbacks that the PlatformViewAndroid
68 /// makes, the JNI instance holding this AndroidShellHolder should
69 /// be created first to supply the jni_facade callback.
70 ///
71 /// @param[in] jni_facade this argument should be the JNI callback facade of
72 /// a new JNI instance meant to hold this AndroidShellHolder.
73 ///
74 /// @returns A new AndroidShellHolder containing a new Shell. Returns
75 /// nullptr when a new Shell can't be created.
76 ///
77 std::unique_ptr<AndroidShellHolder> Spawn(
78 std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
79 const std::string& entrypoint,
80 const std::string& libraryUrl,
81 const std::string& initial_route,
82 const std::vector<std::string>& entrypoint_args,
83 int64_t engine_id) const;
84
85 void Launch(std::unique_ptr<APKAssetProvider> apk_asset_provider,
86 const std::string& entrypoint,
87 const std::string& libraryUrl,
88 const std::vector<std::string>& entrypoint_args,
89 int64_t engine_id);
90
91 const flutter::Settings& GetSettings() const;
92
94
96
98 bool base64_encode);
99
101
102 const std::shared_ptr<PlatformMessageHandler>& GetPlatformMessageHandler()
103 const {
104 return shell_->GetPlatformMessageHandler();
105 }
106
108
109 // Visible for testing.
110 const std::unique_ptr<Shell>& GetShellForTesting() const { return shell_; }
111
112 private:
113 const flutter::Settings settings_;
114 const std::shared_ptr<PlatformViewAndroidJNI> jni_facade_;
116 std::shared_ptr<ThreadHost> thread_host_;
117 std::unique_ptr<Shell> shell_;
118 bool is_valid_ = false;
119 uint64_t next_pointer_flow_id_ = 0;
120 std::unique_ptr<APKAssetProvider> apk_asset_provider_;
121 const AndroidRenderingAPI android_rendering_api_;
122
123 //----------------------------------------------------------------------------
124 /// @brief Constructor with its components injected.
125 ///
126 /// @details This is similar to the standard constructor, except its
127 /// members were constructed elsewhere and injected.
128 ///
129 /// All injected components must be non-null and valid.
130 ///
131 /// Used when constructing the Shell from the inside out when
132 /// spawning from an existing Shell.
133 ///
135 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
136 const std::shared_ptr<ThreadHost>& thread_host,
137 std::unique_ptr<Shell> shell,
138 std::unique_ptr<APKAssetProvider> apk_asset_provider,
140 AndroidRenderingAPI rendering_api);
141 static void ThreadDestructCallback(void* value);
142 std::optional<RunConfiguration> BuildRunConfiguration(
143 const std::string& entrypoint,
144 const std::string& libraryUrl,
145 const std::vector<std::string>& entrypoint_args) const;
146
147 bool IsNDKImageDecoderAvailable();
148
150};
151
152} // namespace flutter
153
154#endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SHELL_HOLDER_H_
std::unique_ptr< flutter::PlatformViewIOS > platform_view
GLenum type
This is the Android owner of the core engine Shell.
const flutter::Settings & GetSettings() const
const std::unique_ptr< Shell > & GetShellForTesting() const
const std::shared_ptr< PlatformMessageHandler > & GetPlatformMessageHandler() const
std::unique_ptr< AndroidShellHolder > Spawn(std::shared_ptr< PlatformViewAndroidJNI > jni_facade, const std::string &entrypoint, const std::string &libraryUrl, const std::string &initial_route, const std::vector< std::string > &entrypoint_args, int64_t engine_id) const
This is a factory for a derived AndroidShellHolder from an existing AndroidShellHolder.
fml::WeakPtr< PlatformViewAndroid > GetPlatformView()
Rasterizer::Screenshot Screenshot(Rasterizer::ScreenshotType type, bool base64_encode)
void Launch(std::unique_ptr< APKAssetProvider > apk_asset_provider, const std::string &entrypoint, const std::string &libraryUrl, const std::vector< std::string > &entrypoint_args, int64_t engine_id)
ScreenshotType
The type of the screenshot to obtain of the previously rendered layer tree.
Definition rasterizer.h:348
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
A POD type used to return the screenshot data along with the size of the frame.
Definition rasterizer.h:399