Modify it to adjust Tizen IVI enviroment
[platform/upstream/kmscon.git] / src / uterm_video_internal.h
1 /*
2  * uterm - Linux User-Space Terminal
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 /* Internal definitions */
27
28 #ifndef UTERM_VIDEO_INTERNAL_H
29 #define UTERM_VIDEO_INTERNAL_H
30
31 #include <inttypes.h>
32 #include <limits.h>
33 #include <stdbool.h>
34 #include <stdlib.h>
35 #include "eloop.h"
36 #include "shl_dlist.h"
37 #include "shl_hook.h"
38 #include "uterm_video.h"
39
40 /* backend-operations */
41
42 struct mode_ops {
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);
48 };
49
50 struct display_ops {
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,
66                             size_t num);
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);
70 };
71
72 struct video_ops {
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);
79 };
80
81 struct uterm_video_module {
82         const struct video_ops *ops;
83 };
84
85 #define VIDEO_CALL(func, els, ...) (func ? func(__VA_ARGS__) : els)
86
87 /* uterm_mode */
88
89 struct uterm_mode {
90         struct shl_dlist list;
91         unsigned long ref;
92         struct uterm_display *disp;
93
94         const struct mode_ops *ops;
95         void *data;
96 };
97
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);
101
102 /* uterm_display */
103
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
111
112 struct uterm_display {
113         struct shl_dlist list;
114         unsigned long ref;
115         unsigned int flags;
116         struct uterm_video *video;
117
118         struct shl_hook *hook;
119         struct shl_dlist modes;
120         struct uterm_mode *default_mode;
121         struct uterm_mode *current_mode;
122         int dpms;
123
124         bool vblank_scheduled;
125         struct itimerspec vblank_spec;
126         struct ev_timer *vblank_timer;
127
128         const struct display_ops *ops;
129         void *data;
130 };
131
132 int display_new(struct uterm_display **out, const struct display_ops *ops);
133 void display_set_vblank_timer(struct uterm_display *disp,
134                               unsigned int msecs);
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);
138
139 #define DISPLAY_CB(disp, act) shl_hook_call((disp)->hook, (disp), \
140                 &(struct uterm_display_event){ \
141                         .action = (act), \
142                 })
143
144 static inline bool display_is_online(const struct uterm_display *disp)
145 {
146         return disp->video && (disp->flags & DISPLAY_ONLINE);
147 }
148
149 /* uterm_video */
150
151 #define VIDEO_AWAKE             0x01
152 #define VIDEO_HOTPLUG           0x02
153
154 struct uterm_video {
155         unsigned long ref;
156         unsigned int flags;
157         struct ev_eloop *eloop;
158
159         struct shl_dlist displays;
160         struct shl_hook *hook;
161
162         const struct uterm_video_module *mod;
163         const struct video_ops *ops;
164         void *data;
165 };
166
167 static inline bool video_is_awake(const struct uterm_video *video)
168 {
169         return video->flags & VIDEO_AWAKE;
170 }
171
172 static inline bool video_need_hotplug(const struct uterm_video *video)
173 {
174         return video->flags & VIDEO_HOTPLUG;
175 }
176
177 #define VIDEO_CB(vid, disp, act) shl_hook_call((vid)->hook, (vid), \
178                 &(struct uterm_video_hotplug){ \
179                         .display = (disp), \
180                         .action = (act), \
181                 })
182
183 #if defined(BUILD_ENABLE_VIDEO_DRM3D) || defined(BUILD_ENABLE_VIDEO_DRM2D)
184
185 #include <xf86drm.h>
186
187 static inline bool video_drm_available(void)
188 {
189         return drmAvailable();
190 }
191
192 #else
193
194 static inline bool video_drm_available(void)
195 {
196         return false;
197 }
198
199 #endif
200
201 #endif /* UTERM_VIDEO_INTERNAL_H */