1 diff -r 5002d6aeb85c src/video/x11/SDL_x11sym.h
2 --- a/src/video/x11/SDL_x11sym.h Fri Jul 09 17:19:18 2010 +0200
3 +++ b/src/video/x11/SDL_x11sym.h Sun Aug 15 11:19:34 2010 -0600
5 SDL_X11_SYM(XRRScreenSize *,XRRConfigSizes,(XRRScreenConfiguration *config, int *nsizes),(config,nsizes),return)
6 SDL_X11_SYM(Status,XRRSetScreenConfig,(Display *dpy, XRRScreenConfiguration *config, Drawable draw, int size_index, Rotation rotation, Time timestamp),(dpy,config,draw,size_index,rotation,timestamp),return)
7 SDL_X11_SYM(void,XRRFreeScreenConfigInfo,(XRRScreenConfiguration *config),(config),)
8 +SDL_X11_SYM(XRRScreenResources *,XRRGetScreenResources,(Display *dpy, Window window),(dpy,window),return)
9 +SDL_X11_SYM(XRRScreenResources *,XRRGetScreenResourcesCurrent,(Display *dpy, Window window),(dpy,window),return)
10 +SDL_X11_SYM(void,XRRFreeScreenResources,(XRRScreenResources *resources),(resources),)
11 +SDL_X11_SYM(int,XRRGetCrtcGammaSize,(Display *dpy, RRCrtc crtc),(dpy,crtc),return)
12 +SDL_X11_SYM(XRRCrtcGamma *,XRRAllocGamma,(int size),(size),return)
13 +SDL_X11_SYM(void,XRRFreeGamma,(XRRCrtcGamma *gamma),(gamma),)
14 +SDL_X11_SYM(XRRCrtcGamma *,XRRGetCrtcGamma,(Display *dpy, RRCrtc crtc),(dpy,crtc),return)
15 +SDL_X11_SYM(void,XRRSetCrtcGamma,(Display *dpy, RRCrtc crtc, XRRCrtcGamma *gamma),(dpy,crtc,gamma),)
18 /* end of SDL_x11sym.h ... */
19 diff -r 5002d6aeb85c src/video/x11/SDL_x11video.c
20 --- a/src/video/x11/SDL_x11video.c Fri Jul 09 17:19:18 2010 +0200
21 +++ b/src/video/x11/SDL_x11video.c Sun Aug 15 11:19:34 2010 -0600
23 static void X11_UpdateMouse(_THIS);
24 static int X11_SetColors(_THIS, int firstcolor, int ncolors,
26 +static void X11_FreeSavedGammaRamp(_THIS);
27 +static int X11_RestoreGammaRamp(_THIS);
28 +static int X11_SaveGammaRamp(_THIS);
29 static int X11_SetGammaRamp(_THIS, Uint16 *ramp);
30 static void X11_VideoQuit(_THIS);
33 if ( this->hidden->depth == 32 ) {
34 vformat->Amask = (0xFFFFFFFF & ~(vformat->Rmask|vformat->Gmask|vformat->Bmask));
36 + X11_SaveGammaRamp(this);
37 X11_SaveVidModeGamma(this);
39 /* Allow environment override of screensaver disable. */
40 @@ -1432,10 +1436,248 @@
44 +void X11_FreeSavedGammaRamp(_THIS)
48 +#if SDL_VIDEO_DRIVER_X11_XRANDR
49 + if (gamma_ramp_saved_xrr) {
50 + for ( i=0; i<gamma_ramp_saved_xrr_size; ++i ) {
51 + XRRFreeGamma(gamma_ramp_saved_xrr[i]);
53 + SDL_free(gamma_ramp_saved_xrr);
54 + gamma_ramp_saved_xrr = NULL;
58 +#if SDL_VIDEO_DRIVER_X11_VIDMODE
59 + if (gamma_ramp_saved_vm) {
60 + SDL_free(gamma_ramp_saved_vm);
61 + gamma_ramp_saved_vm = NULL;
66 +int X11_SaveGammaRamp(_THIS)
71 + X11_FreeSavedGammaRamp(this);
73 +#if SDL_VIDEO_DRIVER_X11_XRANDR
75 + XRRScreenResources *resrc;
77 + if (use_xrandr >= 103) {
78 + resrc = XRRGetScreenResourcesCurrent(SDL_Display, SDL_Root);
80 + resrc = XRRGetScreenResources(SDL_Display, SDL_Root);
83 + if (resrc != NULL) {
84 + gamma_ramp_saved_xrr_size = resrc->ncrtc;
85 + gamma_ramp_saved_xrr = SDL_malloc(
86 + sizeof(gamma_ramp_saved_xrr[0]) *
87 + gamma_ramp_saved_xrr_size);
90 + for ( i=0; resrc != NULL && i<resrc->ncrtc; ++i ) {
91 + gamma_ramp_saved_xrr[i] = XRRGetCrtcGamma(SDL_Display,
95 + if (resrc != NULL) {
96 + XRRFreeScreenResources(resrc);
100 +#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
102 +#if SDL_VIDEO_DRIVER_X11_VIDMODE
103 + if (use_vidmode >= 200 && gamma_ramp_size == 0) {
104 + succeeded = SDL_NAME(XF86VidModeGetGammaRampSize)(
105 + SDL_Display, SDL_Screen,
109 + gamma_ramp_size = 0;
113 + if (use_vidmode >= 200 && gamma_ramp_size > 0) {
114 + gamma_ramp_saved_vm = SDL_malloc(
115 + sizeof(gamma_ramp_saved_vm[0]) *
116 + 3 * gamma_ramp_size);
118 + succeeded = SDL_NAME(XF86VidModeGetGammaRamp)(
119 + SDL_Display, SDL_Screen,
121 + gamma_ramp_saved_vm + 0*gamma_ramp_size,
122 + gamma_ramp_saved_vm + 1*gamma_ramp_size,
123 + gamma_ramp_saved_vm + 2*gamma_ramp_size);
126 + SDL_free(gamma_ramp_saved_vm);
127 + gamma_ramp_saved_vm = NULL;
132 +#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
137 +int X11_RestoreGammaRamp(_THIS)
142 +#if SDL_VIDEO_DRIVER_X11_XRANDR
143 + if (use_xrandr && gamma_ramp_saved_xrr != NULL) {
144 + XRRScreenResources *resrc;
146 + if (use_xrandr >= 103) {
147 + resrc = XRRGetScreenResourcesCurrent(SDL_Display, SDL_Root);
149 + resrc = XRRGetScreenResources(SDL_Display, SDL_Root);
152 + for ( i=0; resrc != NULL && i<resrc->ncrtc && i<gamma_ramp_saved_xrr_size; ++i ) {
153 + XRRSetCrtcGamma(SDL_Display, resrc->crtcs[i],
154 + gamma_ramp_saved_xrr[i]);
157 + if (resrc != NULL) {
158 + XRRFreeScreenResources(resrc);
162 +#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
164 +#if SDL_VIDEO_DRIVER_X11_VIDMODE
165 + if (use_vidmode >= 200 && gamma_ramp_saved_vm != NULL) {
166 + succeeded = SDL_NAME(XF86VidModeSetGammaRamp)(
167 + SDL_Display, SDL_Screen,
169 + gamma_ramp_saved_vm + 0*gamma_ramp_size,
170 + gamma_ramp_saved_vm + 1*gamma_ramp_size,
171 + gamma_ramp_saved_vm + 2*gamma_ramp_size);
176 +#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
181 int X11_SetGammaRamp(_THIS, Uint16 *ramp)
188 +#if SDL_VIDEO_DRIVER_X11_XRANDR
190 + XRRCrtcGamma *gamma = NULL;
192 + XRRScreenResources *resrc;
194 + if (use_xrandr >= 103) {
195 + resrc = XRRGetScreenResourcesCurrent(SDL_Display, SDL_Root);
197 + resrc = XRRGetScreenResources(SDL_Display, SDL_Root);
200 + /* Implementation Note:
201 + * We try to make few assumptions here, notably:
202 + * - Ramp size can vary between crtcs
203 + * (which can happen when using multiple video cards)
204 + * - Ramp size (by index) can vary between calls
205 + * (which can happen if the window is moved to a new crtc)
207 + for ( i=0; resrc != NULL && i<resrc->ncrtc; ++i ) {
210 + crtcgs = XRRGetCrtcGammaSize(SDL_Display,
212 + if (crtcgs != gammasize) {
213 + /* Size in this CRTC differs from last */
214 + if (gamma != NULL) {
215 + XRRFreeGamma(gamma);
218 + gammasize = crtcgs;
219 + gamma = XRRAllocGamma(gammasize);
221 + for ( j=0; j<gammasize; ++j ) {
223 + ramp[0*256+j*256/gammasize];
225 + ramp[1*256+j*256/gammasize];
227 + ramp[2*256+j*256/gammasize];
231 + XRRSetCrtcGamma(SDL_Display, resrc->crtcs[i], gamma);
234 + if (gamma != NULL) {
235 + XRRFreeGamma(gamma);
238 + if (resrc != NULL) {
239 + XRRFreeScreenResources(resrc);
243 +#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
245 +#if SDL_VIDEO_DRIVER_X11_VIDMODE
246 + if (use_vidmode >= 200 && gamma_ramp_size == 0) {
247 + succeeded = SDL_NAME(XF86VidModeGetGammaRampSize)(
248 + SDL_Display, SDL_Screen,
252 + gamma_ramp_size = 0;
256 + if (use_vidmode >= 200 && gamma_ramp_size > 0) {
259 + if (gamma_ramp_size == 256) {
262 + sizedramp = SDL_stack_alloc(Uint16, 3*gamma_ramp_size);
263 + if (sizedramp == NULL) {
268 + for ( i=0; i<gamma_ramp_size*3; ++i ) {
269 + sizedramp[i] = ramp[i * 256 / gamma_ramp_size];
273 + succeeded = SDL_NAME(XF86VidModeSetGammaRamp)(
274 + SDL_Display, SDL_Screen,
280 + if (gamma_ramp_size != 256) {
281 + SDL_stack_free(sizedramp);
284 + return(succeeded ? 0 : -1);
286 +#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
288 /* See if actually setting the gamma is supported */
289 if ( SDL_Visual->class != DirectColor ) {
290 @@ -1507,7 +1749,9 @@
291 /* Restore gamma settings if they've changed */
292 if ( SDL_GetAppState() & SDL_APPACTIVE ) {
293 X11_SwapVidModeGamma(this);
294 + X11_RestoreGammaRamp(this);
296 + X11_FreeSavedGammaRamp(this);
298 /* Free that blank cursor */
299 if ( SDL_BlankCursor != NULL ) {
300 diff -r 5002d6aeb85c src/video/x11/SDL_x11video.h
301 --- a/src/video/x11/SDL_x11video.h Fri Jul 09 17:19:18 2010 +0200
302 +++ b/src/video/x11/SDL_x11video.h Sun Aug 15 11:19:34 2010 -0600
303 @@ -119,12 +119,16 @@
304 XRRScreenConfiguration* screen_config;
306 Rotation saved_rotation;
307 + XRRCrtcGamma** gamma_ramp_saved_xrr;
308 + int gamma_ramp_saved_xrr_size;
310 #if SDL_VIDEO_DRIVER_X11_VIDMODE
311 SDL_NAME(XF86VidModeModeInfo) saved_mode;
315 + int gamma_ramp_size;
316 + Uint16* gamma_ramp_saved_vm;
318 #if SDL_VIDEO_DRIVER_X11_XME /* XiG XME fullscreen */
319 XiGMiscResolutionInfo saved_res;
321 #define mouse_accel (this->hidden->mouse_accel)
322 #define mouse_relative (this->hidden->mouse_relative)
323 #define SDL_modelist (this->hidden->modelist)
324 +#define gamma_ramp_size (this->hidden->gamma_ramp_size)
325 +#define gamma_ramp_saved_vm (this->hidden->gamma_ramp_saved_vm)
326 +#define gamma_ramp_saved_xrr (this->hidden->gamma_ramp_saved_xrr)
327 +#define gamma_ramp_saved_xrr_size (this->hidden->gamma_ramp_saved_xrr_size)
328 #define xinerama_info (this->hidden->xinerama_info)
329 #define saved_mode (this->hidden->saved_mode)
330 #define saved_view (this->hidden->saved_view)