chiark / gitweb /
0064f0be02738fd553d088706c99f44112b49a95
[elogind.git] / src / libsystemd-terminal / grdev-internal.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com>
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #pragma once
23
24 #include <inttypes.h>
25 #include <libudev.h>
26 #include <stdbool.h>
27 #include <stdlib.h>
28 #include <systemd/sd-bus.h>
29 #include <systemd/sd-event.h>
30 #include "grdev.h"
31 #include "hashmap.h"
32 #include "list.h"
33 #include "util.h"
34
35 typedef struct grdev_tile               grdev_tile;
36 typedef struct grdev_display_cache      grdev_display_cache;
37
38 typedef struct grdev_pipe_vtable        grdev_pipe_vtable;
39 typedef struct grdev_pipe               grdev_pipe;
40 typedef struct grdev_card_vtable        grdev_card_vtable;
41 typedef struct grdev_card               grdev_card;
42
43 /*
44  * DRM cards
45  */
46
47 bool grdev_is_drm_card(grdev_card *card);
48 grdev_card *grdev_find_drm_card(grdev_session *session, dev_t devnum);
49 int grdev_drm_card_new(grdev_card **out, grdev_session *session, struct udev_device *ud);
50
51 /*
52  * Displays
53  */
54
55 enum {
56         GRDEV_TILE_LEAF,
57         GRDEV_TILE_NODE,
58         GRDEV_TILE_CNT
59 };
60
61 struct grdev_tile {
62         LIST_FIELDS(grdev_tile, childs_by_node);
63         grdev_tile *parent;
64         grdev_display *display;
65
66         uint32_t x;
67         uint32_t y;
68         unsigned int rotate;
69         unsigned int flip;
70         uint32_t cache_w;
71         uint32_t cache_h;
72
73         unsigned int type;
74
75         union {
76                 struct {
77                         grdev_pipe *pipe;
78                 } leaf;
79
80                 struct {
81                         size_t n_childs;
82                         LIST_HEAD(grdev_tile, child_list);
83                 } node;
84         };
85 };
86
87 int grdev_tile_new_leaf(grdev_tile **out, grdev_pipe *pipe);
88 int grdev_tile_new_node(grdev_tile **out);
89 grdev_tile *grdev_tile_free(grdev_tile *tile);
90
91 DEFINE_TRIVIAL_CLEANUP_FUNC(grdev_tile*, grdev_tile_free);
92
93 struct grdev_display {
94         grdev_session *session;
95         char *name;
96
97         size_t n_leafs;
98         grdev_tile *tile;
99
100         size_t n_pipes;
101         size_t max_pipes;
102
103         uint32_t width;
104         uint32_t height;
105
106         struct grdev_display_cache {
107                 grdev_pipe *pipe;
108                 grdev_display_target target;
109
110                 bool incomplete : 1;
111         } *pipes;
112
113         bool enabled : 1;
114         bool public : 1;
115         bool modified : 1;
116         bool framed : 1;
117 };
118
119 grdev_display *grdev_find_display(grdev_session *session, const char *name);
120
121 int grdev_display_new(grdev_display **out, grdev_session *session, const char *name);
122 grdev_display *grdev_display_free(grdev_display *display);
123
124 DEFINE_TRIVIAL_CLEANUP_FUNC(grdev_display*, grdev_display_free);
125
126 /*
127  * Pipes
128  */
129
130 struct grdev_pipe_vtable {
131         void (*free) (grdev_pipe *pipe);
132         void (*enable) (grdev_pipe *pipe);
133         void (*disable) (grdev_pipe *pipe);
134         grdev_fb *(*target) (grdev_pipe *pipe);
135 };
136
137 struct grdev_pipe {
138         const grdev_pipe_vtable *vtable;
139         grdev_card *card;
140         char *name;
141
142         grdev_tile *tile;
143         grdev_display_cache *cache;
144
145         uint32_t width;
146         uint32_t height;
147
148         size_t max_fbs;
149         grdev_fb *front;
150         grdev_fb *back;
151         grdev_fb **fbs;
152
153         bool enabled : 1;
154         bool running : 1;
155         bool flip : 1;
156         bool flipping : 1;
157 };
158
159 #define GRDEV_PIPE_INIT(_vtable, _card) ((grdev_pipe){ \
160                 .vtable = (_vtable), \
161                 .card = (_card), \
162         })
163
164 grdev_pipe *grdev_find_pipe(grdev_card *card, const char *name);
165
166 int grdev_pipe_add(grdev_pipe *pipe, const char *name, size_t n_fbs);
167 grdev_pipe *grdev_pipe_free(grdev_pipe *pipe);
168
169 DEFINE_TRIVIAL_CLEANUP_FUNC(grdev_pipe*, grdev_pipe_free);
170
171 void grdev_pipe_ready(grdev_pipe *pipe, bool running);
172 void grdev_pipe_frame(grdev_pipe *pipe);
173
174 /*
175  * Cards
176  */
177
178 struct grdev_card_vtable {
179         void (*free) (grdev_card *card);
180         void (*enable) (grdev_card *card);
181         void (*disable) (grdev_card *card);
182         void (*commit) (grdev_card *card);
183         void (*restore) (grdev_card *card);
184 };
185
186 struct grdev_card {
187         const grdev_card_vtable *vtable;
188         grdev_session *session;
189         char *name;
190
191         Hashmap *pipe_map;
192
193         bool enabled : 1;
194         bool modified : 1;
195 };
196
197 #define GRDEV_CARD_INIT(_vtable, _session) ((grdev_card){ \
198                 .vtable = (_vtable), \
199                 .session = (_session), \
200         })
201
202 grdev_card *grdev_find_card(grdev_session *session, const char *name);
203
204 int grdev_card_add(grdev_card *card, const char *name);
205 grdev_card *grdev_card_free(grdev_card *card);
206
207 DEFINE_TRIVIAL_CLEANUP_FUNC(grdev_card*, grdev_card_free);
208
209 /*
210  * Sessions
211  */
212
213 struct grdev_session {
214         grdev_context *context;
215         char *name;
216         char *path;
217         grdev_event_fn event_fn;
218         void *userdata;
219
220         unsigned long n_pins;
221
222         Hashmap *card_map;
223         Hashmap *display_map;
224
225         bool custom : 1;
226         bool managed : 1;
227         bool enabled : 1;
228         bool modified : 1;
229 };
230
231 grdev_session *grdev_session_pin(grdev_session *session);
232 grdev_session *grdev_session_unpin(grdev_session *session);
233
234 DEFINE_TRIVIAL_CLEANUP_FUNC(grdev_session*, grdev_session_unpin);
235
236 /*
237  * Contexts
238  */
239
240 struct grdev_context {
241         unsigned long ref;
242         sd_event *event;
243         sd_bus *sysbus;
244
245         Hashmap *session_map;
246 };