diff options
author | Dima Zavin <dima@android.com> | 2009-07-24 18:33:09 -0700 |
---|---|---|
committer | Dima Zavin <dima@android.com> | 2009-07-24 18:33:32 -0700 |
commit | 40e98c72f0aed307a63ff533ab15940c188a160e (patch) | |
tree | 159d1ac618d9963c0f7f5ceeccd2df20e07e8164 | |
parent | bc0ae701a10a2be0a3fa66ea3ad2abebbbbe98f7 (diff) | |
download | extras-40e98c72f0aed307a63ff533ab15940c188a160e.tar.gz |
add some configurability to mdp_test
-rw-r--r-- | tests/framebuffer/mdp_test.c | 255 |
1 files changed, 218 insertions, 37 deletions
diff --git a/tests/framebuffer/mdp_test.c b/tests/framebuffer/mdp_test.c index 7307eb91..506852fa 100644 --- a/tests/framebuffer/mdp_test.c +++ b/tests/framebuffer/mdp_test.c @@ -16,12 +16,11 @@ #include <stdlib.h> #include <unistd.h> - #include <fcntl.h> #include <stdio.h> - #include <sys/ioctl.h> #include <sys/mman.h> +#include <sys/stat.h> #include <sys/types.h> #include <linux/fb.h> @@ -29,6 +28,70 @@ static struct fb_var_screeninfo vi; +static int open_file(char *name, int *fd, int *len, int *fmt) +{ + struct stat stat; + char *type, *fn; + + type = name; + fn = strchr(name, ':'); + if (!fn) + return -1; + *(fn++) = '\0'; + + if (!strncmp(type, "yuv420", 6)) + *fmt = MDP_Y_CBCR_H2V2; + else if (!strncmp(type, "rgb565", 6)) + *fmt = MDP_RGB_565; + else { + fprintf(stderr, "Unsupported image type: %s\n", type); + return -1; + } + + *fd = open(fn, O_RDONLY); + if (*fd < 0) { + perror("cannot open file"); + return -1; + } + + if (fstat(*fd, &stat) < 0) { + perror("cannot fstat file"); + goto err; + } + + *len = stat.st_size; + + printf("Successfully opened file %s (fmt=%d len=%d fd=%d)\n", fn, *fmt, + *len, *fd); + return 0; + +err: + close(*fd); + return -1; +} + +static int get_pmem(int *fd, void **data, int sz) +{ + *fd = open("/dev/pmem", O_RDWR | O_NONBLOCK | O_SYNC); + if (*fd < 0) { + perror("cannot open /dev/pmem"); + return -1; + } + + sz = (sz + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); + *data = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, *fd, 0); + if (*data == MAP_FAILED) { + perror("pmem mmap"); + goto err_pmem_mmap; + } + + return 0; + +err_pmem_mmap: + close(*fd); + return -1; +} + static int get_framebuffer(int *fd, char **fb, int *width, int *height) { struct fb_fix_screeninfo fi; @@ -73,71 +136,189 @@ static void set_active_framebuffer(int fd, unsigned n) } } -int main(int argc, const char *argv[]) { - int fd, width, height; +/* geometry: WxH+X+Y */ +int parse_geometry(char *geom, int *w, int *h, int *x, int *y) +{ + char *ptr; + + *w = *h = 0; + + if (!(ptr = strchr(geom, 'x'))) + return -1; + *ptr = '\0'; + *w = atoi(geom); + geom = ptr + 1; + + ptr = strchr(geom, '+'); + if (ptr) + *ptr = '\0'; + *h = atoi(geom); + if (!ptr) + return 0; + + geom = ptr + 1; + + if (!x || !y || !(ptr = strchr(geom, '+'))) + return -1; + *ptr = '\0'; + *x = atoi(geom); + geom = ptr + 1; + + *y = atoi(geom); + + return 0; +} + +int main(int argc, const char *argv[]) +{ + int fb_fd, width, height; char* fb; struct mdp_blit_req_list *req_list; struct mdp_blit_req *req; - int srw, srh, drw, drh; + int opt; + int srcw = 0, srch = 0, dstw = 0, dsth = 0; int srcx = 0; int srcy = 0; int dstx = 10; int dsty = 10; + int src_imgw = 0, src_imgh = 0, dst_imgw = 0, dst_imgh = 0; + int from; + int src_fmt; + int dst_fmt = MDP_RGB_565; + int src_fd = -1; + void *src_data; req_list = malloc(sizeof(struct mdp_blit_req_list) + sizeof(struct mdp_blit_req)); req_list->count = 1; req = req_list->req; - if (argc < 5) - printf("not enough args\n"); - srw = atoi(argv[1]); - srh = atoi(argv[2]); - drw = atoi(argv[3]); - drh = atoi(argv[4]); - if (argc >= 7) { - srcx = atoi(argv[5]); - srcy = atoi(argv[6]); - } + while ((opt = getopt(argc, argv, "s:d:f:t:u:v:")) != -1) { + switch (opt) { + case 's': + if (parse_geometry(optarg, &srcw, &srch, &srcx, &srcy)) { + fprintf(stderr, "Can't parse source\n"); + exit(-1); + } + printf("Got source: w=%d h=%d x=%d y=%d\n", srcw, srch, srcx, srcy); + break; - if (argc == 9) { - dstx = atoi(argv[7]); - dsty = atoi(argv[8]); - } + case 'd': + if (parse_geometry(optarg, &dstw, &dsth, &dstx, &dsty)) { + fprintf(stderr, "Can't parse dest\n"); + exit(-1); + } + printf("Got dest: w=%d h=%d x=%d y=%d\n", dstw, dsth, dstx, dsty); + break; + + case 'u': + if (parse_geometry(optarg, &src_imgw, &src_imgh, NULL, NULL)) { + fprintf(stderr, "Can't parse src image size\n"); + exit(-1); + } + printf("Got src img sz: w=%d h=%d\n", src_imgw, src_imgh); + break; + case 'v': + if (parse_geometry(optarg, &dst_imgw, &dst_imgh, NULL, NULL)) { + fprintf(stderr, "Can't parse dst image size\n"); + exit(-1); + } + printf("Got dst img sz: w=%d h=%d\n", dst_imgw, dst_imgh); + break; - if (get_framebuffer(&fd, &fb, &width, &height)) { + case 'f': + { + int file_fd; + int file_len; + int bytes; + void *ptr; + if (open_file(optarg, &file_fd, &file_len, &src_fmt) < 0) { + fprintf(stderr, "Can't open source file\n"); + exit(-1); + } + + if (get_pmem(&src_fd, &src_data, file_len) < 0) { + close(file_fd); + exit(-1); + } + + ptr = src_data; + while (file_len) { + bytes = read(file_fd, ptr, file_len); + if (bytes < 0) { + perror("Could not read data from file"); + exit(-1); + } + file_len -= bytes; + ptr += bytes; + } + } + break; + + case 't': + if (!strncmp(optarg, "yuv420", 6)) + dst_fmt = MDP_Y_CBCR_H2V2; +#if 0 + else if (!strncmp(optarg, "rgb565", 6)) + dst_fmt = MDP_RGB_565; +#endif + break; + + default: + fprintf(stderr, "Usage: %s -s source -d dest\n", argv[0]); + exit(-1); + } + } + + if (get_framebuffer(&fb_fd, &fb, &width, &height)) { printf("couldnt' get fb\n"); return -1; } - /* - req->src.width = 448; - req->src.height = 320; - */ - req->src.width = vi.xres; - req->src.height = vi.yres; - req->src.format = MDP_RGB_565/*MDP_Y_CBCR_H2V2*/; + + set_active_framebuffer(fb_fd, 0); + + if (!src_imgw || !src_imgh) { + src_imgw = width; + src_imgh = height; + } + + if (!dst_imgw || !dst_imgh) { + dst_imgw = width; + dst_imgh = height; + } + + if (src_fd < 0) { + src_fd = fb_fd; + src_fmt = MDP_RGB_565; + } + + req->src.width = src_imgw; + req->src.height = src_imgh; + req->src.format = src_fmt; req->src.offset = 0; - req->src.memory_id = fd; + req->src.memory_id = src_fd; req->src_rect.x = srcx; req->src_rect.y = srcy; - req->src_rect.w = srw; - req->src_rect.h = srh; + req->src_rect.w = srcw; + req->src_rect.h = srch; - req->dst.width = vi.xres; - req->dst.height = vi.yres; - req->dst.format = MDP_RGB_565; + req->dst.width = dst_imgw; + req->dst.height = dst_imgh; + req->dst.format = dst_fmt; req->dst.offset = 0; - req->dst.memory_id = fd; + req->dst.memory_id = fb_fd; req->dst_rect.x = dstx; req->dst_rect.y = dsty; - req->dst_rect.w = drw; - req->dst_rect.h = drh; + req->dst_rect.w = dstw; + req->dst_rect.h = dsth; req->alpha = MDP_ALPHA_NOP; req->transp_mask = MDP_TRANSP_NOP; // req->flags = MDP_ROT_90; req->flags = MDP_ROT_NOP; - if(ioctl(fd, MSMFB_BLIT, req_list)) + if(ioctl(fb_fd, MSMFB_BLIT, req_list)) fprintf(stderr, "crap, failed blit\n"); + + printf("Done\n"); return 0; } |