2 * uterm - Linux User-Space Terminal
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.
26 /* Internal definitions */
28 #ifndef UTERM_VIDEO_INTERNAL_H
29 #define UTERM_VIDEO_INTERNAL_H
36 #include "shl_dlist.h"
38 #include "uterm_video.h"
40 /* backend-operations */
43 int (*init) (struct uterm_mode *mode);
44 void (*destroy) (struct uterm_mode *mode);
45 const char *(*get_name) (const struct uterm_mode *mode);
46 unsigned int (*get_width) (const struct uterm_mode *mode);
47 unsigned int (*get_height) (const struct uterm_mode *mode);
51 int (*init) (struct uterm_display *display);
52 void (*destroy) (struct uterm_display *display);
53 int (*activate) (struct uterm_display *disp, struct uterm_mode *mode);
54 void (*deactivate) (struct uterm_display *disp);
55 int (*set_dpms) (struct uterm_display *disp, int state);
56 int (*use) (struct uterm_display *disp, bool *opengl);
57 int (*get_buffers) (struct uterm_display *disp,
58 struct uterm_video_buffer *buffer,
59 unsigned int formats);
60 int (*swap) (struct uterm_display *disp, bool immediate);
61 int (*blit) (struct uterm_display *disp,
62 const struct uterm_video_buffer *buf,
63 unsigned int x, unsigned int y);
64 int (*fake_blendv) (struct uterm_display *disp,
65 const struct uterm_video_blend_req *req,
67 int (*fill) (struct uterm_display *disp,
68 uint8_t r, uint8_t g, uint8_t b, unsigned int x,
69 unsigned int y, unsigned int width, unsigned int height);
73 int (*init) (struct uterm_video *video, const char *node);
74 void (*destroy) (struct uterm_video *video);
75 void (*segfault) (struct uterm_video *video);
76 int (*poll) (struct uterm_video *video);
77 void (*sleep) (struct uterm_video *video);
78 int (*wake_up) (struct uterm_video *video);
81 struct uterm_video_module {
82 const struct video_ops *ops;
85 #define VIDEO_CALL(func, els, ...) (func ? func(__VA_ARGS__) : els)
90 struct shl_dlist list;
92 struct uterm_display *disp;
94 const struct mode_ops *ops;
98 int mode_new(struct uterm_mode **out, const struct mode_ops *ops);
99 int uterm_mode_bind(struct uterm_mode *mode, struct uterm_display *disp);
100 void uterm_mode_unbind(struct uterm_mode *mode);
104 #define DISPLAY_ONLINE 0x01
105 #define DISPLAY_VSYNC 0x02
106 #define DISPLAY_AVAILABLE 0x04
107 #define DISPLAY_OPEN 0x08
108 #define DISPLAY_DBUF 0x10
109 #define DISPLAY_DITHERING 0x20
110 #define DISPLAY_PFLIP 0x40
112 struct uterm_display {
113 struct shl_dlist list;
116 struct uterm_video *video;
118 struct shl_hook *hook;
119 struct shl_dlist modes;
120 struct uterm_mode *default_mode;
121 struct uterm_mode *current_mode;
124 bool vblank_scheduled;
125 struct itimerspec vblank_spec;
126 struct ev_timer *vblank_timer;
128 const struct display_ops *ops;
132 int display_new(struct uterm_display **out, const struct display_ops *ops);
133 void display_set_vblank_timer(struct uterm_display *disp,
135 int display_schedule_vblank_timer(struct uterm_display *disp);
136 int uterm_display_bind(struct uterm_display *disp, struct uterm_video *video);
137 void uterm_display_unbind(struct uterm_display *disp);
139 #define DISPLAY_CB(disp, act) shl_hook_call((disp)->hook, (disp), \
140 &(struct uterm_display_event){ \
144 static inline bool display_is_online(const struct uterm_display *disp)
146 return disp->video && (disp->flags & DISPLAY_ONLINE);
151 #define VIDEO_AWAKE 0x01
152 #define VIDEO_HOTPLUG 0x02
157 struct ev_eloop *eloop;
159 struct shl_dlist displays;
160 struct shl_hook *hook;
162 const struct uterm_video_module *mod;
163 const struct video_ops *ops;
167 static inline bool video_is_awake(const struct uterm_video *video)
169 return video->flags & VIDEO_AWAKE;
172 static inline bool video_need_hotplug(const struct uterm_video *video)
174 return video->flags & VIDEO_HOTPLUG;
177 #define VIDEO_CB(vid, disp, act) shl_hook_call((vid)->hook, (vid), \
178 &(struct uterm_video_hotplug){ \
183 #if defined(BUILD_ENABLE_VIDEO_DRM3D) || defined(BUILD_ENABLE_VIDEO_DRM2D)
187 static inline bool video_drm_available(void)
189 return drmAvailable();
194 static inline bool video_drm_available(void)
201 #endif /* UTERM_VIDEO_INTERNAL_H */