[Mesa-dev] [PATCH 3/3] egl/wayland: unify dri2_wl_create_surface implementations
Emil Velikov
emil.l.velikov at gmail.com
Fri Nov 11 16:45:01 UTC 2016
From: Emil Velikov <emil.velikov at collabora.com>
Rather than having two almost identical codepaths (one for HW/wl_drm and
another for SW/wl_shm), just factorise and reuse in both places.
Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
Another fine example of useless duplication that we have throughout ;-\
---
src/egl/drivers/dri2/platform_wayland.c | 109 ++++++--------------------------
1 file changed, 19 insertions(+), 90 deletions(-)
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index b5a0c8c..dd1bd2f 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -129,18 +129,17 @@ destroy_window_callback(void *data)
* Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
*/
static _EGLSurface *
-dri2_wl_create_surface(_EGLDriver *drv, _EGLDisplay *disp,
- _EGLConfig *conf, void *native_window,
- const EGLint *attrib_list)
+dri2_wl_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
+ _EGLConfig *conf, void *native_window,
+ const EGLint *attrib_list)
{
+ __DRIcreateNewDrawableFunc createNewDrawable;
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_config *dri2_conf = dri2_egl_config(conf);
struct wl_egl_window *window = native_window;
struct dri2_egl_surface *dri2_surf;
const __DRIconfig *config;
- (void) drv;
-
dri2_surf = calloc(1, sizeof *dri2_surf);
if (!dri2_surf) {
_eglError(EGL_BAD_ALLOC, "dri2_create_surface");
@@ -165,7 +164,6 @@ dri2_wl_create_surface(_EGLDriver *drv, _EGLDisplay *disp,
dri2_surf->wl_win = window;
dri2_surf->wl_win->private = dri2_surf;
- dri2_surf->wl_win->resize_callback = resize_callback;
dri2_surf->wl_win->destroy_window_callback = destroy_window_callback;
dri2_surf->base.Width = -1;
@@ -174,14 +172,24 @@ dri2_wl_create_surface(_EGLDriver *drv, _EGLDisplay *disp,
config = dri2_get_dri_config(dri2_conf, EGL_WINDOW_BIT,
dri2_surf->base.GLColorspace);
- dri2_surf->dri_drawable =
- (*dri2_dpy->dri2->createNewDrawable)(dri2_dpy->dri_screen, config,
- dri2_surf);
+ if (dri2_dpy->dri2) {
+ dri2_surf->wl_win->resize_callback = resize_callback;
+
+ createNewDrawable = dri2_dpy->dri2->createNewDrawable;
+ } else {
+ createNewDrawable = dri2_dpy->swrast->createNewDrawable;
+ }
+
+ dri2_surf->dri_drawable = (*createNewDrawable)(dri2_dpy->dri_screen, config,
+ dri2_surf);
if (dri2_surf->dri_drawable == NULL) {
- _eglError(EGL_BAD_ALLOC, "dri2->createNewDrawable");
+ _eglError(EGL_BAD_ALLOC, "createNewDrawable");
goto cleanup_surf;
}
+ dri2_wl_swap_interval(drv, disp, &dri2_surf->base,
+ dri2_dpy->default_swap_interval);
+
return &dri2_surf->base;
cleanup_surf:
@@ -190,25 +198,6 @@ dri2_wl_create_surface(_EGLDriver *drv, _EGLDisplay *disp,
return NULL;
}
-/**
- * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
- */
-static _EGLSurface *
-dri2_wl_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
- _EGLConfig *conf, void *native_window,
- const EGLint *attrib_list)
-{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- _EGLSurface *surf;
-
- surf = dri2_wl_create_surface(drv, disp, conf, native_window, attrib_list);
-
- if (surf != NULL)
- dri2_wl_swap_interval(drv, disp, surf, dri2_dpy->default_swap_interval);
-
- return surf;
-}
-
static _EGLSurface *
dri2_wl_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp,
_EGLConfig *conf, void *native_window,
@@ -1707,66 +1696,6 @@ dri2_wl_swrast_put_image(__DRIdrawable * draw, int op,
stride, data, loaderPrivate);
}
-/**
- * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
- */
-static _EGLSurface *
-dri2_wl_swrast_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
- _EGLConfig *conf, void *native_window,
- const EGLint *attrib_list)
-{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- struct dri2_egl_config *dri2_conf = dri2_egl_config(conf);
- struct wl_egl_window *window = native_window;
- struct dri2_egl_surface *dri2_surf;
- const __DRIconfig *config;
-
- (void) drv;
-
- dri2_surf = calloc(1, sizeof *dri2_surf);
- if (!dri2_surf) {
- _eglError(EGL_BAD_ALLOC, "dri2_create_surface");
- return NULL;
- }
-
- if (!_eglInitSurface(&dri2_surf->base, disp, EGL_WINDOW_BIT, conf, attrib_list))
- goto cleanup_surf;
-
- if (conf->RedSize == 5)
- dri2_surf->format = WL_SHM_FORMAT_RGB565;
- else if (conf->AlphaSize == 0)
- dri2_surf->format = WL_SHM_FORMAT_XRGB8888;
- else
- dri2_surf->format = WL_SHM_FORMAT_ARGB8888;
-
- dri2_surf->wl_win = window;
- dri2_surf->wl_win->resize_callback = resize_callback;
-
- dri2_surf->base.Width = -1;
- dri2_surf->base.Height = -1;
-
- config = dri2_get_dri_config(dri2_conf, EGL_WINDOW_BIT,
- dri2_surf->base.GLColorspace);
-
- dri2_surf->dri_drawable =
- (*dri2_dpy->swrast->createNewDrawable)(dri2_dpy->dri_screen,
- config, dri2_surf);
- if (dri2_surf->dri_drawable == NULL) {
- _eglError(EGL_BAD_ALLOC, "swrast->createNewDrawable");
- goto cleanup_surf;
- }
-
- dri2_wl_swap_interval(drv, disp, &dri2_surf->base,
- dri2_dpy->default_swap_interval);
-
- return &dri2_surf->base;
-
- cleanup_surf:
- free(dri2_surf);
-
- return NULL;
-}
-
static EGLBoolean
dri2_wl_swrast_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
{
@@ -1819,7 +1748,7 @@ static const struct wl_registry_listener registry_listener_swrast = {
static struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl = {
.authenticate = NULL,
- .create_window_surface = dri2_wl_swrast_create_window_surface,
+ .create_window_surface = dri2_wl_create_window_surface,
.create_pixmap_surface = dri2_wl_create_pixmap_surface,
.create_pbuffer_surface = dri2_fallback_create_pbuffer_surface,
.destroy_surface = dri2_wl_destroy_surface,
--
2.10.2
More information about the mesa-dev
mailing list