Alexandre Julliard : wineandroid: Add helper functions to encapsulate gralloc functionality.
Alexandre Julliard
julliard at winehq.org
Mon Nov 19 15:59:38 CST 2018
Module: wine
Branch: master
Commit: 18ac6bf41a640449161cae4f8371aeda169fb4bb
URL: https://source.winehq.org/git/wine.git/?a=commit;h=18ac6bf41a640449161cae4f8371aeda169fb4bb
Author: Alexandre Julliard <julliard at winehq.org>
Date: Mon Nov 19 16:06:51 2018 +0100
wineandroid: Add helper functions to encapsulate gralloc functionality.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/wineandroid.drv/android.h | 3 +-
dlls/wineandroid.drv/device.c | 72 +++++++++++++++++++++++++++++-------------
dlls/wineandroid.drv/init.c | 14 ++++----
3 files changed, 59 insertions(+), 30 deletions(-)
diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h
index 2a9ac81..b218a9b 100644
--- a/dlls/wineandroid.drv/android.h
+++ b/dlls/wineandroid.drv/android.h
@@ -88,6 +88,7 @@ enum android_window_messages
WM_ANDROID_REFRESH = 0x80001000,
};
+extern void init_gralloc( const struct hw_module_t *module ) DECLSPEC_HIDDEN;
extern HWND get_capture_window(void) DECLSPEC_HIDDEN;
extern void init_monitors( int width, int height ) DECLSPEC_HIDDEN;
extern void set_screen_dpi( DWORD dpi ) DECLSPEC_HIDDEN;
@@ -155,6 +156,4 @@ int send_event( const union event_data *data );
extern JavaVM *wine_get_java_vm(void);
extern jobject wine_get_java_object(void);
-extern struct gralloc_module_t *gralloc_module;
-
#endif /* __WINE_ANDROID_H */
diff --git a/dlls/wineandroid.drv/device.c b/dlls/wineandroid.drv/device.c
index 328f2fa..a6f2838 100644
--- a/dlls/wineandroid.drv/device.c
+++ b/dlls/wineandroid.drv/device.c
@@ -212,6 +212,8 @@ struct ioctl_android_set_capture
struct ioctl_header hdr;
};
+static struct gralloc_module_t *gralloc_module;
+
static inline BOOL is_in_desktop_process(void)
{
return thread != NULL;
@@ -496,6 +498,44 @@ void register_native_window( HWND hwnd, struct ANativeWindow *win, BOOL opengl )
NtQueueApcThread( thread, register_native_window_callback, (ULONG_PTR)hwnd, (ULONG_PTR)win, opengl );
}
+void init_gralloc( const struct hw_module_t *module )
+{
+ TRACE( "got module %p ver %u.%u id %s name %s author %s\n",
+ module, module->module_api_version >> 8, module->module_api_version & 0xff,
+ debugstr_a(module->id), debugstr_a(module->name), debugstr_a(module->author) );
+
+ gralloc_module = (struct gralloc_module_t *)module;
+}
+
+static int gralloc_grab_buffer( struct ANativeWindowBuffer *buffer )
+{
+ if (gralloc_module)
+ return gralloc_module->registerBuffer( gralloc_module, buffer->handle );
+ return -ENODEV;
+}
+
+static void gralloc_release_buffer( struct ANativeWindowBuffer *buffer )
+{
+ if (gralloc_module) gralloc_module->unregisterBuffer( gralloc_module, buffer->handle );
+ close_native_handle( (native_handle_t *)buffer->handle );
+}
+
+static int gralloc_lock( struct ANativeWindowBuffer *buffer, void **bits )
+{
+ if (gralloc_module)
+ return gralloc_module->lock( gralloc_module, buffer->handle,
+ GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
+ 0, 0, buffer->width, buffer->height, bits );
+
+ *bits = ((struct native_buffer_wrapper *)buffer)->bits;
+ return 0;
+}
+
+static void gralloc_unlock( struct ANativeWindowBuffer *buffer )
+{
+ if (gralloc_module) gralloc_module->unlock( gralloc_module, buffer->handle );
+}
+
/* get the capture window stored in the desktop process */
HWND get_capture_window(void)
{
@@ -740,12 +780,10 @@ static NTSTATUS queueBuffer_ioctl( void *data, DWORD in_size, DWORD out_size, UL
if (win_data->mappings[res->buffer_id])
{
void *bits;
- int ret = gralloc_module->lock( gralloc_module, buffer->handle,
- GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
- 0, 0, buffer->width, buffer->height, &bits );
+ ret = gralloc_lock( buffer, &bits );
if (ret) return android_error_to_status( ret );
memcpy( bits, win_data->mappings[res->buffer_id], buffer->stride * buffer->height * 4 );
- gralloc_module->unlock( gralloc_module, buffer->handle );
+ gralloc_unlock( buffer );
}
wrap_java_call();
ret = parent->queueBuffer( parent, buffer, -1 );
@@ -1084,11 +1122,7 @@ static void buffer_decRef( struct android_native_base_t *base )
if (!InterlockedDecrement( &buffer->ref ))
{
- if (!is_in_desktop_process())
- {
- if (gralloc_module) gralloc_module->unregisterBuffer( gralloc_module, buffer->buffer.handle );
- close_native_handle( (native_handle_t *)buffer->buffer.handle );
- }
+ if (!is_in_desktop_process()) gralloc_release_buffer( &buffer->buffer );
if (buffer->bits) UnmapViewOfFile( buffer->bits );
HeapFree( GetProcessHeap(), 0, buffer );
}
@@ -1140,8 +1174,9 @@ static int dequeueBuffer( struct ANativeWindow *window, struct ANativeWindowBuff
}
else if (!is_in_desktop_process())
{
- if ((ret = gralloc_module->registerBuffer( gralloc_module, buf->buffer.handle )) < 0)
- WARN( "hwnd %p, buffer %p failed to register %d %s\n", win->hwnd, &buf->buffer, ret, strerror(-ret) );
+ if ((ret = gralloc_grab_buffer( &buf->buffer )) < 0)
+ WARN( "hwnd %p, buffer %p failed to register %d %s\n",
+ win->hwnd, &buf->buffer, ret, strerror(-ret) );
}
}
@@ -1313,18 +1348,11 @@ static int perform( ANativeWindow *window, int operation, ... )
int ret = window->dequeueBuffer_DEPRECATED( window, &buffer );
if (!ret)
{
- if (gralloc_module)
+ if ((ret = gralloc_lock( buffer, &buffer_ret->bits )))
{
- if ((ret = gralloc_module->lock( gralloc_module, buffer->handle,
- GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
- 0, 0, buffer->width, buffer->height, &buffer_ret->bits )))
- {
- WARN( "gralloc->lock %p failed %d %s\n", win->hwnd, ret, strerror(-ret) );
- window->cancelBuffer( window, buffer, -1 );
- }
+ WARN( "gralloc->lock %p failed %d %s\n", win->hwnd, ret, strerror(-ret) );
+ window->cancelBuffer( window, buffer, -1 );
}
- else
- buffer_ret->bits = ((struct native_buffer_wrapper *)buffer)->bits;
}
if (!ret)
{
@@ -1350,7 +1378,7 @@ static int perform( ANativeWindow *window, int operation, ... )
int ret = -EINVAL;
if (win->locked_buffer)
{
- if (gralloc_module) gralloc_module->unlock( gralloc_module, win->locked_buffer->handle );
+ gralloc_unlock( win->locked_buffer );
ret = window->queueBuffer( window, win->locked_buffer, -1 );
win->locked_buffer = NULL;
}
diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c
index d199696..b5c85ee 100644
--- a/dlls/wineandroid.drv/init.c
+++ b/dlls/wineandroid.drv/init.c
@@ -450,8 +450,6 @@ DECL_FUNCPTR( ANativeWindow_fromSurface );
DECL_FUNCPTR( ANativeWindow_release );
DECL_FUNCPTR( hw_get_module );
-struct gralloc_module_t *gralloc_module = NULL;
-
#ifndef DT_GNU_HASH
#define DT_GNU_HASH 0x6ffffef5
#endif
@@ -564,6 +562,7 @@ static int enum_libs( struct dl_phdr_info* info, size_t size, void* data )
static void load_hardware_libs(void)
{
const struct hw_module_t *module;
+ int ret;
void *libhardware;
char error[256];
@@ -589,10 +588,13 @@ static void load_hardware_libs(void)
}
}
- if (phw_get_module( GRALLOC_HARDWARE_MODULE_ID, &module ) == 0)
- gralloc_module = (struct gralloc_module_t *)module;
- else
- ERR( "failed to load gralloc module\n" );
+ if ((ret = phw_get_module( GRALLOC_HARDWARE_MODULE_ID, &module )))
+ {
+ ERR( "failed to load gralloc module err %d\n", ret );
+ return;
+ }
+
+ init_gralloc( module );
}
static void load_android_libs(void)
More information about the wine-cvs
mailing list