# HG changeset patch # User Thinker K.F. Li # Date 1291204909 -28800 # Node ID d09f603438d8ef42b6a34a7ba7896bead413e43b # Parent cf82361fe5b9d27e2556ba88adfeefad2aa282ec Merge the work of improvement for graphic engine of openvg branch diff -r cf82361fe5b9 -r d09f603438d8 configure.ac --- a/configure.ac Wed Dec 01 19:59:58 2010 +0800 +++ b/configure.ac Wed Dec 01 20:01:49 2010 +0800 @@ -203,7 +203,7 @@ # Checks for libraries. [if [ x"${graphic_engine}" = x"openvg" ]; then] -AC_CHECK_HEADERS([GL/glut.h],, [AC_MSG_ERROR([can not find GL/glut.h])]) +AC_CHECK_HEADERS([EGL/egl.h],, [AC_MSG_ERROR([can not find EGL/egl.h])]) [fi] [if [ x"${image_loader}" = x"imlib2" ]; then] diff -r cf82361fe5b9 -r d09f603438d8 include/mb_basic_types.h --- a/include/mb_basic_types.h Wed Dec 01 19:59:58 2010 +0800 +++ b/include/mb_basic_types.h Wed Dec 01 20:01:49 2010 +0800 @@ -10,4 +10,15 @@ co_comp_t r, g, b, a; } grad_stop_t; +/*! \brief An rectangle area. + * + * This type is used to describe an rectangle area in an image or on a + * screen. + */ +struct _area { + co_aix x, y; + co_aix w, h; +}; +typedef struct _area area_t; + #endif /* __MB_BASIC_TYPES_H_ */ diff -r cf82361fe5b9 -r d09f603438d8 include/mb_graph_engine_cairo.h --- a/include/mb_graph_engine_cairo.h Wed Dec 01 19:59:58 2010 +0800 +++ b/include/mb_graph_engine_cairo.h Wed Dec 01 20:01:49 2010 +0800 @@ -26,7 +26,7 @@ #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_xlib_surface_create cairo_xlib_surface_create +#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 @@ -41,7 +41,7 @@ #define mbe_get_font_face cairo_get_font_face #define mbe_fill_preserve cairo_fill_preserve #define mbe_set_source cairo_set_source -#define mbe_reset_clip cairo_reset_clip +#define mbe_reset_scissoring cairo_reset_clip #define mbe_get_target cairo_get_target #define mbe_close_path cairo_close_path #define mbe_text_path cairo_text_path @@ -59,7 +59,7 @@ #define mbe_paint cairo_paint #define mbe_save cairo_save #define mbe_fill cairo_fill -#define mbe_clip cairo_clip +#define mbe_init() typedef cairo_text_extents_t mbe_text_extents_t; typedef cairo_scaled_font_t mbe_scaled_font_t; @@ -91,6 +91,8 @@ co_aix x1, co_aix y1, grad_stop_t *stops, int stop_cnt); +extern mbe_pattern_t *mbe_pattern_create_image(mb_img_data_t *img); +extern void mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas); static void mbe_pattern_set_matrix(mbe_pattern_t *ptn, diff -r cf82361fe5b9 -r d09f603438d8 include/mb_types.h --- a/include/mb_types.h Wed Dec 01 19:59:58 2010 +0800 +++ b/include/mb_types.h Wed Dec 01 20:01:49 2010 +0800 @@ -10,7 +10,6 @@ typedef struct _shape shape_t; typedef struct _geo geo_t; -typedef struct _area area_t; typedef struct _shnode shnode_t; typedef struct _paint paint_t; typedef struct _mb_obj mb_obj_t; @@ -103,11 +102,6 @@ shnode_t *next; }; -struct _area { - co_aix x, y; - co_aix w, h; -}; - /*! \brief Geometry data of a shape or a group of shape. */ struct _geo { diff -r cf82361fe5b9 -r d09f603438d8 src/X_main.c --- a/src/X_main.c Wed Dec 01 19:59:58 2010 +0800 +++ b/src/X_main.c Wed Dec 01 20:01:49 2010 +0800 @@ -467,9 +467,9 @@ CWOverrideRedirect, &wattr); r = XMapWindow(display, win); - surface = mbe_xlib_surface_create(display, win, visual, w, h); + surface = mbe_win_surface_create(display, win, visual, w, h); if(surface == NULL) - printf("mbe_xlib_surface_create\n"); + printf("mbe_win_surface_create\n"); drawing(surface, w, h); diff -r cf82361fe5b9 -r d09f603438d8 src/X_supp.c --- a/src/X_supp.c Wed Dec 01 19:59:58 2010 +0800 +++ b/src/X_supp.c Wed Dec 01 20:01:49 2010 +0800 @@ -781,7 +781,9 @@ #ifdef XSHM xshm_init(xmb_rt); #endif - + + mbe_init(); + xmb_rt->surface = mbe_image_surface_create(MB_IFMT_ARGB32, w, h); @@ -790,21 +792,27 @@ if(xmb_rt->backend_surface == NULL) /* xshm_init() may create one */ xmb_rt->backend_surface = - mbe_xlib_surface_create(xmb_rt->display, - xmb_rt->win, - xmb_rt->visual, - w, h); + mbe_win_surface_create(xmb_rt->display, + xmb_rt->win, + xmb_rt->visual, + w, h); xmb_rt->cr = mbe_create(xmb_rt->surface); xmb_rt->backend_cr = mbe_create(xmb_rt->backend_surface); + /* TODO: Remove this line. Since we use mbe_copy_source(), it + * will set source for the backend. So, this line is redundants. + * It can be removed. sourface_ptn can be removed, too. + */ mbe_set_source(xmb_rt->backend_cr, xmb_rt->surface_ptn); xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t)); redraw_man_init(xmb_rt->rdman, xmb_rt->cr, xmb_rt->backend_cr); - // FIXME: This is a wired loopback reference. This is inly required when we need - // to get the xmb_rt->tman for the animation. We should relocate the tman - // to the redraw_man_t instead. + /* FIXME: This is a wired loopback reference. This is inly + * required when we need to get the xmb_rt->tman for the + * animation. We should relocate the tman to the + * redraw_man_t instead. + */ xmb_rt->rdman->rt = xmb_rt; xmb_rt->io_man = mb_io_man_new(_io_factory); diff -r cf82361fe5b9 -r d09f603438d8 src/graph_engine_cairo.c --- a/src/graph_engine_cairo.c Wed Dec 01 19:59:58 2010 +0800 +++ b/src/graph_engine_cairo.c Wed Dec 01 20:01:49 2010 +0800 @@ -150,3 +150,57 @@ return ptn; } + +mbe_pattern_t * +mbe_pattern_create_image(mb_img_data_t *img) { + cairo_surface_t *surf; + cairo_pattern_t *ptn; + cairo_format_t fmt; + + switch(img->fmt) { + case MB_IFMT_ARGB32: + fmt = CAIRO_FORMAT_ARGB32; + break; + + case MB_IFMT_RGB24: + fmt = CAIRO_FORMAT_RGB24; + break; + + case MB_IFMT_A8: + fmt = CAIRO_FORMAT_A8; + break; + + case MB_IFMT_A1: + fmt = CAIRO_FORMAT_A1; + break; + + case MB_IFMT_RGB16_565: + fmt = CAIRO_FORMAT_RGB16_565; + break; + + default: + return NULL; + } + + surf = cairo_image_surface_create_for_data(img->content, fmt, + img->w, img->h, img->stride); + ptn = cairo_pattern_create_for_surface(surf); + cairo_surface_destroy(surf); + + return ptn; +} + +void +mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas) { + area_t *area; + int i; + + cairo_new_path(canvas); + + for(i = 0; i < n_areas; i++) { + area = areas[i]; + cairo_rectangle(canvas, area->x, area->y, area->w, area->h); + } + + cairo_clip(canvas); +} diff -r cf82361fe5b9 -r d09f603438d8 src/redraw_man.c --- a/src/redraw_man.c Wed Dec 01 19:59:58 2010 +0800 +++ b/src/redraw_man.c Wed Dec 01 20:01:49 2010 +0800 @@ -2237,36 +2237,22 @@ mbe_clear(canvas); } -static void make_clip(mbe_t *cr, int n_dirty_areas, - area_t **dirty_areas) { - int i; - area_t *area; - - mbe_new_path(cr); - for(i = 0; i < n_dirty_areas; i++) { - area = dirty_areas[i]; - if(area->w < 0.1 || area->h < 0.1) - continue; - mbe_rectangle(cr, area->x, area->y, area->w, area->h); - } - mbe_clip(cr); -} +#define make_scissoring(canvas, n_dirty_areas, dirty_areas) \ + mbe_scissoring(canvas, n_dirty_areas, dirty_areas) static void reset_clip(canvas_t *cr) { - mbe_reset_clip(cr); + mbe_reset_scissoring(cr); } static void copy_cr_2_backend(redraw_man_t *rdman, int n_dirty_areas, area_t **dirty_areas) { if(n_dirty_areas) - make_clip(rdman->backend, n_dirty_areas, dirty_areas); - + make_scissoring(rdman->backend, n_dirty_areas, dirty_areas); + mbe_copy_source(rdman->cr, rdman->backend); } #else /* UNITTEST */ -static void make_clip(mbe_t *cr, int n_dirty_areas, - area_t **dirty_areas) { -} +#define make_scissoring(canvas, n_dirty_areas, dirty_areas) static void clear_canvas(canvas_t *canvas) { } @@ -2401,7 +2387,7 @@ area->h = ceilf(area->h); } - make_clip(canvas, n_areas, areas); + make_scissoring(canvas, n_areas, areas); clear_canvas(canvas); r = draw_coord_shapes_in_dirty_areas(rdman, coord);