Add support for having different GBM formats for different outputs
The gbm-format configuration option can now be specified per-output as
well as in the core config section. If it is not specified it will
default to the format specified in the core section. The
EGL_MESA_configless_context extension is required for this to work. If
this extension is available it will create a context without an
EGLConfig and then it will potentially use a different EGLConfig for
each output.
The gl-renderer interface has been changed so that it takes the EGL
attributes and visual ID in the create_output function as well as in
the create function.
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index e45f47d..3f584a6 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -147,6 +147,7 @@
drmModeCrtcPtr original_crtc;
struct drm_edid edid;
drmModePropertyPtr dpms_prop;
+ uint32_t format;
int vblank_pending;
int page_flip_pending;
@@ -420,8 +421,6 @@
drm_output_check_scanout_format(struct drm_output *output,
struct weston_surface *es, struct gbm_bo *bo)
{
- struct drm_compositor *c =
- (struct drm_compositor *) output->base.compositor;
uint32_t format;
pixman_region32_t r;
@@ -442,7 +441,7 @@
pixman_region32_fini(&r);
}
- if (c->format == format)
+ if (output->format == format)
return format;
return 0;
@@ -507,7 +506,7 @@
return;
}
- output->next = drm_fb_get_from_bo(bo, c, c->format);
+ output->next = drm_fb_get_from_bo(bo, c, output->format);
if (!output->next) {
weston_log("failed to get drm_fb for bo\n");
gbm_surface_release_buffer(output->surface, bo);
@@ -1528,12 +1527,13 @@
static int
drm_output_init_egl(struct drm_output *output, struct drm_compositor *ec)
{
+ EGLint format = output->format;
int i, flags;
output->surface = gbm_surface_create(ec->gbm,
output->base.current_mode->width,
output->base.current_mode->height,
- ec->format,
+ format,
GBM_BO_USE_SCANOUT |
GBM_BO_USE_RENDERING);
if (!output->surface) {
@@ -1541,7 +1541,9 @@
return -1;
}
- if (gl_renderer->output_create(&output->base, output->surface) < 0) {
+ if (gl_renderer->output_create(&output->base, output->surface,
+ gl_renderer->opaque_attribs,
+ &format) < 0) {
weston_log("failed to create gl renderer output state\n");
gbm_surface_destroy(output->surface);
return -1;
@@ -1853,6 +1855,35 @@
}
static int
+get_gbm_format_from_section(struct weston_config_section *section,
+ uint32_t default_value,
+ uint32_t *format)
+{
+ char *s;
+ int ret = 0;
+
+ weston_config_section_get_string(section,
+ "gbm-format", &s, NULL);
+
+ if (s == NULL)
+ *format = default_value;
+ else if (strcmp(s, "xrgb8888") == 0)
+ *format = GBM_FORMAT_XRGB8888;
+ else if (strcmp(s, "rgb565") == 0)
+ *format = GBM_FORMAT_RGB565;
+ else if (strcmp(s, "xrgb2101010") == 0)
+ *format = GBM_FORMAT_XRGB2101010;
+ else {
+ weston_log("fatal: unrecognized pixel format: %s\n", s);
+ ret = -1;
+ }
+
+ free(s);
+
+ return ret;
+}
+
+static int
create_output_for_connector(struct drm_compositor *ec,
drmModeRes *resources,
drmModeConnector *connector,
@@ -1919,6 +1950,11 @@
transform = parse_transform(s, output->base.name);
free(s);
+ if (get_gbm_format_from_section(section,
+ ec->format,
+ &output->format) == -1)
+ output->format = ec->format;
+
weston_config_section_get_string(section, "seat", &s, "");
setup_output_seat_constraint(ec, &output->base, s);
free(s);
@@ -2663,7 +2699,6 @@
struct udev_device *drm_device;
struct wl_event_loop *loop;
const char *path;
- char *s;
uint32_t key;
weston_log("initializing drm backend\n");
@@ -2677,20 +2712,10 @@
ec->sprites_are_broken = 1;
section = weston_config_get_section(config, "core", NULL, NULL);
- weston_config_section_get_string(section,
- "gbm-format", &s, "xrgb8888");
- if (strcmp(s, "xrgb8888") == 0)
- ec->format = GBM_FORMAT_XRGB8888;
- else if (strcmp(s, "rgb565") == 0)
- ec->format = GBM_FORMAT_RGB565;
- else if (strcmp(s, "xrgb2101010") == 0)
- ec->format = GBM_FORMAT_XRGB2101010;
- else {
- weston_log("fatal: unrecognized pixel format: %s\n", s);
- free(s);
+ if (get_gbm_format_from_section(section,
+ GBM_FORMAT_XRGB8888,
+ &ec->format) == -1)
goto err_base;
- }
- free(s);
ec->use_pixman = param->use_pixman;