Move weston_output EGL state into gles2-renderer.

This introduces callbacks for output creation and destruction for the
gles2-renderer. This enables the gles2-renderer to have per-output
state. EGL surface creation is now done by the output_create callback
and the EGL surface is stored in the new per-output gles2-renderer
state. On the first output_create call, the gles2-renderer will setup
it's GL context. This is because EGL requires a EGL surface to be able
to use the GL context.
dev
John Kåre Alsaker 12 years ago committed by Kristian Høgsberg
parent ddf9bb3109
commit 94659274b4
  1. 16
      src/compositor-android.c
  2. 50
      src/compositor-drm.c
  3. 52
      src/compositor-rpi.c
  4. 16
      src/compositor-wayland.c
  5. 25
      src/compositor-x11.c
  6. 10
      src/compositor.h
  7. 80
      src/gles2-renderer.c

@ -145,6 +145,8 @@ android_output_destroy(struct weston_output *base)
wl_list_remove(&output->base.link); wl_list_remove(&output->base.link);
weston_output_destroy(&output->base); weston_output_destroy(&output->base);
gles2_renderer_output_destroy(base);
android_framebuffer_destroy(output->fb); android_framebuffer_destroy(output->fb);
free(output); free(output);
@ -406,16 +408,9 @@ android_init_egl(struct android_compositor *compositor,
return -1; return -1;
} }
output->base.egl_surface = if (gles2_renderer_output_create(&output->base,
eglCreateWindowSurface(compositor->base.egl_display, output->fb->native_window) < 0)
compositor->base.egl_config,
output->fb->native_window,
NULL);
if (output->base.egl_surface == EGL_NO_SURFACE) {
weston_log("Failed to create FB EGLSurface.\n");
print_egl_error_state();
return -1; return -1;
}
return 0; return 0;
} }
@ -478,9 +473,6 @@ android_compositor_create(struct wl_display *display, int argc, char *argv[],
android_compositor_add_output(compositor, output); android_compositor_add_output(compositor, output);
if (gles2_renderer_init(&compositor->base) < 0)
goto err_egl;
compositor->seat = android_seat_create(compositor); compositor->seat = android_seat_create(compositor);
if (!compositor->seat) if (!compositor->seat)
goto err_egl; goto err_egl;

@ -829,7 +829,8 @@ drm_output_destroy(struct weston_output *output_base)
c->crtc_allocator &= ~(1 << output->crtc_id); c->crtc_allocator &= ~(1 << output->crtc_id);
c->connector_allocator &= ~(1 << output->connector_id); c->connector_allocator &= ~(1 << output->connector_id);
eglDestroySurface(c->base.egl_display, output->base.egl_surface); gles2_renderer_output_destroy(output_base);
gbm_surface_destroy(output->surface); gbm_surface_destroy(output->surface);
weston_plane_release(&output->fb_plane); weston_plane_release(&output->fb_plane);
@ -875,7 +876,6 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
int ret; int ret;
struct drm_compositor *ec; struct drm_compositor *ec;
struct gbm_surface *surface; struct gbm_surface *surface;
EGLSurface egl_surface;
if (output_base == NULL) { if (output_base == NULL) {
weston_log("output is NULL.\n"); weston_log("output is NULL.\n");
@ -935,14 +935,11 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
return -1; return -1;
} }
egl_surface = gles2_renderer_output_destroy(&output->base);
eglCreateWindowSurface(ec->base.egl_display,
ec->base.egl_config,
surface, NULL);
if (egl_surface == EGL_NO_SURFACE) { if (!gles2_renderer_output_create(&output->base, surface)) {
weston_log("failed to create egl surface\n"); weston_log("failed to create renderer output\n");
goto err; goto err_gbm;
} }
ret = drmModeSetCrtc(ec->drm.fd, ret = drmModeSetCrtc(ec->drm.fd,
@ -951,7 +948,7 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
&output->connector_id, 1, &drm_mode->mode_info); &output->connector_id, 1, &drm_mode->mode_info);
if (ret) { if (ret) {
weston_log("failed to set mode\n"); weston_log("failed to set mode\n");
goto err; goto err_gles2;
} }
/* reset rendering stuff. */ /* reset rendering stuff. */
@ -973,9 +970,7 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
} }
output->next = NULL; output->next = NULL;
eglDestroySurface(ec->base.egl_display, output->base.egl_surface);
gbm_surface_destroy(output->surface); gbm_surface_destroy(output->surface);
output->base.egl_surface = egl_surface;
output->surface = surface; output->surface = surface;
/*update output*/ /*update output*/
@ -984,8 +979,9 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
weston_output_move(&output->base, output->base.x, output->base.y); weston_output_move(&output->base, output->base.x, output->base.y);
return 0; return 0;
err: err_gles2:
eglDestroySurface(ec->base.egl_display, egl_surface); gles2_renderer_output_destroy(&output->base);
err_gbm:
gbm_surface_destroy(surface); gbm_surface_destroy(surface);
return -1; return -1;
} }
@ -1387,15 +1383,12 @@ create_output_for_connector(struct drm_compositor *ec,
goto err_free; goto err_free;
} }
output->base.egl_surface = weston_output_init(&output->base, &ec->base, x, y,
eglCreateWindowSurface(ec->base.egl_display, connector->mmWidth, connector->mmHeight,
ec->base.egl_config, o ? o->transform : WL_OUTPUT_TRANSFORM_NORMAL);
output->surface,
NULL); if (gles2_renderer_output_create(&output->base, output->surface) < 0)
if (output->base.egl_surface == EGL_NO_SURFACE) { goto err_output;
weston_log("failed to create egl surface\n");
goto err_surface;
}
output->cursor_bo[0] = output->cursor_bo[0] =
gbm_bo_create(ec->gbm, 64, 64, GBM_FORMAT_ARGB8888, gbm_bo_create(ec->gbm, 64, 64, GBM_FORMAT_ARGB8888,
@ -1415,10 +1408,6 @@ create_output_for_connector(struct drm_compositor *ec,
output->base.backlight_current = drm_get_backlight(output); output->base.backlight_current = drm_get_backlight(output);
} }
weston_output_init(&output->base, &ec->base, x, y,
connector->mmWidth, connector->mmHeight,
o ? o->transform : WL_OUTPUT_TRANSFORM_NORMAL);
wl_list_insert(ec->base.output_list.prev, &output->base.link); wl_list_insert(ec->base.output_list.prev, &output->base.link);
output->base.origin = output->base.current; output->base.origin = output->base.current;
@ -1445,7 +1434,8 @@ create_output_for_connector(struct drm_compositor *ec,
return 0; return 0;
err_surface: err_output:
weston_output_destroy(&output->base);
gbm_surface_destroy(output->surface); gbm_surface_destroy(output->surface);
err_free: err_free:
wl_list_for_each_safe(drm_mode, next, &output->base.mode_list, wl_list_for_each_safe(drm_mode, next, &output->base.mode_list,
@ -2227,9 +2217,6 @@ drm_compositor_create(struct wl_display *display,
goto err_sprite; goto err_sprite;
} }
if (gles2_renderer_init(&ec->base) < 0)
goto err_egl;
path = NULL; path = NULL;
evdev_input_create(&ec->base, ec->udev, seat); evdev_input_create(&ec->base, ec->udev, seat);
@ -2270,7 +2257,6 @@ err_drm_source:
wl_event_source_remove(ec->drm_source); wl_event_source_remove(ec->drm_source);
wl_list_for_each_safe(weston_seat, next, &ec->base.seat_list, link) wl_list_for_each_safe(weston_seat, next, &ec->base.seat_list, link)
evdev_input_destroy(weston_seat); evdev_input_destroy(weston_seat);
err_egl:
eglMakeCurrent(ec->base.egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, eglMakeCurrent(ec->base.egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
EGL_NO_CONTEXT); EGL_NO_CONTEXT);
eglTerminate(ec->base.egl_display); eglTerminate(ec->base.egl_display);

@ -970,8 +970,7 @@ rpi_output_destroy(struct weston_output *base)
vc_dispmanx_element_remove(update, output->egl_element); vc_dispmanx_element_remove(update, output->egl_element);
vc_dispmanx_update_submit_sync(update); vc_dispmanx_update_submit_sync(update);
eglDestroySurface(output->compositor->base.egl_display, gles2_renderer_output_destroy(base);
output->base.egl_surface);
wl_list_for_each_safe(element, tmp, &output->element_list, link) wl_list_for_each_safe(element, tmp, &output->element_list, link)
rpi_element_destroy(element); rpi_element_destroy(element);
@ -1050,25 +1049,6 @@ rpi_output_create(struct rpi_compositor *compositor)
output->egl_window.width = modeinfo.width; output->egl_window.width = modeinfo.width;
output->egl_window.height = modeinfo.height; output->egl_window.height = modeinfo.height;
output->base.egl_surface =
eglCreateWindowSurface(compositor->base.egl_display,
compositor->base.egl_config,
(EGLNativeWindowType)&output->egl_window,
NULL);
if (output->base.egl_surface == EGL_NO_SURFACE) {
print_egl_error_state();
weston_log("Failed to create output surface.\n");
goto out_dmx;
}
if (!eglSurfaceAttrib(compositor->base.egl_display,
output->base.egl_surface,
EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED)) {
print_egl_error_state();
weston_log("Failed to set swap behaviour to preserved.\n");
goto out_surface;
}
output->base.repaint = rpi_output_repaint; output->base.repaint = rpi_output_repaint;
output->base.destroy = rpi_output_destroy; output->base.destroy = rpi_output_destroy;
if (compositor->max_planes > 0) if (compositor->max_planes > 0)
@ -1104,6 +1084,19 @@ rpi_output_create(struct rpi_compositor *compositor)
weston_output_init(&output->base, &compositor->base, weston_output_init(&output->base, &compositor->base,
0, 0, round(mm_width), round(mm_height), 0, 0, round(mm_width), round(mm_height),
WL_OUTPUT_TRANSFORM_NORMAL); WL_OUTPUT_TRANSFORM_NORMAL);
if (gles2_renderer_output_create(&output->base,
(EGLNativeWindowType)&output->egl_window) < 0)
goto out_output;
if (!eglSurfaceAttrib(compositor->base.egl_display,
gles2_renderer_output_surface(&output->base),
EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED)) {
print_egl_error_state();
weston_log("Failed to set swap behaviour to preserved.\n");
goto out_gles2;
}
wl_list_insert(compositor->base.output_list.prev, &output->base.link); wl_list_insert(compositor->base.output_list.prev, &output->base.link);
weston_log("Raspberry Pi HDMI output %dx%d px\n", weston_log("Raspberry Pi HDMI output %dx%d px\n",
@ -1113,11 +1106,10 @@ rpi_output_create(struct rpi_compositor *compositor)
return 0; return 0;
out_surface: out_gles2:
eglDestroySurface(compositor->base.egl_display, gles2_renderer_output_destroy(&output->base);
output->base.egl_surface); out_output:
weston_output_destroy(&output->base);
out_dmx:
update = vc_dispmanx_update_start(0); update = vc_dispmanx_update_start(0);
vc_dispmanx_element_remove(update, output->egl_element); vc_dispmanx_element_remove(update, output->egl_element);
vc_dispmanx_update_submit_sync(update); vc_dispmanx_update_submit_sync(update);
@ -1512,7 +1504,6 @@ rpi_compositor_create(struct wl_display *display, int argc, char *argv[],
const char *config_file, struct rpi_parameters *param) const char *config_file, struct rpi_parameters *param)
{ {
struct rpi_compositor *compositor; struct rpi_compositor *compositor;
struct weston_output *output;
const char *seat = default_seat; const char *seat = default_seat;
uint32_t key; uint32_t key;
@ -1571,17 +1562,10 @@ rpi_compositor_create(struct wl_display *display, int argc, char *argv[],
if (rpi_output_create(compositor) < 0) if (rpi_output_create(compositor) < 0)
goto out_egl; goto out_egl;
if (gles2_renderer_init(&compositor->base) < 0)
goto out_output;
evdev_input_create(&compositor->base, compositor->udev, seat); evdev_input_create(&compositor->base, compositor->udev, seat);
return &compositor->base; return &compositor->base;
out_output:
wl_list_for_each(output, &compositor->base.output_list, link)
rpi_output_destroy(output);
out_egl: out_egl:
rpi_fini_egl(compositor); rpi_fini_egl(compositor);

@ -317,9 +317,9 @@ static void
wayland_output_destroy(struct weston_output *output_base) wayland_output_destroy(struct weston_output *output_base)
{ {
struct wayland_output *output = (struct wayland_output *) output_base; struct wayland_output *output = (struct wayland_output *) output_base;
struct weston_compositor *ec = output->base.compositor;
eglDestroySurface(ec->egl_display, output->base.egl_surface); gles2_renderer_output_destroy(output_base);
wl_egl_window_destroy(output->parent.egl_window); wl_egl_window_destroy(output->parent.egl_window);
free(output); free(output);
@ -373,13 +373,9 @@ wayland_compositor_create_output(struct wayland_compositor *c,
goto cleanup_output; goto cleanup_output;
} }
output->base.egl_surface = if (gles2_renderer_output_create(&output->base,
eglCreateWindowSurface(c->base.egl_display, c->base.egl_config, output->parent.egl_window) < 0)
output->parent.egl_window, NULL);
if (!output->base.egl_surface) {
weston_log("failed to create window surface\n");
goto cleanup_window; goto cleanup_window;
}
output->parent.shell_surface = output->parent.shell_surface =
wl_shell_get_shell_surface(c->parent.shell, wl_shell_get_shell_surface(c->parent.shell,
@ -846,10 +842,6 @@ wayland_compositor_create(struct wl_display *display,
if (wayland_compositor_create_output(c, width, height) < 0) if (wayland_compositor_create_output(c, width, height) < 0)
goto err_display; goto err_display;
/* requires wayland_compositor_create_output */
if (gles2_renderer_init(&c->base) < 0)
goto err_display;
/* requires gles2_renderer_init */ /* requires gles2_renderer_init */
create_border(c); create_border(c);

@ -390,8 +390,7 @@ x11_output_destroy(struct weston_output *output_base)
wl_list_remove(&output->base.link); wl_list_remove(&output->base.link);
wl_event_source_remove(output->finish_frame_timer); wl_event_source_remove(output->finish_frame_timer);
eglDestroySurface(compositor->base.egl_display, gles2_renderer_output_destroy(output_base);
output->base.egl_surface);
xcb_destroy_window(compositor->conn, output->window); xcb_destroy_window(compositor->conn, output->window);
@ -607,18 +606,6 @@ x11_compositor_create_output(struct x11_compositor *c, int x, int y,
x11_output_wait_for_map(c, output); x11_output_wait_for_map(c, output);
output->base.egl_surface =
eglCreateWindowSurface(c->base.egl_display, c->base.egl_config,
output->window, NULL);
if (!output->base.egl_surface) {
weston_log("failed to create window surface\n");
return NULL;
}
loop = wl_display_get_event_loop(c->base.wl_display);
output->finish_frame_timer =
wl_event_loop_add_timer(loop, finish_frame_handler, output);
output->base.origin = output->base.current; output->base.origin = output->base.current;
output->base.repaint = x11_output_repaint; output->base.repaint = x11_output_repaint;
output->base.destroy = x11_output_destroy; output->base.destroy = x11_output_destroy;
@ -632,6 +619,13 @@ x11_compositor_create_output(struct x11_compositor *c, int x, int y,
weston_output_init(&output->base, &c->base, weston_output_init(&output->base, &c->base,
x, y, width, height, transform); x, y, width, height, transform);
if (gles2_renderer_output_create(&output->base, output->window) < 0)
return NULL;
loop = wl_display_get_event_loop(c->base.wl_display);
output->finish_frame_timer =
wl_event_loop_add_timer(loop, finish_frame_handler, output);
wl_list_insert(c->base.output_list.prev, &output->base.link); wl_list_insert(c->base.output_list.prev, &output->base.link);
weston_log("x11 output %dx%d, window id %d\n", weston_log("x11 output %dx%d, window id %d\n",
@ -1247,9 +1241,6 @@ x11_compositor_create(struct wl_display *display,
x = pixman_region32_extents(&output->base.region)->x2; x = pixman_region32_extents(&output->base.region)->x2;
} }
if (gles2_renderer_init(&c->base) < 0)
goto err_egl;
c->xcb_source = c->xcb_source =
wl_event_loop_add_fd(c->base.input_loop, wl_event_loop_add_fd(c->base.input_loop,
xcb_get_file_descriptor(c->conn), xcb_get_file_descriptor(c->conn),

@ -154,7 +154,8 @@ enum dpms_enum {
struct weston_output { struct weston_output {
uint32_t id; uint32_t id;
EGLSurface egl_surface; void *renderer_state;
struct wl_list link; struct wl_list link;
struct wl_list resource_list; struct wl_list resource_list;
struct wl_global *global; struct wl_global *global;
@ -838,7 +839,12 @@ int
weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode); weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode);
int int
gles2_renderer_init(struct weston_compositor *ec); gles2_renderer_output_create(struct weston_output *output,
EGLNativeWindowType window);
void
gles2_renderer_output_destroy(struct weston_output *output);
EGLSurface
gles2_renderer_output_surface(struct weston_output *output);
void void
gles2_renderer_destroy(struct weston_compositor *ec); gles2_renderer_destroy(struct weston_compositor *ec);

@ -36,6 +36,17 @@ struct gles2_renderer {
int fragment_shader_debug; int fragment_shader_debug;
}; };
struct gles2_output_state {
EGLSurface egl_surface;
};
static inline struct gles2_output_state *
get_output_state(struct weston_output *output)
{
return (struct gles2_output_state *)output->renderer_state;
}
static const char * static const char *
egl_error_string(EGLint code) egl_error_string(EGLint code)
{ {
@ -706,6 +717,7 @@ static void
gles2_renderer_repaint_output(struct weston_output *output, gles2_renderer_repaint_output(struct weston_output *output,
pixman_region32_t *output_damage) pixman_region32_t *output_damage)
{ {
struct gles2_output_state *go = get_output_state(output);
struct weston_compositor *compositor = output->compositor; struct weston_compositor *compositor = output->compositor;
EGLBoolean ret; EGLBoolean ret;
static int errored; static int errored;
@ -718,8 +730,8 @@ gles2_renderer_repaint_output(struct weston_output *output,
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
ret = eglMakeCurrent(compositor->egl_display, output->egl_surface, ret = eglMakeCurrent(compositor->egl_display, go->egl_surface,
output->egl_surface, compositor->egl_context); go->egl_surface, compositor->egl_context);
if (ret == EGL_FALSE) { if (ret == EGL_FALSE) {
if (errored) if (errored)
return; return;
@ -755,7 +767,7 @@ gles2_renderer_repaint_output(struct weston_output *output,
wl_signal_emit(&output->frame_signal, output); wl_signal_emit(&output->frame_signal, output);
ret = eglSwapBuffers(compositor->egl_display, output->egl_surface); ret = eglSwapBuffers(compositor->egl_display, go->egl_surface);
if (ret == EGL_FALSE && !errored) { if (ret == EGL_FALSE && !errored) {
errored = 1; errored = 1;
weston_log("Failed in eglSwapBuffers.\n"); weston_log("Failed in eglSwapBuffers.\n");
@ -1213,6 +1225,57 @@ log_egl_config_info(EGLDisplay egldpy, EGLConfig eglconfig)
weston_log_continue(" unknown\n"); weston_log_continue(" unknown\n");
} }
static int
gles2_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface);
WL_EXPORT int
gles2_renderer_output_create(struct weston_output *output,
EGLNativeWindowType window)
{
struct weston_compositor *ec = output->compositor;
struct gles2_output_state *go = calloc(1, sizeof *go);
if (!go)
return -1;
go->egl_surface =
eglCreateWindowSurface(ec->egl_display,
ec->egl_config,
window, NULL);
if (go->egl_surface == EGL_NO_SURFACE) {
weston_log("failed to create egl surface\n");
free(go);
return -1;
}
if (ec->egl_context == NULL)
if (gles2_renderer_setup(ec, go->egl_surface) < 0) {
free(go);
return -1;
}
output->renderer_state = go;
return 0;
}
WL_EXPORT void
gles2_renderer_output_destroy(struct weston_output *output)
{
struct gles2_output_state *go = get_output_state(output);
eglDestroySurface(output->compositor->egl_display, go->egl_surface);
free(go);
}
WL_EXPORT EGLSurface
gles2_renderer_output_surface(struct weston_output *output)
{
return get_output_state(output)->egl_surface;
}
WL_EXPORT void WL_EXPORT void
gles2_renderer_destroy(struct weston_compositor *ec) gles2_renderer_destroy(struct weston_compositor *ec)
{ {
@ -1274,12 +1337,11 @@ fragment_debug_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
weston_output_damage(output); weston_output_damage(output);
} }
WL_EXPORT int static int
gles2_renderer_init(struct weston_compositor *ec) gles2_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface)
{ {
struct gles2_renderer *renderer; struct gles2_renderer *renderer;
const char *extensions; const char *extensions;
struct weston_output *output;
EGLBoolean ret; EGLBoolean ret;
static const EGLint context_attribs[] = { static const EGLint context_attribs[] = {
@ -1307,10 +1369,8 @@ gles2_renderer_init(struct weston_compositor *ec)
return -1; return -1;
} }
output = container_of(ec->output_list.next, ret = eglMakeCurrent(ec->egl_display, egl_surface,
struct weston_output, link); egl_surface, ec->egl_context);
ret = eglMakeCurrent(ec->egl_display, output->egl_surface,
output->egl_surface, ec->egl_context);
if (ret == EGL_FALSE) { if (ret == EGL_FALSE) {
weston_log("Failed to make EGL context current.\n"); weston_log("Failed to make EGL context current.\n");
print_egl_error_state(); print_egl_error_state();

Loading…
Cancel
Save