Commit 65c6b73a authored by Thomas Guillem's avatar Thomas Guillem Committed by Jean-Baptiste Kempf

nativewindowpriv: add lock/unlock Data

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 46814a09
......@@ -29,6 +29,8 @@
#include <stdlib.h>
#include <stdbool.h>
#include <android/native_window.h>
#if ANDROID_API <= 13
#include <ui/android_native_buffer.h>
#include <ui/egl/android_natives.h>
......@@ -51,6 +53,8 @@ typedef struct native_window_priv native_window_priv;
struct native_window_priv
{
ANativeWindow *anw;
gralloc_module_t const* gralloc;
int usage;
};
#define LOG_TAG "VLC/ANW"
......@@ -76,6 +80,7 @@ struct native_window_priv
native_window_priv *ANativeWindowPriv_connect( void *window )
{
native_window_priv *priv;
hw_module_t const* module;
ANativeWindow *anw = (ANativeWindow *)window;
if( anw->common.magic != ANDROID_NATIVE_WINDOW_MAGIC &&
......@@ -84,6 +89,10 @@ native_window_priv *ANativeWindowPriv_connect( void *window )
return NULL;
}
if ( hw_get_module( GRALLOC_HARDWARE_MODULE_ID,
&module ) != 0 )
return NULL;
#if ANDROID_API >= 14
if (native_window_api_connect( anw, NATIVE_WINDOW_API_MEDIA ) != 0) {
LOGE( "native_window_api_connect FAIL" );
......@@ -100,6 +109,7 @@ native_window_priv *ANativeWindowPriv_connect( void *window )
return NULL;
}
priv->anw = anw;
priv->gralloc = (gralloc_module_t const *) module;
return priv;
}
......@@ -116,21 +126,20 @@ int ANativeWindowPriv_disconnect( native_window_priv *priv )
int ANativeWindowPriv_setup( native_window_priv *priv, int w, int h, int hal_format, bool is_hw, int hw_usage )
{
int usage = 0;
status_t err;
LOGD( "setup: %p, %d, %d, %X, %X\n",
priv->anw, w, h, hal_format, hw_usage );
if (is_hw)
usage = hw_usage | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
priv->usage = hw_usage | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
else
usage= GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_OFTEN;
priv->usage= GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_OFTEN;
#if ANDROID_API >= 11
usage |= GRALLOC_USAGE_EXTERNAL_DISP;
priv->usage |= GRALLOC_USAGE_EXTERNAL_DISP;
#endif
err = native_window_set_usage( priv->anw, usage );
err = native_window_set_usage( priv->anw, priv->usage );
CHECK_ERR();
#if ANDROID_API <= 13
......@@ -224,6 +233,42 @@ int ANativeWindowPriv_lock( native_window_priv *priv, void *p_handle )
return 0;
}
int ANativeWindowPriv_lockData( native_window_priv *priv, void *p_handle,
ANativeWindow_Buffer *p_out_anb )
{
ANativeWindowBuffer_t *anb = (ANativeWindowBuffer_t *)p_handle;
status_t err = NO_ERROR;
void *p_data;
CHECK_ANB();
err = priv->gralloc->lock( priv->gralloc, anb->handle, priv->usage,
0, 0, anb->width, anb->height, &p_data );
CHECK_ERR();
if( p_out_anb ) {
p_out_anb->bits = p_data;
p_out_anb->width = anb->width;
p_out_anb->height = anb->height;
p_out_anb->stride = anb->stride;
p_out_anb->format = anb->format;
}
return 0;
}
int ANativeWindowPriv_unlockData( native_window_priv *priv, void *p_handle )
{
ANativeWindowBuffer_t *anb = (ANativeWindowBuffer_t *)p_handle;
status_t err = NO_ERROR;
CHECK_ANB();
err = priv->gralloc->unlock(priv->gralloc, anb->handle);
CHECK_ERR();
return 0;
}
int ANativeWindowPriv_queue( native_window_priv *priv, void *p_handle )
{
ANativeWindowBuffer_t *anb = (ANativeWindowBuffer_t *)p_handle;
......
......@@ -63,14 +63,16 @@ int LoadNativeWindowPrivAPI(native_window_priv_api_t *native)
native->setCrop = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_setCrop");
native->dequeue = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_dequeue");
native->lock = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_lock");
native->lockData = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_lockData");
native->unlockData = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_unlockData");
native->queue = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_queue");
native->cancel = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_cancel");
native->setOrientation = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_setOrientation");
return native->connect && native->disconnect && native->setup &&
native->getMinUndequeued && native->setBufferCount && native->setCrop &&
native->dequeue && native->lock && native->queue && native->cancel &&
native->setOrientation ? 0 : -1;
native->dequeue && native->lock && native->lockData && native->unlockData &&
native->queue && native->cancel && native->setOrientation ? 0 : -1;
}
extern void jni_getMouseCoordinates(int *, int *, int *, int *);
......
......@@ -60,6 +60,8 @@ typedef int (*ptr_ANativeWindowPriv_setBufferCount) (native_window_priv *, unsig
typedef int (*ptr_ANativeWindowPriv_setCrop) (native_window_priv *, int, int, int, int);
typedef int (*ptr_ANativeWindowPriv_dequeue) (native_window_priv *, void **);
typedef int (*ptr_ANativeWindowPriv_lock) (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_queue) (native_window_priv *, void *);
typedef int (*ptr_ANativeWindowPriv_cancel) (native_window_priv *, void *);
typedef int (*ptr_ANativeWindowPriv_setOrientation) (native_window_priv *, int);
......@@ -74,6 +76,8 @@ typedef struct
ptr_ANativeWindowPriv_setCrop setCrop;
ptr_ANativeWindowPriv_dequeue dequeue;
ptr_ANativeWindowPriv_lock lock;
ptr_ANativeWindowPriv_lockData lockData;
ptr_ANativeWindowPriv_unlockData unlockData;
ptr_ANativeWindowPriv_queue queue;
ptr_ANativeWindowPriv_cancel cancel;
ptr_ANativeWindowPriv_setOrientation setOrientation;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment