[cairo] [PATCH 14/71] drm: typecasting helpers

Enrico Weigelt, metux IT consult enrico.weigelt at gr13.net
Mon Apr 17 16:56:53 UTC 2017


Signed-off-by: Enrico Weigelt, metux IT consult <enrico.weigelt at gr13.net>
---
 src/drm/cairo-drm-i915-glyphs.c    |  4 +-
 src/drm/cairo-drm-i915-private.h   | 39 +++++++++++++++-
 src/drm/cairo-drm-i915-shader.c    | 25 +++++-----
 src/drm/cairo-drm-i915-surface.c   | 40 ++++++++--------
 src/drm/cairo-drm-i965-glyphs.c    |  2 +-
 src/drm/cairo-drm-i965-private.h   | 27 +++++++++++
 src/drm/cairo-drm-i965-shader.c    | 44 ++++++++---------
 src/drm/cairo-drm-i965-surface.c   | 12 ++---
 src/drm/cairo-drm-intel-private.h  | 57 ++++++++++++++++++++--
 src/drm/cairo-drm-intel-surface.c  | 34 ++++++++------
 src/drm/cairo-drm-intel.c          |  4 +-
 src/drm/cairo-drm-private.h        | 46 ++++++++++++++++++
 src/drm/cairo-drm-radeon-private.h | 96 ++++++++++++++++++++++++++++++++++++++
 src/drm/cairo-drm-radeon-surface.c | 33 ++++---------
 src/drm/cairo-drm-radeon.c         |  8 ++--
 src/drm/cairo-drm-surface.c        |  4 +-
 src/drm/cairo-drm.c                | 10 ++--
 17 files changed, 363 insertions(+), 122 deletions(-)

diff --git a/src/drm/cairo-drm-i915-glyphs.c b/src/drm/cairo-drm-i915-glyphs.c
index 3b0efc248..9800f1c57 100644
--- a/src/drm/cairo-drm-i915-glyphs.c
+++ b/src/drm/cairo-drm-i915-glyphs.c
@@ -218,7 +218,7 @@ i915_surface_mask_internal (i915_surface_t *dst,
 			1. / mask->intel.drm.width,
 			1. / mask->intel.drm.height);
 
-    shader.mask.base.bo = intel_bo_reference (to_intel_bo (mask->intel.drm.bo));
+    shader.mask.base.bo = i915_surface_get_bo_ref (mask);
     shader.mask.base.offset[0] = 0;
     shader.mask.base.map[0] = mask->map0;
     shader.mask.base.map[1] = mask->map1;
@@ -283,7 +283,7 @@ i915_surface_glyphs (void			*abstract_surface,
 		     cairo_clip_t		*clip,
 		     int *num_remaining)
 {
-    i915_surface_t *surface = abstract_surface;
+    i915_surface_t *surface = _cairo_abstract_surface_cast_i915 (abstract_surface);
     i915_surface_t *mask = NULL;
     i915_device_t *device;
     i915_shader_t shader;
diff --git a/src/drm/cairo-drm-i915-private.h b/src/drm/cairo-drm-i915-private.h
index c750cf4cf..f04058768 100644
--- a/src/drm/cairo-drm-i915-private.h
+++ b/src/drm/cairo-drm-i915-private.h
@@ -764,6 +764,39 @@ struct i915_surface {
     uint32_t stencil_offset;
 };
 
+static inline i915_surface_t *
+_cairo_abstract_surface_cast_i915 (cairo_surface_t* surface)
+{
+    return cairo_container_of (
+	cairo_abstract_surface_cast_intel (surface),
+	i915_surface_t,
+	intel);
+}
+
+static inline i915_device_t *
+_cairo_intel_device_cast_i915 (intel_device_t *device)
+{
+    return cairo_container_of (device, i915_device_t, intel);
+}
+
+static inline i915_device_t *
+_cairo_device_cast_i915 (void *device)
+{
+    return _cairo_intel_device_cast_i915 (_cairo_device_cast_intel (device));
+}
+
+static inline intel_bo_t *
+i915_surface_get_bo (const i915_surface_t *surface)
+{
+    return _cairo_intel_surface_get_bo (&surface->intel);
+}
+
+static inline intel_bo_t *
+i915_surface_get_bo_ref (const i915_surface_t *surface)
+{
+    return intel_bo_reference (i915_surface_get_bo (surface));
+}
+
 typedef enum {
     NONE = 0,
     YUV_I420,
@@ -1031,8 +1064,10 @@ BUF_tiling (uint32_t tiling)
 }
 
 #define OUT_DWORD(dword) i915_batch_emit_dword (device, dword)
-#define OUT_RELOC(surface, read, write) i915_batch_emit_reloc (device, to_intel_bo (surface->intel.drm.bo), surface->offset, read, write, FALSE)
-#define OUT_RELOC_FENCED(surface, read, write) i915_batch_emit_reloc (device, to_intel_bo (surface->intel.drm.bo), surface->offset, read, write, TRUE)
+#define OUT_RELOC(surface, read, write) \
+    i915_batch_emit_reloc (device, i915_surface_get_bo (surface), surface->offset, read, write, FALSE)
+#define OUT_RELOC_FENCED(surface, read, write) \
+    i915_batch_emit_reloc (device, i915_surface_get_bo (surface), surface->offset, read, write, TRUE)
 
 #define FS_LOCALS							\
     uint32_t *_shader_start
diff --git a/src/drm/cairo-drm-i915-shader.c b/src/drm/cairo-drm-i915-shader.c
index 65e75c512..370c86df0 100644
--- a/src/drm/cairo-drm-i915-shader.c
+++ b/src/drm/cairo-drm-i915-shader.c
@@ -44,7 +44,7 @@
 static cairo_status_t
 i915_packed_pixel_surface_finish (void *abstract_surface)
 {
-    i915_packed_pixel_surface_t *surface = abstract_surface;
+    i915_packed_pixel_surface_t *surface = _cairo_abstract_surface_cast_i915 (abstract_surface);
     i915_device_t *device;
 
     device = i915_device_acquire (&surface->device->intel.base);
@@ -1306,7 +1306,7 @@ i915_surface_clone (i915_device_t *device,
 	return clone->intel.drm.base.status;
 
     status = intel_bo_put_image (&device->intel,
-				 to_intel_bo (clone->intel.drm.bo),
+				 i915_surface_get_bo (clone),
 				 image,
 				 0, 0,
 				 image->width, image->height,
@@ -1345,7 +1345,7 @@ i915_surface_clone_subimage (i915_device_t *device,
 	return clone->intel.drm.base.status;
 
     status = intel_bo_put_image (&device->intel,
-				 to_intel_bo (clone->intel.drm.bo),
+				 i915_surface_get_bo (clone),
 				 image,
 				 extents->x, extents->y,
 				 extents->width, extents->height,
@@ -1380,7 +1380,8 @@ i915_surface_render_pattern (i915_device_t *device,
 	return clone->intel.drm.base.status;
 
     ptr = intel_bo_map (&device->intel,
-			to_intel_bo (clone->intel.drm.bo));
+			i915_surface_get_bo (clone));
+
     if (unlikely (ptr == NULL)) {
 	cairo_surface_destroy (&clone->intel.drm.base);
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -1516,7 +1517,7 @@ i915_shader_acquire_surface (i915_shader_t *shader,
 
 		/* XXX blt subimage and cache snapshot */
 
-		if (to_intel_bo (s->intel.drm.bo)->batch_write_domain) {
+		if (i915_surface_get_bo (s)->batch_write_domain) {
 		    /* XXX pipelined flush of RENDER/TEXTURE cache */
 		}
 
@@ -1525,7 +1526,7 @@ i915_shader_acquire_surface (i915_shader_t *shader,
 		surface_width  = sub->extents.width;
 		surface_height = sub->extents.height;
 
-		src->base.bo = intel_bo_reference (to_intel_bo (s->intel.drm.bo));
+		src->base.bo = i915_surface_get_bo_ref (s);
 		src->base.n_samplers = 1;
 
 		x = sub->extents.x;
@@ -1563,7 +1564,7 @@ i915_shader_acquire_surface (i915_shader_t *shader,
 		surface_width  = s->intel.drm.width;
 		surface_height = s->intel.drm.height;
 
-		src->base.bo = intel_bo_reference (to_intel_bo (s->intel.drm.bo));
+		src->base.bo = i915_surface_get_bo_ref (s);
 		src->base.n_samplers = 1;
 		src->base.offset[0] = s->offset;
 		src->base.map[0] = s->map0;
@@ -1653,7 +1654,7 @@ i915_shader_acquire_surface (i915_shader_t *shader,
 	src->type.fragment = FS_TEXTURE;
 	src->surface.pixel = NONE;
 
-	src->base.bo = intel_bo_reference (to_intel_bo (s->intel.drm.bo));
+	src->base.bo = i915_surface_get_bo_ref (s);
 	src->base.n_samplers = 1;
 	src->base.offset[0] = s->offset;
 	src->base.map[0] = s->map0;
@@ -2400,7 +2401,7 @@ i915_set_dst (i915_device_t *device, i915_surface_t *dst)
     if (device->current_target != dst) {
 	intel_bo_t *bo;
 
-	bo = to_intel_bo (dst->intel.drm.bo);
+	bo = i915_surface_get_bo (dst);
 	assert (bo != NULL);
 
 	OUT_DWORD (_3DSTATE_BUF_INFO_CMD);
@@ -2520,7 +2521,7 @@ i915_shader_set_clip (i915_shader_t *shader,
     channel->surface.pixel = NONE;
 
     s = (i915_surface_t *) clip_surface;
-    channel->base.bo = to_intel_bo (s->intel.drm.bo);
+    channel->base.bo = i915_surface_get_bo (s);
     channel->base.n_samplers = 1;
     channel->base.offset[0] = s->offset;
     channel->base.map[0] = s->map0;
@@ -2549,7 +2550,7 @@ i915_shader_check_aperture (i915_shader_t *shader,
     uint32_t n = 0;
 
     if (shader->target != device->current_target)
-	bo_array[n++] = to_intel_bo (shader->target->intel.drm.bo);
+	bo_array[n++] = i915_surface_get_bo (shader->target);
 
     if (shader->source.base.bo != NULL)
 	bo_array[n++] = shader->source.base.bo;
@@ -2638,7 +2639,7 @@ i915_shader_setup_dst (i915_shader_t *shader)
     channel->surface.pixel = NONE;
 
     s = shader->target;
-    channel->base.bo = to_intel_bo (s->intel.drm.bo);
+    channel->base.bo = i915_surface_get_bo (s);
     channel->base.n_samplers = 1;
     channel->base.offset[0] = s->offset;
     channel->base.map[0] = s->map0;
diff --git a/src/drm/cairo-drm-i915-surface.c b/src/drm/cairo-drm-i915-surface.c
index cdbf258c2..1db6e5f83 100644
--- a/src/drm/cairo-drm-i915-surface.c
+++ b/src/drm/cairo-drm-i915-surface.c
@@ -652,7 +652,7 @@ i915_surface_create_similar (void *abstract_other,
 static cairo_status_t
 i915_surface_finish (void *abstract_surface)
 {
-    i915_surface_t *surface = abstract_surface;
+    i915_surface_t *surface = _cairo_abstract_surface_cast_i915 (abstract_surface);
     i915_device_t *device = i915_device (surface);
 
     if (surface->stencil != NULL) {
@@ -701,7 +701,7 @@ i915_surface_batch_flush (i915_surface_t *surface)
 
     assert (surface->intel.drm.fallback == NULL);
 
-    bo = to_intel_bo (surface->intel.drm.bo);
+    bo = i915_surface_get_bo (surface);
     if (bo == NULL || bo->batch_write_domain == 0)
 	return CAIRO_STATUS_SUCCESS;
 
@@ -719,7 +719,7 @@ static cairo_status_t
 i915_surface_flush (void *abstract_surface,
 		    unsigned flags)
 {
-    i915_surface_t *surface = abstract_surface;
+    i915_surface_t *surface = _cairo_abstract_surface_cast_i915 (abstract_surface);
     cairo_status_t status;
 
     if (flags)
@@ -1042,8 +1042,8 @@ i915_blt (i915_surface_t *src,
     cairo_status_t status;
     int br13, cmd;
 
-    bo_array[0] = to_intel_bo (dst->intel.drm.bo);
-    bo_array[1] = to_intel_bo (src->intel.drm.bo);
+    bo_array[0] = i915_surface_get_bo (dst);
+    bo_array[1] = i915_surface_get_bo (src);
 
     status = i915_surface_fallback_flush (src);
     if (unlikely (status))
@@ -1139,7 +1139,7 @@ i915_clear_boxes (i915_surface_t *dst,
     i915_device_t *device = i915_device (dst);
     const struct _cairo_boxes_chunk *chunk;
     cairo_status_t status;
-    intel_bo_t *bo_array[1] = { to_intel_bo (dst->intel.drm.bo) };
+    intel_bo_t *bo_array[1] = { i915_surface_get_bo (dst) };
     int cmd, br13, clear = 0, i;
 
     cmd = XY_COLOR_BLT_CMD;
@@ -1308,7 +1308,7 @@ i915_blt_boxes (i915_surface_t *dst,
     ty = _cairo_lround (pattern->matrix.y0);
 
     device = i915_device (dst);
-    if (to_intel_bo (src->intel.drm.bo)->tiling == I915_TILING_Y) {
+    if (i915_surface_get_bo (src)->tiling == I915_TILING_Y) {
 	cairo_rectangle_int_t extents;
 
 	_cairo_boxes_extents (boxes, &extents);
@@ -1324,8 +1324,8 @@ i915_blt_boxes (i915_surface_t *dst,
 	ty = -extents.y;
     }
 
-    bo_array[0] = to_intel_bo (dst->intel.drm.bo);
-    bo_array[1] = to_intel_bo (src->intel.drm.bo);
+    bo_array[0] = i915_surface_get_bo (dst);
+    bo_array[1] = i915_surface_get_bo (src);
 
     status = cairo_device_acquire (&device->intel.base.base);
     if (unlikely (status))
@@ -1437,7 +1437,7 @@ _upload_image_inplace (i915_surface_t *surface,
     }
 
     device = i915_device (surface);
-    bo = to_intel_bo (surface->intel.drm.bo);
+    bo = i915_surface_get_bo (surface);
     if (bo->exec != NULL || ! intel_bo_is_inactive (&device->intel, bo)) {
 	intel_bo_t *new_bo;
 	cairo_bool_t need_clear = FALSE;
@@ -1659,7 +1659,7 @@ i915_surface_clear (i915_surface_t *dst)
 {
     i915_device_t *device;
     cairo_status_t status;
-    intel_bo_t *bo_array[1] = { to_intel_bo (dst->intel.drm.bo) };
+    intel_bo_t *bo_array[1] = { i915_surface_get_bo (dst) };
 
     device = i915_device (dst);
     status = cairo_device_acquire (&device->intel.base.base);
@@ -1877,7 +1877,7 @@ i915_surface_fill_with_alpha (void			*abstract_dst,
 			      cairo_clip_t		*clip,
 			      double			 opacity)
 {
-    i915_surface_t *dst = abstract_dst;
+    i915_surface_t *dst = _cairo_abstract_surface_cast_i915 (abstract_dst);
     cairo_composite_rectangles_t extents;
     composite_polygon_info_t info;
     cairo_box_t boxes_stack[32], *clip_boxes = boxes_stack;
@@ -2473,7 +2473,7 @@ i915_surface_create_internal (cairo_drm_device_t *base_dev,
 	}
 
 	size = stride * height;
-	bo = intel_bo_create (to_intel_device (&base_dev->base),
+	bo = intel_bo_create (_cairo_drm_device_cast_intel (base_dev),
 			      i915_tiling_size (tiling, size), size,
 			      gpu_target, tiling, stride);
 	if (bo == NULL) {
@@ -2553,15 +2553,15 @@ i915_surface_create_for_name (cairo_drm_device_t *base_dev,
 	surface->map1 = (surface->intel.drm.stride/4 - 1) << MS4_PITCH_SHIFT;
 
 	surface->intel.drm.bo =
-	    &intel_bo_create_for_name (to_intel_device (&base_dev->base),
+	    &intel_bo_create_for_name (_cairo_drm_device_cast_intel (base_dev),
 				       name)->base;
 	if (unlikely (surface->intel.drm.bo == NULL)) {
 	    free (surface);
 	    return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
 	}
-	to_intel_bo (surface->intel.drm.bo)->stride = stride;
+	i915_surface_get_bo (surface)->stride = stride;
 
-	surface->map0 |= MS3_tiling (to_intel_bo (surface->intel.drm.bo)->tiling);
+	surface->map0 |= MS3_tiling (i915_surface_get_bo (surface)->tiling);
     }
 
     return &surface->intel.drm.base;
@@ -2647,7 +2647,7 @@ i915_surface_create_from_cacheable_image_internal (i915_device_t *device,
 	    return surface;
 
 	status = intel_bo_put_image (&device->intel,
-				     to_intel_bo (surface->intel.drm.bo),
+				     i915_surface_get_bo (surface),
 				     image,
 				     0, 0,
 				     width, height,
@@ -2795,14 +2795,14 @@ i915_surface_create_from_cacheable_image (cairo_drm_device_t *device,
 static cairo_status_t
 i915_surface_enable_scan_out (void *abstract_surface)
 {
-    i915_surface_t *surface = abstract_surface;
+    i915_surface_t *surface = _cairo_abstract_surface_cast_i915 (abstract_surface);
     intel_bo_t *bo;
     cairo_status_t status;
 
     if (unlikely (surface->intel.drm.bo == NULL))
 	return _cairo_error (CAIRO_STATUS_INVALID_SIZE);
 
-    bo = to_intel_bo (surface->intel.drm.bo);
+    bo = i915_surface_get_bo (surface);
     if (bo->tiling == I915_TILING_Y) {
 	status = i915_surface_batch_flush (surface);
 	if (unlikely (status))
@@ -2854,7 +2854,7 @@ i915_device_throttle (cairo_drm_device_t *device)
 static void
 i915_device_destroy (void *data)
 {
-    i915_device_t *device = data;
+    i915_device_t *device = _cairo_device_cast_i915 (data);
 
     if (device->last_vbo)
 	intel_bo_destroy (&device->intel, device->last_vbo);
diff --git a/src/drm/cairo-drm-i965-glyphs.c b/src/drm/cairo-drm-i965-glyphs.c
index c66a63d73..0ae52c7e4 100644
--- a/src/drm/cairo-drm-i965-glyphs.c
+++ b/src/drm/cairo-drm-i965-glyphs.c
@@ -157,7 +157,7 @@ i965_surface_mask_internal (i965_surface_t *dst,
 			1. / mask->intel.drm.width,
 			1. / mask->intel.drm.height);
 
-    shader.mask.base.bo = to_intel_bo (mask->intel.drm.bo);
+    shader.mask.base.bo = i965_surface_get_bo (mask);
     shader.mask.base.format = mask->intel.drm.format;
     shader.mask.base.width = mask->intel.drm.width;
     shader.mask.base.height = mask->intel.drm.height;
diff --git a/src/drm/cairo-drm-i965-private.h b/src/drm/cairo-drm-i965-private.h
index 79568a63d..7bb1985f2 100644
--- a/src/drm/cairo-drm-i965-private.h
+++ b/src/drm/cairo-drm-i965-private.h
@@ -315,6 +315,33 @@ struct i965_surface {
     uint32_t offset;
 };
 
+static inline i965_surface_t*
+cairo_abstract_surface_cast_i965 (cairo_surface_t *surface)
+{
+    return cairo_container_of (
+	cairo_abstract_surface_cast_intel (surface),
+	i965_surface_t,
+	intel);
+}
+
+static inline i965_device_t *
+_cairo_intel_device_cast_i965 (intel_device_t *device)
+{
+    return container_of (device, intel_device_t, intel);
+}
+
+static inline i965_device_t *
+_cairo_device_cast_i965 (void *device)
+{
+    return _cairo_intel_device_cast_i965 (_cairo_device_cast_intel (device));
+}
+
+static inline intel_bo_t *
+i965_surface_get_bo (const i965_surface_t *surface)
+{
+    return _cairo_intel_surface_get_bo (surface->intel);
+}
+
 struct i965_pending_relocation {
     uint32_t offset;
     uint32_t read_domains;
diff --git a/src/drm/cairo-drm-i965-shader.c b/src/drm/cairo-drm-i965-shader.c
index eed5f5f09..eb8ea0095 100644
--- a/src/drm/cairo-drm-i965-shader.c
+++ b/src/drm/cairo-drm-i965-shader.c
@@ -264,7 +264,7 @@ i965_surface_clone (i965_device_t *device,
 	return clone->intel.drm.base.status;
 
     status = intel_bo_put_image (&device->intel,
-				 to_intel_bo (clone->intel.drm.bo),
+				 _cairo_intel_surface_get_bo (&(clone->intel)),
 				 image,
 				 0, 0,
 				 image->width, image->height,
@@ -308,8 +308,8 @@ i965_surface_clone_subimage (i965_device_t *device,
     if (unlikely (clone->intel.drm.base.status))
 	return clone->intel.drm.base.status;
 
-    status = intel_bo_put_image (to_intel_device (clone->intel.drm.base.device),
-				 to_intel_bo (clone->intel.drm.bo),
+    status = intel_bo_put_image (_cairo_intel_surface_get_device (&(clone->intel)),
+				 _cairo_intel_surface_get_bo (&(clone->intel.drm.bo)),
 				 image,
 				 extents->x, extents->y,
 				 extents->width, extents->height,
@@ -420,12 +420,12 @@ i965_shader_acquire_surface (i965_shader_t *shader,
 			    return status;
 		    }
 
-		    if (to_intel_bo (s->intel.drm.bo)->batch_write_domain)
+		    if (_cairo_intel_surface_get_bo (&(s->intel))->batch_write_domain)
 			i965_pipelined_flush (i965_device (s));
 
 		    src->type.fragment = FS_SURFACE;
 
-		    src->base.bo = to_intel_bo (s->intel.drm.bo);
+		    src->base.bo = i965_surface_get_bo (s);
 		    src->base.format = s->intel.drm.format;
 		    src->base.content = s->intel.drm.base.content;
 		    src->base.width = sub->extents.width;
@@ -472,7 +472,7 @@ i965_shader_acquire_surface (i965_shader_t *shader,
 		    i965_pipelined_flush (i965_device (s));
 		    src->type.fragment = FS_SURFACE;
 
-		    src->base.bo = to_intel_bo (clone->intel.drm.bo);
+		    src->base.bo = i965_surface_get_bo (clone);
 		    src->base.format = clone->intel.drm.format;
 		    src->base.content = clone->intel.drm.base.content;
 		    src->base.width = clone->intel.drm.width;
@@ -494,12 +494,12 @@ i965_shader_acquire_surface (i965_shader_t *shader,
 			    return status;
 		    }
 
-		    if (to_intel_bo (s->intel.drm.bo)->batch_write_domain)
+		    if (i965_surface_get_bo (s)->batch_write_domain)
 			i965_pipelined_flush (i965_device (s));
 
 		    src->type.fragment = FS_SURFACE;
 
-		    src->base.bo = to_intel_bo (s->intel.drm.bo);
+		    src->base.bo = i965_surface_get_bo (s);
 		    src->base.format = s->intel.drm.format;
 		    src->base.content = s->intel.drm.base.content;
 		    src->base.width = s->intel.drm.width;
@@ -536,7 +536,7 @@ i965_shader_acquire_surface (i965_shader_t *shader,
 		    i965_pipelined_flush (i965_device (s));
 		    src->type.fragment = FS_SURFACE;
 
-		    src->base.bo = to_intel_bo (clone->intel.drm.bo);
+		    src->base.bo = i965_surface_get_bo (clone);
 		    src->base.format = clone->intel.drm.format;
 		    src->base.content = clone->intel.drm.base.content;
 		    src->base.width = clone->intel.drm.width;
@@ -562,7 +562,7 @@ i965_shader_acquire_surface (i965_shader_t *shader,
 					 shader->target->intel.drm.base.backend);
 	if (s != NULL) {
 	    i965_device_t *device = i965_device (shader->target);
-	    intel_bo_t *bo = to_intel_bo (s->intel.drm.bo);
+	    intel_bo_t *bo = i965_surface_get_bo (s);
 
 	    if (bo->purgeable &&
 		! intel_bo_madvise (&device->intel, bo, I915_MADV_WILLNEED))
@@ -599,12 +599,12 @@ i965_shader_acquire_surface (i965_shader_t *shader,
 		return status;
 
 	    /* XXX? */
-	    //intel_bo_mark_purgeable (to_intel_bo (s->intel.drm.bo), TRUE);
+	    //intel_bo_mark_purgeable (i965_surface_get_bo (s), TRUE);
 	}
 
 	src->type.fragment = FS_SURFACE;
 
-	src->base.bo = to_intel_bo (s->intel.drm.bo);
+	src->base.bo = i965_surface_get_bo (s);
 	src->base.content = s->intel.drm.base.content;
 	src->base.format = s->intel.drm.format;
 	src->base.width  = s->intel.drm.width;
@@ -741,7 +741,7 @@ i965_shader_set_clip (i965_shader_t *shader,
     assert (clip_surface->type == CAIRO_SURFACE_TYPE_DRM);
     s = (i965_surface_t *) clip_surface;
 
-    if (to_intel_bo (s->intel.drm.bo)->batch_write_domain)
+    if (i965_surface_get_bo (s-)->batch_write_domain)
 	i965_pipelined_flush (i965_device (s));
 
     channel = &shader->clip;
@@ -749,7 +749,7 @@ i965_shader_set_clip (i965_shader_t *shader,
     channel->type.vertex  = VS_NONE;
     channel->type.fragment = FS_SURFACE;
 
-    channel->base.bo = to_intel_bo (s->intel.drm.bo);
+    channel->base.bo = i965_surface_get_bo (s);
     channel->base.content = CAIRO_CONTENT_ALPHA;
     channel->base.format = CAIRO_FORMAT_A8;
     channel->base.width  = s->intel.drm.width;
@@ -774,25 +774,25 @@ i965_shader_check_aperture (i965_shader_t *shader,
     uint32_t size = device->exec.gtt_size;
 
     if (shader->target != device->target) {
-	const intel_bo_t *bo = to_intel_bo (shader->target->intel.drm.bo);
+	const intel_bo_t *bo = i965_surface_get_bo (shader->target);
 	if (bo->exec == NULL)
 	    size += bo->base.size;
     }
 
     if (shader->source.base.bo != NULL && shader->source.base.bo != device->source) {
-	const intel_bo_t *bo = to_intel_bo (shader->target->intel.drm.bo);
+	const intel_bo_t *bo = i965_surface_get_bo (shader->target);
 	if (bo->exec == NULL)
 	    size += bo->base.size;
     }
 
     if (shader->mask.base.bo != NULL && shader->mask.base.bo != device->mask) {
-	const intel_bo_t *bo = to_intel_bo (shader->target->intel.drm.bo);
+	const intel_bo_t *bo = i965_surface_get_bo (shader->target);
 	if (bo->exec == NULL)
 	    size += bo->base.size;
     }
 
     if (shader->clip.base.bo != NULL && shader->clip.base.bo != device->clip) {
-	const intel_bo_t *bo = to_intel_bo (shader->target->intel.drm.bo);
+	const intel_bo_t *bo = i965_surface_get_bo (shader->target);
 	if (bo->exec == NULL)
 	    size += bo->base.size;
     }
@@ -832,7 +832,7 @@ i965_shader_setup_dst (i965_shader_t *shader)
     if (unlikely (clone->intel.drm.base.status))
 	return clone->intel.drm.base.status;
 
-    if (to_intel_bo (s->intel.drm.bo)->batch_write_domain)
+    if (i965_surface_get_bo (s)->batch_write_domain)
 	i965_pipelined_flush (i965_device (s));
 
     channel = &shader->dst;
@@ -842,7 +842,7 @@ i965_shader_setup_dst (i965_shader_t *shader)
     channel->type.pattern = PATTERN_SURFACE;
 
     /* swap buffer objects */
-    channel->base.bo = to_intel_bo (s->intel.drm.bo);
+    channel->base.bo = i965_surface_get_bo (s);
     s->intel.drm.bo = ((cairo_drm_surface_t *) clone)->bo;
     ((cairo_drm_surface_t *) clone)->bo = &channel->base.bo->base;
 
@@ -1426,7 +1426,7 @@ create_wm_kernel (i965_device_t *device,
     brw_compile_init (&compile, device->is_g4x);
 
     if (key.entry.hash == FS_CONSTANT &&
-	to_intel_bo (shader->target->intel.drm.bo)->tiling)
+	i965_surface_get_bo (shader->target)->tiling)
     {
 	struct brw_instruction *insn;
 
@@ -2207,7 +2207,7 @@ emit_binding_table (i965_device_t *device,
 	shader->target->stream = device->surface.serial;
 	shader->target->offset = emit_surface_state (device,
 						     TRUE,
-						     to_intel_bo (shader->target->intel.drm.bo),
+						     i965_surface_get_bo (shader->target),
 						     shader->target->intel.drm.format,
 						     shader->target->intel.drm.width,
 						     shader->target->intel.drm.height,
diff --git a/src/drm/cairo-drm-i965-surface.c b/src/drm/cairo-drm-i965-surface.c
index 04050ef9c..e6ce1f1a2 100644
--- a/src/drm/cairo-drm-i965-surface.c
+++ b/src/drm/cairo-drm-i965-surface.c
@@ -707,7 +707,7 @@ i965_surface_flush (void *abstract_surface, unsigned flags)
 
     /* Forgo flushing on finish as the user cannot access the surface directly. */
     if (! surface->intel.drm.base.finished &&
-	to_intel_bo (surface->intel.drm.bo)->exec != NULL)
+	i965_surface_get_bo (surface)->exec != NULL)
     {
 	status = cairo_device_acquire (surface->intel.drm.base.device);
 	if (likely (status == CAIRO_STATUS_SUCCESS)) {
@@ -1094,7 +1094,7 @@ i965_surface_paint (void			*abstract_dst,
 		    const cairo_pattern_t	*source,
 		    cairo_clip_t		*clip)
 {
-    i965_surface_t *dst = abstract_dst;
+    i965_surface_t *dst = cairo_abstract_surface_cast_i965(abstract_dst);
     cairo_composite_rectangles_t extents;
     cairo_boxes_t boxes;
     cairo_box_t *clip_boxes = boxes.boxes_embedded;
@@ -1588,7 +1588,7 @@ i965_surface_create_internal (cairo_drm_device_t *base_dev,
 	assert (height <= I965_MAX_SIZE);
 
 	size = stride * height;
-	bo = intel_bo_create (to_intel_device (&base_dev->base),
+	bo = intel_bo_create (_cairo_drm_device_cast_intel (base_dev),
 			      size, size,
 			      gpu_target, tiling, stride);
 	if (bo == NULL) {
@@ -1685,7 +1685,7 @@ i965_surface_enable_scan_out (void *abstract_surface)
     if (unlikely (surface->intel.drm.bo == NULL))
 	return _cairo_error (CAIRO_STATUS_INVALID_SIZE);
 
-    bo = to_intel_bo (surface->intel.drm.bo);
+    bo = i965_surface_get_bo (surface);
     if (bo->tiling != I915_TILING_X) {
 	i965_device_t *device = i965_device (surface);
 	cairo_surface_pattern_t pattern;
@@ -1720,7 +1720,7 @@ i965_surface_enable_scan_out (void *abstract_surface)
 	/* swap buffer objects */
 	surface->intel.drm.bo = ((cairo_drm_surface_t *) clone)->bo;
 	((cairo_drm_surface_t *) clone)->bo = &bo->base;
-	bo = to_intel_bo (surface->intel.drm.bo);
+	bo = i965_surface_get_bo (surface);
 
 	cairo_surface_destroy (clone);
     }
@@ -1768,7 +1768,7 @@ _i965_device_throttle (cairo_drm_device_t *device)
 static void
 _i965_device_destroy (void *base)
 {
-    i965_device_t *device = base;
+    i965_device_t *device = _cairo_device_cast_i965 (base);
 
     i965_device_reset (device);
     i965_general_state_reset (device);
diff --git a/src/drm/cairo-drm-intel-private.h b/src/drm/cairo-drm-intel-private.h
index 0cfded1bd..4ba36a875 100644
--- a/src/drm/cairo-drm-intel-private.h
+++ b/src/drm/cairo-drm-intel-private.h
@@ -183,6 +183,15 @@ typedef struct _intel_surface {
     cairo_cache_entry_t snapshot_cache_entry;
 } intel_surface_t;
 
+static inline intel_surface_t*
+cairo_abstract_surface_cast_intel(cairo_surface_t* surface)
+{
+    return cairo_container_of(
+	_cairo_abstract_surface_cast_drm(surface),
+	intel_surface_t,
+	drm);
+}
+
 typedef void (*intel_reset_context_func_t) (void *device);
 
 typedef struct _intel_device {
@@ -214,21 +223,59 @@ typedef struct _intel_device {
 } intel_device_t;
 
 static inline intel_device_t *
-to_intel_device (cairo_device_t *base)
+_cairo_drm_device_cast_intel (cairo_drm_device_t *device)
+{
+    return cairo_container_of (
+	device,
+	intel_device_t,
+	base);
+}
+
+static inline const intel_device_t *
+_cairo_drm_device_cast_intel_const (const cairo_drm_device_t *device)
+{
+    return cairo_container_of (
+	device,
+	const intel_device_t,
+	base);
+}
+
+static inline intel_device_t *
+_cairo_device_cast_intel (cairo_device_t *device)
+{
+    return _cairo_drm_device_cast_intel (
+	_cairo_device_cast_drm (device));
+}
+
+static inline const intel_device_t *
+_cairo_device_cast_intel_const (const cairo_device_t *device)
+{
+    return _cairo_drm_device_cast_intel_const (
+	_cairo_device_cast_drm_const (device));
+}
+
+static inline intel_bo_t *
+_cairo_drm_bo_cast_intel (cairo_drm_bo_t *bo)
+{
+    return cairo_container_of (bo, intel_bo_t, base);
+}
+
+static inline intel_device_t *
+_cairo_intel_surface_get_device (intel_surface_t *surface)
 {
-    return (intel_device_t *) base;
+    return _cairo_device_cast_intel (surface->drm.base.device);
 }
 
 static inline intel_bo_t *
-to_intel_bo (cairo_drm_bo_t *base)
+_cairo_intel_surface_get_bo (const intel_surface_t *surface)
 {
-    return (intel_bo_t *) base;
+    return _cairo_drm_bo_cast_intel (surface->drm.bo);
 }
 
 static inline intel_bo_t *
 intel_bo_reference (intel_bo_t *bo)
 {
-    return to_intel_bo (cairo_drm_bo_reference (&bo->base));
+    return _cairo_drm_bo_cast_intel (cairo_drm_bo_reference (&bo->base));
 }
 
 cairo_private cairo_bool_t
diff --git a/src/drm/cairo-drm-intel-surface.c b/src/drm/cairo-drm-intel-surface.c
index 123572022..9965aa311 100644
--- a/src/drm/cairo-drm-intel-surface.c
+++ b/src/drm/cairo-drm-intel-surface.c
@@ -53,10 +53,11 @@ intel_surface_create_similar (void			*abstract_surface,
 cairo_status_t
 intel_surface_finish (void *abstract_surface)
 {
-    intel_surface_t *surface = abstract_surface;
+    intel_surface_t *surface = cairo_abstract_surface_cast_intel(abstract_surface);
+
+    intel_bo_in_flight_add (_cairo_intel_surface_get_device (surface),
+			    _cairo_intel_surface_get_bo (surface));
 
-    intel_bo_in_flight_add (to_intel_device (surface->drm.base.device),
-			    to_intel_bo (surface->drm.bo));
     return _cairo_drm_surface_finish (&surface->drm);
 }
 
@@ -72,7 +73,7 @@ intel_surface_acquire_source_image (void *abstract_surface,
 				    cairo_image_surface_t **image_out,
 				    void **image_extra)
 {
-    intel_surface_t *surface = abstract_surface;
+    intel_surface_t *surface = cairo_abstract_surface_cast_intel(abstract_surface);
     cairo_surface_t *image;
     cairo_status_t status;
     void *ptr;
@@ -93,8 +94,9 @@ intel_surface_acquire_source_image (void *abstract_surface,
 	    return status;
     }
 
-    ptr = intel_bo_map (to_intel_device (surface->drm.base.device),
-			to_intel_bo (surface->drm.bo));
+    ptr = intel_bo_map (_cairo_intel_surface_get_device (surface),
+			_cairo_intel_surface_get_bo (surface));
+
     if (unlikely (ptr == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
@@ -125,7 +127,7 @@ intel_surface_release_source_image (void *abstract_surface,
 cairo_surface_t *
 intel_surface_map_to_image (void *abstract_surface)
 {
-    intel_surface_t *surface = abstract_surface;
+    intel_surface_t *surface = cairo_abstract_surface_cast_intel(abstract_surface);
 
     if (surface->drm.fallback == NULL) {
 	cairo_surface_t *image;
@@ -138,8 +140,9 @@ intel_surface_map_to_image (void *abstract_surface)
 		return _cairo_surface_create_in_error (status);
 	}
 
-	ptr = intel_bo_map (to_intel_device (surface->drm.base.device),
-			    to_intel_bo (surface->drm.bo));
+	ptr = intel_bo_map (_cairo_intel_surface_get_device (surface),
+			    _cairo_intel_surface_get_bo (surface));
+
 	if (unlikely (ptr == NULL))
 	    return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY);
 
@@ -160,7 +163,7 @@ intel_surface_map_to_image (void *abstract_surface)
 cairo_status_t
 intel_surface_flush (void *abstract_surface, unsigned flags)
 {
-    intel_surface_t *surface = abstract_surface;
+    intel_surface_t *surface = cairo_abstract_surface_cast_intel(abstract_surface);
     cairo_status_t status;
 
     if (flags)
@@ -323,7 +326,7 @@ intel_surface_create (cairo_drm_device_t *device,
 	height = (height + 1) & -2;
 	surface->drm.stride =
 	    cairo_format_stride_for_width (surface->drm.format, width);
-	surface->drm.bo = &intel_bo_create (to_intel_device (&device->base),
+	surface->drm.bo = &intel_bo_create (_cairo_drm_device_cast_intel (device),
 					    surface->drm.stride * height,
 					    surface->drm.stride * height,
 					    TRUE, I915_TILING_NONE, surface->drm.stride)->base;
@@ -371,8 +374,9 @@ intel_surface_create_for_name (cairo_drm_device_t *device,
     if (width && height) {
 	surface->drm.stride = stride;
 
-	surface->drm.bo = &intel_bo_create_for_name (to_intel_device (&device->base),
+	surface->drm.bo = &intel_bo_create_for_name (_cairo_drm_device_cast_intel (device),
 						      name)->base;
+
 	if (unlikely (surface->drm.bo == NULL)) {
 	    status = _cairo_drm_surface_finish (&surface->drm);
 	    free (surface);
@@ -387,12 +391,12 @@ intel_surface_create_for_name (cairo_drm_device_t *device,
 static cairo_status_t
 intel_surface_enable_scan_out (void *abstract_surface)
 {
-    intel_surface_t *surface = abstract_surface;
+    intel_surface_t *surface = cairo_abstract_surface_cast_intel(abstract_surface);
 
     if (unlikely (surface->drm.bo == NULL))
 	return _cairo_error (CAIRO_STATUS_INVALID_SIZE);
 
-    to_intel_bo (surface->drm.bo)->tiling = I915_TILING_X;
+    _cairo_intel_surface_get_bo (surface)->tiling = I915_TILING_X;
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -400,7 +404,7 @@ intel_surface_enable_scan_out (void *abstract_surface)
 static cairo_int_status_t
 intel_device_throttle (cairo_drm_device_t *device)
 {
-    intel_throttle (to_intel_device (&device->base));
+    intel_throttle (_cairo_drm_device_cast_intel (device));
     return CAIRO_STATUS_SUCCESS;
 }
 
diff --git a/src/drm/cairo-drm-intel.c b/src/drm/cairo-drm-intel.c
index b5459d90e..c70f6d2a5 100644
--- a/src/drm/cairo-drm-intel.c
+++ b/src/drm/cairo-drm-intel.c
@@ -493,8 +493,8 @@ FAIL:
 static void
 intel_bo_release (void *_dev, void *_bo)
 {
-    intel_device_t *device = _dev;
-    intel_bo_t *bo = _bo;
+    intel_device_t *device = _cairo_drm_device_cast_intel(_dev);
+    intel_bo_t *bo = _cairo_drm_bo_cast_intel(_bo);
 
     if (bo->virtual != NULL)
 	intel_bo_unmap (bo);
diff --git a/src/drm/cairo-drm-private.h b/src/drm/cairo-drm-private.h
index 4ba8f5b1e..e2d2cea3c 100644
--- a/src/drm/cairo-drm-private.h
+++ b/src/drm/cairo-drm-private.h
@@ -142,6 +142,46 @@ typedef struct _cairo_drm_surface {
     uint32_t map_count;
 } cairo_drm_surface_t;
 
+/* cast from abstract void* pointer */
+static inline cairo_drm_device_t*
+_cairo_abstract_device_cast_drm(cairo_device_t* dev)
+{
+    return cairo_container_of(
+	dev,
+	cairo_drm_device_t,
+	base);
+}
+
+static inline cairo_drm_surface_t*
+_cairo_abstract_surface_cast_drm(cairo_surface_t* surface)
+{
+    return cairo_container_of(surface, cairo_drm_surface_t, base);
+}
+
+static inline cairo_drm_surface_t*
+_cairo_surface_cast_drm (cairo_surface_t* surface)
+{
+    return cairo_container_of (surface, cairo_drm_surface_t, base);
+}
+
+static inline const cairo_drm_surface_t*
+_cairo_surface_cast_drm_const (const cairo_surface_t* surface)
+{
+    return cairo_container_of (surface, const cairo_drm_surface_t, base);
+}
+
+static inline cairo_drm_device_t*
+_cairo_device_cast_drm(cairo_device_t *device)
+{
+    return cairo_container_of (device, cairo_drm_device_t, base);
+}
+
+static inline const cairo_drm_device_t*
+_cairo_device_cast_drm_const(const cairo_device_t *device)
+{
+    return cairo_container_of (device, const cairo_drm_device_t, base);
+}
+
 static inline cairo_drm_bo_t *
 cairo_drm_bo_reference (cairo_drm_bo_t *bo)
 {
@@ -149,6 +189,12 @@ cairo_drm_bo_reference (cairo_drm_bo_t *bo)
     return bo;
 }
 
+static inline cairo_drm_device_t *
+_cairo_drm_surface_get_device (cairo_drm_surface_t *surface)
+{
+    return _cairo_device_cast_drm(surface->base.device);
+}
+
 static cairo_always_inline void
 cairo_drm_bo_destroy (cairo_device_t *abstract_device,
 		      cairo_drm_bo_t *bo)
diff --git a/src/drm/cairo-drm-radeon-private.h b/src/drm/cairo-drm-radeon-private.h
index 076852835..107f55ba8 100644
--- a/src/drm/cairo-drm-radeon-private.h
+++ b/src/drm/cairo-drm-radeon-private.h
@@ -53,6 +53,102 @@ typedef struct _radeon_device {
     uint64_t gart_limit;
 } radeon_device_t;
 
+typedef struct _radeon_surface {
+    cairo_drm_surface_t base;
+} radeon_surface_t;
+
+/* cast void* to radeon_device_t* */
+static inline radeon_surface_t *
+_cairo_abstract_surface_cast_radeon (cairo_surface_t *surface)
+{
+    return cairo_container_of (
+	_cairo_abstract_surface_cast_drm (surface),
+	radeon_surface_t,
+	base);
+}
+
+/* cast cairo_drm_device_t* to radeon_device_t* */
+static inline radeon_surface_t *
+_cairo_drm_surface_cast_radeon (cairo_drm_surface_t *surface)
+{
+    return cairo_container_of (surface, radeon_surface_t, base);
+}
+
+/* cast const cairo_drm_device_t* to const radeon_device_t* */
+static inline const radeon_surface_t *
+_cairo_drm_surface_cast_radeon_const (const cairo_drm_surface_t *surface)
+{
+    return cairo_container_of (surface, const radeon_surface_t, base);
+}
+
+/* cast cairo_device_t to radeon_device_t */
+static inline radeon_surface_t *
+_cairo_surface_cast_radeon (cairo_surface_t *surface)
+{
+    return _cairo_drm_surface_cast_radeon (
+	_cairo_surface_cast_drm (surface));
+}
+
+/* cast const cairo_device_t* to const radeon_device_t* */
+static inline const radeon_surface_t *
+_cairo_surface_cast_radeon_cast (const cairo_surface_t *surface)
+{
+    return _cairo_drm_surface_cast_radeon_const (
+	_cairo_surface_cast_drm_const (surface));
+}
+
+static inline radeon_device_t *
+_cairo_drm_device_cast_radeon (cairo_drm_device_t *device)
+{
+    return cairo_container_of (device, radeon_device_t, base);
+}
+
+static inline const radeon_device_t *
+_cairo_drm_device_cast_radeon_const (const cairo_drm_device_t *device)
+{
+    return cairo_container_of (device, const radeon_device_t, base);
+}
+
+static inline radeon_device_t *
+_cairo_device_cast_radeon (cairo_device_t *device)
+{
+    return _cairo_drm_device_cast_radeon (
+	_cairo_device_cast_drm (device));
+}
+
+static inline const radeon_device_t *
+_cairo_device_cast_radeon_const (const cairo_device_t *device)
+{
+    return _cairo_drm_device_cast_radeon_const (
+	_cairo_device_cast_drm_const (device));
+}
+
+static inline radeon_bo_t *
+_cairo_drm_bo_cast_radeon (cairo_drm_bo_t *bo)
+{
+    return cairo_container_of (bo, radeon_bo_t, base);
+}
+
+static inline const radeon_bo_t *
+_cairo_drm_bo_cast_radeon_const (const cairo_drm_bo_t *bo)
+{
+    return cairo_container_of (bo, const radeon_bo_t, base);
+}
+
+/* get radeon device from radeon surface */
+static inline radeon_device_t *
+_cairo_radeon_surface_get_device (const radeon_surface_t *surface)
+{
+    return _cairo_device_cast_radeon (surface->base.base.device);
+}
+
+/* get radeon bo from radeon surface */
+static inline radeon_bo_t *
+_cairo_radeon_surface_get_bo (const radeon_surface_t *surface)
+{
+    return _cairo_drm_bo_cast_radeon (surface->base.bo);
+}
+
 cairo_private cairo_status_t
 radeon_device_init (radeon_device_t *device, int fd);
 
diff --git a/src/drm/cairo-drm-radeon-surface.c b/src/drm/cairo-drm-radeon-surface.c
index 528aab77c..cb245f329 100644
--- a/src/drm/cairo-drm-radeon-surface.c
+++ b/src/drm/cairo-drm-radeon-surface.c
@@ -44,22 +44,6 @@
 
 #define MAX_SIZE 2048
 
-typedef struct _radeon_surface {
-    cairo_drm_surface_t base;
-} radeon_surface_t;
-
-static inline radeon_device_t *
-to_radeon_device (cairo_device_t *device)
-{
-    return (radeon_device_t *) device;
-}
-
-static inline radeon_bo_t *
-to_radeon_bo (cairo_drm_bo_t *bo)
-{
-    return (radeon_bo_t *) bo;
-}
-
 static cairo_surface_t *
 radeon_surface_create_similar (void			*abstract_surface,
 			      cairo_content_t		 content,
@@ -105,8 +89,8 @@ radeon_surface_acquire_source_image (void *abstract_surface,
 	    return status;
     }
 
-    image = radeon_bo_get_image (to_radeon_device (surface->base.base.device),
-				to_radeon_bo (surface->base.bo),
+    image = radeon_bo_get_image (_cairo_radeon_surface_get_device (surface),
+				 _cairo_radeon_surface_get_bo (surface),
 				&surface->base);
     status = image->status;
     if (unlikely (status))
@@ -142,8 +126,9 @@ radeon_surface_map_to_image (radeon_surface_t *surface)
 		return _cairo_surface_create_in_error (status);
 	}
 
-	ptr = radeon_bo_map (to_radeon_device (surface->base.base.device),
-			    to_radeon_bo (surface->base.bo));
+	ptr = radeon_bo_map (_cairo_radeon_surface_get_device (surface),
+			     _cairo_radeon_surface_get_bo (surface));
+
 	if (unlikely (ptr == NULL))
 	    return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY);
 
@@ -167,7 +152,7 @@ static cairo_status_t
 radeon_surface_flush (void *abstract_surface,
 		      unsigned flags)
 {
-    radeon_surface_t *surface = abstract_surface;
+    radeon_surface_t *surface = _cairo_surface_cast_radeon(abstract_surface);
     cairo_status_t status;
 
     if (flags)
@@ -326,7 +311,7 @@ radeon_surface_create_internal (cairo_drm_device_t *device,
 	surface->base.stride =
 	    cairo_format_stride_for_width (surface->base.format, width);
 
-	surface->base.bo = radeon_bo_create (to_radeon_device (&device->base),
+	surface->base.bo = radeon_bo_create (_cairo_drm_device_cast_radeon (device),
 					     surface->base.stride * height,
 					     RADEON_GEM_DOMAIN_GTT);
 
@@ -393,7 +378,7 @@ radeon_surface_create_for_name (cairo_drm_device_t *device,
     if (width && height) {
 	surface->base.stride = stride;
 
-	surface->base.bo = radeon_bo_create_for_name (to_radeon_device (&device->base),
+	surface->base.bo = radeon_bo_create_for_name (_cairo_drm_device_cast_radeon(device),
 						      name);
 
 	if (unlikely (surface->base.bo == NULL)) {
@@ -409,7 +394,7 @@ radeon_surface_create_for_name (cairo_drm_device_t *device,
 static void
 radeon_device_destroy (void *data)
 {
-    radeon_device_t *device = data;
+    radeon_device_t *device = _cairo_device_cast_radeon (data);
 
     radeon_device_fini (device);
 
diff --git a/src/drm/cairo-drm-radeon.c b/src/drm/cairo-drm-radeon.c
index 8bc91bfe0..842994dd9 100644
--- a/src/drm/cairo-drm-radeon.c
+++ b/src/drm/cairo-drm-radeon.c
@@ -255,8 +255,8 @@ radeon_bo_create_for_name (radeon_device_t *device,
 static void
 radeon_bo_release (void *_dev, void *_bo)
 {
-    radeon_device_t *device = _dev;
-    radeon_bo_t *bo = _bo;
+    radeon_device_t *device = _cairo_device_cast_radeon(_dev);
+    radeon_bo_t *bo = _cairo_drm_bo_cast_radeon(_bo);
 
     _cairo_drm_bo_close (&device->base, &bo->base);
     _cairo_freepool_free (&device->bo_pool, bo);
@@ -271,10 +271,10 @@ radeon_bo_get_image (const radeon_device_t *device,
     uint8_t *dst;
     int size, row;
 
-    image = (cairo_image_surface_t *)
+    image = _cairo_surface_cast_image (
 	cairo_image_surface_create (surface->format,
 				    surface->width,
-				    surface->height);
+				    surface->height));
     if (unlikely (image->base.status))
 	return &image->base;
 
diff --git a/src/drm/cairo-drm-surface.c b/src/drm/cairo-drm-surface.c
index 8c4dd0ee8..ee514ddf1 100644
--- a/src/drm/cairo-drm-surface.c
+++ b/src/drm/cairo-drm-surface.c
@@ -76,7 +76,7 @@ cairo_bool_t
 _cairo_drm_surface_get_extents (void *abstract_surface,
 			        cairo_rectangle_int_t *rectangle)
 {
-    cairo_drm_surface_t *surface = abstract_surface;
+    cairo_drm_surface_t *surface = _cairo_abstract_surface_cast_drm(abstract_surface);
 
     rectangle->x = 0;
     rectangle->y = 0;
@@ -233,7 +233,7 @@ cairo_drm_surface_get_handle (cairo_surface_t *abstract_surface)
 cairo_int_status_t
 _cairo_drm_surface_flink (void *abstract_surface)
 {
-    cairo_drm_surface_t *surface = abstract_surface;
+    cairo_drm_surface_t *surface = _cairo_abstract_surface_cast_drm(abstract_surface);
 
     return _cairo_drm_bo_flink ((cairo_drm_device_t *) surface->base.device,
 				surface->bo);
diff --git a/src/drm/cairo-drm.c b/src/drm/cairo-drm.c
index ad8c827bf..3f79d3569 100644
--- a/src/drm/cairo-drm.c
+++ b/src/drm/cairo-drm.c
@@ -63,7 +63,7 @@ get_udev_property(struct udev_device *device, const char *name)
 static void
 _device_flush (void *abstract_device)
 {
-    cairo_drm_device_t *device = abstract_device;
+    cairo_drm_device_t *device = _cairo_abstract_device_cast_drm(abstract_device);
 
     device->device.flush (device);
 }
@@ -71,7 +71,7 @@ _device_flush (void *abstract_device)
 static void
 _device_finish (void *abstract_device)
 {
-    cairo_drm_device_t *device = abstract_device;
+    cairo_drm_device_t *device = _cairo_abstract_device_cast_drm(abstract_device);
 
     CAIRO_MUTEX_LOCK (_cairo_drm_device_mutex);
     if (device->prev != NULL)
@@ -93,7 +93,7 @@ _device_finish (void *abstract_device)
 static void
 _device_destroy (void *abstract_device)
 {
-    cairo_drm_device_t *device = abstract_device;
+    cairo_drm_device_t *device = _cairo_abstract_device_cast_drm(abstract_device);
 
     device->device.destroy (device);
 }
@@ -344,7 +344,7 @@ _cairo_drm_device_reset_static_data (void)
 int
 cairo_drm_device_get_fd (cairo_device_t *abstract_device)
 {
-    cairo_drm_device_t *device = (cairo_drm_device_t *) abstract_device;
+    cairo_drm_device_t *device = _cairo_abstract_device_cast_drm(abstract_device);
 
     if (device->base.status)
 	return -1;
@@ -362,7 +362,7 @@ _cairo_drm_device_fini (cairo_drm_device_t *device)
 void
 cairo_drm_device_throttle (cairo_device_t *abstract_device)
 {
-    cairo_drm_device_t *device = (cairo_drm_device_t *) abstract_device;
+    cairo_drm_device_t *device = _cairo_abstract_device_cast_drm(abstract_device);
     cairo_status_t status;
 
     if (unlikely (device->base.status))
-- 
2.11.0.rc0.7.gbe5a750





More information about the cairo mailing list