@@ -38,6 +38,7 @@ typedef struct ASurfaceTexture ASurfaceTexture;
38
38
#include < stdint.h>
39
39
40
40
#include < new>
41
+ #include < math/mat4.h>
41
42
42
43
using namespace utils ;
43
44
@@ -73,6 +74,7 @@ JNIEnv* ExternalStreamManagerAndroid::getEnvironmentSlow() noexcept {
73
74
mSurfaceTextureClass_attachToGLContext = env->GetMethodID (SurfaceTextureClass, " attachToGLContext" , " (I)V" );
74
75
mSurfaceTextureClass_detachFromGLContext = env->GetMethodID (SurfaceTextureClass, " detachFromGLContext" , " ()V" );
75
76
mSurfaceTextureClass_getTimestamp = env->GetMethodID (SurfaceTextureClass, " getTimestamp" , " ()J" );
77
+ mSurfaceTextureClass_getTransformMatrix = env->GetMethodID (SurfaceTextureClass, " getTransformMatrix" , " ([F)V" );
76
78
return env;
77
79
}
78
80
@@ -167,4 +169,25 @@ void ExternalStreamManagerAndroid::updateTexImage(Stream* handle, int64_t* times
167
169
}
168
170
}
169
171
172
+ math::mat3f ExternalStreamManagerAndroid::getTransformMatrix (Stream* handle) noexcept {
173
+ EGLStream const * stream = static_cast <EGLStream*>(handle);
174
+ math::mat4f out = math::mat4f ();
175
+ if (__builtin_available (android 28 , *)) {
176
+ ASurfaceTexture_getTransformMatrix (stream->nSurfaceTexture , &out[0 ][0 ]);
177
+ } else {
178
+ JNIEnv* const env = getEnvironment ();
179
+ assert_invariant (env); // we should have called attach() by now
180
+ auto jout = env->NewFloatArray (16 );
181
+ env->CallVoidMethod (stream->jSurfaceTexture , mSurfaceTextureClass_getTransformMatrix , jout);
182
+ env->GetFloatArrayRegion (jout, 0 , 16 , &out[0 ][0 ]);
183
+ env->DeleteLocalRef (jout);
184
+ VirtualMachineEnv::handleException (env);
185
+ }
186
+ return math::mat3f {
187
+ out[0 ][0 ], out[0 ][1 ], out[0 ][3 ],
188
+ out[1 ][0 ], out[1 ][1 ], out[1 ][3 ],
189
+ out[3 ][0 ], out[3 ][1 ], out[3 ][3 ],
190
+ };
191
+ }
192
+
170
193
} // namespace filament::backend
0 commit comments