diff --git a/meson.build b/meson.build index 63f49445..45c5f685 100644 --- a/meson.build +++ b/meson.build @@ -144,7 +144,7 @@ endif enable_docs = get_option('docs').require(xsltproc.found() and have_manpages_stylesheet).allowed() # Additionally check if glesv2 is needed -enable_glesv2 = enable_video_drm3d and enable_renderer_gltex +enable_glesv2 = enable_video_drm3d or enable_renderer_gltex # # Other configuration output diff --git a/src/font.c b/src/font.c index 02202a3f..cb7de85f 100644 --- a/src/font.c +++ b/src/font.c @@ -57,7 +57,7 @@ #include #include #include "font.h" -#include "kmscon_module.h" +#include "shl_module.h" #include "shl_dlist.h" #include "shl_log.h" #include "shl_misc.h" @@ -142,7 +142,7 @@ static inline void kmscon_font_destroy(void *data) { const struct kmscon_font_ops *ops = data; - kmscon_module_unref(ops->owner); + shl_module_unref(ops->owner); } /** @@ -177,7 +177,7 @@ int kmscon_font_register(const struct kmscon_font_ops *ops) return ret; } - kmscon_module_ref(ops->owner); + shl_module_ref(ops->owner); return 0; } diff --git a/src/font.h b/src/font.h index 6f1a79ec..4c181c62 100644 --- a/src/font.h +++ b/src/font.h @@ -32,7 +32,7 @@ #include #include -#include "kmscon_module.h" +#include "shl_module.h" #include "uterm_video.h" /* fonts */ @@ -77,7 +77,7 @@ struct kmscon_font { struct kmscon_font_ops { const char *name; - struct kmscon_module *owner; + struct shl_module *owner; int (*init) (struct kmscon_font *out, const struct kmscon_font_attr *attr); void (*destroy) (struct kmscon_font *font); diff --git a/src/kmscon_conf.c b/src/kmscon_conf.c index 7650334a..64901955 100644 --- a/src/kmscon_conf.c +++ b/src/kmscon_conf.c @@ -569,17 +569,21 @@ static int aftercheck_help(struct conf_option *opt, int argc, char **argv, static int aftercheck_drm(struct conf_option *opt, int argc, char **argv, int idx) { +#ifndef BUILD_ENABLE_VIDEO_DRM2D +#ifndef BUILD_ENABLE_VIDEO_DRM3D struct kmscon_conf_t *conf = KMSCON_CONF_FROM_FIELD(opt->mem, drm); /* disable --drm if DRM runtime support is not available */ /* drmAvailable() is broken, as it only checks for GPU 0, but with * with simpledrm, it's often the case that the first gpu ends up being * GPU 1. So only checks if drm2d or drm3d is available */ - if (conf->drm && !UTERM_VIDEO_DRM3D && !UTERM_VIDEO_DRM2D) { + + if (conf->drm) { log_info("no DRM runtime support available; disabling --drm"); conf->drm = false; } - +#endif +#endif return 0; } diff --git a/src/kmscon_main.c b/src/kmscon_main.c index 1fbe85b2..e28792fd 100644 --- a/src/kmscon_main.c +++ b/src/kmscon_main.c @@ -34,7 +34,7 @@ #include "conf.h" #include "eloop.h" #include "kmscon_conf.h" -#include "kmscon_module.h" +#include "shl_module.h" #include "kmscon_seat.h" #include "shl_dlist.h" #include "shl_log.h" @@ -81,6 +81,10 @@ struct kmscon_app { unsigned int running_seats; }; +const char be_drm3d[] = "drm3d"; +const char be_drm2d[] = "drm2d"; +const char be_fbdev[] = "fbdev"; + static int app_seat_event(struct kmscon_seat *s, unsigned int event, void *data) { @@ -325,7 +329,7 @@ static int app_seat_add_video(struct app_seat *seat, struct uterm_monitor_dev *udev) { int ret; - const struct uterm_video_module *mode; + const char *backend; struct app_video *vid; if (seat->app->exiting) @@ -360,11 +364,11 @@ static int app_seat_add_video(struct app_seat *seat, if (type == UTERM_MONITOR_DRM) { if (seat->conf->hwaccel) - mode = UTERM_VIDEO_DRM3D; + backend = be_drm3d; else - mode = UTERM_VIDEO_DRM2D; + backend = be_drm2d; } else { - mode = UTERM_VIDEO_FBDEV; + backend = be_fbdev; } unsigned int desired_width = 0; @@ -377,14 +381,14 @@ static int app_seat_add_video(struct app_seat *seat, desired_height = 0; } } - ret = uterm_video_new(&vid->video, seat->app->eloop, node, mode, + ret = uterm_video_new(&vid->video, seat->app->eloop, node, backend, desired_width, desired_height); if (ret) { - if (mode == UTERM_VIDEO_DRM3D) { + if (backend == be_drm3d) { log_info("cannot create drm3d device %s on seat %s (%d); trying drm2d mode", vid->node, seat->name, ret); ret = uterm_video_new(&vid->video, seat->app->eloop, - node, UTERM_VIDEO_DRM2D, desired_width, desired_height); + node, be_drm2d, desired_width, desired_height); if (ret) goto err_node; } else { @@ -627,6 +631,8 @@ int main(int argc, char **argv) kmscon_load_modules(); kmscon_font_register(&kmscon_font_8x16_ops); kmscon_text_register(&kmscon_text_bblit_ops); + uterm_register_drm2d(); + uterm_register_fbdev(); memset(&app, 0, sizeof(app)); app.conf_ctx = conf_ctx; diff --git a/src/kmscon_mod_bbulk.c b/src/kmscon_mod_bbulk.c index f0a2052d..34f83e19 100644 --- a/src/kmscon_mod_bbulk.c +++ b/src/kmscon_mod_bbulk.c @@ -31,7 +31,7 @@ #include #include #include "text.h" -#include "kmscon_module_interface.h" +#include "shl_module_interface.h" #include "shl_log.h" #define LOG_SUBSYSTEM "mod_bbulk" @@ -40,7 +40,7 @@ static int kmscon_bbulk_load(void) { int ret; - kmscon_text_bbulk_ops.owner = KMSCON_THIS_MODULE; + kmscon_text_bbulk_ops.owner = SHL_THIS_MODULE; ret = kmscon_text_register(&kmscon_text_bbulk_ops); if (ret) { log_error("cannot register bbulk renderer"); @@ -55,4 +55,4 @@ static void kmscon_bbulk_unload(void) kmscon_text_unregister(kmscon_text_bbulk_ops.name); } -KMSCON_MODULE(NULL, kmscon_bbulk_load, kmscon_bbulk_unload, NULL); +SHL_MODULE(NULL, kmscon_bbulk_load, kmscon_bbulk_unload, NULL); diff --git a/src/kmscon_mod_gltex.c b/src/kmscon_mod_gltex.c index 9f4579df..841786a5 100644 --- a/src/kmscon_mod_gltex.c +++ b/src/kmscon_mod_gltex.c @@ -31,7 +31,7 @@ #include #include #include "text.h" -#include "kmscon_module_interface.h" +#include "shl_module_interface.h" #include "shl_log.h" #define LOG_SUBSYSTEM "mod_gltex" @@ -40,7 +40,7 @@ static int kmscon_gltex_load(void) { int ret; - kmscon_text_gltex_ops.owner = KMSCON_THIS_MODULE; + kmscon_text_gltex_ops.owner = SHL_THIS_MODULE; ret = kmscon_text_register(&kmscon_text_gltex_ops); if (ret) { log_error("cannot register gltex renderer"); @@ -55,4 +55,4 @@ static void kmscon_gltex_unload(void) kmscon_text_unregister(kmscon_text_gltex_ops.name); } -KMSCON_MODULE(NULL, kmscon_gltex_load, kmscon_gltex_unload, NULL); +SHL_MODULE(NULL, kmscon_gltex_load, kmscon_gltex_unload, NULL); diff --git a/src/kmscon_mod_pango.c b/src/kmscon_mod_pango.c index de8b1e71..bb42f0c3 100644 --- a/src/kmscon_mod_pango.c +++ b/src/kmscon_mod_pango.c @@ -31,7 +31,7 @@ #include #include #include "font.h" -#include "kmscon_module_interface.h" +#include "shl_module_interface.h" #include "shl_log.h" #define LOG_SUBSYSTEM "mod_pango" @@ -40,7 +40,7 @@ static int kmscon_pango_load(void) { int ret; - kmscon_font_pango_ops.owner = KMSCON_THIS_MODULE; + kmscon_font_pango_ops.owner = SHL_THIS_MODULE; ret = kmscon_font_register(&kmscon_font_pango_ops); if (ret) { log_error("cannot register pango font"); @@ -55,4 +55,4 @@ static void kmscon_pango_unload(void) kmscon_font_unregister(kmscon_font_pango_ops.name); } -KMSCON_MODULE(NULL, kmscon_pango_load, kmscon_pango_unload, NULL); +SHL_MODULE(NULL, kmscon_pango_load, kmscon_pango_unload, NULL); diff --git a/src/kmscon_mod_pixman.c b/src/kmscon_mod_pixman.c index f229e55d..9bf4c74b 100644 --- a/src/kmscon_mod_pixman.c +++ b/src/kmscon_mod_pixman.c @@ -30,7 +30,7 @@ #include #include #include "text.h" -#include "kmscon_module_interface.h" +#include "shl_module_interface.h" #include "shl_log.h" #define LOG_SUBSYSTEM "mod_pixman" @@ -39,7 +39,7 @@ static int kmscon_pixman_load(void) { int ret; - kmscon_text_pixman_ops.owner = KMSCON_THIS_MODULE; + kmscon_text_pixman_ops.owner = SHL_THIS_MODULE; ret = kmscon_text_register(&kmscon_text_pixman_ops); if (ret) { log_error("cannot register pixman renderer"); @@ -54,4 +54,4 @@ static void kmscon_pixman_unload(void) kmscon_text_unregister(kmscon_text_pixman_ops.name); } -KMSCON_MODULE(NULL, kmscon_pixman_load, kmscon_pixman_unload, NULL); +SHL_MODULE(NULL, kmscon_pixman_load, kmscon_pixman_unload, NULL); diff --git a/src/kmscon_mod_unifont.c b/src/kmscon_mod_unifont.c index 4b199543..a2625527 100644 --- a/src/kmscon_mod_unifont.c +++ b/src/kmscon_mod_unifont.c @@ -31,7 +31,7 @@ #include #include #include "font.h" -#include "kmscon_module_interface.h" +#include "shl_module_interface.h" #include "shl_log.h" #define LOG_SUBSYSTEM "mod_unifont" @@ -40,7 +40,7 @@ static int kmscon_unifont_load(void) { int ret; - kmscon_font_unifont_ops.owner = KMSCON_THIS_MODULE; + kmscon_font_unifont_ops.owner = SHL_THIS_MODULE; ret = kmscon_font_register(&kmscon_font_unifont_ops); if (ret) { log_error("cannot register pango font"); @@ -55,4 +55,4 @@ static void kmscon_unifont_unload(void) kmscon_font_unregister(kmscon_font_unifont_ops.name); } -KMSCON_MODULE(NULL, kmscon_unifont_load, kmscon_unifont_unload, NULL); +SHL_MODULE(NULL, kmscon_unifont_load, kmscon_unifont_unload, NULL); diff --git a/src/meson.build b/src/meson.build index 7cf5c889..dee686c3 100644 --- a/src/meson.build +++ b/src/meson.build @@ -47,28 +47,38 @@ keymap_regex = [ # shl_srcs = [ 'shl_log.c', + 'shl_module.c', githead, ] shl_dep = [ htable_deps, xkbcommon_deps ] + +shl = static_library('shl', shl_srcs, dependencies: shl_dep) +shl_deps = declare_dependency( + link_with: [shl], + include_directories: [include_directories('.')], + dependencies: shl_dep +) + if enable_glesv2 - shl_srcs += [ + shl_gl_srcs = [ 'shl_gl_shader.c', 'shl_gl_math.c', ] - shl_dep += [ + shl_gl_dep = [ + shl_deps, glesv2_deps ] -endif -shl = static_library('shl', shl_srcs, dependencies: shl_dep) -shl_deps = declare_dependency( - link_with: [shl], +shl_gl = static_library('shl_gl', shl_gl_srcs, dependencies: shl_gl_dep) +shl_gl_deps = declare_dependency( + link_with: [shl_gl], include_directories: [include_directories('.')], - dependencies: shl_dep + dependencies: shl_gl_dep ) +endif # # libeloop @@ -122,30 +132,32 @@ if enable_video_drm2d 'uterm_drm2d_render.c' ] endif +uterm = static_library('uterm', uterm_srcs, + dependencies: uterm_dep +) +uterm_deps = declare_dependency( + link_with: [uterm], + dependencies: uterm_dep +) + if enable_video_drm3d - uterm_srcs += [ + mod_drm3d = shared_module('mod-drm3d', [ 'uterm_drm3d_video.c', 'uterm_drm3d_render.c', + 'uterm_mod_drm3d.c', embed_gen.process('uterm_drm3d_blend.vert', extra_args: shader_regex), embed_gen.process('uterm_drm3d_blend.frag', extra_args: shader_regex), embed_gen.process('uterm_drm3d_blit.vert', extra_args: shader_regex), embed_gen.process('uterm_drm3d_blit.frag', extra_args: shader_regex), embed_gen.process('uterm_drm3d_fill.vert', extra_args: shader_regex), embed_gen.process('uterm_drm3d_fill.frag', extra_args: shader_regex), - ] - uterm_dep += [ - egl_deps, - gbm_deps, - glesv2_deps, - ] + ], + name_prefix: '', + dependencies: [uterm_deps, shl_deps, shl_gl_deps, libdrm_deps, egl_deps, gbm_deps, glesv2_deps], + install: true, + install_dir: moduledir, + ) endif -uterm = static_library('uterm', uterm_srcs, - dependencies: uterm_dep -) -uterm_deps = declare_dependency( - link_with: [uterm], - dependencies: uterm_dep -) # # Unifont Generator @@ -207,7 +219,7 @@ if enable_renderer_gltex embed_gen.process('text_gltex_atlas.frag', extra_args: shader_regex), ], name_prefix: '', - dependencies: [libtsm_deps, glesv2_deps, shl_deps], + dependencies: [libtsm_deps, glesv2_deps, shl_deps, shl_gl_deps], install: true, install_dir: moduledir, ) @@ -246,7 +258,6 @@ kmscon_srcs = [ 'font_8x16.c', 'text.c', 'text_bblit.c', - 'kmscon_module.c', 'kmscon_seat.c', 'kmscon_conf.c', 'kmscon_main.c', diff --git a/src/kmscon_module.c b/src/shl_module.c similarity index 88% rename from src/kmscon_module.c rename to src/shl_module.c index f960c504..aee17b1b 100644 --- a/src/kmscon_module.c +++ b/src/shl_module.c @@ -30,8 +30,8 @@ #include #include #include -#include "kmscon_module.h" -#include "kmscon_module_interface.h" +#include "shl_module.h" +#include "shl_module_interface.h" #include "shl_dlist.h" #include "shl_githead.h" #include "shl_log.h" @@ -41,10 +41,10 @@ static struct shl_dlist module_list = SHL_DLIST_INIT(module_list); -int kmscon_module_open(struct kmscon_module **out, const char *file) +int shl_module_open(struct shl_module **out, const char *file) { int ret; - struct kmscon_module *module; + struct shl_module *module; void *handle; if (!out || !file) @@ -119,7 +119,7 @@ int kmscon_module_open(struct kmscon_module **out, const char *file) return ret; } -void kmscon_module_ref(struct kmscon_module *module) +void shl_module_ref(struct shl_module *module) { if (!module || !module->ref) return; @@ -127,7 +127,7 @@ void kmscon_module_ref(struct kmscon_module *module) ++module->ref; } -void kmscon_module_unref(struct kmscon_module *module) +void shl_module_unref(struct shl_module *module) { if (!module || !module->ref || --module->ref) return; @@ -141,7 +141,7 @@ void kmscon_module_unref(struct kmscon_module *module) dlclose(module->handle); } -int kmscon_module_load(struct kmscon_module *module) +int shl_module_load(struct shl_module *module) { int ret; @@ -165,7 +165,7 @@ int kmscon_module_load(struct kmscon_module *module) return 0; } -void kmscon_module_unload(struct kmscon_module *module) +void shl_module_unload(struct shl_module *module) { if (!module || !module->loaded) return; @@ -183,7 +183,7 @@ void kmscon_load_modules(void) DIR *ent; struct dirent *de; char *file; - struct kmscon_module *mod; + struct shl_module *mod; log_debug("loading global modules from %s", BUILD_MODULE_DIR); @@ -235,15 +235,15 @@ void kmscon_load_modules(void) continue; } - ret = kmscon_module_open(&mod, file); + ret = shl_module_open(&mod, file); free(file); if (ret) continue; - ret = kmscon_module_load(mod); + ret = shl_module_load(mod); if (ret) { - kmscon_module_unref(mod); + shl_module_unref(mod); continue; } @@ -255,15 +255,15 @@ void kmscon_load_modules(void) void kmscon_unload_modules(void) { - struct kmscon_module *module; + struct shl_module *module; log_debug("unloading modules"); while (!shl_dlist_empty(&module_list)) { - module = shl_dlist_entry(module_list.prev, struct kmscon_module, + module = shl_dlist_entry(module_list.prev, struct shl_module, list); shl_dlist_unlink(&module->list); - kmscon_module_unload(module); - kmscon_module_unref(module); + shl_module_unload(module); + shl_module_unref(module); } } diff --git a/src/kmscon_module.h b/src/shl_module.h similarity index 87% rename from src/kmscon_module.h rename to src/shl_module.h index 213c538f..775bfacd 100644 --- a/src/kmscon_module.h +++ b/src/shl_module.h @@ -51,21 +51,21 @@ * the module can release its resources. */ -#ifndef KMSCON_MODULE_H -#define KMSCON_MODULE_H +#ifndef SHL_MODULE_H +#define SHL_MODULE_H #include -struct kmscon_module; +struct shl_module; -int kmscon_module_open(struct kmscon_module **out, const char *file); -void kmscon_module_ref(struct kmscon_module *module); -void kmscon_module_unref(struct kmscon_module *module); +int shl_module_open(struct shl_module **out, const char *file); +void shl_module_ref(struct shl_module *module); +void shl_module_unref(struct shl_module *module); -int kmscon_module_load(struct kmscon_module *module); -void kmscon_module_unload(struct kmscon_module *module); +int shl_module_load(struct shl_module *module); +void shl_module_unload(struct shl_module *module); void kmscon_load_modules(void); void kmscon_unload_modules(void); -#endif /* KMSCON_MODULE_H */ +#endif /* SHL_MODULE_H */ diff --git a/src/kmscon_module_interface.h b/src/shl_module_interface.h similarity index 82% rename from src/kmscon_module_interface.h rename to src/shl_module_interface.h index f13f724d..a83913e5 100644 --- a/src/kmscon_module_interface.h +++ b/src/shl_module_interface.h @@ -27,17 +27,17 @@ * Public Module Interface */ -#ifndef KMSCON_MODULE_INTERFACE_H -#define KMSCON_MODULE_INTERFACE_H +#ifndef SHL_MODULE_INTERFACE_H +#define SHL_MODULE_INTERFACE_H #include #include -#include "kmscon_module.h" +#include "shl_module.h" #include "shl_dlist.h" #include "shl_githead.h" #include "shl_misc.h" -struct kmscon_module_info { +struct shl_module_info { const char *githead; const char *date; const char *time; @@ -47,8 +47,8 @@ struct kmscon_module_info { void (*exit) (void); }; -struct kmscon_module { - struct kmscon_module_info info; +struct shl_module { + struct shl_module_info info; struct shl_dlist list; unsigned long ref; bool loaded; @@ -56,8 +56,8 @@ struct kmscon_module { char *file; }; -#define KMSCON_MODULE(_init, _load, _unload, _exit) \ - struct kmscon_module module = { \ +#define SHL_MODULE(_init, _load, _unload, _exit) \ + struct shl_module module = { \ .info = { \ .githead = shl_git_head, \ .date = __DATE__, \ @@ -70,7 +70,7 @@ struct kmscon_module { }; SHL_EXPORT -extern struct kmscon_module module; -#define KMSCON_THIS_MODULE (&module) +extern struct shl_module module; +#define SHL_THIS_MODULE (&module) -#endif /* KMSCON_MODULE_INTERFACE_H */ +#endif /* SHL_MODULE_INTERFACE_H */ diff --git a/src/text.c b/src/text.c index 1d53eb9f..6d1b496d 100644 --- a/src/text.c +++ b/src/text.c @@ -49,7 +49,7 @@ static inline void kmscon_text_destroy(void *data) { const struct kmscon_text_ops *ops = data; - kmscon_module_unref(ops->owner); + shl_module_unref(ops->owner); } /** @@ -84,7 +84,7 @@ int kmscon_text_register(const struct kmscon_text_ops *ops) return ret; } - kmscon_module_ref(ops->owner); + shl_module_ref(ops->owner); return 0; } diff --git a/src/text.h b/src/text.h index bbba5b0e..0c51ce94 100644 --- a/src/text.h +++ b/src/text.h @@ -37,7 +37,7 @@ #include #include #include "font.h" -#include "kmscon_module.h" +#include "shl_module.h" #include "uterm_video.h" /* text renderer */ @@ -70,7 +70,7 @@ struct kmscon_text { struct kmscon_text_ops { const char *name; - struct kmscon_module *owner; + struct shl_module *owner; int (*init) (struct kmscon_text *txt); void (*destroy) (struct kmscon_text *txt); int (*set) (struct kmscon_text *txt); diff --git a/src/uterm_drm2d_video.c b/src/uterm_drm2d_video.c index b991c452..f2a84b6b 100644 --- a/src/uterm_drm2d_video.c +++ b/src/uterm_drm2d_video.c @@ -376,18 +376,14 @@ static int video_wake_up(struct uterm_video *video) return 0; } -static const struct video_ops drm2d_video_ops = { - .init = video_init, - .destroy = video_destroy, - .segfault = NULL, /* TODO: reset all saved CRTCs on segfault */ - .poll = video_poll, - .sleep = video_sleep, - .wake_up = video_wake_up, +struct uterm_video_module drm2d_module = { + .name = "drm2d", + .owner = NULL, + .ops = { + .init = video_init, + .destroy = video_destroy, + .segfault = NULL, /* TODO: reset all saved CRTCs on segfault */ + .poll = video_poll, + .sleep = video_sleep, + .wake_up = video_wake_up,}, }; - -static const struct uterm_video_module drm2d_module = { - .ops = &drm2d_video_ops, -}; - -SHL_EXPORT -const struct uterm_video_module *UTERM_VIDEO_DRM2D = &drm2d_module; diff --git a/src/uterm_drm3d_video.c b/src/uterm_drm3d_video.c index 05e86385..dd4f1446 100644 --- a/src/uterm_drm3d_video.c +++ b/src/uterm_drm3d_video.c @@ -611,18 +611,17 @@ static int video_wake_up(struct uterm_video *video) return 0; } -static const struct video_ops drm_video_ops = { - .init = video_init, - .destroy = video_destroy, - .segfault = NULL, /* TODO: reset all saved CRTCs on segfault */ - .poll = video_poll, - .sleep = video_sleep, - .wake_up = video_wake_up, -}; - -static const struct uterm_video_module drm3d_module = { - .ops = &drm_video_ops, +SHL_EXPORT +struct uterm_video_module drm3d_module = { + .name = "drm3d", + .owner = NULL, + .ops = { + .init = video_init, + .destroy = video_destroy, + .segfault = NULL, /* TODO: reset all saved CRTCs on segfault */ + .poll = video_poll, + .sleep = video_sleep, + .wake_up = video_wake_up, + }, }; -SHL_EXPORT -const struct uterm_video_module *UTERM_VIDEO_DRM3D = &drm3d_module; diff --git a/src/uterm_fbdev_video.c b/src/uterm_fbdev_video.c index c977b8f1..73bb5907 100644 --- a/src/uterm_fbdev_video.c +++ b/src/uterm_fbdev_video.c @@ -649,18 +649,15 @@ static int video_wake_up(struct uterm_video *video) return 0; } -static const struct video_ops fbdev_video_ops = { +struct uterm_video_module fbdev_module = { + .name = "fbdev", + .owner = NULL, + .ops = { .init = video_init, .destroy = video_destroy, .segfault = NULL, /* TODO */ .poll = NULL, .sleep = video_sleep, .wake_up = video_wake_up, + } }; - -static const struct uterm_video_module fbdev_module = { - .ops = &fbdev_video_ops, -}; - -SHL_EXPORT -const struct uterm_video_module *UTERM_VIDEO_FBDEV = &fbdev_module; diff --git a/src/uterm_mod_drm3d.c b/src/uterm_mod_drm3d.c new file mode 100644 index 00000000..3fabfe42 --- /dev/null +++ b/src/uterm_mod_drm3d.c @@ -0,0 +1,59 @@ +/* + * kmscon - drm3d backend module + * + * Copyright (c) 2011-2013 David Herrmann + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * drm3d uterm video backend module + * This module registers the drm3d backend with kmscon. + */ + +#include +#include +#include "shl_module_interface.h" +#include "shl_log.h" +#include "uterm_video_internal.h" + +extern struct uterm_video_module drm3d_module; + +#define LOG_SUBSYSTEM "mod_drm3d" + +static int kmscon_drm3d_load(void) +{ + int ret; + + drm3d_module.owner = SHL_THIS_MODULE; + ret = uterm_video_register(&drm3d_module); + if (ret) { + log_error("cannot register drm3d font"); + return ret; + } + return 0; +} + +static void kmscon_drm3d_unload(void) +{ + uterm_video_unregister(drm3d_module.name); +} + +SHL_MODULE(NULL, kmscon_drm3d_load, kmscon_drm3d_unload, NULL); diff --git a/src/uterm_video.c b/src/uterm_video.c index 830bd5be..84dc728b 100644 --- a/src/uterm_video.c +++ b/src/uterm_video.c @@ -35,15 +35,27 @@ #include #include #include "eloop.h" +#include "shl_module.h" #include "shl_dlist.h" #include "shl_hook.h" #include "shl_log.h" #include "shl_misc.h" +#include "shl_register.h" #include "uterm_video.h" #include "uterm_video_internal.h" #define LOG_SUBSYSTEM "video" +static struct shl_register video_reg = SHL_REGISTER_INIT(video_reg); + + +static inline void uterm_video_destroy(void *data) +{ + const struct uterm_video_module *ops = data; + + shl_module_unref(ops->owner); +} + SHL_EXPORT const char *uterm_dpms_to_name(int dpms) { @@ -541,24 +553,37 @@ int uterm_display_fake_blendv(struct uterm_display *disp, SHL_EXPORT int uterm_video_new(struct uterm_video **out, struct ev_eloop *eloop, - const char *node, const struct uterm_video_module *mod, + const char *node, const char *backend, unsigned int desired_width, unsigned int desired_height) { + struct shl_register_record *record; + const char *name = backend ? backend : ""; struct uterm_video *video; int ret; if (!out || !eloop) return -EINVAL; - if (!mod || !mod->ops) - return -EOPNOTSUPP; + + if (backend) + record = shl_register_find(&video_reg, backend); + else + record = shl_register_first(&video_reg); + + if (!record) { + log_error("requested backend '%s' not found", name); + return -ENOENT; + } video = malloc(sizeof(*video)); - if (!video) - return -ENOMEM; + if (!video) { + ret = -ENOMEM; + goto err_unref; + } memset(video, 0, sizeof(*video)); video->ref = 1; - video->mod = mod; - video->ops = mod->ops; + + video->mod = record->data; + video->eloop = eloop; shl_dlist_init(&video->displays); @@ -566,7 +591,7 @@ int uterm_video_new(struct uterm_video **out, struct ev_eloop *eloop, if (ret) goto err_free; - ret = VIDEO_CALL(video->ops->init, 0, video, node); + ret = VIDEO_CALL(video->mod->ops.init, 0, video, node); if (ret) goto err_hook; @@ -582,6 +607,8 @@ int uterm_video_new(struct uterm_video **out, struct ev_eloop *eloop, shl_hook_free(video->hook); err_free: free(video); +err_unref: + shl_register_record_unref(record); return ret; } @@ -610,7 +637,7 @@ void uterm_video_unref(struct uterm_video *video) uterm_display_unbind(disp); } - VIDEO_CALL(video->ops->destroy, 0, video); + VIDEO_CALL(video->mod->ops.destroy, 0, video); shl_hook_free(video->hook); ev_eloop_unref(video->eloop); free(video); @@ -622,7 +649,7 @@ void uterm_video_segfault(struct uterm_video *video) if (!video) return; - VIDEO_CALL(video->ops->segfault, 0, video); + VIDEO_CALL(video->mod->ops.segfault, 0, video); } SHL_EXPORT @@ -655,6 +682,51 @@ void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb, shl_hook_rm_cast(video->hook, cb, data); } +/** + * kmscon_video_register: + * @ops: a video module. + * + * This register a new video backend with operations set to @ops. The name + * @ops->name must be valid. + * + * Returns: 0 on success, negative error code on failure + */ +SHL_EXPORT +int uterm_video_register(const struct uterm_video_module *ops) +{ + int ret; + + if (!ops) + return -EINVAL; + + log_debug("register video backend %s", ops->name); + + ret = shl_register_add_cb(&video_reg, ops->name, (void*)ops, + uterm_video_destroy); + if (ret) { + log_error("cannot register video backend %s: %d", ops->name, + ret); + return ret; + } + + shl_module_ref(ops->owner); + return 0; +} + +/** + * kmscon_video_unregister: + * @name: Name of backend + * + * This unregisters the video-backend that is registered with name @name. If + * @name is not found, nothing is done. + */ +SHL_EXPORT +void uterm_video_unregister(const char *name) +{ + log_debug("unregister backend %s", name); + shl_register_remove(&video_reg, name); +} + SHL_EXPORT void uterm_video_sleep(struct uterm_video *video) { @@ -665,7 +737,7 @@ void uterm_video_sleep(struct uterm_video *video) VIDEO_CB(video, NULL, UTERM_SLEEP); video->flags &= ~VIDEO_AWAKE; - VIDEO_CALL(video->ops->sleep, 0, video); + VIDEO_CALL(video->mod->ops.sleep, 0, video); } SHL_EXPORT @@ -680,7 +752,7 @@ int uterm_video_wake_up(struct uterm_video *video) log_debug("wake up"); - ret = VIDEO_CALL(video->ops->wake_up, 0, video); + ret = VIDEO_CALL(video->mod->ops.wake_up, 0, video); if (ret) { video->flags &= ~VIDEO_AWAKE; return ret; @@ -703,5 +775,5 @@ void uterm_video_poll(struct uterm_video *video) if (!video) return; - VIDEO_CALL(video->ops->poll, 0, video); + VIDEO_CALL(video->mod->ops.poll, 0, video); } diff --git a/src/uterm_video.h b/src/uterm_video.h index c3f955b0..154f3c20 100644 --- a/src/uterm_video.h +++ b/src/uterm_video.h @@ -192,7 +192,7 @@ int uterm_display_fake_blendv(struct uterm_display *disp, /* video interface */ int uterm_video_new(struct uterm_video **out, struct ev_eloop *eloop, - const char *node, const struct uterm_video_module *mod, + const char *node, const char *backend, unsigned int desired_width, unsigned int desired_height); void uterm_video_ref(struct uterm_video *video); void uterm_video_unref(struct uterm_video *video); @@ -204,29 +204,32 @@ int uterm_video_register_cb(struct uterm_video *video, uterm_video_cb cb, void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb, void *data); +int uterm_video_register(const struct uterm_video_module *ops); +void uterm_video_unregister(const char *name); void uterm_video_sleep(struct uterm_video *video); int uterm_video_wake_up(struct uterm_video *video); bool uterm_video_is_awake(struct uterm_video *video); void uterm_video_poll(struct uterm_video *video); -/* external modules */ +#ifdef BUILD_ENABLE_VIDEO_DRM2D +extern struct uterm_video_module drm2d_module; -#ifdef BUILD_ENABLE_VIDEO_FBDEV -extern const struct uterm_video_module *UTERM_VIDEO_FBDEV; -#else -#define UTERM_VIDEO_FBDEV NULL -#endif +static inline void uterm_register_drm2d(void) { + uterm_video_register(&drm2d_module); +} -#ifdef BUILD_ENABLE_VIDEO_DRM2D -extern const struct uterm_video_module *UTERM_VIDEO_DRM2D; #else -#define UTERM_VIDEO_DRM2D NULL +static inline void uterm_register_drm2d(void) {} #endif -#ifdef BUILD_ENABLE_VIDEO_DRM3D -extern const struct uterm_video_module *UTERM_VIDEO_DRM3D; +#ifdef BUILD_ENABLE_VIDEO_FBDEV +extern struct uterm_video_module fbdev_module; + +static inline void uterm_register_fbdev(void) { + uterm_video_register(&fbdev_module); +} #else -#define UTERM_VIDEO_DRM3D NULL +static inline void uterm_register_fbdev(void) {} #endif #endif /* UTERM_UTERM_VIDEO_H */ diff --git a/src/uterm_video_internal.h b/src/uterm_video_internal.h index 7ad3cc02..949eaf26 100644 --- a/src/uterm_video_internal.h +++ b/src/uterm_video_internal.h @@ -79,7 +79,9 @@ struct video_ops { }; struct uterm_video_module { - const struct video_ops *ops; + const char *name; + struct shl_module *owner; + const struct video_ops ops; }; #define VIDEO_CALL(func, els, ...) (func ? func(__VA_ARGS__) : els) @@ -165,7 +167,6 @@ struct uterm_video { unsigned int desired_height; const struct uterm_video_module *mod; - const struct video_ops *ops; void *data; }; diff --git a/tests/test_output.c b/tests/test_output.c index 204b23c4..a9d6c7ff 100644 --- a/tests/test_output.c +++ b/tests/test_output.c @@ -198,7 +198,7 @@ int main(int argc, char **argv) struct uterm_video *video; int ret; const char *node; - const struct uterm_video_module *mode; + const char *mode; size_t onum; onum = sizeof(options) / sizeof(*options); @@ -207,10 +207,10 @@ int main(int argc, char **argv) goto err_fail; if (output_conf.fbdev) { - mode = UTERM_VIDEO_FBDEV; + mode = "fbdev"; node = "/dev/fb0"; } else { - mode = UTERM_VIDEO_DRM3D; + mode = "drm3d"; node = "/dev/dri/card0"; } @@ -223,10 +223,10 @@ int main(int argc, char **argv) output_conf.desired_width, output_conf.desired_height); if (ret) { - if (mode == UTERM_VIDEO_DRM3D) { + if (!output_conf.fbdev) { log_notice("cannot create drm device; trying drm2d mode"); ret = uterm_video_new(&video, eloop, node, - UTERM_VIDEO_DRM2D, + "drm2d", output_conf.desired_width, output_conf.desired_height); if (ret)