Rev 4503 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4503 | Serge | 1 | /* |
2 | * Copyright (C) 2010 LunarG Inc. |
||
3 | * |
||
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
5 | * copy of this software and associated documentation files (the "Software"), |
||
6 | * to deal in the Software without restriction, including without limitation |
||
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
8 | * and/or sell copies of the Software, and to permit persons to whom the |
||
9 | * Software is furnished to do so, subject to the following conditions: |
||
10 | * |
||
11 | * The above copyright notice and this permission notice shall be included |
||
12 | * in all copies or substantial portions of the Software. |
||
13 | * |
||
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||
20 | * DEALINGS IN THE SOFTWARE. |
||
21 | * |
||
22 | * Authors: |
||
23 | * Chia-I Wu |
||
24 | */ |
||
25 | |||
26 | #include |
||
27 | #include |
||
28 | #include |
||
29 | #include |
||
30 | |||
31 | #define EGL_EGLEXT_PROTOTYPES |
||
32 | #include "EGL/egl.h" |
||
33 | #include "EGL/eglext.h" |
||
34 | #include "gbm.h" |
||
35 | #include |
||
36 | |||
37 | #include "eglutint.h" |
||
38 | |||
39 | #define MAX_MODES 100 |
||
40 | |||
41 | //static EGLScreenMESA kms_screen; |
||
42 | //static EGLModeMESA kms_mode; |
||
43 | //static EGLint kms_width, kms_height; |
||
44 | |||
45 | void |
||
46 | _eglutNativeInitDisplay(void) |
||
47 | { |
||
48 | struct gbm_device *gbm; |
||
49 | int fd; |
||
50 | |||
51 | fd = get_service("DISPLAY"); |
||
52 | gbm = gbm_create_device(fd); |
||
53 | if( gbm == NULL){ |
||
54 | _eglutFatal("failed to initialize GBM device"); |
||
55 | exit(1); |
||
56 | }; |
||
57 | |||
58 | // init_pixlib(HW_BIT_BLIT); |
||
59 | |||
60 | _eglut->native_dpy = gbm; |
||
61 | _eglut->surface_type = EGL_WINDOW_BIT; |
||
62 | } |
||
63 | |||
64 | void |
||
65 | _eglutNativeFiniDisplay(void) |
||
66 | { |
||
67 | // done_pixlib(); |
||
68 | } |
||
69 | |||
70 | #if 0 |
||
71 | static void |
||
72 | init_kms(void) |
||
73 | { |
||
74 | EGLModeMESA modes[MAX_MODES]; |
||
75 | EGLint num_screens, num_modes; |
||
76 | EGLint width, height, best_mode; |
||
77 | EGLint i; |
||
78 | |||
79 | if (!eglGetScreensMESA(_eglut->dpy, &kms_screen, 1, &num_screens) || |
||
80 | !num_screens) |
||
81 | _eglutFatal("eglGetScreensMESA failed\n"); |
||
82 | |||
83 | if (!eglGetModesMESA(_eglut->dpy, kms_screen, |
||
84 | modes, MAX_MODES, &num_modes) || !num_modes) |
||
85 | _eglutFatal("eglGetModesMESA failed!\n"); |
||
86 | |||
87 | printf("Found %d modes:\n", num_modes); |
||
88 | |||
89 | best_mode = 0; |
||
90 | width = 0; |
||
91 | height = 0; |
||
92 | for (i = 0; i < num_modes; i++) { |
||
93 | EGLint w, h; |
||
94 | eglGetModeAttribMESA(_eglut->dpy, modes[i], EGL_WIDTH, &w); |
||
95 | eglGetModeAttribMESA(_eglut->dpy, modes[i], EGL_HEIGHT, &h); |
||
96 | printf("%3d: %d x %d\n", i, w, h); |
||
97 | if (w > width && h > height) { |
||
98 | width = w; |
||
99 | height = h; |
||
100 | best_mode = i; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | printf("Will use screen size: %d x %d\n", width, height); |
||
105 | |||
106 | kms_mode = modes[best_mode]; |
||
107 | kms_width = width; |
||
108 | kms_height = height; |
||
109 | } |
||
110 | #endif |
||
111 | |||
112 | void |
||
113 | _eglutNativeInitWindow(struct eglut_window *win, const char *title, |
||
114 | int x, int y, int w, int h) |
||
115 | { |
||
116 | struct gbm_device *gbm = _eglut->native_dpy; |
||
117 | struct gbm_surface *gs; |
||
118 | |||
119 | gs = gbm_surface_create(gbm, w, h, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING); |
||
120 | |||
121 | win->native.u.surface = gs; |
||
122 | |||
123 | win->native.width = w; |
||
124 | win->native.height = h; |
||
125 | |||
126 | BeginDraw(); |
||
127 | DrawWindow(x, y, w+TYPE_3_BORDER_WIDTH*2, |
||
128 | h+TYPE_3_BORDER_WIDTH+get_skin_height(), title, 0x000000, 0x74); |
||
129 | |||
130 | EndDraw(); |
||
131 | |||
132 | // sna_create_mask(); |
||
133 | } |
||
134 | |||
135 | void |
||
136 | _eglutNativeFiniWindow(struct eglut_window *win) |
||
137 | { |
||
138 | // eglShowScreenSurfaceMESA(_eglut->dpy, |
||
139 | // kms_screen, EGL_NO_SURFACE, 0); |
||
140 | // eglDestroySurface(_eglut->dpy, win->native.u.surface); |
||
141 | } |
||
142 | |||
143 | void |
||
144 | _eglutNativeEventLoop(void) |
||
145 | { |
||
146 | struct eglut_window *win = _eglut->current; |
||
147 | int start = _eglutNow(); |
||
148 | int frames = 0; |
||
149 | int run = 1; |
||
150 | _eglut->redisplay = 1; |
||
151 | |||
152 | while (run) |
||
153 | { |
||
154 | int now = _eglutNow(); |
||
155 | oskey_t key; |
||
156 | int ev; |
||
157 | |||
158 | ev = check_os_event(); |
||
159 | switch(ev) |
||
160 | { |
||
161 | case 1: |
||
162 | BeginDraw(); |
||
4768 | Serge | 163 | DrawWindow(0,0,0,0,NULL,0,0x74); |
4503 | Serge | 164 | EndDraw(); |
165 | break; |
||
166 | |||
167 | case 2: |
||
168 | key = get_key(); |
||
169 | if (key.code == 27) |
||
170 | { |
||
171 | run = 0; |
||
172 | continue; |
||
173 | } |
||
174 | if(win->keyboard_cb) |
||
175 | win->keyboard_cb(key.code); |
||
176 | break; |
||
177 | |||
178 | case 3: |
||
179 | if(get_os_button()==1) |
||
180 | { |
||
181 | run = 0; |
||
182 | continue; |
||
183 | } |
||
184 | break; |
||
185 | }; |
||
186 | |||
187 | if (now - start >= 5000) |
||
188 | { |
||
189 | double elapsed = (double) (now - start) / 1000.0; |
||
190 | |||
191 | printf("%d frames in %3.1f seconds = %6.3f FPS\n", |
||
192 | frames, elapsed, frames / elapsed); |
||
193 | fflush(stdout); |
||
194 | |||
195 | start = now; |
||
196 | frames = 0; |
||
197 | } |
||
198 | |||
199 | if (_eglut->idle_cb) |
||
200 | _eglut->idle_cb(); |
||
201 | |||
202 | if (_eglut->redisplay) |
||
203 | { |
||
204 | _eglut->redisplay = 0; |
||
205 | |||
206 | if (win->display_cb) |
||
207 | win->display_cb(); |
||
208 | |||
209 | render_swap_and_blit(_eglut->render); |
||
210 | frames++; |
||
211 | } |
||
212 | } |
||
213 | // glFinish(); |
||
214 | eglutDestroyWindow(_eglut->current->index); |
||
215 | eglutFini(); |
||
216 | }> |