Flutter Engine
flutter::PlatformViewAndroidJNIImpl Class Referencefinal

Concrete implementation of PlatformViewAndroidJNI that is compiled with the Android toolchain. More...

#include <platform_view_android_jni_impl.h>

Inheritance diagram for flutter::PlatformViewAndroidJNIImpl:
flutter::PlatformViewAndroidJNI

Public Member Functions

 PlatformViewAndroidJNIImpl (fml::jni::JavaObjectWeakGlobalRef java_object)
 
 ~PlatformViewAndroidJNIImpl () override
 
void FlutterViewHandlePlatformMessage (std::unique_ptr< flutter::PlatformMessage > message, int responseId) override
 Sends a platform message. The message may be empty. More...
 
void FlutterViewHandlePlatformMessageResponse (int responseId, std::unique_ptr< fml::Mapping > data) override
 Responds to a platform message. The data may be a nullptr. More...
 
void FlutterViewUpdateSemantics (std::vector< uint8_t > buffer, std::vector< std::string > strings, std::vector< std::vector< uint8_t >> string_attribute_args) override
 Sends semantics tree updates. More...
 
void FlutterViewUpdateCustomAccessibilityActions (std::vector< uint8_t > actions_buffer, std::vector< std::string > strings) override
 Sends new custom accessibility events. More...
 
void FlutterViewOnFirstFrame () override
 Indicates that FlutterView should start painting pixels. More...
 
void FlutterViewOnPreEngineRestart () override
 Indicates that a hot restart is about to happen. More...
 
void SurfaceTextureAttachToGLContext (JavaLocalRef surface_texture, int textureId) override
 Attach the SurfaceTexture to the OpenGL ES context that is current on the calling thread. More...
 
void SurfaceTextureUpdateTexImage (JavaLocalRef surface_texture) override
 Updates the texture image to the most recent frame from the image stream. More...
 
void SurfaceTextureGetTransformMatrix (JavaLocalRef surface_texture, SkMatrix &transform) override
 Gets the transform matrix from the SurfaceTexture. Then, it updates the transform matrix, so it fill the canvas and preserve the aspect ratio. More...
 
void SurfaceTextureDetachFromGLContext (JavaLocalRef surface_texture) override
 Detaches a SurfaceTexture from the OpenGL ES context. More...
 
void FlutterViewOnDisplayPlatformView (int view_id, int x, int y, int width, int height, int viewWidth, int viewHeight, MutatorsStack mutators_stack) override
 Positions and sizes a platform view if using hybrid composition. More...
 
void FlutterViewDisplayOverlaySurface (int surface_id, int x, int y, int width, int height) override
 Positions and sizes an overlay surface in hybrid composition. More...
 
void FlutterViewBeginFrame () override
 Initiates a frame if using hybrid composition. More...
 
void FlutterViewEndFrame () override
 Indicates that the current frame ended. It's used to clean up state. More...
 
std::unique_ptr< PlatformViewAndroidJNI::OverlayMetadataFlutterViewCreateOverlaySurface () override
 Instantiates an overlay surface in hybrid composition and provides the necessary metadata to operate the surface in C. More...
 
void FlutterViewDestroyOverlaySurfaces () override
 Destroys the overlay surfaces. More...
 
std::unique_ptr< std::vector< std::string > > FlutterViewComputePlatformResolvedLocale (std::vector< std::string > supported_locales_data) override
 Computes the locale Android would select. More...
 
double GetDisplayRefreshRate () override
 
bool RequestDartDeferredLibrary (int loading_unit_id) override
 
- Public Member Functions inherited from flutter::PlatformViewAndroidJNI
virtual ~PlatformViewAndroidJNI ()
 

Detailed Description

Concrete implementation of PlatformViewAndroidJNI that is compiled with the Android toolchain.

Definition at line 17 of file platform_view_android_jni_impl.h.

Constructor & Destructor Documentation

◆ PlatformViewAndroidJNIImpl()

flutter::PlatformViewAndroidJNIImpl::PlatformViewAndroidJNIImpl ( fml::jni::JavaObjectWeakGlobalRef  java_object)

Definition at line 1107 of file platform_view_android_jni_impl.cc.

References ~PlatformViewAndroidJNIImpl().

1109  : java_object_(java_object) {}

◆ ~PlatformViewAndroidJNIImpl()

flutter::PlatformViewAndroidJNIImpl::~PlatformViewAndroidJNIImpl ( )
overridedefault

Member Function Documentation

◆ FlutterViewBeginFrame()

void flutter::PlatformViewAndroidJNIImpl::FlutterViewBeginFrame ( )
overridevirtual

Initiates a frame if using hybrid composition.

Note
Must be called from the platform thread.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1461 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_on_begin_frame_method, and fml::jni::JavaObjectWeakGlobalRef::get().

1461  {
1462  JNIEnv* env = fml::jni::AttachCurrentThread();
1463 
1464  auto java_object = java_object_.get(env);
1465  if (java_object.is_null()) {
1466  return;
1467  }
1468 
1469  env->CallVoidMethod(java_object.obj(), g_on_begin_frame_method);
1470 
1472 }
static jmethodID g_on_begin_frame_method
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ FlutterViewComputePlatformResolvedLocale()

std::unique_ptr< std::vector< std::string > > flutter::PlatformViewAndroidJNIImpl::FlutterViewComputePlatformResolvedLocale ( std::vector< std::string >  supported_locales_data)
overridevirtual

Computes the locale Android would select.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1533 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_compute_platform_resolved_locale_method, fml::jni::JavaObjectWeakGlobalRef::get(), fml::jni::JavaStringToString(), length, fml::jni::JavaRef< T >::obj(), result, and fml::jni::VectorToStringArray().

1534  {
1535  JNIEnv* env = fml::jni::AttachCurrentThread();
1536 
1537  std::unique_ptr<std::vector<std::string>> out =
1538  std::make_unique<std::vector<std::string>>();
1539 
1540  auto java_object = java_object_.get(env);
1541  if (java_object.is_null()) {
1542  return out;
1543  }
1545  fml::jni::VectorToStringArray(env, supported_locales_data);
1546  jobjectArray result = static_cast<jobjectArray>(env->CallObjectMethod(
1547  java_object.obj(), g_compute_platform_resolved_locale_method,
1548  j_locales_data.obj()));
1549 
1551 
1552  int length = env->GetArrayLength(result);
1553  for (int i = 0; i < length; i++) {
1554  out->emplace_back(fml::jni::JavaStringToString(
1555  env, static_cast<jstring>(env->GetObjectArrayElement(result, i))));
1556  }
1557  return out;
1558 }
ScopedJavaLocalRef< jobjectArray > VectorToStringArray(JNIEnv *env, const std::vector< std::string > &vector)
Definition: jni_util.cc:128
GAsyncResult * result
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
static jmethodID g_compute_platform_resolved_locale_method
size_t length
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34
std::string JavaStringToString(JNIEnv *env, jstring str)
Definition: jni_util.cc:76

◆ FlutterViewCreateOverlaySurface()

std::unique_ptr< PlatformViewAndroidJNI::OverlayMetadata > flutter::PlatformViewAndroidJNIImpl::FlutterViewCreateOverlaySurface ( )
overridevirtual

Instantiates an overlay surface in hybrid composition and provides the necessary metadata to operate the surface in C.

Note
Must be called from the platform thread.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1488 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_create_overlay_surface_method, flutter::g_overlay_surface_id_method, flutter::g_overlay_surface_surface_method, fml::jni::JavaObjectWeakGlobalRef::get(), and fml::jni::JavaRef< T >::obj().

1488  {
1489  JNIEnv* env = fml::jni::AttachCurrentThread();
1490 
1491  auto java_object = java_object_.get(env);
1492  if (java_object.is_null()) {
1493  return nullptr;
1494  }
1495 
1497  env, env->CallObjectMethod(java_object.obj(),
1500 
1501  if (overlay.is_null()) {
1502  return std::make_unique<PlatformViewAndroidJNI::OverlayMetadata>(0,
1503  nullptr);
1504  }
1505 
1506  jint overlay_id =
1507  env->CallIntMethod(overlay.obj(), g_overlay_surface_id_method);
1508 
1509  jobject overlay_surface =
1510  env->CallObjectMethod(overlay.obj(), g_overlay_surface_surface_method);
1511 
1512  auto overlay_window = fml::MakeRefCounted<AndroidNativeWindow>(
1513  ANativeWindow_fromSurface(env, overlay_surface));
1514 
1515  return std::make_unique<PlatformViewAndroidJNI::OverlayMetadata>(
1516  overlay_id, std::move(overlay_window));
1517 }
static jmethodID g_overlay_surface_surface_method
static jmethodID g_create_overlay_surface_method
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
static jmethodID g_overlay_surface_id_method
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ FlutterViewDestroyOverlaySurfaces()

void flutter::PlatformViewAndroidJNIImpl::FlutterViewDestroyOverlaySurfaces ( )
overridevirtual

Destroys the overlay surfaces.

Note
Must be called from the platform thread.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1519 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_destroy_overlay_surfaces_method, and fml::jni::JavaObjectWeakGlobalRef::get().

1519  {
1520  JNIEnv* env = fml::jni::AttachCurrentThread();
1521 
1522  auto java_object = java_object_.get(env);
1523  if (java_object.is_null()) {
1524  return;
1525  }
1526 
1527  env->CallVoidMethod(java_object.obj(), g_destroy_overlay_surfaces_method);
1528 
1530 }
static jmethodID g_destroy_overlay_surfaces_method
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ FlutterViewDisplayOverlaySurface()

void flutter::PlatformViewAndroidJNIImpl::FlutterViewDisplayOverlaySurface ( int  surface_id,
int  x,
int  y,
int  width,
int  height 
)
overridevirtual

Positions and sizes an overlay surface in hybrid composition.

Note
Must be called from the platform thread.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1442 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_on_display_overlay_surface_method, fml::jni::JavaObjectWeakGlobalRef::get(), height, and width.

1447  {
1448  JNIEnv* env = fml::jni::AttachCurrentThread();
1449 
1450  auto java_object = java_object_.get(env);
1451  if (java_object.is_null()) {
1452  return;
1453  }
1454 
1455  env->CallVoidMethod(java_object.obj(), g_on_display_overlay_surface_method,
1456  surface_id, x, y, width, height);
1457 
1459 }
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
int32_t width
int32_t height
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34
static jmethodID g_on_display_overlay_surface_method

◆ FlutterViewEndFrame()

void flutter::PlatformViewAndroidJNIImpl::FlutterViewEndFrame ( )
overridevirtual

Indicates that the current frame ended. It's used to clean up state.

Note
Must be called from the platform thread.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1474 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_on_end_frame_method, and fml::jni::JavaObjectWeakGlobalRef::get().

1474  {
1475  JNIEnv* env = fml::jni::AttachCurrentThread();
1476 
1477  auto java_object = java_object_.get(env);
1478  if (java_object.is_null()) {
1479  return;
1480  }
1481 
1482  env->CallVoidMethod(java_object.obj(), g_on_end_frame_method);
1483 
1485 }
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
static jmethodID g_on_end_frame_method
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ FlutterViewHandlePlatformMessage()

void flutter::PlatformViewAndroidJNIImpl::FlutterViewHandlePlatformMessage ( std::unique_ptr< flutter::PlatformMessage message,
int  responseId 
)
overridevirtual

Sends a platform message. The message may be empty.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1113 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_handle_platform_message_method, fml::jni::JavaObjectWeakGlobalRef::get(), fml::jni::JavaRef< T >::obj(), fml::MallocMapping::Release(), and fml::jni::StringToJavaString().

1115  {
1116  // Called from the ui thread.
1117  JNIEnv* env = fml::jni::AttachCurrentThread();
1118 
1119  auto java_object = java_object_.get(env);
1120  if (java_object.is_null()) {
1121  return;
1122  }
1123 
1125  fml::jni::StringToJavaString(env, message->channel());
1126 
1127  if (message->hasData()) {
1129  env, env->NewDirectByteBuffer(
1130  const_cast<uint8_t*>(message->data().GetMapping()),
1131  message->data().GetSize()));
1132  // Message data is deleted in CleanupMessageData.
1133  fml::MallocMapping mapping = message->releaseData();
1134  env->CallVoidMethod(java_object.obj(), g_handle_platform_message_method,
1135  java_channel.obj(), message_array.obj(), responseId,
1136  mapping.Release());
1137  } else {
1138  env->CallVoidMethod(java_object.obj(), g_handle_platform_message_method,
1139  java_channel.obj(), nullptr, responseId, nullptr);
1140  }
1141 
1143 }
ScopedJavaLocalRef< jstring > StringToJavaString(JNIEnv *env, const std::string &u8_string)
Definition: jni_util.cc:96
static jmethodID g_handle_platform_message_method
uint8_t * Release()
Definition: mapping.cc:137
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition: mapping.h:129
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ FlutterViewHandlePlatformMessageResponse()

void flutter::PlatformViewAndroidJNIImpl::FlutterViewHandlePlatformMessageResponse ( int  responseId,
std::unique_ptr< fml::Mapping data 
)
overridevirtual

Responds to a platform message. The data may be a nullptr.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1145 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_handle_platform_message_response_method, fml::jni::JavaObjectWeakGlobalRef::get(), and fml::jni::JavaRef< T >::obj().

1147  {
1148  // We are on the platform thread. Attempt to get the strong reference to
1149  // the Java object.
1150  JNIEnv* env = fml::jni::AttachCurrentThread();
1151 
1152  auto java_object = java_object_.get(env);
1153  if (java_object.is_null()) {
1154  // The Java object was collected before this message response got to
1155  // it. Drop the response on the floor.
1156  return;
1157  }
1158  if (data == nullptr) { // Empty response.
1159  env->CallVoidMethod(java_object.obj(),
1161  nullptr);
1162  } else {
1163  // Convert the vector to a Java byte array.
1165  env, env->NewDirectByteBuffer(const_cast<uint8_t*>(data->GetMapping()),
1166  data->GetSize()));
1167 
1168  env->CallVoidMethod(java_object.obj(),
1170  data_array.obj());
1171  }
1172 
1174 }
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34
static jmethodID g_handle_platform_message_response_method

◆ FlutterViewOnDisplayPlatformView()

void flutter::PlatformViewAndroidJNIImpl::FlutterViewOnDisplayPlatformView ( int  view_id,
int  x,
int  y,
int  width,
int  height,
int  viewWidth,
int  viewHeight,
MutatorsStack  mutators_stack 
)
overridevirtual

Positions and sizes a platform view if using hybrid composition.

Note
Must be called from the platform thread.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1363 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), flutter::MutatorsStack::Begin(), fml::jni::CheckException(), flutter::clip_path, flutter::clip_rect, flutter::clip_rrect, flutter::MutatorsStack::End(), FML_CHECK, flutter::g_mutators_stack_init_method, flutter::g_on_display_platform_view_method, fml::jni::JavaObjectWeakGlobalRef::get(), height, fml::jni::JavaRef< T >::obj(), flutter::opacity, flutter::transform, and width.

1371  {
1372  JNIEnv* env = fml::jni::AttachCurrentThread();
1373  auto java_object = java_object_.get(env);
1374  if (java_object.is_null()) {
1375  return;
1376  }
1377 
1378  jobject mutatorsStack = env->NewObject(g_mutators_stack_class->obj(),
1380 
1381  std::vector<std::shared_ptr<Mutator>>::const_iterator iter =
1382  mutators_stack.Begin();
1383  while (iter != mutators_stack.End()) {
1384  switch ((*iter)->GetType()) {
1385  case transform: {
1386  const SkMatrix& matrix = (*iter)->GetMatrix();
1387  SkScalar matrix_array[9];
1388  matrix.get9(matrix_array);
1390  env, env->NewFloatArray(9));
1391 
1392  env->SetFloatArrayRegion(transformMatrix.obj(), 0, 9, matrix_array);
1393  env->CallVoidMethod(mutatorsStack,
1395  transformMatrix.obj());
1396  break;
1397  }
1398  case clip_rect: {
1399  const SkRect& rect = (*iter)->GetRect();
1400  env->CallVoidMethod(
1402  static_cast<int>(rect.left()), static_cast<int>(rect.top()),
1403  static_cast<int>(rect.right()), static_cast<int>(rect.bottom()));
1404  break;
1405  }
1406  case clip_rrect: {
1407  const SkRRect& rrect = (*iter)->GetRRect();
1408  const SkRect& rect = rrect.rect();
1409  const SkVector& upper_left = rrect.radii(SkRRect::kUpperLeft_Corner);
1410  const SkVector& upper_right = rrect.radii(SkRRect::kUpperRight_Corner);
1411  const SkVector& lower_right = rrect.radii(SkRRect::kLowerRight_Corner);
1412  const SkVector& lower_left = rrect.radii(SkRRect::kLowerLeft_Corner);
1413  SkScalar radiis[8] = {
1414  upper_left.x(), upper_left.y(), upper_right.x(), upper_right.y(),
1415  lower_right.x(), lower_right.y(), lower_left.x(), lower_left.y(),
1416  };
1418  env, env->NewFloatArray(8));
1419  env->SetFloatArrayRegion(radiisArray.obj(), 0, 8, radiis);
1420  env->CallVoidMethod(
1422  (int)rect.left(), (int)rect.top(), (int)rect.right(),
1423  (int)rect.bottom(), radiisArray.obj());
1424  break;
1425  }
1426  // TODO(cyanglaz): Implement other mutators.
1427  // https://github.com/flutter/flutter/issues/58426
1428  case clip_path:
1429  case opacity:
1430  break;
1431  }
1432  ++iter;
1433  }
1434 
1435  env->CallVoidMethod(java_object.obj(), g_on_display_platform_view_method,
1436  view_id, x, y, width, height, viewWidth, viewHeight,
1437  mutatorsStack);
1438 
1440 }
static fml::jni::ScopedJavaGlobalRef< jclass > * g_mutators_stack_class
static jmethodID g_mutators_stack_push_cliprrect_method
static jmethodID g_mutators_stack_push_cliprect_method
static jmethodID g_mutators_stack_init_method
static jmethodID g_mutators_stack_push_transform_method
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
static jmethodID g_on_display_platform_view_method
int32_t width
int32_t height
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ FlutterViewOnFirstFrame()

void flutter::PlatformViewAndroidJNIImpl::FlutterViewOnFirstFrame ( )
overridevirtual

Indicates that FlutterView should start painting pixels.

Note
Must be called from the platform thread.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1225 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_on_first_frame_method, and fml::jni::JavaObjectWeakGlobalRef::get().

1225  {
1226  JNIEnv* env = fml::jni::AttachCurrentThread();
1227 
1228  auto java_object = java_object_.get(env);
1229  if (java_object.is_null()) {
1230  return;
1231  }
1232 
1233  env->CallVoidMethod(java_object.obj(), g_on_first_frame_method);
1234 
1236 }
static jmethodID g_on_first_frame_method
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ FlutterViewOnPreEngineRestart()

void flutter::PlatformViewAndroidJNIImpl::FlutterViewOnPreEngineRestart ( )
overridevirtual

Indicates that a hot restart is about to happen.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1238 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_on_engine_restart_method, and fml::jni::JavaObjectWeakGlobalRef::get().

1238  {
1239  JNIEnv* env = fml::jni::AttachCurrentThread();
1240 
1241  auto java_object = java_object_.get(env);
1242  if (java_object.is_null()) {
1243  return;
1244  }
1245 
1246  env->CallVoidMethod(java_object.obj(), g_on_engine_restart_method);
1247 
1249 }
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
static jmethodID g_on_engine_restart_method
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ FlutterViewUpdateCustomAccessibilityActions()

void flutter::PlatformViewAndroidJNIImpl::FlutterViewUpdateCustomAccessibilityActions ( std::vector< uint8_t >  actions_buffer,
std::vector< std::string >  strings 
)
overridevirtual

Sends new custom accessibility events.

Note
Must be called from the platform thread.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1201 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_update_custom_accessibility_actions_method, fml::jni::JavaObjectWeakGlobalRef::get(), fml::jni::JavaRef< T >::obj(), and fml::jni::VectorToStringArray().

1203  {
1204  JNIEnv* env = fml::jni::AttachCurrentThread();
1205 
1206  auto java_object = java_object_.get(env);
1207  if (java_object.is_null()) {
1208  return;
1209  }
1210 
1211  fml::jni::ScopedJavaLocalRef<jobject> direct_actions_buffer(
1212  env,
1213  env->NewDirectByteBuffer(actions_buffer.data(), actions_buffer.size()));
1214 
1216  fml::jni::VectorToStringArray(env, strings);
1217 
1218  env->CallVoidMethod(java_object.obj(),
1220  direct_actions_buffer.obj(), jstrings.obj());
1221 
1223 }
ScopedJavaLocalRef< jobjectArray > VectorToStringArray(JNIEnv *env, const std::vector< std::string > &vector)
Definition: jni_util.cc:128
static jmethodID g_update_custom_accessibility_actions_method
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ FlutterViewUpdateSemantics()

void flutter::PlatformViewAndroidJNIImpl::FlutterViewUpdateSemantics ( std::vector< uint8_t >  buffer,
std::vector< std::string >  strings,
std::vector< std::vector< uint8_t >>  string_attribute_args 
)
overridevirtual

Sends semantics tree updates.

Note
Must be called from the platform thread.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1176 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_update_semantics_method, fml::jni::JavaObjectWeakGlobalRef::get(), fml::jni::JavaRef< T >::obj(), fml::jni::VectorToBufferArray(), and fml::jni::VectorToStringArray().

1179  {
1180  JNIEnv* env = fml::jni::AttachCurrentThread();
1181 
1182  auto java_object = java_object_.get(env);
1183  if (java_object.is_null()) {
1184  return;
1185  }
1186 
1188  env, env->NewDirectByteBuffer(buffer.data(), buffer.size()));
1190  fml::jni::VectorToStringArray(env, strings);
1191  fml::jni::ScopedJavaLocalRef<jobjectArray> jstring_attribute_args =
1192  fml::jni::VectorToBufferArray(env, string_attribute_args);
1193 
1194  env->CallVoidMethod(java_object.obj(), g_update_semantics_method,
1195  direct_buffer.obj(), jstrings.obj(),
1196  jstring_attribute_args.obj());
1197 
1199 }
ScopedJavaLocalRef< jobjectArray > VectorToStringArray(JNIEnv *env, const std::vector< std::string > &vector)
Definition: jni_util.cc:128
ScopedJavaLocalRef< jobjectArray > VectorToBufferArray(JNIEnv *env, const std::vector< std::vector< uint8_t >> &vector)
Definition: jni_util.cc:145
static jmethodID g_update_semantics_method
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
static const uint8_t buffer[]
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ GetDisplayRefreshRate()

double flutter::PlatformViewAndroidJNIImpl::GetDisplayRefreshRate ( )
overridevirtual

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1560 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::JavaObjectWeakGlobalRef::get(), and flutter::kUnknownDisplayRefreshRate.

1560  {
1561  JNIEnv* env = fml::jni::AttachCurrentThread();
1562 
1563  auto java_object = java_object_.get(env);
1564  if (java_object.is_null()) {
1566  }
1567 
1568  jclass clazz = env->GetObjectClass(java_object.obj());
1569  if (clazz == nullptr) {
1571  }
1572 
1573  jfieldID fid = env->GetStaticFieldID(clazz, "refreshRateFPS", "F");
1574  return static_cast<double>(env->GetStaticFloatField(clazz, fid));
1575 }
static constexpr double kUnknownDisplayRefreshRate
To be used when the display refresh rate is unknown.
Definition: display.h:17
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ RequestDartDeferredLibrary()

bool flutter::PlatformViewAndroidJNIImpl::RequestDartDeferredLibrary ( int  loading_unit_id)
overridevirtual

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1577 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_request_dart_deferred_library_method, and fml::jni::JavaObjectWeakGlobalRef::get().

1578  {
1579  JNIEnv* env = fml::jni::AttachCurrentThread();
1580 
1581  auto java_object = java_object_.get(env);
1582  if (java_object.is_null()) {
1583  return true;
1584  }
1585 
1586  env->CallVoidMethod(java_object.obj(), g_request_dart_deferred_library_method,
1587  loading_unit_id);
1588 
1590  return true;
1591 }
static jmethodID g_request_dart_deferred_library_method
ScopedJavaLocalRef< jobject > get(JNIEnv *env) const
Definition: jni_weak_ref.cc:41
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ SurfaceTextureAttachToGLContext()

void flutter::PlatformViewAndroidJNIImpl::SurfaceTextureAttachToGLContext ( JavaLocalRef  surface_texture,
int  textureId 
)
overridevirtual

Attach the SurfaceTexture to the OpenGL ES context that is current on the calling thread.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1251 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_attach_to_gl_context_method, flutter::g_java_weak_reference_get_method, and fml::jni::JavaRef< T >::obj().

1253  {
1254  JNIEnv* env = fml::jni::AttachCurrentThread();
1255 
1256  if (surface_texture.is_null()) {
1257  return;
1258  }
1259 
1260  fml::jni::ScopedJavaLocalRef<jobject> surface_texture_local_ref(
1261  env, env->CallObjectMethod(surface_texture.obj(),
1263 
1264  if (surface_texture_local_ref.is_null()) {
1265  return;
1266  }
1267 
1268  env->CallVoidMethod(surface_texture_local_ref.obj(),
1269  g_attach_to_gl_context_method, textureId);
1270 
1272 }
static jmethodID g_java_weak_reference_get_method
static jmethodID g_attach_to_gl_context_method
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ SurfaceTextureDetachFromGLContext()

void flutter::PlatformViewAndroidJNIImpl::SurfaceTextureDetachFromGLContext ( JavaLocalRef  surface_texture)
overridevirtual

Detaches a SurfaceTexture from the OpenGL ES context.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1342 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_detach_from_gl_context_method, flutter::g_java_weak_reference_get_method, and fml::jni::JavaRef< T >::obj().

1343  {
1344  JNIEnv* env = fml::jni::AttachCurrentThread();
1345 
1346  if (surface_texture.is_null()) {
1347  return;
1348  }
1349 
1350  fml::jni::ScopedJavaLocalRef<jobject> surface_texture_local_ref(
1351  env, env->CallObjectMethod(surface_texture.obj(),
1353  if (surface_texture_local_ref.is_null()) {
1354  return;
1355  }
1356 
1357  env->CallVoidMethod(surface_texture_local_ref.obj(),
1359 
1361 }
static jmethodID g_java_weak_reference_get_method
static jmethodID g_detach_from_gl_context_method
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ SurfaceTextureGetTransformMatrix()

void flutter::PlatformViewAndroidJNIImpl::SurfaceTextureGetTransformMatrix ( JavaLocalRef  surface_texture,
SkMatrix &  transform 
)
overridevirtual

Gets the transform matrix from the SurfaceTexture. Then, it updates the transform matrix, so it fill the canvas and preserve the aspect ratio.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1307 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_get_transform_matrix_method, flutter::g_java_weak_reference_get_method, fml::jni::JavaRef< T >::obj(), and flutter::ScaleToFill().

1309  {
1310  JNIEnv* env = fml::jni::AttachCurrentThread();
1311 
1312  if (surface_texture.is_null()) {
1313  return;
1314  }
1315 
1316  fml::jni::ScopedJavaLocalRef<jobject> surface_texture_local_ref(
1317  env, env->CallObjectMethod(surface_texture.obj(),
1319  if (surface_texture_local_ref.is_null()) {
1320  return;
1321  }
1322 
1324  env, env->NewFloatArray(16));
1325 
1326  env->CallVoidMethod(surface_texture_local_ref.obj(),
1327  g_get_transform_matrix_method, transformMatrix.obj());
1329 
1330  float* m = env->GetFloatArrayElements(transformMatrix.obj(), nullptr);
1331  float scaleX = m[0], scaleY = m[5];
1332  const SkSize scaled = ScaleToFill(scaleX, scaleY);
1333  SkScalar matrix3[] = {
1334  scaled.fWidth, m[1], m[2], //
1335  m[4], scaled.fHeight, m[6], //
1336  m[8], m[9], m[10], //
1337  };
1338  env->ReleaseFloatArrayElements(transformMatrix.obj(), m, JNI_ABORT);
1339  transform.set9(matrix3);
1340 }
static jmethodID g_get_transform_matrix_method
static jmethodID g_java_weak_reference_get_method
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
SkSize ScaleToFill(float scaleX, float scaleY)
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

◆ SurfaceTextureUpdateTexImage()

void flutter::PlatformViewAndroidJNIImpl::SurfaceTextureUpdateTexImage ( JavaLocalRef  surface_texture)
overridevirtual

Updates the texture image to the most recent frame from the image stream.

Implements flutter::PlatformViewAndroidJNI.

Definition at line 1274 of file platform_view_android_jni_impl.cc.

References fml::jni::AttachCurrentThread(), fml::jni::CheckException(), FML_CHECK, flutter::g_java_weak_reference_get_method, flutter::g_update_tex_image_method, and fml::jni::JavaRef< T >::obj().

1275  {
1276  JNIEnv* env = fml::jni::AttachCurrentThread();
1277 
1278  if (surface_texture.is_null()) {
1279  return;
1280  }
1281 
1282  fml::jni::ScopedJavaLocalRef<jobject> surface_texture_local_ref(
1283  env, env->CallObjectMethod(surface_texture.obj(),
1285  if (surface_texture_local_ref.is_null()) {
1286  return;
1287  }
1288 
1289  env->CallVoidMethod(surface_texture_local_ref.obj(),
1291 
1293 }
static jmethodID g_java_weak_reference_get_method
static jmethodID g_update_tex_image_method
bool CheckException(JNIEnv *env)
Definition: jni_util.cc:176
#define FML_CHECK(condition)
Definition: logging.h:68
JNIEnv * AttachCurrentThread()
Definition: jni_util.cc:34

The documentation for this class was generated from the following files: