backend-wayland: Prepare for more renderers, reject no-op
Turn the Pixman/GL if/else conditionals into switch cases to make it easier to add support for other renderers in the future. Also makes sure that weston --backend=wayland --renderer=noop fails with an error message instead of segfaulting. Signed-off-by: Philipp Zabel <philipp.zabel@gmail.com>
This commit is contained in:
parent
ce113969e3
commit
1c262efd70
@ -693,15 +693,20 @@ wayland_output_disable(struct weston_output *base)
|
|||||||
|
|
||||||
wayland_output_destroy_shm_buffers(output);
|
wayland_output_destroy_shm_buffers(output);
|
||||||
|
|
||||||
if (renderer->type == WESTON_RENDERER_PIXMAN) {
|
switch (renderer->type) {
|
||||||
|
case WESTON_RENDERER_PIXMAN:
|
||||||
renderer->pixman->output_destroy(&output->base);
|
renderer->pixman->output_destroy(&output->base);
|
||||||
|
break;
|
||||||
#ifdef ENABLE_EGL
|
#ifdef ENABLE_EGL
|
||||||
} else {
|
case WESTON_RENDERER_GL:
|
||||||
weston_gl_borders_fini(&output->gl.borders, &output->base);
|
weston_gl_borders_fini(&output->gl.borders, &output->base);
|
||||||
|
|
||||||
renderer->gl->output_destroy(&output->base);
|
renderer->gl->output_destroy(&output->base);
|
||||||
wl_egl_window_destroy(output->gl.egl_window);
|
wl_egl_window_destroy(output->gl.egl_window);
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
default:
|
||||||
|
unreachable("invalid renderer");
|
||||||
}
|
}
|
||||||
|
|
||||||
wayland_backend_destroy_output_surface(output);
|
wayland_backend_destroy_output_surface(output);
|
||||||
@ -1021,17 +1026,22 @@ wayland_output_switch_mode_finish(struct wayland_output *output)
|
|||||||
{
|
{
|
||||||
struct weston_renderer *renderer = output->base.compositor->renderer;
|
struct weston_renderer *renderer = output->base.compositor->renderer;
|
||||||
|
|
||||||
if (renderer->type == WESTON_RENDERER_PIXMAN) {
|
switch (renderer->type) {
|
||||||
|
case WESTON_RENDERER_PIXMAN:
|
||||||
renderer->pixman->output_destroy(&output->base);
|
renderer->pixman->output_destroy(&output->base);
|
||||||
if (wayland_output_init_pixman_renderer(output) < 0)
|
if (wayland_output_init_pixman_renderer(output) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
break;
|
||||||
#ifdef ENABLE_EGL
|
#ifdef ENABLE_EGL
|
||||||
} else {
|
case WESTON_RENDERER_GL:
|
||||||
renderer->gl->output_destroy(&output->base);
|
renderer->gl->output_destroy(&output->base);
|
||||||
wl_egl_window_destroy(output->gl.egl_window);
|
wl_egl_window_destroy(output->gl.egl_window);
|
||||||
if (wayland_output_init_gl_renderer(output) < 0)
|
if (wayland_output_init_gl_renderer(output) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
default:
|
||||||
|
unreachable("invalid renderer");
|
||||||
}
|
}
|
||||||
|
|
||||||
weston_output_schedule_repaint(&output->base);
|
weston_output_schedule_repaint(&output->base);
|
||||||
@ -1245,6 +1255,7 @@ wayland_backend_create_output_surface(struct wayland_output *output)
|
|||||||
static int
|
static int
|
||||||
wayland_output_enable(struct weston_output *base)
|
wayland_output_enable(struct weston_output *base)
|
||||||
{
|
{
|
||||||
|
const struct weston_renderer *renderer = base->compositor->renderer;
|
||||||
struct wayland_output *output = to_wayland_output(base);
|
struct wayland_output *output = to_wayland_output(base);
|
||||||
struct wayland_backend *b;
|
struct wayland_backend *b;
|
||||||
enum mode_status mode_status;
|
enum mode_status mode_status;
|
||||||
@ -1269,18 +1280,23 @@ wayland_output_enable(struct weston_output *base)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (base->compositor->renderer->type == WESTON_RENDERER_PIXMAN) {
|
switch (renderer->type) {
|
||||||
|
case WESTON_RENDERER_PIXMAN:
|
||||||
if (wayland_output_init_pixman_renderer(output) < 0)
|
if (wayland_output_init_pixman_renderer(output) < 0)
|
||||||
goto err_output;
|
goto err_output;
|
||||||
|
|
||||||
output->base.repaint = wayland_output_repaint_pixman;
|
output->base.repaint = wayland_output_repaint_pixman;
|
||||||
|
break;
|
||||||
#ifdef ENABLE_EGL
|
#ifdef ENABLE_EGL
|
||||||
} else {
|
case WESTON_RENDERER_GL:
|
||||||
if (wayland_output_init_gl_renderer(output) < 0)
|
if (wayland_output_init_gl_renderer(output) < 0)
|
||||||
goto err_output;
|
goto err_output;
|
||||||
|
|
||||||
output->base.repaint = wayland_output_repaint_gl;
|
output->base.repaint = wayland_output_repaint_gl;
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
default:
|
||||||
|
unreachable("invalid renderer");
|
||||||
}
|
}
|
||||||
|
|
||||||
output->base.start_repaint_loop = wayland_output_start_repaint_loop;
|
output->base.start_repaint_loop = wayland_output_start_repaint_loop;
|
||||||
@ -2900,8 +2916,9 @@ wayland_backend_create(struct weston_compositor *compositor,
|
|||||||
b->formats_count = ARRAY_LENGTH(wayland_formats);
|
b->formats_count = ARRAY_LENGTH(wayland_formats);
|
||||||
b->formats = pixel_format_get_array(wayland_formats, b->formats_count);
|
b->formats = pixel_format_get_array(wayland_formats, b->formats_count);
|
||||||
|
|
||||||
if (renderer == WESTON_RENDERER_AUTO ||
|
switch (renderer) {
|
||||||
renderer == WESTON_RENDERER_GL) {
|
case WESTON_RENDERER_AUTO:
|
||||||
|
case WESTON_RENDERER_GL: {
|
||||||
const struct gl_renderer_display_options options = {
|
const struct gl_renderer_display_options options = {
|
||||||
.egl_platform = EGL_PLATFORM_WAYLAND_KHR,
|
.egl_platform = EGL_PLATFORM_WAYLAND_KHR,
|
||||||
.egl_native_display = b->parent.wl_display,
|
.egl_native_display = b->parent.wl_display,
|
||||||
@ -2914,22 +2931,28 @@ wayland_backend_create(struct weston_compositor *compositor,
|
|||||||
WESTON_RENDERER_GL,
|
WESTON_RENDERER_GL,
|
||||||
&options.base) < 0) {
|
&options.base) < 0) {
|
||||||
weston_log("Failed to initialize the GL renderer");
|
weston_log("Failed to initialize the GL renderer");
|
||||||
if (renderer == WESTON_RENDERER_AUTO) {
|
if (renderer == WESTON_RENDERER_GL) {
|
||||||
weston_log_continue("; falling back to Pixman.\n");
|
weston_log_continue("\n");
|
||||||
renderer = WESTON_RENDERER_PIXMAN;
|
|
||||||
} else {
|
|
||||||
goto err_display;
|
goto err_display;
|
||||||
}
|
}
|
||||||
|
renderer = WESTON_RENDERER_PIXMAN;
|
||||||
}
|
}
|
||||||
|
if (renderer != WESTON_RENDERER_PIXMAN)
|
||||||
|
break;
|
||||||
|
weston_log_continue("; falling back to Pixman.\n");
|
||||||
}
|
}
|
||||||
|
/* fallthrough */
|
||||||
if (renderer == WESTON_RENDERER_PIXMAN) {
|
case WESTON_RENDERER_PIXMAN:
|
||||||
if (weston_compositor_init_renderer(compositor,
|
if (weston_compositor_init_renderer(compositor,
|
||||||
WESTON_RENDERER_PIXMAN,
|
WESTON_RENDERER_PIXMAN,
|
||||||
NULL) < 0) {
|
NULL) < 0) {
|
||||||
weston_log("Failed to initialize pixman renderer\n");
|
weston_log("Failed to initialize pixman renderer\n");
|
||||||
goto err_display;
|
goto err_display;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
weston_log("Unsupported renderer requested\n");
|
||||||
|
goto err_display;
|
||||||
}
|
}
|
||||||
|
|
||||||
b->base.shutdown = wayland_shutdown;
|
b->base.shutdown = wayland_shutdown;
|
||||||
|
Loading…
Reference in New Issue
Block a user