[vlc-commits] android/utils: AWindowHandler_releaseANativeWindow can clear the surface

Thomas Guillem git at videolan.org
Wed Oct 5 12:16:25 CEST 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Oct  5 11:51:27 2016 +0200| [029ef55a425160c256bb090491d1d3b399517cdf] | committer: Thomas Guillem

android/utils: AWindowHandler_releaseANativeWindow can clear the surface

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=029ef55a425160c256bb090491d1d3b399517cdf
---

 modules/codec/omxil/mediacodec.c              |  3 ++-
 modules/video_output/android/android_window.c |  2 +-
 modules/video_output/android/utils.c          | 26 +++++++++++++++++++++-----
 modules/video_output/android/utils.h          |  2 +-
 4 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index 6f291b6..0a860b7 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -577,7 +577,8 @@ static void StopMediaCodec(decoder_t *p_dec)
 
     p_sys->api->stop(p_sys->api);
     if (p_dec->fmt_in.i_cat == VIDEO_ES && p_sys->u.video.p_awh)
-        AWindowHandler_releaseANativeWindow(p_sys->u.video.p_awh, AWindow_Video);
+        AWindowHandler_releaseANativeWindow(p_sys->u.video.p_awh, AWindow_Video,
+                                            false);
 }
 
 /*****************************************************************************
diff --git a/modules/video_output/android/android_window.c b/modules/video_output/android/android_window.c
index 7f9fd7f..e95df93 100644
--- a/modules/video_output/android/android_window.c
+++ b/modules/video_output/android/android_window.c
@@ -335,7 +335,7 @@ static void AndroidWindow_DisconnectSurface(vout_display_sys_t *sys,
         p_window->p_handle_priv = NULL;
     }
     if (p_window->p_handle) {
-        AWindowHandler_releaseANativeWindow(sys->p_awh, p_window->id);
+        AWindowHandler_releaseANativeWindow(sys->p_awh, p_window->id, false);
         p_window->p_handle = NULL;
     }
 }
diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index 7c0c05a..9b8dd3b 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -504,12 +504,26 @@ AWindowHandler_new(vlc_object_t *p_obj)
 
 static void
 AWindowHandler_releaseANativeWindowEnv(AWindowHandler *p_awh, JNIEnv *p_env,
-                                       enum AWindow_ID id)
+                                       enum AWindow_ID id, bool b_clear)
 {
     assert(id < AWindow_Max);
 
     if (p_awh->views[id].p_anw)
     {
+        if (b_clear && p_awh->anw_api.setBuffersGeometry)
+        {
+            /* Clear the surface by displaying a 1x1 black RGB buffer */
+            ANativeWindow *p_anw = p_awh->views[id].p_anw;
+            p_awh->anw_api.setBuffersGeometry(p_anw, 1, 1,
+                                              WINDOW_FORMAT_RGB_565);
+            ANativeWindow_Buffer buf;
+            if (p_awh->anw_api.winLock(p_anw, &buf, NULL) == 0)
+            {
+                uint16_t *p_bit = buf.bits;
+                p_bit[0] = 0x0000;
+                p_awh->anw_api.unlockAndPost(p_anw);
+            }
+        }
         p_awh->pf_winRelease(p_awh->views[id].p_anw);
         p_awh->views[id].p_anw = NULL;
     }
@@ -530,8 +544,10 @@ AWindowHandler_destroy(AWindowHandler *p_awh)
     {
         if (p_awh->event.b_registered)
             JNI_CALL(CallBooleanMethod, setCallback, (jlong)0LL);
-        AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, AWindow_Video);
-        AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, AWindow_Subtitles);
+        AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, AWindow_Video,
+                                               false);
+        AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, AWindow_Subtitles,
+                                               false);
         (*p_env)->DeleteGlobalRef(p_env, p_awh->jobj);
     }
 
@@ -613,11 +629,11 @@ AWindowHandler_getSurface(AWindowHandler *p_awh, enum AWindow_ID id)
 
 
 void AWindowHandler_releaseANativeWindow(AWindowHandler *p_awh,
-                                         enum AWindow_ID id)
+                                         enum AWindow_ID id, bool b_clear)
 {
     JNIEnv *p_env = AWindowHandler_getEnv(p_awh);
     if (p_env)
-        AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, id);
+        AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, id, b_clear);
 }
 
 static inline AWindowHandler *jlong_AWindowHandler(jlong handle)
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index 5adacd6..6072ac7 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -153,7 +153,7 @@ jobject AWindowHandler_getSurface(AWindowHandler *p_awh, enum AWindow_ID id);
 ANativeWindow *AWindowHandler_getANativeWindow(AWindowHandler *p_awh,
                                                enum AWindow_ID id);
 void AWindowHandler_releaseANativeWindow(AWindowHandler *p_awh,
-                                         enum AWindow_ID id);
+                                         enum AWindow_ID id, bool b_clear);
 /**
  * This function is a fix up of ANativeWindow_setBuffersGeometry that doesn't
  * work before Android ICS. It configures the Surface from the Android



More information about the vlc-commits mailing list