From 9b1c3a86f13d86dbd3f26c4d527f64309f64389a Mon Sep 17 00:00:00 2001 From: Steve Chaplin Date: Wed, 30 Dec 2009 22:05:02 +0800 Subject: Add XCB surface support - it is an ABI change. Add src/__init__.py (was previously auto-generated) --- doc/pycairo_c_api.rst | 2 ++ doc/reference/surfaces.rst | 17 +++++++++++++ src/.gitignore | 1 - src/__init__.py | 1 + src/cairomodule.c | 15 +++++++++++ src/private.h | 4 +++ src/pycairo.h | 6 +++++ src/surface.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 108 insertions(+), 1 deletion(-) create mode 100755 src/__init__.py diff --git a/doc/pycairo_c_api.rst b/doc/pycairo_c_api.rst index d7d3bd8..680b1c9 100644 --- a/doc/pycairo_c_api.rst +++ b/doc/pycairo_c_api.rst @@ -52,6 +52,7 @@ Objects:: PycairoPSSurface PycairoSVGSurface PycairoWin32Surface + PycairoXCBSurface PycairoXlibSurface @@ -78,6 +79,7 @@ Types:: PyTypeObject *PSSurface_Type; PyTypeObject *SVGSurface_Type; PyTypeObject *Win32Surface_Type; + PyTypeObject *XCBSurface_Type; PyTypeObject *XlibSurface_Type; diff --git a/doc/reference/surfaces.rst b/doc/reference/surfaces.rst index b8cc399..0957649 100644 --- a/doc/reference/surfaces.rst +++ b/doc/reference/surfaces.rst @@ -626,6 +626,23 @@ Windows windows, bitmaps, and printing device contexts. cairo.FORMAT_RGB24, see :ref:`FORMAT attributes `. + +class XCBSurface(:class:`Surface`) +=================================== + +The XCB surface is used to render cairo graphics to X Window System windows +and pixmaps using the XCB library. + +Note that the XCB surface automatically takes advantage of X render extension +if it is available. + +.. class:: XCBSurface + + .. note:: *XCBSurface* cannot be instantiated directly because Python + interaction with XCB would require open source Python bindings to Xlib + which provided a C API. + + class XlibSurface(:class:`Surface`) =================================== diff --git a/src/.gitignore b/src/.gitignore index 599e3f3..0a7d55e 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,6 +1,5 @@ .deps .libs -__init__.py Makefile Makefile.in *.la diff --git a/src/__init__.py b/src/__init__.py new file mode 100755 index 0000000..07501fc --- /dev/null +++ b/src/__init__.py @@ -0,0 +1 @@ +from _cairo import * diff --git a/src/cairomodule.c b/src/cairomodule.c index 386ddab..a83ba49 100644 --- a/src/cairomodule.c +++ b/src/cairomodule.c @@ -132,6 +132,11 @@ static Pycairo_CAPI_t CAPI = { #else 0, #endif +#ifdef CAIRO_HAS_XCB_SURFACE + &PycairoXCBSurface_Type, +#else + 0, +#endif #ifdef CAIRO_HAS_XLIB_SURFACE &PycairoXlibSurface_Type, #else @@ -217,6 +222,10 @@ init_cairo(void) if (PyType_Ready(&PycairoWin32Surface_Type) < 0) return; #endif +#ifdef CAIRO_HAS_XCB_SURFACE + if (PyType_Ready(&PycairoXCBSurface_Type) < 0) + return; +#endif #ifdef CAIRO_HAS_XLIB_SURFACE if (PyType_Ready(&PycairoXlibSurface_Type) < 0) return; @@ -296,6 +305,12 @@ init_cairo(void) (PyObject *)&PycairoWin32Surface_Type); #endif +#ifdef CAIRO_HAS_XCB_SURFACE + Py_INCREF(&PycairoXCBSurface_Type); + PyModule_AddObject(m, "XCBSurface", + (PyObject *)&PycairoXCBSurface_Type); +#endif + #ifdef CAIRO_HAS_XLIB_SURFACE Py_INCREF(&PycairoXlibSurface_Type); PyModule_AddObject(m, "XlibSurface", diff --git a/src/private.h b/src/private.h index 5951104..4bbf4fd 100644 --- a/src/private.h +++ b/src/private.h @@ -94,6 +94,10 @@ extern PyTypeObject PycairoSVGSurface_Type; extern PyTypeObject PycairoWin32Surface_Type; #endif +#if CAIRO_HAS_XCB_SURFACE +extern PyTypeObject PycairoXCBSurface_Type; +#endif + #if CAIRO_HAS_XLIB_SURFACE extern PyTypeObject PycairoXlibSurface_Type; #endif diff --git a/src/pycairo.h b/src/pycairo.h index 255bc74..f9cfacf 100644 --- a/src/pycairo.h +++ b/src/pycairo.h @@ -92,6 +92,7 @@ typedef struct { #define PycairoPSSurface PycairoSurface #define PycairoSVGSurface PycairoSurface #define PycairoWin32Surface PycairoSurface +#define PycairoXCBSurface PycairoSurface #define PycairoXlibSurface PycairoSurface /* get C object out of the Python wrapper */ @@ -131,6 +132,7 @@ typedef struct { PyTypeObject *PSSurface_Type; PyTypeObject *SVGSurface_Type; PyTypeObject *Win32Surface_Type; + PyTypeObject *XCBSurface_Type; PyTypeObject *XlibSurface_Type; PyObject *(*Surface_FromSurface)(cairo_surface_t *surface, PyObject *base); @@ -186,6 +188,10 @@ typedef struct { #define PycairoWin32Surface_Type *(Pycairo_CAPI->Win32Surface_Type) #endif +#if CAIRO_HAS_XCB_SURFACE +#define PycairoXCBSurface_Type *(Pycairo_CAPI->XCBSurface_Type) +#endif + #if CAIRO_HAS_XLIB_SURFACE #define PycairoXlibSurface_Type *(Pycairo_CAPI->XlibSurface_Type) #endif diff --git a/src/surface.c b/src/surface.c index b08ee8c..7a6fd2e 100644 --- a/src/surface.c +++ b/src/surface.c @@ -90,6 +90,11 @@ PycairoSurface_FromSurface (cairo_surface_t *surface, PyObject *base) { type = &PycairoWin32Surface_Type; break; #endif +#if CAIRO_HAS_XCB_SURFACE + case CAIRO_SURFACE_TYPE_XCB: + type = &PycairoXCBSurface_Type; + break; +#endif #if CAIRO_HAS_XLIB_SURFACE case CAIRO_SURFACE_TYPE_XLIB: type = &PycairoXlibSurface_Type; @@ -1135,6 +1140,64 @@ PyTypeObject PycairoWin32Surface_Type = { #endif /* CAIRO_HAS_WIN32_SURFACE */ +/* Class XCBSurface(Surface) --------------------------------------------- */ +#ifdef CAIRO_HAS_XCB_SURFACE +#include + +static PyObject * +xcb_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) { + PyErr_SetString(PyExc_TypeError, + "The XCBSurface type cannot be directly instantiated"); + return NULL; +} + +PyTypeObject PycairoXCBSurface_Type = { + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ + "cairo.XCBSurface", /* tp_name */ + sizeof(PycairoXCBSurface), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + 0, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &PycairoSurface_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + (newfunc)xcb_surface_new, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ +}; +#endif /* CAIRO_HAS_XCB_SURFACE */ + + /* Class XlibSurface(Surface) --------------------------------------------- */ #ifdef CAIRO_HAS_XLIB_SURFACE #include -- cgit v1.2.1