Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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 Enables or disables the semantics tree.
75 ///
76 /// @note Must be called from the platform thread.
77 ///
78 virtual void FlutterViewSetSemanticsTreeEnabled(bool enabled) = 0;
79
80 //----------------------------------------------------------------------------
81 /// @brief Sends new custom accessibility events.
82 ///
83 /// @note Must be called from the platform thread.
84 ///
86 std::vector<uint8_t> actions_buffer,
87 std::vector<std::string> strings) = 0;
88
89 //----------------------------------------------------------------------------
90 /// @brief Indicates that FlutterView should start painting pixels.
91 ///
92 /// @note Must be called from the platform thread.
93 ///
94 virtual void FlutterViewOnFirstFrame() = 0;
95
96 //----------------------------------------------------------------------------
97 /// @brief Indicates that a hot restart is about to happen.
98 ///
100
101 //----------------------------------------------------------------------------
102 /// @brief Attach the SurfaceTexture to the OpenGL ES context that is
103 /// current on the calling thread.
104 ///
105 virtual void SurfaceTextureAttachToGLContext(JavaLocalRef surface_texture,
106 int textureId) = 0;
107
108 //----------------------------------------------------------------------------
109 /// @brief Returns true if surface_texture should be updated.
110 ///
111 virtual bool SurfaceTextureShouldUpdate(JavaLocalRef surface_texture) = 0;
112
113 //----------------------------------------------------------------------------
114 /// @brief Updates the texture image to the most recent frame from the
115 /// image stream.
116 ///
117 virtual void SurfaceTextureUpdateTexImage(JavaLocalRef surface_texture) = 0;
118
119 //----------------------------------------------------------------------------
120 /// @brief Gets the transform matrix from the SurfaceTexture.
121 /// Then, it updates the `transform` matrix, so it fill the canvas
122 /// and preserve the aspect ratio.
123 ///
125 JavaLocalRef surface_texture) = 0;
126
127 //----------------------------------------------------------------------------
128 /// @brief Detaches a SurfaceTexture from the OpenGL ES context.
129 ///
131 JavaLocalRef surface_texture) = 0;
132
133 //----------------------------------------------------------------------------
134 /// @brief Acquire the latest image available.
135 ///
137 JavaLocalRef image_texture_entry) = 0;
138
139 //----------------------------------------------------------------------------
140 /// @brief Grab the HardwareBuffer from image.
141 ///
143
144 //----------------------------------------------------------------------------
145 /// @brief Call close on image.
146 ///
147 virtual void ImageClose(JavaLocalRef image) = 0;
148
149 //----------------------------------------------------------------------------
150 /// @brief Call close on hardware_buffer.
151 ///
152 virtual void HardwareBufferClose(JavaLocalRef hardware_buffer) = 0;
153
154 //----------------------------------------------------------------------------
155 /// @brief Positions and sizes a platform view if using hybrid
156 /// composition.
157 ///
158 /// @note Must be called from the platform thread.
159 ///
161 int view_id,
162 int x,
163 int y,
164 int width,
165 int height,
166 int viewWidth,
167 int viewHeight,
168 MutatorsStack mutators_stack) = 0;
169
170 //----------------------------------------------------------------------------
171 /// @brief Positions and sizes an overlay surface in hybrid composition.
172 ///
173 /// @note Must be called from the platform thread.
174 ///
175 virtual void FlutterViewDisplayOverlaySurface(int surface_id,
176 int x,
177 int y,
178 int width,
179 int height) = 0;
180
181 //----------------------------------------------------------------------------
182 /// @brief Initiates a frame if using hybrid composition.
183 ///
184 ///
185 /// @note Must be called from the platform thread.
186 ///
187 virtual void FlutterViewBeginFrame() = 0;
188
189 //----------------------------------------------------------------------------
190 /// @brief Indicates that the current frame ended.
191 /// It's used to clean up state.
192 ///
193 /// @note Must be called from the platform thread.
194 ///
195 virtual void FlutterViewEndFrame() = 0;
196
197 //------------------------------------------------------------------------------
198 /// The metadata returned from Java which is converted into an |OverlayLayer|
199 /// by |SurfacePool|.
200 ///
204
205 ~OverlayMetadata() = default;
206
207 // A unique id to identify the overlay when it gets recycled.
208 const int id;
209
210 // Holds a reference to the native window. That is, an `ANativeWindow`,
211 // which is the C counterpart of the `android.view.Surface` object in Java.
213 };
214
215 //----------------------------------------------------------------------------
216 /// @brief Instantiates an overlay surface in hybrid composition and
217 /// provides the necessary metadata to operate the surface in C.
218 ///
219 /// @note Must be called from the platform thread.
220 ///
221 virtual std::unique_ptr<PlatformViewAndroidJNI::OverlayMetadata>
223
224 //----------------------------------------------------------------------------
225 /// @brief Destroys the overlay surfaces.
226 ///
227 /// @note Must be called from the platform thread.
228 ///
230
231 // New Platform View Support.
232 virtual ASurfaceTransaction* createTransaction() = 0;
233
234 virtual void swapTransaction() = 0;
235
236 virtual void applyTransaction() = 0;
237
238 virtual std::unique_ptr<PlatformViewAndroidJNI::OverlayMetadata>
240
241 virtual void destroyOverlaySurface2() = 0;
242
243 virtual void onEndFrame2() = 0;
244
245 virtual void onDisplayPlatformView2(int32_t view_id,
246 int32_t x,
247 int32_t y,
248 int32_t width,
249 int32_t height,
250 int32_t viewWidth,
251 int32_t viewHeight,
252 MutatorsStack mutators_stack) = 0;
253
254 virtual void hidePlatformView2(int32_t view_id) = 0;
255
256 virtual void showOverlaySurface2() = 0;
257
258 virtual void hideOverlaySurface2() = 0;
259
260 //----------------------------------------------------------------------------
261 /// @brief Computes the locale Android would select.
262 ///
263 virtual std::unique_ptr<std::vector<std::string>>
265 std::vector<std::string> supported_locales_data) = 0;
266
267 virtual double GetDisplayRefreshRate() = 0;
268
269 virtual double GetDisplayWidth() = 0;
270
271 virtual double GetDisplayHeight() = 0;
272
273 virtual double GetDisplayDensity() = 0;
274
275 virtual bool RequestDartDeferredLibrary(int loading_unit_id) = 0;
276
277 virtual double FlutterViewGetScaledFontSize(double unscaled_font_size,
278 int configuration_id) const = 0;
279
280 virtual void MaybeResizeSurfaceView(int32_t width, int32_t height) const = 0;
281};
282
283} // namespace flutter
284
285#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 FlutterViewSetSemanticsTreeEnabled(bool enabled)=0
Enables or disables the semantics tree.
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 MaybeResizeSurfaceView(int32_t width, int32_t height) const =0
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
const char * 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)