Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
1150 lines (1035 loc) · 34.3 KB

SDL_dgavideo.c

File metadata and controls

1150 lines (1035 loc) · 34.3 KB
 
Apr 26, 2001
Apr 26, 2001
1
/*
Feb 1, 2006
Feb 1, 2006
2
3
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
Feb 1, 2006
Feb 1, 2006
5
6
7
8
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
Feb 1, 2006
Feb 1, 2006
10
11
12
13
This library 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
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
Feb 1, 2006
Feb 1, 2006
19
20
Sam Lantinga
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
25
26
/* DGA 2.0 based SDL video driver implementation.
*/
Feb 7, 2006
Feb 7, 2006
27
28
#include <stdio.h>
Apr 26, 2001
Apr 26, 2001
29
#include <X11/Xlib.h>
Feb 16, 2006
Feb 16, 2006
30
#include "../Xext/extensions/xf86dga.h"
Apr 26, 2001
Apr 26, 2001
31
32
33
#include "SDL_video.h"
#include "SDL_mouse.h"
Feb 16, 2006
Feb 16, 2006
34
35
36
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
Apr 26, 2001
Apr 26, 2001
37
38
39
40
#include "SDL_dgavideo.h"
#include "SDL_dgamouse_c.h"
#include "SDL_dgaevents_c.h"
Nov 5, 2005
Nov 5, 2005
41
42
43
/* get function pointers... */
#include "../x11/SDL_x11dyn.h"
May 17, 2006
May 17, 2006
44
45
46
/*#define DGA_DEBUG*/
/* Heheh we're using X11 event code */
May 29, 2006
May 29, 2006
47
48
49
50
51
extern void X11_SaveScreenSaver(Display * display, int *saved_timeout,
BOOL * dpms);
extern void X11_DisableScreenSaver(Display * display);
extern void X11_RestoreScreenSaver(Display * display, int saved_timeout,
BOOL dpms);
May 17, 2006
May 17, 2006
52
Apr 26, 2001
Apr 26, 2001
53
/* Initialization/Query functions */
May 29, 2006
May 29, 2006
54
55
56
57
58
59
60
61
62
static int DGA_VideoInit(_THIS, SDL_PixelFormat * vformat);
static SDL_Rect **DGA_ListModes(_THIS, SDL_PixelFormat * format,
Uint32 flags);
static SDL_Surface *DGA_SetVideoMode(_THIS, SDL_Surface * current, int width,
int height, int bpp, Uint32 flags);
static int DGA_SetColors(_THIS, int firstcolor, int ncolors,
SDL_Color * colors);
static int DGA_SetGammaRamp(_THIS, Uint16 * ramp);
static void DGA_VideoQuit(_THIS);
Apr 26, 2001
Apr 26, 2001
63
64
/* Hardware surface functions */
May 29, 2006
May 29, 2006
65
66
67
68
69
70
71
72
73
74
75
static int DGA_InitHWSurfaces(_THIS, SDL_Surface * screen, Uint8 * base,
int size);
static void DGA_FreeHWSurfaces(_THIS);
static int DGA_AllocHWSurface(_THIS, SDL_Surface * surface);
static int DGA_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * rect,
Uint32 color);
static int DGA_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst);
static int DGA_LockHWSurface(_THIS, SDL_Surface * surface);
static void DGA_UnlockHWSurface(_THIS, SDL_Surface * surface);
static void DGA_FreeHWSurface(_THIS, SDL_Surface * surface);
static int DGA_FlipHWSurface(_THIS, SDL_Surface * surface);
Apr 26, 2001
Apr 26, 2001
76
77
78
/* DGA driver bootstrap functions */
May 28, 2006
May 28, 2006
79
static int
May 29, 2006
May 29, 2006
80
DGA_Available(void)
Apr 26, 2001
Apr 26, 2001
81
{
May 28, 2006
May 28, 2006
82
83
84
85
86
87
88
const char *display = NULL;
Display *dpy = NULL;
int available = 0;
/* The driver is available is available if the display is local
and the DGA 2.0+ extension is available, and we can map mem.
*/
May 29, 2006
May 29, 2006
89
90
91
92
if (SDL_X11_LoadSymbols()) {
if ((SDL_strncmp(XDisplayName(display), ":", 1) == 0) ||
(SDL_strncmp(XDisplayName(display), "unix:", 5) == 0)) {
dpy = XOpenDisplay(display);
May 28, 2006
May 28, 2006
93
94
95
if (dpy) {
int events, errors, major, minor;
May 29, 2006
May 29, 2006
96
if (SDL_NAME(XDGAQueryExtension)
May 28, 2006
May 28, 2006
97
(dpy, &events, &errors)
May 29, 2006
May 29, 2006
98
&& SDL_NAME(XDGAQueryVersion) (dpy, &major, &minor)) {
May 28, 2006
May 28, 2006
99
100
int screen;
May 29, 2006
May 29, 2006
101
screen = DefaultScreen(dpy);
May 28, 2006
May 28, 2006
102
if ((major >= 2) &&
May 29, 2006
May 29, 2006
103
SDL_NAME(XDGAOpenFramebuffer) (dpy, screen)) {
May 28, 2006
May 28, 2006
104
available = 1;
May 29, 2006
May 29, 2006
105
SDL_NAME(XDGACloseFramebuffer) (dpy, screen);
May 28, 2006
May 28, 2006
106
107
}
}
May 29, 2006
May 29, 2006
108
XCloseDisplay(dpy);
May 28, 2006
May 28, 2006
109
110
}
}
May 29, 2006
May 29, 2006
111
SDL_X11_UnloadSymbols();
May 28, 2006
May 28, 2006
112
113
}
return (available);
Apr 26, 2001
Apr 26, 2001
114
115
}
May 28, 2006
May 28, 2006
116
static void
May 29, 2006
May 29, 2006
117
DGA_DeleteDevice(SDL_VideoDevice * device)
Apr 26, 2001
Apr 26, 2001
118
{
May 28, 2006
May 28, 2006
119
if (device != NULL) {
May 29, 2006
May 29, 2006
120
121
122
SDL_free(device->hidden);
SDL_free(device);
SDL_X11_UnloadSymbols();
May 28, 2006
May 28, 2006
123
}
Apr 26, 2001
Apr 26, 2001
124
125
}
May 28, 2006
May 28, 2006
126
static SDL_VideoDevice *
May 29, 2006
May 29, 2006
127
DGA_CreateDevice(int devindex)
Apr 26, 2001
Apr 26, 2001
128
{
May 28, 2006
May 28, 2006
129
130
131
SDL_VideoDevice *device = NULL;
/* Initialize all variables that we clean on shutdown */
May 29, 2006
May 29, 2006
132
133
if (SDL_X11_LoadSymbols()) {
device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
May 28, 2006
May 28, 2006
134
if (device) {
May 29, 2006
May 29, 2006
135
SDL_memset(device, 0, (sizeof *device));
May 28, 2006
May 28, 2006
136
device->hidden = (struct SDL_PrivateVideoData *)
May 29, 2006
May 29, 2006
137
SDL_malloc((sizeof *device->hidden));
May 28, 2006
May 28, 2006
138
139
}
if ((device == NULL) || (device->hidden == NULL)) {
May 29, 2006
May 29, 2006
140
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
141
if (device) {
May 29, 2006
May 29, 2006
142
SDL_free(device);
May 28, 2006
May 28, 2006
143
}
May 29, 2006
May 29, 2006
144
SDL_X11_UnloadSymbols();
May 28, 2006
May 28, 2006
145
146
return (0);
}
May 29, 2006
May 29, 2006
147
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
May 28, 2006
May 28, 2006
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
/* Set the function pointers */
device->VideoInit = DGA_VideoInit;
device->ListModes = DGA_ListModes;
device->SetVideoMode = DGA_SetVideoMode;
device->SetColors = DGA_SetColors;
device->UpdateRects = NULL;
device->VideoQuit = DGA_VideoQuit;
device->AllocHWSurface = DGA_AllocHWSurface;
device->CheckHWBlit = DGA_CheckHWBlit;
device->FillHWRect = DGA_FillHWRect;
device->SetHWColorKey = NULL;
device->SetHWAlpha = NULL;
device->LockHWSurface = DGA_LockHWSurface;
device->UnlockHWSurface = DGA_UnlockHWSurface;
device->FlipHWSurface = DGA_FlipHWSurface;
device->FreeHWSurface = DGA_FreeHWSurface;
device->SetGammaRamp = DGA_SetGammaRamp;
device->GetGammaRamp = NULL;
device->SetCaption = NULL;
device->SetIcon = NULL;
device->IconifyWindow = NULL;
device->GrabInput = NULL;
device->GetWMInfo = NULL;
device->InitOSKeymap = DGA_InitOSKeymap;
device->PumpEvents = DGA_PumpEvents;
device->free = DGA_DeleteDevice;
}
return device;
Apr 26, 2001
Apr 26, 2001
179
180
181
}
VideoBootStrap DGA_bootstrap = {
May 28, 2006
May 28, 2006
182
183
"dga", "XFree86 DGA 2.0",
DGA_Available, DGA_CreateDevice
Apr 26, 2001
Apr 26, 2001
184
185
};
May 28, 2006
May 28, 2006
186
static int
May 29, 2006
May 29, 2006
187
DGA_AddMode(_THIS, int bpp, int w, int h)
Apr 26, 2001
Apr 26, 2001
188
{
May 28, 2006
May 28, 2006
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
SDL_Rect *mode;
int index;
int next_mode;
/* Check to see if we already have this mode */
if (bpp < 8) { /* Not supported */
return (0);
}
index = ((bpp + 7) / 8) - 1;
if (SDL_nummodes[index] > 0) {
mode = SDL_modelist[index][SDL_nummodes[index] - 1];
if ((mode->w == w) && (mode->h == h)) {
return (0);
}
}
/* Set up the new video mode rectangle */
May 29, 2006
May 29, 2006
206
mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
May 28, 2006
May 28, 2006
207
if (mode == NULL) {
May 29, 2006
May 29, 2006
208
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
209
210
211
212
213
214
215
216
217
218
return (-1);
}
mode->x = 0;
mode->y = 0;
mode->w = w;
mode->h = h;
/* Allocate the new list of modes, and fill in the new mode */
next_mode = SDL_nummodes[index];
SDL_modelist[index] = (SDL_Rect **)
May 29, 2006
May 29, 2006
219
220
SDL_realloc(SDL_modelist[index],
(1 + next_mode + 1) * sizeof(SDL_Rect *));
May 28, 2006
May 28, 2006
221
if (SDL_modelist[index] == NULL) {
May 29, 2006
May 29, 2006
222
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
223
SDL_nummodes[index] = 0;
May 29, 2006
May 29, 2006
224
SDL_free(mode);
May 28, 2006
May 28, 2006
225
226
227
228
229
230
231
return (-1);
}
SDL_modelist[index][next_mode] = mode;
SDL_modelist[index][next_mode + 1] = NULL;
SDL_nummodes[index]++;
return (0);
Apr 26, 2001
Apr 26, 2001
232
233
234
}
/* This whole function is a hack. :) */
May 28, 2006
May 28, 2006
235
static Uint32
May 29, 2006
May 29, 2006
236
get_video_size(_THIS)
Apr 26, 2001
Apr 26, 2001
237
{
May 28, 2006
May 28, 2006
238
/* This is a non-exported function from libXxf86dga.a */
May 29, 2006
May 29, 2006
239
extern unsigned char *SDL_NAME(XDGAGetMappedMemory) (int screen);
May 28, 2006
May 28, 2006
240
241
242
243
244
245
FILE *proc;
unsigned long mem;
unsigned start, stop;
char line[BUFSIZ];
Uint32 size;
May 29, 2006
May 29, 2006
246
mem = (unsigned long) SDL_NAME(XDGAGetMappedMemory) (DGA_Screen);
May 28, 2006
May 28, 2006
247
size = 0;
May 29, 2006
May 29, 2006
248
proc = fopen("/proc/self/maps", "r");
May 28, 2006
May 28, 2006
249
if (proc) {
May 29, 2006
May 29, 2006
250
251
while (fgets(line, sizeof(line) - 1, proc)) {
SDL_sscanf(line, "%x-%x", &start, &stop);
May 28, 2006
May 28, 2006
252
253
254
255
256
if (start == mem) {
size = (Uint32) ((stop - start) / 1024);
break;
}
}
May 29, 2006
May 29, 2006
257
fclose(proc);
May 28, 2006
May 28, 2006
258
259
}
return (size);
Apr 26, 2001
Apr 26, 2001
260
261
262
}
#ifdef DGA_DEBUG
May 28, 2006
May 28, 2006
263
static void
May 29, 2006
May 29, 2006
264
PrintMode(SDL_NAME(XDGAMode) * mode)
Apr 26, 2001
Apr 26, 2001
265
{
May 29, 2006
May 29, 2006
266
267
268
269
270
271
272
273
274
275
276
277
printf("Mode: %s (%dx%d) at %d bpp (%f refresh, %d pitch) num: %d\n",
mode->name,
mode->viewportWidth, mode->viewportHeight,
mode->depth == 24 ? mode->bitsPerPixel : mode->depth,
mode->verticalRefresh, mode->bytesPerScanline, mode->num);
printf("\tRGB: 0x%8.8x 0x%8.8x 0x%8.8x (%d - %s)\n",
mode->redMask, mode->greenMask, mode->blueMask,
mode->visualClass,
mode->visualClass == TrueColor ? "truecolor" :
mode->visualClass == DirectColor ? "directcolor" :
mode->visualClass == PseudoColor ? "pseudocolor" : "unknown");
printf("\tFlags: ");
May 28, 2006
May 28, 2006
278
if (mode->flags & XDGAConcurrentAccess)
May 29, 2006
May 29, 2006
279
printf(" XDGAConcurrentAccess");
May 28, 2006
May 28, 2006
280
if (mode->flags & XDGASolidFillRect)
May 29, 2006
May 29, 2006
281
printf(" XDGASolidFillRect");
May 28, 2006
May 28, 2006
282
if (mode->flags & XDGABlitRect)
May 29, 2006
May 29, 2006
283
printf(" XDGABlitRect");
May 28, 2006
May 28, 2006
284
if (mode->flags & XDGABlitTransRect)
May 29, 2006
May 29, 2006
285
printf(" XDGABlitTransRect");
May 28, 2006
May 28, 2006
286
if (mode->flags & XDGAPixmap)
May 29, 2006
May 29, 2006
287
printf(" XDGAPixmap");
May 28, 2006
May 28, 2006
288
if (mode->flags & XDGAInterlaced)
May 29, 2006
May 29, 2006
289
printf(" XDGAInterlaced");
May 28, 2006
May 28, 2006
290
if (mode->flags & XDGADoublescan)
May 29, 2006
May 29, 2006
291
printf(" XDGADoublescan");
May 28, 2006
May 28, 2006
292
if (mode->viewportFlags & XDGAFlipRetrace)
May 29, 2006
May 29, 2006
293
printf(" XDGAFlipRetrace");
May 28, 2006
May 28, 2006
294
if (mode->viewportFlags & XDGAFlipImmediate)
May 29, 2006
May 29, 2006
295
296
printf(" XDGAFlipImmediate");
printf("\n");
Apr 26, 2001
Apr 26, 2001
297
298
299
}
#endif /* DGA_DEBUG */
May 28, 2006
May 28, 2006
300
static int
May 29, 2006
May 29, 2006
301
cmpmodes(const void *va, const void *vb)
Apr 26, 2001
Apr 26, 2001
302
{
May 29, 2006
May 29, 2006
303
304
const SDL_NAME(XDGAMode) * a = (const SDL_NAME(XDGAMode) *) va;
const SDL_NAME(XDGAMode) * b = (const SDL_NAME(XDGAMode) *) vb;
Apr 26, 2001
Apr 26, 2001
305
May 28, 2006
May 28, 2006
306
307
if ((a->viewportWidth == b->viewportWidth) &&
(b->viewportHeight == a->viewportHeight)) {
May 17, 2006
May 17, 2006
308
309
310
/* Prefer 32 bpp over 24 bpp, 16 bpp over 15 bpp */
int a_bpp = a->depth == 24 ? a->bitsPerPixel : a->depth;
int b_bpp = b->depth == 24 ? b->bitsPerPixel : b->depth;
May 28, 2006
May 28, 2006
311
if (a_bpp != b_bpp) {
May 17, 2006
May 17, 2006
312
313
314
return b_bpp - a_bpp;
}
/* Prefer DirectColor visuals, for gamma support */
May 28, 2006
May 28, 2006
315
if (a->visualClass == DirectColor && b->visualClass != DirectColor)
Apr 26, 2001
Apr 26, 2001
316
return -1;
May 28, 2006
May 28, 2006
317
if (b->visualClass == DirectColor && a->visualClass != DirectColor)
Nov 12, 2004
Nov 12, 2004
318
return 1;
May 17, 2006
May 17, 2006
319
320
/* Maintain server refresh rate sorting */
return a->num - b->num;
May 28, 2006
May 28, 2006
321
} else if (a->viewportWidth == b->viewportWidth) {
Apr 26, 2001
Apr 26, 2001
322
return b->viewportHeight - a->viewportHeight;
Nov 12, 2004
Nov 12, 2004
323
324
} else {
return b->viewportWidth - a->viewportWidth;
Apr 26, 2001
Apr 26, 2001
325
326
}
}
May 28, 2006
May 28, 2006
327
static void
May 29, 2006
May 29, 2006
328
UpdateHWInfo(_THIS, SDL_NAME(XDGAMode) * mode)
Apr 26, 2001
Apr 26, 2001
329
{
May 28, 2006
May 28, 2006
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
this->info.wm_available = 0;
this->info.hw_available = 1;
if (mode->flags & XDGABlitRect) {
this->info.blit_hw = 1;
} else {
this->info.blit_hw = 0;
}
if (mode->flags & XDGABlitTransRect) {
this->info.blit_hw_CC = 1;
} else {
this->info.blit_hw_CC = 0;
}
if (mode->flags & XDGASolidFillRect) {
this->info.blit_fill = 1;
} else {
this->info.blit_fill = 0;
}
May 29, 2006
May 29, 2006
347
this->info.video_mem = get_video_size(this);
Apr 26, 2001
Apr 26, 2001
348
349
}
May 28, 2006
May 28, 2006
350
static int
May 29, 2006
May 29, 2006
351
DGA_VideoInit(_THIS, SDL_PixelFormat * vformat)
Apr 26, 2001
Apr 26, 2001
352
{
May 28, 2006
May 28, 2006
353
354
355
356
const char *display;
int event_base, error_base;
int major_version, minor_version;
Visual *visual;
May 29, 2006
May 29, 2006
357
SDL_NAME(XDGAMode) * modes;
May 28, 2006
May 28, 2006
358
359
360
361
362
int i, num_modes;
/* Open the X11 display */
display = NULL; /* Get it from DISPLAY environment variable */
May 29, 2006
May 29, 2006
363
DGA_Display = XOpenDisplay(display);
May 28, 2006
May 28, 2006
364
if (DGA_Display == NULL) {
May 29, 2006
May 29, 2006
365
SDL_SetError("Couldn't open X11 display");
May 28, 2006
May 28, 2006
366
367
368
369
return (-1);
}
/* Check for the DGA extension */
May 29, 2006
May 29, 2006
370
371
372
373
374
if (!SDL_NAME(XDGAQueryExtension) (DGA_Display, &event_base, &error_base)
|| !SDL_NAME(XDGAQueryVersion) (DGA_Display, &major_version,
&minor_version)) {
SDL_SetError("DGA extension not available");
XCloseDisplay(DGA_Display);
May 28, 2006
May 28, 2006
375
376
377
return (-1);
}
if (major_version < 2) {
May 29, 2006
May 29, 2006
378
379
SDL_SetError("DGA driver requires DGA 2.0 or newer");
XCloseDisplay(DGA_Display);
May 28, 2006
May 28, 2006
380
381
382
383
384
return (-1);
}
DGA_event_base = event_base;
/* Determine the current screen size */
May 29, 2006
May 29, 2006
385
386
this->info.current_w = DisplayWidth(DGA_Display, DGA_Screen);
this->info.current_h = DisplayHeight(DGA_Display, DGA_Screen);
May 28, 2006
May 28, 2006
387
388
/* Determine the current screen depth */
May 29, 2006
May 29, 2006
389
visual = DefaultVisual(DGA_Display, DGA_Screen);
May 28, 2006
May 28, 2006
390
391
392
393
{
XPixmapFormatValues *pix_format;
int i, num_formats;
May 29, 2006
May 29, 2006
394
395
vformat->BitsPerPixel = DefaultDepth(DGA_Display, DGA_Screen);
pix_format = XListPixmapFormats(DGA_Display, &num_formats);
May 28, 2006
May 28, 2006
396
if (pix_format == NULL) {
May 29, 2006
May 29, 2006
397
398
SDL_SetError("Couldn't determine screen formats");
XCloseDisplay(DGA_Display);
May 28, 2006
May 28, 2006
399
400
401
402
403
404
405
406
return (-1);
}
for (i = 0; i < num_formats; ++i) {
if (vformat->BitsPerPixel == pix_format[i].depth)
break;
}
if (i != num_formats)
vformat->BitsPerPixel = pix_format[i].bits_per_pixel;
May 29, 2006
May 29, 2006
407
XFree((char *) pix_format);
May 28, 2006
May 28, 2006
408
409
410
411
412
413
414
415
}
if (vformat->BitsPerPixel > 8) {
vformat->Rmask = visual->red_mask;
vformat->Gmask = visual->green_mask;
vformat->Bmask = visual->blue_mask;
}
/* Open access to the framebuffer */
May 29, 2006
May 29, 2006
416
417
418
if (!SDL_NAME(XDGAOpenFramebuffer) (DGA_Display, DGA_Screen)) {
SDL_SetError("Unable to map the video memory");
XCloseDisplay(DGA_Display);
May 28, 2006
May 28, 2006
419
420
421
422
return (-1);
}
/* Save DPMS and screensaver settings */
May 29, 2006
May 29, 2006
423
424
X11_SaveScreenSaver(DGA_Display, &screensaver_timeout, &dpms_enabled);
X11_DisableScreenSaver(DGA_Display);
May 28, 2006
May 28, 2006
425
426
/* Query for the list of available video modes */
May 29, 2006
May 29, 2006
427
428
modes = SDL_NAME(XDGAQueryModes) (DGA_Display, DGA_Screen, &num_modes);
SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
May 28, 2006
May 28, 2006
429
430
431
432
433
for (i = 0; i < num_modes; ++i) {
if (((modes[i].visualClass == PseudoColor) ||
(modes[i].visualClass == DirectColor) ||
(modes[i].visualClass == TrueColor)) &&
!(modes[i].flags & (XDGAInterlaced | XDGADoublescan))) {
Apr 26, 2001
Apr 26, 2001
434
#ifdef DGA_DEBUG
May 29, 2006
May 29, 2006
435
PrintMode(&modes[i]);
Apr 26, 2001
Apr 26, 2001
436
#endif
May 29, 2006
May 29, 2006
437
438
DGA_AddMode(this, modes[i].bitsPerPixel,
modes[i].viewportWidth, modes[i].viewportHeight);
May 28, 2006
May 28, 2006
439
440
}
}
May 29, 2006
May 29, 2006
441
442
UpdateHWInfo(this, modes);
XFree(modes);
May 28, 2006
May 28, 2006
443
444
/* Create the hardware surface lock mutex */
May 29, 2006
May 29, 2006
445
hw_lock = SDL_CreateMutex();
May 28, 2006
May 28, 2006
446
if (hw_lock == NULL) {
May 29, 2006
May 29, 2006
447
448
SDL_SetError("Unable to create lock mutex");
DGA_VideoQuit(this);
May 28, 2006
May 28, 2006
449
450
return (-1);
}
Jul 12, 2001
Jul 12, 2001
451
#ifdef LOCK_DGA_DISPLAY
May 28, 2006
May 28, 2006
452
/* Create the event lock so we're thread-safe.. :-/ */
May 29, 2006
May 29, 2006
453
event_lock = SDL_CreateMutex();
Jul 12, 2001
Jul 12, 2001
454
455
#endif /* LOCK_DGA_DISPLAY */
May 28, 2006
May 28, 2006
456
457
/* We're done! */
return (0);
Apr 26, 2001
Apr 26, 2001
458
459
}
May 28, 2006
May 28, 2006
460
SDL_Rect **
May 29, 2006
May 29, 2006
461
DGA_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
Apr 26, 2001
Apr 26, 2001
462
{
May 28, 2006
May 28, 2006
463
return (SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]);
Apr 26, 2001
Apr 26, 2001
464
465
466
}
/* Various screen update functions available */
May 29, 2006
May 29, 2006
467
static void DGA_DirectUpdate(_THIS, int numrects, SDL_Rect * rects);
Apr 26, 2001
Apr 26, 2001
468
May 28, 2006
May 28, 2006
469
SDL_Surface *
May 29, 2006
May 29, 2006
470
471
DGA_SetVideoMode(_THIS, SDL_Surface * current,
int width, int height, int bpp, Uint32 flags)
Apr 26, 2001
Apr 26, 2001
472
{
May 29, 2006
May 29, 2006
473
SDL_NAME(XDGAMode) * modes;
May 28, 2006
May 28, 2006
474
int i, num_modes;
May 29, 2006
May 29, 2006
475
SDL_NAME(XDGADevice) * mode;
May 28, 2006
May 28, 2006
476
477
478
479
480
481
int screen_len;
Uint8 *surfaces_mem;
int surfaces_len;
/* Free any previous colormap */
if (DGA_colormap) {
May 29, 2006
May 29, 2006
482
XFreeColormap(DGA_Display, DGA_colormap);
May 28, 2006
May 28, 2006
483
484
485
486
DGA_colormap = 0;
}
/* Search for a matching video mode */
May 29, 2006
May 29, 2006
487
488
modes = SDL_NAME(XDGAQueryModes) (DGA_Display, DGA_Screen, &num_modes);
SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
May 28, 2006
May 28, 2006
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
for (i = 0; i < num_modes; ++i) {
int depth;
depth = modes[i].depth;
if (depth == 24) { /* Distinguish between 24 and 32 bpp */
depth = modes[i].bitsPerPixel;
}
if ((depth == bpp) &&
(modes[i].viewportWidth == width) &&
(modes[i].viewportHeight == height) &&
((modes[i].visualClass == PseudoColor) ||
(modes[i].visualClass == DirectColor) ||
(modes[i].visualClass == TrueColor)) &&
!(modes[i].flags & (XDGAInterlaced | XDGADoublescan))) {
break;
}
}
if (i == num_modes) {
May 29, 2006
May 29, 2006
507
SDL_SetError("No matching video mode found");
May 28, 2006
May 28, 2006
508
509
return (NULL);
}
May 17, 2006
May 17, 2006
510
#ifdef DGA_DEBUG
May 29, 2006
May 29, 2006
511
PrintMode(&modes[i]);
May 17, 2006
May 17, 2006
512
#endif
Apr 26, 2001
Apr 26, 2001
513
May 28, 2006
May 28, 2006
514
/* Set the video mode */
May 29, 2006
May 29, 2006
515
516
mode = SDL_NAME(XDGASetMode) (DGA_Display, DGA_Screen, modes[i].num);
XFree(modes);
May 28, 2006
May 28, 2006
517
if (mode == NULL) {
May 29, 2006
May 29, 2006
518
SDL_SetError("Unable to switch to requested mode");
May 28, 2006
May 28, 2006
519
520
521
522
523
524
525
526
527
528
529
530
return (NULL);
}
DGA_visualClass = mode->mode.visualClass;
memory_base = (Uint8 *) mode->data;
memory_pitch = mode->mode.bytesPerScanline;
/* Set up the new mode framebuffer */
current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE);
current->w = mode->mode.viewportWidth;
current->h = mode->mode.viewportHeight;
current->pitch = memory_pitch;
current->pixels = memory_base;
May 29, 2006
May 29, 2006
531
532
533
if (!SDL_ReallocFormat(current, mode->mode.bitsPerPixel,
mode->mode.redMask,
mode->mode.greenMask, mode->mode.blueMask, 0)) {
May 28, 2006
May 28, 2006
534
535
536
537
538
539
540
return (NULL);
}
screen_len = current->h * current->pitch;
/* Create a colormap if necessary */
if ((DGA_visualClass == PseudoColor) || (DGA_visualClass == DirectColor)) {
DGA_colormap =
May 29, 2006
May 29, 2006
541
542
SDL_NAME(XDGACreateColormap) (DGA_Display, DGA_Screen, mode,
AllocAll);
May 28, 2006
May 28, 2006
543
544
545
546
if (DGA_visualClass == PseudoColor) {
current->flags |= SDL_HWPALETTE;
} else {
/* Initialize the colormap to the identity mapping */
May 29, 2006
May 29, 2006
547
SDL_GetGammaRamp(0, 0, 0);
May 28, 2006
May 28, 2006
548
this->screen = current;
May 29, 2006
May 29, 2006
549
DGA_SetGammaRamp(this, this->gamma);
May 28, 2006
May 28, 2006
550
551
552
553
this->screen = NULL;
}
} else {
DGA_colormap =
May 29, 2006
May 29, 2006
554
555
SDL_NAME(XDGACreateColormap) (DGA_Display, DGA_Screen, mode,
AllocNone);
May 28, 2006
May 28, 2006
556
}
May 29, 2006
May 29, 2006
557
SDL_NAME(XDGAInstallColormap) (DGA_Display, DGA_Screen, DGA_colormap);
May 28, 2006
May 28, 2006
558
559
/* Update the hardware capabilities */
May 29, 2006
May 29, 2006
560
UpdateHWInfo(this, &mode->mode);
May 28, 2006
May 28, 2006
561
562
563
564
565
566
/* Set up the information for hardware surfaces */
surfaces_mem = (Uint8 *) current->pixels + screen_len;
surfaces_len = (mode->mode.imageHeight * current->pitch - screen_len);
/* Update for double-buffering, if we can */
May 29, 2006
May 29, 2006
567
568
SDL_NAME(XDGASetViewport) (DGA_Display, DGA_Screen, 0, 0,
XDGAFlipRetrace);
May 28, 2006
May 28, 2006
569
570
571
572
573
574
575
576
577
578
579
580
581
582
if (flags & SDL_DOUBLEBUF) {
if (mode->mode.imageHeight >= (current->h * 2)) {
current->flags |= SDL_DOUBLEBUF;
flip_page = 0;
flip_yoffset[0] = 0;
flip_yoffset[1] = current->h;
flip_address[0] = memory_base;
flip_address[1] = memory_base + screen_len;
surfaces_mem += screen_len;
surfaces_len -= screen_len;
}
}
/* Allocate memory tracking for hardware surfaces */
May 29, 2006
May 29, 2006
583
DGA_FreeHWSurfaces(this);
May 28, 2006
May 28, 2006
584
585
586
if (surfaces_len < 0) {
surfaces_len = 0;
}
May 29, 2006
May 29, 2006
587
DGA_InitHWSurfaces(this, current, surfaces_mem, surfaces_len);
May 28, 2006
May 28, 2006
588
589
590
591
/* Expose the back buffer as surface memory */
if (current->flags & SDL_DOUBLEBUF) {
this->screen = current;
May 29, 2006
May 29, 2006
592
DGA_FlipHWSurface(this, current);
May 28, 2006
May 28, 2006
593
594
595
596
597
598
599
600
601
602
603
604
this->screen = NULL;
}
/* Set the update rectangle function */
this->UpdateRects = DGA_DirectUpdate;
/* Enable mouse and keyboard support */
{
long input_mask;
input_mask = (KeyPressMask | KeyReleaseMask);
input_mask |= (ButtonPressMask | ButtonReleaseMask);
input_mask |= PointerMotionMask;
May 29, 2006
May 29, 2006
605
SDL_NAME(XDGASelectInput) (DGA_Display, DGA_Screen, input_mask);
May 28, 2006
May 28, 2006
606
607
608
609
}
/* We're done */
return (current);
Apr 26, 2001
Apr 26, 2001
610
611
612
}
#ifdef DGA_DEBUG
May 28, 2006
May 28, 2006
613
static void
May 29, 2006
May 29, 2006
614
DGA_DumpHWSurfaces(_THIS)
Apr 26, 2001
Apr 26, 2001
615
{
May 28, 2006
May 28, 2006
616
617
vidmem_bucket *bucket;
May 29, 2006
May 29, 2006
618
619
620
621
printf("Memory left: %d (%d total)\n", surfaces_memleft,
surfaces_memtotal);
printf("\n");
printf(" Base Size\n");
May 28, 2006
May 28, 2006
622
for (bucket = &surfaces; bucket; bucket = bucket->next) {
May 29, 2006
May 29, 2006
623
624
printf("Bucket: %p, %d (%s)\n", bucket->base, bucket->size,
bucket->used ? "used" : "free");
May 28, 2006
May 28, 2006
625
626
if (bucket->prev) {
if (bucket->base != bucket->prev->base + bucket->prev->size) {
May 29, 2006
May 29, 2006
627
printf("Warning, corrupt bucket list! (prev)\n");
May 28, 2006
May 28, 2006
628
629
630
}
} else {
if (bucket != &surfaces) {
May 29, 2006
May 29, 2006
631
printf("Warning, corrupt bucket list! (!prev)\n");
May 28, 2006
May 28, 2006
632
633
634
635
}
}
if (bucket->next) {
if (bucket->next->base != bucket->base + bucket->size) {
May 29, 2006
May 29, 2006
636
printf("Warning, corrupt bucket list! (next)\n");
May 28, 2006
May 28, 2006
637
638
639
}
}
}
May 29, 2006
May 29, 2006
640
printf("\n");
Apr 26, 2001
Apr 26, 2001
641
642
643
}
#endif
May 28, 2006
May 28, 2006
644
static int
May 29, 2006
May 29, 2006
645
DGA_InitHWSurfaces(_THIS, SDL_Surface * screen, Uint8 * base, int size)
Apr 26, 2001
Apr 26, 2001
646
{
May 28, 2006
May 28, 2006
647
648
649
650
651
652
vidmem_bucket *bucket;
surfaces_memtotal = size;
surfaces_memleft = size;
if (surfaces_memleft > 0) {
May 29, 2006
May 29, 2006
653
bucket = (vidmem_bucket *) SDL_malloc(sizeof(*bucket));
May 28, 2006
May 28, 2006
654
if (bucket == NULL) {
May 29, 2006
May 29, 2006
655
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
return (-1);
}
bucket->prev = &surfaces;
bucket->used = 0;
bucket->dirty = 0;
bucket->base = base;
bucket->size = size;
bucket->next = NULL;
} else {
bucket = NULL;
}
surfaces.prev = NULL;
surfaces.used = 1;
surfaces.dirty = 0;
surfaces.base = screen->pixels;
surfaces.size = (unsigned int) ((long) base - (long) surfaces.base);
surfaces.next = bucket;
screen->hwdata = (struct private_hwdata *) &surfaces;
return (0);
Apr 26, 2001
Apr 26, 2001
676
}
May 28, 2006
May 28, 2006
677
static void
May 29, 2006
May 29, 2006
678
DGA_FreeHWSurfaces(_THIS)
Apr 26, 2001
Apr 26, 2001
679
{
May 28, 2006
May 28, 2006
680
681
682
683
684
685
vidmem_bucket *bucket, *freeable;
bucket = surfaces.next;
while (bucket) {
freeable = bucket;
bucket = bucket->next;
May 29, 2006
May 29, 2006
686
SDL_free(freeable);
May 28, 2006
May 28, 2006
687
688
}
surfaces.next = NULL;
Apr 26, 2001
Apr 26, 2001
689
690
}
May 28, 2006
May 28, 2006
691
static __inline__ void
May 29, 2006
May 29, 2006
692
DGA_AddBusySurface(SDL_Surface * surface)
Jul 12, 2001
Jul 12, 2001
693
{
May 28, 2006
May 28, 2006
694
((vidmem_bucket *) surface->hwdata)->dirty = 1;
Jul 12, 2001
Jul 12, 2001
695
696
}
May 28, 2006
May 28, 2006
697
static __inline__ int
May 29, 2006
May 29, 2006
698
DGA_IsSurfaceBusy(SDL_Surface * surface)
Jul 12, 2001
Jul 12, 2001
699
{
May 28, 2006
May 28, 2006
700
return ((vidmem_bucket *) surface->hwdata)->dirty;
Jul 12, 2001
Jul 12, 2001
701
702
}
May 28, 2006
May 28, 2006
703
static __inline__ void
May 29, 2006
May 29, 2006
704
DGA_WaitBusySurfaces(_THIS)
Jul 12, 2001
Jul 12, 2001
705
{
May 28, 2006
May 28, 2006
706
vidmem_bucket *bucket;
Jul 12, 2001
Jul 12, 2001
707
May 28, 2006
May 28, 2006
708
/* Wait for graphic operations to complete */
May 29, 2006
May 29, 2006
709
SDL_NAME(XDGASync) (DGA_Display, DGA_Screen);
Jul 12, 2001
Jul 12, 2001
710
May 28, 2006
May 28, 2006
711
712
713
714
/* Clear all surface dirty bits */
for (bucket = &surfaces; bucket; bucket = bucket->next) {
bucket->dirty = 0;
}
Jul 12, 2001
Jul 12, 2001
715
716
}
May 28, 2006
May 28, 2006
717
static int
May 29, 2006
May 29, 2006
718
DGA_AllocHWSurface(_THIS, SDL_Surface * surface)
Apr 26, 2001
Apr 26, 2001
719
{
May 28, 2006
May 28, 2006
720
721
722
723
vidmem_bucket *bucket;
int size;
int extra;
int retval = 0;
Apr 26, 2001
Apr 26, 2001
724
725
726
727
728
/* Temporarily, we only allow surfaces the same width as display.
Some blitters require the pitch between two hardware surfaces
to be the same. Others have interesting alignment restrictions.
*/
May 28, 2006
May 28, 2006
729
if (surface->pitch > SDL_VideoSurface->pitch) {
May 29, 2006
May 29, 2006
730
SDL_SetError("Surface requested wider than screen");
May 28, 2006
May 28, 2006
731
732
733
734
return (-1);
}
surface->pitch = SDL_VideoSurface->pitch;
size = surface->h * surface->pitch;
Apr 26, 2001
Apr 26, 2001
735
#ifdef DGA_DEBUG
May 29, 2006
May 29, 2006
736
fprintf(stderr, "Allocating bucket of %d bytes\n", size);
Apr 26, 2001
Apr 26, 2001
737
#endif
May 29, 2006
May 29, 2006
738
LOCK_DISPLAY();
May 28, 2006
May 28, 2006
739
740
741
/* Quick check for available mem */
if (size > surfaces_memleft) {
May 29, 2006
May 29, 2006
742
SDL_SetError("Not enough video memory");
May 28, 2006
May 28, 2006
743
744
745
746
747
748
749
750
751
752
753
retval = -1;
goto done;
}
/* Search for an empty bucket big enough */
for (bucket = &surfaces; bucket; bucket = bucket->next) {
if (!bucket->used && (size <= bucket->size)) {
break;
}
}
if (bucket == NULL) {
May 29, 2006
May 29, 2006
754
SDL_SetError("Video memory too fragmented");
May 28, 2006
May 28, 2006
755
756
757
758
759
760
761
762
retval = -1;
goto done;
}
/* Create a new bucket for left-over memory */
extra = (bucket->size - size);
if (extra) {
vidmem_bucket *newbucket;
Apr 26, 2001
Apr 26, 2001
763
764
#ifdef DGA_DEBUG
May 29, 2006
May 29, 2006
765
fprintf(stderr, "Adding new free bucket of %d bytes\n", extra);
Apr 26, 2001
Apr 26, 2001
766
#endif
May 29, 2006
May 29, 2006
767
newbucket = (vidmem_bucket *) SDL_malloc(sizeof(*newbucket));
May 28, 2006
May 28, 2006
768
if (newbucket == NULL) {
May 29, 2006
May 29, 2006
769
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
retval = -1;
goto done;
}
newbucket->prev = bucket;
newbucket->used = 0;
newbucket->base = bucket->base + size;
newbucket->size = extra;
newbucket->next = bucket->next;
if (bucket->next) {
bucket->next->prev = newbucket;
}
bucket->next = newbucket;
}
/* Set the current bucket values and return it! */
bucket->used = 1;
bucket->size = size;
bucket->dirty = 0;
Apr 26, 2001
Apr 26, 2001
788
#ifdef DGA_DEBUG
May 29, 2006
May 29, 2006
789
fprintf(stderr, "Allocated %d bytes at %p\n", bucket->size, bucket->base);
Apr 26, 2001
Apr 26, 2001
790
#endif
May 28, 2006
May 28, 2006
791
792
793
794
795
surfaces_memleft -= size;
surface->flags |= SDL_HWSURFACE;
surface->pixels = bucket->base;
surface->hwdata = (struct private_hwdata *) bucket;
done:
May 29, 2006
May 29, 2006
796
UNLOCK_DISPLAY();
May 28, 2006
May 28, 2006
797
return (retval);
Apr 26, 2001
Apr 26, 2001
798
}
May 28, 2006
May 28, 2006
799
static void
May 29, 2006
May 29, 2006
800
DGA_FreeHWSurface(_THIS, SDL_Surface * surface)
Apr 26, 2001
Apr 26, 2001
801
{
May 28, 2006
May 28, 2006
802
803
804
vidmem_bucket *bucket, *freeable;
/* Wait for any pending operations involving this surface */
May 29, 2006
May 29, 2006
805
806
807
808
if (DGA_IsSurfaceBusy(surface)) {
LOCK_DISPLAY();
DGA_WaitBusySurfaces(this);
UNLOCK_DISPLAY();
May 28, 2006
May 28, 2006
809
810
811
812
813
814
815
816
817
818
}
/* Look for the bucket in the current list */
for (bucket = &surfaces; bucket; bucket = bucket->next) {
if (bucket == (vidmem_bucket *) surface->hwdata) {
break;
}
}
if (bucket && bucket->used) {
/* Add the memory back to the total */
Apr 26, 2001
Apr 26, 2001
819
#ifdef DGA_DEBUG
May 29, 2006
May 29, 2006
820
printf("Freeing bucket of %d bytes\n", bucket->size);
Apr 26, 2001
Apr 26, 2001
821
#endif
May 28, 2006
May 28, 2006
822
surfaces_memleft += bucket->size;
Apr 26, 2001
Apr 26, 2001
823
May 28, 2006
May 28, 2006
824
825
826
/* Can we merge the space with surrounding buckets? */
bucket->used = 0;
if (bucket->next && !bucket->next->used) {
Apr 26, 2001
Apr 26, 2001
827
#ifdef DGA_DEBUG
May 29, 2006
May 29, 2006
828
829
printf("Merging with next bucket, for %d total bytes\n",
bucket->size + bucket->next->size);
Apr 26, 2001
Apr 26, 2001
830
#endif
May 28, 2006
May 28, 2006
831
832
833
834
835
836
freeable = bucket->next;
bucket->size += bucket->next->size;
bucket->next = bucket->next->next;
if (bucket->next) {
bucket->next->prev = bucket;
}
May 29, 2006
May 29, 2006
837
SDL_free(freeable);
May 28, 2006
May 28, 2006
838
839
}
if (bucket->prev && !bucket->prev->used) {
Apr 26, 2001
Apr 26, 2001
840
#ifdef DGA_DEBUG
May 29, 2006
May 29, 2006
841
842
printf("Merging with previous bucket, for %d total bytes\n",
bucket->prev->size + bucket->size);
Apr 26, 2001
Apr 26, 2001
843
#endif
May 28, 2006
May 28, 2006
844
845
846
847
848
849
freeable = bucket;
bucket->prev->size += bucket->size;
bucket->prev->next = bucket->next;
if (bucket->next) {
bucket->next->prev = bucket->prev;
}
May 29, 2006
May 29, 2006
850
SDL_free(freeable);
May 28, 2006
May 28, 2006
851
852
853
854
}
}
surface->pixels = NULL;
surface->hwdata = NULL;
Apr 26, 2001
Apr 26, 2001
855
856
}
May 28, 2006
May 28, 2006
857
static __inline__ void
May 29, 2006
May 29, 2006
858
DGA_dst_to_xy(_THIS, SDL_Surface * dst, int *x, int *y)
Apr 26, 2001
Apr 26, 2001
859
{
May 28, 2006
May 28, 2006
860
861
*x = (long) ((Uint8 *) dst->pixels - memory_base) % memory_pitch;
*y = (long) ((Uint8 *) dst->pixels - memory_base) / memory_pitch;
Apr 26, 2001
Apr 26, 2001
862
863
}
May 28, 2006
May 28, 2006
864
static int
May 29, 2006
May 29, 2006
865
DGA_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * rect, Uint32 color)
Apr 26, 2001
Apr 26, 2001
866
{
May 28, 2006
May 28, 2006
867
868
869
870
int x, y;
unsigned int w, h;
/* Don't fill the visible part of the screen, wait until flipped */
May 29, 2006
May 29, 2006
871
LOCK_DISPLAY();
May 28, 2006
May 28, 2006
872
if (was_flipped && (dst == this->screen)) {
May 29, 2006
May 29, 2006
873
while (SDL_NAME(XDGAGetViewportStatus) (DGA_Display, DGA_Screen))
May 28, 2006
May 28, 2006
874
875
876
/* Keep waiting for the hardware ... */ ;
was_flipped = 0;
}
May 29, 2006
May 29, 2006
877
DGA_dst_to_xy(this, dst, &x, &y);
May 28, 2006
May 28, 2006
878
879
880
881
x += rect->x;
y += rect->y;
w = rect->w;
h = rect->h;
Apr 26, 2001
Apr 26, 2001
882
#if 0
May 29, 2006
May 29, 2006
883
884
printf("Hardware accelerated rectangle fill: %dx%d at %d,%d\n", w, h, x,
y);
Apr 26, 2001
Apr 26, 2001
885
#endif
May 29, 2006
May 29, 2006
886
SDL_NAME(XDGAFillRectangle) (DGA_Display, DGA_Screen, x, y, w, h, color);
May 28, 2006
May 28, 2006
887
if (!(this->screen->flags & SDL_DOUBLEBUF)) {
May 29, 2006
May 29, 2006
888
XFlush(DGA_Display);
May 28, 2006
May 28, 2006
889
}
May 29, 2006
May 29, 2006
890
891
DGA_AddBusySurface(dst);
UNLOCK_DISPLAY();
May 28, 2006
May 28, 2006
892
return (0);
Apr 26, 2001
Apr 26, 2001
893
894
}
May 28, 2006
May 28, 2006
895
static int
May 29, 2006
May 29, 2006
896
897
HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect)
Apr 26, 2001
Apr 26, 2001
898
{
May 28, 2006
May 28, 2006
899
900
901
902
903
904
905
SDL_VideoDevice *this;
int srcx, srcy;
int dstx, dsty;
unsigned int w, h;
this = current_video;
/* Don't blit to the visible part of the screen, wait until flipped */
May 29, 2006
May 29, 2006
906
LOCK_DISPLAY();
May 28, 2006
May 28, 2006
907
if (was_flipped && (dst == this->screen)) {
May 29, 2006
May 29, 2006
908
while (SDL_NAME(XDGAGetViewportStatus) (DGA_Display, DGA_Screen))
May 28, 2006
May 28, 2006
909
910
911
/* Keep waiting for the hardware ... */ ;
was_flipped = 0;
}
May 29, 2006
May 29, 2006
912
DGA_dst_to_xy(this, src, &srcx, &srcy);
May 28, 2006
May 28, 2006
913
914
srcx += srcrect->x;
srcy += srcrect->y;
May 29, 2006
May 29, 2006
915
DGA_dst_to_xy(this, dst, &dstx, &dsty);
May 28, 2006
May 28, 2006
916
917
918
919
dstx += dstrect->x;
dsty += dstrect->y;
w = srcrect->w;
h = srcrect->h;
Apr 26, 2001
Apr 26, 2001
920
#if 0
May 29, 2006
May 29, 2006
921
922
printf("Blitting %dx%d from %d,%d to %d,%d\n", w, h, srcx, srcy, dstx,
dsty);
Apr 26, 2001
Apr 26, 2001
923
#endif
May 28, 2006
May 28, 2006
924
if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
May 29, 2006
May 29, 2006
925
926
927
SDL_NAME(XDGACopyTransparentArea) (DGA_Display, DGA_Screen,
srcx, srcy, w, h, dstx, dsty,
src->format->colorkey);
May 28, 2006
May 28, 2006
928
} else {
May 29, 2006
May 29, 2006
929
930
SDL_NAME(XDGACopyArea) (DGA_Display, DGA_Screen,
srcx, srcy, w, h, dstx, dsty);
May 28, 2006
May 28, 2006
931
932
}
if (!(this->screen->flags & SDL_DOUBLEBUF)) {
May 29, 2006
May 29, 2006
933
XFlush(DGA_Display);
May 28, 2006
May 28, 2006
934
}
May 29, 2006
May 29, 2006
935
936
937
DGA_AddBusySurface(src);
DGA_AddBusySurface(dst);
UNLOCK_DISPLAY();
May 28, 2006
May 28, 2006
938
return (0);
Apr 26, 2001
Apr 26, 2001
939
940
}
May 28, 2006
May 28, 2006
941
static int
May 29, 2006
May 29, 2006
942
DGA_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst)
Apr 26, 2001
Apr 26, 2001
943
{
May 28, 2006
May 28, 2006
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
int accelerated;
/* Set initial acceleration on */
src->flags |= SDL_HWACCEL;
/* Set the surface attributes */
if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
if (!this->info.blit_hw_A) {
src->flags &= ~SDL_HWACCEL;
}
}
if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
if (!this->info.blit_hw_CC) {
src->flags &= ~SDL_HWACCEL;
}
}
/* Check to see if final surface blit is accelerated */
accelerated = !!(src->flags & SDL_HWACCEL);
if (accelerated) {
src->map->hw_blit = HWAccelBlit;
}
return (accelerated);
Apr 26, 2001
Apr 26, 2001
967
968
}
May 28, 2006
May 28, 2006
969
static __inline__ void
May 29, 2006
May 29, 2006
970
DGA_WaitFlip(_THIS)
Apr 26, 2001
Apr 26, 2001
971
{
May 28, 2006
May 28, 2006
972
if (was_flipped) {
May 29, 2006
May 29, 2006
973
while (SDL_NAME(XDGAGetViewportStatus) (DGA_Display, DGA_Screen))
May 28, 2006
May 28, 2006
974
975
976
/* Keep waiting for the hardware ... */ ;
was_flipped = 0;
}
Apr 26, 2001
Apr 26, 2001
977
978
}
May 28, 2006
May 28, 2006
979
static int
May 29, 2006
May 29, 2006
980
DGA_LockHWSurface(_THIS, SDL_Surface * surface)
Apr 26, 2001
Apr 26, 2001
981
{
May 28, 2006
May 28, 2006
982
if (surface == this->screen) {
May 29, 2006
May 29, 2006
983
984
985
986
SDL_mutexP(hw_lock);
LOCK_DISPLAY();
if (DGA_IsSurfaceBusy(surface)) {
DGA_WaitBusySurfaces(this);
May 28, 2006
May 28, 2006
987
}
May 29, 2006
May 29, 2006
988
989
DGA_WaitFlip(this);
UNLOCK_DISPLAY();
May 28, 2006
May 28, 2006
990
} else {
May 29, 2006
May 29, 2006
991
992
993
994
if (DGA_IsSurfaceBusy(surface)) {
LOCK_DISPLAY();
DGA_WaitBusySurfaces(this);
UNLOCK_DISPLAY();
May 28, 2006
May 28, 2006
995
996
997
}
}
return (0);
Apr 26, 2001
Apr 26, 2001
998
}
May 28, 2006
May 28, 2006
999
static void
May 29, 2006
May 29, 2006
1000
DGA_UnlockHWSurface(_THIS, SDL_Surface * surface)