From 0c20a24bb733ee2148bf9be9ac7911bb63ec9086 Mon Sep 17 00:00:00 2001 From: Ramprasad N Date: Fri, 30 Sep 2016 14:05:05 +0530 Subject: [PATCH] Add rotation support Signed-off-by: Ramprasad N --- util/display-kms.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/util/display-kms.c b/util/display-kms.c index 7a5a4d1..3383622 100644 --- a/util/display-kms.c +++ b/util/display-kms.c @@ -20,7 +20,6 @@ #endif #include "util.h" - #include @@ -57,6 +56,7 @@ struct display_kms { struct buffer *current; bool no_master; int mastership; + uint32_t rotation; }; #define to_buffer_kms(x) container_of(x, struct buffer_kms, base) @@ -68,7 +68,8 @@ struct buffer_kms { static int global_fd = 0; static uint32_t used_planes = 0; static int ndisplays = 0; - +static uint32_t get_prop_id(struct display *disp, + drmModeObjectPropertiesPtr props, const char *name); static struct omap_bo * alloc_bo(struct display *disp, uint32_t bpp, uint32_t width, uint32_t height, uint32_t *bo_handle, uint32_t *pitch) @@ -359,6 +360,22 @@ get_overlay_plane(struct display *disp, struct buffer *buf) return 0; } +static uint32_t get_prop_id(struct display *disp, + drmModeObjectPropertiesPtr props, const char *name) +{ + drmModePropertyPtr p; + uint32_t i, prop_id = 0; /* Property ID should always be > 0 */ + for (i = 0; !prop_id && i < props->count_props; i++) { + p = drmModeGetProperty(disp->fd, props->props[i]); + if (!strcmp(p->name, name)) + prop_id = p->prop_id; + drmModeFreeProperty(p); + } + if (!prop_id) + printf("Could not find %s property\n", name); + return prop_id; +} + static int post_vid_buffer(struct display *disp, struct buffer *buf, uint32_t x, uint32_t y, uint32_t w, uint32_t h) @@ -366,7 +383,8 @@ post_vid_buffer(struct display *disp, struct buffer *buf, struct display_kms *disp_kms = to_display_kms(disp); struct buffer_kms *buf_kms = to_buffer_kms(buf); int ret = 0; - uint32_t i, j; + uint32_t i, j,k; + uint32_t rotation_pid = 0, rotationMask = disp_kms->rotation ; /* ensure we have the overlay setup: */ for (i = 0; i < disp_kms->connectors_count; i++) { @@ -385,7 +403,28 @@ post_vid_buffer(struct display *disp, struct buffer *buf, } drmModePlane *ovr = drmModeGetPlane(disp->fd, disp_kms->plane_resources->planes[j]); - if (ovr->possible_crtcs & (1 << connector->pipe)) { + if((disp_kms->bo_flags & OMAP_BO_TILED) && rotationMask) + { + drmModeObjectPropertiesPtr props; + props = drmModeObjectGetProperties(disp->fd, ovr->plane_id, DRM_MODE_OBJECT_PLANE); + if (props) { + + rotation_pid = get_prop_id(disp, props, "rotation"); + if(!rotation_pid) + MSG("Rotation not supported\n"); + + drmModeFreeObjectProperties(props); + } + if(rotation_pid) { + ret = drmModeObjectSetProperty(disp->fd, ovr->plane_id, DRM_MODE_OBJECT_PLANE, rotation_pid, rotationMask); + if (ret < 0) { + printf("set rotation property failed\n"); + exit(0); + } + } + } + + if (ovr->possible_crtcs & (1 << connector->pipe)) { disp_kms->ovr[i] = ovr; used_planes |= (1 << j); break; @@ -618,6 +657,25 @@ disp_kms_open(int argc, char **argv) ERROR("invalid arg: %s", argv[i]); goto fail; } + } else if (!strcmp("-r", argv[i])) { + int n; + argv[i++] = NULL; + if(sscanf(argv[i], "%d", &n) != 1) { + ERROR("invalid arg: %s", argv[i]); + goto fail; + } + if(n != 0 && n != 90 && n != 180 && n != 270) { + ERROR("invalid arg: %s rotation 0, 90, 180, 270 are supported", argv[i]); + goto fail; + } + if(n == 90) + disp_kms->rotation = 0x2; + else if(n == 180) + disp_kms->rotation = 0x4; + else if(n == 270) + disp_kms->rotation = 0x8; + else + disp_kms->rotation = 0x1; } else if (!strcmp("-s", argv[i])) { struct connector *connector = &disp_kms->connector[disp_kms->connectors_count++]; -- 1.9.1