[cairo] [PATCH 35/71] drm: consolidated bo_pool into drm_device

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


All driver-specific devices have their own bo_pool, which only needs
to be initialized differently (size of the driver-specific bo struct),
so consolidate it into cairo_drm_device_t.

Signed-off-by: Enrico Weigelt, metux IT consult <enrico.weigelt at gr13.net>
---
 src/drm/cairo-drm-bo.c             |  1 +
 src/drm/cairo-drm-intel-private.h  |  1 -
 src/drm/cairo-drm-intel.c          | 12 +++++-------
 src/drm/cairo-drm-private.h        | 15 +++++++++++++++
 src/drm/cairo-drm-radeon-private.h |  1 -
 src/drm/cairo-drm-radeon-surface.c |  2 +-
 src/drm/cairo-drm-radeon.c         | 35 ++++++-----------------------------
 src/drm/cairo-drm.c                |  4 +++-
 8 files changed, 31 insertions(+), 40 deletions(-)

diff --git a/src/drm/cairo-drm-bo.c b/src/drm/cairo-drm-bo.c
index 6b946ac62..532700e51 100644
--- a/src/drm/cairo-drm-bo.c
+++ b/src/drm/cairo-drm-bo.c
@@ -61,6 +61,7 @@ _cairo_drm_bo_open_for_name (const cairo_drm_device_t *dev,
     bo->name = name;
     bo->size = open.size;
     bo->handle = open.handle;
+    bo->mapped = NULL;
 
     return CAIRO_STATUS_SUCCESS;
 }
diff --git a/src/drm/cairo-drm-intel-private.h b/src/drm/cairo-drm-intel-private.h
index 43550eeca..3e5373327 100644
--- a/src/drm/cairo-drm-intel-private.h
+++ b/src/drm/cairo-drm-intel-private.h
@@ -203,7 +203,6 @@ typedef struct _intel_device {
     size_t gtt_max_size;
     size_t gtt_avail_size;
 
-    cairo_freepool_t bo_pool;
     cairo_list_t bo_in_flight;
 
     cairo_mutex_t mutex;
diff --git a/src/drm/cairo-drm-intel.c b/src/drm/cairo-drm-intel.c
index 9e8219f8a..86876e667 100644
--- a/src/drm/cairo-drm-intel.c
+++ b/src/drm/cairo-drm-intel.c
@@ -380,7 +380,7 @@ intel_bo_create (intel_device_t *device,
     }
 
     /* no cached buffer available, allocate fresh */
-    bo = _cairo_freepool_alloc (&device->bo_pool);
+    bo = _cairo_drm_bo_cast_intel (_cairo_drm_bo_from_pool (&device->base));
     if (unlikely (bo == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return bo;
@@ -412,7 +412,7 @@ intel_bo_create (intel_device_t *device,
     ret = ioctl (device->base.fd, DRM_IOCTL_I915_GEM_CREATE, &create);
     if (unlikely (ret != 0)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
-	_cairo_freepool_free (&device->bo_pool, bo);
+	_cairo_freepool_free (&device->base.bo_pool, bo);
 	return NULL;
     }
 
@@ -435,7 +435,7 @@ intel_bo_create_for_name (intel_device_t *device, uint32_t name)
     intel_bo_t *bo;
     int ret;
 
-    bo = _cairo_freepool_alloc (&device->bo_pool);
+    bo = _cairo_drm_bo_cast_intel (_cairo_drm_bo_from_pool (&device->base));
     if (unlikely (bo == NULL)) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
@@ -450,7 +450,6 @@ intel_bo_create_for_name (intel_device_t *device, uint32_t name)
 
     bo->full_size = bo->base.size;
     bo->offset = 0;
-    bo->base.mapped = NULL;
     bo->purgeable = 0;
     bo->busy = TRUE;
     bo->cpu = FALSE;
@@ -479,7 +478,7 @@ intel_bo_create_for_name (intel_device_t *device, uint32_t name)
     return bo;
 
 FAIL:
-    _cairo_freepool_free (&device->bo_pool, bo);
+    _cairo_freepool_free (&device->base.bo_pool, bo);
     return NULL;
 }
 
@@ -495,7 +494,7 @@ intel_bo_release (cairo_drm_device_t *_dev, cairo_drm_bo_t *_bo)
     assert (cairo_list_is_empty (&bo->cache_list));
 
     _cairo_drm_bo_close (_dev, _bo);
-    _cairo_freepool_free (&device->bo_pool, bo);
+    _cairo_freepool_free (&device->base.bo_pool, bo);
 }
 
 void
@@ -767,7 +766,6 @@ intel_device_fini (intel_device_t *device)
     _cairo_cache_fini (&device->snapshot_cache);
 
     _intel_gradient_cache_fini (device);
-    _cairo_freepool_fini (&device->bo_pool);
 
     _cairo_drm_device_fini (&device->base);
 }
diff --git a/src/drm/cairo-drm-private.h b/src/drm/cairo-drm-private.h
index 299ed3630..800d1598c 100644
--- a/src/drm/cairo-drm-private.h
+++ b/src/drm/cairo-drm-private.h
@@ -45,6 +45,8 @@
 #include "cairo-device-private.h"
 #include "cairo-reference-count-private.h"
 #include "cairo-surface-private.h"
+#include "cairo-freelist-type-private.h"
+#include "cairo-freelist-private.h"
 
 typedef struct _cairo_drm_device cairo_drm_device_t;
 typedef struct _cairo_drm_bo cairo_drm_bo_t;
@@ -128,6 +130,7 @@ struct _cairo_drm_device {
     cairo_drm_bo_backend_t bo;
     cairo_drm_surface_backend_t surface;
     cairo_drm_device_backend_t device;
+    cairo_freepool_t bo_pool;
 
     cairo_drm_device_t *next, *prev;
 };
@@ -200,6 +203,18 @@ _cairo_drm_surface_get_device (cairo_drm_surface_t *surface)
     return _cairo_device_cast_drm(surface->base.device);
 }
 
+static inline cairo_always_inline cairo_drm_bo_t *
+_cairo_drm_bo_from_pool (cairo_drm_device_t *device)
+{
+    cairo_drm_bo_t *bo = _cairo_freepool_alloc (&device->bo_pool);
+
+    if (unlikely(bo == NULL))
+	return NULL;
+    bo->mapped = NULL;
+
+    return bo;
+}
+
 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 3567562de..561518c8b 100644
--- a/src/drm/cairo-drm-radeon-private.h
+++ b/src/drm/cairo-drm-radeon-private.h
@@ -45,7 +45,6 @@ typedef struct _radeon_bo {
 
 typedef struct _radeon_device {
     cairo_drm_device_t base;
-    cairo_freepool_t bo_pool;
 
     uint64_t vram_limit;
     uint64_t gart_limit;
diff --git a/src/drm/cairo-drm-radeon-surface.c b/src/drm/cairo-drm-radeon-surface.c
index 7de342f08..0a1f27cba 100644
--- a/src/drm/cairo-drm-radeon-surface.c
+++ b/src/drm/cairo-drm-radeon-surface.c
@@ -379,7 +379,7 @@ radeon_device_destroy (void *data)
 {
     radeon_device_t *device = _cairo_device_cast_radeon (data);
 
-    radeon_device_fini (device);
+    _cairo_drm_device_fini (&device->base);
 
     free (data);
 }
diff --git a/src/drm/cairo-drm-radeon.c b/src/drm/cairo-drm-radeon.c
index bf92270ed..409c75e58 100644
--- a/src/drm/cairo-drm-radeon.c
+++ b/src/drm/cairo-drm-radeon.c
@@ -185,7 +185,7 @@ radeon_bo_create (radeon_device_t *device,
     radeon_bo_t *bo;
     int ret;
 
-    bo = _cairo_freepool_alloc (&device->bo_pool);
+    bo = _cairo_drm_bo_cast_radeon (_cairo_drm_bo_from_pool (&device->base));
     if (unlikely (bo == NULL))
 	return NULL;
 
@@ -199,15 +199,13 @@ radeon_bo_create (radeon_device_t *device,
 	ret = ioctl (device->base.fd, DRM_IOCTL_RADEON_GEM_CREATE, &create);
     } while (ret == -1 && errno == EINTR);
     if (ret == -1) {
-	_cairo_freepool_free (&device->bo_pool, bo);
+	_cairo_freepool_free (&device->base.bo_pool, bo);
 	return NULL;
     }
 
     bo->base.handle = create.handle;
     bo->base.size = size;
 
-    bo->base.mapped = NULL;
-
     bo->in_batch = FALSE;
     bo->read_domains = 0;
     bo->write_domain = 0;
@@ -223,18 +221,16 @@ radeon_bo_create_for_name (radeon_device_t *device,
     radeon_bo_t *bo;
     cairo_status_t status;
 
-    bo = _cairo_freepool_alloc (&device->bo_pool);
+    bo = _cairo_drm_bo_cast_radeon (_cairo_drm_bo_from_pool (&device->base));
     if (unlikely (bo == NULL))
 	return NULL;
 
     status = _cairo_drm_bo_open_for_name (&device->base, &bo->base, name);
     if (unlikely (status)) {
-	_cairo_freepool_free (&device->bo_pool, bo);
+	_cairo_freepool_free (&device->base.bo_pool, bo);
 	return NULL;
     }
 
-    bo->base.mapped = NULL;
-
     bo->in_batch = FALSE;
     bo->read_domains = 0;
     bo->write_domain = 0;
@@ -250,7 +246,7 @@ radeon_bo_release (cairo_drm_device_t *_dev, cairo_drm_bo_t *_bo)
     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);
+    _cairo_freepool_free (&device->base.bo_pool, bo);
 }
 
 cairo_surface_t *
@@ -292,31 +288,12 @@ radeon_bo_get_image (const radeon_device_t *device,
     return &image->base;
 }
 
-static void
-_radeon_device_init_bo_cache (radeon_device_t *device)
-{
-    _cairo_freepool_init (&device->bo_pool, sizeof (radeon_bo_t));
-}
-
 cairo_status_t
 radeon_device_init (radeon_device_t *device, int fd)
 {
-    _radeon_device_init_bo_cache (device);
+    _cairo_freepool_init (&device->base.bo_pool, sizeof (radeon_bo_t));
 
     device->base.bo.release = radeon_bo_release;
 
     return CAIRO_STATUS_SUCCESS;
 }
-
-static void
-_radeon_bo_cache_fini (radeon_device_t *device)
-{
-    _cairo_freepool_fini (&device->bo_pool);
-}
-
-void
-radeon_device_fini (radeon_device_t *device)
-{
-    _radeon_bo_cache_fini (device);
-    _cairo_drm_device_fini (&device->base);
-}
diff --git a/src/drm/cairo-drm.c b/src/drm/cairo-drm.c
index 5e8d40748..d4c107925 100644
--- a/src/drm/cairo-drm.c
+++ b/src/drm/cairo-drm.c
@@ -33,7 +33,7 @@
 #include "cairoint.h"
 
 #include "cairo-drm-private.h"
-
+#include "cairo-freelist-private.h"
 #include "cairo-device-private.h"
 #include "cairo-error-private.h"
 
@@ -368,6 +368,8 @@ _cairo_drm_device_fini (cairo_drm_device_t *device)
 {
     if (device->fd != -1)
 	close (device->fd);
+
+    _cairo_freepool_fini (&device->bo_pool);
 }
 
 void
-- 
2.11.0.rc0.7.gbe5a750



More information about the cairo mailing list