From fbfa075f085ea925e6754577bbb6855913760545 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 5 Mar 2008 00:58:24 -0500 Subject: [PATCH] make rendering much faster --- dcompmgr.c | 10 +++++++--- plugin.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ plugin.h | 19 +++++++++++++++++++ render.c | 50 +++++++++++++++++++++++++------------------------- render.h | 2 +- screen.c | 27 +++++++++++++-------------- screen.h | 11 ++++++----- window.c | 33 ++++++++++++++++++++------------- window.h | 9 +++++---- 9 files changed, 144 insertions(+), 65 deletions(-) create mode 100644 plugin.c create mode 100644 plugin.h diff --git a/dcompmgr.c b/dcompmgr.c index a0a4694..d2cfc92 100644 --- a/dcompmgr.c +++ b/dcompmgr.c @@ -132,8 +132,10 @@ event(d_display_t *dpy) window_configure(w, cev->x, cev->y, cev->width, cev->height, cev->border_width); - if (window_is_mapped(w)) - sc->window_reconfigure(w); + if (window_is_mapped(w) && + (width != cev->width || + height != cev->height || bwidth != cev->border_width)) + sc->window_resize(w); } above = screen_find_window(sc, cev->above_sibling); screen_stacking_move_above(sc, w, above); @@ -250,10 +252,12 @@ setup_functions(d_display_t *dpy) for (it = list_top(dpy->screens); it; it = it->next) { d_screen_t *sc = it->data; + int id; screen_setup_default_functions(sc); /* these can be plugins.. */ - render_init(sc); + id = 1; + render_init(sc, id++); } } diff --git a/plugin.c b/plugin.c new file mode 100644 index 0000000..f3935ad --- /dev/null +++ b/plugin.c @@ -0,0 +1,48 @@ +#include "plugin.h" +#include "list.h" +#include + +d_plugin_data_t* +plugin_data_new(int id, void *data) +{ + d_plugin_data_t *pd = malloc(sizeof(d_plugin_data_t)); + pd->id = id; + pd->data = data; + return pd; +} + +void +plugin_data_free(d_plugin_data_t *pd) +{ + if (pd) free(pd); +} + +void +plugin_data_add(d_list_t *list, int id, void *data) +{ + d_plugin_data_t *pd; + pd = plugin_data_new(id, data); + list_append(list, pd); +} + +void* +plugin_data_find(d_list_t *list, int id) +{ + d_list_it_t *it; + for (it = list_top(list); it; it = it->next) { + d_plugin_data_t *pd = it->data; + if (pd->id == id) return pd->data; + } + return NULL; +} + +void +plugin_data_remove(d_list_t *list, int id) +{ + d_list_it_t *it, *next; + for (it = list_top(list); it; it = next) { + d_plugin_data_t *pd = it->data; + next = it->next; + if (pd->id == id) list_delete_link(list, it); + } +} diff --git a/plugin.h b/plugin.h new file mode 100644 index 0000000..3f0abd3 --- /dev/null +++ b/plugin.h @@ -0,0 +1,19 @@ +#ifndef dc__plugin_h +#define dc__plugin_h + +struct d_list; + +typedef struct d_plugin_data { + int id; + void *data; +} d_plugin_data_t; + +d_plugin_data_t* plugin_data_new(int id, void *data); +void plugin_data_free(d_plugin_data_t *pd); + +void plugin_data_add(struct d_list *list, int id, void *data); +void plugin_data_remove(struct d_list *list, int it); +void* plugin_data_find(struct d_list *list, int id); + + +#endif diff --git a/render.c b/render.c index 2643be0..fbc4070 100644 --- a/render.c +++ b/render.c @@ -7,13 +7,13 @@ #include #include -#define PLUGIN_NAME "render" +static int plugin_id; typedef struct { void (*screen_paint)(d_screen_t *sc); void (*window_show)(d_window_t *w); void (*window_hide)(d_window_t *w); - void (*window_reconfigure)(d_window_t *w); + void (*window_resize)(d_window_t *w); xcb_render_query_pict_formats_reply_t *pict_formats; xcb_render_picture_t overlay_picture; @@ -28,7 +28,7 @@ typedef struct { static void render_screen_paint(d_screen_t *sc); static void paint_root(d_screen_t *sc, data_t *d); -static void paint_window(d_window_t *window); +static void paint_window(d_window_t *window, data_t *d); static void render_update_picture(d_window_t *w, data_t *d, window_data_t *wd, gboolean children); static void render_free_picture(d_window_t *w, window_data_t *wd); @@ -40,26 +40,28 @@ static xcb_render_picture_t solid_picture(d_screen_t *sc, static void render_window_show(d_window_t *window); static void render_window_hide(d_window_t *window); -static void render_window_reconfigure(d_window_t *window); +static void render_window_resize(d_window_t *window); void -render_init(d_screen_t *sc) +render_init(d_screen_t *sc, int id) { xcb_render_query_pict_formats_cookie_t ck; xcb_render_pictformat_t format; xcb_pixmap_t px; + plugin_id = id; + data_t *d = malloc(sizeof(data_t)); d->screen_paint = sc->screen_paint; d->window_show = sc->window_show; d->window_hide = sc->window_hide; - d->window_reconfigure = sc->window_reconfigure; - screen_add_plugin_data(sc, PLUGIN_NAME, d); + d->window_resize = sc->window_resize; + screen_add_plugin_data(sc, plugin_id, d); sc->screen_paint = render_screen_paint; sc->window_show = render_window_show; sc->window_hide = render_window_hide; - sc->window_reconfigure = render_window_reconfigure; + sc->window_resize = render_window_resize; ck = xcb_render_query_pict_formats_unchecked(sc->dpy->conn); d->pict_formats = xcb_render_query_pict_formats_reply(sc->dpy->conn, ck, @@ -88,7 +90,7 @@ render_init(d_screen_t *sc) void render_free(d_screen_t *sc) { - data_t *d = screen_find_plugin_data(sc, PLUGIN_NAME); + data_t *d = screen_find_plugin_data(sc, plugin_id); free(d->pict_formats); xcb_render_free_picture(sc->dpy->conn, d->solid_bg); xcb_render_free_picture(sc->dpy->conn, d->overlay_picture); @@ -109,19 +111,19 @@ render_window_show(d_window_t *w) data_t *d; window_data_t *wd; - d = screen_find_plugin_data(w->sc, PLUGIN_NAME); + d = screen_find_plugin_data(w->sc, plugin_id); /* pass it on */ d->window_show(w); - wd = window_find_plugin_data(w, PLUGIN_NAME); + wd = window_find_plugin_data(w, plugin_id); if (wd) render_window_free(w, wd); wd = malloc(sizeof(window_data_t)); wd->picture = XCB_NONE; wd->ck_picture.sequence = 0; - window_add_plugin_data(w, PLUGIN_NAME, wd); + window_add_plugin_data(w, plugin_id, wd); window_ref(w); } @@ -132,11 +134,11 @@ render_window_hide(d_window_t *w) data_t *d; window_data_t *wd; - d = screen_find_plugin_data(w->sc, PLUGIN_NAME); - wd = window_find_plugin_data(w, PLUGIN_NAME); + d = screen_find_plugin_data(w->sc, plugin_id); + wd = window_find_plugin_data(w, plugin_id); if (wd) { render_window_free(w, wd); - window_remove_plugin_data(w, PLUGIN_NAME); + window_remove_plugin_data(w, plugin_id); } window_unref(w); @@ -243,23 +245,23 @@ render_update_picture(d_window_t *w, data_t *d, window_data_t *wd, } static void -render_window_reconfigure(d_window_t *w) +render_window_resize(d_window_t *w) { data_t *d; window_data_t *wd; - d = screen_find_plugin_data(w->sc, PLUGIN_NAME); - wd = window_find_plugin_data(w, PLUGIN_NAME); + d = screen_find_plugin_data(w->sc, plugin_id); + wd = window_find_plugin_data(w, plugin_id); render_free_picture(w, wd); /* pass it on */ - d->window_reconfigure(w); + d->window_resize(w); } static void render_screen_paint(d_screen_t *sc) { - data_t *d = screen_find_plugin_data(sc, PLUGIN_NAME); + data_t *d = screen_find_plugin_data(sc, plugin_id); d_list_it_t *it; //printf("-- painting --\n"); @@ -268,7 +270,7 @@ render_screen_paint(d_screen_t *sc) for (it = list_bottom(sc->stacking); it; it = it->prev) { d_window_t *w = it->data; if (!window_is_input_only(w) && window_is_mapped(w)) - paint_window(w); + paint_window(w, d); } #endif @@ -302,15 +304,13 @@ paint_root(d_screen_t *sc, data_t *d) } static void -paint_window(d_window_t *w) +paint_window(d_window_t *w, data_t *d) { - data_t *d; window_data_t *wd; xcb_render_picture_t pict; int x, y, width, height, bwidth; - d = screen_find_plugin_data(w->sc, PLUGIN_NAME); - wd = window_find_plugin_data(w, PLUGIN_NAME); + wd = window_find_plugin_data(w, plugin_id); if (!wd->picture) render_update_picture(w, d, wd, TRUE); diff --git a/render.h b/render.h index 3ea2ad7..09a0c6e 100644 --- a/render.h +++ b/render.h @@ -3,7 +3,7 @@ struct d_screen; -void render_init(struct d_screen *sc); +void render_init(struct d_screen *sc, int id); void render_free(struct d_screen *sc); #endif diff --git a/screen.c b/screen.c index 8c0ea58..b800817 100644 --- a/screen.c +++ b/screen.c @@ -1,5 +1,6 @@ #include "screen.h" #include "display.h" +#include "plugin.h" #include "list.h" #include "time.h" #include "window.h" @@ -45,9 +46,7 @@ screen_new(struct d_display *dpy, int num, xcb_screen_t *xcb) sc->winhash = g_hash_table_new((GHashFunc)xcb_window_hash, (GEqualFunc)xcb_window_equal); sc->stacking = list_new(); - sc->plugin_data = g_hash_table_new_full((GHashFunc)g_str_hash, - (GEqualFunc)g_str_equal, - g_free, NULL); + sc->plugin_data = list_new(); return sc; } @@ -64,7 +63,7 @@ screen_unref(d_screen_t *sc) if (sc && --sc->ref == 0) { g_hash_table_unref(sc->winhash); list_unref(sc->stacking); - g_hash_table_unref(sc->plugin_data); + list_unref(sc->plugin_data); free(sc); } } @@ -311,8 +310,8 @@ static void screen_set_next_repaint(d_screen_t *sc) { gettimeofday(&sc->next_repaint, NULL); - /* add time for the refresh rate (60 hz) */ - time_add(&sc->next_repaint, 1000000/60); + /* add time for the refresh rate (30 hz) */ + time_add(&sc->next_repaint, 1000000/30); sc->need_repaint = FALSE; } @@ -323,26 +322,26 @@ screen_setup_default_functions(d_screen_t *sc) sc->window_show = window_show; sc->window_hide = window_hide; sc->window_become_zombie = window_become_zombie; - sc->window_reconfigure = window_reconfigure; + sc->window_move = window_move; + sc->window_resize = window_resize; } void -screen_add_plugin_data(d_screen_t *sc, const char *key, void *data) +screen_add_plugin_data(d_screen_t *sc, int id, void *data) { - char *skey = g_strdup(key); - g_hash_table_replace(sc->plugin_data, skey, data); + plugin_data_add(sc->plugin_data, id, data); } void* -screen_find_plugin_data(d_screen_t *sc, const char *key) +screen_find_plugin_data(d_screen_t *sc, int id) { - return g_hash_table_lookup(sc->plugin_data, key); + return plugin_data_find(sc->plugin_data, id); } void -screen_remove_plugin_data(d_screen_t *sc, const char *key) +screen_remove_plugin_data(d_screen_t *sc, int id) { - g_hash_table_remove(sc->plugin_data, key); + plugin_data_remove(sc->plugin_data, id); } void screen_refresh(d_screen_t *sc) diff --git a/screen.h b/screen.h index 2060c19..5067a80 100644 --- a/screen.h +++ b/screen.h @@ -26,13 +26,14 @@ typedef struct d_screen { GHashTable *winhash; struct d_list *stacking; - GHashTable *plugin_data; + struct d_list *plugin_data; void (*screen_paint)(struct d_screen *sc); void (*window_show)(struct d_window *w); void (*window_hide)(struct d_window *w); void (*window_become_zombie)(struct d_window *w); - void (*window_reconfigure)(struct d_window *w); + void (*window_move)(struct d_window *w); + void (*window_resize)(struct d_window *w); } d_screen_t; d_screen_t* screen_new(struct d_display *dpy, int num, xcb_screen_t *xcb); @@ -57,9 +58,9 @@ void screen_stacking_move_above(d_screen_t *sc, struct d_window *w, void screen_setup_default_functions(d_screen_t *sc); -void screen_add_plugin_data(d_screen_t *sc, const char *key, void *data); -void* screen_find_plugin_data(d_screen_t *sc, const char *key); -void screen_remove_plugin_data(d_screen_t *sc, const char *key); +void screen_add_plugin_data(d_screen_t *sc, int id, void *data); +void* screen_find_plugin_data(d_screen_t *sc, int id); +void screen_remove_plugin_data(d_screen_t *sc, int id); void screen_refresh(d_screen_t *sc); diff --git a/window.c b/window.c index d76aec7..593c9f4 100644 --- a/window.c +++ b/window.c @@ -1,5 +1,7 @@ #include "window.h" #include "screen.h" +#include "plugin.h" +#include "list.h" #include "display.h" #include #include @@ -22,9 +24,11 @@ typedef struct { xcb_visualid_t visual; xcb_pixmap_t pixmap; + double opacity; + gboolean zombie; - GHashTable *plugin_data; + d_list_t *plugin_data; xcb_damage_damage_t damage; @@ -56,9 +60,7 @@ window_new(xcb_window_t id, struct d_screen *sc) w->ck_get_pixmap.sequence = 0; - w->plugin_data = g_hash_table_new_full((GHashFunc)g_str_hash, - (GEqualFunc)g_str_equal, - g_free, NULL); + w->plugin_data = list_new(); //printf("new window 0x%x\n", w->id); @@ -88,7 +90,7 @@ window_unref(d_window_t *pubw) w->pixmap = XCB_NONE; } - g_hash_table_unref(w->plugin_data); + list_unref(w->plugin_data); free(w); } } @@ -291,31 +293,36 @@ window_configure(d_window_t *pubw, int x, int y, int width, int height, } void -window_reconfigure(d_window_t *w) +window_move(d_window_t *w) +{ + (void)w; +} + +void +window_resize(d_window_t *w) { window_update_pixmap((d_window_priv_t*)w); } void -window_add_plugin_data(d_window_t *pubw, const char *key, void *data) +window_add_plugin_data(d_window_t *pubw, int id, void *data) { d_window_priv_t *w = (d_window_priv_t*)pubw; - char *skey = g_strdup(key); - g_hash_table_replace(w->plugin_data, skey, data); + plugin_data_add(w->plugin_data, id, data); } void* -window_find_plugin_data(d_window_t *pubw, const char *key) +window_find_plugin_data(d_window_t *pubw, int id) { d_window_priv_t *w = (d_window_priv_t*)pubw; - return g_hash_table_lookup(w->plugin_data, key); + return plugin_data_find(w->plugin_data, id); } void -window_remove_plugin_data(d_window_t *pubw, const char *key) +window_remove_plugin_data(d_window_t *pubw, int id) { d_window_priv_t *w = (d_window_priv_t*)pubw; - g_hash_table_remove(w->plugin_data, key); + plugin_data_remove(w->plugin_data, id); } void diff --git a/window.h b/window.h index 6015b99..23cf5d9 100644 --- a/window.h +++ b/window.h @@ -23,7 +23,8 @@ void window_become_zombie(d_window_t *w); void window_configure(d_window_t *w, int x, int y, int width, int height, int border_width); -void window_reconfigure(d_window_t *w); +void window_move(d_window_t *w); +void window_resize(d_window_t *w); gboolean window_is_zombie(d_window_t *w); gboolean window_is_input_only(d_window_t *w); @@ -35,9 +36,9 @@ void window_get_area(d_window_t *pubw, int *x, int *y, int *width, int *height, xcb_pixmap_t window_get_pixmap(d_window_t *w); xcb_visualid_t window_get_visual(d_window_t *w); -void window_add_plugin_data(d_window_t *w, const char *key, void *data); -void* window_find_plugin_data(d_window_t *w, const char *key); -void window_remove_plugin_data(d_window_t *w, const char *key); +void window_add_plugin_data(d_window_t *w, int id, void *data); +void* window_find_plugin_data(d_window_t *w, int id); +void window_remove_plugin_data(d_window_t *w, int it); void window_create_damage(d_window_t *w); void window_destroy_damage(d_window_t *w); -- 1.9.1