2 * uterm - Linux User-Space Terminal
4 * Copyright (c) 2011-2012 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.
26 /* Internal definitions */
39 /* backend-operations */
42 int (*init) (struct uterm_mode *mode);
43 void (*destroy) (struct uterm_mode *mode);
44 const char *(*get_name) (const struct uterm_mode *mode);
45 unsigned int (*get_width) (const struct uterm_mode *mode);
46 unsigned int (*get_height) (const struct uterm_mode *mode);
50 int (*init) (struct uterm_display *display);
51 void (*destroy) (struct uterm_display *display);
52 int (*activate) (struct uterm_display *disp, struct uterm_mode *mode);
53 void (*deactivate) (struct uterm_display *disp);
54 int (*set_dpms) (struct uterm_display *disp, int state);
55 int (*use) (struct uterm_display *disp);
56 int (*swap) (struct uterm_display *disp);
57 int (*blit) (struct uterm_display *disp,
58 const struct uterm_video_buffer *buf,
59 unsigned int x, unsigned int y);
60 int (*blend) (struct uterm_display *disp,
61 const struct uterm_video_buffer *buf,
62 unsigned int x, unsigned int y,
63 uint8_t fr, uint8_t fg, uint8_t fb,
64 uint8_t br, uint8_t bg, uint8_t bb);
65 int (*blendv) (struct uterm_display *disp,
66 const struct uterm_video_blend_req *req, size_t num);
67 int (*fake_blendv) (struct uterm_display *disp,
68 const struct uterm_video_blend_req *req,
70 int (*fill) (struct uterm_display *disp,
71 uint8_t r, uint8_t g, uint8_t b, unsigned int x,
72 unsigned int y, unsigned int width, unsigned int height);
76 int (*init) (struct uterm_video *video, const char *node);
77 void (*destroy) (struct uterm_video *video);
78 void (*segfault) (struct uterm_video *video);
79 int (*use) (struct uterm_video *video);
80 int (*poll) (struct uterm_video *video);
81 void (*sleep) (struct uterm_video *video);
82 int (*wake_up) (struct uterm_video *video);
85 #define VIDEO_CALL(func, els, ...) (func ? func(__VA_ARGS__) : els)
89 #ifdef BUILD_ENABLE_DRM
92 #include <EGL/eglext.h>
94 #include <GLES2/gl2.h>
95 #include <GLES2/gl2ext.h>
97 #include <xf86drmMode.h>
98 #include "static_gl.h"
101 drmModeModeInfo info;
114 drmModeCrtc *saved_crtc;
124 struct gbm_device *gbm;
129 bool supports_rowlen;
132 struct gl_shader *fill_shader;
133 GLuint uni_fill_proj;
135 struct gl_shader *blend_shader;
136 GLuint uni_blend_proj;
137 GLuint uni_blend_tex;
138 GLuint uni_blend_fgcol;
139 GLuint uni_blend_bgcol;
141 struct gl_shader *blit_shader;
142 GLuint uni_blit_proj;
146 static const bool drm_available = true;
147 extern const struct mode_ops drm_mode_ops;
148 extern const struct display_ops drm_display_ops;
149 extern const struct video_ops drm_video_ops;
151 #else /* !BUILD_ENABLE_DRM */
165 static const bool drm_available = false;
166 static const struct mode_ops drm_mode_ops;
167 static const struct display_ops drm_display_ops;
168 static const struct video_ops drm_video_ops;
170 #endif /* BUILD_ENABLE_DRM */
174 #ifdef BUILD_ENABLE_DUMB
177 #include <xf86drmMode.h>
180 drmModeModeInfo info;
192 struct dumb_display {
195 drmModeCrtc *saved_crtc;
198 struct dumb_rb rb[2];
206 static const bool dumb_available = true;
207 extern const struct mode_ops dumb_mode_ops;
208 extern const struct display_ops dumb_display_ops;
209 extern const struct video_ops dumb_video_ops;
211 #else /* !BUILD_ENABLE_DUMB */
217 struct dumb_display {
225 static const bool dumb_available = false;
226 static const struct mode_ops dumb_mode_ops;
227 static const struct display_ops dumb_display_ops;
228 static const struct video_ops dumb_video_ops;
230 #endif /* BUILD_ENABLE_DUMB */
234 #ifdef BUILD_ENABLE_FBDEV
236 #include <linux/fb.h>
243 struct fbdev_display {
248 struct fb_fix_screeninfo finfo;
249 struct fb_var_screeninfo vinfo;
267 int_fast32_t dither_r;
268 int_fast32_t dither_g;
269 int_fast32_t dither_b;
276 static const bool fbdev_available = true;
277 extern const struct mode_ops fbdev_mode_ops;
278 extern const struct display_ops fbdev_display_ops;
279 extern const struct video_ops fbdev_video_ops;
281 #else /* !BUILD_ENABLE_FBDEV */
287 struct fbdev_display {
295 static const bool fbdev_available = false;
296 static const struct mode_ops fbdev_mode_ops;
297 static const struct display_ops fbdev_display_ops;
298 static const struct video_ops fbdev_video_ops;
300 #endif /* BUILD_ENABLE_FBDEV */
304 struct uterm_screen {
306 struct uterm_display *disp;
313 struct uterm_mode *next;
315 const struct mode_ops *ops;
318 struct dumb_mode dumb;
319 struct fbdev_mode fbdev;
323 int mode_new(struct uterm_mode **out, const struct mode_ops *ops);
327 #define DISPLAY_ONLINE 0x01
328 #define DISPLAY_VSYNC 0x02
329 #define DISPLAY_AVAILABLE 0x04
330 #define DISPLAY_OPEN 0x08
331 #define DISPLAY_DBUF 0x10
332 #define DISPLAY_DITHERING 0x20
334 struct uterm_display {
337 struct uterm_display *next;
338 struct uterm_video *video;
340 struct shl_hook *hook;
341 struct uterm_mode *modes;
342 struct uterm_mode *default_mode;
343 struct uterm_mode *current_mode;
346 bool vblank_scheduled;
347 struct itimerspec vblank_spec;
348 struct ev_timer *vblank_timer;
350 const struct display_ops *ops;
352 struct drm_display drm;
353 struct dumb_display dumb;
354 struct fbdev_display fbdev;
358 int display_new(struct uterm_display **out, const struct display_ops *ops,
359 struct uterm_video *video);
360 void display_set_vblank_timer(struct uterm_display *disp,
362 int display_schedule_vblank_timer(struct uterm_display *disp);
364 #define DISPLAY_CB(disp, act) shl_hook_call((disp)->hook, (disp), \
365 &(struct uterm_display_event){ \
369 static inline bool display_is_conn(const struct uterm_display *disp)
374 static inline bool display_is_online(const struct uterm_display *disp)
376 return display_is_conn(disp) && (disp->flags & DISPLAY_ONLINE);
381 #define VIDEO_AWAKE 0x01
382 #define VIDEO_HOTPLUG 0x02
387 struct ev_eloop *eloop;
389 struct uterm_display *displays;
390 struct shl_hook *hook;
392 const struct video_ops *ops;
394 struct drm_video drm;
395 struct dumb_video dumb;
396 struct fbdev_video fbdev;
400 static inline bool video_is_awake(const struct uterm_video *video)
402 return video->flags & VIDEO_AWAKE;
405 static inline bool video_need_hotplug(const struct uterm_video *video)
407 return video->flags & VIDEO_HOTPLUG;
410 #define VIDEO_CB(vid, disp, act) shl_hook_call((vid)->hook, (vid), \
411 &(struct uterm_video_hotplug){ \
416 static inline int video_do_use(struct uterm_video *video)
418 return VIDEO_CALL(video->ops->use, -EOPNOTSUPP, video);
421 #endif /* UTERM_VIDEO_H */