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