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 {
85 struct uterm_video_hotplug {
86 struct uterm_display *display;
90 enum uterm_display_action {
94 struct uterm_display_event {
98 enum uterm_video_format {
99 UTERM_FORMAT_GREY = 0x01,
100 UTERM_FORMAT_XRGB32 = 0x02,
101 UTERM_FORMAT_RGB16 = 0x04,
104 struct uterm_video_buffer {
112 struct uterm_video_blend_req {
113 const struct uterm_video_buffer *buf;
124 typedef void (*uterm_video_cb) (struct uterm_video *video,
125 struct uterm_video_hotplug *arg,
127 typedef void (*uterm_display_cb) (struct uterm_display *disp,
128 struct uterm_display_event *arg,
133 const char *uterm_dpms_to_name(int dpms);
134 bool uterm_video_available(const struct uterm_video_module *mod);
136 /* display modes interface */
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);
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);
146 /* display interface */
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);
152 int uterm_display_register_cb(struct uterm_display *disp, uterm_display_cb cb,
154 void uterm_display_unregister_cb(struct uterm_display *disp,
155 uterm_display_cb cb, void *data);
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);
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);
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);
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,
190 /* video interface */
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);
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,
201 void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb,
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);
209 /* external modules */
211 #ifdef BUILD_ENABLE_VIDEO_FBDEV
212 extern const struct uterm_video_module *UTERM_VIDEO_FBDEV;
214 #define UTERM_VIDEO_FBDEV NULL
217 #ifdef BUILD_ENABLE_VIDEO_DRM2D
218 extern const struct uterm_video_module *UTERM_VIDEO_DRM2D;
220 #define UTERM_VIDEO_DRM2D NULL
223 #ifdef BUILD_ENABLE_VIDEO_DRM3D
224 extern const struct uterm_video_module *UTERM_VIDEO_DRM3D;
226 #define UTERM_VIDEO_DRM3D NULL
229 #endif /* UTERM_UTERM_VIDEO_H */