summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2010-09-07 14:11:42 +0200
committerMurray Cumming <murrayc@murrayc.com>2010-09-07 14:14:01 +0200
commit1dcaaa6dd18e0b69b876c75f741434ae1ec7b4f2 (patch)
tree09870813e700af2abee3ceab875d258cf95f6850
parent3b7fcd28c113ba76fa641717d87bf02b10563602 (diff)
Added Device class.
* cairomm/device.[h|cc]: Added these files, wrapping cairo_device_t. * cairomm/filelist.am: * cairomm/cairomm.h: Mention the new file.
-rw-r--r--ChangeLog8
-rw-r--r--cairomm/cairomm.h1
-rw-r--r--cairomm/device.cc72
-rw-r--r--cairomm/device.h79
-rw-r--r--cairomm/enums.h10
-rw-r--r--cairomm/filelist.am2
-rw-r--r--cairomm/region.h2
7 files changed, 173 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index c746a70..b193af1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-09-07 Murray Cumming <murrayc@murrayc.com>
+
+ Added Device class.
+
+ * cairomm/device.[h|cc]: Added these files, wrapping cairo_device_t.
+ * cairomm/filelist.am:
+ * cairomm/cairomm.h: Mention the new file.
+
1.9.2:
2010-09-02 Murray Cumming <murrayc@murrayc.com>
diff --git a/cairomm/cairomm.h b/cairomm/cairomm.h
index b96c3b1..19dad97 100644
--- a/cairomm/cairomm.h
+++ b/cairomm/cairomm.h
@@ -33,6 +33,7 @@
#include <cairommconfig.h>
#include <cairomm/context.h>
+#include <cairomm/device.h>
#include <cairomm/enums.h>
#include <cairomm/exception.h>
#include <cairomm/fontface.h>
diff --git a/cairomm/device.cc b/cairomm/device.cc
new file mode 100644
index 0000000..c4035dc
--- /dev/null
+++ b/cairomm/device.cc
@@ -0,0 +1,72 @@
+/* Copyright (C) 2010s 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 <cairomm/device.h>
+#include <cairomm/private.h>
+
+namespace Cairo
+{
+
+Device::Device(cairo_device_t* cobject, bool has_reference)
+: m_cobject(0)
+{
+ if(has_reference)
+ m_cobject = cobject;
+ else
+ m_cobject = cairo_device_reference(cobject);
+}
+
+Device::~Device()
+{
+ if(m_cobject)
+ cairo_device_destroy(m_cobject);
+}
+
+void Device::reference() const
+{
+ cairo_device_reference(m_cobject);
+}
+
+void Device::unreference() const
+{
+ cairo_device_destroy(m_cobject);
+}
+
+DeviceType Device::get_type() const
+{
+ cairo_device_type_t surface_type =
+ cairo_device_get_type(const_cast<cobject*>(cobj()));
+ check_object_status_and_throw_exception(*this);
+ return static_cast<DeviceType>(surface_type);
+}
+
+void Device::flush()
+{
+ cairo_device_flush(m_cobject);
+ check_object_status_and_throw_exception(*this);
+}
+
+void Device::finish()
+{
+ cairo_device_flush(m_cobject);
+ check_object_status_and_throw_exception(*this);
+}
+
+} //namespace Cairo
+
+// vim: ts=2 sw=2 et
diff --git a/cairomm/device.h b/cairomm/device.h
new file mode 100644
index 0000000..90972fc
--- /dev/null
+++ b/cairomm/device.h
@@ -0,0 +1,79 @@
+/* Copyright (C) 2010 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_DEVICE_H
+#define __CAIROMM_DEVICE_H
+
+#include <cairomm/types.h>
+#include <cairomm/enums.h>
+#include <cairomm/refptr.h>
+#include <cairo.h>
+
+
+namespace Cairo
+{
+
+//TODO: Documentation.
+
+/**
+ * This is a reference-counted object that should be used via Cairo::RefPtr.
+ */
+class 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.
+ */
+ explicit Device(cairo_device_t* cobject, bool has_reference = false);
+
+ virtual ~Device();
+
+ DeviceType get_type() const;
+
+ //TODO: Documentation.
+ void flush();
+
+ //TODO: Documentation.
+ void finish();
+
+ typedef cairo_device_t cobject;
+
+ inline cobject* cobj() { return m_cobject; }
+ inline const cobject* cobj() const { return m_cobject; }
+
+ #ifndef DOXYGEN_IGNORE_THIS
+ ///For use only by the cairomm implementation.
+ inline ErrorStatus get_status() const
+ { return cairo_device_status(const_cast<cairo_device_t*>(cobj())); }
+ #endif //DOXYGEN_IGNORE_THIS
+
+ void reference() const;
+ void unreference() const;
+
+protected:
+
+ cobject* m_cobject;
+};
+
+} // namespace Cairo
+
+#endif //__CAIROMM_DEVICE_H
+
+// vim: ts=2 sw=2 et
diff --git a/cairomm/enums.h b/cairomm/enums.h
index 7475dac..cee49c9 100644
--- a/cairomm/enums.h
+++ b/cairomm/enums.h
@@ -105,6 +105,16 @@ typedef enum
CONTENT_COLOR_ALPHA = CAIRO_CONTENT_COLOR_ALPHA
} Content;
+//TODO: Mark as new in 1.10
+typedef enum
+{
+ DEVICE_TYPE_DRM = CAIRO_DEVICE_TYPE_DRM,
+ DEVICE_TYPE_GL = CAIRO_DEVICE_TYPE_GL,
+ DEVICE_TYPE_SCRIPT = CAIRO_DEVICE_TYPE_SCRIPT,
+ DEVICE_TYPE_XCB = CAIRO_DEVICE_TYPE_XCB,
+ DEVICE_TYPE_XLIB = CAIRO_DEVICE_TYPE_XLIB,
+ DEVICE_TYPE_XML = CAIRO_DEVICE_TYPE_XML
+} DeviceType;
typedef enum
{
diff --git a/cairomm/filelist.am b/cairomm/filelist.am
index 48517d5..9f0b832 100644
--- a/cairomm/filelist.am
+++ b/cairomm/filelist.am
@@ -5,6 +5,7 @@ cairomm_cc = \
context_surface_quartz.cc \
context_surface_win32.cc \
context_surface_xlib.cc \
+ device.cc \
exception.cc \
fontface.cc \
fontoptions.cc \
@@ -24,6 +25,7 @@ cairomm_cc = \
cairomm_public_h = \
cairomm.h \
context.h \
+ device.h \
enums.h \
exception.h \
fontface.h \
diff --git a/cairomm/region.h b/cairomm/region.h
index d6acb0c..9909d8e 100644
--- a/cairomm/region.h
+++ b/cairomm/region.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005 The cairomm Development Team
+/* Copyright (C) 2010 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