Flutter Engine
The 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/macros.h"
11#include "flutter/fml/mapping.h"
12
13#include "flutter/flow/embedded_views.h"
14#include "flutter/lib/ui/window/platform_message.h"
15#include "flutter/shell/platform/android/surface/android_native_window.h"
17
18#if FML_OS_ANDROID
19#include "flutter/fml/platform/android/scoped_java_ref.h"
20#endif
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 Sends new custom accessibility events.
68 ///
69 /// @note Must be called from the platform thread.
70 ///
72 std::vector<uint8_t> actions_buffer,
73 std::vector<std::string> strings) = 0;
74
75 //----------------------------------------------------------------------------
76 /// @brief Indicates that FlutterView should start painting pixels.
77 ///
78 /// @note Must be called from the platform thread.
79 ///
80 virtual void FlutterViewOnFirstFrame() = 0;
81
82 //----------------------------------------------------------------------------
83 /// @brief Indicates that a hot restart is about to happen.
84 ///
86
87 //----------------------------------------------------------------------------
88 /// @brief Attach the SurfaceTexture to the OpenGL ES context that is
89 /// current on the calling thread.
90 ///
91 virtual void SurfaceTextureAttachToGLContext(JavaLocalRef surface_texture,
92 int textureId) = 0;
93
94 //----------------------------------------------------------------------------
95 /// @brief Returns true if surface_texture should be updated.
96 ///
97 virtual bool SurfaceTextureShouldUpdate(JavaLocalRef surface_texture) = 0;
98
99 //----------------------------------------------------------------------------
100 /// @brief Updates the texture image to the most recent frame from the
101 /// image stream.
102 ///
103 virtual void SurfaceTextureUpdateTexImage(JavaLocalRef surface_texture) = 0;
104
105 //----------------------------------------------------------------------------
106 /// @brief Gets the transform matrix from the SurfaceTexture.
107 /// Then, it updates the `transform` matrix, so it fill the canvas
108 /// and preserve the aspect ratio.
109 ///
110 virtual void SurfaceTextureGetTransformMatrix(JavaLocalRef surface_texture,
111 SkMatrix& transform) = 0;
112
113 //----------------------------------------------------------------------------
114 /// @brief Detaches a SurfaceTexture from the OpenGL ES context.
115 ///
117 JavaLocalRef surface_texture) = 0;
118
119 //----------------------------------------------------------------------------
120 /// @brief Acquire the latest image available.
121 ///
123 JavaLocalRef image_texture_entry) = 0;
124
125 //----------------------------------------------------------------------------
126 /// @brief Grab the HardwareBuffer from image.
127 ///
129
130 //----------------------------------------------------------------------------
131 /// @brief Call close on image.
132 ///
133 virtual void ImageClose(JavaLocalRef image) = 0;
134
135 //----------------------------------------------------------------------------
136 /// @brief Call close on hardware_buffer.
137 ///
138 virtual void HardwareBufferClose(JavaLocalRef hardware_buffer) = 0;
139
140 //----------------------------------------------------------------------------
141 /// @brief Positions and sizes a platform view if using hybrid
142 /// composition.
143 ///
144 /// @note Must be called from the platform thread.
145 ///
147 int view_id,
148 int x,
149 int y,
150 int width,
151 int height,
152 int viewWidth,
153 int viewHeight,
154 MutatorsStack mutators_stack) = 0;
155
156 //----------------------------------------------------------------------------
157 /// @brief Positions and sizes an overlay surface in hybrid composition.
158 ///
159 /// @note Must be called from the platform thread.
160 ///
161 virtual void FlutterViewDisplayOverlaySurface(int surface_id,
162 int x,
163 int y,
164 int width,
165 int height) = 0;
166
167 //----------------------------------------------------------------------------
168 /// @brief Initiates a frame if using hybrid composition.
169 ///
170 ///
171 /// @note Must be called from the platform thread.
172 ///
173 virtual void FlutterViewBeginFrame() = 0;
174
175 //----------------------------------------------------------------------------
176 /// @brief Indicates that the current frame ended.
177 /// It's used to clean up state.
178 ///
179 /// @note Must be called from the platform thread.
180 ///
181 virtual void FlutterViewEndFrame() = 0;
182
183 //------------------------------------------------------------------------------
184 /// The metadata returned from Java which is converted into an |OverlayLayer|
185 /// by |SurfacePool|.
186 ///
190
191 ~OverlayMetadata() = default;
192
193 // A unique id to identify the overlay when it gets recycled.
194 const int id;
195
196 // Holds a reference to the native window. That is, an `ANativeWindow`,
197 // which is the C counterpart of the `android.view.Surface` object in Java.
199 };
200
201 //----------------------------------------------------------------------------
202 /// @brief Instantiates an overlay surface in hybrid composition and
203 /// provides the necessary metadata to operate the surface in C.
204 ///
205 /// @note Must be called from the platform thread.
206 ///
207 virtual std::unique_ptr<PlatformViewAndroidJNI::OverlayMetadata>
209
210 //----------------------------------------------------------------------------
211 /// @brief Destroys the overlay surfaces.
212 ///
213 /// @note Must be called from the platform thread.
214 ///
216
217 //----------------------------------------------------------------------------
218 /// @brief Computes the locale Android would select.
219 ///
220 virtual std::unique_ptr<std::vector<std::string>>
222 std::vector<std::string> supported_locales_data) = 0;
223
224 virtual double GetDisplayRefreshRate() = 0;
225
226 virtual double GetDisplayWidth() = 0;
227
228 virtual double GetDisplayHeight() = 0;
229
230 virtual double GetDisplayDensity() = 0;
231
232 virtual bool RequestDartDeferredLibrary(int loading_unit_id) = 0;
233
234 virtual double FlutterViewGetScaledFontSize(double unscaled_font_size,
235 int configuration_id) const = 0;
236};
237
238} // namespace flutter
239
240#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 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 JavaLocalRef ImageGetHardwareBuffer(JavaLocalRef image)=0
Grab the HardwareBuffer from image.
virtual void SurfaceTextureGetTransformMatrix(JavaLocalRef surface_texture, SkMatrix &transform)=0
Gets the transform matrix from the SurfaceTexture. Then, it updates the transform matrix,...
virtual void FlutterViewDestroyOverlaySurfaces()=0
Destroys the overlay surfaces.
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 FlutterViewUpdateCustomAccessibilityActions(std::vector< uint8_t > actions_buffer, std::vector< std::string > strings)=0
Sends new custom accessibility events.
virtual void FlutterViewOnFirstFrame()=0
Indicates that FlutterView should start painting pixels.
virtual double FlutterViewGetScaledFontSize(double unscaled_font_size, int configuration_id) const =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 std::unique_ptr< PlatformViewAndroidJNI::OverlayMetadata > FlutterViewCreateOverlaySurface()=0
Instantiates an overlay surface in hybrid composition and provides the necessary metadata to operate ...
virtual void FlutterViewOnPreEngineRestart()=0
Indicates that a hot restart is about to happen.
virtual double GetDisplayHeight()=0
sk_sp< SkImage > image
Definition examples.cpp:29
Win32Message message
double y
double x
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 switches.h:41
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition switches.h:126
Definition ref_ptr.h:256
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47
int32_t height
int32_t width
const fml::RefPtr< AndroidNativeWindow > window
OverlayMetadata(int id, fml::RefPtr< AndroidNativeWindow > window)