Commit 1c0e40d9 authored by Giulio Camuffo's avatar Giulio Camuffo Committed by Pekka Paalanen

drm: port the drm backend to the new init api

Preparing for libweston and for the separation of the code base into
libweston vs. weston the compositor, we must remove all uses
weston_config structures from the backends. We have decided that all
option and config input happens in the compositor (main.c), and
configuration is passed in for the backends as structs.

Most other backends have already converted, and this patch converts the
DRM-backend to the libweston-style init API.

The libweston-style init API includes a header for each backend (here
compositor-drm.h) defining the configuration interface. The compositor
(main.c) prepares a configuration struct to be passed through libweston
core to the backend during initialization.

A complication with the DRM-backend is that outputs can be hotplugged,
and their configuration needs to be fetched from the compositor
(main.c). For this, the config struct contains a callback member. The
output configuration API is subject to change later, this is just a
temporary API to get libweston forward.

As weston_compositor's user_data was not previously used for anything,
and the output configuration callback needs data, the user_data is set
to the 'config' pointer. This pointer is only used in
drm_configure_output() in main.c.

[Bryce: lots of stuff and rebasing]
Signed-off-by: default avatarBryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Quentin Glidic's avatarQuentin Glidic <sardemff7+git@sardemff7.net>
Acked-by: Pekka Paalanen's avatarPekka Paalanen <pekka.paalanen@collabora.co.uk>
Tested-by: default avatarBenoit Gschwind <gschwind@gnu-log.net>
[Pekka: write commit message]
[Pekka: squash in "drm: Don't hang onto the backend config object
post-backend_init" from Bryce Harrington]
[Pekka: drop the compositor.h hunk]
[Pekka: do not #include inside extern "C"]
[Pekka: remove incorrect comment about weston_drm_backend_config
ownership.]
Signed-off-by: Pekka Paalanen's avatarPekka Paalanen <pekka.paalanen@collabora.co.uk>
parent 59987fa1
......@@ -72,11 +72,12 @@ weston_SOURCES = \
src/log.c \
src/compositor.c \
src/compositor.h \
src/compositor-headless.h \
src/compositor-drm.h \
src/compositor-fbdev.h \
src/compositor-headless.h \
src/compositor-rdp.h \
src/compositor-x11.h \
src/compositor-wayland.h \
src/compositor-x11.h \
src/input.c \
src/data-device.c \
src/screenshooter.c \
......@@ -213,11 +214,12 @@ westonincludedir = $(includedir)/weston
westoninclude_HEADERS = \
src/version.h \
src/compositor.h \
src/compositor-headless.h \
src/compositor-drm.h \
src/compositor-fbdev.h \
src/compositor-headless.h \
src/compositor-rdp.h \
src/compositor-x11.h \
src/compositor-wayland.h \
src/compositor-x11.h \
src/timeline-object.h \
shared/matrix.h \
shared/config-parser.h \
......@@ -289,6 +291,7 @@ drm_backend_la_CFLAGS = \
$(AM_CFLAGS)
drm_backend_la_SOURCES = \
src/compositor-drm.c \
src/compositor-drm.h \
$(INPUT_BACKEND_SOURCES) \
shared/helpers.h \
shared/timespec-util.h \
......
This diff is collapsed.
/*
* Copyright © 2008-2011 Kristian Høgsberg
* Copyright © 2011 Intel Corporation
* Copyright © 2015 Giulio Camuffo
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef WESTON_COMPOSITOR_DRM_H
#define WESTON_COMPOSITOR_DRM_H
#include "compositor.h"
#ifdef __cplusplus
extern "C" {
#endif
#define WESTON_DRM_BACKEND_CONFIG_VERSION 1
enum weston_drm_backend_output_mode {
/** The output is disabled */
WESTON_DRM_BACKEND_OUTPUT_OFF,
/** The output will use the current active mode */
WESTON_DRM_BACKEND_OUTPUT_CURRENT,
/** The output will use the preferred mode. A modeline can be provided
* by setting weston_backend_output_config::modeline in the form of
* "WIDTHxHEIGHT" or in the form of an explicit modeline calculated
* using e.g. the cvt tool. If a valid modeline is supplied it will be
* used, if invalid or NULL the preferred available mode will be used. */
WESTON_DRM_BACKEND_OUTPUT_PREFERRED,
};
struct weston_drm_backend_output_config {
struct weston_backend_output_config base;
/** The pixel format to be used by the output. Valid values are:
* - NULL - The format set at backend creation time will be used;
* - "xrgb8888";
* - "rgb565"
* - "xrgb2101010"
*/
char *gbm_format;
/** The seat to be used by the output. Set to NULL to use the
* default seat. */
char *seat;
/** The modeline to be used by the output. Refer to the documentation
* of WESTON_DRM_BACKEND_OUTPUT_PREFERRED for details. */
char *modeline;
};
/** The backend configuration struct.
*
* weston_drm_backend_config contains the configuration used by a DRM
* backend.
*/
struct weston_drm_backend_config {
struct weston_backend_config base;
/** The connector id of the output to be initialized.
*
* A value of 0 will enable all available outputs.
*/
int connector;
/** The tty to be used. Set to 0 to use the current tty. */
int tty;
/** Whether to use the pixman renderer instead of the OpenGL ES renderer. */
bool use_pixman;
/** The seat to be used for input and output.
*
* If NULL the default "seat0" will be used. The backend will
* take ownership of the seat_id pointer and will free it on
* backend destruction.
*/
char *seat_id;
/** The pixel format of the framebuffer to be used.
*
* Valid values are:
* - NULL - The default format ("xrgb8888") will be used;
* - "xrgb8888";
* - "rgb565"
* - "xrgb2101010"
* The backend will take ownership of the format pointer and will free
* it on backend destruction.
*/
char *gbm_format;
/** Callback used to configure the outputs.
*
* This function will be called by the backend when a new DRM
* output needs to be configured.
*/
enum weston_drm_backend_output_mode
(*configure_output)(struct weston_compositor *compositor,
bool use_current_mode,
const char *name,
struct weston_drm_backend_output_config *output_config);
bool use_current_mode;
};
#ifdef __cplusplus
}
#endif
#endif /* WESTON_COMPOSITOR_DRM_H */
......@@ -47,6 +47,7 @@
#include "git-version.h"
#include "version.h"
#include "compositor-drm.h"
#include "compositor-headless.h"
#include "compositor-rdp.h"
#include "compositor-fbdev.h"
......@@ -688,6 +689,83 @@ load_backend_new(struct weston_compositor *compositor, const char *backend,
return backend_init(compositor, NULL, NULL, NULL, config_base);
}
static enum weston_drm_backend_output_mode
drm_configure_output(struct weston_compositor *c,
bool use_current_mode,
const char *name,
struct weston_drm_backend_output_config *config)
{
struct weston_config *wc = weston_compositor_get_user_data(c);
struct weston_config_section *section;
char *s;
int scale;
enum weston_drm_backend_output_mode mode =
WESTON_DRM_BACKEND_OUTPUT_PREFERRED;
section = weston_config_get_section(wc, "output", "name", name);
weston_config_section_get_string(section, "mode", &s, "preferred");
if (strcmp(s, "off") == 0) {
free(s);
return WESTON_DRM_BACKEND_OUTPUT_OFF;
}
if (use_current_mode || strcmp(s, "current") == 0) {
mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT;
} else if (strcmp(s, "preferred") != 0) {
config->modeline = s;
s = NULL;
}
free(s);
weston_config_section_get_int(section, "scale", &scale, 1);
config->base.scale = scale >= 1 ? scale : 1;
weston_config_section_get_string(section, "transform", &s, "normal");
if (weston_parse_transform(s, &config->base.transform) < 0)
weston_log("Invalid transform \"%s\" for output %s\n",
s, name);
free(s);
weston_config_section_get_string(section,
"gbm-format", &config->gbm_format, NULL);
weston_config_section_get_string(section, "seat", &config->seat, "");
return mode;
}
static int
load_drm_backend(struct weston_compositor *c, const char *backend,
int *argc, char **argv, struct weston_config *wc)
{
struct weston_drm_backend_config config = {{ 0, }};
struct weston_config_section *section;
int ret = 0;
const struct weston_option options[] = {
{ WESTON_OPTION_INTEGER, "connector", 0, &config.connector },
{ WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
{ WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
{ WESTON_OPTION_BOOLEAN, "current-mode", 0, &config.use_current_mode },
{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
};
parse_options(options, ARRAY_LENGTH(options), argc, argv);
section = weston_config_get_section(wc, "core", NULL, NULL);
weston_config_section_get_string(section,
"gbm-format", &config.gbm_format,
NULL);
config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
config.base.struct_size = sizeof(struct weston_drm_backend_config);
config.configure_output = drm_configure_output;
ret = load_backend_new(c, backend, &config.base);
free(config.gbm_format);
free(config.seat_id);
return ret;
}
static int
load_headless_backend(struct weston_compositor *c, char const * backend,
int *argc, char **argv, struct weston_config *wc)
......@@ -959,11 +1037,11 @@ load_backend(struct weston_compositor *compositor, const char *backend,
return load_rdp_backend(compositor, backend, argc, argv, config);
else if (strstr(backend, "fbdev-backend.so"))
return load_fbdev_backend(compositor, backend, argc, argv, config);
else if (strstr(backend, "drm-backend.so"))
return load_drm_backend(compositor, backend, argc, argv, config);
else if (strstr(backend, "x11-backend.so"))
return load_x11_backend(compositor, backend, argc, argv, config);
#if 0
else if (strstr(backend, "drm-backend.so"))
return load_drm_backend(compositor, backend, argc, argv, config);
else if (strstr(backend, "wayland-backend.so"))
return load_wayland_backend(compositor, backend, argc, argv, config);
else if (strstr(backend, "rpi-backend.so"))
......@@ -1064,7 +1142,7 @@ int main(int argc, char *argv[])
backend = weston_choose_default_backend();
}
ec = weston_compositor_create(display, NULL);
ec = weston_compositor_create(display, config);
if (ec == NULL) {
weston_log("fatal: failed to create compositor\n");
goto out;
......
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