summaryrefslogtreecommitdiff
path: root/src/cairo-xlib-display.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2010-04-23 22:10:32 +0200
committerBenjamin Otte <otte@redhat.com>2010-04-23 22:18:54 +0200
commit637564c562de21c17c36d192d3ab1b3fe069754b (patch)
tree3d9c0e9846cfbd9fe29014c06ea33c683d265d3e /src/cairo-xlib-display.c
parent49b52a8946cbd5f785f71069313e4a204358887b (diff)
downloadcairo-637564c562de21c17c36d192d3ab1b3fe069754b.tar.gz
xlib: Fix screen device handling
Add a _cairo_xlib_device_create() function that could easily be exported as a replacement for _cairo_xlib_display_get(). This function returns a cairo_device_t instead of a cairo_xlib_display_t because the display isn't acquired.
Diffstat (limited to 'src/cairo-xlib-display.c')
-rw-r--r--src/cairo-xlib-display.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/cairo-xlib-display.c b/src/cairo-xlib-display.c
index b0a582808..6dd62cc6e 100644
--- a/src/cairo-xlib-display.c
+++ b/src/cairo-xlib-display.c
@@ -254,15 +254,22 @@ static const cairo_device_backend_t _cairo_xlib_device_backend = {
_cairo_xlib_display_destroy,
};
-cairo_status_t
-_cairo_xlib_display_get (Display *dpy,
- cairo_xlib_display_t **out)
+/**
+ * cairo_xlib_device_create:
+ * @dpy: the display to create the device for
+ *
+ * Gets the device belonging to @dpy, or creates it if it doesn't exist yet.
+ *
+ * Returns: the device belonging to @dpy
+ **/
+cairo_device_t *
+_cairo_xlib_device_create (Display *dpy)
{
cairo_xlib_display_t *display;
cairo_xlib_display_t **prev;
+ cairo_device_t *device;
XExtCodes *codes;
const char *env;
- cairo_status_t status = CAIRO_STATUS_SUCCESS;
/* There is an apparent deadlock between this mutex and the
* mutex for the display, but it's actually safe. For the
@@ -284,18 +291,14 @@ _cairo_xlib_display_get (Display *dpy,
display->next = _cairo_xlib_display_list;
_cairo_xlib_display_list = display;
}
- break;
+ device = cairo_device_reference (&display->base);
+ goto UNLOCK;
}
}
- if (display != NULL) {
- cairo_device_reference (&display->base);
- goto UNLOCK;
- }
-
display = malloc (sizeof (cairo_xlib_display_t));
if (unlikely (display == NULL)) {
- status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ device = _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY);
goto UNLOCK;
}
@@ -326,9 +329,8 @@ _cairo_xlib_display_get (Display *dpy,
codes = XAddExtension (dpy);
if (unlikely (codes == NULL)) {
- status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ device = _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY);
free (display);
- display = NULL;
goto UNLOCK;
}
@@ -433,10 +435,11 @@ _cairo_xlib_display_get (Display *dpy,
display->next = _cairo_xlib_display_list;
_cairo_xlib_display_list = display;
+ device = &display->base;
+
UNLOCK:
CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex);
- *out = display;
- return status;
+ return device;
}
void