xcb,xlib: Cleanup GC cache handling

Device mutexes guarantee the consistency between multiple threads,
hence GC cache does not rely anymore on atomic operations.

This makes it possible to avoid bit twiddling and to use a simple
array.
This commit is contained in:
Andrea Canciani 2011-07-04 12:36:23 +02:00
parent 5eb8eacde0
commit 1aa077e129
4 changed files with 23 additions and 19 deletions

View file

@ -56,6 +56,9 @@
#include <xcb/xcbext.h>
#include <pixman.h>
/* maximum number of cached GC's */
#define GC_CACHE_SIZE 4
#define CAIRO_XCB_RENDER_AT_LEAST(major, minor) \
((XCB_RENDER_MAJOR_VERSION > major) || \
((XCB_RENDER_MAJOR_VERSION == major) && (XCB_RENDER_MINOR_VERSION >= minor)))
@ -172,8 +175,8 @@ struct _cairo_xcb_screen {
xcb_screen_t *xcb_screen;
xcb_gcontext_t gc[4];
int gc_depths; /* 4 x uint8_t */
xcb_gcontext_t gc[GC_CACHE_SIZE];
uint8_t gc_depths[GC_CACHE_SIZE];
cairo_surface_t *stock_colors[CAIRO_STOCK_NUM_COLORS];
struct {

View file

@ -81,7 +81,7 @@ _cairo_xcb_screen_finish (cairo_xcb_screen_t *screen)
cairo_surface_destroy (screen->stock_colors[i]);
for (i = 0; i < ARRAY_LENGTH (screen->gc); i++) {
if (((screen->gc_depths >> (8*i)) & 0xff) != 0)
if (screen->gc_depths[i] != 0)
_cairo_xcb_connection_free_gc (screen->connection, screen->gc[i]);
}
@ -168,7 +168,7 @@ _cairo_xcb_screen_get (xcb_connection_t *xcb_connection,
cairo_list_init (&screen->surfaces);
cairo_list_init (&screen->pictures);
screen->gc_depths = 0;
memset (screen->gc_depths, 0, sizeof (screen->gc_depths));
memset (screen->gc, 0, sizeof (screen->gc));
screen->solid_cache_size = 0;
@ -228,8 +228,8 @@ _cairo_xcb_screen_get_gc (cairo_xcb_screen_t *screen,
assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex));
for (i = 0; i < ARRAY_LENGTH (screen->gc); i++) {
if (((screen->gc_depths >> (8*i)) & 0xff) == depth) {
screen->gc_depths &= ~(0xff << (8*i));
if (screen->gc_depths[i] == depth) {
screen->gc_depths[i] = 0;
return screen->gc[i];
}
}
@ -245,7 +245,7 @@ _cairo_xcb_screen_put_gc (cairo_xcb_screen_t *screen, int depth, xcb_gcontext_t
assert (CAIRO_MUTEX_IS_LOCKED (screen->connection->device.mutex));
for (i = 0; i < ARRAY_LENGTH (screen->gc); i++) {
if (((screen->gc_depths >> (8*i)) & 0xff) == 0)
if (screen->gc_depths[i] == 0)
break;
}
@ -256,8 +256,7 @@ _cairo_xcb_screen_put_gc (cairo_xcb_screen_t *screen, int depth, xcb_gcontext_t
}
screen->gc[i] = gc;
screen->gc_depths &= ~(0xff << (8*i));
screen->gc_depths |= depth << (8*i);
screen->gc_depths[i] = depth;
}
cairo_status_t

View file

@ -66,6 +66,8 @@ struct _cairo_xlib_hook {
#define CUBE_SIZE 6
/* size of gray ramp */
#define RAMP_SIZE 16
/* maximum number of cached GC's */
#define GC_CACHE_SIZE 4
struct _cairo_xlib_display {
cairo_device_t base;
@ -110,8 +112,8 @@ struct _cairo_xlib_screen {
cairo_bool_t has_font_options;
cairo_font_options_t font_options;
GC gc[4];
cairo_atomic_int_t gc_depths; /* 4 x uint8_t */
GC gc[GC_CACHE_SIZE];
uint8_t gc_depths[GC_CACHE_SIZE];
cairo_list_t visuals;
};

View file

@ -278,10 +278,11 @@ _cairo_xlib_screen_close_display (cairo_xlib_display_t *display,
dpy = display->display;
for (i = 0; i < ARRAY_LENGTH (info->gc); i++) {
if ((info->gc_depths >> (8*i)) & 0xff)
if (info->gc_depths[i] != 0) {
XFreeGC (dpy, info->gc[i]);
info->gc_depths[i] = 0;
}
}
info->gc_depths = 0;
}
void
@ -332,7 +333,7 @@ _cairo_xlib_screen_get (Display *dpy,
info->device = device;
info->screen = screen;
info->has_font_options = FALSE;
info->gc_depths = 0;
memset (info->gc_depths, 0, sizeof (info->gc_depths));
memset (info->gc, 0, sizeof (info->gc));
cairo_list_init (&info->visuals);
@ -358,8 +359,8 @@ _cairo_xlib_screen_get_gc (cairo_xlib_display_t *display,
int i;
for (i = 0; i < ARRAY_LENGTH (info->gc); i++) {
if (((info->gc_depths >> (8*i)) & 0xff) == depth) {
info->gc_depths &= ~(0xff << (8*i));
if (info->gc_depths[i] == depth) {
info->gc_depths[i] = 0;
gc = info->gc[i];
break;
}
@ -387,7 +388,7 @@ _cairo_xlib_screen_put_gc (cairo_xlib_display_t *display,
int i;
for (i = 0; i < ARRAY_LENGTH (info->gc); i++) {
if (((info->gc_depths >> (8*i)) & 0xff) == 0)
if (info->gc_depths[i] == 0)
break;
}
@ -408,8 +409,7 @@ _cairo_xlib_screen_put_gc (cairo_xlib_display_t *display,
}
info->gc[i] = gc;
info->gc_depths &= ~(0xff << (8*i));
info->gc_depths |= depth << (8*i);
info->gc_depths[i] = depth;
}
cairo_status_t