Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11image.c @ 1358:c71e05b4dc2e
More header massaging... works great on Windows. ;-)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 10 Feb 2006 06:48:43 +0000 |
parents | 604d73db6802 |
children | 19418e4422cb |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1168
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1168
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1168
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1168
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:
1168
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:
1168
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:
1168
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
166
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
23 #include <stdio.h> |
166
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
24 #include <unistd.h> |
0 | 25 |
26 #include "SDL_endian.h" | |
161
eb6b76a95f2d
An expose event is now sent when using XVideo output.
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
27 #include "SDL_events_c.h" |
0 | 28 #include "SDL_x11image_c.h" |
29 | |
30 #ifndef NO_SHARED_MEMORY | |
31 | |
32 /* Shared memory error handler routine */ | |
33 static int shm_error; | |
34 static int (*X_handler)(Display *, XErrorEvent *) = NULL; | |
35 static int shm_errhandler(Display *d, XErrorEvent *e) | |
36 { | |
37 if ( e->error_code == BadAccess ) { | |
810
26a0e2d69d39
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
38 shm_error = True; |
0 | 39 return(0); |
40 } else | |
41 return(X_handler(d,e)); | |
42 } | |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
43 |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
44 static void try_mitshm(_THIS, SDL_Surface *screen) |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
45 { |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
46 if(!use_mitshm) |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
47 return; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
48 shminfo.shmid = shmget(IPC_PRIVATE, screen->h*screen->pitch, |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
49 IPC_CREAT | 0777); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
50 if ( shminfo.shmid >= 0 ) { |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
51 shminfo.shmaddr = (char *)shmat(shminfo.shmid, 0, 0); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
52 shminfo.readOnly = False; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
53 if ( shminfo.shmaddr != (char *)-1 ) { |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
54 shm_error = False; |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
55 X_handler = pXSetErrorHandler(shm_errhandler); |
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
56 pXShmAttach(SDL_Display, &shminfo); |
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
57 pXSync(SDL_Display, True); |
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
58 pXSetErrorHandler(X_handler); |
810
26a0e2d69d39
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
59 if ( shm_error ) |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
60 shmdt(shminfo.shmaddr); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
61 } else { |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
62 shm_error = True; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
63 } |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
64 shmctl(shminfo.shmid, IPC_RMID, NULL); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
65 } else { |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
66 shm_error = True; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
67 } |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
68 if ( shm_error ) |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
69 use_mitshm = 0; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
70 if ( use_mitshm ) |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
71 screen->pixels = shminfo.shmaddr; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
72 } |
0 | 73 #endif /* ! NO_SHARED_MEMORY */ |
74 | |
75 /* Various screen update functions available */ | |
76 static void X11_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); | |
77 static void X11_MITSHMUpdate(_THIS, int numrects, SDL_Rect *rects); | |
78 | |
79 int X11_SetupImage(_THIS, SDL_Surface *screen) | |
80 { | |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
81 #ifndef NO_SHARED_MEMORY |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
82 try_mitshm(this, screen); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
83 if(use_mitshm) { |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
84 SDL_Ximage = pXShmCreateImage(SDL_Display, SDL_Visual, |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
85 this->hidden->depth, ZPixmap, |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
86 shminfo.shmaddr, &shminfo, |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
87 screen->w, screen->h); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
88 if(!SDL_Ximage) { |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
89 pXShmDetach(SDL_Display, &shminfo); |
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
90 pXSync(SDL_Display, False); |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
91 shmdt(shminfo.shmaddr); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
92 screen->pixels = NULL; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
93 goto error; |
0 | 94 } |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
95 this->UpdateRects = X11_MITSHMUpdate; |
0 | 96 } |
551
b0c5a13a4243
Doh! Compile error if there was no X11 shared image support
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
97 if(!use_mitshm) |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
98 #endif /* not NO_SHARED_MEMORY */ |
551
b0c5a13a4243
Doh! Compile error if there was no X11 shared image support
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
99 { |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
100 int bpp; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
101 screen->pixels = SDL_malloc(screen->h*screen->pitch); |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
102 if ( screen->pixels == NULL ) { |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
103 SDL_OutOfMemory(); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
104 return -1; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
105 } |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
106 bpp = screen->format->BytesPerPixel; |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
107 SDL_Ximage = pXCreateImage(SDL_Display, SDL_Visual, |
0 | 108 this->hidden->depth, ZPixmap, 0, |
109 (char *)screen->pixels, | |
110 screen->w, screen->h, | |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
111 32, 0); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
112 if ( SDL_Ximage == NULL ) |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
113 goto error; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
114 /* XPutImage will convert byte sex automatically */ |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
115 SDL_Ximage->byte_order = (SDL_BYTEORDER == SDL_BIG_ENDIAN) |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
116 ? MSBFirst : LSBFirst; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
117 this->UpdateRects = X11_NormalUpdate; |
0 | 118 } |
119 screen->pitch = SDL_Ximage->bytes_per_line; | |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
120 return(0); |
0 | 121 |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
122 error: |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
123 SDL_SetError("Couldn't create XImage"); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
124 return 1; |
0 | 125 } |
126 | |
127 void X11_DestroyImage(_THIS, SDL_Surface *screen) | |
128 { | |
129 if ( SDL_Ximage ) { | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
130 pXDestroyImage(SDL_Ximage); |
0 | 131 #ifndef NO_SHARED_MEMORY |
132 if ( use_mitshm ) { | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
133 pXShmDetach(SDL_Display, &shminfo); |
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
134 pXSync(SDL_Display, False); |
0 | 135 shmdt(shminfo.shmaddr); |
136 } | |
137 #endif /* ! NO_SHARED_MEMORY */ | |
138 SDL_Ximage = NULL; | |
139 } | |
140 if ( screen ) { | |
141 screen->pixels = NULL; | |
142 } | |
143 } | |
144 | |
166
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
145 /* Determine the number of CPUs in the system */ |
0 | 146 static int num_CPU(void) |
147 { | |
148 static int num_cpus = 0; | |
149 | |
150 if(!num_cpus) { | |
166
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
151 #if defined(__linux) |
0 | 152 char line[BUFSIZ]; |
153 FILE *pstat = fopen("/proc/stat", "r"); | |
154 if ( pstat ) { | |
155 while ( fgets(line, sizeof(line), pstat) ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
156 if (SDL_memcmp(line, "cpu", 3) == 0 && line[3] != ' ') { |
0 | 157 ++num_cpus; |
158 } | |
159 } | |
160 fclose(pstat); | |
161 } | |
605
6399f4e90211
IRIX patches from Andrea Suatoni
Sam Lantinga <slouken@libsdl.org>
parents:
551
diff
changeset
|
162 #elif defined(__sgi) |
6399f4e90211
IRIX patches from Andrea Suatoni
Sam Lantinga <slouken@libsdl.org>
parents:
551
diff
changeset
|
163 num_cpus = sysconf(_SC_NPROC_ONLN); |
166
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
164 #elif defined(_SC_NPROCESSORS_ONLN) |
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
165 /* number of processors online (SVR4.0MP compliant machines) */ |
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
166 num_cpus = sysconf(_SC_NPROCESSORS_ONLN); |
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
167 #elif defined(_SC_NPROCESSORS_CONF) |
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
168 /* number of processors configured (SVR4.0MP compliant machines) */ |
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
169 num_cpus = sysconf(_SC_NPROCESSORS_CONF); |
0 | 170 #endif |
171 if ( num_cpus <= 0 ) { | |
172 num_cpus = 1; | |
173 } | |
174 } | |
175 return num_cpus; | |
176 } | |
177 | |
178 int X11_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags) | |
179 { | |
180 int retval; | |
181 | |
182 X11_DestroyImage(this, screen); | |
183 if ( flags & SDL_OPENGL ) { /* No image when using GL */ | |
184 retval = 0; | |
185 } else { | |
186 retval = X11_SetupImage(this, screen); | |
187 /* We support asynchronous blitting on the display */ | |
188 if ( flags & SDL_ASYNCBLIT ) { | |
189 /* This is actually slower on single-CPU systems, | |
190 probably because of CPU contention between the | |
191 X server and the application. | |
192 Note: Is this still true with XFree86 4.0? | |
193 */ | |
194 if ( num_CPU() > 1 ) { | |
195 screen->flags |= SDL_ASYNCBLIT; | |
196 } | |
197 } | |
198 } | |
199 return(retval); | |
200 } | |
201 | |
202 /* We don't actually allow hardware surfaces other than the main one */ | |
203 int X11_AllocHWSurface(_THIS, SDL_Surface *surface) | |
204 { | |
205 return(-1); | |
206 } | |
207 void X11_FreeHWSurface(_THIS, SDL_Surface *surface) | |
208 { | |
209 return; | |
210 } | |
211 | |
212 int X11_LockHWSurface(_THIS, SDL_Surface *surface) | |
213 { | |
214 if ( (surface == SDL_VideoSurface) && blit_queued ) { | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
215 pXSync(GFX_Display, False); |
0 | 216 blit_queued = 0; |
217 } | |
218 return(0); | |
219 } | |
220 void X11_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
221 { | |
222 return; | |
223 } | |
224 | |
225 int X11_FlipHWSurface(_THIS, SDL_Surface *surface) | |
226 { | |
227 return(0); | |
228 } | |
229 | |
230 static void X11_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
231 { | |
232 int i; | |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
233 |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
234 for (i = 0; i < numrects; ++i) { |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
235 if ( rects[i].w == 0 || rects[i].h == 0 ) { /* Clipped? */ |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
236 continue; |
0 | 237 } |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
238 pXPutImage(GFX_Display, SDL_Window, SDL_GC, SDL_Ximage, |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
239 rects[i].x, rects[i].y, |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
240 rects[i].x, rects[i].y, rects[i].w, rects[i].h); |
0 | 241 } |
242 if ( SDL_VideoSurface->flags & SDL_ASYNCBLIT ) { | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
243 pXFlush(GFX_Display); |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
244 blit_queued = 1; |
0 | 245 } else { |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
246 pXSync(GFX_Display, False); |
0 | 247 } |
248 } | |
249 | |
250 static void X11_MITSHMUpdate(_THIS, int numrects, SDL_Rect *rects) | |
251 { | |
252 #ifndef NO_SHARED_MEMORY | |
253 int i; | |
254 | |
255 for ( i=0; i<numrects; ++i ) { | |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
256 if ( rects[i].w == 0 || rects[i].h == 0 ) { /* Clipped? */ |
0 | 257 continue; |
258 } | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
259 pXShmPutImage(GFX_Display, SDL_Window, SDL_GC, SDL_Ximage, |
0 | 260 rects[i].x, rects[i].y, |
261 rects[i].x, rects[i].y, rects[i].w, rects[i].h, | |
262 False); | |
263 } | |
264 if ( SDL_VideoSurface->flags & SDL_ASYNCBLIT ) { | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
265 pXFlush(GFX_Display); |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
266 blit_queued = 1; |
0 | 267 } else { |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
268 pXSync(GFX_Display, False); |
0 | 269 } |
270 #endif /* ! NO_SHARED_MEMORY */ | |
271 } | |
272 | |
273 /* There's a problem with the automatic refreshing of the display. | |
274 Even though the XVideo code uses the GFX_Display to update the | |
275 video memory, it appears that updating the window asynchronously | |
276 from a different thread will cause "blackouts" of the window. | |
277 This is a sort of a hacked workaround for the problem. | |
278 */ | |
279 static int enable_autorefresh = 1; | |
280 | |
281 void X11_DisableAutoRefresh(_THIS) | |
282 { | |
283 --enable_autorefresh; | |
284 } | |
285 | |
286 void X11_EnableAutoRefresh(_THIS) | |
287 { | |
288 ++enable_autorefresh; | |
289 } | |
290 | |
291 void X11_RefreshDisplay(_THIS) | |
292 { | |
161
eb6b76a95f2d
An expose event is now sent when using XVideo output.
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
293 /* Don't refresh a display that doesn't have an image (like GL) |
eb6b76a95f2d
An expose event is now sent when using XVideo output.
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
294 Instead, post an expose event so the application can refresh. |
eb6b76a95f2d
An expose event is now sent when using XVideo output.
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
295 */ |
0 | 296 if ( ! SDL_Ximage || (enable_autorefresh <= 0) ) { |
161
eb6b76a95f2d
An expose event is now sent when using XVideo output.
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
297 SDL_PrivateExpose(); |
0 | 298 return; |
299 } | |
300 #ifndef NO_SHARED_MEMORY | |
301 if ( this->UpdateRects == X11_MITSHMUpdate ) { | |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
302 pXShmPutImage(SDL_Display, SDL_Window, SDL_GC, SDL_Ximage, |
0 | 303 0, 0, 0, 0, this->screen->w, this->screen->h, |
304 False); | |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
305 } else |
0 | 306 #endif /* ! NO_SHARED_MEMORY */ |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
307 { |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
308 pXPutImage(SDL_Display, SDL_Window, SDL_GC, SDL_Ximage, |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
309 0, 0, 0, 0, this->screen->w, this->screen->h); |
0 | 310 } |
1168
045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
311 pXSync(SDL_Display, False); |
0 | 312 } |