comparison src/video/x11/SDL_x11render.c @ 4633:100f7ab48946

Documentation and code safety updates. (x11 renderer)
author Sunny Sachanandani <sunnysachanandani@gmail.com>
date Sun, 08 Aug 2010 19:26:30 +0530
parents 066ce836b80e
children 164bee619400
comparison
equal deleted inserted replaced
4632:066ce836b80e 4633:100f7ab48946
312 XRenderPictFormat templ; 312 XRenderPictFormat templ;
313 templ.type = PictTypeDirect; 313 templ.type = PictTypeDirect;
314 XRenderPictFormat *pict_format; 314 XRenderPictFormat *pict_format;
315 Uint32 format; 315 Uint32 format;
316 int i = 0; 316 int i = 0;
317 /* Convert each XRenderPictFormat into appropriate
318 * SDLPixelFormatEnum. */
317 while (info->num_texture_formats < 50) { 319 while (info->num_texture_formats < 50) {
318 pict_format = 320 pict_format =
319 XRenderFindFormat(data->display, PictFormatType, &templ, i++); 321 XRenderFindFormat(data->display, PictFormatType, &templ, i++);
320 if (pict_format) { 322 if (pict_format) {
321 format = XRenderPictFormatToSDLPixelFormatEnum(pict_format); 323 format = XRenderPictFormatToSDLPixelFormatEnum(pict_format);
324 } 326 }
325 } 327 }
326 else 328 else
327 break; 329 break;
328 } 330 }
331 /* Update the capabilities of the renderer. */
329 info->blend_modes |= (SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | 332 info->blend_modes |= (SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD |
330 SDL_BLENDMODE_MOD | SDL_BLENDMODE_MASK); 333 SDL_BLENDMODE_MOD | SDL_BLENDMODE_MASK);
331 info->scale_modes |= (SDL_TEXTURESCALEMODE_FAST | SDL_TEXTURESCALEMODE_SLOW | 334 info->scale_modes |= (SDL_TEXTURESCALEMODE_FAST | SDL_TEXTURESCALEMODE_SLOW |
332 SDL_TEXTURESCALEMODE_BEST); 335 SDL_TEXTURESCALEMODE_BEST);
333 info->mod_modes |= (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA); 336 info->mod_modes |= (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA);
437 0, 0, 440 0, 0,
438 window->w, window->h); 441 window->w, window->h);
439 /* Create a clip mask that is used for rendering primitives. */ 442 /* Create a clip mask that is used for rendering primitives. */
440 data->stencil = XCreatePixmap(data->display, data->xwindow, 443 data->stencil = XCreatePixmap(data->display, data->xwindow,
441 window->w, window->h, 32); 444 window->w, window->h, 32);
445 if (!data->stencil) {
446 SDL_SetError("XCreatePixmap() failed.");
447 return NULL;
448 }
442 449
443 /* Create the GC for the clip mask. */ 450 /* Create the GC for the clip mask. */
444 data->stencil_gc = XCreateGC(data->display, data->stencil, 451 data->stencil_gc = XCreateGC(data->display, data->stencil,
445 GCGraphicsExposures, &gcv); 452 GCGraphicsExposures, &gcv);
453 /* Set the GC parameters. */
446 XSetBackground(data->display, data->stencil_gc, 0); 454 XSetBackground(data->display, data->stencil_gc, 0);
447 XSetForeground(data->display, data->stencil_gc, 0); 455 XSetForeground(data->display, data->stencil_gc, 0);
448 XFillRectangle(data->display, data->stencil, data->stencil_gc, 456 XFillRectangle(data->display, data->stencil, data->stencil_gc,
449 0, 0, window->w, window->h); 457 0, 0, window->w, window->h);
450 XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF); 458 XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
459
460 /* Create an XRender Picture for the clip mask. */
451 data->stencil_pict = 461 data->stencil_pict =
452 XRenderCreatePicture(data->display, data->stencil, 462 XRenderCreatePicture(data->display, data->stencil,
453 XRenderFindStandardFormat(data->display, 463 XRenderFindStandardFormat(data->display,
454 PictStandardARGB32), 464 PictStandardARGB32),
455 0, NULL); 465 0, NULL);
466 if (!data->stencil_pict) {
467 SDL_SetError("XRenderCreatePicture() failed.");
468 return NULL;
469 }
456 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE 470 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
457 if (data->use_xdamage) { 471 if (data->use_xdamage) {
458 data->stencil_damage = 472 data->stencil_damage =
459 XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty); 473 XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty);
474 if (!data->stencil_damage) {
475 SDL_SetError("XDamageCreate() failed.");
476 return NULL;
477 }
460 XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts); 478 XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
461 } 479 }
462 #endif 480 #endif
481 /* Create a brush pixmap for the color being
482 * drawn at any given time. */
463 data->brush = 483 data->brush =
464 XCreatePixmap(data->display, data->xwindow, 1, 1, 32); 484 XCreatePixmap(data->display, data->xwindow, 1, 1, 32);
485 if (!data->brush) {
486 SDL_SetError("XCreatePixmap() failed.");
487 return NULL;
488 }
489
490 /* Set some parameters for the brush. */
465 XRenderPictureAttributes brush_attr; 491 XRenderPictureAttributes brush_attr;
466 brush_attr.repeat = RepeatNormal; 492 brush_attr.repeat = RepeatNormal;
493 /* Create an XRender Picture for the brush
494 * with the above parameters. */
467 data->brush_pict = 495 data->brush_pict =
468 XRenderCreatePicture(data->display, data->brush, 496 XRenderCreatePicture(data->display, data->brush,
469 XRenderFindStandardFormat(data->display, 497 XRenderFindStandardFormat(data->display,
470 PictStandardARGB32), 498 PictStandardARGB32),
471 CPRepeat, &brush_attr); 499 CPRepeat, &brush_attr);
472 // Set the default blending mode. 500 if (!data->brush_pict) {
501 SDL_SetError("XRenderCreatePicture() failed.");
502 return NULL;
503 }
504 // FIXME: Is the following necessary?
505 /* Set the default blending mode. */
473 renderer->blendMode = SDL_BLENDMODE_BLEND; 506 renderer->blendMode = SDL_BLENDMODE_BLEND;
474 data->blend_op = PictOpOver; 507 data->blend_op = PictOpOver;
475 } 508 }
476 #endif 509 #endif
477 if (flags & SDL_RENDERER_SINGLEBUFFER) { 510 if (flags & SDL_RENDERER_SINGLEBUFFER) {
511 { 544 {
512 data->pixmaps[i] = 545 data->pixmaps[i] =
513 XCreatePixmap(data->display, data->xwindow, window->w, window->h, 546 XCreatePixmap(data->display, data->xwindow, window->w, window->h,
514 displaydata->depth); 547 displaydata->depth);
515 } 548 }
516 if (data->pixmaps[i] == None) { 549 if (!data->pixmaps[i]) {
517 X11_DestroyRenderer(renderer); 550 X11_DestroyRenderer(renderer);
518 SDL_SetError("XCreatePixmap() failed"); 551 SDL_SetError("XCreatePixmap() failed");
519 return NULL; 552 return NULL;
520 } 553 }
521 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 554 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
522 if (data->use_xrender) { 555 if (data->use_xrender) {
523 /* Create xrender pictures for each of the pixmaps 556 /* Create XRender pictures for each of the pixmaps
524 * and clear the pixmaps. */ 557 * and clear the pixmaps. */
525 data->pixmap_picts[i] = 558 data->pixmap_picts[i] =
526 XRenderCreatePicture(data->display, 559 XRenderCreatePicture(data->display,
527 data->pixmaps[i], 560 data->pixmaps[i],
528 XRenderFindStandardFormat(data->display, 561 XRenderFindStandardFormat(data->display,
561 data->makedirty = SDL_FALSE; 594 data->makedirty = SDL_FALSE;
562 } 595 }
563 data->current_pixmap = 0; 596 data->current_pixmap = 0;
564 597
565 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 598 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
599 /* When using XRender the drawable format
600 * is not the same as the screen format. */
566 if (data->use_xrender) { 601 if (data->use_xrender) {
567 bpp = data->drawable_pict_fmt->depth; 602 bpp = data->drawable_pict_fmt->depth;
568 Rmask = ((data->drawable_pict_fmt->direct.redMask) 603 Rmask = ((data->drawable_pict_fmt->direct.redMask)
569 << (data->drawable_pict_fmt->direct.red)); 604 << (data->drawable_pict_fmt->direct.red));
570 Gmask = ((data->drawable_pict_fmt->direct.greenMask) 605 Gmask = ((data->drawable_pict_fmt->direct.greenMask)
612 if (data->use_xrender) { 647 if (data->use_xrender) {
613 XRenderFreePicture(data->display, data->xwindow_pict); 648 XRenderFreePicture(data->display, data->xwindow_pict);
614 649
615 data->xwindow_pict_fmt = 650 data->xwindow_pict_fmt =
616 XRenderFindVisualFormat(data->display, data->visual); 651 XRenderFindVisualFormat(data->display, data->visual);
652 if (!data->xwindow_pict_fmt) {
653 SDL_SetError("XRenderFindVisualFormat() failed.");
654 return -1;
655 }
656
617 data->xwindow_pict = 657 data->xwindow_pict =
618 XRenderCreatePicture(data->display, data->xwindow, 658 XRenderCreatePicture(data->display, data->xwindow,
619 data->xwindow_pict_fmt, 0, NULL); 659 data->xwindow_pict_fmt, 0, NULL);
620 660 if (!data->xwindow_pict) {
661 SDL_SetError("XRenderCreatePicture() failed.");
662 return -1;
663 }
664
621 XRenderComposite(data->display, 665 XRenderComposite(data->display,
622 PictOpClear, 666 PictOpClear,
623 data->xwindow_pict, 667 data->xwindow_pict,
624 None, 668 None,
625 data->xwindow_pict, 669 data->xwindow_pict,
627 0, 0, 671 0, 0,
628 0, 0, 672 0, 0,
629 window->w, window->h); 673 window->w, window->h);
630 674
631 XFreePixmap(data->display, data->stencil); 675 XFreePixmap(data->display, data->stencil);
632 /* Create a clip mask that is used for rendering primitives. */
633 data->stencil = XCreatePixmap(data->display, data->xwindow, 676 data->stencil = XCreatePixmap(data->display, data->xwindow,
634 window->w, window->h, 32); 677 window->w, window->h, 32);
635 678 if (!data->stencil) {
679 SDL_SetError("XCreatePixmap() failed.");
680 return -1;
681 }
682
636 XRenderFreePicture(data->display, data->stencil_pict); 683 XRenderFreePicture(data->display, data->stencil_pict);
637 data->stencil_pict = 684 data->stencil_pict =
638 XRenderCreatePicture(data->display, data->stencil, 685 XRenderCreatePicture(data->display, data->stencil,
639 XRenderFindStandardFormat(data->display, 686 XRenderFindStandardFormat(data->display,
640 PictStandardARGB32), 687 PictStandardARGB32),
641 0, NULL); 688 0, NULL);
689 if (!data->stencil_pict) {
690 SDL_SetError("XRenderCreatePicture() failed.");
691 return -1;
692 }
642 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE 693 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
643 XDamageDestroy(data->display, data->stencil_damage); 694 XDamageDestroy(data->display, data->stencil_damage);
644 if (data->use_xdamage) { 695 if (data->use_xdamage) {
645 data->stencil_damage = 696 data->stencil_damage =
646 XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty); 697 XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty);
698 if (!data->stencil_damage) {
699 SDL_SetError("XDamageCreate() failed.");
700 return -1;
701 }
647 XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts); 702 XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
648 } 703 }
649 #endif 704 #endif
650 } 705 }
651 #endif 706 #endif
1018 if (!data->modulated_picture) { 1073 if (!data->modulated_picture) {
1019 X11_DestroyTexture(renderer, texture); 1074 X11_DestroyTexture(renderer, texture);
1020 SDL_SetError("XRenderCreatePicture() failed"); 1075 SDL_SetError("XRenderCreatePicture() failed");
1021 return -1; 1076 return -1;
1022 } 1077 }
1078 // FIXME: Is the following required?
1079 /* Set the default blending and scaling modes. */
1023 texture->blendMode = SDL_BLENDMODE_NONE; 1080 texture->blendMode = SDL_BLENDMODE_NONE;
1024 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE; 1081 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
1025 data->blend_op = PictOpSrc; 1082 data->blend_op = PictOpSrc;
1026 data->filter = NULL; 1083 data->filter = NULL;
1027 } 1084 }