From 33287e8a893821be86b395ce9d5d639cc8a535f3 Mon Sep 17 00:00:00 2001 From: Miao Wang Date: Mon, 6 Mar 2017 09:31:32 -0800 Subject: [PATCH 1/2] [RenderScript] Use ANativeWindow_fromSurface to get ANativeWindow from Java Surface. - ANativeWindow_fromSurface and ANativeWindow_release has to be used in pairs to avoid leaks. Bug: 34396220 Test: mm, CTS tests pass. Change-Id: Id67fd005a056df4d496a48f705d445a2d8c45232 --- rs/jni/Android.mk | 1 + rs/jni/android_renderscript_RenderScript.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rs/jni/Android.mk b/rs/jni/Android.mk index 447a47d3c56e0..4040db36c4fb7 100644 --- a/rs/jni/Android.mk +++ b/rs/jni/Android.mk @@ -5,6 +5,7 @@ LOCAL_SRC_FILES:= \ android_renderscript_RenderScript.cpp LOCAL_SHARED_LIBRARIES := \ + libandroid \ libandroid_runtime \ libandroidfw \ libnativehelper \ diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp index 2300da32d355a..c663255d33157 100644 --- a/rs/jni/android_renderscript_RenderScript.cpp +++ b/rs/jni/android_renderscript_RenderScript.cpp @@ -34,6 +34,8 @@ #include "android_runtime/android_view_Surface.h" #include "android_runtime/android_util_AssetManager.h" #include "android/graphics/GraphicsJNI.h" +#include "android/native_window.h" +#include "android/native_window_jni.h" #include #include @@ -1281,13 +1283,12 @@ nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobje (RsAllocation)alloc, (Surface *)sur); } - sp s; + ANativeWindow *anw = nullptr; if (sur != 0) { - s = android_view_Surface_getSurface(_env, sur); + anw = ANativeWindow_fromSurface(_env, sur); } - rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc, - static_cast(s.get())); + rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc, anw); } static void From 1e95fc86581514c718fc96367f6d575e87fecffb Mon Sep 17 00:00:00 2001 From: Miao Wang Date: Sat, 4 Mar 2017 16:28:56 -0800 Subject: [PATCH 2/2] [RenderScript] Update RenderScript JNI with the corresponding AllocationGetSurface driver implementation change. - AllocationGetSurface now returns opaque handle to ANativeWindow*, instead of IGraphicBufferProducer*, as IGraphicBufferProducer is not part of NDK. So the JNI side need to change accordingly. Bug: 34396220 Test: mm, CTS tests pass. Change-Id: If9b6a733202d29bc40c0e0b87c4fb48db092cbe5 --- rs/jni/android_renderscript_RenderScript.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp index c663255d33157..b4630efe80e89 100644 --- a/rs/jni/android_renderscript_RenderScript.cpp +++ b/rs/jni/android_renderscript_RenderScript.cpp @@ -1266,10 +1266,10 @@ nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a) ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); } - IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con, - (RsAllocation)a); - sp bp = v; - v->decStrong(nullptr); + ANativeWindow *anw = (ANativeWindow *)rsAllocationGetSurface((RsContext)con, (RsAllocation)a); + + sp surface(static_cast(anw)); + sp bp = surface->getIGraphicBufferProducer(); jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp); return o;