summaryrefslogtreecommitdiff
path: root/src/libsystemd-terminal/grdev-internal.h
blob: 0064f0be02738fd553d088706c99f44112b49a95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*-*- 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 <libudev.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;

/*
 * DRM cards
 */

bool grdev_is_drm_card(grdev_card *card);
grdev_card *grdev_find_drm_card(grdev_session *session, dev_t devnum);
int grdev_drm_card_new(grdev_card **out, grdev_session *session, struct udev_device *ud);

/*
 * 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;
};