[cairo] [PATCH 39/71] drm: generalized *_surface_acquire_source_image() functions

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


The driver-specific drm backends have their individual implementation,
which is generalized by moving out the driver specific parts to
their own callbacks.

Signed-off-by: Enrico Weigelt, metux IT consult <enrico.weigelt at gr13.net>
---
 src/drm/cairo-drm-i915-surface.c   |  2 +-
 src/drm/cairo-drm-i965-surface.c   |  2 +-
 src/drm/cairo-drm-intel-private.h  |  5 ---
 src/drm/cairo-drm-intel-surface.c  | 57 +---------------------------------
 src/drm/cairo-drm-private.h        | 11 +++++--
 src/drm/cairo-drm-radeon-private.h |  6 ++--
 src/drm/cairo-drm-radeon-surface.c | 44 +-------------------------
 src/drm/cairo-drm-radeon.c         | 12 +++++---
 src/drm/cairo-drm-surface.c        | 63 ++++++++++++++++++++++++++++++++++++++
 9 files changed, 87 insertions(+), 115 deletions(-)

diff --git a/src/drm/cairo-drm-i915-surface.c b/src/drm/cairo-drm-i915-surface.c
index dd8ef012b..c7e0fef55 100644
--- a/src/drm/cairo-drm-i915-surface.c
+++ b/src/drm/cairo-drm-i915-surface.c
@@ -2359,7 +2359,7 @@ static const cairo_surface_backend_t i915_surface_backend = {
     .create_context		= _cairo_default_context_create,
     .create_similar		= i915_surface_create_similar,
     .finish			= i915_surface_finish,
-    .acquire_source_image	= intel_surface_acquire_source_image,
+    .acquire_source_image	= _cairo_drm_surface_acquire_source_image,
     .release_source_image	= intel_surface_release_source_image,
     .get_extents		= _cairo_drm_surface_get_extents,
     .get_font_options		= _cairo_drm_surface_get_font_options,
diff --git a/src/drm/cairo-drm-i965-surface.c b/src/drm/cairo-drm-i965-surface.c
index 825555fe3..8343f9223 100644
--- a/src/drm/cairo-drm-i965-surface.c
+++ b/src/drm/cairo-drm-i965-surface.c
@@ -1496,7 +1496,7 @@ static const cairo_surface_backend_t i965_surface_backend = {
     .create_context		= _cairo_default_context_create,
     .create_similar		= i965_surface_create_similar,
     .finish			= i965_surface_finish,
-    .acquire_source_image	= intel_surface_acquire_source_image,
+    .acquire_source_image	= _cairo_drm_surface_acquire_source_image,
     .release_source_image	= intel_surface_release_source_image,
     .get_extents		= _cairo_drm_surface_get_extents,
     .get_font_options		= _cairo_drm_surface_get_font_options,
diff --git a/src/drm/cairo-drm-intel-private.h b/src/drm/cairo-drm-intel-private.h
index ace9742e8..570494c59 100644
--- a/src/drm/cairo-drm-intel-private.h
+++ b/src/drm/cairo-drm-intel-private.h
@@ -429,11 +429,6 @@ intel_snapshot_cache_thaw (intel_device_t *device);
 cairo_private void
 intel_throttle (intel_device_t *device);
 
-cairo_private cairo_status_t
-intel_surface_acquire_source_image (void *abstract_surface,
-				    cairo_image_surface_t **image_out,
-				    void **image_extra);
-
 cairo_private void
 intel_surface_release_source_image (void *abstract_surface,
 				    cairo_image_surface_t *image,
diff --git a/src/drm/cairo-drm-intel-surface.c b/src/drm/cairo-drm-intel-surface.c
index 3000f2ac3..0f08dc62a 100644
--- a/src/drm/cairo-drm-intel-surface.c
+++ b/src/drm/cairo-drm-intel-surface.c
@@ -61,61 +61,6 @@ intel_surface_finish (void *abstract_surface)
     return _cairo_drm_surface_finish (&surface->drm);
 }
 
-static void
-surface_finish_and_destroy (cairo_surface_t *surface)
-{
-    cairo_surface_finish (surface);
-    cairo_surface_destroy (surface);
-}
-
-cairo_status_t
-intel_surface_acquire_source_image (void *abstract_surface,
-				    cairo_image_surface_t **image_out,
-				    void **image_extra)
-{
-    intel_surface_t *surface = cairo_abstract_surface_cast_intel(abstract_surface);
-    cairo_surface_t *image;
-    cairo_status_t status;
-    void *ptr;
-
-    if (surface->drm.fallback != NULL) {
-	image = surface->drm.fallback;
-	goto DONE;
-    }
-
-    image = _cairo_surface_has_snapshot (&surface->drm.base,
-	                                 &_cairo_image_surface_backend);
-    if (image != NULL)
-	goto DONE;
-
-    if (surface->drm.base.backend->flush != NULL) {
-	status = surface->drm.base.backend->flush (surface, 0);
-	if (unlikely (status))
-	    return status;
-    }
-
-    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);
-
-    image = cairo_image_surface_create_for_data (ptr,
-						 surface->drm.format,
-						 surface->drm.width,
-						 surface->drm.height,
-						 surface->drm.stride);
-    if (unlikely (image->status))
-	return image->status;
-
-    _cairo_surface_attach_snapshot (&surface->drm.base, image, surface_finish_and_destroy);
-
-DONE:
-    *image_out = (cairo_image_surface_t *) cairo_surface_reference (image);
-    *image_extra = NULL;
-    return CAIRO_STATUS_SUCCESS;
-}
-
 void
 intel_surface_release_source_image (void *abstract_surface,
 				    cairo_image_surface_t *image,
@@ -151,7 +96,7 @@ static const cairo_surface_backend_t intel_surface_backend = {
     .create_context		= _cairo_default_context_create,
     .create_similar		= intel_surface_create_similar,
     .finish			= intel_surface_finish,
-    .acquire_source_image	= intel_surface_acquire_source_image,
+    .acquire_source_image	= _cairo_drm_surface_acquire_source_image,
     .release_source_image	= intel_surface_release_source_image,
     .get_extents		= _cairo_drm_surface_get_extents,
     .get_font_options		= _cairo_drm_surface_get_font_options,
diff --git a/src/drm/cairo-drm-private.h b/src/drm/cairo-drm-private.h
index 3917447bd..e975ad376 100644
--- a/src/drm/cairo-drm-private.h
+++ b/src/drm/cairo-drm-private.h
@@ -50,6 +50,7 @@
 
 typedef struct _cairo_drm_device cairo_drm_device_t;
 typedef struct _cairo_drm_bo cairo_drm_bo_t;
+typedef struct _cairo_drm_surface cairo_drm_surface_t;
 
 typedef cairo_drm_device_t *
 (*cairo_drm_device_create_func_t) (int fd,
@@ -93,6 +94,7 @@ typedef cairo_surface_t *
 typedef struct _cairo_drm_bo_backend {
     void (*release) (cairo_drm_device_t *device, cairo_drm_bo_t *bo);
     void *(*map)    (const cairo_drm_device_t *device, cairo_drm_bo_t *bo);
+    cairo_surface_t *(*get_image) (const cairo_drm_device_t *device, cairo_drm_bo_t *bo, const cairo_drm_surface_t *surface);
 } cairo_drm_bo_backend_t;
 
 typedef struct _cairo_drm_device_backend {
@@ -136,7 +138,7 @@ struct _cairo_drm_device {
     cairo_drm_device_t *next, *prev;
 };
 
-typedef struct _cairo_drm_surface {
+struct _cairo_drm_surface {
     cairo_surface_t base;
 
     cairo_drm_bo_t *bo;
@@ -146,7 +148,7 @@ typedef struct _cairo_drm_surface {
 
     cairo_surface_t *fallback;
     uint32_t map_count;
-} cairo_drm_surface_t;
+};
 
 /* cast from abstract void* pointer */
 static inline cairo_drm_device_t*
@@ -366,6 +368,11 @@ _cairo_drm_surface_glyphs (void				*abstract_surface,
 			   cairo_scaled_font_t		*scaled_font,
 			   const cairo_clip_t		*clip);
 
+cairo_private cairo_status_t
+_cairo_drm_surface_acquire_source_image (void *abstract_surface,
+					 cairo_image_surface_t **image_out,
+					 void **image_extra);
+
 /* h/w specific backends */
 
 cairo_private cairo_drm_device_t *
diff --git a/src/drm/cairo-drm-radeon-private.h b/src/drm/cairo-drm-radeon-private.h
index c2234fc20..1987c1347 100644
--- a/src/drm/cairo-drm-radeon-private.h
+++ b/src/drm/cairo-drm-radeon-private.h
@@ -192,8 +192,8 @@ cairo_private cairo_drm_bo_t *
 radeon_bo_create_for_name (radeon_device_t *dev, uint32_t name);
 
 cairo_private cairo_surface_t *
-radeon_bo_get_image (const radeon_device_t *device,
-	             radeon_bo_t *bo,
-		     const cairo_drm_surface_t *surface);
+_cairo_drm_radeon_bo_get_image (const cairo_drm_device_t *device,
+				cairo_drm_bo_t *bo,
+				const cairo_drm_surface_t *surface);
 
 #endif /* CAIRO_DRM_RADEON_PRIVATE_H */
diff --git a/src/drm/cairo-drm-radeon-surface.c b/src/drm/cairo-drm-radeon-surface.c
index 72d222af8..d1d9fe6b9 100644
--- a/src/drm/cairo-drm-radeon-surface.c
+++ b/src/drm/cairo-drm-radeon-surface.c
@@ -62,48 +62,6 @@ radeon_surface_finish (void *abstract_surface)
     return _cairo_drm_surface_finish (&surface->base);
 }
 
-static cairo_status_t
-radeon_surface_acquire_source_image (void *abstract_surface,
-				     cairo_image_surface_t **image_out,
-				     void **image_extra)
-{
-    radeon_surface_t *surface = abstract_surface;
-    cairo_surface_t *image;
-    cairo_status_t status;
-
-    /* XXX batch flush */
-
-    if (surface->base.fallback != NULL) {
-	image = surface->base.fallback;
-	goto DONE;
-    }
-
-    image = _cairo_surface_has_snapshot (&surface->base.base,
-	                                 &_cairo_image_surface_backend);
-    if (image != NULL)
-	goto DONE;
-
-    if (surface->base.base.backend->flush != NULL) {
-	status = surface->base.base.backend->flush (surface, 0);
-	if (unlikely (status))
-	    return status;
-    }
-
-    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))
-	return status;
-
-    _cairo_surface_attach_snapshot (&surface->base.base, image, cairo_surface_destroy);
-
-DONE:
-    *image_out = (cairo_image_surface_t *) cairo_surface_reference (image);
-    *image_extra = NULL;
-    return CAIRO_STATUS_SUCCESS;
-}
-
 static void
 radeon_surface_release_source_image (void *abstract_surface,
 				     cairo_image_surface_t *image,
@@ -142,7 +100,7 @@ static const cairo_surface_backend_t radeon_surface_backend = {
     .create_context		= _cairo_default_context_create,
     .create_similar		= radeon_surface_create_similar,
     .finish			= radeon_surface_finish,
-    .acquire_source_image	= radeon_surface_acquire_source_image,
+    .acquire_source_image	= _cairo_drm_surface_acquire_source_image,
     .release_source_image	= radeon_surface_release_source_image,
     .get_extents		= _cairo_drm_surface_get_extents,
     .get_font_options		= _cairo_drm_surface_get_font_options,
diff --git a/src/drm/cairo-drm-radeon.c b/src/drm/cairo-drm-radeon.c
index 2ef53d16d..72cc0b04c 100644
--- a/src/drm/cairo-drm-radeon.c
+++ b/src/drm/cairo-drm-radeon.c
@@ -253,14 +253,17 @@ radeon_bo_release (cairo_drm_device_t *_dev, cairo_drm_bo_t *_bo)
 }
 
 cairo_surface_t *
-radeon_bo_get_image (const radeon_device_t *device,
-	             radeon_bo_t *bo,
+_cairo_drm_radeon_bo_get_image (const cairo_drm_device_t *drm_dev,
+	             cairo_drm_bo_t *drm_bo,
 		     const cairo_drm_surface_t *surface)
 {
     cairo_image_surface_t *image;
     uint8_t *dst;
     int size, row;
 
+    const radeon_device_t *device = _cairo_drm_device_cast_radeon_const (drm_dev);
+    radeon_bo_t *bo = _cairo_drm_bo_cast_radeon (drm_bo);
+
     image = _cairo_surface_cast_image (
 	cairo_image_surface_create (surface->format,
 				    surface->width,
@@ -296,8 +299,9 @@ radeon_device_init (radeon_device_t *device, int fd)
 {
     _cairo_freepool_init (&device->base.bo_pool, sizeof (radeon_bo_t));
 
-    device->base.bo.release = radeon_bo_release;
-    device->base.bo.map     = _cairo_drm_radeon_bo_map;
+    device->base.bo.release   = radeon_bo_release;
+    device->base.bo.map       = _cairo_drm_radeon_bo_map;
+    device->base.bo.get_image = _cairo_drm_radeon_bo_get_image;
 
     return CAIRO_STATUS_SUCCESS;
 }
diff --git a/src/drm/cairo-drm-surface.c b/src/drm/cairo-drm-surface.c
index 217eb5797..47dccadc3 100644
--- a/src/drm/cairo-drm-surface.c
+++ b/src/drm/cairo-drm-surface.c
@@ -501,3 +501,66 @@ _cairo_drm_surface_glyphs (void				*abstract_surface,
 					    scaled_font,
 					    clip);
 }
+
+static void
+_surface_finish_and_destroy (cairo_surface_t *surface)
+{
+    cairo_surface_finish (surface);
+    cairo_surface_destroy (surface);
+}
+
+cairo_status_t
+_cairo_drm_surface_acquire_source_image (void *abstract_surface,
+					 cairo_image_surface_t **image_out,
+					 void **image_extra)
+{
+    cairo_drm_surface_t *surface = _cairo_surface_cast_drm(abstract_surface);
+    cairo_surface_t *image;
+    cairo_status_t status;
+
+    if (surface->fallback != NULL) {
+	image = surface->fallback;
+	goto DONE;
+    }
+
+    image = _cairo_surface_has_snapshot (&surface->base,
+					 &_cairo_image_surface_backend);
+    if (image != NULL)
+	goto DONE;
+
+    if (surface->base.backend->flush != NULL) {
+	status = surface->base.backend->flush (surface, 0);
+	if (unlikely (status))
+	    return status;
+    }
+
+    cairo_drm_device_t *drm_dev = _cairo_drm_surface_get_device (surface);
+
+    if (drm_dev->bo.get_image == NULL)
+    {
+	void *ptr = drm_dev->bo.map (drm_dev, surface->bo);
+
+	if (unlikely (ptr == NULL))
+	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+
+	image = cairo_image_surface_create_for_data (ptr,
+						     surface->format,
+						     surface->width,
+						     surface->height,
+						     surface->stride);
+    }
+    else
+    {
+	image = drm_dev->bo.get_image (drm_dev, surface->bo, surface);
+    }
+
+    if (unlikely (image->status))
+	return image->status;
+
+    _cairo_surface_attach_snapshot (&surface->base, image, _surface_finish_and_destroy);
+
+DONE:
+    *image_out = (cairo_image_surface_t *) cairo_surface_reference (image);
+    *image_extra = NULL;
+    return CAIRO_STATUS_SUCCESS;
+}
-- 
2.11.0.rc0.7.gbe5a750



More information about the cairo mailing list