text: add owner field to text-ops
authorDavid Herrmann <dh.herrmann@googlemail.com>
Thu, 3 Jan 2013 16:24:41 +0000 (17:24 +0100)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Thu, 3 Jan 2013 16:24:41 +0000 (17:24 +0100)
When text-ops are registered via modules, we need an owner field so
they're correctly tracked. Hence, add this field to all text-ops and
correctly keep module references.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/text.c
src/text.h
src/text_bblit.c
src/text_bbulk.c
src/text_gltex.c

index 055f498..e825d37 100644 (file)
 
 static struct shl_register text_reg = SHL_REGISTER_INIT(text_reg);
 
+static inline void kmscon_text_destroy(void *data)
+{
+       const struct kmscon_text_ops *ops = data;
+
+       kmscon_module_unref(ops->owner);
+}
+
 /**
  * kmscon_text_register:
  * @ops: Text operations and name for new backend
@@ -68,13 +75,15 @@ int kmscon_text_register(const struct kmscon_text_ops *ops)
 
        log_debug("register text backend %s", ops->name);
 
-       ret = shl_register_add(&text_reg, ops->name, (void*)ops);
+       ret = shl_register_add_cb(&text_reg, ops->name, (void*)ops,
+                                 kmscon_text_destroy);
        if (ret) {
                log_error("cannot register text backend %s: %d", ops->name,
                          ret);
                return ret;
        }
 
+       kmscon_module_ref(ops->owner);
        return 0;
 }
 
index 74db25c..5fdcd8e 100644 (file)
@@ -36,6 +36,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include "font.h"
+#include "kmscon_module.h"
 #include "tsm_screen.h"
 #include "uterm.h"
 
@@ -60,6 +61,7 @@ struct kmscon_text {
 
 struct kmscon_text_ops {
        const char *name;
+       struct kmscon_module *owner;
        int (*init) (struct kmscon_text *txt);
        void (*destroy) (struct kmscon_text *txt);
        int (*set) (struct kmscon_text *txt);
@@ -108,6 +110,10 @@ int kmscon_text_render_cb(struct tsm_screen *con, void *data);
 
 /* modularized backends */
 
+extern struct kmscon_text_ops kmscon_text_bblit_ops;
+extern struct kmscon_text_ops kmscon_text_bbulk_ops;
+extern struct kmscon_text_ops kmscon_text_gltex_ops;
+
 #ifdef BUILD_ENABLE_RENDERER_BBLIT
 
 int kmscon_text_bblit_load(void);
index d10be98..26fe246 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * kmscon - Bit-Blitting Text Renderer Backend
  *
- * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
+ * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files
@@ -109,8 +109,9 @@ static int bblit_draw(struct kmscon_text *txt,
        return ret;
 }
 
-static const struct kmscon_text_ops kmscon_text_bblit_ops = {
+struct kmscon_text_ops kmscon_text_bblit_ops = {
        .name = "bblit",
+       .owner = NULL,
        .init = NULL,
        .destroy = NULL,
        .set = bblit_set,
index d733803..eb87441 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * kmscon - Bit-Blitting Bulk Text Renderer Backend
  *
- * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
+ * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files
@@ -173,8 +173,9 @@ static int bbulk_render(struct kmscon_text *txt)
                                         txt->cols * txt->rows);
 }
 
-static const struct kmscon_text_ops kmscon_text_bbulk_ops = {
+struct kmscon_text_ops kmscon_text_bbulk_ops = {
        .name = "bbulk",
+       .owner = NULL,
        .init = bbulk_init,
        .destroy = bbulk_destroy,
        .set = bbulk_set,
index 41419c0..4842f2d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * kmscon - OpenGL Textures Text Renderer Backend
  *
- * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
+ * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files
@@ -682,8 +682,9 @@ static int gltex_render(struct kmscon_text *txt)
        return 0;
 }
 
-static const struct kmscon_text_ops kmscon_text_gltex_ops = {
+struct kmscon_text_ops kmscon_text_gltex_ops = {
        .name = "gltex",
+       .owner = NULL,
        .init = gltex_init,
        .destroy = gltex_destroy,
        .set = gltex_set,