mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-06 09:18:11 +02:00
src: check the surface backend for NULL
This is a follow-up patch on top of 150c1e7044
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@samsung.com>
This commit is contained in:
parent
06b9f8fa2d
commit
573ddfc3d5
4 changed files with 60 additions and 5 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -171,6 +171,21 @@ cairo_win32_surface_get_dc (cairo_surface_t *surface)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* _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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue