comparison src/X_supp.c @ 757:f43224bf3524

Remove unused variables and refactor to X_MB_init_with_win
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 26 Aug 2010 17:54:11 +0800
parents cceac4ba259e
children 586e50f82c1f
comparison
equal deleted inserted replaced
756:cceac4ba259e 757:f43224bf3524
589 case 24: surf_fmt = CAIRO_FORMAT_RGB24; break; 589 case 24: surf_fmt = CAIRO_FORMAT_RGB24; break;
590 case 32: surf_fmt = CAIRO_FORMAT_ARGB32; break; 590 case 32: surf_fmt = CAIRO_FORMAT_ARGB32; break;
591 } 591 }
592 592
593 xmb_rt->backend_surface = 593 xmb_rt->backend_surface =
594 mbe_image_surface_create_for_data(ximage->data, 594 mbe_image_surface_create_for_data((unsigned char *)ximage->data,
595 surf_fmt, 595 surf_fmt,
596 xmb_rt->w, 596 xmb_rt->w,
597 xmb_rt->h, 597 xmb_rt->h,
598 ximage->bytes_per_line); 598 ximage->bytes_per_line);
599 if(xmb_rt->backend_surface == NULL) 599 if(xmb_rt->backend_surface == NULL)
601 } 601 }
602 #endif /* XSHM */ 602 #endif /* XSHM */
603 603
604 /*! \brief Initialize a MadButterfy runtime for Xlib. 604 /*! \brief Initialize a MadButterfy runtime for Xlib.
605 * 605 *
606 * This one is very like X_MB_init(), except it accepts a
607 * X_MB_runtime_t object initialized with a display connected to a X
608 * server and an opened window.
609 *
610 * Following field of the X_MB_runtime_t object should be initialized.
611 * - w, h
612 * - win
613 * - display
614 * - visual
615 */
616 static int
617 X_MB_init_with_win(X_MB_runtime_t *xmb_rt) {
618 mb_img_ldr_t *img_ldr;
619 int w, h;
620
621 w = xmb_rt->w;
622 h = xmb_rt->h;
623
624 #ifdef XSHM
625 xshm_init(xmb_rt);
626 #endif
627
628 xmb_rt->surface =
629 mbe_image_surface_create(MB_IFMT_ARGB32, w, h);
630
631 xmb_rt->surface_ptn =
632 mbe_pattern_create_for_surface(xmb_rt->surface);
633
634 if(xmb_rt->backend_surface == NULL) /* xshm_init() may create one */
635 xmb_rt->backend_surface =
636 mbe_xlib_surface_create(xmb_rt->display,
637 xmb_rt->win,
638 xmb_rt->visual,
639 w, h);
640
641 xmb_rt->cr = mbe_create(xmb_rt->surface);
642 xmb_rt->backend_cr = mbe_create(xmb_rt->backend_surface);
643
644 mbe_set_source(xmb_rt->backend_cr, xmb_rt->surface_ptn);
645
646 xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t));
647 redraw_man_init(xmb_rt->rdman, xmb_rt->cr, xmb_rt->backend_cr);
648 // FIXME: This is a wired loopback reference. This is inly required when we need
649 // to get the xmb_rt->tman for the animation. We should relocate the tman
650 // to the redraw_man_t instead.
651 xmb_rt->rdman->rt = xmb_rt;
652
653 xmb_rt->tman = mb_tman_new();
654
655 img_ldr = simple_mb_img_ldr_new("");
656 xmb_rt->img_ldr = img_ldr;
657 rdman_set_img_ldr(xmb_rt->rdman, img_ldr);
658 memset(xmb_rt->monitors,0,sizeof(xmb_rt->monitors));
659
660 #ifndef ONLY_MOUSE_MOVE_RAW
661 xmb_rt->last = NULL;
662 #endif
663
664 X_kb_init(&xmb_rt->kbinfo, xmb_rt->display, xmb_rt->rdman);
665
666 return OK;
667 }
668
669 /*! \brief Initialize a MadButterfy runtime for Xlib.
670 *
606 * It setups a runtime environment to run MadButterfly with Xlib. 671 * It setups a runtime environment to run MadButterfly with Xlib.
607 * Users should specify width and height of the opening window. 672 * Users should specify width and height of the opening window.
608 */ 673 */
609 static int X_MB_init(const char *display_name, 674 static int X_MB_init(const char *display_name,
610 int w, int h, X_MB_runtime_t *xmb_rt) { 675 int w, int h, X_MB_runtime_t *xmb_rt) {
611 mb_img_ldr_t *img_ldr;
612 int r; 676 int r;
613 677
614 memset(xmb_rt, 0, sizeof(X_MB_runtime_t)); 678 memset(xmb_rt, 0, sizeof(X_MB_runtime_t));
615 679
616 xmb_rt->w = w; 680 xmb_rt->w = w;
618 r = X_init_connection(display_name, w, h, &xmb_rt->display, 682 r = X_init_connection(display_name, w, h, &xmb_rt->display,
619 &xmb_rt->visual, &xmb_rt->win); 683 &xmb_rt->visual, &xmb_rt->win);
620 if(r != OK) 684 if(r != OK)
621 return ERR; 685 return ERR;
622 686
623 #ifdef XSHM 687 r = X_MB_init_with_win(xmb_rt);
624 xshm_init(xmb_rt); 688
625 #endif 689 return r;
626
627 xmb_rt->surface =
628 mbe_image_surface_create(MB_IFMT_ARGB32, w, h);
629
630 xmb_rt->surface_ptn =
631 mbe_pattern_create_for_surface(xmb_rt->surface);
632
633 if(xmb_rt->backend_surface == NULL) /* xshm_init() may create one */
634 xmb_rt->backend_surface =
635 mbe_xlib_surface_create(xmb_rt->display,
636 xmb_rt->win,
637 xmb_rt->visual,
638 w, h);
639
640 xmb_rt->cr = mbe_create(xmb_rt->surface);
641 xmb_rt->backend_cr = mbe_create(xmb_rt->backend_surface);
642
643 mbe_set_source(xmb_rt->backend_cr, xmb_rt->surface_ptn);
644
645 xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t));
646 redraw_man_init(xmb_rt->rdman, xmb_rt->cr, xmb_rt->backend_cr);
647 // FIXME: This is a wired loopback reference. This is inly required when we need
648 // to get the xmb_rt->tman for the animation. We should relocate the tman
649 // to the redraw_man_t instead.
650 xmb_rt->rdman->rt = xmb_rt;
651 xmb_rt->rdman->w = w;
652 xmb_rt->rdman->h = h;
653
654 xmb_rt->tman = mb_tman_new();
655
656 img_ldr = simple_mb_img_ldr_new("");
657 xmb_rt->img_ldr = img_ldr;
658 rdman_set_img_ldr(xmb_rt->rdman, img_ldr);
659 memset(xmb_rt->monitors,0,sizeof(xmb_rt->monitors));
660
661 #ifndef ONLY_MOUSE_MOVE_RAW
662 xmb_rt->last = NULL;
663 #endif
664
665 X_kb_init(&xmb_rt->kbinfo, xmb_rt->display, xmb_rt->rdman);
666
667 return OK;
668 } 690 }
669 691
670 static void X_MB_destroy(X_MB_runtime_t *xmb_rt) { 692 static void X_MB_destroy(X_MB_runtime_t *xmb_rt) {
671 if(xmb_rt->rdman) { 693 if(xmb_rt->rdman) {
672 redraw_man_destroy(xmb_rt->rdman); 694 redraw_man_destroy(xmb_rt->rdman);