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