Mercurial > MadButterfly
changeset 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 | 77596f3d8d0c |
children | fa5f71d4aa04 |
files | include/mb_graph_engine_cairo.h include/mb_graph_engine_openvg.h src/X_supp.c src/graph_engine_cairo.c src/graph_engine_openvg.c |
diffstat | 5 files changed, 85 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/include/mb_graph_engine_cairo.h Tue Dec 07 12:42:41 2010 +0800 +++ b/include/mb_graph_engine_cairo.h Wed Dec 08 18:31:39 2010 +0800 @@ -26,7 +26,6 @@ #define mbe_image_surface_get_width cairo_image_surface_get_width #define mbe_image_surface_get_data cairo_image_surface_get_data #define mbe_scaled_font_reference cairo_scaled_font_reference -#define mbe_win_surface_create cairo_xlib_surface_create #define mbe_scaled_font_destroy cairo_scaled_font_destroy #define mbe_font_face_reference cairo_font_face_reference #define mbe_font_face_destroy cairo_font_face_destroy @@ -78,6 +77,12 @@ } +extern mbe_surface_t *mbe_win_surface_create(void *display, + void *drawable, + int fmt, + int width, + int height); + extern mbe_font_face_t * mbe_query_font_face(const char *family, int slant, int weight); extern void mbe_free_font_face(mbe_font_face_t *face);
--- a/include/mb_graph_engine_openvg.h Tue Dec 07 12:42:41 2010 +0800 +++ b/include/mb_graph_engine_openvg.h Wed Dec 08 18:31:39 2010 +0800 @@ -207,9 +207,12 @@ #include <X11/Xlib.h> #include <X11/Xutil.h> -extern mbe_surface_t *mbe_win_surface_create(Display *display, - Drawable drawable, - Visual *visual, +/* + * TODO: define a proper type for display and drawable. + */ +extern mbe_surface_t *mbe_win_surface_create(void *display, + void *drawable, + int fmt, int width, int height); #endif
--- a/src/X_supp.c Tue Dec 07 12:42:41 2010 +0800 +++ b/src/X_supp.c Wed Dec 08 18:31:39 2010 +0800 @@ -755,6 +755,48 @@ } #endif /* XSHM */ +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +static int +_get_img_fmt_from_xvisual(Display *display, Visual *visual) { + VisualID visual_id; + XVisualInfo temp; + XVisualInfo *infos; + int n; + int fmt = -1; + + visual_id = XVisualIDFromVisual(visual); + temp.visualid = visual_id; + infos = XGetVisualInfo(display, VisualIDMask, &temp, &n); + if(n != 1) + return -1; + + switch(infos->depth) { + case 32: + fmt = MB_IFMT_ARGB32; + break; + + case 24: + fmt = MB_IFMT_RGB24; + break; + + case 16: + fmt = MB_IFMT_RGB16_565; + break; + + case 8: + fmt = MB_IFMT_A8; + break; + + case 1: + fmt = MB_IFMT_A1; + break; + } + + return fmt; +} + /*! \brief Initialize a MadButterfy runtime for Xlib. * * This one is very like _x_supp_init(), except it accepts a @@ -772,6 +814,7 @@ mb_img_ldr_t *img_ldr; int w, h; int disp_fd; + int fmt; w = xmb_rt->w; h = xmb_rt->h; @@ -785,12 +828,17 @@ xmb_rt->surface = mbe_image_surface_create(MB_IFMT_ARGB32, w, h); - if(xmb_rt->backend_surface == NULL) /* xshm_init() may create one */ + if(xmb_rt->backend_surface == NULL) { /* xshm_init() may create one */ + fmt = _get_img_fmt_from_xvisual(xmb_rt->display, xmb_rt->visual); + if(fmt == -1) + return ERR; + xmb_rt->backend_surface = mbe_win_surface_create(xmb_rt->display, xmb_rt->win, - xmb_rt->visual, + fmt, w, h); + } xmb_rt->cr = mbe_create(xmb_rt->surface); xmb_rt->backend_cr = mbe_create(xmb_rt->backend_surface);
--- a/src/graph_engine_cairo.c Tue Dec 07 12:42:41 2010 +0800 +++ b/src/graph_engine_cairo.c Wed Dec 08 18:31:39 2010 +0800 @@ -1,5 +1,6 @@ // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- // vim: sw=4:ts=8:sts=4 +#include <X11/Xlib.h> #include <fontconfig/fontconfig.h> #include <cairo-ft.h> #include "mb_graph_engine_cairo.h" @@ -82,6 +83,23 @@ } +extern mbe_surface_t * +mbe_win_surface_create(void *display, void *drawable, + int fmt, int width, int height) { + XWindowAttributes attrs; + mbe_surface_t *surf; + int r; + + r = XGetWindowAttributes((Display *)display, (Drawable)drawable, &attrs); + if(r == 0) + return NULL; + + surf = cairo_xlib_surface_create((Display *)display, (Drawable)drawable, + attrs.visual, width, height); + + return surf; +} + /*! \brief Find out a font face for a pattern specified. * * The pattern, here, is a vector of family, slant, and weight.
--- a/src/graph_engine_openvg.c Tue Dec 07 12:42:41 2010 +0800 +++ b/src/graph_engine_openvg.c Wed Dec 08 18:31:39 2010 +0800 @@ -540,76 +540,30 @@ } #ifdef EGL_GLX -#include <X11/Xlib.h> -#include <X11/Xutil.h> - -static int -_get_img_fmt_from_xvisual(Display *display, Visual *visual) { - VisualID visual_id; - XVisualInfo temp; - XVisualInfo *infos; - int n; - int fmt = -1; - - visual_id = XVisualIDFromVisual(visual); - temp.visualid = visual_id; - infos = XGetVisualInfo(display, VisualIDMask, &temp, &n); - if(n != 1) - return -1; - - switch(infos->depth) { - case 32: - fmt = MB_IFMT_ARGB32; - break; - - case 24: - fmt = MB_IFMT_RGB24; - break; - - case 16: - fmt = MB_IFMT_RGB16_565; - break; - - case 8: - fmt = MB_IFMT_A8; - break; - - case 1: - fmt = MB_IFMT_A1; - break; - } - - return fmt; -} - /*! \brief Create an EGL window surface for X11. * * This function is compiled only for GLX enabled. */ mbe_surface_t * -mbe_win_surface_create(Display *display, Drawable drawable, - Visual *visual, int width, int height) { +mbe_win_surface_create(void *display, void *drawable, + int fmt, int width, int height) { EGLDisplay egl_disp; EGLSurface egl_surface; mbe_surface_t *surface; EGLConfig config; EGLint attrib_list[2] = {EGL_NONE}; - int fmt; int r; - fmt = _get_img_fmt_from_xvisual(display, visual); - if(fmt == -1) - return NULL; - r = _openvg_find_config(fmt, width, height, &config); if(r != 0) return NULL; - egl_disp = eglGetDisplay(display); + egl_disp = eglGetDisplay((Display *)display); if(egl_disp == EGL_NO_DISPLAY || egl_disp != _VG_DISPLAY()) return NULL; - egl_surface = eglCreateWindowSurface(egl_disp, config, drawable, + egl_surface = eglCreateWindowSurface(egl_disp, config, + (Drawable)drawable, attrib_list); surface = O_ALLOC(mbe_surface_t);