From: Rémi Bernon rbernon@codeweavers.com
--- dlls/wineandroid.drv/opengl.c | 117 ++++++++++++---------------------- 1 file changed, 40 insertions(+), 77 deletions(-)
diff --git a/dlls/wineandroid.drv/opengl.c b/dlls/wineandroid.drv/opengl.c index aacb0c6a1fc..e4939267584 100644 --- a/dlls/wineandroid.drv/opengl.c +++ b/dlls/wineandroid.drv/opengl.c @@ -49,22 +49,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(android);
-#define DECL_FUNCPTR(f) typeof(f) * p_##f = NULL -DECL_FUNCPTR( eglCreateContext ); -DECL_FUNCPTR( eglCreateWindowSurface ); -DECL_FUNCPTR( eglCreatePbufferSurface ); -DECL_FUNCPTR( eglDestroyContext ); -DECL_FUNCPTR( eglDestroySurface ); -DECL_FUNCPTR( eglGetConfigAttrib ); -DECL_FUNCPTR( eglGetConfigs ); -DECL_FUNCPTR( eglGetDisplay ); -DECL_FUNCPTR( eglGetProcAddress ); -DECL_FUNCPTR( eglInitialize ); -DECL_FUNCPTR( eglMakeCurrent ); -DECL_FUNCPTR( eglSwapBuffers ); -DECL_FUNCPTR( eglSwapInterval ); -#undef DECL_FUNCPTR - +static const struct opengl_funcs *funcs; static const int egl_client_version = 2;
struct egl_pixel_format @@ -94,7 +79,6 @@ struct gl_drawable int swap_interval; };
-static void *egl_handle; static void *opengl_handle; static struct egl_pixel_format *pixel_formats; static int nb_pixel_formats, nb_onscreen_formats; @@ -116,7 +100,7 @@ static struct gl_drawable *create_gl_drawable( HWND hwnd, HDC hdc, int format ) gl->format = format; gl->window = create_ioctl_window( hwnd, TRUE, 1.0f ); gl->surface = 0; - gl->pbuffer = p_eglCreatePbufferSurface( display, pixel_formats[gl->format - 1].config, attribs ); + gl->pbuffer = funcs->p_eglCreatePbufferSurface( display, pixel_formats[gl->format - 1].config, attribs ); pthread_mutex_lock( &drawable_mutex ); list_add_head( &gl_drawables, &gl->entry ); return gl; @@ -150,8 +134,8 @@ void destroy_gl_drawable( HWND hwnd ) { if (gl->hwnd != hwnd) continue; list_remove( &gl->entry ); - if (gl->surface) p_eglDestroySurface( display, gl->surface ); - if (gl->pbuffer) p_eglDestroySurface( display, gl->pbuffer ); + if (gl->surface) funcs->p_eglDestroySurface( display, gl->surface ); + if (gl->pbuffer) funcs->p_eglDestroySurface( display, gl->pbuffer ); release_ioctl_window( gl->window ); free( gl ); break; @@ -166,7 +150,7 @@ static BOOL refresh_context( struct android_context *ctx ) if (ret) { TRACE( "refreshing hwnd %p context %p surface %p\n", ctx->hwnd, ctx->context, ctx->surface ); - p_eglMakeCurrent( display, ctx->surface, ctx->surface, ctx->context ); + funcs->p_eglMakeCurrent( display, ctx->surface, ctx->surface, ctx->context ); NtUserRedrawWindow( ctx->hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE ); } return ret; @@ -180,7 +164,8 @@ void update_gl_drawable( HWND hwnd ) if ((gl = get_gl_drawable( hwnd, 0 ))) { if (!gl->surface && - (gl->surface = p_eglCreateWindowSurface( display, pixel_formats[gl->format - 1].config, gl->window, NULL ))) + (gl->surface = funcs->p_eglCreateWindowSurface( display, pixel_formats[gl->format - 1].config, + gl->window, NULL ))) { LIST_FOR_EACH_ENTRY( ctx, &gl_contexts, struct android_context, entry ) { @@ -188,7 +173,7 @@ void update_gl_drawable( HWND hwnd ) TRACE( "hwnd %p refreshing %p %scurrent\n", hwnd, ctx, NtCurrentTeb()->glReserved2 == ctx ? "" : "not " ); ctx->surface = gl->surface; if (NtCurrentTeb()->glReserved2 == ctx) - p_eglMakeCurrent( display, ctx->surface, ctx->surface, ctx->context ); + funcs->p_eglMakeCurrent( display, ctx->surface, ctx->surface, ctx->context ); else InterlockedExchange( &ctx->refresh, TRUE ); } @@ -209,7 +194,7 @@ static BOOL android_set_pixel_format( HWND hwnd, int old_format, int new_format, if (internal) { EGLint pf; - p_eglGetConfigAttrib( display, pixel_formats[new_format - 1].config, EGL_NATIVE_VISUAL_ID, &pf ); + funcs->p_eglGetConfigAttrib( display, pixel_formats[new_format - 1].config, EGL_NATIVE_VISUAL_ID, &pf ); gl->window->perform( gl->window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, pf ); gl->format = new_format; } @@ -262,7 +247,7 @@ static BOOL android_context_create( HDC hdc, int format, void *share, const int ctx->config = pixel_formats[format - 1].config; ctx->surface = 0; ctx->refresh = FALSE; - ctx->context = p_eglCreateContext( display, ctx->config, shared_ctx ? shared_ctx->context : EGL_NO_CONTEXT, attribs ); + ctx->context = funcs->p_eglCreateContext( display, ctx->config, shared_ctx ? shared_ctx->context : EGL_NO_CONTEXT, attribs ); TRACE( "%p fmt %d ctx %p\n", hdc, format, ctx->context ); list_add_head( &gl_contexts, &ctx->entry );
@@ -286,19 +271,19 @@ static BOOL android_describe_pixel_format( int format, struct wgl_pixel_format * pfd->iPixelType = PFD_TYPE_RGBA; pfd->iLayerType = PFD_MAIN_PLANE;
- p_eglGetConfigAttrib( display, config, EGL_BUFFER_SIZE, &val ); + funcs->p_eglGetConfigAttrib( display, config, EGL_BUFFER_SIZE, &val ); pfd->cColorBits = val; - p_eglGetConfigAttrib( display, config, EGL_RED_SIZE, &val ); + funcs->p_eglGetConfigAttrib( display, config, EGL_RED_SIZE, &val ); pfd->cRedBits = val; - p_eglGetConfigAttrib( display, config, EGL_GREEN_SIZE, &val ); + funcs->p_eglGetConfigAttrib( display, config, EGL_GREEN_SIZE, &val ); pfd->cGreenBits = val; - p_eglGetConfigAttrib( display, config, EGL_BLUE_SIZE, &val ); + funcs->p_eglGetConfigAttrib( display, config, EGL_BLUE_SIZE, &val ); pfd->cBlueBits = val; - p_eglGetConfigAttrib( display, config, EGL_ALPHA_SIZE, &val ); + funcs->p_eglGetConfigAttrib( display, config, EGL_ALPHA_SIZE, &val ); pfd->cAlphaBits = val; - p_eglGetConfigAttrib( display, config, EGL_DEPTH_SIZE, &val ); + funcs->p_eglGetConfigAttrib( display, config, EGL_DEPTH_SIZE, &val ); pfd->cDepthBits = val; - p_eglGetConfigAttrib( display, config, EGL_STENCIL_SIZE, &val ); + funcs->p_eglGetConfigAttrib( display, config, EGL_STENCIL_SIZE, &val ); pfd->cStencilBits = val;
pfd->cAlphaShift = 0; @@ -320,7 +305,7 @@ static BOOL android_context_make_current( HDC draw_hdc, HDC read_hdc, void *priv
if (!private) { - p_eglMakeCurrent( display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); + funcs->p_eglMakeCurrent( display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); NtCurrentTeb()->glReserved2 = NULL; return TRUE; } @@ -333,7 +318,7 @@ static BOOL android_context_make_current( HDC draw_hdc, HDC read_hdc, void *priv read_surface = read_gl->surface ? read_gl->surface : read_gl->pbuffer; TRACE( "%p/%p context %p surface %p/%p\n", draw_hdc, read_hdc, ctx->context, draw_surface, read_surface ); - ret = p_eglMakeCurrent( display, draw_surface, read_surface, ctx->context ); + ret = funcs->p_eglMakeCurrent( display, draw_surface, read_surface, ctx->context ); if (ret) { ctx->surface = draw_gl->surface; @@ -369,7 +354,7 @@ static BOOL android_context_destroy( void *private ) pthread_mutex_lock( &drawable_mutex ); list_remove( &ctx->entry ); pthread_mutex_unlock( &drawable_mutex ); - p_eglDestroyContext( display, ctx->context ); + funcs->p_eglDestroyContext( display, ctx->context ); free( ctx ); return TRUE; } @@ -378,7 +363,7 @@ static void *android_get_proc_address( const char *name ) { void *ptr; if ((ptr = dlsym( opengl_handle, name ))) return ptr; - return p_eglGetProcAddress( name ); + return funcs->p_eglGetProcAddress( name ); }
static BOOL android_context_share( void *org, void *dest ) @@ -391,7 +376,7 @@ static void set_swap_interval( struct gl_drawable *gl, int interval ) { if (interval < 0) interval = -interval; if (gl->swap_interval == interval) return; - p_eglSwapInterval( display, interval ); + funcs->p_eglSwapInterval( display, interval ); gl->swap_interval = interval; }
@@ -412,7 +397,7 @@ static BOOL android_swap_buffers( void *private, HWND hwnd, HDC hdc, int interva release_gl_drawable( gl ); }
- if (ctx->surface) p_eglSwapBuffers( display, ctx->surface ); + if (ctx->surface) funcs->p_eglSwapBuffers( display, ctx->surface ); return TRUE; }
@@ -450,10 +435,10 @@ static UINT android_init_pixel_formats( UINT *onscreen_count ) EGLConfig *configs; EGLint count, i, pass;
- p_eglGetConfigs( display, NULL, 0, &count ); + funcs->p_eglGetConfigs( display, NULL, 0, &count ); configs = malloc( count * sizeof(*configs) ); pixel_formats = malloc( count * sizeof(*pixel_formats) ); - p_eglGetConfigs( display, configs, count, &count ); + funcs->p_eglGetConfigs( display, configs, count, &count ); if (!count || !configs || !pixel_formats) { free( configs ); @@ -468,22 +453,22 @@ static UINT android_init_pixel_formats( UINT *onscreen_count ) { EGLint id, type, visual_id, native, render, color, r, g, b, d, s;
- p_eglGetConfigAttrib( display, configs[i], EGL_SURFACE_TYPE, &type ); + funcs->p_eglGetConfigAttrib( display, configs[i], EGL_SURFACE_TYPE, &type ); if (!(type & EGL_WINDOW_BIT) == !pass) continue; - p_eglGetConfigAttrib( display, configs[i], EGL_RENDERABLE_TYPE, &render ); + funcs->p_eglGetConfigAttrib( display, configs[i], EGL_RENDERABLE_TYPE, &render ); if (egl_client_version == 2 && !(render & EGL_OPENGL_ES2_BIT)) continue;
pixel_formats[nb_pixel_formats++].config = configs[i];
- p_eglGetConfigAttrib( display, configs[i], EGL_CONFIG_ID, &id ); - p_eglGetConfigAttrib( display, configs[i], EGL_NATIVE_VISUAL_ID, &visual_id ); - p_eglGetConfigAttrib( display, configs[i], EGL_NATIVE_RENDERABLE, &native ); - p_eglGetConfigAttrib( display, configs[i], EGL_COLOR_BUFFER_TYPE, &color ); - p_eglGetConfigAttrib( display, configs[i], EGL_RED_SIZE, &r ); - p_eglGetConfigAttrib( display, configs[i], EGL_GREEN_SIZE, &g ); - p_eglGetConfigAttrib( display, configs[i], EGL_BLUE_SIZE, &b ); - p_eglGetConfigAttrib( display, configs[i], EGL_DEPTH_SIZE, &d ); - p_eglGetConfigAttrib( display, configs[i], EGL_STENCIL_SIZE, &s ); + funcs->p_eglGetConfigAttrib( display, configs[i], EGL_CONFIG_ID, &id ); + funcs->p_eglGetConfigAttrib( display, configs[i], EGL_NATIVE_VISUAL_ID, &visual_id ); + funcs->p_eglGetConfigAttrib( display, configs[i], EGL_NATIVE_RENDERABLE, &native ); + funcs->p_eglGetConfigAttrib( display, configs[i], EGL_COLOR_BUFFER_TYPE, &color ); + funcs->p_eglGetConfigAttrib( display, configs[i], EGL_RED_SIZE, &r ); + funcs->p_eglGetConfigAttrib( display, configs[i], EGL_GREEN_SIZE, &g ); + funcs->p_eglGetConfigAttrib( display, configs[i], EGL_BLUE_SIZE, &b ); + funcs->p_eglGetConfigAttrib( display, configs[i], EGL_DEPTH_SIZE, &d ); + funcs->p_eglGetConfigAttrib( display, configs[i], EGL_STENCIL_SIZE, &s ); TRACE( "%u: config %u id %u type %x visual %u native %u render %x colortype %u rgb %u,%u,%u depth %u stencil %u\n", nb_pixel_formats, i, id, type, visual_id, native, render, color, r, g, b, d, s ); } @@ -522,38 +507,16 @@ UINT ANDROID_OpenGLInit( UINT version, const struct opengl_funcs *opengl_funcs, ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_OPENGL_DRIVER_VERSION ); return STATUS_INVALID_PARAMETER; } - if (!(egl_handle = dlopen( SONAME_LIBEGL, RTLD_NOW|RTLD_GLOBAL ))) - { - ERR( "failed to load %s: %s\n", SONAME_LIBEGL, dlerror() ); - return STATUS_NOT_SUPPORTED; - } + if (!opengl_funcs->egl_handle) return STATUS_NOT_SUPPORTED; if (!(opengl_handle = dlopen( SONAME_LIBGLESV2, RTLD_NOW|RTLD_GLOBAL ))) { ERR( "failed to load %s: %s\n", SONAME_LIBGLESV2, dlerror() ); return STATUS_NOT_SUPPORTED; } + funcs = opengl_funcs;
-#define LOAD_FUNCPTR(func) do { \ - if (!(p_##func = dlsym( egl_handle, #func ))) \ - { ERR( "can't find symbol %s\n", #func); return FALSE; } \ - } while(0) - LOAD_FUNCPTR( eglCreateContext ); - LOAD_FUNCPTR( eglCreateWindowSurface ); - LOAD_FUNCPTR( eglCreatePbufferSurface ); - LOAD_FUNCPTR( eglDestroyContext ); - LOAD_FUNCPTR( eglDestroySurface ); - LOAD_FUNCPTR( eglGetConfigAttrib ); - LOAD_FUNCPTR( eglGetConfigs ); - LOAD_FUNCPTR( eglGetDisplay ); - LOAD_FUNCPTR( eglGetProcAddress ); - LOAD_FUNCPTR( eglInitialize ); - LOAD_FUNCPTR( eglMakeCurrent ); - LOAD_FUNCPTR( eglSwapBuffers ); - LOAD_FUNCPTR( eglSwapInterval ); -#undef LOAD_FUNCPTR - - display = p_eglGetDisplay( EGL_DEFAULT_DISPLAY ); - if (!p_eglInitialize( display, &major, &minor )) return 0; + display = funcs->p_eglGetDisplay( EGL_DEFAULT_DISPLAY ); + if (!funcs->p_eglInitialize( display, &major, &minor )) return 0; TRACE( "display %p version %u.%u\n", display, major, minor );
*driver_funcs = &android_driver_funcs;