author | yan |
Fri, 08 Aug 2008 03:32:34 -0700 | |
changeset 1188 | 44c63c47def9 |
parent 1178 | 4734cf2a22bf |
parent 715 | f16baef3a20e |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
#include "splashscreen_impl.h" |
|
27 |
#include <X11/Xlib.h> |
|
28 |
#include <X11/Xutil.h> |
|
29 |
#include <X11/extensions/shape.h> |
|
30 |
#include <X11/Xmd.h> |
|
31 |
#include <X11/Xatom.h> |
|
32 |
#include <X11/cursorfont.h> |
|
33 |
#include <sys/types.h> |
|
34 |
#include <pthread.h> |
|
35 |
#include <signal.h> |
|
36 |
#include <unistd.h> |
|
37 |
#include <sys/time.h> |
|
38 |
#include <errno.h> |
|
39 |
#include <iconv.h> |
|
40 |
#include <langinfo.h> |
|
41 |
#include <locale.h> |
|
42 |
#include <fcntl.h> |
|
1178
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
43 |
#include <poll.h> |
2 | 44 |
|
45 |
static Bool shapeSupported; |
|
46 |
static int shapeEventBase, shapeErrorBase; |
|
47 |
||
48 |
void SplashRemoveDecoration(Splash * splash); |
|
49 |
||
50 |
||
51 |
/* Could use npt but decided to cut down on linked code size */ |
|
52 |
char* SplashConvertStringAlloc(const char* in, int* size) { |
|
53 |
const char *codeset; |
|
54 |
const char *codeset_out; |
|
55 |
iconv_t cd; |
|
56 |
size_t rc; |
|
57 |
char *buf = NULL, *out; |
|
58 |
size_t bufSize, inSize, outSize; |
|
59 |
const char* old_locale; |
|
60 |
||
61 |
if (!in) { |
|
62 |
return NULL; |
|
63 |
} |
|
64 |
old_locale = setlocale(LC_ALL, ""); |
|
65 |
||
66 |
codeset = nl_langinfo(CODESET); |
|
67 |
if ( codeset == NULL || codeset[0] == 0 ) { |
|
68 |
goto done; |
|
69 |
} |
|
70 |
/* we don't need BOM in output so we choose native BE or LE encoding here */ |
|
71 |
codeset_out = (platformByteOrder()==BYTE_ORDER_MSBFIRST) ? |
|
72 |
"UCS-2BE" : "UCS-2LE"; |
|
73 |
||
74 |
cd = iconv_open(codeset_out, codeset); |
|
75 |
if (cd == (iconv_t)-1 ) { |
|
76 |
goto done; |
|
77 |
} |
|
78 |
inSize = strlen(in); |
|
79 |
bufSize = inSize*2; // need 2 bytes per char for UCS-2, this is |
|
80 |
// 2 bytes per source byte max |
|
81 |
buf = malloc(bufSize); |
|
82 |
out = buf; outSize = bufSize; |
|
83 |
/* linux iconv wants char** source and solaris wants const char**... |
|
84 |
cast to void* */ |
|
85 |
rc = iconv(cd, (void*)&in, &inSize, &out, &outSize); |
|
86 |
iconv_close(cd); |
|
87 |
||
88 |
if (rc == (size_t)-1) { |
|
89 |
free(buf); |
|
90 |
buf = NULL; |
|
91 |
} else { |
|
92 |
if (size) { |
|
93 |
*size = (bufSize-outSize)/2; /* bytes to wchars */ |
|
94 |
} |
|
95 |
} |
|
96 |
done: |
|
97 |
setlocale(LC_ALL, old_locale); |
|
98 |
return buf; |
|
99 |
} |
|
100 |
||
101 |
void |
|
102 |
SplashInitFrameShape(Splash * splash, int imageIndex) { |
|
103 |
ImageRect maskRect; |
|
104 |
XRectangle *rects; |
|
105 |
SplashImage *frame = splash->frames + imageIndex; |
|
106 |
||
107 |
frame->rects = NULL; |
|
108 |
frame->numRects = 0; |
|
109 |
||
110 |
if (!splash->maskRequired) |
|
111 |
return; |
|
112 |
if (!shapeSupported) |
|
113 |
return; |
|
114 |
initRect(&maskRect, 0, 0, splash->width, splash->height, 1, |
|
115 |
splash->width * splash->imageFormat.depthBytes, |
|
116 |
splash->frames[imageIndex].bitmapBits, &splash->imageFormat); |
|
117 |
rects = |
|
118 |
malloc(sizeof(XRectangle) * (splash->width / 2 + 1) * splash->height); |
|
119 |
||
120 |
frame->numRects = BitmapToYXBandedRectangles(&maskRect, rects); |
|
121 |
frame->rects = malloc(frame->numRects * sizeof(XRectangle)); |
|
122 |
memcpy(frame->rects, rects, frame->numRects * sizeof(XRectangle)); |
|
123 |
free(rects); |
|
124 |
} |
|
125 |
||
126 |
unsigned |
|
127 |
SplashTime(void) { |
|
128 |
struct timeval tv; |
|
129 |
struct timezone tz; |
|
130 |
unsigned long long msec; |
|
131 |
||
132 |
gettimeofday(&tv, &tz); |
|
133 |
msec = (unsigned long long) tv.tv_sec * 1000 + |
|
134 |
(unsigned long long) tv.tv_usec / 1000; |
|
135 |
||
136 |
return (unsigned) msec; |
|
137 |
} |
|
138 |
||
139 |
void |
|
140 |
msec2timeval(unsigned time, struct timeval *tv) { |
|
141 |
tv->tv_sec = time / 1000; |
|
142 |
tv->tv_usec = (time % 1000) * 1000; |
|
143 |
} |
|
144 |
||
145 |
int |
|
146 |
GetNumAvailableColors(Display * display, Screen * screen, unsigned map_entries) { |
|
147 |
unsigned long pmr[1]; |
|
148 |
unsigned long pr[SPLASH_COLOR_MAP_SIZE]; |
|
149 |
unsigned nFailed, nAllocated, done = 0, nPlanes = 0; |
|
150 |
Colormap cmap; |
|
151 |
unsigned numColors = SPLASH_COLOR_MAP_SIZE; // never try allocating more than that |
|
152 |
||
153 |
if (numColors > map_entries) { |
|
154 |
numColors = map_entries; |
|
155 |
} |
|
156 |
cmap = XDefaultColormapOfScreen(screen); |
|
157 |
nAllocated = 0; /* lower bound */ |
|
158 |
nFailed = numColors + 1; /* upper bound */ |
|
159 |
||
160 |
/* Binary search to determine the number of available cells */ |
|
161 |
for (done = 0; !done;) { |
|
162 |
if (XAllocColorCells(display, cmap, 0, pmr, nPlanes, pr, numColors)) { |
|
163 |
nAllocated = numColors; |
|
164 |
XFreeColors(display, cmap, pr, numColors, 0); |
|
165 |
if (nAllocated < (nFailed - 1)) { |
|
166 |
numColors = (nAllocated + nFailed) / 2; |
|
167 |
} else |
|
168 |
done = 1; |
|
169 |
} else { |
|
170 |
nFailed = numColors; |
|
171 |
if (nFailed > (nAllocated + 1)) |
|
172 |
numColors = (nAllocated + nFailed) / 2; |
|
173 |
else |
|
174 |
done = 1; |
|
175 |
} |
|
176 |
} |
|
177 |
return nAllocated; |
|
178 |
} |
|
179 |
||
180 |
Colormap |
|
181 |
AllocColors(Display * display, Screen * screen, int numColors, |
|
182 |
unsigned long *pr) { |
|
183 |
unsigned long pmr[1]; |
|
184 |
Colormap cmap = XDefaultColormapOfScreen(screen); |
|
185 |
||
186 |
XAllocColorCells(display, cmap, 0, pmr, 0, pr, numColors); |
|
187 |
return cmap; |
|
188 |
} |
|
189 |
||
190 |
void |
|
191 |
FreeColors(Display * display, Screen * screen, int numColors, |
|
192 |
unsigned long *pr) { |
|
193 |
Colormap cmap = XDefaultColormapOfScreen(screen); |
|
194 |
||
195 |
XFreeColors(display, cmap, pr, numColors, 0); |
|
196 |
} |
|
197 |
||
198 |
static void SplashCenter(Splash * splash) { |
|
199 |
Atom type, atom, actual_type; |
|
200 |
int status, actual_format; |
|
201 |
unsigned long nitems, bytes_after; |
|
202 |
CARD16 *prop = NULL; |
|
203 |
||
204 |
/* try centering using Xinerama hint |
|
205 |
if there's no hint, use the center of the screen */ |
|
206 |
atom = XInternAtom(splash->display, "XINERAMA_CENTER_HINT", True); |
|
207 |
if (atom != None) { |
|
208 |
status = XGetWindowProperty(splash->display, |
|
209 |
XRootWindowOfScreen(splash->screen), atom, 0, 1, False, XA_INTEGER, |
|
210 |
&actual_type, &actual_format, &nitems, |
|
211 |
&bytes_after, (unsigned char**)(&prop)); |
|
212 |
if (status == Success && actual_type != None && prop != NULL) { |
|
213 |
splash->x = prop[0] - splash->width/2; |
|
214 |
splash->y = prop[1] - splash->height/2; |
|
215 |
XFree(prop); |
|
216 |
return; |
|
217 |
} |
|
218 |
if (prop != NULL) { |
|
219 |
XFree(prop); |
|
220 |
} |
|
221 |
} |
|
222 |
splash->x = (XWidthOfScreen(splash->screen) - splash->width) / 2; |
|
223 |
splash->y = (XHeightOfScreen(splash->screen) - splash->height) / 2; |
|
224 |
} |
|
225 |
||
226 |
static void SplashUpdateSizeHints(Splash * splash) { |
|
227 |
if (splash->window) { |
|
228 |
XSizeHints sizeHints; |
|
229 |
||
230 |
sizeHints.flags = USPosition | PPosition | USSize | PSize | PMinSize | PMaxSize | PWinGravity; |
|
231 |
sizeHints.width = sizeHints.base_width = sizeHints.min_width = sizeHints.max_width = splash->width; |
|
232 |
sizeHints.height = sizeHints.base_height = sizeHints.min_height = sizeHints.max_height = splash->height; |
|
233 |
sizeHints.win_gravity = NorthWestGravity; |
|
234 |
||
235 |
XSetWMNormalHints(splash->display, splash->window, &sizeHints); |
|
236 |
} |
|
237 |
} |
|
238 |
||
239 |
void |
|
240 |
SplashCreateWindow(Splash * splash) { |
|
241 |
XSizeHints sizeHints; |
|
242 |
||
243 |
XSetWindowAttributes attr; |
|
244 |
||
245 |
attr.backing_store = NotUseful; |
|
246 |
attr.colormap = XDefaultColormapOfScreen(splash->screen); |
|
247 |
attr.save_under = True; |
|
248 |
attr.cursor = splash->cursor = XCreateFontCursor(splash->display, XC_watch); |
|
249 |
attr.event_mask = ExposureMask; |
|
250 |
||
251 |
SplashCenter(splash); |
|
252 |
||
253 |
splash->window = XCreateWindow(splash->display, XRootWindowOfScreen(splash->screen), |
|
254 |
splash->x, splash->y, splash->width, splash->height, 0, CopyFromParent, |
|
255 |
InputOutput, CopyFromParent, CWColormap | CWBackingStore | CWSaveUnder | CWCursor | CWEventMask, |
|
256 |
&attr); |
|
257 |
SplashUpdateSizeHints(splash); |
|
258 |
||
259 |
||
260 |
splash->wmHints = XAllocWMHints(); |
|
261 |
if (splash->wmHints) { |
|
262 |
splash->wmHints->flags = InputHint | StateHint; |
|
263 |
splash->wmHints->input = False; |
|
264 |
splash->wmHints->initial_state = NormalState; |
|
265 |
XSetWMHints(splash->display, splash->window, splash->wmHints); |
|
266 |
} |
|
267 |
} |
|
268 |
||
269 |
/* for changing the visible shape of a window to an nonrectangular form */ |
|
270 |
void |
|
271 |
SplashUpdateShape(Splash * splash) { |
|
272 |
if (!shapeSupported) |
|
273 |
return; |
|
274 |
if (!splash->maskRequired) { |
|
275 |
return; |
|
276 |
} |
|
277 |
XShapeCombineRectangles(splash->display, splash->window, ShapeClip, 0, 0, |
|
278 |
splash->frames[splash->currentFrame].rects, |
|
279 |
splash->frames[splash->currentFrame].numRects, ShapeSet, YXBanded); |
|
280 |
XShapeCombineRectangles(splash->display, splash->window, ShapeBounding, |
|
281 |
0, 0, splash->frames[splash->currentFrame].rects, |
|
282 |
splash->frames[splash->currentFrame].numRects, ShapeSet, YXBanded); |
|
283 |
} |
|
284 |
||
285 |
/* for reverting the visible shape of a window to an rectangular form */ |
|
286 |
void |
|
287 |
SplashRevertShape(Splash * splash) { |
|
288 |
if (!shapeSupported) |
|
289 |
return; |
|
290 |
if (splash->maskRequired) |
|
291 |
return; |
|
292 |
||
293 |
XShapeCombineMask (splash->display, splash->window, ShapeClip, |
|
294 |
0, 0, None, ShapeSet); |
|
295 |
XShapeCombineMask (splash->display, splash->window , ShapeBounding, |
|
296 |
0, 0, None, ShapeSet); |
|
297 |
} |
|
298 |
||
299 |
int |
|
300 |
ByteOrderToX(int byteOrder) { |
|
301 |
if (byteOrder == BYTE_ORDER_NATIVE) |
|
302 |
byteOrder = platformByteOrder(); |
|
303 |
switch (byteOrder) { |
|
304 |
case BYTE_ORDER_LSBFIRST: |
|
305 |
return LSBFirst; |
|
306 |
case BYTE_ORDER_MSBFIRST: |
|
307 |
return MSBFirst; |
|
308 |
default: |
|
309 |
return -1; |
|
310 |
} |
|
311 |
} |
|
312 |
||
313 |
void |
|
314 |
SplashRedrawWindow(Splash * splash) { |
|
315 |
XImage *ximage; |
|
316 |
||
317 |
// making this method redraw a part of the image does not make |
|
318 |
// much sense as SplashUpdateScreenData always re-generates |
|
319 |
// the image completely, so whole window is always redrawn |
|
320 |
||
321 |
SplashUpdateScreenData(splash); |
|
322 |
ximage = XCreateImage(splash->display, splash->visual, |
|
323 |
splash->screenFormat.depthBytes * 8, ZPixmap, 0, (char *) NULL, |
|
324 |
splash->width, splash->height, 8, 0); |
|
325 |
ximage->data = (char *) splash->screenData; |
|
326 |
ximage->bits_per_pixel = ximage->depth; |
|
327 |
ximage->bytes_per_line = ximage->depth * ximage->width / 8; |
|
328 |
ximage->byte_order = ByteOrderToX(splash->screenFormat.byteOrder); |
|
329 |
ximage->bitmap_unit = 8; |
|
330 |
XPutImage(splash->display, splash->window, |
|
331 |
XDefaultGCOfScreen(splash->screen), ximage, 0, 0, 0, 0, |
|
332 |
splash->width, splash->height); |
|
333 |
ximage->data = NULL; |
|
334 |
XDestroyImage(ximage); |
|
335 |
SplashRemoveDecoration(splash); |
|
336 |
XMapWindow(splash->display, splash->window); |
|
337 |
} |
|
338 |
||
339 |
void SplashReconfigureNow(Splash * splash) { |
|
340 |
SplashCenter(splash); |
|
341 |
if (splash->window) { |
|
342 |
XUnmapWindow(splash->display, splash->window); |
|
343 |
XMoveResizeWindow(splash->display, splash->window, |
|
344 |
splash->x, splash->y, |
|
345 |
splash->width, splash->height); |
|
346 |
SplashUpdateSizeHints(splash); |
|
347 |
} |
|
348 |
if (splash->maskRequired) { |
|
349 |
SplashUpdateShape(splash); |
|
350 |
} else { |
|
351 |
SplashRevertShape(splash); |
|
352 |
} |
|
353 |
SplashRedrawWindow(splash); |
|
354 |
} |
|
355 |
||
356 |
||
357 |
void |
|
358 |
sendctl(Splash * splash, char code) { |
|
359 |
// if (splash->isVisible>0) { |
|
360 |
if (splash && splash->controlpipe[1]) { |
|
361 |
write(splash->controlpipe[1], &code, 1); |
|
362 |
} |
|
363 |
} |
|
364 |
||
365 |
int |
|
366 |
HandleError(Display * disp, XErrorEvent * err) { |
|
367 |
// silently ignore non-fatal errors |
|
368 |
/* |
|
369 |
char msg[0x1000]; |
|
370 |
char buf[0x1000]; |
|
371 |
XGetErrorText(disp, err->error_code, msg, sizeof(msg)); |
|
372 |
fprintf(stderr, "Xerror %s, XID %x, ser# %d\n", msg, err->resourceid, |
|
373 |
err->serial); |
|
374 |
sprintf(buf, "%d", err->request_code); |
|
375 |
XGetErrorDatabaseText(disp, "XRequest", buf, "Unknown", msg, sizeof(msg)); |
|
376 |
fprintf(stderr, "Major opcode %d (%s)\n", err->request_code, msg); |
|
377 |
if (err->request_code > 128) { |
|
378 |
fprintf(stderr, "Minor opcode %d\n", err->minor_code); |
|
379 |
} |
|
380 |
*/ |
|
381 |
return 0; |
|
382 |
} |
|
383 |
||
384 |
int |
|
385 |
HandleIOError(Display * display) { |
|
386 |
// for really bad errors, we should exit the thread we're on |
|
387 |
SplashCleanup(SplashGetInstance()); |
|
388 |
pthread_exit(NULL); |
|
389 |
return 0; |
|
390 |
} |
|
391 |
||
392 |
void |
|
393 |
SplashInitPlatform(Splash * splash) { |
|
394 |
int shapeVersionMajor, shapeVersionMinor; |
|
395 |
||
396 |
// This setting enables the synchronous Xlib mode! |
|
397 |
// Don't use it == 1 in production builds! |
|
398 |
#if (defined DEBUG) |
|
399 |
_Xdebug = 1; |
|
400 |
#endif |
|
401 |
||
402 |
pthread_mutex_init(&splash->lock, NULL); |
|
403 |
||
404 |
// We should not ignore any errors. |
|
405 |
//XSetErrorHandler(HandleError); |
|
406 |
// XSetIOErrorHandler(HandleIOError); |
|
407 |
XSetIOErrorHandler(NULL); |
|
408 |
splash->display = XOpenDisplay(NULL); |
|
409 |
if (!splash->display) { |
|
410 |
splash->isVisible = -1; |
|
411 |
return; |
|
412 |
} |
|
413 |
||
414 |
shapeSupported = XShapeQueryExtension(splash->display, &shapeEventBase, |
|
415 |
&shapeErrorBase); |
|
416 |
if (shapeSupported) { |
|
417 |
XShapeQueryVersion(splash->display, &shapeVersionMajor, |
|
418 |
&shapeVersionMinor); |
|
419 |
} |
|
420 |
||
421 |
splash->screen = XDefaultScreenOfDisplay(splash->display); |
|
422 |
splash->visual = XDefaultVisualOfScreen(splash->screen); |
|
423 |
switch (splash->visual->class) { |
|
424 |
case TrueColor: { |
|
425 |
int depth = XDefaultDepthOfScreen(splash->screen); |
|
426 |
||
427 |
splash->byteAlignment = 1; |
|
428 |
splash->maskRequired = shapeSupported; |
|
429 |
initFormat(&splash->screenFormat, splash->visual->red_mask, |
|
430 |
splash->visual->green_mask, splash->visual->blue_mask, 0); |
|
431 |
splash->screenFormat.byteOrder = |
|
432 |
(XImageByteOrder(splash->display) == LSBFirst ? |
|
433 |
BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST); |
|
434 |
splash->screenFormat.depthBytes = (depth + 7) / 8; |
|
435 |
// TrueColor depth probably can't be less |
|
436 |
// than 8 bits, and it's always byte padded |
|
437 |
break; |
|
438 |
} |
|
439 |
case PseudoColor: { |
|
422
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
440 |
int availableColors; |
2 | 441 |
int numColors; |
442 |
int numComponents[3]; |
|
443 |
unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE]; |
|
444 |
XColor xColors[SPLASH_COLOR_MAP_SIZE]; |
|
445 |
int i; |
|
446 |
int depth = XDefaultDepthOfScreen(splash->screen); |
|
447 |
int scale = 65535 / MAX_COLOR_VALUE; |
|
448 |
||
422
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
449 |
availableColors = GetNumAvailableColors(splash->display, splash->screen, |
2 | 450 |
splash->visual->map_entries); |
422
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
451 |
numColors = quantizeColors(availableColors, numComponents); |
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
452 |
if (numColors > availableColors) { |
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
453 |
// Could not allocate the color cells. Most probably |
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
454 |
// the pool got exhausted. Disable the splash screen. |
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
455 |
XCloseDisplay(splash->display); |
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
456 |
splash->isVisible = -1; |
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
457 |
splash->display = NULL; |
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
458 |
splash->screen = NULL; |
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
459 |
splash->visual = NULL; |
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
460 |
fprintf(stderr, "Warning: unable to initialize the splashscreen. Not enough available color cells.\n"); |
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
461 |
return; |
5b2da06c1acc
6603312: Segmentation fault running java -jar SwingSet2.jar in 256 color mode
anthony
parents:
2
diff
changeset
|
462 |
} |
2 | 463 |
splash->cmap = AllocColors(splash->display, splash->screen, |
464 |
numColors, colorIndex); |
|
465 |
for (i = 0; i < numColors; i++) { |
|
466 |
splash->colorIndex[i] = colorIndex[i]; |
|
467 |
} |
|
468 |
initColorCube(numComponents, splash->colorMap, splash->dithers, |
|
469 |
splash->colorIndex); |
|
470 |
for (i = 0; i < numColors; i++) { |
|
471 |
xColors[i].pixel = colorIndex[i]; |
|
472 |
xColors[i].red = (unsigned short) |
|
473 |
QUAD_RED(splash->colorMap[colorIndex[i]]) * scale; |
|
474 |
xColors[i].green = (unsigned short) |
|
475 |
QUAD_GREEN(splash->colorMap[colorIndex[i]]) * scale; |
|
476 |
xColors[i].blue = (unsigned short) |
|
477 |
QUAD_BLUE(splash->colorMap[colorIndex[i]]) * scale; |
|
478 |
xColors[i].flags = DoRed | DoGreen | DoBlue; |
|
479 |
} |
|
480 |
XStoreColors(splash->display, splash->cmap, xColors, numColors); |
|
481 |
initFormat(&splash->screenFormat, 0, 0, 0, 0); |
|
482 |
splash->screenFormat.colorIndex = splash->colorIndex; |
|
483 |
splash->screenFormat.depthBytes = (depth + 7) / 8; // or always 8? |
|
484 |
splash->screenFormat.colorMap = splash->colorMap; |
|
485 |
splash->screenFormat.dithers = splash->dithers; |
|
486 |
splash->screenFormat.numColors = numColors; |
|
487 |
splash->screenFormat.byteOrder = BYTE_ORDER_NATIVE; |
|
488 |
break; |
|
489 |
} |
|
490 |
default: |
|
491 |
; /* FIXME: should probably be fixed, but javaws splash screen doesn't support other visuals either */ |
|
492 |
} |
|
493 |
} |
|
494 |
||
495 |
||
496 |
void |
|
497 |
SplashCleanupPlatform(Splash * splash) { |
|
498 |
int i; |
|
499 |
||
500 |
if (splash->frames) { |
|
501 |
for (i = 0; i < splash->frameCount; i++) { |
|
502 |
if (splash->frames[i].rects) { |
|
503 |
free(splash->frames[i].rects); |
|
504 |
splash->frames[i].rects = NULL; |
|
505 |
} |
|
506 |
} |
|
507 |
} |
|
508 |
splash->maskRequired = shapeSupported; |
|
509 |
} |
|
510 |
||
511 |
void |
|
512 |
SplashDonePlatform(Splash * splash) { |
|
513 |
pthread_mutex_destroy(&splash->lock); |
|
514 |
if (splash->cmap) { |
|
515 |
unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE]; |
|
516 |
int i; |
|
517 |
||
518 |
for (i = 0; i < splash->screenFormat.numColors; i++) { |
|
519 |
colorIndex[i] = splash->colorIndex[i]; |
|
520 |
} |
|
521 |
FreeColors(splash->display, splash->screen, |
|
522 |
splash->screenFormat.numColors, colorIndex); |
|
523 |
} |
|
524 |
if (splash->window) |
|
525 |
XDestroyWindow(splash->display, splash->window); |
|
526 |
if (splash->wmHints) |
|
527 |
XFree(splash->wmHints); |
|
528 |
if (splash->cursor) |
|
529 |
XFreeCursor(splash->display, splash->cursor); |
|
530 |
if (splash->display) |
|
531 |
XCloseDisplay(splash->display); |
|
532 |
} |
|
533 |
||
534 |
void |
|
535 |
SplashEventLoop(Splash * splash) { |
|
536 |
||
537 |
/* Different from win32 implementation - this loop |
|
1178
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
538 |
uses poll timeouts instead of a timer */ |
2 | 539 |
/* we should have splash _locked_ on entry!!! */ |
540 |
||
541 |
int xconn = XConnectionNumber(splash->display); |
|
542 |
||
543 |
while (1) { |
|
1178
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
544 |
struct pollfd pfd[2]; |
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
545 |
int timeout = -1; |
2 | 546 |
int ctl = splash->controlpipe[0]; |
547 |
int rc; |
|
548 |
int pipes_empty; |
|
549 |
||
1178
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
550 |
pfd[0].fd = xconn; |
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
551 |
pfd[0].events = POLLIN | POLLPRI; |
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
552 |
|
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
553 |
pfd[1].fd = ctl; |
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
554 |
pfd[1].events = POLLIN | POLLPRI; |
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
555 |
|
2 | 556 |
errno = 0; |
557 |
if (splash->isVisible>0 && SplashIsStillLooping(splash)) { |
|
1178
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
558 |
timeout = splash->time + splash->frames[splash->currentFrame].delay |
2 | 559 |
- SplashTime(); |
1178
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
560 |
if (timeout < 0) { |
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
561 |
timeout = 0; |
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
562 |
} |
2 | 563 |
} |
564 |
SplashUnlock(splash); |
|
1178
4734cf2a22bf
6704896: FD_SET usage can cause stack corruption (sol)
anthony
parents:
422
diff
changeset
|
565 |
rc = poll(pfd, 2, timeout); |
2 | 566 |
SplashLock(splash); |
567 |
if (splash->isVisible>0 && SplashTime() >= splash->time + |
|
568 |
splash->frames[splash->currentFrame].delay) { |
|
569 |
SplashNextFrame(splash); |
|
570 |
SplashUpdateShape(splash); |
|
571 |
SplashRedrawWindow(splash); |
|
572 |
} |
|
573 |
if (rc <= 0) { |
|
574 |
errno = 0; |
|
575 |
continue; |
|
576 |
} |
|
577 |
pipes_empty = 0; |
|
578 |
while(!pipes_empty) { |
|
579 |
char buf; |
|
580 |
||
581 |
pipes_empty = 1; |
|
582 |
if (read(ctl, &buf, sizeof(buf)) > 0) { |
|
583 |
pipes_empty = 0; |
|
584 |
switch (buf) { |
|
585 |
case SPLASHCTL_UPDATE: |
|
586 |
if (splash->isVisible>0) { |
|
587 |
SplashRedrawWindow(splash); |
|
588 |
} |
|
589 |
break; |
|
590 |
case SPLASHCTL_RECONFIGURE: |
|
591 |
if (splash->isVisible>0) { |
|
592 |
SplashReconfigureNow(splash); |
|
593 |
} |
|
594 |
break; |
|
595 |
case SPLASHCTL_QUIT: |
|
596 |
return; |
|
597 |
} |
|
598 |
} |
|
599 |
// we're not using "while(XPending)", processing one event |
|
600 |
// at a time to avoid control pipe starvation |
|
601 |
if (XPending(splash->display)) { |
|
602 |
XEvent evt; |
|
603 |
||
604 |
pipes_empty = 0; |
|
605 |
XNextEvent(splash->display, &evt); |
|
606 |
switch (evt.type) { |
|
607 |
case Expose: |
|
608 |
if (splash->isVisible>0) { |
|
609 |
// we're doing full redraw so we just |
|
610 |
// skip the remaining painting events in the queue |
|
611 |
while(XCheckTypedEvent(splash->display, Expose, |
|
612 |
&evt)); |
|
613 |
SplashRedrawWindow(splash); |
|
614 |
} |
|
615 |
break; |
|
616 |
/* ... */ |
|
617 |
} |
|
618 |
} |
|
619 |
} |
|
620 |
} |
|
621 |
} |
|
622 |
||
623 |
/* we can't use OverrideRedirect for the window as the window should not be |
|
624 |
always-on-top, so we must set appropriate wm hints |
|
625 |
||
626 |
this functions sets olwm, mwm and EWMH hints for undecorated window at once |
|
627 |
||
628 |
It works for: mwm, openbox, wmaker, metacity, KWin (FIXME: test more wm's) |
|
629 |
Should work for: fvwm2.5.x, blackbox, olwm |
|
630 |
Maybe works for: enlightenment, icewm |
|
631 |
Does not work for: twm, fvwm2.4.7 |
|
632 |
||
633 |
*/ |
|
634 |
||
635 |
void |
|
636 |
SplashRemoveDecoration(Splash * splash) { |
|
637 |
Atom atom_set; |
|
638 |
Atom atom_list[4]; |
|
639 |
||
640 |
/* the struct below was copied from MwmUtil.h */ |
|
641 |
||
642 |
struct PROPMOTIFWMHINTS { |
|
643 |
/* 32-bit property items are stored as long on the client (whether |
|
644 |
* that means 32 bits or 64). XChangeProperty handles the conversion |
|
645 |
* to the actual 32-bit quantities sent to the server. |
|
646 |
*/ |
|
647 |
unsigned long flags; |
|
648 |
unsigned long functions; |
|
649 |
unsigned long decorations; |
|
650 |
long inputMode; |
|
651 |
unsigned long status; |
|
652 |
} |
|
653 |
mwm_hints; |
|
654 |
||
655 |
/* WM_TAKE_FOCUS hint to avoid wm's transfer of focus to this window */ |
|
656 |
/* WM_DELETE_WINDOW hint to avoid closing this window with Alt-F4. See bug 6474035 */ |
|
657 |
atom_set = XInternAtom(splash->display, "WM_PROTOCOLS", True); |
|
658 |
if (atom_set != None) { |
|
659 |
atom_list[0] = XInternAtom(splash->display, "WM_TAKE_FOCUS", True); |
|
660 |
atom_list[1] = XInternAtom(splash->display, "WM_DELETE_WINDOW", True); |
|
661 |
||
662 |
XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32, |
|
663 |
PropModeReplace, (unsigned char *) atom_list, 2); |
|
664 |
} |
|
665 |
||
666 |
/* mwm hints */ |
|
667 |
atom_set = XInternAtom(splash->display, "_MOTIF_WM_HINTS", True); |
|
668 |
if (atom_set != None) { |
|
669 |
/* flags for decoration and functions */ |
|
670 |
mwm_hints.flags = (1L << 1) | (1L << 0); |
|
671 |
mwm_hints.decorations = 0; |
|
672 |
mwm_hints.functions = 0; |
|
673 |
XChangeProperty(splash->display, splash->window, atom_set, atom_set, |
|
674 |
32, PropModeReplace, (unsigned char *) &mwm_hints, 5); |
|
675 |
} |
|
676 |
||
677 |
/* olwm hints */ |
|
678 |
atom_set = XInternAtom(splash->display, "_OL_DECOR_DEL", True); |
|
679 |
if (atom_set != None) { |
|
680 |
atom_list[0] = XInternAtom(splash->display, "_OL_DECOR_RESIZE", True); |
|
681 |
atom_list[1] = XInternAtom(splash->display, "_OL_DECOR_HEADER", True); |
|
682 |
atom_list[2] = XInternAtom(splash->display, "_OL_DECOR_PIN", True); |
|
683 |
atom_list[3] = XInternAtom(splash->display, "_OL_DECOR_CLOSE", True); |
|
684 |
XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32, |
|
685 |
PropModeReplace, (unsigned char *) atom_list, 4); |
|
686 |
} |
|
687 |
||
688 |
/* generic EMWH hints |
|
689 |
we do not set _NET_WM_WINDOW_TYPE to _NET_WM_WINDOW_TYPE_SPLASH |
|
690 |
hint support due to gnome making this window always-on-top |
|
691 |
so we have to set _NET_WM_STATE and _NET_WM_ALLOWED_ACTIONS correctly |
|
692 |
_NET_WM_STATE: SKIP_TASKBAR and SKIP_PAGER |
|
693 |
_NET_WM_ALLOWED_ACTIONS: disable all actions */ |
|
694 |
atom_set = XInternAtom(splash->display, "_NET_WM_STATE", True); |
|
695 |
if (atom_set != None) { |
|
696 |
atom_list[0] = XInternAtom(splash->display, |
|
697 |
"_NET_WM_STATE_SKIP_TASKBAR", True); |
|
698 |
atom_list[1] = XInternAtom(splash->display, |
|
699 |
"_NET_WM_STATE_SKIP_PAGER", True); |
|
700 |
XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32, |
|
701 |
PropModeReplace, (unsigned char *) atom_list, 2); |
|
702 |
} |
|
703 |
atom_set = XInternAtom(splash->display, "_NET_WM_ALLOWED_ACTIONS", True); |
|
704 |
if (atom_set != None) { |
|
705 |
XChangeProperty(splash->display, splash->window, atom_set, XA_ATOM, 32, |
|
706 |
PropModeReplace, (unsigned char *) atom_list, 0); |
|
707 |
} |
|
708 |
} |
|
709 |
||
710 |
void |
|
711 |
SplashPThreadDestructor(void *arg) { |
|
712 |
/* this will be used in case of emergency thread exit on xlib error */ |
|
713 |
Splash *splash = (Splash *) arg; |
|
714 |
||
715 |
if (splash) { |
|
716 |
SplashCleanup(splash); |
|
717 |
} |
|
718 |
} |
|
719 |
||
720 |
void * |
|
721 |
SplashScreenThread(void *param) { |
|
722 |
Splash *splash = (Splash *) param; |
|
723 |
// pthread_key_t key; |
|
724 |
||
725 |
// pthread_key_create(&key, SplashPThreadDestructor); |
|
726 |
// pthread_setspecific(key, splash); |
|
727 |
||
728 |
SplashLock(splash); |
|
729 |
pipe(splash->controlpipe); |
|
730 |
fcntl(splash->controlpipe[0], F_SETFL, |
|
731 |
fcntl(splash->controlpipe[0], F_GETFL, 0) | O_NONBLOCK); |
|
732 |
splash->time = SplashTime(); |
|
733 |
SplashCreateWindow(splash); |
|
734 |
fflush(stdout); |
|
735 |
if (splash->window) { |
|
736 |
SplashRemoveDecoration(splash); |
|
737 |
XStoreName(splash->display, splash->window, "Java"); |
|
738 |
XMapRaised(splash->display, splash->window); |
|
739 |
SplashUpdateShape(splash); |
|
740 |
SplashRedrawWindow(splash); |
|
741 |
SplashEventLoop(splash); |
|
742 |
} |
|
743 |
SplashUnlock(splash); |
|
744 |
SplashDone(splash); |
|
745 |
||
746 |
splash->isVisible=-1; |
|
747 |
return 0; |
|
748 |
} |
|
749 |
||
750 |
void |
|
751 |
SplashCreateThread(Splash * splash) { |
|
752 |
pthread_t thr; |
|
753 |
pthread_attr_t attr; |
|
754 |
int rc; |
|
755 |
||
756 |
pthread_attr_init(&attr); |
|
757 |
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash); |
|
758 |
} |
|
759 |
||
760 |
void |
|
761 |
SplashLock(Splash * splash) { |
|
762 |
pthread_mutex_lock(&splash->lock); |
|
763 |
} |
|
764 |
||
765 |
void |
|
766 |
SplashUnlock(Splash * splash) { |
|
767 |
pthread_mutex_unlock(&splash->lock); |
|
768 |
} |
|
769 |
||
770 |
void |
|
771 |
SplashClosePlatform(Splash * splash) { |
|
772 |
sendctl(splash, SPLASHCTL_QUIT); |
|
773 |
} |
|
774 |
||
775 |
void |
|
776 |
SplashUpdate(Splash * splash) { |
|
777 |
sendctl(splash, SPLASHCTL_UPDATE); |
|
778 |
} |
|
779 |
||
780 |
void |
|
781 |
SplashReconfigure(Splash * splash) { |
|
782 |
sendctl(splash, SPLASHCTL_RECONFIGURE); |
|
783 |
} |