]> git.pld-linux.org Git - packages/SDL.git/blame - SDL-new_gamma_ramp_support.patch
- release 7 (rebuild with tslib 1.14)
[packages/SDL.git] / SDL-new_gamma_ramp_support.patch
CommitLineData
478f7d7b
JR
1diff -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
4@@ -189,6 +189,14 @@
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),)
16 #endif
17
18 /* end of SDL_x11sym.h ... */
19diff -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
22@@ -65,6 +65,9 @@
23 static void X11_UpdateMouse(_THIS);
24 static int X11_SetColors(_THIS, int firstcolor, int ncolors,
25 SDL_Color *colors);
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);
31
32@@ -667,6 +670,7 @@
33 if ( this->hidden->depth == 32 ) {
34 vformat->Amask = (0xFFFFFFFF & ~(vformat->Rmask|vformat->Gmask|vformat->Bmask));
35 }
36+ X11_SaveGammaRamp(this);
37 X11_SaveVidModeGamma(this);
38
39 /* Allow environment override of screensaver disable. */
40@@ -1432,10 +1436,248 @@
41 return nrej == 0;
42 }
43
44+void X11_FreeSavedGammaRamp(_THIS)
45+{
46+ int i;
47+
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]);
52+ }
53+ SDL_free(gamma_ramp_saved_xrr);
54+ gamma_ramp_saved_xrr = NULL;
55+ }
56+#endif
57+
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;
62+ }
63+#endif
64+}
65+
66+int X11_SaveGammaRamp(_THIS)
67+{
68+ int i;
69+ Bool succeeded;
70+
71+ X11_FreeSavedGammaRamp(this);
72+
73+#if SDL_VIDEO_DRIVER_X11_XRANDR
74+ if (use_xrandr) {
75+ XRRScreenResources *resrc;
76+
77+ if (use_xrandr >= 103) {
78+ resrc = XRRGetScreenResourcesCurrent(SDL_Display, SDL_Root);
79+ } else {
80+ resrc = XRRGetScreenResources(SDL_Display, SDL_Root);
81+ }
82+
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);
88+ }
89+
90+ for ( i=0; resrc != NULL && i<resrc->ncrtc; ++i ) {
91+ gamma_ramp_saved_xrr[i] = XRRGetCrtcGamma(SDL_Display,
92+ resrc->crtcs[i]);
93+ }
94+
95+ if (resrc != NULL) {
96+ XRRFreeScreenResources(resrc);
97+ return(0);
98+ }
99+ }
100+#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
101+
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,
106+ &gamma_ramp_size);
107+
108+ if (!succeeded) {
109+ gamma_ramp_size = 0;
110+ }
111+ }
112+
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);
117+
118+ succeeded = SDL_NAME(XF86VidModeGetGammaRamp)(
119+ SDL_Display, SDL_Screen,
120+ gamma_ramp_size,
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);
124+
125+ if (!succeeded) {
126+ SDL_free(gamma_ramp_saved_vm);
127+ gamma_ramp_saved_vm = NULL;
128+ } else {
129+ return(0);
130+ }
131+ }
132+#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
133+
134+ return(-1);
135+}
136+
137+int X11_RestoreGammaRamp(_THIS)
138+{
139+ int i;
140+ Bool succeeded;
141+
142+#if SDL_VIDEO_DRIVER_X11_XRANDR
143+ if (use_xrandr && gamma_ramp_saved_xrr != NULL) {
144+ XRRScreenResources *resrc;
145+
146+ if (use_xrandr >= 103) {
147+ resrc = XRRGetScreenResourcesCurrent(SDL_Display, SDL_Root);
148+ } else {
149+ resrc = XRRGetScreenResources(SDL_Display, SDL_Root);
150+ }
151+
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]);
155+ }
156+
157+ if (resrc != NULL) {
158+ XRRFreeScreenResources(resrc);
159+ return(0);
160+ }
161+ }
162+#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
163+
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,
168+ gamma_ramp_size,
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);
172+
173+ if (succeeded)
174+ return(0);
175+ }
176+#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
177+
178+ return(-1);
179+}
180+
181 int X11_SetGammaRamp(_THIS, Uint16 *ramp)
182 {
183- int i, ncolors;
184+ int i, j, ncolors;
185 XColor xcmap[256];
186+ Bool succeeded;
187+
188+#if SDL_VIDEO_DRIVER_X11_XRANDR
189+ if (use_xrandr) {
190+ XRRCrtcGamma *gamma = NULL;
191+ int gammasize = 0;
192+ XRRScreenResources *resrc;
193+
194+ if (use_xrandr >= 103) {
195+ resrc = XRRGetScreenResourcesCurrent(SDL_Display, SDL_Root);
196+ } else {
197+ resrc = XRRGetScreenResources(SDL_Display, SDL_Root);
198+ }
199+
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)
206+ */
207+ for ( i=0; resrc != NULL && i<resrc->ncrtc; ++i ) {
208+ int crtcgs;
209+
210+ crtcgs = XRRGetCrtcGammaSize(SDL_Display,
211+ resrc->crtcs[i]);
212+ if (crtcgs != gammasize) {
213+ /* Size in this CRTC differs from last */
214+ if (gamma != NULL) {
215+ XRRFreeGamma(gamma);
216+ }
217+
218+ gammasize = crtcgs;
219+ gamma = XRRAllocGamma(gammasize);
220+
221+ for ( j=0; j<gammasize; ++j ) {
222+ gamma->red[j] =
223+ ramp[0*256+j*256/gammasize];
224+ gamma->green[j] =
225+ ramp[1*256+j*256/gammasize];
226+ gamma->blue[j] =
227+ ramp[2*256+j*256/gammasize];
228+ }
229+ }
230+
231+ XRRSetCrtcGamma(SDL_Display, resrc->crtcs[i], gamma);
232+ }
233+
234+ if (gamma != NULL) {
235+ XRRFreeGamma(gamma);
236+ }
237+
238+ if (resrc != NULL) {
239+ XRRFreeScreenResources(resrc);
240+ return(0);
241+ }
242+ }
243+#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
244+
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,
249+ &gamma_ramp_size);
250+
251+ if (!succeeded) {
252+ gamma_ramp_size = 0;
253+ }
254+ }
255+
256+ if (use_vidmode >= 200 && gamma_ramp_size > 0) {
257+ Uint16 *sizedramp;
258+
259+ if (gamma_ramp_size == 256) {
260+ sizedramp = ramp;
261+ } else {
262+ sizedramp = SDL_stack_alloc(Uint16, 3*gamma_ramp_size);
263+ if (sizedramp == NULL) {
264+ SDL_OutOfMemory();
265+ return(-1);
266+ }
267+
268+ for ( i=0; i<gamma_ramp_size*3; ++i ) {
269+ sizedramp[i] = ramp[i * 256 / gamma_ramp_size];
270+ }
271+ }
272+
273+ succeeded = SDL_NAME(XF86VidModeSetGammaRamp)(
274+ SDL_Display, SDL_Screen,
275+ gamma_ramp_size,
276+ sizedramp+0*256,
277+ sizedramp+1*256,
278+ sizedramp+2*256);
279+
280+ if (gamma_ramp_size != 256) {
281+ SDL_stack_free(sizedramp);
282+ }
283+
284+ return(succeeded ? 0 : -1);
285+ }
286+#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
287
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);
295 }
296+ X11_FreeSavedGammaRamp(this);
297
298 /* Free that blank cursor */
299 if ( SDL_BlankCursor != NULL ) {
300diff -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;
305 int saved_size_id;
306 Rotation saved_rotation;
307+ XRRCrtcGamma** gamma_ramp_saved_xrr;
308+ int gamma_ramp_saved_xrr_size;
309 #endif
310 #if SDL_VIDEO_DRIVER_X11_VIDMODE
311 SDL_NAME(XF86VidModeModeInfo) saved_mode;
312 struct {
313 int x, y;
314 } saved_view;
315+ int gamma_ramp_size;
316+ Uint16* gamma_ramp_saved_vm;
317 #endif
318 #if SDL_VIDEO_DRIVER_X11_XME /* XiG XME fullscreen */
319 XiGMiscResolutionInfo saved_res;
320@@ -182,6 +186,10 @@
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)
This page took 0.086835 seconds and 4 git commands to generate.