388 fprintf(stderr, "Xerror %s, XID %x, ser# %d\n", msg, err->resourceid,
389 err->serial);
390 sprintf(buf, "%d", err->request_code);
391 XGetErrorDatabaseText(disp, "XRequest", buf, "Unknown", msg, sizeof(msg));
392 fprintf(stderr, "Major opcode %d (%s)\n", err->request_code, msg);
393 if (err->request_code > 128) {
394 fprintf(stderr, "Minor opcode %d\n", err->minor_code);
395 }
396 */
397 return 0;
398 }
399
400 int
401 HandleIOError(Display * display) {
402 // for really bad errors, we should exit the thread we're on
403 SplashCleanup(SplashGetInstance());
404 pthread_exit(NULL);
405 return 0;
406 }
407
408 void
409 SplashInitPlatform(Splash * splash) {
410 int shapeVersionMajor, shapeVersionMinor;
411
412 // This setting enables the synchronous Xlib mode!
413 // Don't use it == 1 in production builds!
414 #if (defined DEBUG)
415 _Xdebug = 1;
416 #endif
417
418 pthread_mutex_init(&splash->lock, NULL);
419
420 // We should not ignore any errors.
421 //XSetErrorHandler(HandleError);
422 // XSetIOErrorHandler(HandleIOError);
423 XSetIOErrorHandler(NULL);
424 splash->display = XOpenDisplay(NULL);
425 if (!splash->display) {
426 splash->isVisible = -1;
427 return;
428 }
429
430 shapeSupported = XShapeQueryExtension(splash->display, &shapeEventBase,
431 &shapeErrorBase);
432 if (shapeSupported) {
433 XShapeQueryVersion(splash->display, &shapeVersionMajor,
434 &shapeVersionMinor);
435 }
436
437 splash->screen = XDefaultScreenOfDisplay(splash->display);
438 splash->visual = XDefaultVisualOfScreen(splash->screen);
439 switch (splash->visual->class) {
440 case TrueColor: {
441 int depth = XDefaultDepthOfScreen(splash->screen);
442
443 splash->byteAlignment = 1;
444 splash->maskRequired = shapeSupported;
445 initFormat(&splash->screenFormat, splash->visual->red_mask,
446 splash->visual->green_mask, splash->visual->blue_mask, 0);
447 splash->screenFormat.byteOrder =
457 int numColors;
458 int numComponents[3];
459 unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE];
460 XColor xColors[SPLASH_COLOR_MAP_SIZE];
461 int i;
462 int depth = XDefaultDepthOfScreen(splash->screen);
463 int scale = 65535 / MAX_COLOR_VALUE;
464
465 availableColors = GetNumAvailableColors(splash->display, splash->screen,
466 splash->visual->map_entries);
467 numColors = quantizeColors(availableColors, numComponents);
468 if (numColors > availableColors) {
469 // Could not allocate the color cells. Most probably
470 // the pool got exhausted. Disable the splash screen.
471 XCloseDisplay(splash->display);
472 splash->isVisible = -1;
473 splash->display = NULL;
474 splash->screen = NULL;
475 splash->visual = NULL;
476 fprintf(stderr, "Warning: unable to initialize the splashscreen. Not enough available color cells.\n");
477 return;
478 }
479 splash->cmap = AllocColors(splash->display, splash->screen,
480 numColors, colorIndex);
481 for (i = 0; i < numColors; i++) {
482 splash->colorIndex[i] = colorIndex[i];
483 }
484 initColorCube(numComponents, splash->colorMap, splash->dithers,
485 splash->colorIndex);
486 for (i = 0; i < numColors; i++) {
487 xColors[i].pixel = colorIndex[i];
488 xColors[i].red = (unsigned short)
489 QUAD_RED(splash->colorMap[colorIndex[i]]) * scale;
490 xColors[i].green = (unsigned short)
491 QUAD_GREEN(splash->colorMap[colorIndex[i]]) * scale;
492 xColors[i].blue = (unsigned short)
493 QUAD_BLUE(splash->colorMap[colorIndex[i]]) * scale;
494 xColors[i].flags = DoRed | DoGreen | DoBlue;
495 }
496 XStoreColors(splash->display, splash->cmap, xColors, numColors);
497 initFormat(&splash->screenFormat, 0, 0, 0, 0);
498 splash->screenFormat.colorIndex = splash->colorIndex;
499 splash->screenFormat.depthBytes = (depth + 7) / 8; // or always 8?
500 splash->screenFormat.colorMap = splash->colorMap;
501 splash->screenFormat.dithers = splash->dithers;
502 splash->screenFormat.numColors = numColors;
503 splash->screenFormat.byteOrder = BYTE_ORDER_NATIVE;
504 break;
505 }
506 default:
507 ; /* FIXME: should probably be fixed, but javaws splash screen doesn't support other visuals either */
508 }
509 }
510
511
512 void
513 SplashCleanupPlatform(Splash * splash) {
514 int i;
515
516 if (splash->frames) {
517 for (i = 0; i < splash->frameCount; i++) {
518 if (splash->frames[i].rects) {
519 free(splash->frames[i].rects);
520 splash->frames[i].rects = NULL;
521 }
522 }
523 }
524 splash->maskRequired = shapeSupported;
525 }
526
527 void
528 SplashDonePlatform(Splash * splash) {
|
388 fprintf(stderr, "Xerror %s, XID %x, ser# %d\n", msg, err->resourceid,
389 err->serial);
390 sprintf(buf, "%d", err->request_code);
391 XGetErrorDatabaseText(disp, "XRequest", buf, "Unknown", msg, sizeof(msg));
392 fprintf(stderr, "Major opcode %d (%s)\n", err->request_code, msg);
393 if (err->request_code > 128) {
394 fprintf(stderr, "Minor opcode %d\n", err->minor_code);
395 }
396 */
397 return 0;
398 }
399
400 int
401 HandleIOError(Display * display) {
402 // for really bad errors, we should exit the thread we're on
403 SplashCleanup(SplashGetInstance());
404 pthread_exit(NULL);
405 return 0;
406 }
407
408 int
409 SplashInitPlatform(Splash * splash) {
410 int shapeVersionMajor, shapeVersionMinor;
411
412 // This setting enables the synchronous Xlib mode!
413 // Don't use it == 1 in production builds!
414 #if (defined DEBUG)
415 _Xdebug = 1;
416 #endif
417
418 pthread_mutex_init(&splash->lock, NULL);
419
420 // We should not ignore any errors.
421 //XSetErrorHandler(HandleError);
422 // XSetIOErrorHandler(HandleIOError);
423 XSetIOErrorHandler(NULL);
424 splash->display = XOpenDisplay(NULL);
425 if (!splash->display) {
426 splash->isVisible = -1;
427 return 0;
428 }
429
430 shapeSupported = XShapeQueryExtension(splash->display, &shapeEventBase,
431 &shapeErrorBase);
432 if (shapeSupported) {
433 XShapeQueryVersion(splash->display, &shapeVersionMajor,
434 &shapeVersionMinor);
435 }
436
437 splash->screen = XDefaultScreenOfDisplay(splash->display);
438 splash->visual = XDefaultVisualOfScreen(splash->screen);
439 switch (splash->visual->class) {
440 case TrueColor: {
441 int depth = XDefaultDepthOfScreen(splash->screen);
442
443 splash->byteAlignment = 1;
444 splash->maskRequired = shapeSupported;
445 initFormat(&splash->screenFormat, splash->visual->red_mask,
446 splash->visual->green_mask, splash->visual->blue_mask, 0);
447 splash->screenFormat.byteOrder =
457 int numColors;
458 int numComponents[3];
459 unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE];
460 XColor xColors[SPLASH_COLOR_MAP_SIZE];
461 int i;
462 int depth = XDefaultDepthOfScreen(splash->screen);
463 int scale = 65535 / MAX_COLOR_VALUE;
464
465 availableColors = GetNumAvailableColors(splash->display, splash->screen,
466 splash->visual->map_entries);
467 numColors = quantizeColors(availableColors, numComponents);
468 if (numColors > availableColors) {
469 // Could not allocate the color cells. Most probably
470 // the pool got exhausted. Disable the splash screen.
471 XCloseDisplay(splash->display);
472 splash->isVisible = -1;
473 splash->display = NULL;
474 splash->screen = NULL;
475 splash->visual = NULL;
476 fprintf(stderr, "Warning: unable to initialize the splashscreen. Not enough available color cells.\n");
477 return 0;
478 }
479 splash->cmap = AllocColors(splash->display, splash->screen,
480 numColors, colorIndex);
481 for (i = 0; i < numColors; i++) {
482 splash->colorIndex[i] = colorIndex[i];
483 }
484 initColorCube(numComponents, splash->colorMap, splash->dithers,
485 splash->colorIndex);
486 for (i = 0; i < numColors; i++) {
487 xColors[i].pixel = colorIndex[i];
488 xColors[i].red = (unsigned short)
489 QUAD_RED(splash->colorMap[colorIndex[i]]) * scale;
490 xColors[i].green = (unsigned short)
491 QUAD_GREEN(splash->colorMap[colorIndex[i]]) * scale;
492 xColors[i].blue = (unsigned short)
493 QUAD_BLUE(splash->colorMap[colorIndex[i]]) * scale;
494 xColors[i].flags = DoRed | DoGreen | DoBlue;
495 }
496 XStoreColors(splash->display, splash->cmap, xColors, numColors);
497 initFormat(&splash->screenFormat, 0, 0, 0, 0);
498 splash->screenFormat.colorIndex = splash->colorIndex;
499 splash->screenFormat.depthBytes = (depth + 7) / 8; // or always 8?
500 splash->screenFormat.colorMap = splash->colorMap;
501 splash->screenFormat.dithers = splash->dithers;
502 splash->screenFormat.numColors = numColors;
503 splash->screenFormat.byteOrder = BYTE_ORDER_NATIVE;
504 break;
505 }
506 default:
507 ; /* FIXME: should probably be fixed, but javaws splash screen doesn't support other visuals either */
508 }
509 return 1;
510 }
511
512
513 void
514 SplashCleanupPlatform(Splash * splash) {
515 int i;
516
517 if (splash->frames) {
518 for (i = 0; i < splash->frameCount; i++) {
519 if (splash->frames[i].rects) {
520 free(splash->frames[i].rects);
521 splash->frames[i].rects = NULL;
522 }
523 }
524 }
525 splash->maskRequired = shapeSupported;
526 }
527
528 void
529 SplashDonePlatform(Splash * splash) {
|