diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index 8a7d1cf9c12fd..bde913487e8af 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -101,17 +101,7 @@ sp android_view_Surface_getSurface(JNIEnv* env, jobject surfaceObj) { return sur; } -jobject android_view_Surface_createFromIGraphicBufferProducer(JNIEnv* env, - const sp& bufferProducer) { - if (bufferProducer == NULL) { - return NULL; - } - - sp surface(new Surface(bufferProducer, true)); - if (surface == NULL) { - return NULL; - } - +jobject android_view_Surface_createFromSurface(JNIEnv* env, const sp& surface) { jobject surfaceObj = env->NewObject(gSurfaceClassInfo.clazz, gSurfaceClassInfo.ctor, (jlong)surface.get()); if (surfaceObj == NULL) { @@ -126,6 +116,16 @@ jobject android_view_Surface_createFromIGraphicBufferProducer(JNIEnv* env, return surfaceObj; } +jobject android_view_Surface_createFromIGraphicBufferProducer(JNIEnv* env, + const sp& bufferProducer) { + if (bufferProducer == NULL) { + return NULL; + } + + sp surface(new Surface(bufferProducer, true)); + return android_view_Surface_createFromSurface(env, surface); +} + int android_view_Surface_mapPublicFormatToHalFormat(PublicFormat f) { switch(f) { diff --git a/core/jni/include/android_runtime/android_view_Surface.h b/core/jni/include/android_runtime/android_view_Surface.h index d27c5a3546774..36487b3b40b33 100644 --- a/core/jni/include/android_runtime/android_view_Surface.h +++ b/core/jni/include/android_runtime/android_view_Surface.h @@ -70,6 +70,10 @@ extern bool android_view_Surface_isInstanceOf(JNIEnv* env, jobject obj); /* Gets the underlying Surface from a Surface Java object. */ extern sp android_view_Surface_getSurface(JNIEnv* env, jobject surfaceObj); +/* Creates a Surface from an android::Surface. */ +extern jobject android_view_Surface_createFromSurface(JNIEnv* env, + const sp& surface); + /* Creates a Surface from an IGraphicBufferProducer. */ extern jobject android_view_Surface_createFromIGraphicBufferProducer(JNIEnv* env, const sp& bufferProducer); diff --git a/native/android/libandroid.map.txt b/native/android/libandroid.map.txt index c7bed9bc16855..c82a1f6a646ab 100644 --- a/native/android/libandroid.map.txt +++ b/native/android/libandroid.map.txt @@ -153,6 +153,7 @@ LIBANDROID { ANativeWindow_acquire; ANativeWindow_fromSurface; ANativeWindow_fromSurfaceTexture; # introduced-arm=13 introduced-mips=13 introduced-x86=13 + ANativeWindow_toSurface; # introduced=26 ANativeWindow_getFormat; ANativeWindow_getHeight; ANativeWindow_getWidth; diff --git a/native/android/native_window_jni.cpp b/native/android/native_window_jni.cpp index dc3040533974f..859c550db94df 100644 --- a/native/android/native_window_jni.cpp +++ b/native/android/native_window_jni.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -33,3 +34,11 @@ ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface) { } return win.get(); } + +jobject ANativeWindow_toSurface(JNIEnv* env, ANativeWindow* window) { + if (window == NULL) { + return NULL; + } + sp surface = static_cast(window); + return android_view_Surface_createFromSurface(env, surface); +}