cogl/winsys/glx: Merge 'xlib' and 'glx' structs

The GLX winsys code had split up the GLX onscreen implementation into an
Xlib part (with a struct name confusingly enough identical to that of
the onscreen in the actual Xlib winsys). To remove some confusion,
combine the two.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
This commit is contained in:
Jonas Ådahl 2020-10-17 16:24:06 +02:00 committed by Robert Mader
parent 7cf24ccc34
commit 2eea373241

View File

@ -84,16 +84,12 @@ typedef struct _CoglContextGLX
GLXDrawable current_drawable; GLXDrawable current_drawable;
} CoglContextGLX; } CoglContextGLX;
typedef struct _CoglOnscreenXlib typedef struct _CoglOnscreenGLX
{ {
Window xwin; Window xwin;
int x, y; int x, y;
CoglOutput *output; CoglOutput *output;
} CoglOnscreenXlib;
typedef struct _CoglOnscreenGLX
{
CoglOnscreenXlib _parent;
GLXDrawable glxwin; GLXDrawable glxwin;
uint32_t last_swap_vsync_counter; uint32_t last_swap_vsync_counter;
uint32_t pending_sync_notify; uint32_t pending_sync_notify;
@ -176,14 +172,14 @@ find_onscreen_for_xid (CoglContext *context, uint32_t xid)
for (l = context->framebuffers; l; l = l->next) for (l = context->framebuffers; l; l = l->next)
{ {
CoglFramebuffer *framebuffer = l->data; CoglFramebuffer *framebuffer = l->data;
CoglOnscreenXlib *xlib_onscreen; CoglOnscreenGLX *onscreen_glx;
if (!COGL_IS_ONSCREEN (framebuffer)) if (!COGL_IS_ONSCREEN (framebuffer))
continue; continue;
/* Does the GLXEvent have the GLXDrawable or the X Window? */ /* Does the GLXEvent have the GLXDrawable or the X Window? */
xlib_onscreen = cogl_onscreen_get_winsys (COGL_ONSCREEN (framebuffer)); onscreen_glx = cogl_onscreen_get_winsys (COGL_ONSCREEN (framebuffer));
if (xlib_onscreen != NULL && xlib_onscreen->xwin == (Window)xid) if (onscreen_glx && onscreen_glx->xwin == (Window)xid)
return COGL_ONSCREEN (framebuffer); return COGL_ONSCREEN (framebuffer);
} }
@ -464,7 +460,7 @@ notify_swap_buffers (CoglContext *context, GLXBufferSwapComplete *swap_event)
static void static void
update_output (CoglOnscreen *onscreen) update_output (CoglOnscreen *onscreen)
{ {
CoglOnscreenXlib *xlib_onscreen = cogl_onscreen_get_winsys (onscreen); CoglOnscreenGLX *onscreen_glx = cogl_onscreen_get_winsys (onscreen);
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
CoglContext *context = cogl_framebuffer_get_context (framebuffer); CoglContext *context = cogl_framebuffer_get_context (framebuffer);
CoglDisplay *display = context->display; CoglDisplay *display = context->display;
@ -474,18 +470,18 @@ update_output (CoglOnscreen *onscreen)
width = cogl_framebuffer_get_width (framebuffer); width = cogl_framebuffer_get_width (framebuffer);
height = cogl_framebuffer_get_height (framebuffer); height = cogl_framebuffer_get_height (framebuffer);
output = _cogl_xlib_renderer_output_for_rectangle (display->renderer, output = _cogl_xlib_renderer_output_for_rectangle (display->renderer,
xlib_onscreen->x, onscreen_glx->x,
xlib_onscreen->y, onscreen_glx->y,
width, height); width, height);
if (xlib_onscreen->output != output) if (onscreen_glx->output != output)
{ {
if (xlib_onscreen->output) if (onscreen_glx->output)
cogl_object_unref (xlib_onscreen->output); cogl_object_unref (onscreen_glx->output);
xlib_onscreen->output = output; onscreen_glx->output = output;
if (output) if (output)
cogl_object_ref (xlib_onscreen->output); cogl_object_ref (onscreen_glx->output);
} }
} }
@ -499,13 +495,11 @@ notify_resize (CoglContext *context,
CoglRenderer *renderer = context->display->renderer; CoglRenderer *renderer = context->display->renderer;
CoglGLXRenderer *glx_renderer = renderer->winsys; CoglGLXRenderer *glx_renderer = renderer->winsys;
CoglOnscreenGLX *glx_onscreen; CoglOnscreenGLX *glx_onscreen;
CoglOnscreenXlib *xlib_onscreen;
if (!onscreen) if (!onscreen)
return; return;
glx_onscreen = cogl_onscreen_get_winsys (onscreen); glx_onscreen = cogl_onscreen_get_winsys (onscreen);
xlib_onscreen = cogl_onscreen_get_winsys (onscreen);
_cogl_framebuffer_winsys_update_size (framebuffer, _cogl_framebuffer_winsys_update_size (framebuffer,
configure_event->width, configure_event->width,
@ -542,8 +536,8 @@ notify_resize (CoglContext *context,
0, 0, &x, &y, &child); 0, 0, &x, &y, &child);
} }
xlib_onscreen->x = x; glx_onscreen->x = x;
xlib_onscreen->y = y; glx_onscreen->y = y;
update_output (onscreen); update_output (onscreen);
} }
@ -1244,7 +1238,6 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
_cogl_xlib_renderer_get_data (display->renderer); _cogl_xlib_renderer_get_data (display->renderer);
CoglGLXRenderer *glx_renderer = display->renderer->winsys; CoglGLXRenderer *glx_renderer = display->renderer->winsys;
Window xwin; Window xwin;
CoglOnscreenXlib *xlib_onscreen;
CoglOnscreenGLX *glx_onscreen; CoglOnscreenGLX *glx_onscreen;
const CoglFramebufferConfig *config; const CoglFramebufferConfig *config;
GLXFBConfig fbconfig; GLXFBConfig fbconfig;
@ -1350,10 +1343,9 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
winsys = g_slice_new0 (CoglOnscreenGLX); winsys = g_slice_new0 (CoglOnscreenGLX);
cogl_onscreen_set_winsys (onscreen, winsys); cogl_onscreen_set_winsys (onscreen, winsys);
xlib_onscreen = cogl_onscreen_get_winsys (onscreen);
glx_onscreen = cogl_onscreen_get_winsys (onscreen); glx_onscreen = cogl_onscreen_get_winsys (onscreen);
xlib_onscreen->xwin = xwin; glx_onscreen->xwin = xwin;
/* Try and create a GLXWindow to use with extensions dependent on /* Try and create a GLXWindow to use with extensions dependent on
* GLX versions >= 1.3 that don't accept regular X Windows as GLX * GLX versions >= 1.3 that don't accept regular X Windows as GLX
@ -1363,7 +1355,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
glx_onscreen->glxwin = glx_onscreen->glxwin =
glx_renderer->glXCreateWindow (xlib_renderer->xdpy, glx_renderer->glXCreateWindow (xlib_renderer->xdpy,
fbconfig, fbconfig,
xlib_onscreen->xwin, glx_onscreen->xwin,
NULL); NULL);
} }
@ -1371,7 +1363,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
if (_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) if (_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT))
{ {
GLXDrawable drawable = GLXDrawable drawable =
glx_onscreen->glxwin ? glx_onscreen->glxwin : xlib_onscreen->xwin; glx_onscreen->glxwin ? glx_onscreen->glxwin : glx_onscreen->xwin;
/* similarly to above, we unconditionally select this event /* similarly to above, we unconditionally select this event
* because we rely on it to advance the master clock, and * because we rely on it to advance the master clock, and
@ -1397,7 +1389,6 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
_cogl_xlib_renderer_get_data (context->display->renderer); _cogl_xlib_renderer_get_data (context->display->renderer);
CoglGLXRenderer *glx_renderer = context->display->renderer->winsys; CoglGLXRenderer *glx_renderer = context->display->renderer->winsys;
CoglXlibTrapState old_state; CoglXlibTrapState old_state;
CoglOnscreenXlib *xlib_onscreen = cogl_onscreen_get_winsys (onscreen);
CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen); CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen);
GLXDrawable drawable; GLXDrawable drawable;
@ -1405,16 +1396,16 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
if (glx_onscreen == NULL) if (glx_onscreen == NULL)
return; return;
if (xlib_onscreen->output != NULL) if (glx_onscreen->output != NULL)
{ {
cogl_object_unref (xlib_onscreen->output); cogl_object_unref (glx_onscreen->output);
xlib_onscreen->output = NULL; glx_onscreen->output = NULL;
} }
_cogl_xlib_renderer_trap_errors (context->display->renderer, &old_state); _cogl_xlib_renderer_trap_errors (context->display->renderer, &old_state);
drawable = drawable =
glx_onscreen->glxwin == None ? xlib_onscreen->xwin : glx_onscreen->glxwin; glx_onscreen->glxwin == None ? glx_onscreen->xwin : glx_onscreen->glxwin;
/* Cogl always needs a valid context bound to something so if we are /* Cogl always needs a valid context bound to something so if we are
* destroying the onscreen that is currently bound we'll switch back * destroying the onscreen that is currently bound we'll switch back
@ -1442,13 +1433,15 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
glx_onscreen->glxwin = None; glx_onscreen->glxwin = None;
} }
if (xlib_onscreen->xwin != None) if (glx_onscreen->xwin != None)
{ {
XDestroyWindow (xlib_renderer->xdpy, xlib_onscreen->xwin); XDestroyWindow (xlib_renderer->xdpy, glx_onscreen->xwin);
xlib_onscreen->xwin = None; glx_onscreen->xwin = None;
} }
else else
xlib_onscreen->xwin = None; {
glx_onscreen->xwin = None;
}
XSync (xlib_renderer->xdpy, False); XSync (xlib_renderer->xdpy, False);
@ -1468,13 +1461,12 @@ _cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
CoglXlibRenderer *xlib_renderer = CoglXlibRenderer *xlib_renderer =
_cogl_xlib_renderer_get_data (context->display->renderer); _cogl_xlib_renderer_get_data (context->display->renderer);
CoglGLXRenderer *glx_renderer = context->display->renderer->winsys; CoglGLXRenderer *glx_renderer = context->display->renderer->winsys;
CoglOnscreenXlib *xlib_onscreen = cogl_onscreen_get_winsys (onscreen);
CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen); CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen);
CoglXlibTrapState old_state; CoglXlibTrapState old_state;
GLXDrawable drawable; GLXDrawable drawable;
drawable = drawable =
glx_onscreen->glxwin ? glx_onscreen->glxwin : xlib_onscreen->xwin; glx_onscreen->glxwin ? glx_onscreen->glxwin : glx_onscreen->xwin;
if (glx_context->current_drawable == drawable) if (glx_context->current_drawable == drawable)
return; return;
@ -1609,14 +1601,17 @@ _cogl_winsys_onscreen_get_buffer_age (CoglOnscreen *onscreen)
CoglXlibRenderer *xlib_renderer = _cogl_xlib_renderer_get_data (context->display->renderer); CoglXlibRenderer *xlib_renderer = _cogl_xlib_renderer_get_data (context->display->renderer);
CoglGLXRenderer *glx_renderer = context->display->renderer->winsys; CoglGLXRenderer *glx_renderer = context->display->renderer->winsys;
CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen); CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen);
CoglOnscreenXlib *xlib_onscreen = cogl_onscreen_get_winsys (onscreen); GLXDrawable drawable;
GLXDrawable drawable = glx_onscreen->glxwin ? glx_onscreen->glxwin : xlib_onscreen->xwin;
unsigned int age; unsigned int age;
if (!_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_BUFFER_AGE)) if (!_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_BUFFER_AGE))
return 0; return 0;
glx_renderer->glXQueryDrawable (xlib_renderer->xdpy, drawable, GLX_BACK_BUFFER_AGE_EXT, &age); drawable = glx_onscreen->glxwin ? glx_onscreen->glxwin : glx_onscreen->xwin;
glx_renderer->glXQueryDrawable (xlib_renderer->xdpy,
drawable,
GLX_BACK_BUFFER_AGE_EXT,
&age);
return age; return age;
} }
@ -1648,10 +1643,9 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
_cogl_xlib_renderer_get_data (context->display->renderer); _cogl_xlib_renderer_get_data (context->display->renderer);
CoglGLXRenderer *glx_renderer = context->display->renderer->winsys; CoglGLXRenderer *glx_renderer = context->display->renderer->winsys;
CoglGLXDisplay *glx_display = context->display->winsys; CoglGLXDisplay *glx_display = context->display->winsys;
CoglOnscreenXlib *xlib_onscreen = cogl_onscreen_get_winsys (onscreen);
CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen); CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen);
GLXDrawable drawable = GLXDrawable drawable =
glx_onscreen->glxwin ? glx_onscreen->glxwin : xlib_onscreen->xwin; glx_onscreen->glxwin ? glx_onscreen->glxwin : glx_onscreen->xwin;
uint32_t end_frame_vsync_counter = 0; uint32_t end_frame_vsync_counter = 0;
gboolean have_counter; gboolean have_counter;
gboolean can_wait; gboolean can_wait;
@ -1823,8 +1817,8 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
output = output =
_cogl_xlib_renderer_output_for_rectangle (context->display->renderer, _cogl_xlib_renderer_output_for_rectangle (context->display->renderer,
xlib_onscreen->x + x_min, glx_onscreen->x + x_min,
xlib_onscreen->y + y_min, glx_onscreen->y + y_min,
x_max - x_min, x_max - x_min,
y_max - y_min); y_max - y_min);
@ -1856,7 +1850,6 @@ _cogl_winsys_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
_cogl_xlib_renderer_get_data (context->display->renderer); _cogl_xlib_renderer_get_data (context->display->renderer);
CoglGLXRenderer *glx_renderer = context->display->renderer->winsys; CoglGLXRenderer *glx_renderer = context->display->renderer->winsys;
CoglGLXDisplay *glx_display = context->display->winsys; CoglGLXDisplay *glx_display = context->display->winsys;
CoglOnscreenXlib *xlib_onscreen = cogl_onscreen_get_winsys (onscreen);
CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen); CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen);
gboolean have_counter; gboolean have_counter;
GLXDrawable drawable; GLXDrawable drawable;
@ -1869,7 +1862,7 @@ _cogl_winsys_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
framebuffer, framebuffer,
COGL_FRAMEBUFFER_STATE_BIND); COGL_FRAMEBUFFER_STATE_BIND);
drawable = glx_onscreen->glxwin ? glx_onscreen->glxwin : xlib_onscreen->xwin; drawable = glx_onscreen->glxwin ? glx_onscreen->glxwin : glx_onscreen->xwin;
have_counter = glx_display->have_vblank_counter; have_counter = glx_display->have_vblank_counter;
@ -1919,14 +1912,15 @@ _cogl_winsys_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
glx_onscreen->last_swap_vsync_counter = glx_onscreen->last_swap_vsync_counter =
_cogl_winsys_get_vsync_counter (context); _cogl_winsys_get_vsync_counter (context);
set_frame_info_output (onscreen, xlib_onscreen->output); set_frame_info_output (onscreen, glx_onscreen->output);
} }
static uint32_t static uint32_t
_cogl_winsys_onscreen_x11_get_window_xid (CoglOnscreen *onscreen) _cogl_winsys_onscreen_x11_get_window_xid (CoglOnscreen *onscreen)
{ {
CoglOnscreenXlib *xlib_onscreen = cogl_onscreen_get_winsys (onscreen); CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen);
return xlib_onscreen->xwin;
return glx_onscreen->xwin;
} }
static void static void
@ -1937,12 +1931,12 @@ _cogl_winsys_onscreen_set_visibility (CoglOnscreen *onscreen,
CoglContext *context = cogl_framebuffer_get_context (framebuffer); CoglContext *context = cogl_framebuffer_get_context (framebuffer);
CoglXlibRenderer *xlib_renderer = CoglXlibRenderer *xlib_renderer =
_cogl_xlib_renderer_get_data (context->display->renderer); _cogl_xlib_renderer_get_data (context->display->renderer);
CoglOnscreenXlib *xlib_onscreen = cogl_onscreen_get_winsys (onscreen); CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen);
if (visibility) if (visibility)
XMapWindow (xlib_renderer->xdpy, xlib_onscreen->xwin); XMapWindow (xlib_renderer->xdpy, glx_onscreen->xwin);
else else
XUnmapWindow (xlib_renderer->xdpy, xlib_onscreen->xwin); XUnmapWindow (xlib_renderer->xdpy, glx_onscreen->xwin);
} }
static void static void
@ -1953,7 +1947,7 @@ _cogl_winsys_onscreen_set_resizable (CoglOnscreen *onscreen,
CoglContext *context = cogl_framebuffer_get_context (framebuffer); CoglContext *context = cogl_framebuffer_get_context (framebuffer);
CoglXlibRenderer *xlib_renderer = CoglXlibRenderer *xlib_renderer =
_cogl_xlib_renderer_get_data (context->display->renderer); _cogl_xlib_renderer_get_data (context->display->renderer);
CoglOnscreenXlib *xlib_onscreen = cogl_onscreen_get_winsys (onscreen); CoglOnscreenGLX *glx_onscreen = cogl_onscreen_get_winsys (onscreen);
XSizeHints *size_hints = XAllocSizeHints (); XSizeHints *size_hints = XAllocSizeHints ();
@ -1978,7 +1972,7 @@ _cogl_winsys_onscreen_set_resizable (CoglOnscreen *onscreen,
size_hints->max_height = height; size_hints->max_height = height;
} }
XSetWMNormalHints (xlib_renderer->xdpy, xlib_onscreen->xwin, size_hints); XSetWMNormalHints (xlib_renderer->xdpy, glx_onscreen->xwin, size_hints);
XFree (size_hints); XFree (size_hints);
} }