Commit 3fda9393 authored by Emil Velikov's avatar Emil Velikov

egl: fold eglGetConfigAttrib() within wegl_config_choose()

Rather than having the call in multiple places and multiple times, just
query the native visual id once and store it for later use.
Signed-off-by: default avatarEmil Velikov <emil.velikov@collabora.com>
parent 03d55669
......@@ -214,6 +214,7 @@ wegl_config_choose(struct wcore_platform *wc_plat,
struct wcore_display *wc_dpy,
const struct wcore_config_attrs *attrs)
{
struct wegl_platform *plat = wegl_platform(wc_plat);
struct wegl_display *dpy = wegl_display(wc_dpy);
struct wegl_config *config;
bool ok;
......@@ -235,6 +236,12 @@ wegl_config_choose(struct wcore_platform *wc_plat,
if (!config->egl)
goto fail;
ok = plat->eglGetConfigAttrib(dpy->egl, config->egl,
EGL_NATIVE_VISUAL_ID, &config->visual);
if (!ok)
goto fail;
return &config->wcore;
fail:
......
......@@ -40,6 +40,7 @@ struct wcore_config_attrs;
struct wegl_config {
struct wcore_config wcore;
EGLConfig egl;
EGLint visual;
};
DEFINE_CONTAINER_CAST_FUNC(wegl_config,
......
......@@ -30,45 +30,6 @@
#include "wgbm_config.h"
#include "wgbm_display.h"
struct wcore_config*
wgbm_config_choose(struct wcore_platform *wc_plat,
struct wcore_display *wc_dpy,
const struct wcore_config_attrs *attrs)
{
struct wcore_config *wc_config = wegl_config_choose(wc_plat, wc_dpy, attrs);
if (!wc_config)
return NULL;
if (wgbm_config_get_gbm_format(wc_plat, wc_dpy, wc_config) == 0) {
wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
"requested config is unsupported on GBM");
wegl_config_destroy(wc_config);
return NULL;
}
return wc_config;
}
uint32_t
wgbm_config_get_gbm_format(struct wcore_platform *wc_plat,
struct wcore_display *wc_display,
struct wcore_config *wc_config)
{
EGLint gbm_format;
struct wegl_display *dpy = wegl_display(wc_display);
struct wegl_platform *plat = wegl_platform(wc_plat);
struct wegl_config *egl_config = wegl_config(wc_config);
bool ok = plat->eglGetConfigAttrib(dpy->egl,
egl_config->egl,
EGL_NATIVE_VISUAL_ID,
&gbm_format);
if (!ok) {
return 0;
}
return gbm_format;
}
union waffle_native_config*
wgbm_config_get_native(struct wcore_config *wc_config)
{
......
......@@ -34,15 +34,5 @@
union waffle_native_config;
struct wcore_config*
wgbm_config_choose(struct wcore_platform *wc_plat,
struct wcore_display *wc_dpy,
const struct wcore_config_attrs *attrs);
uint32_t
wgbm_config_get_gbm_format(struct wcore_platform *wc_plat,
struct wcore_display *wc_dpy,
struct wcore_config *wc_config);
union waffle_native_config*
wgbm_config_get_native(struct wcore_config *wc_config);
......@@ -189,7 +189,7 @@ static const struct wcore_platform_vtbl wgbm_platform_vtbl = {
},
.config = {
.choose = wgbm_config_choose,
.choose = wegl_config_choose,
.destroy = wegl_config_destroy,
.get_native = wgbm_config_get_native,
},
......
......@@ -67,7 +67,6 @@ wgbm_window_create(struct wcore_platform *wc_plat,
struct wgbm_display *dpy = wgbm_display(wc_config->display);
struct wgbm_platform *plat = wgbm_platform(wegl_platform(wc_plat));
struct wgbm_window *self;
uint32_t gbm_format;
bool ok = true;
if (width == -1 && height == -1) {
......@@ -85,11 +84,9 @@ wgbm_window_create(struct wcore_platform *wc_plat,
if (self == NULL)
return NULL;
gbm_format = wgbm_config_get_gbm_format(wc_plat, wc_config->display,
wc_config);
assert(gbm_format != 0);
self->gbm_surface = plat->gbm_surface_create(dpy->gbm_device,
width, height, gbm_format,
width, height,
wegl_config(wc_config)->visual,
GBM_BO_USE_RENDERING);
if (!self->gbm_surface) {
wcore_errorf(WAFFLE_ERROR_UNKNOWN,
......
......@@ -63,8 +63,6 @@ xegl_window_create(struct wcore_platform *wc_plat,
struct xegl_window *self;
struct xegl_display *dpy = xegl_display(wc_config->display);
struct wegl_config *config = wegl_config(wc_config);
struct wegl_platform *plat = wegl_platform(wc_plat);
xcb_visualid_t visual;
bool ok = true;
if (width == -1 && height == -1) {
......@@ -81,18 +79,9 @@ xegl_window_create(struct wcore_platform *wc_plat,
if (self == NULL)
return NULL;
ok = plat->eglGetConfigAttrib(dpy->wegl.egl,
config->egl,
EGL_NATIVE_VISUAL_ID,
(EGLint*) &visual);
if (!ok) {
wegl_emit_error(plat, "eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID)");
goto error;
}
ok = x11_window_init(&self->x11,
&dpy->x11,
visual,
(xcb_visualid_t) config->visual,
width,
height);
if (!ok)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment