Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11gamma.c @ 968:4675910b0b7b
Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST)
From: Hannu Savolainen
Subject: Re: SDL uses obsolete OSS features
I did some work on getting OSS to work better with SDL. There have been
some problems with select which should be fixed now.
I'm having some problems in understanding what is the purpose of the
DSP_WaitAudio() routine. I added a return to the very beginning of this
routine and commendted out the define for USE_BLOCKING_WRITES. At least
lbreakout2 seems to work as well as earlier. The latencies are the same.
An ordinary blocking write does exactly the same thing than DSP_WaitAudio
does. So I would recommend using the USE_BLOCKING_WRITES approach and
removing everything from the DSP_WaitAudio routine. Also enabling
USE_BLOCKING_WRITES makes it possible to simplify DSP_PlayAudio() because
you don't need to handle the partial writes (the do-while loop).
Attached is a patch against SDL-1.2.7. After these changes SDL will use
OSS as it's designed to be used (make it as simple as possible). This code
should work with all OSS implementations because it uses only the very
fundamental features that have been there since the jurassic times.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 12 Nov 2004 21:39:04 +0000 |
parents | b8d311d90021 |
children | 045f186426e1 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
445
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
232
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include "SDL.h" | |
29 #include "SDL_events.h" | |
30 #include "SDL_events_c.h" | |
31 #include "SDL_x11video.h" | |
32 | |
33 /* From the X server sources... */ | |
34 #define MAX_GAMMA 10.0 | |
35 #define MIN_GAMMA (1.0/MAX_GAMMA) | |
36 | |
37 static int X11_SetGammaNoLock(_THIS, float red, float green, float blue) | |
38 { | |
39 #ifdef XFREE86_VMGAMMA | |
100
a1c973c35fef
Fixed using the video mode extension on older servers
Sam Lantinga <slouken@lokigames.com>
parents:
90
diff
changeset
|
40 if (use_vidmode >= 200) { |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
41 SDL_NAME(XF86VidModeGamma) gamma; |
0 | 42 Bool succeeded; |
43 | |
44 /* Clamp the gamma values */ | |
45 if ( red < MIN_GAMMA ) { | |
46 gamma.red = MIN_GAMMA; | |
47 } else | |
48 if ( red > MAX_GAMMA ) { | |
49 gamma.red = MAX_GAMMA; | |
50 } else { | |
51 gamma.red = red; | |
52 } | |
53 if ( green < MIN_GAMMA ) { | |
54 gamma.green = MIN_GAMMA; | |
55 } else | |
56 if ( green > MAX_GAMMA ) { | |
57 gamma.green = MAX_GAMMA; | |
58 } else { | |
59 gamma.green = green; | |
60 } | |
61 if ( blue < MIN_GAMMA ) { | |
62 gamma.blue = MIN_GAMMA; | |
63 } else | |
64 if ( blue > MAX_GAMMA ) { | |
65 gamma.blue = MAX_GAMMA; | |
66 } else { | |
67 gamma.blue = blue; | |
68 } | |
69 if ( SDL_GetAppState() & SDL_APPACTIVE ) { | |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
70 succeeded = SDL_NAME(XF86VidModeSetGamma)(SDL_Display, SDL_Screen, &gamma); |
0 | 71 XSync(SDL_Display, False); |
72 } else { | |
73 gamma_saved[0] = gamma.red; | |
74 gamma_saved[1] = gamma.green; | |
75 gamma_saved[2] = gamma.blue; | |
76 succeeded = True; | |
77 } | |
78 if ( succeeded ) { | |
79 ++gamma_changed; | |
80 } | |
81 return succeeded ? 0 : -1; | |
82 } | |
83 #endif | |
84 SDL_SetError("Gamma correction not supported"); | |
85 return -1; | |
86 } | |
87 int X11_SetVidModeGamma(_THIS, float red, float green, float blue) | |
88 { | |
89 int result; | |
90 | |
91 SDL_Lock_EventThread(); | |
92 result = X11_SetGammaNoLock(this, red, green, blue); | |
93 SDL_Unlock_EventThread(); | |
94 | |
95 return(result); | |
96 } | |
97 | |
98 static int X11_GetGammaNoLock(_THIS, float *red, float *green, float *blue) | |
99 { | |
100 #ifdef XFREE86_VMGAMMA | |
445
98d778ed4abf
Fixed video crash on older XFree86 servers
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
101 if (use_vidmode >= 200) { |
292
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
102 SDL_NAME(XF86VidModeGamma) gamma; |
eadc0746dfaf
Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
103 if (SDL_NAME(XF86VidModeGetGamma)(SDL_Display, SDL_Screen, &gamma)) { |
0 | 104 *red = gamma.red; |
105 *green = gamma.green; | |
106 *blue = gamma.blue; | |
107 return 0; | |
108 } | |
109 return -1; | |
110 } | |
111 #endif | |
112 return -1; | |
113 } | |
114 int X11_GetVidModeGamma(_THIS, float *red, float *green, float *blue) | |
115 { | |
116 int result; | |
117 | |
118 SDL_Lock_EventThread(); | |
119 result = X11_GetGammaNoLock(this, red, green, blue); | |
120 SDL_Unlock_EventThread(); | |
121 | |
122 return(result); | |
123 } | |
124 | |
125 void X11_SaveVidModeGamma(_THIS) | |
126 { | |
127 /* Try to save the current gamma, otherwise disable gamma control */ | |
128 if ( X11_GetGammaNoLock(this, | |
129 &gamma_saved[0], &gamma_saved[1], &gamma_saved[2]) < 0 ) { | |
130 this->SetGamma = 0; | |
131 this->GetGamma = 0; | |
132 } | |
133 gamma_changed = 0; | |
134 } | |
135 void X11_SwapVidModeGamma(_THIS) | |
136 { | |
137 float new_gamma[3]; | |
138 | |
139 if ( gamma_changed ) { | |
140 new_gamma[0] = gamma_saved[0]; | |
141 new_gamma[1] = gamma_saved[1]; | |
142 new_gamma[2] = gamma_saved[2]; | |
143 X11_GetGammaNoLock(this, &gamma_saved[0], &gamma_saved[1], &gamma_saved[2]); | |
144 X11_SetGammaNoLock(this, new_gamma[0], new_gamma[1], new_gamma[2]); | |
145 } | |
146 } |