From: Rémi Bernon rbernon@codeweavers.com
--- dlls/wineandroid.drv/opengl.c | 123 +++++----------------------------- 1 file changed, 16 insertions(+), 107 deletions(-)
diff --git a/dlls/wineandroid.drv/opengl.c b/dlls/wineandroid.drv/opengl.c index 480b7bbab2a..94a82a6934b 100644 --- a/dlls/wineandroid.drv/opengl.c +++ b/dlls/wineandroid.drv/opengl.c @@ -77,15 +77,18 @@ struct gl_drawable };
static void *opengl_handle; -static struct egl_pixel_format *pixel_formats; -static int nb_pixel_formats, nb_onscreen_formats; -static char wgl_extensions[4096]; - static struct list gl_contexts = LIST_INIT( gl_contexts ); static struct list gl_drawables = LIST_INIT( gl_drawables );
pthread_mutex_t drawable_mutex;
+static inline EGLConfig egl_config_for_format(int format) +{ + assert(format > 0 && format <= 2 * funcs->egl_config_count); + if (format <= funcs->egl_config_count) return funcs->egl_configs[format - 1]; + return funcs->egl_configs[format - funcs->egl_config_count - 1]; +} + static struct gl_drawable *create_gl_drawable( HWND hwnd, HDC hdc, int format ) { static const int attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE }; @@ -96,7 +99,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 = funcs->p_eglCreatePbufferSurface( funcs->egl_display, pixel_formats[gl->format - 1].config, attribs ); + gl->pbuffer = funcs->p_eglCreatePbufferSurface( funcs->egl_display, egl_config_for_format(gl->format), attribs ); pthread_mutex_lock( &drawable_mutex ); list_add_head( &gl_drawables, &gl->entry ); return gl; @@ -160,7 +163,7 @@ void update_gl_drawable( HWND hwnd ) if ((gl = get_gl_drawable( hwnd, 0 ))) { if (!gl->surface && - (gl->surface = funcs->p_eglCreateWindowSurface( funcs->egl_display, pixel_formats[gl->format - 1].config, + (gl->surface = funcs->p_eglCreateWindowSurface( funcs->egl_display, egl_config_for_format(gl->format), gl->window, NULL ))) { LIST_FOR_EACH_ENTRY( ctx, &gl_contexts, struct android_context, entry ) @@ -190,7 +193,7 @@ static BOOL android_set_pixel_format( HWND hwnd, int old_format, int new_format, if (internal) { EGLint pf; - funcs->p_eglGetConfigAttrib( funcs->egl_display, pixel_formats[new_format - 1].config, EGL_NATIVE_VISUAL_ID, &pf ); + funcs->p_eglGetConfigAttrib( funcs->egl_display, egl_config_for_format(new_format), EGL_NATIVE_VISUAL_ID, &pf ); gl->window->perform( gl->window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, pf ); gl->format = new_format; } @@ -240,7 +243,7 @@ static BOOL android_context_create( HDC hdc, int format, void *share, const int
ctx = malloc( sizeof(*ctx) );
- ctx->config = pixel_formats[format - 1].config; + ctx->config = egl_config_for_format(format); ctx->surface = 0; ctx->refresh = FALSE; ctx->context = funcs->p_eglCreateContext( funcs->egl_display, ctx->config, shared_ctx ? shared_ctx->context : EGL_NO_CONTEXT, attribs ); @@ -251,44 +254,6 @@ static BOOL android_context_create( HDC hdc, int format, void *share, const int return TRUE; }
-static BOOL android_describe_pixel_format( int format, struct wgl_pixel_format *desc ) -{ - struct egl_pixel_format *fmt = pixel_formats + format - 1; - PIXELFORMATDESCRIPTOR *pfd = &desc->pfd; - EGLint val; - EGLConfig config = fmt->config; - - if (format <= 0 || format > nb_pixel_formats) return FALSE; - - memset( pfd, 0, sizeof(*pfd) ); - pfd->nSize = sizeof(*pfd); - pfd->nVersion = 1; - pfd->dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER | PFD_SUPPORT_COMPOSITION; - pfd->iPixelType = PFD_TYPE_RGBA; - pfd->iLayerType = PFD_MAIN_PLANE; - - funcs->p_eglGetConfigAttrib( funcs->egl_display, config, EGL_BUFFER_SIZE, &val ); - pfd->cColorBits = val; - funcs->p_eglGetConfigAttrib( funcs->egl_display, config, EGL_RED_SIZE, &val ); - pfd->cRedBits = val; - funcs->p_eglGetConfigAttrib( funcs->egl_display, config, EGL_GREEN_SIZE, &val ); - pfd->cGreenBits = val; - funcs->p_eglGetConfigAttrib( funcs->egl_display, config, EGL_BLUE_SIZE, &val ); - pfd->cBlueBits = val; - funcs->p_eglGetConfigAttrib( funcs->egl_display, config, EGL_ALPHA_SIZE, &val ); - pfd->cAlphaBits = val; - funcs->p_eglGetConfigAttrib( funcs->egl_display, config, EGL_DEPTH_SIZE, &val ); - pfd->cDepthBits = val; - funcs->p_eglGetConfigAttrib( funcs->egl_display, config, EGL_STENCIL_SIZE, &val ); - pfd->cStencilBits = val; - - pfd->cAlphaShift = 0; - pfd->cBlueShift = pfd->cAlphaShift + pfd->cAlphaBits; - pfd->cGreenShift = pfd->cBlueShift + pfd->cBlueBits; - pfd->cRedShift = pfd->cGreenShift + pfd->cGreenBits; - return TRUE; -} - static BOOL android_context_make_current( HDC draw_hdc, HDC read_hdc, void *private ) { struct android_context *ctx = private; @@ -419,74 +384,15 @@ static BOOL android_context_flush( void *private, HWND hwnd, HDC hdc, int interv return FALSE; }
-static void register_extension( const char *ext ) -{ - if (wgl_extensions[0]) strcat( wgl_extensions, " " ); - strcat( wgl_extensions, ext ); - TRACE( "%s\n", ext ); -} - static const char *android_init_wgl_extensions( struct opengl_funcs *funcs ) { - register_extension("WGL_EXT_framebuffer_sRGB"); - return wgl_extensions; + return "WGL_EXT_framebuffer_sRGB"; }
-static UINT android_init_pixel_formats( UINT *onscreen_count ) -{ - EGLConfig *configs; - EGLint count, i, pass; - - funcs->p_eglGetConfigs( funcs->egl_display, NULL, 0, &count ); - configs = malloc( count * sizeof(*configs) ); - pixel_formats = malloc( count * sizeof(*pixel_formats) ); - funcs->p_eglGetConfigs( funcs->egl_display, configs, count, &count ); - if (!count || !configs || !pixel_formats) - { - free( configs ); - free( pixel_formats ); - ERR( "eglGetConfigs returned no configs\n" ); - return 0; - } - - for (pass = 0; pass < 2; pass++) - { - for (i = 0; i < count; i++) - { - EGLint id, type, visual_id, native, render, color, r, g, b, d, s; - - funcs->p_eglGetConfigAttrib( funcs->egl_display, configs[i], EGL_SURFACE_TYPE, &type ); - if (!(type & EGL_WINDOW_BIT) == !pass) continue; - funcs->p_eglGetConfigAttrib( funcs->egl_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]; - - funcs->p_eglGetConfigAttrib( funcs->egl_display, configs[i], EGL_CONFIG_ID, &id ); - funcs->p_eglGetConfigAttrib( funcs->egl_display, configs[i], EGL_NATIVE_VISUAL_ID, &visual_id ); - funcs->p_eglGetConfigAttrib( funcs->egl_display, configs[i], EGL_NATIVE_RENDERABLE, &native ); - funcs->p_eglGetConfigAttrib( funcs->egl_display, configs[i], EGL_COLOR_BUFFER_TYPE, &color ); - funcs->p_eglGetConfigAttrib( funcs->egl_display, configs[i], EGL_RED_SIZE, &r ); - funcs->p_eglGetConfigAttrib( funcs->egl_display, configs[i], EGL_GREEN_SIZE, &g ); - funcs->p_eglGetConfigAttrib( funcs->egl_display, configs[i], EGL_BLUE_SIZE, &b ); - funcs->p_eglGetConfigAttrib( funcs->egl_display, configs[i], EGL_DEPTH_SIZE, &d ); - funcs->p_eglGetConfigAttrib( funcs->egl_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 ); - } - if (!pass) nb_onscreen_formats = nb_pixel_formats; - } - - *onscreen_count = nb_onscreen_formats; - return nb_pixel_formats; -} - -static const struct opengl_driver_funcs android_driver_funcs = +static struct opengl_driver_funcs android_driver_funcs = { .p_get_egl_platform = android_get_egl_platform, .p_get_proc_address = android_get_proc_address, - .p_init_pixel_formats = android_init_pixel_formats, - .p_describe_pixel_format = android_describe_pixel_format, .p_init_wgl_extensions = android_init_wgl_extensions, .p_set_pixel_format = android_set_pixel_format, .p_swap_buffers = android_swap_buffers, @@ -516,6 +422,9 @@ UINT ANDROID_OpenGLInit( UINT version, const struct opengl_funcs *opengl_funcs, } funcs = opengl_funcs;
+ android_driver_funcs.p_init_pixel_formats = (*driver_funcs)->p_init_pixel_formats; + android_driver_funcs.p_describe_pixel_format = (*driver_funcs)->p_describe_pixel_format; + *driver_funcs = &android_driver_funcs; return STATUS_SUCCESS; }