Skip to content

Commit

Permalink
Add XCB surface support - it is an ABI change.
Browse files Browse the repository at this point in the history
Add src/__init__.py (was previously auto-generated)
  • Loading branch information
Steve Chaplin committed Dec 30, 2009
1 parent da1b906 commit 9b1c3a8
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/pycairo_c_api.rst
Expand Up @@ -52,6 +52,7 @@ Objects::
PycairoPSSurface
PycairoSVGSurface
PycairoWin32Surface
PycairoXCBSurface
PycairoXlibSurface


Expand All @@ -78,6 +79,7 @@ Types::
PyTypeObject *PSSurface_Type;
PyTypeObject *SVGSurface_Type;
PyTypeObject *Win32Surface_Type;
PyTypeObject *XCBSurface_Type;
PyTypeObject *XlibSurface_Type;


Expand Down
17 changes: 17 additions & 0 deletions doc/reference/surfaces.rst
Expand Up @@ -626,6 +626,23 @@ Windows windows, bitmaps, and printing device contexts.
cairo.FORMAT_RGB24, see :ref:`FORMAT attributes <constants_FORMAT>`.



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`)
===================================

Expand Down
1 change: 0 additions & 1 deletion src/.gitignore
@@ -1,6 +1,5 @@
.deps
.libs
__init__.py
Makefile
Makefile.in
*.la
Expand Down
1 change: 1 addition & 0 deletions src/__init__.py
@@ -0,0 +1 @@
from _cairo import *
15 changes: 15 additions & 0 deletions src/cairomodule.c
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/private.h
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/pycairo.h
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions src/surface.c
Expand Up @@ -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;
Expand Down Expand Up @@ -1135,6 +1140,64 @@ PyTypeObject PycairoWin32Surface_Type = {
#endif /* CAIRO_HAS_WIN32_SURFACE */


/* Class XCBSurface(Surface) --------------------------------------------- */
#ifdef CAIRO_HAS_XCB_SURFACE
#include <cairo-xcb.h>

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 <cairo-xlib.h>
Expand Down

0 comments on commit 9b1c3a8

Please sign in to comment.