Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 8d9d48a

Browse files
author
Emmanuel Garcia
committed
Chinmay suggestion
1 parent 19aa4e7 commit 8d9d48a

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

shell/platform/android/jni/platform_view_android_jni.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_JNI_H_
66
#define FLUTTER_SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_JNI_H_
77

8-
#include <any>
8+
#if OS_ANDROID
9+
#include "flutter/fml/platform/android/jni_weak_ref.h"
10+
#endif
911

1012
#include "flutter/fml/macros.h"
1113
#include "flutter/fml/mapping.h"
@@ -15,6 +17,12 @@
1517

1618
namespace flutter {
1719

20+
#if OS_ANDROID
21+
using JavaWeakGlobalRef = fml::jni::JavaObjectWeakGlobalRef;
22+
#else
23+
using JavaWeakGlobalRef = std::nullptr_t;
24+
#endif
25+
1826
//------------------------------------------------------------------------------
1927
/// Allows to call Java code running in the JVM from any thread. However, most
2028
/// methods can only be called from the platform thread as that is where the
@@ -74,35 +82,31 @@ class PlatformViewAndroidJNI {
7482
/// @brief Attach the SurfaceTexture to the OpenGL ES context that is
7583
/// current on the calling thread.
7684
///
77-
/// @note `surface_texture` must be `fml::jni::JavaObjectWeakGlobalRef`
78-
///
79-
virtual void SurfaceTextureAttachToGLContext(std::any surface_texture,
80-
int textureId) = 0;
85+
virtual void SurfaceTextureAttachToGLContext(
86+
JavaWeakGlobalRef surface_texture,
87+
int textureId) = 0;
8188

8289
//----------------------------------------------------------------------------
8390
/// @brief Updates the texture image to the most recent frame from the
8491
/// image stream.
8592
///
86-
/// @note `surface_texture` must be `fml::jni::JavaObjectWeakGlobalRef`
87-
///
88-
virtual void SurfaceTextureUpdateTexImage(std::any surface_texture) = 0;
93+
virtual void SurfaceTextureUpdateTexImage(
94+
JavaWeakGlobalRef surface_texture) = 0;
8995

9096
//----------------------------------------------------------------------------
9197
/// @brief Gets the transform matrix from the SurfaceTexture.
9298
/// Then, it updates the `transform` matrix, so it fill the canvas
9399
/// and preserve the aspect ratio.
94100
///
95-
/// @note `surface_texture` must be `fml::jni::JavaObjectWeakGlobalRef`
96-
///
97-
virtual void SurfaceTextureGetTransformMatrix(std::any surface_texture,
98-
SkMatrix& transform) = 0;
101+
virtual void SurfaceTextureGetTransformMatrix(
102+
JavaWeakGlobalRef surface_texture,
103+
SkMatrix& transform) = 0;
99104

100105
//----------------------------------------------------------------------------
101106
/// @brief Detaches a SurfaceTexture from the OpenGL ES context.
102107
///
103-
/// @note `surface_texture` must be `fml::jni::JavaObjectWeakGlobalRef`
104-
///
105-
virtual void SurfaceTextureDetachFromGLContext(std::any surface_texture) = 0;
108+
virtual void SurfaceTextureDetachFromGLContext(
109+
JavaWeakGlobalRef surface_texture) = 0;
106110

107111
//----------------------------------------------------------------------------
108112
/// @brief Positions and sizes a platform view if using hybrid

shell/platform/android/platform_view_android_jni_impl.cc

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
#define ANDROID_SHELL_HOLDER \
3030
(reinterpret_cast<AndroidShellHolder*>(shell_holder))
3131

32-
#define SURFACE_TEXTURE_LOCAL_REF \
33-
(std::any_cast<fml::jni::JavaObjectWeakGlobalRef>(surface_texture))
34-
3532
namespace flutter {
3633

3734
namespace {
@@ -890,12 +887,12 @@ void PlatformViewAndroidJNIImpl::FlutterViewOnPreEngineRestart() {
890887
}
891888

892889
void PlatformViewAndroidJNIImpl::SurfaceTextureAttachToGLContext(
893-
std::any surface_texture,
890+
JavaWeakGlobalRef surface_texture,
894891
int textureId) {
895892
JNIEnv* env = fml::jni::AttachCurrentThread();
896893

897894
fml::jni::ScopedJavaLocalRef<jobject> surface_texture_local_ref =
898-
SURFACE_TEXTURE_LOCAL_REF.get(env);
895+
surface_texture.get(env);
899896
if (surface_texture_local_ref.is_null()) {
900897
return;
901898
}
@@ -907,11 +904,11 @@ void PlatformViewAndroidJNIImpl::SurfaceTextureAttachToGLContext(
907904
}
908905

909906
void PlatformViewAndroidJNIImpl::SurfaceTextureUpdateTexImage(
910-
std::any surface_texture) {
907+
JavaWeakGlobalRef surface_texture) {
911908
JNIEnv* env = fml::jni::AttachCurrentThread();
912909

913910
fml::jni::ScopedJavaLocalRef<jobject> surface_texture_local_ref =
914-
SURFACE_TEXTURE_LOCAL_REF.get(env);
911+
surface_texture.get(env);
915912
if (surface_texture_local_ref.is_null()) {
916913
return;
917914
}
@@ -935,12 +932,12 @@ SkSize ScaleToFill(float scaleX, float scaleY) {
935932
}
936933

937934
void PlatformViewAndroidJNIImpl::SurfaceTextureGetTransformMatrix(
938-
std::any surface_texture,
935+
JavaWeakGlobalRef surface_texture,
939936
SkMatrix& transform) {
940937
JNIEnv* env = fml::jni::AttachCurrentThread();
941938

942939
fml::jni::ScopedJavaLocalRef<jobject> surface_texture_local_ref =
943-
SURFACE_TEXTURE_LOCAL_REF.get(env);
940+
surface_texture.get(env);
944941
if (surface_texture_local_ref.is_null()) {
945942
return;
946943
}
@@ -965,11 +962,11 @@ void PlatformViewAndroidJNIImpl::SurfaceTextureGetTransformMatrix(
965962
}
966963

967964
void PlatformViewAndroidJNIImpl::SurfaceTextureDetachFromGLContext(
968-
std::any surface_texture) {
965+
JavaWeakGlobalRef surface_texture) {
969966
JNIEnv* env = fml::jni::AttachCurrentThread();
970967

971968
fml::jni::ScopedJavaLocalRef<jobject> surface_texture_local_ref =
972-
SURFACE_TEXTURE_LOCAL_REF.get(env);
969+
surface_texture.get(env);
973970
if (surface_texture_local_ref.is_null()) {
974971
return;
975972
}

shell/platform/android/platform_view_android_jni_impl.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@ class PlatformViewAndroidJNIImpl final : public PlatformViewAndroidJNI {
3939

4040
void FlutterViewOnPreEngineRestart() override;
4141

42-
void SurfaceTextureAttachToGLContext(std::any surface_texture,
42+
void SurfaceTextureAttachToGLContext(JavaWeakGlobalRef surface_texture,
4343
int textureId) override;
4444

45-
void SurfaceTextureUpdateTexImage(std::any surface_texture) override;
45+
void SurfaceTextureUpdateTexImage(JavaWeakGlobalRef surface_texture) override;
4646

47-
void SurfaceTextureGetTransformMatrix(std::any surface_texture,
47+
void SurfaceTextureGetTransformMatrix(JavaWeakGlobalRef surface_texture,
4848
SkMatrix& transform) override;
4949

50-
void SurfaceTextureDetachFromGLContext(std::any surface_texture) override;
50+
void SurfaceTextureDetachFromGLContext(
51+
JavaWeakGlobalRef surface_texture) override;
5152

5253
void FlutterViewOnDisplayPlatformView(int view_id,
5354
int x,

0 commit comments

Comments
 (0)