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