summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2011-07-04 12:36:23 +0200
committerAndrea Canciani <ranma42@gmail.com>2011-07-21 19:16:42 +0200
commit1aa077e129485789803ad050f461067b4fe374d7 (patch)
tree455c9b9d86429eb427d3db98e60dd6696b2c4dae
parent5eb8eacde0ec3267e55e9b63a33ed2d4642867a7 (diff)
downloadcairo-1aa077e129485789803ad050f461067b4fe374d7.tar.gz
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.
-rw-r--r--src/cairo-xcb-private.h7
-rw-r--r--src/cairo-xcb-screen.c13
-rw-r--r--src/cairo-xlib-private.h6
-rw-r--r--src/cairo-xlib-screen.c16
4 files changed, 23 insertions, 19 deletions
diff --git a/src/cairo-xcb-private.h b/src/cairo-xcb-private.h
index 2897b07a8..a80ed14bb 100644
--- a/src/cairo-xcb-private.h
+++ b/src/cairo-xcb-private.h
@@ -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 {
diff --git a/src/cairo-xcb-screen.c b/src/cairo-xcb-screen.c
index a7802c2df..7b5493f19 100644
--- a/src/cairo-xcb-screen.c
+++ b/src/cairo-xcb-screen.c
@@ -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
diff --git a/src/cairo-xlib-private.h b/src/cairo-xlib-private.h
index a6bdcd1e2..d10e986d1 100644
--- a/src/cairo-xlib-private.h
+++ b/src/cairo-xlib-private.h
@@ -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;
};
diff --git a/src/cairo-xlib-screen.c b/src/cairo-xlib-screen.c
index 8ac99351f..dc060c2ea 100644
--- a/src/cairo-xlib-screen.c
+++ b/src/cairo-xlib-screen.c
@@ -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