[PATCH 4/4] Add cairo_xcb_surface_set_drawable

Keith Packard <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Mirrors cairo_xlib_surface_set_drawable, allowing the drawable
targeted by a surface to be changed on the fly.

Signed-off-by: Keith Packard <[email protected]>
---
 doc/public/cairo-sections.txt |    1 +
 src/cairo-xcb-private.h       |    1 +
 src/cairo-xcb-surface.c       |   68 +++++++++++++++++++++++++++++++++++++++++
 src/cairo-xcb.h               |    6 +++
 4 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/doc/public/cairo-sections.txt b/doc/public/cairo-sections.txt
index ddc6921..f988663 100644
--- a/doc/public/cairo-sections.txt
+++ b/doc/public/cairo-sections.txt
@@ -160,6 +160,7 @@ cairo_xcb_surface_create
 cairo_xcb_surface_create_for_bitmap
 cairo_xcb_surface_create_with_xrender_format
 cairo_xcb_surface_set_size
+cairo_xcb_surface_set_drawable
 </SECTION>
 
 <SECTION>
diff --git a/src/cairo-xcb-private.h b/src/cairo-xcb-private.h
index 42a112c..8d90bc6 100644
--- a/src/cairo-xcb-private.h
+++ b/src/cairo-xcb-private.h
@@ -806,6 +806,7 @@ slim_hidden_proto (cairo_xcb_surface_create);
 slim_hidden_proto (cairo_xcb_surface_create_for_bitmap);
 slim_hidden_proto (cairo_xcb_surface_create_with_xrender_format);
 slim_hidden_proto (cairo_xcb_surface_set_size);
+slim_hidden_proto (cairo_xcb_surface_set_drawable);
 slim_hidden_proto (cairo_xcb_device_debug_get_precision);
 slim_hidden_proto_no_warn (cairo_xcb_device_debug_set_precision);
 #endif
diff --git a/src/cairo-xcb-surface.c b/src/cairo-xcb-surface.c
index 6ddc815..3254cda 100644
--- a/src/cairo-xcb-surface.c
+++ b/src/cairo-xcb-surface.c
@@ -1430,3 +1430,71 @@ cairo_xcb_surface_set_size (cairo_surface_t *abstract_surface,
 #if CAIRO_HAS_XLIB_XCB_FUNCTIONS
 slim_hidden_def (cairo_xcb_surface_set_size);
 #endif
+
+/**
+ * cairo_xcb_surface_set_drawable:
+ * @surface: a #cairo_surface_t for the XCB backend
+ * @drawable: the new drawable of the surface
+ * @width: the new width of the surface
+ * @height: the new height of the surface
+ *
+ * Informs cairo of the new drawable and size of the XCB drawable underlying the
+ * surface.
+ *
+ **/
+void
+cairo_xcb_surface_set_drawable (cairo_surface_t	*abstract_surface,
+				xcb_drawable_t	drawable,
+				int            	width,
+				int             height)
+{
+    cairo_xcb_surface_t *surface;
+
+    if (unlikely (abstract_surface->status))
+	return;
+    if (unlikely (abstract_surface->finished)) {
+	_cairo_surface_set_error (abstract_surface,
+				  _cairo_error (CAIRO_STATUS_SURFACE_FINISHED));
+	return;
+    }
+
+
+    if (abstract_surface->type != CAIRO_SURFACE_TYPE_XCB) {
+	_cairo_surface_set_error (abstract_surface,
+				  _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH));
+	return;
+    }
+
+    if (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX || width <= 0 || height <= 0) {
+	_cairo_surface_set_error (abstract_surface,
+				  _cairo_error (CAIRO_STATUS_INVALID_SIZE));
+	return;
+    }
+
+    surface = (cairo_xcb_surface_t *) abstract_surface;
+
+    if (surface->owns_pixmap)
+	    return;
+
+    if (surface->drawable != drawable) {
+	    cairo_status_t status;
+	    status = _cairo_xcb_connection_acquire (surface->connection);
+	    if (unlikely (status))
+		    return;
+
+	    if (surface->picture != XCB_NONE) {
+		    _cairo_xcb_connection_render_free_picture (surface->connection,
+							       surface->picture);
+		    surface->picture = XCB_NONE;
+	    }
+
+	    _cairo_xcb_connection_release (surface->connection);
+
+	    surface->drawable = drawable;
+    }
+    surface->width  = width;
+    surface->height = height;
+}
+#if CAIRO_HAS_XLIB_XCB_FUNCTIONS
+slim_hidden_def (cairo_xcb_surface_set_drawable);
+#endif
diff --git a/src/cairo-xcb.h b/src/cairo-xcb.h
index 4bfb0b5..e321d84 100644
--- a/src/cairo-xcb.h
+++ b/src/cairo-xcb.h
@@ -75,6 +75,12 @@ cairo_xcb_surface_set_size (cairo_surface_t *surface,
 			    int		     width,
 			    int		     height);
 
+cairo_public void
+cairo_xcb_surface_set_drawable (cairo_surface_t *surface,
+				xcb_drawable_t	drawable,
+				int		width,
+				int		height);
+
 cairo_public xcb_connection_t *
 cairo_xcb_device_get_connection (cairo_device_t *device);
 
-- 
1.7.7.3

--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.