Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11image.c @ 1575:3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 22 Mar 2006 05:00:59 +0000 |
parents | d910939febfa |
children | e49147870aac c121d94672cb a1b03ba2fcd0 |
comparison
equal
deleted
inserted
replaced
1574:0fd72308659e | 1575:3ba88cb7eb1b |
---|---|
42 return(X_handler(d,e)); | 42 return(X_handler(d,e)); |
43 } | 43 } |
44 | 44 |
45 static void try_mitshm(_THIS, SDL_Surface *screen) | 45 static void try_mitshm(_THIS, SDL_Surface *screen) |
46 { | 46 { |
47 /* Dynamic X11 may not have SHM entry points on this box. */ | |
48 if ((use_mitshm) && (!SDL_X11_HAVE_SHM)) | |
49 use_mitshm = 0; | |
50 | |
47 if(!use_mitshm) | 51 if(!use_mitshm) |
48 return; | 52 return; |
49 shminfo.shmid = shmget(IPC_PRIVATE, screen->h*screen->pitch, | 53 shminfo.shmid = shmget(IPC_PRIVATE, screen->h*screen->pitch, |
50 IPC_CREAT | 0777); | 54 IPC_CREAT | 0777); |
51 if ( shminfo.shmid >= 0 ) { | 55 if ( shminfo.shmid >= 0 ) { |
52 shminfo.shmaddr = (char *)shmat(shminfo.shmid, 0, 0); | 56 shminfo.shmaddr = (char *)shmat(shminfo.shmid, 0, 0); |
53 shminfo.readOnly = False; | 57 shminfo.readOnly = False; |
54 if ( shminfo.shmaddr != (char *)-1 ) { | 58 if ( shminfo.shmaddr != (char *)-1 ) { |
55 shm_error = False; | 59 shm_error = False; |
56 X_handler = pXSetErrorHandler(shm_errhandler); | 60 X_handler = XSetErrorHandler(shm_errhandler); |
57 pXShmAttach(SDL_Display, &shminfo); | 61 XShmAttach(SDL_Display, &shminfo); |
58 pXSync(SDL_Display, True); | 62 XSync(SDL_Display, True); |
59 pXSetErrorHandler(X_handler); | 63 XSetErrorHandler(X_handler); |
60 if ( shm_error ) | 64 if ( shm_error ) |
61 shmdt(shminfo.shmaddr); | 65 shmdt(shminfo.shmaddr); |
62 } else { | 66 } else { |
63 shm_error = True; | 67 shm_error = True; |
64 } | 68 } |
80 int X11_SetupImage(_THIS, SDL_Surface *screen) | 84 int X11_SetupImage(_THIS, SDL_Surface *screen) |
81 { | 85 { |
82 #ifndef NO_SHARED_MEMORY | 86 #ifndef NO_SHARED_MEMORY |
83 try_mitshm(this, screen); | 87 try_mitshm(this, screen); |
84 if(use_mitshm) { | 88 if(use_mitshm) { |
85 SDL_Ximage = pXShmCreateImage(SDL_Display, SDL_Visual, | 89 SDL_Ximage = XShmCreateImage(SDL_Display, SDL_Visual, |
86 this->hidden->depth, ZPixmap, | 90 this->hidden->depth, ZPixmap, |
87 shminfo.shmaddr, &shminfo, | 91 shminfo.shmaddr, &shminfo, |
88 screen->w, screen->h); | 92 screen->w, screen->h); |
89 if(!SDL_Ximage) { | 93 if(!SDL_Ximage) { |
90 pXShmDetach(SDL_Display, &shminfo); | 94 XShmDetach(SDL_Display, &shminfo); |
91 pXSync(SDL_Display, False); | 95 XSync(SDL_Display, False); |
92 shmdt(shminfo.shmaddr); | 96 shmdt(shminfo.shmaddr); |
93 screen->pixels = NULL; | 97 screen->pixels = NULL; |
94 goto error; | 98 goto error; |
95 } | 99 } |
96 this->UpdateRects = X11_MITSHMUpdate; | 100 this->UpdateRects = X11_MITSHMUpdate; |
103 if ( screen->pixels == NULL ) { | 107 if ( screen->pixels == NULL ) { |
104 SDL_OutOfMemory(); | 108 SDL_OutOfMemory(); |
105 return -1; | 109 return -1; |
106 } | 110 } |
107 bpp = screen->format->BytesPerPixel; | 111 bpp = screen->format->BytesPerPixel; |
108 SDL_Ximage = pXCreateImage(SDL_Display, SDL_Visual, | 112 SDL_Ximage = XCreateImage(SDL_Display, SDL_Visual, |
109 this->hidden->depth, ZPixmap, 0, | 113 this->hidden->depth, ZPixmap, 0, |
110 (char *)screen->pixels, | 114 (char *)screen->pixels, |
111 screen->w, screen->h, | 115 screen->w, screen->h, |
112 32, 0); | 116 32, 0); |
113 if ( SDL_Ximage == NULL ) | 117 if ( SDL_Ximage == NULL ) |
126 } | 130 } |
127 | 131 |
128 void X11_DestroyImage(_THIS, SDL_Surface *screen) | 132 void X11_DestroyImage(_THIS, SDL_Surface *screen) |
129 { | 133 { |
130 if ( SDL_Ximage ) { | 134 if ( SDL_Ximage ) { |
131 pXDestroyImage(SDL_Ximage); | 135 XDestroyImage(SDL_Ximage); |
132 #ifndef NO_SHARED_MEMORY | 136 #ifndef NO_SHARED_MEMORY |
133 if ( use_mitshm ) { | 137 if ( use_mitshm ) { |
134 pXShmDetach(SDL_Display, &shminfo); | 138 XShmDetach(SDL_Display, &shminfo); |
135 pXSync(SDL_Display, False); | 139 XSync(SDL_Display, False); |
136 shmdt(shminfo.shmaddr); | 140 shmdt(shminfo.shmaddr); |
137 } | 141 } |
138 #endif /* ! NO_SHARED_MEMORY */ | 142 #endif /* ! NO_SHARED_MEMORY */ |
139 SDL_Ximage = NULL; | 143 SDL_Ximage = NULL; |
140 } | 144 } |
211 } | 215 } |
212 | 216 |
213 int X11_LockHWSurface(_THIS, SDL_Surface *surface) | 217 int X11_LockHWSurface(_THIS, SDL_Surface *surface) |
214 { | 218 { |
215 if ( (surface == SDL_VideoSurface) && blit_queued ) { | 219 if ( (surface == SDL_VideoSurface) && blit_queued ) { |
216 pXSync(GFX_Display, False); | 220 XSync(GFX_Display, False); |
217 blit_queued = 0; | 221 blit_queued = 0; |
218 } | 222 } |
219 return(0); | 223 return(0); |
220 } | 224 } |
221 void X11_UnlockHWSurface(_THIS, SDL_Surface *surface) | 225 void X11_UnlockHWSurface(_THIS, SDL_Surface *surface) |
234 | 238 |
235 for (i = 0; i < numrects; ++i) { | 239 for (i = 0; i < numrects; ++i) { |
236 if ( rects[i].w == 0 || rects[i].h == 0 ) { /* Clipped? */ | 240 if ( rects[i].w == 0 || rects[i].h == 0 ) { /* Clipped? */ |
237 continue; | 241 continue; |
238 } | 242 } |
239 pXPutImage(GFX_Display, SDL_Window, SDL_GC, SDL_Ximage, | 243 XPutImage(GFX_Display, SDL_Window, SDL_GC, SDL_Ximage, |
240 rects[i].x, rects[i].y, | 244 rects[i].x, rects[i].y, |
241 rects[i].x, rects[i].y, rects[i].w, rects[i].h); | 245 rects[i].x, rects[i].y, rects[i].w, rects[i].h); |
242 } | 246 } |
243 if ( SDL_VideoSurface->flags & SDL_ASYNCBLIT ) { | 247 if ( SDL_VideoSurface->flags & SDL_ASYNCBLIT ) { |
244 pXFlush(GFX_Display); | 248 XFlush(GFX_Display); |
245 blit_queued = 1; | 249 blit_queued = 1; |
246 } else { | 250 } else { |
247 pXSync(GFX_Display, False); | 251 XSync(GFX_Display, False); |
248 } | 252 } |
249 } | 253 } |
250 | 254 |
251 static void X11_MITSHMUpdate(_THIS, int numrects, SDL_Rect *rects) | 255 static void X11_MITSHMUpdate(_THIS, int numrects, SDL_Rect *rects) |
252 { | 256 { |
255 | 259 |
256 for ( i=0; i<numrects; ++i ) { | 260 for ( i=0; i<numrects; ++i ) { |
257 if ( rects[i].w == 0 || rects[i].h == 0 ) { /* Clipped? */ | 261 if ( rects[i].w == 0 || rects[i].h == 0 ) { /* Clipped? */ |
258 continue; | 262 continue; |
259 } | 263 } |
260 pXShmPutImage(GFX_Display, SDL_Window, SDL_GC, SDL_Ximage, | 264 XShmPutImage(GFX_Display, SDL_Window, SDL_GC, SDL_Ximage, |
261 rects[i].x, rects[i].y, | 265 rects[i].x, rects[i].y, |
262 rects[i].x, rects[i].y, rects[i].w, rects[i].h, | 266 rects[i].x, rects[i].y, rects[i].w, rects[i].h, |
263 False); | 267 False); |
264 } | 268 } |
265 if ( SDL_VideoSurface->flags & SDL_ASYNCBLIT ) { | 269 if ( SDL_VideoSurface->flags & SDL_ASYNCBLIT ) { |
266 pXFlush(GFX_Display); | 270 XFlush(GFX_Display); |
267 blit_queued = 1; | 271 blit_queued = 1; |
268 } else { | 272 } else { |
269 pXSync(GFX_Display, False); | 273 XSync(GFX_Display, False); |
270 } | 274 } |
271 #endif /* ! NO_SHARED_MEMORY */ | 275 #endif /* ! NO_SHARED_MEMORY */ |
272 } | 276 } |
273 | 277 |
274 /* There's a problem with the automatic refreshing of the display. | 278 /* There's a problem with the automatic refreshing of the display. |
298 SDL_PrivateExpose(); | 302 SDL_PrivateExpose(); |
299 return; | 303 return; |
300 } | 304 } |
301 #ifndef NO_SHARED_MEMORY | 305 #ifndef NO_SHARED_MEMORY |
302 if ( this->UpdateRects == X11_MITSHMUpdate ) { | 306 if ( this->UpdateRects == X11_MITSHMUpdate ) { |
303 pXShmPutImage(SDL_Display, SDL_Window, SDL_GC, SDL_Ximage, | 307 XShmPutImage(SDL_Display, SDL_Window, SDL_GC, SDL_Ximage, |
304 0, 0, 0, 0, this->screen->w, this->screen->h, | 308 0, 0, 0, 0, this->screen->w, this->screen->h, |
305 False); | 309 False); |
306 } else | 310 } else |
307 #endif /* ! NO_SHARED_MEMORY */ | 311 #endif /* ! NO_SHARED_MEMORY */ |
308 { | 312 { |
309 pXPutImage(SDL_Display, SDL_Window, SDL_GC, SDL_Ximage, | 313 XPutImage(SDL_Display, SDL_Window, SDL_GC, SDL_Ximage, |
310 0, 0, 0, 0, this->screen->w, this->screen->h); | 314 0, 0, 0, 0, this->screen->w, this->screen->h); |
311 } | 315 } |
312 pXSync(SDL_Display, False); | 316 XSync(SDL_Display, False); |
313 } | 317 } |
318 |