From 757215698293d1c1869ff0a23794c645dbfc66cc Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Thu, 13 Feb 2014 02:10:09 +0200 Subject: [PATCH 5/7] Wrap Xlib device API --- cairomm/filelist.am | 2 ++ cairomm/surface.cc | 8 ++++- cairomm/xlib_device.cc | 57 +++++++++++++++++++++++++++++++++ cairomm/xlib_device.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 cairomm/xlib_device.cc create mode 100644 cairomm/xlib_device.h diff --git a/cairomm/filelist.am b/cairomm/filelist.am index adbe3c5..53f1293 100644 --- a/cairomm/filelist.am +++ b/cairomm/filelist.am @@ -24,6 +24,7 @@ cairomm_cc = \ win32_surface.cc \ xcb_device.cc \ xcb_surface.cc \ + xlib_device.cc \ xlib_surface.cc cairomm_public_h = \ @@ -49,6 +50,7 @@ cairomm_public_h = \ win32_surface.h \ xcb_device.h \ xcb_surface.h \ + xlib_device.h \ xlib_surface.h cairomm_private_h = \ diff --git a/cairomm/surface.cc b/cairomm/surface.cc index 89ddade..e1b517e 100644 --- a/cairomm/surface.cc +++ b/cairomm/surface.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2005 The cairomm Development Team +/* Copyright (C) 2005-2014 The cairomm Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -19,6 +19,7 @@ #include #include #include +#include #include namespace Cairo @@ -261,6 +262,11 @@ RefPtr Surface::get_device() return RefPtr(new XcbDevice(d, true /* has reference */)); break; #endif +#if CAIRO_HAS_XLIB_SURFACE + case CAIRO_SURFACE_TYPE_XLIB: + return RefPtr(new XlibDevice(d, true /* has reference */)); + break; +#endif default: return RefPtr(new Device(d, true /* has reference */)); } diff --git a/cairomm/xlib_device.cc b/cairomm/xlib_device.cc new file mode 100644 index 0000000..98b4578 --- /dev/null +++ b/cairomm/xlib_device.cc @@ -0,0 +1,57 @@ +/* Copyright (C) 2014 The cairomm Development Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include +#include + +#if CAIRO_HAS_XLIB_SURFACE +#include +#endif + +namespace Cairo { + +#ifdef CAIRO_HAS_XLIB_SURFACE + +XlibDevice::XlibDevice(cairo_device_t* cobject, bool has_reference) : + Device(cobject, has_reference) +{} + +XlibDevice::~XlibDevice() +{ + // device is destroyed in base class +} + +void XlibDevice::debug_cap_xrender_version(int major_version, int minor_version) +{ + cairo_xlib_device_debug_cap_xrender_version(m_cobject, major_version, + minor_version); +} + +int XlibDevice::debug_get_precision() const +{ + return cairo_xlib_device_debug_get_precision(m_cobject); +} + +void XlibDevice::debug_set_precision(int precision) +{ + cairo_xlib_device_debug_set_precision(m_cobject, precision); +} + +#endif // CAIRO_HAS_XLIB_SURFACE + +} //namespace Cairo diff --git a/cairomm/xlib_device.h b/cairomm/xlib_device.h new file mode 100644 index 0000000..7910cec --- /dev/null +++ b/cairomm/xlib_device.h @@ -0,0 +1,86 @@ +/* Copyright (C) 2014 The cairomm Development Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __CAIROMM_XLIB_DEVICE_H +#define __CAIROMM_XLIB_DEVICE_H + +#include + +namespace Cairo { + +#ifdef CAIRO_HAS_XLIB_SURFACE + +/** + * An XLIB device + * + * @since 1.12 + */ +class XlibDevice : public Device { +public: + + /** + * Create a C++ wrapper for the C instance. This C++ instance should then be + * given to a RefPtr. + * + * @param cobject The C instance. + * @param has_reference whether we already have a reference. Otherwise, the + * constructor will take an extra reference. + * + * @since 1.12 + */ + explicit XlibDevice(cairo_device_t* cobject, bool has_reference = false); + virtual ~XlibDevice(); + + /** + * Restricts all future XCB surfaces for this device to the specified + * version of the RENDER extension. This function exists solely for debugging + * purpose. It lets you find out how Cairomm would behave with an older + * version of the RENDER extension. + * + * Use the special values -1 and -1 for disabling the RENDER extension. + * + * @param major_version major version to restrict to + * @param minor_version minor version to restrict to + * + * @since 1.12 + */ + void debug_cap_xrender_version(int major_version, int minor_version); + + /** + * Returns the Xrender precision mode. + * + * @since 1.12 + */ + int debug_get_precision() const; + + /** + * The Xrender extension supports two modes of precision when rendering + * trapezoids. Set the precision to the desired mode. + * + * @since 1.12 + */ + void debug_set_precision(int precision); + +}; + +#endif // CAIRO_HAS_XLIB_SURFACE + +} // namespace Cairo + +#endif //__CAIROMM_XLIB_SURFACE_H + -- 1.8.5.3