Mercurial > MadButterfly
comparison src/X_supp.c @ 1110:851a062368bd
Change signature of mbe_win_surface_create() by using format argument
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 08 Dec 2010 18:31:39 +0800 |
parents | c5255cc77143 |
children | 1993e5ae60aa |
comparison
equal
deleted
inserted
replaced
1109:77596f3d8d0c | 1110:851a062368bd |
---|---|
753 if(xmb_rt->backend_surface == NULL) | 753 if(xmb_rt->backend_surface == NULL) |
754 xshm_destroy(xmb_rt); | 754 xshm_destroy(xmb_rt); |
755 } | 755 } |
756 #endif /* XSHM */ | 756 #endif /* XSHM */ |
757 | 757 |
758 #include <X11/Xlib.h> | |
759 #include <X11/Xutil.h> | |
760 | |
761 static int | |
762 _get_img_fmt_from_xvisual(Display *display, Visual *visual) { | |
763 VisualID visual_id; | |
764 XVisualInfo temp; | |
765 XVisualInfo *infos; | |
766 int n; | |
767 int fmt = -1; | |
768 | |
769 visual_id = XVisualIDFromVisual(visual); | |
770 temp.visualid = visual_id; | |
771 infos = XGetVisualInfo(display, VisualIDMask, &temp, &n); | |
772 if(n != 1) | |
773 return -1; | |
774 | |
775 switch(infos->depth) { | |
776 case 32: | |
777 fmt = MB_IFMT_ARGB32; | |
778 break; | |
779 | |
780 case 24: | |
781 fmt = MB_IFMT_RGB24; | |
782 break; | |
783 | |
784 case 16: | |
785 fmt = MB_IFMT_RGB16_565; | |
786 break; | |
787 | |
788 case 8: | |
789 fmt = MB_IFMT_A8; | |
790 break; | |
791 | |
792 case 1: | |
793 fmt = MB_IFMT_A1; | |
794 break; | |
795 } | |
796 | |
797 return fmt; | |
798 } | |
799 | |
758 /*! \brief Initialize a MadButterfy runtime for Xlib. | 800 /*! \brief Initialize a MadButterfy runtime for Xlib. |
759 * | 801 * |
760 * This one is very like _x_supp_init(), except it accepts a | 802 * This one is very like _x_supp_init(), except it accepts a |
761 * X_supp_runtime_t object initialized with a display connected to a X | 803 * X_supp_runtime_t object initialized with a display connected to a X |
762 * server and an opened window. | 804 * server and an opened window. |
770 static int | 812 static int |
771 _x_supp_init_with_win_internal(X_supp_runtime_t *xmb_rt) { | 813 _x_supp_init_with_win_internal(X_supp_runtime_t *xmb_rt) { |
772 mb_img_ldr_t *img_ldr; | 814 mb_img_ldr_t *img_ldr; |
773 int w, h; | 815 int w, h; |
774 int disp_fd; | 816 int disp_fd; |
817 int fmt; | |
775 | 818 |
776 w = xmb_rt->w; | 819 w = xmb_rt->w; |
777 h = xmb_rt->h; | 820 h = xmb_rt->h; |
778 | 821 |
779 #ifdef XSHM | 822 #ifdef XSHM |
783 mbe_init(); | 826 mbe_init(); |
784 | 827 |
785 xmb_rt->surface = | 828 xmb_rt->surface = |
786 mbe_image_surface_create(MB_IFMT_ARGB32, w, h); | 829 mbe_image_surface_create(MB_IFMT_ARGB32, w, h); |
787 | 830 |
788 if(xmb_rt->backend_surface == NULL) /* xshm_init() may create one */ | 831 if(xmb_rt->backend_surface == NULL) { /* xshm_init() may create one */ |
832 fmt = _get_img_fmt_from_xvisual(xmb_rt->display, xmb_rt->visual); | |
833 if(fmt == -1) | |
834 return ERR; | |
835 | |
789 xmb_rt->backend_surface = | 836 xmb_rt->backend_surface = |
790 mbe_win_surface_create(xmb_rt->display, | 837 mbe_win_surface_create(xmb_rt->display, |
791 xmb_rt->win, | 838 xmb_rt->win, |
792 xmb_rt->visual, | 839 fmt, |
793 w, h); | 840 w, h); |
841 } | |
794 | 842 |
795 xmb_rt->cr = mbe_create(xmb_rt->surface); | 843 xmb_rt->cr = mbe_create(xmb_rt->surface); |
796 xmb_rt->backend_cr = mbe_create(xmb_rt->backend_surface); | 844 xmb_rt->backend_cr = mbe_create(xmb_rt->backend_surface); |
797 | 845 |
798 xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t)); | 846 xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t)); |