2 * uterm_video - Linux User-Space Terminal Video Handling
4 * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@googlemail.com>
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
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.
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
46 * If VT support is not available you need other ways to switch between
47 * applications. See uterm_vt for more.
50 #ifndef UTERM_UTERM_VIDEO_H
51 #define UTERM_UTERM_VIDEO_H
61 struct uterm_video_module;
63 enum uterm_display_state {
66 UTERM_DISPLAY_INACTIVE,
70 enum uterm_display_dpms {
78 enum uterm_video_action {
86 struct uterm_video_hotplug {
87 struct uterm_display *display;
91 enum uterm_display_action {
95 struct uterm_display_event {
99 enum uterm_video_format {
100 UTERM_FORMAT_GREY = 0x01,
101 UTERM_FORMAT_XRGB32 = 0x02,
102 UTERM_FORMAT_RGB16 = 0x04,
105 struct uterm_video_buffer {
113 struct uterm_video_blend_req {
114 const struct uterm_video_buffer *buf;
125 typedef void (*uterm_video_cb) (struct uterm_video *video,
126 struct uterm_video_hotplug *arg,
128 typedef void (*uterm_display_cb) (struct uterm_display *disp,
129 struct uterm_display_event *arg,
134 const char *uterm_dpms_to_name(int dpms);
135 bool uterm_video_available(const struct uterm_video_module *mod);
137 /* display modes interface */
139 void uterm_mode_ref(struct uterm_mode *mode);
140 void uterm_mode_unref(struct uterm_mode *mode);
141 struct uterm_mode *uterm_mode_next(struct uterm_mode *mode);
143 const char *uterm_mode_get_name(const struct uterm_mode *mode);
144 unsigned int uterm_mode_get_width(const struct uterm_mode *mode);
145 unsigned int uterm_mode_get_height(const struct uterm_mode *mode);
147 /* display interface */
149 void uterm_display_ref(struct uterm_display *disp);
150 void uterm_display_unref(struct uterm_display *disp);
151 struct uterm_display *uterm_display_next(struct uterm_display *disp);
153 int uterm_display_register_cb(struct uterm_display *disp, uterm_display_cb cb,
155 void uterm_display_unregister_cb(struct uterm_display *disp,
156 uterm_display_cb cb, void *data);
158 struct uterm_mode *uterm_display_get_modes(struct uterm_display *disp);
159 struct uterm_mode *uterm_display_get_current(struct uterm_display *disp);
160 struct uterm_mode *uterm_display_get_default(struct uterm_display *disp);
162 int uterm_display_get_state(struct uterm_display *disp);
163 int uterm_display_activate(struct uterm_display *disp, struct uterm_mode *mode);
164 void uterm_display_deactivate(struct uterm_display *disp);
165 int uterm_display_set_dpms(struct uterm_display *disp, int state);
166 int uterm_display_get_dpms(const struct uterm_display *disp);
168 int uterm_display_use(struct uterm_display *disp, bool *opengl);
169 int uterm_display_get_buffers(struct uterm_display *disp,
170 struct uterm_video_buffer *buffer,
171 unsigned int formats);
172 int uterm_display_swap(struct uterm_display *disp, bool immediate);
173 bool uterm_display_is_swapping(struct uterm_display *disp);
175 int uterm_display_fill(struct uterm_display *disp,
176 uint8_t r, uint8_t g, uint8_t b,
177 unsigned int x, unsigned int y,
178 unsigned int width, unsigned int height);
179 int uterm_display_blit(struct uterm_display *disp,
180 const struct uterm_video_buffer *buf,
181 unsigned int x, unsigned int y);
182 int uterm_display_fake_blend(struct uterm_display *disp,
183 const struct uterm_video_buffer *buf,
184 unsigned int x, unsigned int y,
185 uint8_t fr, uint8_t fg, uint8_t fb,
186 uint8_t br, uint8_t bg, uint8_t bb);
187 int uterm_display_fake_blendv(struct uterm_display *disp,
188 const struct uterm_video_blend_req *req,
191 /* video interface */
193 int uterm_video_new(struct uterm_video **out, struct ev_eloop *eloop,
194 const char *node, const struct uterm_video_module *mod);
195 void uterm_video_ref(struct uterm_video *video);
196 void uterm_video_unref(struct uterm_video *video);
198 void uterm_video_segfault(struct uterm_video *video);
199 struct uterm_display *uterm_video_get_displays(struct uterm_video *video);
200 int uterm_video_register_cb(struct uterm_video *video, uterm_video_cb cb,
202 void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb,
205 void uterm_video_sleep(struct uterm_video *video);
206 int uterm_video_wake_up(struct uterm_video *video);
207 bool uterm_video_is_awake(struct uterm_video *video);
208 void uterm_video_poll(struct uterm_video *video);
210 /* external modules */
212 #ifdef BUILD_ENABLE_VIDEO_FBDEV
213 extern const struct uterm_video_module *UTERM_VIDEO_FBDEV;
215 #define UTERM_VIDEO_FBDEV NULL
218 #ifdef BUILD_ENABLE_VIDEO_DRM2D
219 extern const struct uterm_video_module *UTERM_VIDEO_DRM2D;
221 #define UTERM_VIDEO_DRM2D NULL
224 #ifdef BUILD_ENABLE_VIDEO_DRM3D
225 extern const struct uterm_video_module *UTERM_VIDEO_DRM3D;
227 #define UTERM_VIDEO_DRM3D NULL
230 #endif /* UTERM_UTERM_VIDEO_H */