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