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/scoped_java_ref.h"
18 #endif
19 
20 namespace flutter {
21 
22 #if OS_ANDROID
24 #else
25 using JavaLocalRef = 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  ///
44  std::unique_ptr<flutter::PlatformMessage> message,
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(
60  std::vector<uint8_t> buffer,
61  std::vector<std::string> strings,
62  std::vector<std::vector<uint8_t>> string_attribute_args) = 0;
63 
64  //----------------------------------------------------------------------------
65  /// @brief Sends new custom accessibility events.
66  ///
67  /// @note Must be called from the platform thread.
68  ///
70  std::vector<uint8_t> actions_buffer,
71  std::vector<std::string> strings) = 0;
72 
73  //----------------------------------------------------------------------------
74  /// @brief Indicates that FlutterView should start painting pixels.
75  ///
76  /// @note Must be called from the platform thread.
77  ///
78  virtual void FlutterViewOnFirstFrame() = 0;
79 
80  //----------------------------------------------------------------------------
81  /// @brief Indicates that a hot restart is about to happen.
82  ///
83  virtual void FlutterViewOnPreEngineRestart() = 0;
84 
85  //----------------------------------------------------------------------------
86  /// @brief Attach the SurfaceTexture to the OpenGL ES context that is
87  /// current on the calling thread.
88  ///
89  virtual void SurfaceTextureAttachToGLContext(JavaLocalRef surface_texture,
90  int textureId) = 0;
91 
92  //----------------------------------------------------------------------------
93  /// @brief Updates the texture image to the most recent frame from the
94  /// image stream.
95  ///
96  virtual void SurfaceTextureUpdateTexImage(JavaLocalRef 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  ///
103  virtual void SurfaceTextureGetTransformMatrix(JavaLocalRef surface_texture,
104  SkMatrix& transform) = 0;
105 
106  //----------------------------------------------------------------------------
107  /// @brief Detaches a SurfaceTexture from the OpenGL ES context.
108  ///
110  JavaLocalRef surface_texture) = 0;
111 
112  //----------------------------------------------------------------------------
113  /// @brief Positions and sizes a platform view if using hybrid
114  /// composition.
115  ///
116  /// @note Must be called from the platform thread.
117  ///
119  int view_id,
120  int x,
121  int y,
122  int width,
123  int height,
124  int viewWidth,
125  int viewHeight,
126  MutatorsStack mutators_stack) = 0;
127 
128  //----------------------------------------------------------------------------
129  /// @brief Positions and sizes an overlay surface in hybrid composition.
130  ///
131  /// @note Must be called from the platform thread.
132  ///
133  virtual void FlutterViewDisplayOverlaySurface(int surface_id,
134  int x,
135  int y,
136  int width,
137  int height) = 0;
138 
139  //----------------------------------------------------------------------------
140  /// @brief Initiates a frame if using hybrid composition.
141  ///
142  ///
143  /// @note Must be called from the platform thread.
144  ///
145  virtual void FlutterViewBeginFrame() = 0;
146 
147  //----------------------------------------------------------------------------
148  /// @brief Indicates that the current frame ended.
149  /// It's used to clean up state.
150  ///
151  /// @note Must be called from the platform thread.
152  ///
153  virtual void FlutterViewEndFrame() = 0;
154 
155  //------------------------------------------------------------------------------
156  /// The metadata returned from Java which is converted into an |OverlayLayer|
157  /// by |SurfacePool|.
158  ///
161  : id(id), window(window){};
162 
163  ~OverlayMetadata() = default;
164 
165  // A unique id to identify the overlay when it gets recycled.
166  const int id;
167 
168  // Holds a reference to the native window. That is, an `ANativeWindow`,
169  // which is the C counterpart of the `android.view.Surface` object in Java.
171  };
172 
173  //----------------------------------------------------------------------------
174  /// @brief Instantiates an overlay surface in hybrid composition and
175  /// provides the necessary metadata to operate the surface in C.
176  ///
177  /// @note Must be called from the platform thread.
178  ///
179  virtual std::unique_ptr<PlatformViewAndroidJNI::OverlayMetadata>
181 
182  //----------------------------------------------------------------------------
183  /// @brief Destroys the overlay surfaces.
184  ///
185  /// @note Must be called from the platform thread.
186  ///
187  virtual void FlutterViewDestroyOverlaySurfaces() = 0;
188 
189  //----------------------------------------------------------------------------
190  /// @brief Computes the locale Android would select.
191  ///
192  virtual std::unique_ptr<std::vector<std::string>>
194  std::vector<std::string> supported_locales_data) = 0;
195 
196  virtual double GetDisplayRefreshRate() = 0;
197 
198  virtual bool RequestDartDeferredLibrary(int loading_unit_id) = 0;
199 };
200 
201 } // namespace flutter
202 
203 #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 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.
const fml::RefPtr< AndroidNativeWindow > window
virtual void FlutterViewDestroyOverlaySurfaces()=0
Destroys the overlay surfaces.
virtual void FlutterViewOnPreEngineRestart()=0
Indicates that a hot restart is about to happen.
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 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 FlutterViewBeginFrame()=0
Initiates a frame if using hybrid composition.
virtual bool RequestDartDeferredLibrary(int loading_unit_id)=0
virtual void SurfaceTextureGetTransformMatrix(JavaLocalRef surface_texture, SkMatrix &transform)=0
Gets the transform matrix from the SurfaceTexture. Then, it updates the transform matrix...
virtual void FlutterViewEndFrame()=0
Indicates that the current frame ended. It&#39;s used to clean up state.
virtual double GetDisplayRefreshRate()=0
int32_t width
int32_t height
virtual void FlutterViewHandlePlatformMessage(std::unique_ptr< flutter::PlatformMessage > message, int responseId)=0
Sends a platform message. The message may be empty.
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.
static const uint8_t buffer[]
std::nullptr_t JavaLocalRef
virtual void SurfaceTextureUpdateTexImage(JavaLocalRef surface_texture)=0
Updates the texture image to the most recent frame from the image stream.
virtual void FlutterViewOnFirstFrame()=0
Indicates that FlutterView should start painting pixels.
virtual void SurfaceTextureAttachToGLContext(JavaLocalRef surface_texture, int textureId)=0
Attach the SurfaceTexture to the OpenGL ES context that is current on the calling thread...