wlt: fix shl_hook API changes
[platform/upstream/kmscon.git] / src / uterm_video.h
1 /*
2  * uterm_video - Linux User-Space Terminal Video Handling
3  *
4  * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@googlemail.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files
8  * (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26 /*
27  * Video Control
28  * Linux provides 2 famous ways to access the video hardware: FBDEV and DRM.
29  * fbdev is the older one of both and is simply a mmap() of the framebuffer into
30  * main memory. It does not allow 3D acceleration and if you need 2D
31  * acceleration you should use libraries like cairo to draw into the framebuffer
32  * provided by this library.
33  * DRM is the new approach which provides 3D acceleration with mesa. It allows
34  * much more configuration as fbdev and is the recommended way to access video
35  * hardware on modern computers.
36  * Modern mesa provides 3D acceleration on fbdev, too. This is used in systems
37  * like Android. This will allow us to provide an fbdev backend here.
38  *
39  * Famous linux graphics systems like X.Org/X11 or Wayland use fbdev or DRM
40  * internally to access the video hardware. This API allows low-level access to
41  * fbdev and DRM without the need of X.Org/X11 or Wayland. If VT support is
42  * enabled in your kernel, each application can run on a different VT. For
43  * instance, X.Org may run on VT-7, Wayland on VT-8, your application on VT-9
44  * and default consoles on VT-1 to VT-6. You can switch between them with
45  * ctrl-alt-F1-F12.
46  * If VT support is not available you need other ways to switch between
47  * applications. See uterm_vt for more.
48  */
49
50 #ifndef UTERM_UTERM_VIDEO_H
51 #define UTERM_UTERM_VIDEO_H
52
53 #include <eloop.h>
54 #include <inttypes.h>
55 #include <stdbool.h>
56 #include <stdlib.h>
57
58 struct uterm_mode;
59 struct uterm_display;
60 struct uterm_video;
61 struct uterm_video_module;
62
63 enum uterm_display_state {
64         UTERM_DISPLAY_ACTIVE,
65         UTERM_DISPLAY_ASLEEP,
66         UTERM_DISPLAY_INACTIVE,
67         UTERM_DISPLAY_GONE,
68 };
69
70 enum uterm_display_dpms {
71         UTERM_DPMS_ON,
72         UTERM_DPMS_STANDBY,
73         UTERM_DPMS_SUSPEND,
74         UTERM_DPMS_OFF,
75         UTERM_DPMS_UNKNOWN,
76 };
77
78 enum uterm_video_action {
79         UTERM_WAKE_UP,
80         UTERM_SLEEP,
81         UTERM_NEW,
82         UTERM_GONE,
83 };
84
85 struct uterm_video_hotplug {
86         struct uterm_display *display;
87         int action;
88 };
89
90 enum uterm_display_action {
91         UTERM_PAGE_FLIP,
92 };
93
94 struct uterm_display_event {
95         int action;
96 };
97
98 enum uterm_video_format {
99         UTERM_FORMAT_GREY       = 0x01,
100         UTERM_FORMAT_XRGB32     = 0x02,
101         UTERM_FORMAT_RGB16      = 0x04,
102 };
103
104 struct uterm_video_buffer {
105         unsigned int width;
106         unsigned int height;
107         unsigned int stride;
108         unsigned int format;
109         uint8_t *data;
110 };
111
112 struct uterm_video_blend_req {
113         const struct uterm_video_buffer *buf;
114         unsigned int x;
115         unsigned int y;
116         uint8_t fr;
117         uint8_t fg;
118         uint8_t fb;
119         uint8_t br;
120         uint8_t bg;
121         uint8_t bb;
122 };
123
124 typedef void (*uterm_video_cb) (struct uterm_video *video,
125                                 struct uterm_video_hotplug *arg,
126                                 void *data);
127 typedef void (*uterm_display_cb) (struct uterm_display *disp,
128                                   struct uterm_display_event *arg,
129                                   void *data);
130
131 /* misc */
132
133 const char *uterm_dpms_to_name(int dpms);
134 bool uterm_video_available(const struct uterm_video_module *mod);
135
136 /* display modes interface */
137
138 void uterm_mode_ref(struct uterm_mode *mode);
139 void uterm_mode_unref(struct uterm_mode *mode);
140 struct uterm_mode *uterm_mode_next(struct uterm_mode *mode);
141
142 const char *uterm_mode_get_name(const struct uterm_mode *mode);
143 unsigned int uterm_mode_get_width(const struct uterm_mode *mode);
144 unsigned int uterm_mode_get_height(const struct uterm_mode *mode);
145
146 /* display interface */
147
148 void uterm_display_ref(struct uterm_display *disp);
149 void uterm_display_unref(struct uterm_display *disp);
150 struct uterm_display *uterm_display_next(struct uterm_display *disp);
151
152 int uterm_display_register_cb(struct uterm_display *disp, uterm_display_cb cb,
153                               void *data);
154 void uterm_display_unregister_cb(struct uterm_display *disp,
155                                  uterm_display_cb cb, void *data);
156
157 struct uterm_mode *uterm_display_get_modes(struct uterm_display *disp);
158 struct uterm_mode *uterm_display_get_current(struct uterm_display *disp);
159 struct uterm_mode *uterm_display_get_default(struct uterm_display *disp);
160
161 int uterm_display_get_state(struct uterm_display *disp);
162 int uterm_display_activate(struct uterm_display *disp, struct uterm_mode *mode);
163 void uterm_display_deactivate(struct uterm_display *disp);
164 int uterm_display_set_dpms(struct uterm_display *disp, int state);
165 int uterm_display_get_dpms(const struct uterm_display *disp);
166
167 int uterm_display_use(struct uterm_display *disp, bool *opengl);
168 int uterm_display_get_buffers(struct uterm_display *disp,
169                               struct uterm_video_buffer *buffer,
170                               unsigned int formats);
171 int uterm_display_swap(struct uterm_display *disp, bool immediate);
172 bool uterm_display_is_swapping(struct uterm_display *disp);
173
174 int uterm_display_fill(struct uterm_display *disp,
175                        uint8_t r, uint8_t g, uint8_t b,
176                        unsigned int x, unsigned int y,
177                        unsigned int width, unsigned int height);
178 int uterm_display_blit(struct uterm_display *disp,
179                        const struct uterm_video_buffer *buf,
180                        unsigned int x, unsigned int y);
181 int uterm_display_fake_blend(struct uterm_display *disp,
182                              const struct uterm_video_buffer *buf,
183                              unsigned int x, unsigned int y,
184                              uint8_t fr, uint8_t fg, uint8_t fb,
185                              uint8_t br, uint8_t bg, uint8_t bb);
186 int uterm_display_fake_blendv(struct uterm_display *disp,
187                               const struct uterm_video_blend_req *req,
188                               size_t num);
189
190 /* video interface */
191
192 int uterm_video_new(struct uterm_video **out, struct ev_eloop *eloop,
193                     const char *node, const struct uterm_video_module *mod);
194 void uterm_video_ref(struct uterm_video *video);
195 void uterm_video_unref(struct uterm_video *video);
196
197 void uterm_video_segfault(struct uterm_video *video);
198 struct uterm_display *uterm_video_get_displays(struct uterm_video *video);
199 int uterm_video_register_cb(struct uterm_video *video, uterm_video_cb cb,
200                             void *data);
201 void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb,
202                                void *data);
203
204 void uterm_video_sleep(struct uterm_video *video);
205 int uterm_video_wake_up(struct uterm_video *video);
206 bool uterm_video_is_awake(struct uterm_video *video);
207 void uterm_video_poll(struct uterm_video *video);
208
209 /* external modules */
210
211 #ifdef BUILD_ENABLE_VIDEO_FBDEV
212 extern const struct uterm_video_module *UTERM_VIDEO_FBDEV;
213 #else
214 #define UTERM_VIDEO_FBDEV NULL
215 #endif
216
217 #ifdef BUILD_ENABLE_VIDEO_DRM2D
218 extern const struct uterm_video_module *UTERM_VIDEO_DRM2D;
219 #else
220 #define UTERM_VIDEO_DRM2D NULL
221 #endif
222
223 #ifdef BUILD_ENABLE_VIDEO_DRM3D
224 extern const struct uterm_video_module *UTERM_VIDEO_DRM3D;
225 #else
226 #define UTERM_VIDEO_DRM3D NULL
227 #endif
228
229 #endif /* UTERM_UTERM_VIDEO_H */