fbdev-backend: refactor configuration API

Implement a "well" defined API to configure the fbdev backend.
Following and according to discussion about libweston API

The output transform configuration is moved into weston and added to the
fbdev configuration structure.

Signed-off-by: Benoit Gschwind <gschwind@gnu-log.net>
[Pekka: squashed two patches and rebased.]
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
Benoit Gschwind 2016-04-27 23:56:42 +02:00 committed by Pekka Paalanen
parent e5b5659240
commit 934e89a749
4 changed files with 121 additions and 38 deletions

View File

@ -72,7 +72,8 @@ weston_SOURCES = \
src/log.c \
src/compositor.c \
src/compositor.h \
src/compositor-headless.h \
src/compositor-headless.h \
src/compositor-fbdev.h \
src/compositor-rdp.h \
src/input.c \
src/data-device.c \
@ -211,6 +212,7 @@ westoninclude_HEADERS = \
src/version.h \
src/compositor.h \
src/compositor-headless.h \
src/compositor-fbdev.h \
src/compositor-rdp.h \
src/timeline-object.h \
shared/matrix.h \
@ -379,6 +381,7 @@ fbdev_backend_la_CFLAGS = \
$(AM_CFLAGS)
fbdev_backend_la_SOURCES = \
src/compositor-fbdev.c \
src/compositor-fbdev.h \
shared/helpers.h \
$(INPUT_BACKEND_SOURCES)
endif

View File

@ -44,6 +44,7 @@
#include "shared/helpers.h"
#include "compositor.h"
#include "compositor-fbdev.h"
#include "launcher-util.h"
#include "pixman-renderer.h"
#include "libinput-seat.h"
@ -58,6 +59,7 @@ struct fbdev_backend {
struct udev *udev;
struct udev_input input;
int use_pixman;
uint32_t output_transform;
struct wl_listener session_listener;
};
@ -93,12 +95,6 @@ struct fbdev_output {
uint8_t depth;
};
struct fbdev_parameters {
int tty;
char *device;
int use_gl;
};
struct gl_renderer_interface *gl_renderer;
static const char default_seat[] = "seat0";
@ -457,11 +453,8 @@ fbdev_output_create(struct fbdev_backend *backend,
const char *device)
{
struct fbdev_output *output;
struct weston_config_section *section;
int fb_fd;
struct wl_event_loop *loop;
uint32_t config_transform;
char *s;
weston_log("Creating fbdev output.\n");
@ -506,19 +499,10 @@ fbdev_output_create(struct fbdev_backend *backend,
output->base.model = output->fb_info.id;
output->base.name = strdup("fbdev");
section = weston_config_get_section(backend->compositor->config,
"output", "name",
output->base.name);
weston_config_section_get_string(section, "transform", &s, "normal");
if (weston_parse_transform(s, &config_transform) < 0)
weston_log("Invalid transform \"%s\" for output %s\n",
s, output->base.name);
free(s);
weston_output_init(&output->base, backend->compositor,
0, 0, output->fb_info.width_mm,
output->fb_info.height_mm,
config_transform,
backend->output_transform,
1);
if (backend->use_pixman) {
@ -747,7 +731,7 @@ fbdev_restore(struct weston_compositor *compositor)
static struct fbdev_backend *
fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv[],
struct weston_config *config,
struct fbdev_parameters *param)
struct weston_fbdev_backend_config *param)
{
struct fbdev_backend *backend;
const char *seat_id = default_seat;
@ -786,6 +770,7 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv
backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
backend->use_pixman = !param->use_gl;
backend->output_transform = param->output_transform;
weston_setup_vt_switch_bindings(compositor);
@ -830,29 +815,36 @@ out_compositor:
return NULL;
}
static void
config_init_to_defaults(struct weston_fbdev_backend_config *config)
{
/* TODO: Ideally, available frame buffers should be enumerated using
* udev, rather than passing a device node in as a parameter. */
config->tty = 0; /* default to current tty */
config->device = "/dev/fb0"; /* default frame buffer */
config->use_gl = 0;
config->output_transform = WL_OUTPUT_TRANSFORM_NORMAL;
}
WL_EXPORT int
backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
struct weston_config *config,
struct weston_config *wc,
struct weston_backend_config *config_base)
{
struct fbdev_backend *b;
/* TODO: Ideally, available frame buffers should be enumerated using
* udev, rather than passing a device node in as a parameter. */
struct fbdev_parameters param = {
.tty = 0, /* default to current tty */
.device = "/dev/fb0", /* default frame buffer */
.use_gl = 0,
};
struct weston_fbdev_backend_config config = {{ 0, }};
const struct weston_option fbdev_options[] = {
{ WESTON_OPTION_INTEGER, "tty", 0, &param.tty },
{ WESTON_OPTION_STRING, "device", 0, &param.device },
{ WESTON_OPTION_BOOLEAN, "use-gl", 0, &param.use_gl },
};
if (config_base == NULL ||
config_base->struct_version != WESTON_FBDEV_BACKEND_CONFIG_VERSION ||
config_base->struct_size > sizeof(struct weston_fbdev_backend_config)) {
weston_log("fbdev backend config structure is invalid\n");
return -1;
}
parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
config_init_to_defaults(&config);
memcpy(&config, config_base, config_base->struct_size);
b = fbdev_backend_create(compositor, argc, argv, config, &param);
b = fbdev_backend_create(compositor, argc, argv, wc, &config);
if (b == NULL)
return -1;
return 0;

51
src/compositor-fbdev.h Normal file
View File

@ -0,0 +1,51 @@
/*
* Copyright © 2016 Benoit Gschwind
*
* 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_FBDEV_H
#define WESTON_COMPOSITOR_FBDEV_H
#ifdef __cplusplus
extern "C" {
#endif
#include "compositor.h"
#define WESTON_FBDEV_BACKEND_CONFIG_VERSION 1
struct weston_fbdev_backend_config {
struct weston_backend_config base;
int tty;
char *device;
int use_gl;
uint32_t output_transform;
};
#ifdef __cplusplus
}
#endif
#endif /* WESTON_COMPOSITOR_FBDEV_H */

View File

@ -49,6 +49,7 @@
#include "compositor-headless.h"
#include "compositor-rdp.h"
#include "compositor-fbdev.h"
static struct wl_list child_process_list;
static struct weston_compositor *segv_compositor;
@ -767,6 +768,42 @@ load_rdp_backend(struct weston_compositor *c, char const * backend,
return ret;
}
static int
load_fbdev_backend(struct weston_compositor *c, char const * backend,
int *argc, char **argv, struct weston_config *wc)
{
struct weston_fbdev_backend_config config = {{ 0, }};
struct weston_config_section *section;
char *s = NULL;
int ret = 0;
const struct weston_option fbdev_options[] = {
{ WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
{ WESTON_OPTION_STRING, "device", 0, &config.device },
{ WESTON_OPTION_BOOLEAN, "use-gl", 0, &config.use_gl },
};
parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
if (!config.device)
config.device = strdup("/dev/fb0");
section = weston_config_get_section(wc, "output", "name", "fbdev");
weston_config_section_get_string(section, "transform", &s, "normal");
if (weston_parse_transform(s, &config.output_transform) < 0)
weston_log("Invalid transform \"%s\" for output fbdev\n", s);
free(s);
config.base.struct_version = WESTON_FBDEV_BACKEND_CONFIG_VERSION;
config.base.struct_size = sizeof(struct weston_fbdev_backend_config);
/* load the actual wayland backend and configure it */
ret = load_backend_new(c, backend, &config.base);
free(config.device);
return ret;
}
static int
load_backend(struct weston_compositor *compositor, const char *backend,
int *argc, char **argv, struct weston_config *config)
@ -775,6 +812,8 @@ load_backend(struct weston_compositor *compositor, const char *backend,
return load_headless_backend(compositor, backend, argc, argv, config);
else if (strstr(backend, "rdp-backend.so"))
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);
#if 0
else if (strstr(backend, "drm-backend.so"))
return load_drm_backend(compositor, backend, argc, argv, config);
@ -782,8 +821,6 @@ load_backend(struct weston_compositor *compositor, const char *backend,
return load_wayland_backend(compositor, backend, argc, argv, config);
else if (strstr(backend, "x11-backend.so"))
return load_x11_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, "rpi-backend.so"))
return load_rpi_backend(compositor, backend, argc, argv, config);
#endif