Flutter Engine
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 "flutter/fml/macros.h"
9 #include "flutter/fml/mapping.h"
10 
11 #include "flutter/flow/embedded_views.h"
12 #include "flutter/lib/ui/window/platform_message.h"
13 #include "flutter/shell/platform/android/surface/android_native_window.h"
14 #include "third_party/skia/include/core/SkMatrix.h"
15 
16 #if OS_ANDROID
17 #include "flutter/fml/platform/android/jni_weak_ref.h"
18 #endif
19 
20 namespace flutter {
21 
22 #if OS_ANDROID
24 #else
25 using JavaWeakGlobalRef = std::nullptr_t;
26 #endif
27 
28 //------------------------------------------------------------------------------
29 /// Allows to call Java code running in the JVM from any thread. However, most
30 /// methods can only be called from the platform thread as that is where the
31 /// Java code runs.
32 ///
33 /// This interface must not depend on the Android toolchain directly, so it can
34 /// be used in unit tests compiled with the host toolchain.
35 ///
37  public:
38  virtual ~PlatformViewAndroidJNI();
39 
40  //----------------------------------------------------------------------------
41  /// @brief Sends a platform message. The message may be empty.
42  ///
45  int responseId) = 0;
46 
47  //----------------------------------------------------------------------------
48  /// @brief Responds to a platform message. The data may be a `nullptr`.
49  ///
51  int responseId,
52  std::unique_ptr<fml::Mapping> data) = 0;
53 
54  //----------------------------------------------------------------------------
55  /// @brief Sends semantics tree updates.
56  ///
57  /// @note Must be called from the platform thread.
58  ///
59  virtual void FlutterViewUpdateSemantics(std::vector<uint8_t> buffer,
60  std::vector<std::string> strings) = 0;
61 
62  //----------------------------------------------------------------------------
63  /// @brief Sends new custom accessibility events.
64  ///
65  /// @note Must be called from the platform thread.
66  ///
68  std::vector<uint8_t> actions_buffer,
69  std::vector<std::string> strings) = 0;
70 
71  //----------------------------------------------------------------------------
72  /// @brief Indicates that FlutterView should start painting pixels.
73  ///
74  /// @note Must be called from the platform thread.
75  ///
76  virtual void FlutterViewOnFirstFrame() = 0;
77 
78  //----------------------------------------------------------------------------
79  /// @brief Indicates that a hot restart is about to happen.
80  ///
81  virtual void FlutterViewOnPreEngineRestart() = 0;
82 
83  //----------------------------------------------------------------------------
84  /// @brief Attach the SurfaceTexture to the OpenGL ES context that is
85  /// current on the calling thread.
86  ///
88  JavaWeakGlobalRef surface_texture,
89  int textureId) = 0;
90 
91  //----------------------------------------------------------------------------
92  /// @brief Updates the texture image to the most recent frame from the
93  /// image stream.
94  ///
95  virtual void SurfaceTextureUpdateTexImage(
96  JavaWeakGlobalRef surface_texture) = 0;
97 
98  //----------------------------------------------------------------------------
99  /// @brief Gets the transform matrix from the SurfaceTexture.
100  /// Then, it updates the `transform` matrix, so it fill the canvas
101  /// and preserve the aspect ratio.
102  ///
104  JavaWeakGlobalRef surface_texture,
105  SkMatrix& transform) = 0;
106 
107  //----------------------------------------------------------------------------
108  /// @brief Detaches a SurfaceTexture from the OpenGL ES context.
109  ///
111  JavaWeakGlobalRef surface_texture) = 0;
112 
113  //----------------------------------------------------------------------------
114  /// @brief Positions and sizes a platform view if using hybrid
115  /// composition.
116  ///
117  /// @note Must be called from the platform thread.
118  ///
120  int view_id,
121  int x,
122  int y,
123  int width,
124  int height,
125  int viewWidth,
126  int viewHeight,
127  MutatorsStack mutators_stack) = 0;
128 
129  //----------------------------------------------------------------------------
130  /// @brief Positions and sizes an overlay surface in hybrid composition.
131  ///
132  /// @note Must be called from the platform thread.
133  ///
134  virtual void FlutterViewDisplayOverlaySurface(int surface_id,
135  int x,
136  int y,
137  int width,
138  int height) = 0;
139 
140  //----------------------------------------------------------------------------
141  /// @brief Initiates a frame if using hybrid composition.
142  ///
143  ///
144  /// @note Must be called from the platform thread.
145  ///
146  virtual void FlutterViewBeginFrame() = 0;
147 
148  //----------------------------------------------------------------------------
149  /// @brief Indicates that the current frame ended.
150  /// It's used to clean up state.
151  ///
152  /// @note Must be called from the platform thread.
153  ///
154  virtual void FlutterViewEndFrame() = 0;
155 
156  //------------------------------------------------------------------------------
157  /// The metadata returned from Java which is converted into an |OverlayLayer|
158  /// by |SurfacePool|.
159  ///
162  : id(id), window(window){};
163 
164  ~OverlayMetadata() = default;
165 
166  // A unique id to identify the overlay when it gets recycled.
167  const int id;
168 
169  // Holds a reference to the native window. That is, an `ANativeWindow`,
170  // which is the C counterpart of the `android.view.Surface` object in Java.
172  };
173 
174  //----------------------------------------------------------------------------
175  /// @brief Instantiates an overlay surface in hybrid composition and
176  /// provides the necessary metadata to operate the surface in C.
177  ///
178  /// @note Must be called from the platform thread.
179  ///
180  virtual std::unique_ptr<PlatformViewAndroidJNI::OverlayMetadata>
182 
183  //----------------------------------------------------------------------------
184  /// @brief Destroys the overlay surfaces.
185  ///
186  /// @note Must be called from the platform thread.
187  ///
188  virtual void FlutterViewDestroyOverlaySurfaces() = 0;
189 
190  //----------------------------------------------------------------------------
191  /// @brief Computes the locale Android would select.
192  ///
193  virtual std::unique_ptr<std::vector<std::string>>
195  std::vector<std::string> supported_locales_data) = 0;
196 
197  virtual double GetDisplayRefreshRate() = 0;
198 };
199 
200 } // namespace flutter
201 
202 #endif // FLUTTER_SHELL_PLATFORM_ANDROID_JNI_PLATFORM_VIEW_ANDROID_JNI_H_
OverlayMetadata(int id, fml::RefPtr< AndroidNativeWindow > window)
virtual std::unique_ptr< PlatformViewAndroidJNI::OverlayMetadata > FlutterViewCreateOverlaySurface()=0
Instantiates an overlay surface in hybrid composition and provides the necessary metadata to operate ...
virtual std::unique_ptr< std::vector< std::string > > FlutterViewComputePlatformResolvedLocale(std::vector< std::string > supported_locales_data)=0
Computes the locale Android would select.
const fml::RefPtr< AndroidNativeWindow > window
std::nullptr_t JavaWeakGlobalRef
virtual void SurfaceTextureDetachFromGLContext(JavaWeakGlobalRef surface_texture)=0
Detaches a SurfaceTexture from the OpenGL ES context.
virtual void FlutterViewDestroyOverlaySurfaces()=0
Destroys the overlay surfaces.
virtual void FlutterViewOnPreEngineRestart()=0
Indicates that a hot restart is about to happen.
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 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 void FlutterViewHandlePlatformMessage(fml::RefPtr< flutter::PlatformMessage > message, int responseId)=0
Sends a platform message. The message may be empty.
virtual void FlutterViewBeginFrame()=0
Initiates a frame if using hybrid composition.
virtual void FlutterViewEndFrame()=0
Indicates that the current frame ended. It&#39;s used to clean up state.
virtual double GetDisplayRefreshRate()=0
int32_t height
virtual void SurfaceTextureUpdateTexImage(JavaWeakGlobalRef surface_texture)=0
Updates the texture image to the most recent frame from the image stream.
int32_t width
virtual void FlutterViewUpdateSemantics(std::vector< uint8_t > buffer, std::vector< std::string > strings)=0
Sends semantics tree updates.
virtual void FlutterViewHandlePlatformMessageResponse(int responseId, std::unique_ptr< fml::Mapping > data)=0
Responds to a platform message. The data may be a nullptr.
virtual void FlutterViewUpdateCustomAccessibilityActions(std::vector< uint8_t > actions_buffer, std::vector< std::string > strings)=0
Sends new custom accessibility events.
virtual void SurfaceTextureAttachToGLContext(JavaWeakGlobalRef surface_texture, int textureId)=0
Attach the SurfaceTexture to the OpenGL ES context that is current on the calling thread...
virtual void FlutterViewOnFirstFrame()=0
Indicates that FlutterView should start painting pixels.
virtual void SurfaceTextureGetTransformMatrix(JavaWeakGlobalRef surface_texture, SkMatrix &transform)=0
Gets the transform matrix from the SurfaceTexture. Then, it updates the transform matrix...