diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2014-09-19 14:05:52 +0200 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2014-09-19 14:05:52 +0200 |
commit | 650c5444273993f969b9cd7df9add6ab2df0414e (patch) | |
tree | 042d7d3412fff2b44e5328df70e143cba1acc231 /src/libsystemd-terminal/grdev-internal.h | |
parent | 2ec3ff668ff03410e94cfef8e3ee9384a8222211 (diff) |
terminal: add graphics interface
The grdev layer provides graphics-device access via the
libsystemd-terminal library. It will be used by all terminal helpers to
actually access display hardware.
Like idev, the grdev layer is built around session objects. On each
session object you add/remove graphics devices as they appear and vanish.
Any device type can be supported via specific card-backends. The exported
grdev API hides any device details.
Graphics devices are represented by "cards". Those are hidden in the
session and any pipe-configuration is automatically applied. Out of those,
we configure displays which are then exported to the API user. Displays
are meant as lowest hardware entity available outside of grdev. The
underlying pipe configuration is fully hidden and not accessible from the
outside. The grdev tiling layer allows almost arbitrary setups out of
multiple pipes, but so far we only use a small subset of this. More will
follow.
A grdev-display is meant to represent real connected displays/monitors.
The upper level screen arrangements are user policy and not controlled by
grdev. Applications are free to apply any policy they want.
Real card-backends will follow in later patches.
Diffstat (limited to 'src/libsystemd-terminal/grdev-internal.h')
-rw-r--r-- | src/libsystemd-terminal/grdev-internal.h | 237 |
1 files changed, 237 insertions, 0 deletions
diff --git a/src/libsystemd-terminal/grdev-internal.h b/src/libsystemd-terminal/grdev-internal.h new file mode 100644 index 0000000000..7e69c49b63 --- /dev/null +++ b/src/libsystemd-terminal/grdev-internal.h @@ -0,0 +1,237 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com> + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#pragma once + +#include <inttypes.h> +#include <stdbool.h> +#include <stdlib.h> +#include <systemd/sd-bus.h> +#include <systemd/sd-event.h> +#include "grdev.h" +#include "hashmap.h" +#include "list.h" +#include "util.h" + +typedef struct grdev_tile grdev_tile; +typedef struct grdev_display_cache grdev_display_cache; + +typedef struct grdev_pipe_vtable grdev_pipe_vtable; +typedef struct grdev_pipe grdev_pipe; +typedef struct grdev_card_vtable grdev_card_vtable; +typedef struct grdev_card grdev_card; + +/* + * Displays + */ + +enum { + GRDEV_TILE_LEAF, + GRDEV_TILE_NODE, + GRDEV_TILE_CNT +}; + +struct grdev_tile { + LIST_FIELDS(grdev_tile, childs_by_node); + grdev_tile *parent; + grdev_display *display; + + uint32_t x; + uint32_t y; + unsigned int rotate; + unsigned int flip; + uint32_t cache_w; + uint32_t cache_h; + + unsigned int type; + + union { + struct { + grdev_pipe *pipe; + } leaf; + + struct { + size_t n_childs; + LIST_HEAD(grdev_tile, child_list); + } node; + }; +}; + +int grdev_tile_new_leaf(grdev_tile **out, grdev_pipe *pipe); +int grdev_tile_new_node(grdev_tile **out); +grdev_tile *grdev_tile_free(grdev_tile *tile); + +DEFINE_TRIVIAL_CLEANUP_FUNC(grdev_tile*, grdev_tile_free); + +struct grdev_display { + grdev_session *session; + char *name; + + size_t n_leafs; + grdev_tile *tile; + + size_t n_pipes; + size_t max_pipes; + + uint32_t width; + uint32_t height; + + struct grdev_display_cache { + grdev_pipe *pipe; + grdev_display_target target; + + bool incomplete : 1; + } *pipes; + + bool enabled : 1; + bool public : 1; + bool modified : 1; + bool framed : 1; +}; + +grdev_display *grdev_find_display(grdev_session *session, const char *name); + +int grdev_display_new(grdev_display **out, grdev_session *session, const char *name); +grdev_display *grdev_display_free(grdev_display *display); + +DEFINE_TRIVIAL_CLEANUP_FUNC(grdev_display*, grdev_display_free); + +/* + * Pipes + */ + +struct grdev_pipe_vtable { + void (*free) (grdev_pipe *pipe); + void (*enable) (grdev_pipe *pipe); + void (*disable) (grdev_pipe *pipe); + grdev_fb *(*target) (grdev_pipe *pipe); +}; + +struct grdev_pipe { + const grdev_pipe_vtable *vtable; + grdev_card *card; + char *name; + + grdev_tile *tile; + grdev_display_cache *cache; + + uint32_t width; + uint32_t height; + + size_t max_fbs; + grdev_fb *front; + grdev_fb *back; + grdev_fb **fbs; + + bool enabled : 1; + bool running : 1; + bool flip : 1; + bool flipping : 1; +}; + +#define GRDEV_PIPE_INIT(_vtable, _card) ((grdev_pipe){ \ + .vtable = (_vtable), \ + .card = (_card), \ + }) + +grdev_pipe *grdev_find_pipe(grdev_card *card, const char *name); + +int grdev_pipe_add(grdev_pipe *pipe, const char *name, size_t n_fbs); +grdev_pipe *grdev_pipe_free(grdev_pipe *pipe); + +DEFINE_TRIVIAL_CLEANUP_FUNC(grdev_pipe*, grdev_pipe_free); + +void grdev_pipe_ready(grdev_pipe *pipe, bool running); +void grdev_pipe_frame(grdev_pipe *pipe); + +/* + * Cards + */ + +struct grdev_card_vtable { + void (*free) (grdev_card *card); + void (*enable) (grdev_card *card); + void (*disable) (grdev_card *card); + void (*commit) (grdev_card *card); + void (*restore) (grdev_card *card); +}; + +struct grdev_card { + const grdev_card_vtable *vtable; + grdev_session *session; + char *name; + + Hashmap *pipe_map; + + bool enabled : 1; + bool modified : 1; +}; + +#define GRDEV_CARD_INIT(_vtable, _session) ((grdev_card){ \ + .vtable = (_vtable), \ + .session = (_session), \ + }) + +grdev_card *grdev_find_card(grdev_session *session, const char *name); + +int grdev_card_add(grdev_card *card, const char *name); +grdev_card *grdev_card_free(grdev_card *card); + +DEFINE_TRIVIAL_CLEANUP_FUNC(grdev_card*, grdev_card_free); + +/* + * Sessions + */ + +struct grdev_session { + grdev_context *context; + char *name; + char *path; + grdev_event_fn event_fn; + void *userdata; + + unsigned long n_pins; + + Hashmap *card_map; + Hashmap *display_map; + + bool custom : 1; + bool managed : 1; + bool enabled : 1; + bool modified : 1; +}; + +grdev_session *grdev_session_pin(grdev_session *session); +grdev_session *grdev_session_unpin(grdev_session *session); + +DEFINE_TRIVIAL_CLEANUP_FUNC(grdev_session*, grdev_session_unpin); + +/* + * Contexts + */ + +struct grdev_context { + unsigned long ref; + sd_event *event; + sd_bus *sysbus; + + Hashmap *session_map; +}; |