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