[cairo] [PATCH v8 26/71] drm: fixed handling of private pointers in scaled_font objects

Enrico Weigelt, metux IT consult enrico.weigelt at gr13.net
Thu Jun 30 15:46:04 UTC 2016


Signed-off-by: Enrico Weigelt, metux IT consult <enrico.weigelt at gr13.net>
---
 src/drm/cairo-drm-i915-glyphs.c   | 37 +++++++++++++++++++++++++++++++------
 src/drm/cairo-drm-i915-private.h  |  7 +++++++
 src/drm/cairo-drm-i965-glyphs.c   | 38 +++++++++++++++++++++++++++++++-------
 src/drm/cairo-drm-i965-private.h  |  7 +++++++
 src/drm/cairo-drm-intel-private.h |  4 ++++
 5 files changed, 80 insertions(+), 13 deletions(-)

diff --git a/src/drm/cairo-drm-i915-glyphs.c b/src/drm/cairo-drm-i915-glyphs.c
index fe140ae..1787f96 100644
--- a/src/drm/cairo-drm-i915-glyphs.c
+++ b/src/drm/cairo-drm-i915-glyphs.c
@@ -273,6 +273,22 @@ CLEANUP_SHADER:
     return status;
 }
 
+/* this is just a dummy to produce an unique address */
+static const char *_i915_scaled_font_key = "i915_scaled_font_t";
+
+/* destructor for the i915_scaled_font object */
+static void _i915_scaled_font_fini (
+    cairo_scaled_font_private_t *abstract_priv,
+    cairo_scaled_font_t* scaled_font)
+{
+    i915_scaled_font_private_t *i915_priv = cairo_container_of (abstract_priv, i915_scaled_font_private_t, base);
+
+    // FIXME: do we need to do something more ?
+
+    cairo_list_del (&i915_priv->base.link);
+    free (i915_priv);
+}
+
 cairo_int_status_t
 i915_surface_glyphs (void			*abstract_surface,
 		     cairo_operator_t		 op,
@@ -425,10 +441,19 @@ i915_surface_glyphs (void			*abstract_surface,
     device = i915_device (surface);
 
     _cairo_scaled_font_freeze_cache (scaled_font);
-    if (scaled_font->surface_private == NULL) {
-	scaled_font->surface_private = device;
-	scaled_font->surface_backend = surface->intel.drm.base.backend;
-	cairo_list_add (&scaled_font->link, &device->intel.fonts);
+
+    if (_cairo_scaled_font_find_private(scaled_font, _i915_scaled_font_key) == NULL) {
+	i915_scaled_font_private_t *priv = (i915_scaled_font_private_t*)calloc (1, sizeof (i915_scaled_font_private_t));
+
+	priv->device = device;
+	priv->backend = surface->intel.drm.base.backend;
+
+	_cairo_scaled_font_attach_private (
+		scaled_font,
+		&priv->base,
+		_i915_scaled_font_key,
+		_i915_scaled_font_fini
+	);
     }
 
     memset (glyph_cache, 0, sizeof (glyph_cache));
@@ -476,7 +501,7 @@ i915_surface_glyphs (void			*abstract_surface,
 	    continue;
 	}
 
-	if (scaled_glyph->surface_private == NULL) {
+	if (scaled_glyph->dev_private == NULL) {
 	    status = intel_get_glyph (&device->intel, scaled_font, scaled_glyph);
 	    if (unlikely (status == CAIRO_INT_STATUS_NOTHING_TO_DO)) {
 		status = CAIRO_INT_STATUS_SUCCESS;
@@ -486,7 +511,7 @@ i915_surface_glyphs (void			*abstract_surface,
 		goto FINISH;
 	}
 
-	glyph = intel_glyph_pin (scaled_glyph->surface_private);
+	glyph = intel_glyph_pin (scaled_glyph->dev_private);
 	if (glyph->cache->buffer.bo != last_bo) {
 	    intel_buffer_cache_t *cache = glyph->cache;
 
diff --git a/src/drm/cairo-drm-i915-private.h b/src/drm/cairo-drm-i915-private.h
index 22c9dba..0f2ce91 100644
--- a/src/drm/cairo-drm-i915-private.h
+++ b/src/drm/cairo-drm-i915-private.h
@@ -620,6 +620,7 @@ i915_fs_operand_pure_alpha (int pure)
 typedef struct i915_surface i915_surface_t;
 typedef struct i915_device i915_device_t;
 typedef struct i915_shader i915_shader_t;
+typedef struct i915_scaled_font_private i915_scaled_font_private_t;
 
 typedef void (*i915_add_rectangle_func_t) (const i915_shader_t *shader,
 					   int x, int y,
@@ -710,6 +711,12 @@ struct i915_device {
     uint8_t vbo_base[I915_VBO_SIZE];
 };
 
+struct i915_scaled_font_private {
+    cairo_scaled_font_private_t base;
+    i915_device_t *device;
+    const cairo_surface_backend_t *backend;
+};
+
 enum {
     CURRENT_SOURCE = 0x1,
     CURRENT_MASK = 0x2,
diff --git a/src/drm/cairo-drm-i965-glyphs.c b/src/drm/cairo-drm-i965-glyphs.c
index 4d42f27..814c98f 100644
--- a/src/drm/cairo-drm-i965-glyphs.c
+++ b/src/drm/cairo-drm-i965-glyphs.c
@@ -215,6 +215,22 @@ i965_surface_mask_internal (i965_surface_t *dst,
     return status;
 }
 
+/* this is just a dummy to produce an unique address */
+static const char *_i965_scaled_font_key = "i965_scaled_font_t";
+
+/* destructor for the i915_scaled_font object */
+static void _i965_scaled_font_fini (
+    cairo_scaled_font_private_t *abstract_priv,
+    cairo_scaled_font_t* scaled_font)
+{
+    i965_scaled_font_private_t *i915_priv = cairo_container_of (abstract_priv, i965_scaled_font_private_t, base);
+
+    // FIXME: do we need to do something more ?
+
+    cairo_list_del (&i915_priv->base.link);
+    free (i915_priv);
+}
+
 cairo_int_status_t
 i965_surface_glyphs (void			*abstract_surface,
 		     cairo_operator_t		 op,
@@ -341,11 +357,19 @@ i965_surface_glyphs (void			*abstract_surface,
 	goto CLEANUP_GLYPHS;
 
     _cairo_scaled_font_freeze_cache (scaled_font);
-    //private = _cairo_scaled_font_get_device (scaled_font, device);
-    if (scaled_font->surface_private == NULL) {
-	scaled_font->surface_private = device;
-	scaled_font->surface_backend = surface->intel.drm.base.backend;
-	cairo_list_add (&scaled_font->link, &device->intel.fonts);
+
+    if (_cairo_scaled_font_find_private(scaled_font, _i965_scaled_font_key) == NULL) {
+	i965_scaled_font_private_t *priv = (i965_scaled_font_private_t*)calloc (1, sizeof (i965_scaled_font_private_t));
+
+	priv->device = device;
+	priv->backend = surface->intel.drm.base.backend;
+
+	_cairo_scaled_font_attach_private (
+	    scaled_font,
+	    priv->base,
+	    _i965_scaled_font_key,
+	    _i965_scaled_font_fini
+	);
     }
 
     memset (glyph_cache, 0, sizeof (glyph_cache));
@@ -393,7 +417,7 @@ i965_surface_glyphs (void			*abstract_surface,
 	    continue;
 	}
 
-	if (scaled_glyph->surface_private == NULL) {
+	if (scaled_glyph->dev_private == NULL) {
 	    status = intel_get_glyph (&device->intel, scaled_font, scaled_glyph);
 	    if (unlikely (status == CAIRO_INT_STATUS_NOTHING_TO_DO)) {
 		status = CAIRO_STATUS_SUCCESS;
@@ -402,7 +426,7 @@ i965_surface_glyphs (void			*abstract_surface,
 	    if (unlikely (status))
 		goto FINISH;
 	}
-	glyph = intel_glyph_pin (scaled_glyph->surface_private);
+	glyph = intel_glyph_pin (scaled_glyph->dev_private);
 
 	if (glyph->cache->buffer.bo != last_bo) {
 	    intel_buffer_cache_t *cache = glyph->cache;
diff --git a/src/drm/cairo-drm-i965-private.h b/src/drm/cairo-drm-i965-private.h
index f3f8ece..ce01e78 100644
--- a/src/drm/cairo-drm-i965-private.h
+++ b/src/drm/cairo-drm-i965-private.h
@@ -255,6 +255,7 @@ typedef struct i965_device i965_device_t;
 typedef struct i965_surface i965_surface_t;
 typedef struct i965_shader i965_shader_t;
 typedef struct i965_stream i965_stream_t;
+typedef struct i965_scaled_font_private i965_scaled_font_private_t;
 
 struct i965_sf_state {
     cairo_hash_entry_t entry;
@@ -533,6 +534,12 @@ struct i965_shader {
     jmp_buf unwind;
 };
 
+struct i965_scaled_font_private {
+    cairo_scaled_font_private_t base;
+    i965_device_t *device;
+    const cairo_surface_backend_t *backend;
+};
+
 enum i965_shader_linear_mode {
     /* XXX REFLECT */
     LINEAR_TEXTURE,
diff --git a/src/drm/cairo-drm-intel-private.h b/src/drm/cairo-drm-intel-private.h
index 4ba36a8..a9a5ff9 100644
--- a/src/drm/cairo-drm-intel-private.h
+++ b/src/drm/cairo-drm-intel-private.h
@@ -171,6 +171,10 @@ typedef struct _intel_glyph {
     int width, height;
 } intel_glyph_t;
 
+typedef struct _intel_scaled_font {
+    cairo_scaled_font_private_t base;
+} intel_scaled_font_t;
+
 typedef struct _intel_gradient_cache {
     cairo_pattern_union_t pattern;
     intel_buffer_t buffer;
-- 
2.6.4.442.g545299f



More information about the cairo mailing list