compositor: Move EGL context creation to gles2-renderer.c

Kristian Høgsberg 12 years ago
parent 2bc5e8eaf8
commit 9793fc7a4e
  1. 48
      src/compositor-android.c
  2. 18
      src/compositor-drm.c
  3. 25
      src/compositor-wayland.c
  4. 21
      src/compositor-x11.c
  5. 18
      src/gles2-renderer.c

@ -114,29 +114,6 @@ print_egl_error_state(void)
egl_error_string(code), (long)code);
}
static int
android_output_make_current(struct android_output *output)
{
struct android_compositor *compositor = output->compositor;
EGLBoolean ret;
static int errored;
ret = eglMakeCurrent(compositor->base.egl_display,
output->base.egl_surface,
output->base.egl_surface,
compositor->base.egl_context);
if (ret == EGL_FALSE) {
if (errored)
return -1;
errored = 1;
weston_log("Failed to make EGL context current.\n");
print_egl_error_state();
return -1;
}
return 0;
}
static void
android_finish_frame(void *data)
{
@ -398,11 +375,6 @@ android_init_egl(struct android_compositor *compositor,
EGLint eglmajor, eglminor;
int ret;
static const EGLint context_attrs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
static const EGLint config_attrs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 1,
@ -427,12 +399,6 @@ android_init_egl(struct android_compositor *compositor,
return -1;
}
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
weston_log("Failed to bind EGL_OPENGL_ES_API.\n");
print_egl_error_state();
return -1;
}
ret = android_egl_choose_config(compositor, output->fb, config_attrs);
if (ret < 0) {
weston_log("Failed to find an EGL config.\n");
@ -440,17 +406,6 @@ android_init_egl(struct android_compositor *compositor,
return -1;
}
compositor->base.egl_context =
eglCreateContext(compositor->base.egl_display,
compositor->base.egl_config,
EGL_NO_CONTEXT,
context_attrs);
if (compositor->base.egl_context == EGL_NO_CONTEXT) {
weston_log("Failed to create a GL ES 2 context.\n");
print_egl_error_state();
return -1;
}
output->base.egl_surface =
eglCreateWindowSurface(compositor->base.egl_display,
compositor->base.egl_config,
@ -462,9 +417,6 @@ android_init_egl(struct android_compositor *compositor,
return -1;
}
if (android_output_make_current(output) < 0)
return -1;
return 0;
}

@ -1043,11 +1043,6 @@ init_egl(struct drm_compositor *ec, struct udev_device *device)
EGLint major, minor, n;
const char *filename, *sysnum;
int fd;
static const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
static const EGLint config_attribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 1,
@ -1090,25 +1085,12 @@ init_egl(struct drm_compositor *ec, struct udev_device *device)
return -1;
}
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
weston_log("failed to bind api EGL_OPENGL_ES_API\n");
return -1;
}
if (!eglChooseConfig(ec->base.egl_display, config_attribs,
&ec->base.egl_config, 1, &n) || n != 1) {
weston_log("failed to choose config: %d\n", n);
return -1;
}
ec->base.egl_context =
eglCreateContext(ec->base.egl_display, ec->base.egl_config,
EGL_NO_CONTEXT, context_attribs);
if (ec->base.egl_context == NULL) {
weston_log("failed to create context\n");
return -1;
}
return 0;
}

@ -259,10 +259,6 @@ wayland_compositor_init_egl(struct wayland_compositor *c)
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE
};
static const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
c->base.egl_display = eglGetDisplay(c->parent.wl_display);
if (c->base.egl_display == NULL) {
@ -275,24 +271,12 @@ wayland_compositor_init_egl(struct wayland_compositor *c)
return -1;
}
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
weston_log("failed to bind EGL_OPENGL_ES_API\n");
return -1;
}
if (!eglChooseConfig(c->base.egl_display, config_attribs,
&c->base.egl_config, 1, &n) || n == 0) {
weston_log("failed to choose config: %d\n", n);
return -1;
}
c->base.egl_context =
eglCreateContext(c->base.egl_display, c->base.egl_config,
EGL_NO_CONTEXT, context_attribs);
if (c->base.egl_context == NULL) {
weston_log("failed to create context\n");
return -1;
}
return 0;
}
@ -403,13 +387,6 @@ wayland_compositor_create_output(struct wayland_compositor *c,
goto cleanup_window;
}
if (!eglMakeCurrent(c->base.egl_display, output->base.egl_surface,
output->base.egl_surface, c->base.egl_context)) {
weston_log("failed to make surface current\n");
goto cleanup_surface;
return -1;
}
output->parent.shell_surface =
wl_shell_get_shell_surface(c->parent.shell,
output->parent.surface);
@ -432,8 +409,6 @@ wayland_compositor_create_output(struct wayland_compositor *c,
return 0;
cleanup_surface:
eglDestroySurface(c->base.egl_display, output->base.egl_surface);
cleanup_window:
wl_egl_window_destroy(output->parent.egl_window);
cleanup_output:

@ -249,10 +249,6 @@ x11_compositor_init_egl(struct x11_compositor *c)
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE
};
static const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
c->base.egl_display = eglGetDisplay(c->dpy);
if (c->base.egl_display == NULL) {
@ -265,24 +261,12 @@ x11_compositor_init_egl(struct x11_compositor *c)
return -1;
}
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
weston_log("failed to bind EGL_OPENGL_ES_API\n");
return -1;
}
if (!eglChooseConfig(c->base.egl_display, config_attribs,
&c->base.egl_config, 1, &n) || n == 0) {
weston_log("failed to choose config: %d\n", n);
return -1;
}
c->base.egl_context =
eglCreateContext(c->base.egl_display, c->base.egl_config,
EGL_NO_CONTEXT, context_attribs);
if (c->base.egl_context == NULL) {
weston_log("failed to create context\n");
return -1;
}
return 0;
}
@ -547,11 +531,6 @@ x11_compositor_create_output(struct x11_compositor *c, int x, int y,
weston_log("failed to create window surface\n");
return NULL;
}
if (!eglMakeCurrent(c->base.egl_display, output->base.egl_surface,
output->base.egl_surface, c->base.egl_context)) {
weston_log("failed to make surface current\n");
return NULL;
}
loop = wl_display_get_event_loop(c->base.wl_display);
output->finish_frame_timer =

@ -1048,10 +1048,28 @@ gles2_renderer_init(struct weston_compositor *ec)
struct weston_output *output;
EGLBoolean ret;
static const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
renderer = malloc(sizeof *renderer);
if (renderer == NULL)
return -1;
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
weston_log("failed to bind EGL_OPENGL_ES_API\n");
print_egl_error_state();
return -1;
}
ec->egl_context = eglCreateContext(ec->egl_display, ec->egl_config,
EGL_NO_CONTEXT, context_attribs);
if (ec->egl_context == NULL) {
weston_log("failed to create context\n");
print_egl_error_state();
return -1;
}
output = container_of(ec->output_list.next,
struct weston_output, link);
ret = eglMakeCurrent(ec->egl_display, output->egl_surface,

Loading…
Cancel
Save