Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11image.c @ 4396:f5d3f7fa071d SDL-1.2
1.2 pulseaudio: make some function pointers static.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 17 Jan 2010 05:17:59 +0000 |
parents | a1b03ba2fcd0 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
4159 | 3 Copyright (C) 1997-2009 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 */ |
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 |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
24 #include <stdio.h> |
166
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
25 #include <unistd.h> |
0 | 26 |
27 #include "SDL_endian.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
28 #include "../../events/SDL_events_c.h" |
0 | 29 #include "SDL_x11image_c.h" |
30 | |
31 #ifndef NO_SHARED_MEMORY | |
32 | |
33 /* Shared memory error handler routine */ | |
34 static int shm_error; | |
35 static int (*X_handler)(Display *, XErrorEvent *) = NULL; | |
36 static int shm_errhandler(Display *d, XErrorEvent *e) | |
37 { | |
38 if ( e->error_code == BadAccess ) { | |
810
26a0e2d69d39
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
39 shm_error = True; |
0 | 40 return(0); |
41 } else | |
42 return(X_handler(d,e)); | |
43 } | |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
44 |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
45 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
|
46 { |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
47 /* Dynamic X11 may not have SHM entry points on this box. */ |
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
48 if ((use_mitshm) && (!SDL_X11_HAVE_SHM)) |
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
49 use_mitshm = 0; |
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
50 |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
51 if(!use_mitshm) |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
52 return; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
53 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
|
54 IPC_CREAT | 0777); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
55 if ( shminfo.shmid >= 0 ) { |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
56 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
|
57 shminfo.readOnly = False; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
58 if ( shminfo.shmaddr != (char *)-1 ) { |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
59 shm_error = False; |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
60 X_handler = XSetErrorHandler(shm_errhandler); |
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
61 XShmAttach(SDL_Display, &shminfo); |
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
62 XSync(SDL_Display, True); |
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
63 XSetErrorHandler(X_handler); |
810
26a0e2d69d39
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
64 if ( shm_error ) |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
65 shmdt(shminfo.shmaddr); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
66 } else { |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
67 shm_error = True; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
68 } |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
69 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
|
70 } else { |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
71 shm_error = True; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
72 } |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
73 if ( shm_error ) |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
74 use_mitshm = 0; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
75 if ( use_mitshm ) |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
76 screen->pixels = shminfo.shmaddr; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
77 } |
0 | 78 #endif /* ! NO_SHARED_MEMORY */ |
79 | |
80 /* Various screen update functions available */ | |
81 static void X11_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); | |
82 static void X11_MITSHMUpdate(_THIS, int numrects, SDL_Rect *rects); | |
83 | |
84 int X11_SetupImage(_THIS, SDL_Surface *screen) | |
85 { | |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
86 #ifndef NO_SHARED_MEMORY |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
87 try_mitshm(this, screen); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
88 if(use_mitshm) { |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
89 SDL_Ximage = XShmCreateImage(SDL_Display, SDL_Visual, |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
90 this->hidden->depth, ZPixmap, |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
91 shminfo.shmaddr, &shminfo, |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
92 screen->w, screen->h); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
93 if(!SDL_Ximage) { |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
94 XShmDetach(SDL_Display, &shminfo); |
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
95 XSync(SDL_Display, False); |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
96 shmdt(shminfo.shmaddr); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
97 screen->pixels = NULL; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
98 goto error; |
0 | 99 } |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
100 this->UpdateRects = X11_MITSHMUpdate; |
0 | 101 } |
551
b0c5a13a4243
Doh! Compile error if there was no X11 shared image support
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
102 if(!use_mitshm) |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
103 #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
|
104 { |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
105 int bpp; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
106 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
|
107 if ( screen->pixels == NULL ) { |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
108 SDL_OutOfMemory(); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
109 return -1; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
110 } |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
111 bpp = screen->format->BytesPerPixel; |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
112 SDL_Ximage = XCreateImage(SDL_Display, SDL_Visual, |
0 | 113 this->hidden->depth, ZPixmap, 0, |
114 (char *)screen->pixels, | |
115 screen->w, screen->h, | |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
116 32, 0); |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
117 if ( SDL_Ximage == NULL ) |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
118 goto error; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
119 /* 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
|
120 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
|
121 ? MSBFirst : LSBFirst; |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
122 this->UpdateRects = X11_NormalUpdate; |
0 | 123 } |
124 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
|
125 return(0); |
0 | 126 |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
127 error: |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
128 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
|
129 return 1; |
0 | 130 } |
131 | |
132 void X11_DestroyImage(_THIS, SDL_Surface *screen) | |
133 { | |
134 if ( SDL_Ximage ) { | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
135 XDestroyImage(SDL_Ximage); |
0 | 136 #ifndef NO_SHARED_MEMORY |
137 if ( use_mitshm ) { | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
138 XShmDetach(SDL_Display, &shminfo); |
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
139 XSync(SDL_Display, False); |
0 | 140 shmdt(shminfo.shmaddr); |
141 } | |
142 #endif /* ! NO_SHARED_MEMORY */ | |
143 SDL_Ximage = NULL; | |
144 } | |
145 if ( screen ) { | |
146 screen->pixels = NULL; | |
147 } | |
148 } | |
149 | |
166
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
150 /* Determine the number of CPUs in the system */ |
0 | 151 static int num_CPU(void) |
152 { | |
153 static int num_cpus = 0; | |
154 | |
155 if(!num_cpus) { | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
156 #if defined(__LINUX__) |
0 | 157 char line[BUFSIZ]; |
158 FILE *pstat = fopen("/proc/stat", "r"); | |
159 if ( pstat ) { | |
160 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
|
161 if (SDL_memcmp(line, "cpu", 3) == 0 && line[3] != ' ') { |
0 | 162 ++num_cpus; |
163 } | |
164 } | |
165 fclose(pstat); | |
166 } | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
167 #elif defined(__IRIX__) |
605
6399f4e90211
IRIX patches from Andrea Suatoni
Sam Lantinga <slouken@libsdl.org>
parents:
551
diff
changeset
|
168 num_cpus = sysconf(_SC_NPROC_ONLN); |
166
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
169 #elif defined(_SC_NPROCESSORS_ONLN) |
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
170 /* number of processors online (SVR4.0MP compliant machines) */ |
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
171 num_cpus = sysconf(_SC_NPROCESSORS_ONLN); |
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
172 #elif defined(_SC_NPROCESSORS_CONF) |
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
173 /* number of processors configured (SVR4.0MP compliant machines) */ |
39877400bd1e
Fixed Solaris nitpicks (thanks Mattias!)
Sam Lantinga <slouken@libsdl.org>
parents:
161
diff
changeset
|
174 num_cpus = sysconf(_SC_NPROCESSORS_CONF); |
0 | 175 #endif |
176 if ( num_cpus <= 0 ) { | |
177 num_cpus = 1; | |
178 } | |
179 } | |
180 return num_cpus; | |
181 } | |
182 | |
183 int X11_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags) | |
184 { | |
185 int retval; | |
186 | |
187 X11_DestroyImage(this, screen); | |
188 if ( flags & SDL_OPENGL ) { /* No image when using GL */ | |
189 retval = 0; | |
190 } else { | |
191 retval = X11_SetupImage(this, screen); | |
192 /* We support asynchronous blitting on the display */ | |
193 if ( flags & SDL_ASYNCBLIT ) { | |
194 /* This is actually slower on single-CPU systems, | |
195 probably because of CPU contention between the | |
196 X server and the application. | |
197 Note: Is this still true with XFree86 4.0? | |
198 */ | |
199 if ( num_CPU() > 1 ) { | |
200 screen->flags |= SDL_ASYNCBLIT; | |
201 } | |
202 } | |
203 } | |
204 return(retval); | |
205 } | |
206 | |
207 /* We don't actually allow hardware surfaces other than the main one */ | |
208 int X11_AllocHWSurface(_THIS, SDL_Surface *surface) | |
209 { | |
210 return(-1); | |
211 } | |
212 void X11_FreeHWSurface(_THIS, SDL_Surface *surface) | |
213 { | |
214 return; | |
215 } | |
216 | |
217 int X11_LockHWSurface(_THIS, SDL_Surface *surface) | |
218 { | |
219 if ( (surface == SDL_VideoSurface) && blit_queued ) { | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
220 XSync(GFX_Display, False); |
0 | 221 blit_queued = 0; |
222 } | |
223 return(0); | |
224 } | |
225 void X11_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
226 { | |
227 return; | |
228 } | |
229 | |
230 int X11_FlipHWSurface(_THIS, SDL_Surface *surface) | |
231 { | |
232 return(0); | |
233 } | |
234 | |
235 static void X11_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
236 { | |
237 int i; | |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
238 |
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
239 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
|
240 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
|
241 continue; |
0 | 242 } |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
243 XPutImage(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
|
244 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
|
245 rects[i].x, rects[i].y, rects[i].w, rects[i].h); |
0 | 246 } |
247 if ( SDL_VideoSurface->flags & SDL_ASYNCBLIT ) { | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
248 XFlush(GFX_Display); |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
249 blit_queued = 1; |
0 | 250 } else { |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
251 XSync(GFX_Display, False); |
0 | 252 } |
253 } | |
254 | |
255 static void X11_MITSHMUpdate(_THIS, int numrects, SDL_Rect *rects) | |
256 { | |
257 #ifndef NO_SHARED_MEMORY | |
258 int i; | |
259 | |
260 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
|
261 if ( rects[i].w == 0 || rects[i].h == 0 ) { /* Clipped? */ |
0 | 262 continue; |
263 } | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
264 XShmPutImage(GFX_Display, SDL_Window, SDL_GC, SDL_Ximage, |
0 | 265 rects[i].x, rects[i].y, |
266 rects[i].x, rects[i].y, rects[i].w, rects[i].h, | |
267 False); | |
268 } | |
269 if ( SDL_VideoSurface->flags & SDL_ASYNCBLIT ) { | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
270 XFlush(GFX_Display); |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
271 blit_queued = 1; |
0 | 272 } else { |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
273 XSync(GFX_Display, False); |
0 | 274 } |
275 #endif /* ! NO_SHARED_MEMORY */ | |
276 } | |
277 | |
278 /* There's a problem with the automatic refreshing of the display. | |
279 Even though the XVideo code uses the GFX_Display to update the | |
280 video memory, it appears that updating the window asynchronously | |
281 from a different thread will cause "blackouts" of the window. | |
282 This is a sort of a hacked workaround for the problem. | |
283 */ | |
284 static int enable_autorefresh = 1; | |
285 | |
286 void X11_DisableAutoRefresh(_THIS) | |
287 { | |
288 --enable_autorefresh; | |
289 } | |
290 | |
291 void X11_EnableAutoRefresh(_THIS) | |
292 { | |
293 ++enable_autorefresh; | |
294 } | |
295 | |
296 void X11_RefreshDisplay(_THIS) | |
297 { | |
161
eb6b76a95f2d
An expose event is now sent when using XVideo output.
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
298 /* 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
|
299 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
|
300 */ |
0 | 301 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
|
302 SDL_PrivateExpose(); |
0 | 303 return; |
304 } | |
305 #ifndef NO_SHARED_MEMORY | |
306 if ( this->UpdateRects == X11_MITSHMUpdate ) { | |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
307 XShmPutImage(SDL_Display, SDL_Window, SDL_GC, SDL_Ximage, |
0 | 308 0, 0, 0, 0, this->screen->w, this->screen->h, |
309 False); | |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
310 } else |
0 | 311 #endif /* ! NO_SHARED_MEMORY */ |
270
37fa1484f71b
From: "Mattias Engdeg�rd" <f91-men@nada.kth.se>
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
312 { |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
313 XPutImage(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
|
314 0, 0, 0, 0, this->screen->w, this->screen->h); |
0 | 315 } |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
316 XSync(SDL_Display, False); |
0 | 317 } |
1575
3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
318 |