Mercurial > MadButterfly
changeset 1066:292fbb86d8f3
Merge from the HEAD
author | wycc |
---|---|
date | Tue, 30 Nov 2010 03:57:36 +0800 |
parents | eb3719020866 (current diff) 09c1ef31884f (diff) |
children | 7b4e80ab671a afa42d5836cc |
files | nodejs/X_supp_njs.c nodejs/X_supp_njs.h |
diffstat | 34 files changed, 611 insertions(+), 657 deletions(-) [+] |
line wrap: on
line diff
--- a/dox/dictionary.h Tue Nov 30 03:57:14 2010 +0800 +++ b/dox/dictionary.h Tue Nov 30 03:57:36 2010 +0800 @@ -11,7 +11,6 @@ * - \b man stands for MANager. * - \b mb stands for MadButterfly. * - \b mbe stands for MadButterfly graphic Engine. - * - \b ob stands for OBserver. * - \b obj stands for OBJect. * - \b prop stands for PROPerty. * - \b rdman stands for ReDraw MANager.
--- a/examples/tank/tank_main.c Tue Nov 30 03:57:14 2010 +0800 +++ b/examples/tank/tank_main.c Tue Nov 30 03:57:36 2010 +0800 @@ -58,7 +58,7 @@ int direction; mb_progm_t *progm; mb_timeval_t start_time; - observer_t *ob_redraw; + observer_t *observer_redraw; int hit_tmr; mb_timer_man_t *timer_man; }; @@ -170,7 +170,7 @@ mb_rt_t *mb_rt = tank_rt->mb_rt; redraw_man_t *rdman; mb_timer_man_t *timer_man; - ob_factory_t *factory; + observer_factory_t *factory; /* for the program */ mb_progm_t *progm; subject_t *comp_sub; @@ -238,7 +238,7 @@ rdman = mb_runtime_rdman(mb_rt); timer_man = mb_runtime_timer_man(mb_rt); - factory = mb_runtime_ob_factory(mb_rt); + factory = mb_runtime_observer_factory(mb_rt); progm = mb_progm_new(1, rdman); tank->progm = progm;
--- a/include/mb.h Tue Nov 30 03:57:14 2010 +0800 +++ b/include/mb.h Tue Nov 30 03:57:36 2010 +0800 @@ -16,5 +16,6 @@ #include "mb_animate.h" #include "mb_shapes.h" #include "mb_backend.h" +#include "mb_sprite.h" #endif /* __MB_H_ */
--- a/include/mb_backend.h Tue Nov 30 03:57:14 2010 +0800 +++ b/include/mb_backend.h Tue Nov 30 03:57:36 2010 +0800 @@ -82,7 +82,7 @@ subject_t *(*kbevents)(mb_rt_t *rt); redraw_man_t *(*rdman)(mb_rt_t *rt); mb_timer_man_t *(*timer_man)(mb_rt_t *rt); - ob_factory_t *(*ob_factory)(mb_rt_t *rt); + observer_factory_t *(*observer_factory)(mb_rt_t *rt); mb_img_ldr_t *(*loader)(mb_rt_t *rt); /* @@ -126,8 +126,8 @@ mb_dfl_backend.rdman(rt) #define mb_runtime_timer_man(rt) \ mb_dfl_backend.timer_man(rt) -#define mb_runtime_ob_factory(rt) \ - mb_dfl_backend.ob_factory(rt) +#define mb_runtime_observer_factory(rt) \ + mb_dfl_backend.observer_factory(rt) #define mb_runtime_loader(rt) \ mb_dfl_backend.loader(rt)
--- a/include/mb_dfb_supp.h Tue Nov 30 03:57:14 2010 +0800 +++ b/include/mb_dfb_supp.h Tue Nov 30 03:57:36 2010 +0800 @@ -32,7 +32,7 @@ extern subject_t *X_MB_kbevents(void *xmb_rt); extern redraw_man_t *X_MB_rdman(void *xmb_rt); extern mb_tman_t *X_MB_tman(void *xmb_rt); -extern ob_factory_t *X_MB_ob_factory(void *xmb_rt); +extern observer_factory_t *X_MB_observer_factory(void *xmb_rt); extern mb_img_ldr_t *X_MB_img_ldr(void *xmb_rt); #endif
--- a/include/mb_observer.h Tue Nov 30 03:57:14 2010 +0800 +++ b/include/mb_observer.h Tue Nov 30 03:57:36 2010 +0800 @@ -10,7 +10,7 @@ typedef struct _subject subject_t; typedef struct _mouse_event mouse_event_t; typedef struct _monitor_event monitor_event_t; -typedef struct _ob_factory ob_factory_t; +typedef struct _observer_factory observer_factory_t; typedef void (*evt_handler)(event_t *event, void *arg); struct _event { @@ -55,7 +55,7 @@ int flags; subject_t *monitor_sub; /*!< \brief Monitor adding/removing * obervers on this subject. */ - ob_factory_t *factory; + observer_factory_t *factory; STAILQ(observer_t) observers; }; /*! \brief Flag that make a subject to stop propagate events to parents. */ @@ -87,13 +87,13 @@ * It provides functions for allocation of subject and observer objects, * and strategy function for getting the subject of parent coord object. */ -struct _ob_factory { - subject_t *(*subject_alloc)(ob_factory_t *factory); - void (*subject_free)(ob_factory_t *factory, subject_t *subject); - observer_t *(*observer_alloc)(ob_factory_t *factory); - void (*observer_free)(ob_factory_t *factory, observer_t *observer); +struct _observer_factory { + subject_t *(*subject_alloc)(observer_factory_t *factory); + void (*subject_free)(observer_factory_t *factory, subject_t *subject); + observer_t *(*observer_alloc)(observer_factory_t *factory); + void (*observer_free)(observer_factory_t *factory, observer_t *observer); /*! This is a strategy function to get subjects of parents. */ - subject_t *(*get_parent_subject)(ob_factory_t *factory, + subject_t *(*get_parent_subject)(observer_factory_t *factory, subject_t *cur_subject); }; @@ -105,7 +105,7 @@ EVT_MOUSE_MOVE_RAW }; -extern subject_t *subject_new(ob_factory_t *factory, +extern subject_t *subject_new(observer_factory_t *factory, void *obj, int obj_type); extern void subject_free(subject_t *subject); extern void subject_notify(subject_t *subject, event_t *evt);
--- a/include/mb_redraw_man.h Tue Nov 30 03:57:14 2010 +0800 +++ b/include/mb_redraw_man.h Tue Nov 30 03:57:36 2010 +0800 @@ -9,8 +9,14 @@ #include "mb_observer.h" #include "mb_img_ldr.h" +/*! \defgroup rdman Redraw Manager + * @{ + */ typedef struct _redraw_man redraw_man_t; +/*! \defgroup rdman_private Private Types of Redraw Manager + * @{ + */ typedef void (*free_func_t)(redraw_man_t *rdman, void *obj); struct _free_obj { void *obj; @@ -25,6 +31,7 @@ DARRAY(coords, coord_t *); DARRAY(geos, geo_t *); +/* @} */ /*! \brief Manage redrawing of shapes (graphic elements). * @@ -75,7 +82,7 @@ mbe_t *cr; mbe_t *backend; - ob_factory_t ob_factory; + observer_factory_t observer_factory; subject_t *redraw; /*!< \brief Notified after redrawing. */ subject_t *addrm_monitor; /*!< \brief Monitor adding/removing observers @@ -105,7 +112,7 @@ extern int rdman_add_shape(redraw_man_t *rdman, shape_t *shape, coord_t *coord); /*! \brief Make a shape been managed by a redraw manager. */ -#define rdman_shape_man(rdman, shape) \ +#define rdman_man_shape(rdman, shape) \ do { \ mb_prop_store_init(&((mb_obj_t *)(shape))->props, \ (rdman)->pent_pool); \ @@ -147,6 +154,10 @@ } \ shnode_free(rdman, __last); \ } while(0) + +/*! \defgroup rdman_paints Paints Supporting of Redraw Manger + * @{ + */ #define _rdman_paint_child(rdman, paint, shape) \ do { \ shnode_t *__node; \ @@ -190,14 +201,23 @@ (shape)->stroke = paint; \ } while(0) extern int rdman_paint_changed(redraw_man_t *rdman, paint_t *paint); +/* @} */ +/*! \defgroup rdman_pos Position/Overlay Detection for Managed Objects + * @{ + */ extern shape_t *find_shape_at_pos(redraw_man_t *rdman, co_aix x, co_aix y, int *in_stroke); extern int mb_obj_pos_is_in(redraw_man_t *rdman, mb_obj_t *obj, co_aix x, co_aix y, int *in_stroke); extern int mb_objs_are_overlay(redraw_man_t *rdman, mb_obj_t *obj1, mb_obj_t *obj2); -#define rdman_get_ob_factory(rdman) (&(rdman)->ob_factory) +/* @} */ + +/*! \defgroup rdman_accessors Accessors of Redraw Manager + * @{ + */ +#define rdman_get_observer_factory(rdman) (&(rdman)->observer_factory) #define rdman_get_redraw_subject(rdman) ((rdman)->redraw) #define rdman_get_root(rdman) ((rdman)->root_coord) #define rdman_get_cr(rdman) ((rdman)->cr) @@ -211,36 +231,24 @@ rdman_get_gen_geos(rdman)->num #define rdman_clear_shape_gl(rdman) \ DARRAY_CLEAN(rdman_get_gen_geos(rdman)) +#define _coord_get_canvas(coord) ((coord)->canvas_info->canvas) +#define _coord_set_canvas(coord, _canvas) \ + do { \ + (coord)->canvas_info->canvas = _canvas; \ + } while(0) #define rdman_prop_store(rdman) ((rdman)->props) #define rdman_img_ldr(rdman) ((rdman)->img_ldr) #define rdman_set_img_ldr(rdman, ldr) \ do { (rdman)->img_ldr = ldr; } while(0) +/* @} */ /*! \brief Attach backend to the redraw manager so that we can hide the backend from the users. * */ #define rdman_attach_backend(rdman,backend) (((rdman)->rt)=(backend)) -/*! \brief Load sprite dymanicly from the shared object module. - * - * The search path can be changed by sprite_set_search_path. The name - * can have a relative path in the front of it. - * This function will search the object in the current working directory - * and then search the system search path. - */ -extern mb_sprite_t *sprite_load(const char *name, redraw_man_t *rdman, - coord_t *root); - -/*! \brief Set the search path of dymanic object loading. - * - */ -extern void sprite_set_search_path(const char *path); extern paint_t *rdman_img_ldr_load_paint(redraw_man_t *rdman, const char *img_id); - -typedef void (*mb_eventcb_t )(int fd,void *arg); -#define MONITOR_READ 1 -#define MONITOR_WRITE 2 - +/* @} */ #endif /* __REDRAW_MAN_H_ */
--- a/include/mb_shapes.h Tue Nov 30 03:57:14 2010 +0800 +++ b/include/mb_shapes.h Tue Nov 30 03:57:36 2010 +0800 @@ -28,7 +28,7 @@ * - mb_obj_init() to initialize shape_t::obj. * - assign *_free() to \ref shape_t::free. * - make new object been managed by a redraw manager. - * - call rdman_shape_man() + * - call rdman_man_shape() * - *_free() * - assigned to \ref shape_t::free. * - *_transform()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/mb_sprite.h Tue Nov 30 03:57:36 2010 +0800 @@ -0,0 +1,69 @@ +#ifndef __MB_SPRITE_H_ +#define __MB_SPRITE_H_ + +#include "mb_types.h" +#include "mb_redraw_man.h" + +/*! \defgroup mb_sprite Implement sprites for animation. + * @{ + */ +/*! \brief A sprite is a set of graphics that being an object in animation. + * + * A sprite include graphics comprise an object. For example, a tank, in + * example tank, is comprised a set of graphics that is represented as a + * sprite. + */ +struct _mb_sprite { + void (*free)(mb_sprite_t *); + mb_obj_t *(*get_obj_with_name)(mb_sprite_t *sprite, const char *id); + /*! Return non-zero for error. */ + int (*goto_scene)(mb_sprite_t *sprite, int scene_no); +}; + +#define MB_SPRITE_FREE(sprite) ((mb_sprite_t *)(sprite))->free(sprite) +#define MB_SPRITE_GET_OBJ(sprite, name) \ + ((mb_sprite_t *)(sprite))->get_obj_with_name((mb_sprite_t *)(sprite), \ + (name)) +#define MB_SPRITE_GOTO_SCENE(sprite, scene_no) \ + ((mb_sprite_t *)(sprite))->goto_scene((mb_sprite_t *)(sprite), scene_no) + + +/*! \brief Load sprite dymanicly from the shared object module. + * + * The search path can be changed by sprite_set_search_path. The name + * can have a relative path in the front of it. + * This function will search the object in the current working directory + * and then search the system search path. + */ +extern mb_sprite_t *sprite_load(const char *name, redraw_man_t *rdman, + coord_t *root); + +/*! \brief Set the search path of dymanic object loading. + * + */ +extern void sprite_set_search_path(const char *path); + +/*! \defgroup mb_sprite_lsym Sprite with linear symbol table. + * @{ + */ +struct _mb_sprite_lsym_entry { + const char *sym; + const int offset; +}; +typedef struct _mb_sprite_lsym_entry mb_sprite_lsym_entry_t; + +/*! \brief A sub-type of mb_sprite_t with linear symbol table. + * + * This type of sprite search symbols with linear/or binary searching. + */ +struct _mb_sprite_lsym { + mb_sprite_t sprite; + int num_entries; + mb_sprite_lsym_entry_t *entries; +}; +typedef struct _mb_sprite_lsym mb_sprite_lsym_t; +/* @} */ +/* @} */ + +#endif /* __MB_SPRITE_H_ */ +
--- a/include/mb_types.h Tue Nov 30 03:57:14 2010 +0800 +++ b/include/mb_types.h Tue Nov 30 03:57:36 2010 +0800 @@ -33,9 +33,11 @@ * mb_obj_t should be initialized with mb_obj_init() and destroied with * mb_obj_destroy(). * - * We have defined a set of convienent API which will wrap the coord_t or shape_t API accoridng to its type. - * Please refer to http://www.assembla.com/wiki/show/dFrSMOtDer3BZUab7jnrAJ/MBAF_Object for the details. This - * API is designed for regular programmers which can be used to change some common properties of objects without + * We have defined a set of convienent API which will wrap the coord_t + * or shape_t API accoridng to its type. Please refer to + * http://www.assembla.com/wiki/show/dFrSMOtDer3BZUab7jnrAJ/MBAF_Object + * for the details. This API is designed for regular programmers which + * can be used to change some common properties of objects without * checking its type. */ struct _mb_obj { @@ -309,21 +311,6 @@ (co)->flags &= ~COF_CACHE_MASK; \ } while(0) #define coord_is_root(co) ((co)->parent == NULL) -#define coord_is_cached(co) ((co)->flags & COF_OWN_CANVAS) -#define coord_is_always_cached(co) ((co)->flags & COF_ALWAYS_CACHE) -#define coord_is_fast_cached(co) ((co)->flags & COF_FAST_MASK) -#define coord_is_precise_cached(co) ((co)->flags & COF_PRECISE_MASK) -#define coord_is_zeroing(co) ((co)->flags & COF_MUST_ZEROING) -#define coord_set_zeroing(co) \ - do { (co)->flags |= COF_MUST_ZEROING; } while(0) -#define coord_clear_zeroing(co) \ - do { (co)->flags &= ~COF_MUST_ZEROING; } while(0) -#define coord_set_flags(co, _flags) \ - do { (co)->flags |= (_flags); } while(0) -#define coord_get_parent(co) ((co)->parent) -#define coord_get_flags(co, _flags) ((co)->flags & (_flags)) -#define coord_clear_flags(co, _flags) \ - do { (co)->flags &= ~(_flags); } while(0) #define coord_get_mouse_event(coord) ((coord)->mouse_event) #define coord_get_opacity(coord) ((coord)->opacity) #define coord_set_opacity(coord, v) do { (coord)->opacity = v; } while(0) @@ -361,22 +348,6 @@ sh_get_geo(shape)))) #define coord_get_area(coord) ((coord)->cur_area) #define coord_get_last_area(coord) ((coord)->last_area) -#define coord_get_pcache_area(coord) ((coord)->canvas_info->pcache_cur_area) -#define coord_get_pcache_last_area(coord) \ - ((coord)->canvas_info->pcache_last_area) -#define coord_get_cached(coord) ((coord)->canvas_info->owner) -#define _coord_get_canvas(coord) ((coord)->canvas_info->canvas) -#define _coord_set_canvas(coord, _canvas) \ - do { \ - (coord)->canvas_info->canvas = _canvas; \ - } while(0) -#define _coord_get_dirty_areas(coord) (&(coord)->canvas_info->dirty_areas) -#define _coord_get_aggr_dirty_areas(coord) \ - ((coord)->canvas_info->aggr_dirty_areas) -#define coord_get_2pdev(coord) ((coord)->canvas_info->cache_2_pdev) -#define coord_get_2pdev_rev(coord) ((coord)->canvas_info->cache_2_pdev_rev) -#define coord_get_aggr2pdev(coord) ((coord)->canvas_info->aggr_2_pdev) -#define coord_get_aggr2pdev_rev(coord) ((coord)->canvas_info->aggr_2_pdev_rev) /* @} */ @@ -428,48 +399,4 @@ #define sh_set_stroke_width(sh, v) do { (sh)->stroke_width = (v); } while(0) #define sh_get_stroke_width(sh) (sh)->stroke_width - -/*! \brief A sprite is a set of graphics that being an object in animation. - * - * A sprite include graphics comprise an object. For example, a tank, in - * example tank, is comprised a set of graphics that is represented as a - * sprite. - */ -struct _mb_sprite { - void (*free)(mb_sprite_t *); - mb_obj_t *(*get_obj_with_name)(mb_sprite_t *sprite, const char *id); - /*! Return non-zero for error. */ - int (*goto_scene)(mb_sprite_t *sprite, int scene_no); -}; - -#define MB_SPRITE_FREE(sprite) ((mb_sprite_t *)(sprite))->free(sprite) -#define MB_SPRITE_GET_OBJ(sprite, name) \ - ((mb_sprite_t *)(sprite))->get_obj_with_name((mb_sprite_t *)(sprite), \ - (name)) -#define MB_SPRITE_GOTO_SCENE(sprite, scene_no) \ - ((mb_sprite_t *)(sprite))->goto_scene((mb_sprite_t *)(sprite), scene_no) - - -/*! \defgroup mb_sprite_lsym Sprite with linear symbol table. - * @{ - */ -struct _mb_sprite_lsym_entry { - const char *sym; - const int offset; -}; -typedef struct _mb_sprite_lsym_entry mb_sprite_lsym_entry_t; - -/*! \brief A sub-type of mb_sprite_t with linear symbol table. - * - * This type of sprite search symbols with linear/or binary searching. - */ -struct _mb_sprite_lsym { - mb_sprite_t sprite; - int num_entries; - mb_sprite_lsym_entry_t *entries; -}; -typedef struct _mb_sprite_lsym mb_sprite_lsym_t; - -/* @} */ - #endif /* __MB_TYPES_H_ */
--- a/nodejs/Makefile.am Tue Nov 30 03:57:14 2010 +0800 +++ b/nodejs/Makefile.am Tue Nov 30 03:57:36 2010 +0800 @@ -1,7 +1,7 @@ # -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- # vim: sw=4:ts=8:sts=4 -mbfly_node_SRCS = mbfly_njs.cc X_supp_njs.c coord.cc shapes.cc paints.cc \ +mbfly_node_SRCS = mbfly_njs.cc njs_mb_supp.c coord.cc shapes.cc paints.cc \ font.cc mbfly_node_CFLAGS= -I$(abs_top_builddir)/include \ -I$(abs_top_srcdir)/include \
--- a/nodejs/X_supp_njs.c Tue Nov 30 03:57:14 2010 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,403 +0,0 @@ -// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- -// vim: sw=4:ts=8:sts=4 -/*! \brief Implement X11 backend for nodejs plugin. - * - * Since nodejs use libev to handle event loops, part of X11 backend - * code can not be used directly. The part of code should be rewrote. - * The part is about - */ -#include <stdio.h> -#include <string.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <ev.h> -#include "mb_X_supp.h" -#include "mb_tools.h" -#include <mb_backend.h> -#include "X_supp_njs.h" - -#ifndef ASSERT -#define ASSERT(x) -#endif - -#define OK 0 -#define ERR -1 - - -/*! \defgroup njs_timer_man Timer manager for nodejs. - * @{ - */ -struct _njs_timer_timeout { - ev_timer tmwatcher; - mb_timer_cb_t cb; - mb_timeval_t *timeout; - void *data; -}; - -static int njs_timer_man_timeout(mb_timer_man_t *tm_man, - mb_timeval_t *tm_out, - mb_timer_cb_t cb, void *data); -static void njs_timer_man_remove(mb_timer_man_t *tm_man, int tm_hdl); -static mb_timer_man_t *njs_timer_man_new(void); -static void njs_timer_man_free(mb_timer_man_t *timer_man); - -static mb_timer_man_t njs_timer_man = { - njs_timer_man_timeout, - njs_timer_man_remove -}; - -static mb_timer_factory_t njs_timer_factory = { - njs_timer_man_new, - njs_timer_man_free -}; - -static void -njs_timer_man_cb(EV_P_ ev_timer *tmwatcher, int revent) { - struct _njs_timer_timeout *timer_timeout = - MEM2OBJ(tmwatcher, struct _njs_timer_timeout, tmwatcher); - mb_timeval_t now; - - get_now(&now); - timer_timeout->cb((int)timer_timeout, timer_timeout->timeout, &now, - timer_timeout->data); -} - -static int -njs_timer_man_timeout(mb_timer_man_t *tm_man, - mb_timeval_t *timeout, - mb_timer_cb_t cb, void *data) { - struct _njs_timer_timeout *timer_timeout; - mb_timeval_t now, timeout_diff; - ev_tstamp timeout_stamp; - - timer_timeout = O_ALLOC(struct _njs_timer_timeout); - if(timer_timeout == NULL) - return ERR; - - timer_timeout->cb = cb; - timer_timeout->timeout = timeout; - - get_now(&now); - - memcpy(&timeout_diff, timeout, sizeof(mb_timeval_t)); - MB_TIMEVAL_DIFF(&timeout_diff, &now); - timeout_stamp = (ev_tstamp)MB_TIMEVAL_SEC(&timeout_diff) + - (ev_tstamp)MB_TIMEVAL_USEC(&timeout_diff) / 1000000; - ev_timer_init(&timer_timeout->tmwatcher, njs_timer_man_cb, - timeout_stamp, 0); - ev_timer_start(&timer_timeout->tmwatcher); - - return (int)timer_timeout; -} - -static void -njs_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl) { - struct _njs_timer_timeout *timer_timeout = - (struct _njs_timer_timeout *)tm_hdl; - - ev_timer_stop(&timer_timeout->tmwatcher); - free(timer_timeout); -} - -static mb_timer_man_t * -njs_timer_man_new(void) { - return &njs_timer_man; -} - -static void -njs_timer_man_free(mb_timer_man_t *timer_man) { -} - -void -X_njs_MB_reg_timer_man(void) { - mb_reg_timer_factory(&njs_timer_factory); -} - -/* @} */ - -#ifdef USE_MB_TMAN -static void timer_cb(EV_P_ ev_timer *tmwatcher, int revent); - -/*! \brief Register next timeout with libev. - */ -static void -set_next_timeout(njs_runtime_t *rt) { - mb_tman_t *tman; - mb_timeval_t now, tmo; - ev_tstamp tout; - int r; - - tman = X_MB_tman(rt->xrt); - get_now(&now); - r = mb_tman_next_timeout(tman, &now, &tmo); - if(r == 0) { - MB_TIMEVAL_DIFF(&tmo, &now); - tout = (ev_tstamp)MB_TIMEVAL_SEC(&tmo) + - (ev_tstamp)MB_TIMEVAL_USEC(&tmo) / 1000000; - ev_timer_init(&rt->tmwatcher, timer_cb, tout, 0); - ev_timer_start(&rt->tmwatcher); - rt->enable_timer = 1; - } else - rt->enable_timer = 0; -} - -static void -x_conn_cb(EV_P_ ev_io *iowatcher, int revent) { - njs_runtime_t *rt = MEM2OBJ(iowatcher, njs_runtime_t, iowatcher); - redraw_man_t *rdman; - extern void _X_MB_handle_x_event_for_nodejs(void *rt); - - rdman = X_MB_rdman(rt->xrt); - _X_MB_handle_x_event_for_nodejs(rt->xrt); - rdman_redraw_changed(rdman); - - if(rt->enable_timer == 0) /* no installed timeout */ - set_next_timeout(rt); -} - -static void -timer_cb(EV_P_ ev_timer *tmwatcher, int revent) { - njs_runtime_t *rt = MEM2OBJ(tmwatcher, njs_runtime_t, tmwatcher); - mb_tman_t *tman; - redraw_man_t *rdman; - mb_timeval_t now; - extern int _X_MB_flush_x_conn_for_nodejs(void *rt); - - tman = X_MB_tman(rt->xrt); - get_now(&now); - mb_tman_handle_timeout(tman, &now); - - rdman = X_MB_rdman(rt->xrt); - rdman_redraw_changed(rdman); - _X_MB_flush_x_conn_for_nodejs(rt->xrt); - - set_next_timeout(rt); -} - -#endif /* USE_MB_TMAN */ - -/*! \defgroup njs_io_man IO manager for nodejs. - * @{ - */ -struct _njs_io_reg { - ev_io iowatcher; - int fd; - mb_IO_cb_t cb; - void *data; -}; - -static int njs_io_man_reg(struct _mb_IO_man *io_man, - int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data); -static void njs_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl); -static mb_IO_man_t *njs_io_man_new(void); -static void njs_io_man_free(mb_IO_man_t *io_man); - -static mb_IO_man_t njs_io_man = { - njs_io_man_reg, - njs_io_man_unreg -}; - -/*! \brief IO factory to integrate MadButterfly to event loop of nodejs. - */ -static mb_IO_factory_t njs_io_factory = { - njs_io_man_new, - njs_io_man_free -}; - -/*! \brief Bridge libev callback to IO manager callback. - */ -static void -njs_io_man_cb(EV_P_ ev_io *iowatcher, int revent) { - struct _njs_io_reg *io_reg = - MEM2OBJ(iowatcher, struct _njs_io_reg, iowatcher); - MB_IO_TYPE type; - - switch(revent & (EV_READ | EV_WRITE)) { - case EV_READ: - type = MB_IO_R; - break; - case EV_WRITE: - type = MB_IO_W; - break; - case EV_READ | EV_WRITE: - type = MB_IO_RW; - break; - } - - io_reg->cb((int)io_reg, io_reg->fd, type, io_reg->data); -} - -static int -njs_io_man_reg(struct _mb_IO_man *io_man, - int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data) { - int _type; - struct _njs_io_reg *io_reg; - - if(type == MB_IO_R) - _type = EV_READ; - else if(type == MB_IO_W) - _type = EV_WRITE; - else if(type == MB_IO_RW) - _type = EV_READ | EV_WRITE; - else - return ERR; - - io_reg = O_ALLOC(struct _njs_io_reg); - if(io_reg == NULL) - return ERR; - - io_reg->fd = fd; - io_reg->cb = cb; - io_reg->data = data; - - ev_io_init(&io_reg->iowatcher, njs_io_man_cb, fd, _type); - ev_io_start(&io_reg->iowatcher); - - return (int)io_reg; -} - -static void -njs_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl) { - struct _njs_io_reg *io_reg = (struct _njs_io_reg *)io_hdl; - - ev_io_stop(&io_reg->iowatcher); - free(io_reg); -} - -static mb_IO_man_t * -njs_io_man_new(void) { - return &njs_io_man; -} - -static void -njs_io_man_free(mb_IO_man_t *io_man) { -} - -/*! \brief Register an IO factory with MadButterfly backend. - */ -void -X_njs_MB_reg_IO_man(void) { - mb_reg_IO_factory(&njs_io_factory); -} - -/* @} */ - -#if 0 -/*! \brief Handle connection coming data and timeout of timers. - * - * \param rt is a runtime object for X. - */ -void -X_njs_MB_init_handle_connection(njs_runtime_t *rt) { - void *xrt = rt->xrt; - int fd; - extern int _X_MB_get_x_conn_for_nodejs(void *rt); - - /* - * Setup watcher for X connection. - */ - fd = _X_MB_get_x_conn_for_nodejs(xrt); - ev_io_init(&rt->iowatcher, x_conn_cb, fd, EV_READ); - ev_io_start(&rt->iowatcher); - rt->enable_io = 1; - - set_next_timeout(rt); -} -#endif - -/*! \brief Free njs_runtime_t. - */ -void -X_njs_MB_free(njs_runtime_t *rt) { - /*! - * TODO: Release all IO and timer request. - */ - mb_runtime_free(rt->xrt); - free(rt); -} - -/*! \brief Free njs_runtime_t. - */ -void -X_njs_MB_free_keep_win(njs_runtime_t *rt) { - /* - * TODO: Release all IO and timer request. - */ - mb_runtime_free_keep_win(rt->xrt); - free(rt); -} - -int -X_njs_MB_flush(njs_runtime_t *rt) { - mb_rt_t *mb_rt = rt->xrt; - int r; - - r = mb_runtime_flush(mb_rt); - return r; -} - -njs_runtime_t * -X_njs_MB_new(char *display_name, int w, int h) { - njs_runtime_t *rt; - mb_rt_t *mb_rt; - - rt = (njs_runtime_t *)malloc(sizeof(njs_runtime_t)); - ASSERT(rt != NULL); - - mb_rt = mb_runtime_new(display_name, w, h); - - rt->xrt = mb_rt; - - return rt; -} - -/*! \brief Create a njs_runtime_t for an existed window. - * - * The njs_runtime_t created by this function must be free by - * X_njs_MB_free_keep_win(). - */ -njs_runtime_t * -X_njs_MB_new_with_win(void *display, long win) { - njs_runtime_t *rt; - mb_rt_t *mb_rt; - - rt = (njs_runtime_t *)malloc(sizeof(njs_runtime_t)); - ASSERT(rt != NULL); - - mb_rt = mb_runtime_new_with_win((Display *)display, win); - - rt->xrt = mb_rt; - - return rt; -} - -/*! \brief Pass a X event to X runtime. - */ -void -X_njs_MB_handle_single_event(njs_runtime_t *rt, void *evt) { -#if 0 - void *xrt = rt->xrt; - extern void _X_MB_handle_single_event(void *rt, void *evt); - - _X_MB_handle_single_event(xrt, evt); -#endif -} - -/*! \brief Called at end of an iteration of event loop. - */ -void -X_njs_MB_no_more_event(njs_runtime_t *rt) { -#if 0 - mb_rt_t *xrt = rt->xrt; - extern void _X_MB_no_more_event(mb_rt_t *rt); - - _X_MB_no_more_event(xrt); -#endif -} - -/*! \brief Get X runtime that is backend of this njs runtime. - */ -mb_rt_t * -_X_njs_MB_get_X_runtime(njs_runtime_t *rt) { - return rt->xrt; -}
--- a/nodejs/X_supp_njs.h Tue Nov 30 03:57:14 2010 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- -// vim: sw=4:ts=8:sts=4 -#ifndef __X_SUPP_NJS_H_ -#define __X_SUPP_NJS_H_ - -#include <ev.h> -#include <mb_backend.h> - -typedef struct _njs_runtime { - mb_rt_t *xrt; -} njs_runtime_t; - -extern void X_njs_MB_reg_timer_man(void); -extern void X_njs_MB_reg_IO_man(void); -/* extern void X_njs_MB_init_handle_connection(njs_runtime_t *rt); */ -extern void X_njs_MB_free(njs_runtime_t *rt); -extern njs_runtime_t *X_njs_MB_new(char *display_name, int w, int h); -extern void X_njs_MB_free_keep_win(njs_runtime_t *rt); -extern njs_runtime_t *X_njs_MB_new_with_win(void *display, long win); -extern int X_njs_MB_flush(njs_runtime_t *rt); -extern void X_njs_MB_handle_single_event(njs_runtime_t *rt, void *evt); -extern void X_njs_MB_no_more_event(njs_runtime_t *rt); -extern mb_rt_t *_X_njs_MB_get_X_runtime(njs_runtime_t *rt); - -#define X_njs_MB_kbevents(rt) mb_runtime_kbevents((rt)->xrt) -#define X_njs_MB_rdman(rt) mb_runtime_rdman((rt)->xrt) -#define X_njs_MB_timer_man(rt) mb_runtime_timer_man((rt)->xrt) -#define X_njs_MB_ob_factory(rt) mb_runtime_ob_factory((rt)->xrt) -#define X_njs_MB_img_ldr(rt) mb_runtime_img_ldr((rt)->xrt) - -#endif /* __X_SUPP_NJS_H_ */
--- a/nodejs/coord.cc Tue Nov 30 03:57:14 2010 +0800 +++ b/nodejs/coord.cc Tue Nov 30 03:57:36 2010 +0800 @@ -7,7 +7,7 @@ #include "mb.h" #include "mb_X_supp.h" #include "mb_tools.h" -#include "X_supp_njs.h" +#include "njs_mb_supp.h" } #include "mbfly_njs.h"
--- a/nodejs/mbfly_njs.cc Tue Nov 30 03:57:14 2010 +0800 +++ b/nodejs/mbfly_njs.cc Tue Nov 30 03:57:36 2010 +0800 @@ -5,7 +5,7 @@ #include <v8.h> extern "C" { -#include "X_supp_njs.h" +#include "njs_mb_supp.h" } #include "mbfly_njs.h" @@ -22,7 +22,7 @@ coord_t *coord; redraw_man_t *rdman; - rdman = X_njs_MB_rdman(rt); + rdman = njs_mb_rdman(rt); coord = rdman_coord_new(rdman, parent); if(coord == NULL) { *err = "Can not allocate a redraw_man_t"; @@ -46,7 +46,7 @@ xnjsmb_redraw_changed(njs_runtime_t *rt) { redraw_man_t *rdman; - rdman = X_njs_MB_rdman(rt); + rdman = njs_mb_rdman(rt); rdman_redraw_changed(rdman); } @@ -54,35 +54,35 @@ xnjsmb_redraw_all(njs_runtime_t *rt) { redraw_man_t *rdman; - rdman = X_njs_MB_rdman(rt); + rdman = njs_mb_rdman(rt); rdman_redraw_all(rdman); } static void xnjsmb_handle_single_event(njs_runtime_t *rt, void *evt) { - X_njs_MB_handle_single_event(rt, evt); + njs_mb_handle_single_event(rt, evt); } static void xnjsmb_no_more_event(njs_runtime_t *rt) { - X_njs_MB_no_more_event(rt); + njs_mb_no_more_event(rt); } static njs_runtime_t * -_X_njs_MB_new(Handle<Object> self, char *display_name, +_njs_mb_new(Handle<Object> self, char *display_name, int width, int height) { njs_runtime_t *obj; subject_t *subject; Handle<Value> subject_o; - obj = X_njs_MB_new(display_name, width, height); + obj = njs_mb_new(display_name, width, height); WRAP(self, obj); /* mkroot need a wrapped object, but * it is wrapped after returning of * this function. So, we wrap it * here. */ xnjsmb_coord_mkroot(self); - subject = X_njs_MB_kbevents(obj); + subject = njs_mb_kbevents(obj); subject_o = export_xnjsmb_auto_subject_new(subject); SET(self, "kbevents", subject_o); @@ -90,20 +90,20 @@ } static njs_runtime_t * -_X_njs_MB_new_with_win(Handle<Object> self, void *display, +_njs_mb_new_with_win(Handle<Object> self, void *display, long win) { njs_runtime_t *obj; subject_t *subject; Handle<Value> subject_o; - obj = X_njs_MB_new_with_win(display, win); + obj = njs_mb_new_with_win(display, win); WRAP(self, obj); /* mkroot need a wrapped object, but * it is wrapped after returning of * this function. So, we wrap it * here. */ xnjsmb_coord_mkroot(self); - subject = X_njs_MB_kbevents(obj); + subject = njs_mb_kbevents(obj); subject_o = export_xnjsmb_auto_subject_new(subject); SET(self, "kbevents", subject_o); @@ -143,7 +143,7 @@ redraw_man_t *rdman; rt = (njs_runtime_t *)UNWRAP(mbrt); - rdman = X_njs_MB_rdman(rt); + rdman = njs_mb_rdman(rt); return rdman; } @@ -170,8 +170,8 @@ xnjsmb_auto_mb_rt_init(); xnjsmb_auto_mb_rt_display_init(); xnjsmb_auto_mb_rt_with_win_init(); - X_njs_MB_reg_timer_man(); - X_njs_MB_reg_IO_man(); + njs_mb_reg_timer_man(); + njs_mb_reg_IO_man(); /* * Add properties to mb_rt templates for other modules.
--- a/nodejs/mbfly_njs.h Tue Nov 30 03:57:14 2010 +0800 +++ b/nodejs/mbfly_njs.h Tue Nov 30 03:57:36 2010 +0800 @@ -6,7 +6,7 @@ #include <v8.h> extern "C" { #include <mb.h> -#include "X_supp_njs.h" +#include "njs_mb_supp.h" } #define THROW(x) \
--- a/nodejs/mbfly_njs.m4 Tue Nov 30 03:57:14 2010 +0800 +++ b/nodejs/mbfly_njs.m4 Tue Nov 30 03:57:36 2010 +0800 @@ -8,7 +8,7 @@ (([MOD], [xnjsmb_mb_rt_objs_mod]))), METHOD([redraw_changed], [xnjsmb_redraw_changed], (), 0, []), METHOD([redraw_all], [xnjsmb_redraw_all], (), 0, []), - METHOD([flush], [X_njs_MB_flush], (), 0, []), + METHOD([flush], [njs_mb_flush], (), 0, []), METHOD([path_new], [xnjsmb_path_new], (STR(txt)), 1, [OBJ([path], [shape_t])], (([MOD], [xnjsmb_mb_rt_objs_mod]))), METHOD([stext_new], [xnjsmb_stext_new], @@ -44,7 +44,7 @@ (OBJ([evt], [event], [void])), 1, []), METHOD([no_more_event], [xnjsmb_no_more_event], (), 0, [])], - ((CTOR, ([_X_njs_MB_new], (SELF, STR(display_name), INT(width), INT(height)), 3)))dnl + ((CTOR, ([_njs_mb_new], (SELF, STR(display_name), INT(width), INT(height)), 3)))dnl ) dnl dnl @@ -57,7 +57,7 @@ dnl STRUCT([mb_rt_with_win], [njs_runtime_t], [], [], - ((CTOR, ([_X_njs_MB_new_with_win],dnl + ((CTOR, ([_njs_mb_new_with_win],dnl (SELF, OBJ([display], [mb_rt_display], [void]),dnl INT([window])),dnl 2)),dnl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/njs_mb_supp.c Tue Nov 30 03:57:36 2010 +0800 @@ -0,0 +1,317 @@ +// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- +// vim: sw=4:ts=8:sts=4 +/*! \brief Implement X11 backend for nodejs plugin. + * + * Since nodejs use libev to handle event loops, part of X11 backend + * code can not be used directly. The part of code should be rewrote. + * The part is about + */ +#include <stdio.h> +#include <string.h> +#include <ev.h> +#include "mb_tools.h" +#include <mb_backend.h> +#include "njs_mb_supp.h" + +#ifndef ASSERT +#define ASSERT(x) +#endif + +#define OK 0 +#define ERR -1 + + +/*! \defgroup njs_timer_man Timer manager for nodejs. + * @{ + */ +struct _njs_timer_timeout { + ev_timer tmwatcher; + mb_timer_cb_t cb; + mb_timeval_t *timeout; + void *data; +}; + +static int njs_timer_man_timeout(mb_timer_man_t *tm_man, + mb_timeval_t *tm_out, + mb_timer_cb_t cb, void *data); +static void njs_timer_man_remove(mb_timer_man_t *tm_man, int tm_hdl); +static mb_timer_man_t *njs_timer_man_new(void); +static void njs_timer_man_free(mb_timer_man_t *timer_man); + +static mb_timer_man_t njs_timer_man = { + njs_timer_man_timeout, + njs_timer_man_remove +}; + +static mb_timer_factory_t njs_timer_factory = { + njs_timer_man_new, + njs_timer_man_free +}; + +static void +njs_timer_man_cb(EV_P_ ev_timer *tmwatcher, int revent) { + struct _njs_timer_timeout *timer_timeout = + MEM2OBJ(tmwatcher, struct _njs_timer_timeout, tmwatcher); + mb_timeval_t now; + + get_now(&now); + timer_timeout->cb((int)timer_timeout, timer_timeout->timeout, &now, + timer_timeout->data); +} + +static int +njs_timer_man_timeout(mb_timer_man_t *tm_man, + mb_timeval_t *timeout, + mb_timer_cb_t cb, void *data) { + struct _njs_timer_timeout *timer_timeout; + mb_timeval_t now, timeout_diff; + ev_tstamp timeout_stamp; + + timer_timeout = O_ALLOC(struct _njs_timer_timeout); + if(timer_timeout == NULL) + return ERR; + + timer_timeout->cb = cb; + timer_timeout->timeout = timeout; + + get_now(&now); + + memcpy(&timeout_diff, timeout, sizeof(mb_timeval_t)); + MB_TIMEVAL_DIFF(&timeout_diff, &now); + timeout_stamp = (ev_tstamp)MB_TIMEVAL_SEC(&timeout_diff) + + (ev_tstamp)MB_TIMEVAL_USEC(&timeout_diff) / 1000000; + ev_timer_init(&timer_timeout->tmwatcher, njs_timer_man_cb, + timeout_stamp, 0); + ev_timer_start(&timer_timeout->tmwatcher); + + return (int)timer_timeout; +} + +static void +njs_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl) { + struct _njs_timer_timeout *timer_timeout = + (struct _njs_timer_timeout *)tm_hdl; + + ev_timer_stop(&timer_timeout->tmwatcher); + free(timer_timeout); +} + +static mb_timer_man_t * +njs_timer_man_new(void) { + return &njs_timer_man; +} + +static void +njs_timer_man_free(mb_timer_man_t *timer_man) { +} + +void +njs_mb_reg_timer_man(void) { + mb_reg_timer_factory(&njs_timer_factory); +} + +/* @} */ + + +/*! \defgroup njs_io_man IO manager for nodejs. + * @{ + */ +struct _njs_io_reg { + ev_io iowatcher; + int fd; + mb_IO_cb_t cb; + void *data; +}; + +static int njs_io_man_reg(struct _mb_IO_man *io_man, + int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data); +static void njs_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl); +static mb_IO_man_t *njs_io_man_new(void); +static void njs_io_man_free(mb_IO_man_t *io_man); + +static mb_IO_man_t njs_io_man = { + njs_io_man_reg, + njs_io_man_unreg +}; + +/*! \brief IO factory to integrate MadButterfly to event loop of nodejs. + */ +static mb_IO_factory_t njs_io_factory = { + njs_io_man_new, + njs_io_man_free +}; + +/*! \brief Bridge libev callback to IO manager callback. + */ +static void +njs_io_man_cb(EV_P_ ev_io *iowatcher, int revent) { + struct _njs_io_reg *io_reg = + MEM2OBJ(iowatcher, struct _njs_io_reg, iowatcher); + MB_IO_TYPE type; + + switch(revent & (EV_READ | EV_WRITE)) { + case EV_READ: + type = MB_IO_R; + break; + case EV_WRITE: + type = MB_IO_W; + break; + case EV_READ | EV_WRITE: + type = MB_IO_RW; + break; + } + + io_reg->cb((int)io_reg, io_reg->fd, type, io_reg->data); +} + +static int +njs_io_man_reg(struct _mb_IO_man *io_man, + int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data) { + int _type; + struct _njs_io_reg *io_reg; + + if(type == MB_IO_R) + _type = EV_READ; + else if(type == MB_IO_W) + _type = EV_WRITE; + else if(type == MB_IO_RW) + _type = EV_READ | EV_WRITE; + else + return ERR; + + io_reg = O_ALLOC(struct _njs_io_reg); + if(io_reg == NULL) + return ERR; + + io_reg->fd = fd; + io_reg->cb = cb; + io_reg->data = data; + + ev_io_init(&io_reg->iowatcher, njs_io_man_cb, fd, _type); + ev_io_start(&io_reg->iowatcher); + + return (int)io_reg; +} + +static void +njs_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl) { + struct _njs_io_reg *io_reg = (struct _njs_io_reg *)io_hdl; + + ev_io_stop(&io_reg->iowatcher); + free(io_reg); +} + +static mb_IO_man_t * +njs_io_man_new(void) { + return &njs_io_man; +} + +static void +njs_io_man_free(mb_IO_man_t *io_man) { +} + +/*! \brief Register an IO factory with MadButterfly backend. + */ +void +njs_mb_reg_IO_man(void) { + mb_reg_IO_factory(&njs_io_factory); +} + +/* @} */ + +/*! \brief Free njs_runtime_t. + */ +void +njs_mb_free(njs_runtime_t *rt) { + /*! + * TODO: Release all IO and timer request. + */ + mb_runtime_free(rt->mb_rt); + free(rt); +} + +/*! \brief Free njs_runtime_t. + */ +void +njs_mb_free_keep_win(njs_runtime_t *rt) { + /* + * TODO: Release all IO and timer request. + */ + mb_runtime_free_keep_win(rt->mb_rt); + free(rt); +} + +int +njs_mb_flush(njs_runtime_t *rt) { + mb_rt_t *mb_rt = rt->mb_rt; + int r; + + r = mb_runtime_flush(mb_rt); + return r; +} + +njs_runtime_t * +njs_mb_new(char *display_name, int w, int h) { + njs_runtime_t *rt; + mb_rt_t *mb_rt; + + rt = (njs_runtime_t *)malloc(sizeof(njs_runtime_t)); + ASSERT(rt != NULL); + + mb_rt = mb_runtime_new(display_name, w, h); + + rt->mb_rt = mb_rt; + + return rt; +} + +/*! \brief Create a njs_runtime_t for an existed window. + * + * The njs_runtime_t created by this function must be free by + * njs_mb_free_keep_win(). + */ +njs_runtime_t * +njs_mb_new_with_win(void *display, long win) { + njs_runtime_t *rt; + mb_rt_t *mb_rt; + + rt = (njs_runtime_t *)malloc(sizeof(njs_runtime_t)); + ASSERT(rt != NULL); + + mb_rt = mb_runtime_new_with_win((Display *)display, win); + + rt->mb_rt = mb_rt; + + return rt; +} + +/*! \brief Pass a X event to X runtime. + */ +void +njs_mb_handle_single_event(njs_runtime_t *rt, void *evt) { +#if 0 + void *mb_rt = rt->mb_rt; + extern void _X_MB_handle_single_event(void *rt, void *evt); + + _X_MB_handle_single_event(mb_rt, evt); +#endif +} + +/*! \brief Called at end of an iteration of event loop. + */ +void +njs_mb_no_more_event(njs_runtime_t *rt) { +#if 0 + mb_rt_t *mb_rt = rt->mb_rt; + extern void _X_MB_no_more_event(mb_rt_t *rt); + + _X_MB_no_more_event(mb_rt); +#endif +} + +/*! \brief Get X runtime that is backend of this njs runtime. + */ +mb_rt_t * +_njs_mb_get_runtime(njs_runtime_t *rt) { + return rt->mb_rt; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/njs_mb_supp.h Tue Nov 30 03:57:36 2010 +0800 @@ -0,0 +1,31 @@ +// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- +// vim: sw=4:ts=8:sts=4 +#ifndef __NJS_MB_SUPP_H_ +#define __NJS_MB_SUPP_H_ + +#include <ev.h> +#include <mb_backend.h> + +typedef struct _njs_runtime { + mb_rt_t *mb_rt; +} njs_runtime_t; + +extern void njs_mb_reg_timer_man(void); +extern void njs_mb_reg_IO_man(void); +/* extern void njs_mb_init_handle_connection(njs_runtime_t *rt); */ +extern void njs_mb_free(njs_runtime_t *rt); +extern njs_runtime_t *njs_mb_new(char *display_name, int w, int h); +extern void njs_mb_free_keep_win(njs_runtime_t *rt); +extern njs_runtime_t *njs_mb_new_with_win(void *display, long win); +extern int njs_mb_flush(njs_runtime_t *rt); +extern void njs_mb_handle_single_event(njs_runtime_t *rt, void *evt); +extern void njs_mb_no_more_event(njs_runtime_t *rt); +extern mb_rt_t *_njs_mb_get_runtime(njs_runtime_t *rt); + +#define njs_mb_kbevents(rt) mb_runtime_kbevents((rt)->mb_rt) +#define njs_mb_rdman(rt) mb_runtime_rdman((rt)->mb_rt) +#define njs_mb_timer_man(rt) mb_runtime_timer_man((rt)->mb_rt) +#define njs_mb_observer_factory(rt) mb_runtime_observer_factory((rt)->mb_rt) +#define njs_mb_img_ldr(rt) mb_runtime_img_ldr((rt)->mb_rt) + +#endif /* __NJS_MB_SUPP_H_ */
--- a/nodejs/paints.cc Tue Nov 30 03:57:14 2010 +0800 +++ b/nodejs/paints.cc Tue Nov 30 03:57:36 2010 +0800 @@ -195,7 +195,7 @@ paint_t *paint; redraw_man_t *rdman; - rdman = X_njs_MB_rdman(rt); + rdman = njs_mb_rdman(rt); paint = rdman_paint_color_new(rdman, r, g, b, a); if(paint == NULL) { *err = "can not allocate a paint_color_t"; @@ -211,7 +211,7 @@ paint_t *paint; redraw_man_t *rdman; - rdman = X_njs_MB_rdman(rt); + rdman = njs_mb_rdman(rt); paint = rdman_paint_image_new(rdman, img); if(paint == NULL) { *err = "can not allocate a paint_image_t"; @@ -228,7 +228,7 @@ paint_t *paint; redraw_man_t *rdman; - rdman = X_njs_MB_rdman(rt); + rdman = njs_mb_rdman(rt); paint = rdman_paint_linear_new(rdman, x1, y1, x2, y2); if(paint == NULL) { *err = "can not allocate a paint_linear_t"; @@ -245,7 +245,7 @@ paint_t *paint; redraw_man_t *rdman; - rdman = X_njs_MB_rdman(rt); + rdman = njs_mb_rdman(rt); paint = rdman_paint_radial_new(rdman, cx, cy, r); if(paint == NULL) { *err = "can not allocate a paint_radial_t";
--- a/nodejs/shapes.cc Tue Nov 30 03:57:14 2010 +0800 +++ b/nodejs/shapes.cc Tue Nov 30 03:57:36 2010 +0800 @@ -282,7 +282,7 @@ redraw_man_t *rdman; shape_t *sh; - rdman = X_njs_MB_rdman(rt); + rdman = njs_mb_rdman(rt); sh = rdman_shape_path_new(rdman, d); /* Code generator supposes that callee should free the memory */ free((void *)d); @@ -295,7 +295,7 @@ redraw_man_t *rdman; shape_t *sh; - rdman = X_njs_MB_rdman(rt); + rdman = njs_mb_rdman(rt); sh = rdman_shape_stext_new(rdman, txt, x, y); /* Code generator supposes that callee should free the memory */ free((void *)txt); @@ -308,7 +308,7 @@ redraw_man_t *rdman; shape_t *sh; - rdman = X_njs_MB_rdman(rt); + rdman = njs_mb_rdman(rt); sh = rdman_shape_image_new(rdman, x, y, w, h); return sh; @@ -320,7 +320,7 @@ redraw_man_t *rdman; shape_t *sh; - rdman = X_njs_MB_rdman(rt); + rdman = njs_mb_rdman(rt); sh = rdman_shape_rect_new(rdman, x, y, w, h, rx, ry); if(sh == NULL) { *err = "Can not create a sh_rect_t";
--- a/nodejs/wscript Tue Nov 30 03:57:14 2010 +0800 +++ b/nodejs/wscript Tue Nov 30 03:57:36 2010 +0800 @@ -30,7 +30,7 @@ obj = conf.new_task_gen('cxx', 'shlib', 'node_addon') obj.target = 'mbfly' obj.source = 'font.cc image_ldr.cc' - obj.add_objects = 'X_supp_njs.o observer.o coord.o mbfly_njs.o ' + \ + obj.add_objects = 'njs_mb_supp.o observer.o coord.o mbfly_njs.o ' + \ 'shapes.o paints.o' obj.staticlib = 'mbfly' @@ -42,6 +42,6 @@ pass obj = conf.new_task_gen('cc', 'shlib', 'node_addon') - obj.target = 'X_supp_njs.o' - obj.source = 'X_supp_njs.c' + obj.target = 'njs_mb_supp.o' + obj.source = 'njs_mb_supp.c' pass
--- a/src/X_supp.c Tue Nov 30 03:57:14 2010 +0800 +++ b/src/X_supp.c Tue Nov 30 03:57:36 2010 +0800 @@ -39,7 +39,7 @@ int ksym_per_code; KeySym *syms; subject_t *kbevents; - ob_factory_t *ob_factory; + observer_factory_t *observer_factory; }; /* @} */ @@ -286,7 +286,7 @@ static int X_kb_init(X_kb_info_t *kbinfo, Display *display, redraw_man_t *rdman) { int n_syms; - ob_factory_t *factory; + observer_factory_t *factory; int r; r = XDisplayKeycodes(display, @@ -302,12 +302,12 @@ if(kbinfo->syms == NULL) return ERR; - factory = rdman_get_ob_factory(rdman); + factory = rdman_get_observer_factory(rdman); kbinfo->kbevents = subject_new(factory, kbinfo, OBJT_KB); if(kbinfo->kbevents == NULL) return ERR; - /*! \todo Make sure ob_factory is still need. */ - kbinfo->ob_factory = factory; + /*! \todo Make sure observer_factory is still need. */ + kbinfo->observer_factory = factory; return OK; } @@ -1011,12 +1011,12 @@ return xmb_rt->timer_man; } -static ob_factory_t * -_x_supp_ob_factory(mb_rt_t *rt) { +static observer_factory_t * +_x_supp_observer_factory(mb_rt_t *rt) { X_supp_runtime_t *xmb_rt = (X_supp_runtime_t *) rt; - ob_factory_t *factory; + observer_factory_t *factory; - factory = rdman_get_ob_factory(xmb_rt->rdman); + factory = rdman_get_observer_factory(xmb_rt->rdman); return factory; } @@ -1086,7 +1086,7 @@ _x_supp_kbevents, _x_supp_rdman, _x_supp_timer_man, - _x_supp_ob_factory, + _x_supp_observer_factory, _x_supp_img_ldr, _x_supp_reg_IO_factory,
--- a/src/animate.c Tue Nov 30 03:57:14 2010 +0800 +++ b/src/animate.c Tue Nov 30 03:57:36 2010 +0800 @@ -115,7 +115,7 @@ mb_progm_t *mb_progm_new(int max_words, redraw_man_t *rdman) { mb_progm_t *progm; #ifndef UNITTEST - ob_factory_t *factory; + observer_factory_t *factory; #endif /* UNITTEST */ int i; @@ -127,7 +127,7 @@ progm->rdman = rdman; #ifndef UNITTEST - factory = rdman_get_ob_factory(rdman); + factory = rdman_get_observer_factory(rdman); progm->complete = subject_new(factory, progm, OBJT_PROGM); if(progm->complete == NULL) { free(progm);
--- a/src/dfb_supp.c Tue Nov 30 03:57:14 2010 +0800 +++ b/src/dfb_supp.c Tue Nov 30 03:57:36 2010 +0800 @@ -24,7 +24,7 @@ int keycode_min, keycode_max; int ksym_per_code; subject_t *kbevents; - ob_factory_t *ob_factory; + observer_factory_t *observer_factory; }; /* @} */ @@ -458,11 +458,11 @@ return xmb_rt->tman; } -ob_factory_t *X_MB_ob_factory(void *rt) { +observer_factory_t *X_MB_observer_factory(void *rt) { X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt; - ob_factory_t *factory; + observer_factory_t *factory; - factory = rdman_get_ob_factory(xmb_rt->rdman); + factory = rdman_get_observer_factory(xmb_rt->rdman); return factory; } @@ -525,7 +525,7 @@ X_MB_kbevents, X_MB_rdman, X_MB_tman, - X_MB_ob_factory, + X_MB_observer_factory, X_MB_img_ldr };
--- a/src/observer.c Tue Nov 30 03:57:14 2010 +0800 +++ b/src/observer.c Tue Nov 30 03:57:36 2010 +0800 @@ -9,7 +9,7 @@ #define ASSERT(x) #endif -subject_t *subject_new(ob_factory_t *factory, void *obj, int obj_type) { +subject_t *subject_new(observer_factory_t *factory, void *obj, int obj_type) { subject_t *subject; subject = factory->subject_alloc(factory); @@ -28,10 +28,10 @@ } /*! - * \todo Keep ob_factory following subject objects. + * \todo Keep observer_factory following subject objects. */ void subject_free(subject_t *subject) { - ob_factory_t *factory = subject->factory; + observer_factory_t *factory = subject->factory; observer_t *observer; monitor_event_t mevt; @@ -60,7 +60,7 @@ void subject_notify(subject_t *subject, event_t *evt) { - ob_factory_t *factory = subject->factory; + observer_factory_t *factory = subject->factory; observer_t *observer; subject_t *old_subject; int stop_propagate = 0; @@ -114,7 +114,7 @@ */ observer_t *subject_add_event_observer(subject_t *subject, int type, evt_handler hdr, void *arg) { - ob_factory_t *factory = subject->factory; + observer_factory_t *factory = subject->factory; observer_t *observer; monitor_event_t mevt; @@ -141,7 +141,7 @@ */ observer_t *subject_add_event_observer_head(subject_t *subject, int type, evt_handler hdr, void *arg) { - ob_factory_t *factory = subject->factory; + observer_factory_t *factory = subject->factory; observer_t *observer; monitor_event_t mevt; @@ -166,7 +166,7 @@ void subject_remove_observer(subject_t *subject, observer_t *observer) { - ob_factory_t *factory = subject->factory; + observer_factory_t *factory = subject->factory; monitor_event_t mevt; STAILQ_REMOVE(subject->observers, observer_t, next, observer); @@ -186,34 +186,36 @@ #include <CUnit/Basic.h> #include <stdlib.h> -static subject_t *test_subject_alloc(ob_factory_t *factory) { +static subject_t *test_subject_alloc(observer_factory_t *factory) { subject_t *subject; subject = (subject_t *)malloc(sizeof(subject_t)); return subject; } -static void test_subject_free(ob_factory_t *factory, subject_t *subject) { +static void +test_subject_free(observer_factory_t *factory, subject_t *subject) { free(subject); } -static observer_t *test_observer_alloc(ob_factory_t *factory) { +static observer_t *test_observer_alloc(observer_factory_t *factory) { observer_t *observer; observer = (observer_t *)malloc(sizeof(observer_t)); return observer; } -static void test_observer_free(ob_factory_t *factory, observer_t *observer) { +static void +test_observer_free(observer_factory_t *factory, observer_t *observer) { free(observer); } -static subject_t *test_get_parent_subject(ob_factory_t *factory, +static subject_t *test_get_parent_subject(observer_factory_t *factory, subject_t *subject) { return NULL; } -static ob_factory_t test_factory = { +static observer_factory_t test_factory = { test_subject_alloc, test_subject_free, test_observer_alloc,
--- a/src/redraw_man.c Tue Nov 30 03:57:14 2010 +0800 +++ b/src/redraw_man.c Tue Nov 30 03:57:36 2010 +0800 @@ -304,6 +304,38 @@ #define ASSERT(x) #endif +/* + * Conitions for coords. + */ +#define coord_is_cached(co) ((co)->flags & COF_OWN_CANVAS) +#define coord_is_always_cached(co) ((co)->flags & COF_ALWAYS_CACHE) +#define coord_is_fast_cached(co) ((co)->flags & COF_FAST_MASK) +#define coord_is_precise_cached(co) ((co)->flags & COF_PRECISE_MASK) +#define coord_is_zeroing(co) ((co)->flags & COF_MUST_ZEROING) +#define coord_set_zeroing(co) \ + do { (co)->flags |= COF_MUST_ZEROING; } while(0) +#define coord_clear_zeroing(co) \ + do { (co)->flags &= ~COF_MUST_ZEROING; } while(0) +#define coord_set_flags(co, _flags) \ + do { (co)->flags |= (_flags); } while(0) +#define coord_get_parent(co) ((co)->parent) +#define coord_get_flags(co, _flags) ((co)->flags & (_flags)) +#define coord_clear_flags(co, _flags) \ + do { (co)->flags &= ~(_flags); } while(0) + +#define coord_get_pcache_area(coord) ((coord)->canvas_info->pcache_cur_area) +#define coord_get_pcache_last_area(coord) \ + ((coord)->canvas_info->pcache_last_area) +#define coord_get_cached(coord) ((coord)->canvas_info->owner) +#define _coord_get_dirty_areas(coord) (&(coord)->canvas_info->dirty_areas) +#define _coord_get_aggr_dirty_areas(coord) \ + ((coord)->canvas_info->aggr_dirty_areas) +#define coord_get_2pdev(coord) ((coord)->canvas_info->cache_2_pdev) +#define coord_get_2pdev_rev(coord) ((coord)->canvas_info->cache_2_pdev_rev) +#define coord_get_aggr2pdev(coord) ((coord)->canvas_info->aggr_2_pdev) +#define coord_get_aggr2pdev_rev(coord) ((coord)->canvas_info->aggr_2_pdev_rev) + + /* NOTE: bounding box should also consider width of stroke. */ @@ -338,12 +370,14 @@ extern void sh_dummy_fill(shape_t *, mbe_t *); #endif /* UNITTEST */ -static subject_t *ob_subject_alloc(ob_factory_t *factory); -static void ob_subject_free(ob_factory_t *factory, subject_t *subject); -static observer_t *ob_observer_alloc(ob_factory_t *factory); -static void ob_observer_free(ob_factory_t *factory, observer_t *observer); -static subject_t *ob_get_parent_subject(ob_factory_t *factory, - subject_t *cur_subject); +static subject_t *observer_subject_alloc(observer_factory_t *factory); +static void observer_subject_free(observer_factory_t *factory, + subject_t *subject); +static observer_t *observer_observer_alloc(observer_factory_t *factory); +static void observer_observer_free(observer_factory_t *factory, + observer_t *observer); +static subject_t *observer_get_parent_subject(observer_factory_t *factory, + subject_t *cur_subject); /* Functions for children. */ #define FORCHILDREN(coord, child) \ for((child) = STAILQ_HEAD((coord)->children); \ @@ -678,16 +712,16 @@ rdman->paint_color_pool && rdman->coord_canvas_pool)) goto err; - rdman->ob_factory.subject_alloc = ob_subject_alloc; - rdman->ob_factory.subject_free = ob_subject_free; - rdman->ob_factory.observer_alloc = ob_observer_alloc; - rdman->ob_factory.observer_free = ob_observer_free; - rdman->ob_factory.get_parent_subject = ob_get_parent_subject; + rdman->observer_factory.subject_alloc = observer_subject_alloc; + rdman->observer_factory.subject_free = observer_subject_free; + rdman->observer_factory.observer_alloc = observer_observer_alloc; + rdman->observer_factory.observer_free = observer_observer_free; + rdman->observer_factory.get_parent_subject = observer_get_parent_subject; rdman->redraw = - subject_new(&rdman->ob_factory, rdman, OBJT_RDMAN); + subject_new(&rdman->observer_factory, rdman, OBJT_RDMAN); rdman->addrm_monitor = - subject_new(&rdman->ob_factory, rdman, OBJT_RDMAN); + subject_new(&rdman->observer_factory, rdman, OBJT_RDMAN); if(!(rdman->redraw && rdman->addrm_monitor)) goto err; @@ -704,7 +738,7 @@ rdman->n_coords = 1; coord_init(rdman->root_coord, NULL); mb_prop_store_init(&rdman->root_coord->obj.props, rdman->pent_pool); - rdman->root_coord->mouse_event = subject_new(&rdman->ob_factory, + rdman->root_coord->mouse_event = subject_new(&rdman->observer_factory, rdman->root_coord, OBJT_COORD); coord_set_flags(rdman->root_coord, COF_OWN_CANVAS); @@ -854,7 +888,7 @@ return ERR; geo_init(geo); - geo->mouse_event = subject_new(&rdman->ob_factory, geo, OBJT_GEO); + geo->mouse_event = subject_new(&rdman->observer_factory, geo, OBJT_GEO); subject_set_monitor(geo->mouse_event, rdman->addrm_monitor); geo_attach_coord(geo, coord); @@ -1002,7 +1036,7 @@ coord_init(coord, parent); mb_prop_store_init(&coord->obj.props, rdman->pent_pool); - coord->mouse_event = subject_new(&rdman->ob_factory, + coord->mouse_event = subject_new(&rdman->observer_factory, coord, OBJT_COORD); subject_set_monitor(coord->mouse_event, rdman->addrm_monitor); @@ -2587,48 +2621,51 @@ * Implment factory and strategy functions for observers and subjects. * @{ */ -static subject_t *ob_subject_alloc(ob_factory_t *factory) { +static subject_t *observer_subject_alloc(observer_factory_t *factory) { redraw_man_t *rdman; subject_t *subject; - rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); + rdman = MEM2OBJ(factory, redraw_man_t, observer_factory); subject = elmpool_elm_alloc(rdman->subject_pool); return subject; } -static void ob_subject_free(ob_factory_t *factory, subject_t *subject) { +static void +observer_subject_free(observer_factory_t *factory, subject_t *subject) { redraw_man_t *rdman; - rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); + rdman = MEM2OBJ(factory, redraw_man_t, observer_factory); elmpool_elm_free(rdman->subject_pool, subject); } -static observer_t *ob_observer_alloc(ob_factory_t *factory) { +static observer_t *observer_observer_alloc(observer_factory_t *factory) { redraw_man_t *rdman; observer_t *observer; - rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); + rdman = MEM2OBJ(factory, redraw_man_t, observer_factory); observer = elmpool_elm_alloc(rdman->observer_pool); return observer; } -static void ob_observer_free(ob_factory_t *factory, observer_t *observer) { +static void +observer_observer_free(observer_factory_t *factory, observer_t *observer) { redraw_man_t *rdman; - rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); + rdman = MEM2OBJ(factory, redraw_man_t, observer_factory); elmpool_elm_free(rdman->observer_pool, observer); } -static subject_t *ob_get_parent_subject(ob_factory_t *factory, - subject_t *cur_subject) { +static subject_t * +observer_get_parent_subject(observer_factory_t *factory, + subject_t *cur_subject) { redraw_man_t *rdman; coord_t *coord, *parent_coord; geo_t *geo; subject_t *parent; - rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); + rdman = MEM2OBJ(factory, redraw_man_t, observer_factory); switch(cur_subject->obj_type) { case OBJT_GEO: geo = (geo_t *)cur_subject->obj; @@ -2708,7 +2745,7 @@ dummy->draw_cnt = 0; dummy->shape.free = sh_dummy_free; - rdman_shape_man(rdman, (shape_t *)dummy); + rdman_man_shape(rdman, (shape_t *)dummy); return (shape_t *)dummy; }
--- a/src/shape_image.c Tue Nov 30 03:57:14 2010 +0800 +++ b/src/shape_image.c Tue Nov 30 03:57:36 2010 +0800 @@ -87,7 +87,7 @@ img->w = w; img->h = h; - rdman_shape_man(rdman, (shape_t *)img); + rdman_man_shape(rdman, (shape_t *)img); return (shape_t *)img; }
--- a/src/shape_path.c Tue Nov 30 03:57:14 2010 +0800 +++ b/src/shape_path.c Tue Nov 30 03:57:36 2010 +0800 @@ -49,8 +49,8 @@ #define PI 3.1415926535897931 #ifdef UNITTEST -#undef rdman_shape_man -#define rdman_shape_man(x, y) +#undef rdman_man_shape +#define rdman_man_shape(x, y) #undef elmpool_elm_alloc #define elmpool_elm_alloc(pool) _elmpool_elm_alloc(pool) @@ -847,7 +847,7 @@ path->shape.free = sh_path_free; path->rdman = rdman; - rdman_shape_man(rdman, (shape_t *)path); + rdman_man_shape(rdman, (shape_t *)path); return (shape_t *)path; } @@ -888,7 +888,7 @@ path->shape.free = sh_path_free; path->rdman = rdman; - rdman_shape_man(rdman, (shape_t *)path); + rdman_man_shape(rdman, (shape_t *)path); return (shape_t *)path; }
--- a/src/shape_rect.c Tue Nov 30 03:57:14 2010 +0800 +++ b/src/shape_rect.c Tue Nov 30 03:57:36 2010 +0800 @@ -45,7 +45,7 @@ rect->shape.free = sh_rect_free; rect->rdman = rdman; - rdman_shape_man(rdman, (shape_t *)rect); + rdman_man_shape(rdman, (shape_t *)rect); return (shape_t *)rect; }
--- a/src/shape_stext.c Tue Nov 30 03:57:14 2010 +0800 +++ b/src/shape_stext.c Tue Nov 30 03:57:36 2010 +0800 @@ -36,8 +36,8 @@ #undef mb_obj_init #define mb_obj_init(o, t) -#undef rdman_shape_man -#define rdman_shape_man(rdman, sh) +#undef rdman_man_shape +#define rdman_man_shape(rdman, sh) #define rdman_shape_stext_new ut_rdman_shape_stext_new #define sh_stext_transform ut_sh_stext_transform @@ -306,7 +306,7 @@ txt_o->shape.free = _rdman_shape_stext_free; - rdman_shape_man(rdman, (shape_t *)txt_o); + rdman_man_shape(rdman, (shape_t *)txt_o); return (shape_t *)txt_o; }
--- a/src/shape_text.c Tue Nov 30 03:57:14 2010 +0800 +++ b/src/shape_text.c Tue Nov 30 03:57:36 2010 +0800 @@ -68,7 +68,7 @@ text->align = TEXTALIGN_START; text->w = text->h = 0; - rdman_shape_man(rdman, (shape_t *)text); + rdman_man_shape(rdman, (shape_t *)text); return (shape_t *)text; }
--- a/src/sprite.c Tue Nov 30 03:57:14 2010 +0800 +++ b/src/sprite.c Tue Nov 30 03:57:36 2010 +0800 @@ -3,15 +3,11 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "mb_graph_engine.h" #include <dlfcn.h> #include <sys/stat.h> #include "mb_types.h" -#include "mb_shapes.h" -#include "mb_tools.h" #include "mb_redraw_man.h" -#include "mb_observer.h" -#include "mb_prop.h" +#include "mb_sprite.h" #define ASSERT(x) #define OK 0