[vlc-devel] [PATCH 6/8] nativewindowpriv: use only one call to lock/unlock sw buffers

Thomas Guillem thomas at gllm.fr
Thu Nov 20 13:16:42 CET 2014


---
 modules/video_output/android/android_window.c   | 19 ++++++-------------
 modules/video_output/android/nativewindowpriv.c | 21 +++++++++++++++++----
 modules/video_output/android/utils.h            |  4 ++--
 3 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/modules/video_output/android/android_window.c b/modules/video_output/android/android_window.c
index d2ac522..81eafab 100644
--- a/modules/video_output/android/android_window.c
+++ b/modules/video_output/android/android_window.c
@@ -470,20 +470,15 @@ static void AndroidWindow_UnlockPicture(vout_display_sys_t *sys,
     picture_sys_t *p_picsys = p_pic->p_sys;
 
     if (p_window->b_use_priv) {
-        int err = 0;
         void *p_handle = p_picsys->priv.sw.p_handle;
 
         if (p_handle == NULL)
             return;
 
-        err = sys->anwp.unlockData(p_window->p_handle_priv, p_handle);
+        sys->anwp.unlockData(p_window->p_handle_priv, p_handle,
+                             p_picsys->b_render);
+
 
-        if (err == 0) {
-            if (p_picsys->b_render)
-                err = sys->anwp.queue(p_window->p_handle_priv, p_handle);
-            else
-                err = sys->anwp.cancel(p_window->p_handle_priv, p_handle);
-        }
     } else
         sys->anw.unlockAndPost(p_window->p_handle);
 }
@@ -498,11 +493,9 @@ static int AndroidWindow_LockPicture(vout_display_sys_t *sys,
         void *p_handle;
         int err;
 
-        err = sys->anwp.dequeue(p_window->p_handle_priv, &p_handle);
-        err = err == 0 ? sys->anwp.lock(p_window->p_handle_priv, p_handle) : err;
-        err = err == 0 ? sys->anwp.lockData(p_window->p_handle_priv,
-                                            p_handle,
-                                            &p_picsys->priv.sw.buf) : err;
+        err = sys->anwp.lockData(p_window->p_handle_priv,
+                                 &p_handle,
+                                 &p_picsys->priv.sw.buf);
         if (err != 0)
             return -1;
         p_picsys->priv.sw.p_handle = p_handle;
diff --git a/modules/video_output/android/nativewindowpriv.c b/modules/video_output/android/nativewindowpriv.c
index 626f117..0557fcf 100644
--- a/modules/video_output/android/nativewindowpriv.c
+++ b/modules/video_output/android/nativewindowpriv.c
@@ -291,15 +291,22 @@ int ANativeWindowPriv_cancel( native_window_priv *priv, void *p_handle )
     return 0;
 }
 
-int ANativeWindowPriv_lockData( native_window_priv *priv, void *p_handle,
+int ANativeWindowPriv_lockData( native_window_priv *priv, void **pp_handle,
                                 ANativeWindow_Buffer *p_out_anb )
 {
-    ANativeWindowBuffer_t *anb = (ANativeWindowBuffer_t *)p_handle;
+    ANativeWindowBuffer_t *anb;
     status_t err = NO_ERROR;
     void *p_data;
 
+    err = ANativeWindowPriv_dequeue( priv, pp_handle );
+    CHECK_ERR();
+
+    anb = (ANativeWindowBuffer_t *)*pp_handle;
     CHECK_ANB();
 
+    err = ANativeWindowPriv_lock( priv, *pp_handle );
+    CHECK_ERR();
+
     err = priv->gralloc->lock( priv->gralloc, anb->handle, priv->usage,
                                0, 0, anb->width, anb->height, &p_data );
     CHECK_ERR();
@@ -314,16 +321,22 @@ int ANativeWindowPriv_lockData( native_window_priv *priv, void *p_handle,
     return 0;
 }
 
-int ANativeWindowPriv_unlockData( native_window_priv *priv, void *p_handle )
+int ANativeWindowPriv_unlockData( native_window_priv *priv, void *p_handle,
+                                  bool b_render )
 {
     ANativeWindowBuffer_t *anb = (ANativeWindowBuffer_t *)p_handle;
     status_t err = NO_ERROR;
 
     CHECK_ANB();
 
-    err = priv->gralloc->unlock(priv->gralloc, anb->handle);
+    err = priv->gralloc->unlock( priv->gralloc, anb->handle );
     CHECK_ERR();
 
+    if( b_render )
+        ANativeWindowPriv_queue( priv, p_handle );
+    else
+        ANativeWindowPriv_cancel( priv, p_handle );
+
     return 0;
 }
 
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index 7ff1542..96d4f86 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -82,8 +82,8 @@ typedef int (*ptr_ANativeWindowPriv_dequeue) (native_window_priv *, void **);
 typedef int (*ptr_ANativeWindowPriv_lock) (native_window_priv *, void *);
 typedef int (*ptr_ANativeWindowPriv_queue) (native_window_priv *, void *);
 typedef int (*ptr_ANativeWindowPriv_cancel) (native_window_priv *, void *);
-typedef int (*ptr_ANativeWindowPriv_lockData) (native_window_priv *, void *, ANativeWindow_Buffer *);
-typedef int (*ptr_ANativeWindowPriv_unlockData) (native_window_priv *, void *);
+typedef int (*ptr_ANativeWindowPriv_lockData) (native_window_priv *, void **, ANativeWindow_Buffer *);
+typedef int (*ptr_ANativeWindowPriv_unlockData) (native_window_priv *, void *, bool b_render);
 typedef int (*ptr_ANativeWindowPriv_setOrientation) (native_window_priv *, int);
 
 typedef struct
-- 
2.1.1




More information about the vlc-devel mailing list