[cairo-commit] src/cairo-qt-surface.cpp src/cairo-quartz-image-surface.c src/cairo-quartz-surface.c src/win32

Bryce Harrington bryce at kemper.freedesktop.org
Mon Sep 29 16:00:13 PDT 2014


 src/cairo-qt-surface.cpp         |   28 +++++++++++++++++++++++++---
 src/cairo-quartz-image-surface.c |    4 +++-
 src/cairo-quartz-surface.c       |   14 ++++++++++++++
 src/win32/cairo-win32-surface.c  |   19 ++++++++++++++++++-
 4 files changed, 60 insertions(+), 5 deletions(-)

New commits:
commit 573ddfc3d5c08c37b95a21e0a1b34acecc646053
Author: Ravi Nanjundappa <nravi.n at samsung.com>
Date:   Thu Sep 25 08:38:50 2014 +0530

    src: check the surface backend for NULL
    
    This is a follow-up patch on top of 150c1e7044c57443d458e12bfc427d3a019cb60b
    As discussed in the mailing list, http://lists.cairographics.org/archives/cairo/2014-September/025647.html,
    check if the surfaces are of particular backend type or not, before proceeding further.
    
    These changes are based on _cairo_surface_is_xlib() and _cairo_surface_is_image()
    
    Signed-off-by: Ravi Nanjundappa <nravi.n at samsung.com>

diff --git a/src/cairo-qt-surface.cpp b/src/cairo-qt-surface.cpp
index d1c7760..7ddad77 100644
--- a/src/cairo-qt-surface.cpp
+++ b/src/cairo-qt-surface.cpp
@@ -1660,13 +1660,30 @@ cairo_qt_surface_create_with_qpixmap (cairo_content_t content,
     return &qs->base;
 }
 
+/**
+ * _cairo_surface_is_qt:
+ * @surface: a #cairo_surface_t
+ *
+ * Checks if a surface is a #cairo_qt_surface_t
+ *
+ * Return value: True if the surface is an qt surface
+ **/
+static inline cairo_bool_t
+_cairo_surface_is_qt (cairo_surface_t *surface)
+{
+    return surface->backend == &cairo_qt_surface_backend;
+}
+
 QPainter *
 cairo_qt_surface_get_qpainter (cairo_surface_t *surface)
 {
     cairo_qt_surface_t *qs = (cairo_qt_surface_t*) surface;
 
-    if (surface->type != CAIRO_SURFACE_TYPE_QT)
+    /* Throw an error for a non-qt surface */
+    if (! _cairo_surface_is_qt (surface)) {
+        _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
         return NULL;
+    }
 
     return qs->p;
 }
@@ -1676,8 +1693,11 @@ cairo_qt_surface_get_qimage (cairo_surface_t *surface)
 {
     cairo_qt_surface_t *qs = (cairo_qt_surface_t*) surface;
 
-    if (surface->type != CAIRO_SURFACE_TYPE_QT)
+    /* Throw an error for a non-qt surface */
+    if (! _cairo_surface_is_qt (surface)) {
+        _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
         return NULL;
+    }
 
     return qs->image;
 }
@@ -1687,8 +1707,10 @@ cairo_qt_surface_get_image (cairo_surface_t *surface)
 {
     cairo_qt_surface_t *qs = (cairo_qt_surface_t*) surface;
 
-    if (surface->type != CAIRO_SURFACE_TYPE_QT)
+    /* Throw an error for a non-qt surface */
+    if (! _cairo_surface_is_qt (surface)) {
         return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH));
+    }
 
     return qs->image_equiv;
 }
diff --git a/src/cairo-quartz-image-surface.c b/src/cairo-quartz-image-surface.c
index 511b634..b4bc8b9 100644
--- a/src/cairo-quartz-image-surface.c
+++ b/src/cairo-quartz-image-surface.c
@@ -378,8 +378,10 @@ cairo_quartz_image_surface_get_image (cairo_surface_t *asurface)
 {
     cairo_quartz_image_surface_t *surface = (cairo_quartz_image_surface_t*) asurface;
 
-    if (asurface->type != CAIRO_SURFACE_TYPE_QUARTZ_IMAGE)
+    /* Throw an error for a non-quartz surface */
+    if (! _cairo_surface_is_quartz (surface)) {
         return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH));
+    }
 
     return (cairo_surface_t*) surface->imageSurface;
 }
diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index 868c6c8..2aa83be 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -2195,6 +2195,20 @@ _cairo_quartz_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clip
     return CAIRO_STATUS_SUCCESS;
 }
 
+/**
+ * _cairo_surface_is_quartz:
+ * @surface: a #cairo_surface_t
+ *
+ * Checks if a surface is a #cairo_quartz_surface_t
+ *
+ * Return value: True if the surface is an quartz surface
+ **/
+inline cairo_bool_t
+_cairo_surface_is_quartz (cairo_surface_t *surface)
+{
+    return surface->backend == &cairo_quartz_surface_backend;
+}
+
 // XXXtodo implement show_page; need to figure out how to handle begin/end
 
 static const struct _cairo_surface_backend cairo_quartz_surface_backend = {
diff --git a/src/win32/cairo-win32-surface.c b/src/win32/cairo-win32-surface.c
index f11cbd8..e6862bd 100644
--- a/src/win32/cairo-win32-surface.c
+++ b/src/win32/cairo-win32-surface.c
@@ -172,6 +172,21 @@ cairo_win32_surface_get_dc (cairo_surface_t *surface)
 }
 
 /**
+ * _cairo_surface_is_win32:
+ * @surface: a #cairo_surface_t
+ *
+ * Checks if a surface is an #cairo_win32_surface_t
+ *
+ * Return value: %TRUE if the surface is an win32 surface
+ **/
+static inline cairo_bool_t
+_cairo_surface_is_win32 (const cairo_surface_t *surface)
+{
+    /* _cairo_surface_nil sets a NULL backend so be safe */
+    return surface->backend && surface->backend->type == CAIRO_SURFACE_TYPE_WIN32;
+}
+
+/**
  * cairo_win32_surface_get_image:
  * @surface: a #cairo_surface_t
  *
@@ -187,8 +202,10 @@ cairo_win32_surface_get_dc (cairo_surface_t *surface)
 cairo_surface_t *
 cairo_win32_surface_get_image (cairo_surface_t *surface)
 {
-    if (surface->backend->type != CAIRO_SURFACE_TYPE_WIN32)
+
+    if (! _cairo_surface_is_win32 (surface)) {
         return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH));
+    }
 
     GdiFlush();
     return to_win32_display_surface(surface)->image;


More information about the cairo-commit mailing list