From b00dde0bc976d8f65b1ae286a4ae754b092a8da6 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Fri, 18 Oct 2013 17:17:26 +0200 Subject: uterm: drm: move display_ops into vdrm object Instead of passing display-ops to every helper store it in vdrm-objects. During vdrm-setup we set the pointer and reuse it in all helpers. This simplifies the function headers and allows calling them from helper-callbacks without requiring a pointer from the respective user. Signed-off-by: David Herrmann --- src/uterm_drm2d_video.c | 7 ++++--- src/uterm_drm3d_video.c | 7 ++++--- src/uterm_drm_shared.c | 20 +++++++++----------- src/uterm_drm_shared_internal.h | 11 +++++------ 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/uterm_drm2d_video.c b/src/uterm_drm2d_video.c index bd103b3..cf40312 100644 --- a/src/uterm_drm2d_video.c +++ b/src/uterm_drm2d_video.c @@ -322,7 +322,8 @@ static int video_init(struct uterm_video *video, const char *node) uint64_t has_dumb; struct uterm_drm_video *vdrm; - ret = uterm_drm_video_init(video, node, NULL, NULL); + ret = uterm_drm_video_init(video, node, &drm2d_display_ops, + NULL, NULL); if (ret) return ret; vdrm = video->data; @@ -347,7 +348,7 @@ static void video_destroy(struct uterm_video *video) static int video_poll(struct uterm_video *video) { - return uterm_drm_video_poll(video, &drm2d_display_ops); + return uterm_drm_video_poll(video); } static void video_sleep(struct uterm_video *video) @@ -360,7 +361,7 @@ static int video_wake_up(struct uterm_video *video) { int ret; - ret = uterm_drm_video_wake_up(video, &drm2d_display_ops); + ret = uterm_drm_video_wake_up(video); if (ret) return ret; diff --git a/src/uterm_drm3d_video.c b/src/uterm_drm3d_video.c index cc60685..c291c8a 100644 --- a/src/uterm_drm3d_video.c +++ b/src/uterm_drm3d_video.c @@ -423,7 +423,8 @@ static int video_init(struct uterm_video *video, const char *node) return -ENOMEM; memset(v3d, 0, sizeof(*v3d)); - ret = uterm_drm_video_init(video, node, page_flip_handler, v3d); + ret = uterm_drm_video_init(video, node, &drm_display_ops, + page_flip_handler, v3d); if (ret) goto err_free; vdrm = video->data; @@ -536,7 +537,7 @@ static void video_destroy(struct uterm_video *video) static int video_poll(struct uterm_video *video) { - return uterm_drm_video_poll(video, &drm_display_ops); + return uterm_drm_video_poll(video); } static void video_sleep(struct uterm_video *video) @@ -549,7 +550,7 @@ static int video_wake_up(struct uterm_video *video) { int ret; - ret = uterm_drm_video_wake_up(video, &drm_display_ops); + ret = uterm_drm_video_wake_up(video); if (ret) return ret; diff --git a/src/uterm_drm_shared.c b/src/uterm_drm_shared.c index cfa8a80..c66ed8f 100644 --- a/src/uterm_drm_shared.c +++ b/src/uterm_drm_shared.c @@ -462,6 +462,7 @@ static void io_event(struct ev_fd *fd, int mask, void *data) } int uterm_drm_video_init(struct uterm_video *video, const char *node, + const struct display_ops *display_ops, uterm_drm_page_flip_t pflip, void *data) { struct uterm_drm_video *vdrm; @@ -476,6 +477,7 @@ int uterm_drm_video_init(struct uterm_video *video, const char *node, video->data = vdrm; vdrm->data = data; vdrm->page_flip = pflip; + vdrm->display_ops = display_ops; vdrm->fd = open(node, O_RDWR | O_CLOEXEC | O_NONBLOCK); if (vdrm->fd < 0) { @@ -546,8 +548,7 @@ int uterm_drm_video_find_crtc(struct uterm_video *video, drmModeRes *res, } static void bind_display(struct uterm_video *video, drmModeRes *res, - drmModeConnector *conn, - const struct display_ops *ops) + drmModeConnector *conn) { struct uterm_drm_video *vdrm = video->data; struct uterm_display *disp; @@ -555,7 +556,7 @@ static void bind_display(struct uterm_video *video, drmModeRes *res, struct uterm_mode *mode; int ret, i; - ret = display_new(&disp, ops); + ret = display_new(&disp, vdrm->display_ops); if (ret) return; ddrm = disp->data; @@ -606,7 +607,6 @@ err_unref: } int uterm_drm_video_hotplug(struct uterm_video *video, - const struct display_ops *ops, bool read_dpms) { struct uterm_drm_video *vdrm = video->data; @@ -662,7 +662,7 @@ int uterm_drm_video_hotplug(struct uterm_video *video, } if (iter == &video->displays) - bind_display(video, res, conn, ops); + bind_display(video, res, conn); drmModeFreeConnector(conn); } @@ -679,8 +679,7 @@ int uterm_drm_video_hotplug(struct uterm_video *video, return 0; } -int uterm_drm_video_wake_up(struct uterm_video *video, - const struct display_ops *ops) +int uterm_drm_video_wake_up(struct uterm_video *video) { int ret; struct uterm_drm_video *vdrm = video->data; @@ -692,7 +691,7 @@ int uterm_drm_video_wake_up(struct uterm_video *video, } video->flags |= VIDEO_AWAKE; - ret = uterm_drm_video_hotplug(video, ops, true); + ret = uterm_drm_video_hotplug(video, true); if (ret) { drmDropMaster(vdrm->fd); return ret; @@ -708,11 +707,10 @@ void uterm_drm_video_sleep(struct uterm_video *video) drmDropMaster(vdrm->fd); } -int uterm_drm_video_poll(struct uterm_video *video, - const struct display_ops *ops) +int uterm_drm_video_poll(struct uterm_video *video) { video->flags |= VIDEO_HOTPLUG; - return uterm_drm_video_hotplug(video, ops, false); + return uterm_drm_video_hotplug(video, false); } /* Waits for events on DRM fd for \mtimeout milliseconds and returns 0 if the diff --git a/src/uterm_drm_shared_internal.h b/src/uterm_drm_shared_internal.h index 824fbdc..e76ec33 100644 --- a/src/uterm_drm_shared_internal.h +++ b/src/uterm_drm_shared_internal.h @@ -98,20 +98,19 @@ struct uterm_drm_video { uterm_drm_page_flip_t page_flip; void *data; struct shl_timer *timer; + const struct display_ops *display_ops; }; int uterm_drm_video_init(struct uterm_video *video, const char *node, + const struct display_ops *display_ops, uterm_drm_page_flip_t pflip, void *data); void uterm_drm_video_destroy(struct uterm_video *video); int uterm_drm_video_find_crtc(struct uterm_video *video, drmModeRes *res, drmModeEncoder *enc); -int uterm_drm_video_hotplug(struct uterm_video *video, - const struct display_ops *ops, bool read_dpms); -int uterm_drm_video_wake_up(struct uterm_video *video, - const struct display_ops *ops); +int uterm_drm_video_hotplug(struct uterm_video *video, bool read_dpms); +int uterm_drm_video_wake_up(struct uterm_video *video); void uterm_drm_video_sleep(struct uterm_video *video); -int uterm_drm_video_poll(struct uterm_video *video, - const struct display_ops *ops); +int uterm_drm_video_poll(struct uterm_video *video); int uterm_drm_video_wait_pflip(struct uterm_video *video, unsigned int *mtimeout); -- cgit v1.2.3