diff options
author | David Herrmann <dh.herrmann@googlemail.com> | 2013-01-11 12:16:43 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@googlemail.com> | 2013-01-11 12:16:43 +0100 |
commit | 694f451ae81ff23cece6afdbe349a5e879d1c602 (patch) | |
tree | cfabe1a57be1b98dbfc4626e545ccaf27b1f63ab /src/uterm_video.c | |
parent | 81b691b742534ca5e1dda003f6549477733b60d3 (diff) |
uterm: video: modularize video backends
We want to allow dynamic backend loading during runtime so we need to
avoid static definitions. This converts the backend IDs into module
structures which are then linked into the binary.
To make this fully modular, we need to load the backends dynamicly via
dlsym() and move all the static declarations from uterm_video.h into the
backends. But for now at least the backends can be easily exchanged and
configured during compile-time.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Diffstat (limited to 'src/uterm_video.c')
-rw-r--r-- | src/uterm_video.c | 63 |
1 files changed, 12 insertions, 51 deletions
diff --git a/src/uterm_video.c b/src/uterm_video.c index 082038d..78cf661 100644 --- a/src/uterm_video.c +++ b/src/uterm_video.c @@ -58,27 +58,15 @@ const char *uterm_dpms_to_name(int dpms) } } -bool uterm_video_available(unsigned int type) +bool uterm_video_available(const struct uterm_video_module *mod) { - switch (type) { - case UTERM_VIDEO_DRM: -#ifdef BUILD_ENABLE_VIDEO_DRM - return video_drm_available(); -#endif + if (!mod) return false; - case UTERM_VIDEO_DUMB: -#ifdef BUILD_ENABLE_VIDEO_DUMB + + if (mod == UTERM_VIDEO_DUMB || mod == UTERM_VIDEO_DRM) return video_drm_available(); -#endif - return false; - case UTERM_VIDEO_FBDEV: -#ifdef BUILD_ENABLE_VIDEO_FBDEV - return true; -#endif - return false; - default: - return false; - } + + return true; } int mode_new(struct uterm_mode **out, const struct mode_ops *ops) @@ -459,51 +447,24 @@ int uterm_display_fake_blendv(struct uterm_display *disp, return VIDEO_CALL(disp->ops->fake_blendv, -EOPNOTSUPP, disp, req, num); } -int uterm_video_new(struct uterm_video **out, - struct ev_eloop *eloop, - unsigned int type, - const char *node) +int uterm_video_new(struct uterm_video **out, struct ev_eloop *eloop, + const char *node, const struct uterm_video_module *mod) { struct uterm_video *video; int ret; - const struct video_ops *ops; if (!out || !eloop) return -EINVAL; - - switch (type) { - case UTERM_VIDEO_DRM: - if (!drm_available) { - log_err("DRM backend is not available"); - return -EOPNOTSUPP; - } - ops = &drm_video_ops; - break; - case UTERM_VIDEO_DUMB: - if (!dumb_available) { - log_err("Dumb DRM backend is not available"); - return -EOPNOTSUPP; - } - ops = &dumb_video_ops; - break; - case UTERM_VIDEO_FBDEV: - if (!fbdev_available) { - log_err("FBDEV backend is not available"); - return -EOPNOTSUPP; - } - ops = &fbdev_video_ops; - break; - default: - log_err("invalid video backend %d", type); - return -EINVAL; - } + if (!mod || !mod->ops) + return -EOPNOTSUPP; video = malloc(sizeof(*video)); if (!video) return -ENOMEM; memset(video, 0, sizeof(*video)); video->ref = 1; - video->ops = ops; + video->mod = mod; + video->ops = mod->ops; video->eloop = eloop; ret = shl_hook_new(&video->hook); |