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