From 0cecc8de1e9df6a0127e77a6e1344586020952f4 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Thu, 3 Jan 2013 17:24:41 +0100 Subject: [PATCH] text: add owner field to text-ops 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 --- src/text.c | 11 ++++++++++- src/text.h | 6 ++++++ src/text_bblit.c | 5 +++-- src/text_bbulk.c | 5 +++-- src/text_gltex.c | 5 +++-- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/text.c b/src/text.c index 055f498..e825d37 100644 --- a/src/text.c +++ b/src/text.c @@ -45,6 +45,13 @@ 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; } diff --git a/src/text.h b/src/text.h index 74db25c..5fdcd8e 100644 --- a/src/text.h +++ b/src/text.h @@ -36,6 +36,7 @@ #include #include #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); diff --git a/src/text_bblit.c b/src/text_bblit.c index d10be98..26fe246 100644 --- a/src/text_bblit.c +++ b/src/text_bblit.c @@ -1,7 +1,7 @@ /* * kmscon - Bit-Blitting Text Renderer Backend * - * Copyright (c) 2012 David Herrmann + * Copyright (c) 2012-2013 David Herrmann * * 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, diff --git a/src/text_bbulk.c b/src/text_bbulk.c index d733803..eb87441 100644 --- a/src/text_bbulk.c +++ b/src/text_bbulk.c @@ -1,7 +1,7 @@ /* * kmscon - Bit-Blitting Bulk Text Renderer Backend * - * Copyright (c) 2012 David Herrmann + * Copyright (c) 2012-2013 David Herrmann * * 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, diff --git a/src/text_gltex.c b/src/text_gltex.c index 41419c0..4842f2d 100644 --- a/src/text_gltex.c +++ b/src/text_gltex.c @@ -1,7 +1,7 @@ /* * kmscon - OpenGL Textures Text Renderer Backend * - * Copyright (c) 2012 David Herrmann + * Copyright (c) 2012-2013 David Herrmann * * 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,