~ubuntu-branches/ubuntu/quantal/vice/quantal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*
 * fullscreen.c
 *
 * Written by
 *  Andreas Boose <viceteam@t-online.de>
 *  Martin Pottendorfer <pottendo@utanet.at>
 *
 * This file is part of VICE, the Versatile Commodore Emulator.
 * See README for copyright notice.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 *  02111-1307  USA.
 *
 */

#include "vice.h"

#include <stdio.h>
#include <string.h>

#include "fullscreen.h"
#include "fullscreenarch.h"
#include "lib.h"
#include "video.h"
#include "videoarch.h"
#include "x11menu.h"


#ifdef USE_XF86_EXTENSIONS

#define STR_VIDMODE "Vidmode"
#define STR_DGA1    "DGA1"
#define STR_DGA2    "DGA2"

#ifdef USE_XF86_VIDMODE_EXT
#include "vidmode.h"
#endif
#ifdef USE_XF86_DGA1_EXTENSIONS
#include "dga1.h"
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
#include "dga2.h"
#endif

int fullscreen_is_enabled;

int fullscreen_available(void) 
{
#ifdef USE_XF86_VIDMODE_EXT
    if (vidmode_available())
        return 1;
#endif
#ifdef USE_XF86_DGA1_EXTENSIONS
    if (dga1_available())
        return 1;
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
    if (dga2_available())
	return 1;
#endif    
    return 0;
}

void fullscreen_shutdown(void)
{
#ifdef USE_XF86_VIDMODE_EXT
    vidmode_shutdown();
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
    dga2_shutdown();
#endif
}

void fullscreen_suspend(int level)
{
#ifdef USE_XF86_VIDMODE_EXT
    vidmode_suspend(level);
#endif
#ifdef USE_XF86_DGA1_EXTENSIONS
    dga1_suspend(level);
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
    dga2_suspend(level);
#endif
}

void fullscreen_resume(void)
{
#ifdef USE_XF86_VIDMODE_EXT
    vidmode_resume();
#endif
#ifdef USE_XF86_DGA1_EXTENSIONS
    dga1_resume();
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
    dga2_resume();
#endif
}

void fullscreen_set_mouse_timeout(void)
{
#ifdef USE_XF86_VIDMODE_EXT
    vidmode_set_mouse_timeout();
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
    dga2_set_mouse_timeout();
#endif
}

void fullscreen_mode_callback(const char *device, void *callback)
{
#ifdef USE_XF86_VIDMODE_EXT
    if (strcmp(STR_VIDMODE, device) == 0)
        vidmode_mode_callback(callback);
#endif
#ifdef USE_XF86_DGA1_EXTENSIONS
    if (strcmp(STR_DGA1, device) == 0)
        dga1_mode_callback(callback);
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
    if (strcmp(STR_DGA2, device) == 0)
        dga2_mode_callback(callback);
#endif
}

void fullscreen_menu_create(struct ui_menu_entry_s menu[])
{
#ifdef USE_XF86_VIDMODE_EXT
    vidmode_menu_create(menu);
#endif
#ifdef USE_XF86_DGA1_EXTENSIONS
    dga1_menu_create(menu);
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
    dga2_menu_create(menu);
#endif
}

void fullscreen_menu_shutdown(struct ui_menu_entry_s menu[])
{
#ifdef USE_XF86_VIDMODE_EXT
    vidmode_menu_shutdown(menu);
#endif
#ifdef USE_XF86_DGA1_EXTENSIONS
    dga1_menu_shutdown(menu);
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
    dga2_menu_shutdown(menu);
#endif
}

int fullscreen_init(void)
{
#ifdef USE_XF86_VIDMODE_EXT
    if (vidmode_init() < 0)
        return -1;
#endif
#ifdef USE_XF86_DGA1_EXTENSIONS
    if (dga1_init() < 0)
        return -1;
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
    if (dga2_init() < 0)
        return -1;
#endif
    return 0;
}

int fullscreen_init_alloc_hooks(struct video_canvas_s *canvas)
{
#ifdef USE_XF86_DGA2_EXTENSIONS
    if (dga2_init_alloc_hooks(canvas) < 0)
        return -1;
#endif
    return 0;
}

void fullscreen_shutdown_alloc_hooks(struct video_canvas_s *canvas)
{
#ifdef USE_XF86_DGA2_EXTENSIONS
    dga2_shutdown_alloc_hooks(canvas);
#endif
}

static int fullscreen_enable(struct video_canvas_s *canvas, int enable)
{
    if (canvas->fullscreenconfig->device == NULL)
	return 0;
    
#ifdef USE_XF86_VIDMODE_EXT
    if (strcmp(STR_VIDMODE, canvas->fullscreenconfig->device) == 0)
        if (vidmode_enable(canvas, enable) < 0)
            return -1;
#endif
#ifdef USE_XF86_DGA1_EXTENSIONS
    if (strcmp(STR_DGA1, canvas->fullscreenconfig->device) == 0)
        if (dga1_enable(canvas, enable) < 0)
            return -1;
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
    if (strcmp(STR_DGA2, canvas->fullscreenconfig->device) == 0)
        if (dga2_enable(canvas, enable) < 0)
            return -1;
#endif
    fullscreen_is_enabled = canvas->fullscreenconfig->enable = enable;
    return 0;
}

static int fullscreen_double_size(struct video_canvas_s *canvas,
                                  int double_size)
{
    canvas->fullscreenconfig->double_size = double_size;
    return 0;
}

static int fullscreen_double_scan(struct video_canvas_s *canvas,
                                  int double_scan)
{
    canvas->fullscreenconfig->double_scan = double_scan;
    return 0;
}

static int fullscreen_device(struct video_canvas_s *canvas, const char *device)
{
    while (1) {
#ifdef USE_XF86_VIDMODE_EXT
    if (strcmp(STR_VIDMODE, device) == 0)
        break;
#endif
#ifdef USE_XF86_DGA1_EXTENSIONS
    if (strcmp(STR_DGA1, device) == 0)
        break;
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
    if (strcmp(STR_DGA2, device) == 0)
        break;
#endif
        return -1;
    }

    if (canvas->fullscreenconfig->device)
	lib_free(canvas->fullscreenconfig->device);
    
    canvas->fullscreenconfig->device = lib_stralloc(device);

    return 0;
}

#ifdef USE_XF86_VIDMODE_EXT
static int fullscreen_mode_vidmode(struct video_canvas_s *canvas, int mode)
{
    vidmode_mode(canvas, mode);
    return 0;
}
#endif

#ifdef USE_XF86_DGA1_EXTENSIONS
static int fullscreen_mode_dga1(struct video_canvas_s *canvas, int mode)
{
    dga1_mode(canvas, mode);
    return 0;
}
#endif

#ifdef USE_XF86_DGA2_EXTENSIONS
static int fullscreen_mode_dga2(struct video_canvas_s *canvas, int mode)
{
    dga2_mode(canvas, mode);
    return 0;
}
#endif

#endif

void fullscreen_capability(cap_fullscreen_t *cap_fullscreen)
{
    cap_fullscreen->device_num = 0;

#ifdef USE_XF86_VIDMODE_EXT
    cap_fullscreen->device_name[cap_fullscreen->device_num] = STR_VIDMODE;
    cap_fullscreen->enable = fullscreen_enable;
    cap_fullscreen->double_size = fullscreen_double_size;
    cap_fullscreen->double_scan = fullscreen_double_scan;
    cap_fullscreen->device = fullscreen_device;
    cap_fullscreen->mode[cap_fullscreen->device_num] = fullscreen_mode_vidmode;
    cap_fullscreen->device_num += 1;
#endif
#ifdef USE_XF86_DGA1_EXTENSIONS
    cap_fullscreen->device_name[cap_fullscreen->device_num] = STR_DGA1;
    cap_fullscreen->enable = fullscreen_enable;
    cap_fullscreen->double_size = fullscreen_double_size;
    cap_fullscreen->double_scan = fullscreen_double_scan;
    cap_fullscreen->device = fullscreen_device;
    cap_fullscreen->mode[cap_fullscreen->device_num] = fullscreen_mode_dga1;
    cap_fullscreen->device_num += 1;
#endif
#ifdef USE_XF86_DGA2_EXTENSIONS
    cap_fullscreen->device_name[cap_fullscreen->device_num] = STR_DGA2;
    cap_fullscreen->enable = fullscreen_enable;
    cap_fullscreen->double_size = fullscreen_double_size;
    cap_fullscreen->double_scan = fullscreen_double_scan;
    cap_fullscreen->device = fullscreen_device;
    cap_fullscreen->mode[cap_fullscreen->device_num] = fullscreen_mode_dga2;
    cap_fullscreen->device_num += 1;
#endif
}