Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11framebuffer.c @ 5198:bb45ecd958d8
Renamed files for consistency
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 05 Feb 2011 12:01:11 -0800 |
parents | 073b86030262 |
children | b530ef003506 |
rev | line source |
---|---|
5185
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2009 Sam Lantinga |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 #include "SDL_x11video.h" |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 #include "SDL_x11framebuffer.h" |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 #ifndef NO_SHARED_MEMORY |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 /* Shared memory error handler routine */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 static int shm_error; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 static int (*X_handler)(Display *, XErrorEvent *) = NULL; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 static int shm_errhandler(Display *d, XErrorEvent *e) |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 if ( e->error_code == BadAccess ) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 shm_error = True; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 return(0); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 } else |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 return(X_handler(d,e)); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 static SDL_bool have_mitshm(void) |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 /* Only use shared memory on local X servers */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 if ( (SDL_strncmp(XDisplayName(NULL), ":", 1) == 0) || |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 (SDL_strncmp(XDisplayName(NULL), "unix:", 5) == 0) ) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 return SDL_X11_HAVE_SHM; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 return SDL_FALSE; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 #endif /* !NO_SHARED_MEMORY */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 int |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 void ** pixels, int *pitch) |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 Display *display = data->videodata->display; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 XGCValues gcv; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 XVisualInfo vinfo; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 /* Free the old framebuffer surface */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 X11_DestroyWindowFramebuffer(_this, window); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 /* Create the graphics context for drawing */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 gcv.graphics_exposures = False; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 data->gc = XCreateGC(display, data->xwindow, GCGraphicsExposures, &gcv); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 if (!data->gc) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 SDL_SetError("Couldn't create graphics context"); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 return -1; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 /* Find out the pixel format and depth */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 if (X11_GetVisualInfoFromVisual(display, data->visual, &vinfo) < 0) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 SDL_SetError("Couldn't get window visual information"); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 return -1; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 *format = X11_GetPixelFormatFromVisualInfo(display, &vinfo); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 if (*format == SDL_PIXELFORMAT_UNKNOWN) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 SDL_SetError("Unknown window pixel format"); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 return -1; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 /* Calculate pitch */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 /* Create the actual image */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 #ifndef NO_SHARED_MEMORY |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 if (have_mitshm()) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 XShmSegmentInfo *shminfo = &data->shminfo; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 shminfo->shmid = shmget(IPC_PRIVATE, window->h*(*pitch), IPC_CREAT | 0777); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 if ( shminfo->shmid >= 0 ) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 shminfo->shmaddr = (char *)shmat(shminfo->shmid, 0, 0); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 shminfo->readOnly = False; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 if ( shminfo->shmaddr != (char *)-1 ) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 shm_error = False; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 X_handler = XSetErrorHandler(shm_errhandler); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 XShmAttach(display, shminfo); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 XSync(display, True); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 XSetErrorHandler(X_handler); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 if ( shm_error ) |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 shmdt(shminfo->shmaddr); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 } else { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 shm_error = True; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 shmctl(shminfo->shmid, IPC_RMID, NULL); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 } else { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 shm_error = True; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 if (!shm_error) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 data->ximage = XShmCreateImage(display, data->visual, |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 vinfo.depth, ZPixmap, |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 shminfo->shmaddr, shminfo, |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 window->w, window->h); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 if (!data->ximage) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 XShmDetach(display, shminfo); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 XSync(display, False); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 shmdt(shminfo->shmaddr); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 } else { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 /* Done! */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 data->use_mitshm = SDL_TRUE; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 *pixels = shminfo->shmaddr; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 return 0; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 #endif /* not NO_SHARED_MEMORY */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 *pixels = SDL_malloc(window->h*(*pitch)); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 if (*pixels == NULL) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 SDL_OutOfMemory(); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 return -1; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 data->ximage = XCreateImage(display, data->visual, |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 vinfo.depth, ZPixmap, 0, (char *)(*pixels), |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 window->w, window->h, 32, 0); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 if (!data->ximage) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 SDL_free(*pixels); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 SDL_SetError("Couldn't create XImage"); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 return -1; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 return 0; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 int |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 int numrects, SDL_Rect * rects) |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 Display *display = data->videodata->display; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 int i; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 SDL_Rect *rect; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 #ifndef NO_SHARED_MEMORY |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 if (data->use_mitshm) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 for (i = 0; i < numrects; ++i) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 rect = &rects[i]; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 if (rect->w == 0 || rect->h == 0) { /* Clipped? */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 continue; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 XShmPutImage(display, data->xwindow, data->gc, data->ximage, |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 rect->x, rect->y, |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 rect->x, rect->y, rect->w, rect->h, False); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 else |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 #endif /* !NO_SHARED_MEMORY */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 for (i = 0; i < numrects; ++i) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 rect = &rects[i]; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 if (rect->w == 0 || rect->h == 0) { /* Clipped? */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 continue; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 XPutImage(display, data->xwindow, data->gc, data->ximage, |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 rect->x, rect->y, |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 rect->x, rect->y, rect->w, rect->h); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 XSync(display, False); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 void |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 X11_DestroyWindowFramebuffer(_THIS, SDL_Window * window) |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 Display *display = data->videodata->display; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 if (data->ximage) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 XDestroyImage(data->ximage); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 #ifndef NO_SHARED_MEMORY |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 if (data->use_mitshm) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 XShmDetach(display, &data->shminfo); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 XSync(display, False); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 shmdt(data->shminfo.shmaddr); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 data->use_mitshm = SDL_FALSE; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 #endif /* !NO_SHARED_MEMORY */ |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 data->ximage = NULL; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 if (data->gc) { |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 XFreeGC(display, data->gc); |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 data->gc = NULL; |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 } |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 |
073b86030262
Added the X11 framebuffer implementation. Simple! :)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 /* vi: set ts=4 sw=4 expandtab: */ |