Flutter Engine
 
Loading...
Searching...
No Matches
platform_view_android_jni.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_JNI_PLATFORM_VIEW_ANDROID_JNI_H_
6#define FLUTTER_SHELL_PLATFORM_ANDROID_JNI_PLATFORM_VIEW_ANDROID_JNI_H_
7
8#include <utility>
9
10#include "flutter/fml/mapping.h"
11
15
16#if FML_OS_ANDROID
18#endif
19
20struct ASurfaceTransaction;
21
22namespace flutter {
23
24#if FML_OS_ANDROID
26#else
27using JavaLocalRef = std::nullptr_t;
28#endif
29
30//------------------------------------------------------------------------------
31/// Allows to call Java code running in the JVM from any thread. However, most
32/// methods can only be called from the platform thread as that is where the
33/// Java code runs.
34///
35/// This interface must not depend on the Android toolchain directly, so it can
36/// be used in unit tests compiled with the host toolchain.
37///
39 public:
41
42 //----------------------------------------------------------------------------
43 /// @brief Sends a platform message. The message may be empty.
44 ///
46 std::unique_ptr<flutter::PlatformMessage> message,
47 int responseId) = 0;
48
49 //----------------------------------------------------------------------------
50 /// @brief Responds to a platform message. The data may be a `nullptr`.
51 ///
53 int responseId,
54 std::unique_ptr<fml::Mapping> data) = 0;
55
56 //----------------------------------------------------------------------------
57 /// @brief Sends semantics tree updates.
58 ///
59 /// @note Must be called from the platform thread.
60 ///
62 std::vector<uint8_t> buffer,
63 std::vector<std::string> strings,
64 std::vector<std::vector<uint8_t>> string_attribute_args) = 0;
65
66 //----------------------------------------------------------------------------
67 /// @brief Set application locale to a given language.
68 ///
69 /// @note Must be called from the platform thread.
70 ///
71 virtual void FlutterViewSetApplicationLocale(std::string locale) = 0;
72
73 //----------------------------------------------------------------------------
74 /// @brief Sends new custom accessibility events.
75 ///
76 /// @note Must be called from the platform thread.
77 ///
79 std::vector<uint8_t> actions_buffer,
80 std::vector<std::string> strings) = 0;
81
82 //----------------------------------------------------------------------------
83 /// @brief Indicates that FlutterView should start painting pixels.
84 ///
85 /// @note Must be called from the platform thread.
86 ///
87 virtual void FlutterViewOnFirstFrame() = 0;
88
89 //----------------------------------------------------------------------------
90 /// @brief Indicates that a hot restart is about to happen.
91 ///
93
94 //----------------------------------------------------------------------------
95 /// @brief Attach the SurfaceTexture to the OpenGL ES context that is
96 /// current on the calling thread.
97 ///
98 virtual void SurfaceTextureAttachToGLContext(JavaLocalRef surface_texture,
99 int textureId) = 0;
100
101 //----------------------------------------------------------------------------
102 /// @brief Returns true if surface_texture should be updated.
103 ///
104 virtual bool SurfaceTextureShouldUpdate(JavaLocalRef surface_texture) = 0;
105
106 //----------------------------------------------------------------------------
107 /// @brief Updates the texture image to the most recent frame from the
108 /// image stream.
109 ///
110 virtual void SurfaceTextureUpdateTexImage(JavaLocalRef surface_texture) = 0;
111
112 //----------------------------------------------------------------------------
113 /// @brief Gets the transform matrix from the SurfaceTexture.
114 /// Then, it updates the `transform` matrix, so it fill the canvas
115 /// and preserve the aspect ratio.
116 ///
118 JavaLocalRef surface_texture) = 0;
119
120 //----------------------------------------------------------------------------
121 /// @brief Detaches a SurfaceTexture from the OpenGL ES context.
122 ///
124 JavaLocalRef surface_texture) = 0;
125
126 //----------------------------------------------------------------------------
127 /// @brief Acquire the latest image available.
128 ///
130 JavaLocalRef image_texture_entry) = 0;
131
132 //----------------------------------------------------------------------------
133 /// @brief Grab the HardwareBuffer from image.
134 ///
136
137 //----------------------------------------------------------------------------
138 /// @brief Call close on image.
139 ///
140 virtual void ImageClose(JavaLocalRef image) = 0;
141
142 //----------------------------------------------------------------------------
143 /// @brief Call close on hardware_buffer.
144 ///
145 virtual void HardwareBufferClose(JavaLocalRef hardware_buffer) = 0;
146
147 //----------------------------------------------------------------------------
148 /// @brief Positions and sizes a platform view if using hybrid
149 /// composition.
150 ///
151 /// @note Must be called from the platform thread.
152 ///
154 int view_id,
155 int x,
156 int y,
157 int width,
158 int height,
159 int viewWidth,
160 int viewHeight,
161 MutatorsStack mutators_stack) = 0;
162
163 //----------------------------------------------------------------------------
164 /// @brief Positions and sizes an overlay surface in hybrid composition.
165 ///
166 /// @note Must be called from the platform thread.
167 ///
168 virtual void FlutterViewDisplayOverlaySurface(int surface_id,
169 int x,
170 int y,
171 int width,
172 int height) = 0;
173
174 //----------------------------------------------------------------------------
175 /// @brief Initiates a frame if using hybrid composition.
176 ///
177 ///
178 /// @note Must be called from the platform thread.
179 ///
180 virtual void FlutterViewBeginFrame() = 0;
181
182 //----------------------------------------------------------------------------
183 /// @brief Indicates that the current frame ended.
184 /// It's used to clean up state.
185 ///
186 /// @note Must be called from the platform thread.
187 ///
188 virtual void FlutterViewEndFrame() = 0;
189
190 //------------------------------------------------------------------------------
191 /// The metadata returned from Java which is converted into an |OverlayLayer|
192 /// by |SurfacePool|.
193 ///
197
198 ~OverlayMetadata() = default;
199
200 // A unique id to identify the overlay when it gets recycled.
201 const int id;
202
203 // Holds a reference to the native window. That is, an `ANativeWindow`,
204 // which is the C counterpart of the `android.view.Surface` object in Java.
206 };
207
208 //----------------------------------------------------------------------------
209 /// @brief Instantiates an overlay surface in hybrid composition and
210 /// provides the necessary metadata to operate the surface in C.
211 ///
212 /// @note Must be called from the platform thread.
213 ///
214 virtual std::unique_ptr<PlatformViewAndroidJNI::OverlayMetadata>
216
217 //----------------------------------------------------------------------------
218 /// @brief Destroys the overlay surfaces.
219 ///
220 /// @note Must be called from the platform thread.
221 ///
223
224 // New Platform View Support.
225 virtual ASurfaceTransaction* createTransaction() = 0;
226
227 virtual void swapTransaction() = 0;
228
229 virtual void applyTransaction() = 0;
230
231 virtual std::unique_ptr<PlatformViewAndroidJNI::OverlayMetadata>
233
234 virtual void destroyOverlaySurface2() = 0;
235
236 virtual void onEndFrame2() = 0;
237
238 virtual void onDisplayPlatformView2(int32_t view_id,
239 int32_t x,
240 int32_t y,
241 int32_t width,
242 int32_t height,
243 int32_t viewWidth,
244 int32_t viewHeight,
245 MutatorsStack mutators_stack) = 0;
246
247 virtual void hidePlatformView2(int32_t view_id) = 0;
248
249 virtual void showOverlaySurface2() = 0;
250
251 virtual void hideOverlaySurface2() = 0;
252
253 //----------------------------------------------------------------------------
254 /// @brief Computes the locale Android would select.
255 ///
256 virtual std::unique_ptr<std::vector<std::string>>
258 std::vector<std::string> supported_locales_data) = 0;
259
260 virtual double GetDisplayRefreshRate() = 0;
261
262 virtual double GetDisplayWidth() = 0;
263
264 virtual double GetDisplayHeight() = 0;
265
266 virtual double GetDisplayDensity() = 0;
267
268 virtual bool RequestDartDeferredLibrary(int loading_unit_id) = 0;
269
270 virtual double FlutterViewGetScaledFontSize(double unscaled_font_size,
271 int configuration_id) const = 0;
272};
273
274} // namespace flutter
275
276#endif // FLUTTER_SHELL_PLATFORM_ANDROID_JNI_PLATFORM_VIEW_ANDROID_JNI_H_
virtual void FlutterViewHandlePlatformMessageResponse(int responseId, std::unique_ptr< fml::Mapping > data)=0
Responds to a platform message. The data may be a nullptr.
virtual JavaLocalRef ImageProducerTextureEntryAcquireLatestImage(JavaLocalRef image_texture_entry)=0
Acquire the latest image available.
virtual void FlutterViewBeginFrame()=0
Initiates a frame if using hybrid composition.
virtual void FlutterViewSetApplicationLocale(std::string locale)=0
Set application locale to a given language.
virtual void SurfaceTextureUpdateTexImage(JavaLocalRef surface_texture)=0
Updates the texture image to the most recent frame from the image stream.
virtual void SurfaceTextureAttachToGLContext(JavaLocalRef surface_texture, int textureId)=0
Attach the SurfaceTexture to the OpenGL ES context that is current on the calling thread.
virtual void swapTransaction()=0
virtual JavaLocalRef ImageGetHardwareBuffer(JavaLocalRef image)=0
Grab the HardwareBuffer from image.
virtual void FlutterViewDestroyOverlaySurfaces()=0
Destroys the overlay surfaces.
virtual void showOverlaySurface2()=0
virtual double GetDisplayDensity()=0
virtual double GetDisplayRefreshRate()=0
virtual void FlutterViewEndFrame()=0
Indicates that the current frame ended. It's used to clean up state.
virtual void SurfaceTextureDetachFromGLContext(JavaLocalRef surface_texture)=0
Detaches a SurfaceTexture from the OpenGL ES context.
virtual void FlutterViewDisplayOverlaySurface(int surface_id, int x, int y, int width, int height)=0
Positions and sizes an overlay surface in hybrid composition.
virtual void HardwareBufferClose(JavaLocalRef hardware_buffer)=0
Call close on hardware_buffer.
virtual void FlutterViewHandlePlatformMessage(std::unique_ptr< flutter::PlatformMessage > message, int responseId)=0
Sends a platform message. The message may be empty.
virtual void ImageClose(JavaLocalRef image)=0
Call close on image.
virtual void destroyOverlaySurface2()=0
virtual void FlutterViewUpdateCustomAccessibilityActions(std::vector< uint8_t > actions_buffer, std::vector< std::string > strings)=0
Sends new custom accessibility events.
virtual void applyTransaction()=0
virtual void FlutterViewOnFirstFrame()=0
Indicates that FlutterView should start painting pixels.
virtual std::unique_ptr< PlatformViewAndroidJNI::OverlayMetadata > createOverlaySurface2()=0
virtual double FlutterViewGetScaledFontSize(double unscaled_font_size, int configuration_id) const =0
virtual ASurfaceTransaction * createTransaction()=0
virtual void FlutterViewOnDisplayPlatformView(int view_id, int x, int y, int width, int height, int viewWidth, int viewHeight, MutatorsStack mutators_stack)=0
Positions and sizes a platform view if using hybrid composition.
virtual bool SurfaceTextureShouldUpdate(JavaLocalRef surface_texture)=0
Returns true if surface_texture should be updated.
virtual void FlutterViewUpdateSemantics(std::vector< uint8_t > buffer, std::vector< std::string > strings, std::vector< std::vector< uint8_t > > string_attribute_args)=0
Sends semantics tree updates.
virtual std::unique_ptr< std::vector< std::string > > FlutterViewComputePlatformResolvedLocale(std::vector< std::string > supported_locales_data)=0
Computes the locale Android would select.
virtual bool RequestDartDeferredLibrary(int loading_unit_id)=0
virtual double GetDisplayWidth()=0
virtual SkM44 SurfaceTextureGetTransformMatrix(JavaLocalRef surface_texture)=0
Gets the transform matrix from the SurfaceTexture. Then, it updates the transform matrix,...
virtual std::unique_ptr< PlatformViewAndroidJNI::OverlayMetadata > FlutterViewCreateOverlaySurface()=0
Instantiates an overlay surface in hybrid composition and provides the necessary metadata to operate ...
virtual void onDisplayPlatformView2(int32_t view_id, int32_t x, int32_t y, int32_t width, int32_t height, int32_t viewWidth, int32_t viewHeight, MutatorsStack mutators_stack)=0
virtual void FlutterViewOnPreEngineRestart()=0
Indicates that a hot restart is about to happen.
virtual double GetDisplayHeight()=0
virtual void hideOverlaySurface2()=0
virtual void hidePlatformView2(int32_t view_id)=0
int32_t x
FlutterVulkanImage * image
G_BEGIN_DECLS GBytes * message
G_BEGIN_DECLS FlutterViewId view_id
double y
std::nullptr_t JavaLocalRef
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36
Definition ref_ptr.h:261
int32_t height
int32_t width
const fml::RefPtr< AndroidNativeWindow > window
OverlayMetadata(int id, fml::RefPtr< AndroidNativeWindow > window)