diff options
author | Yang Wei <yangweix.shui@intel.com> | 2015-03-10 11:10:54 +0800 |
---|---|---|
committer | Yi Sun <yi.sun@intel.com> | 2015-03-11 15:13:03 +0800 |
commit | 0112d4b107bb73a957786164924033aa3260a231 (patch) | |
tree | 8d2c35f86b2bf0b3a1346d1f05060c42bdb0e8a1 | |
parent | e60c3f8c6753ea286600487f5324fcf90e05338f (diff) |
Dynamically set image size and location
-rw-r--r-- | tools/vtview.c | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/tools/vtview.c b/tools/vtview.c index 6b58f58..902a0d3 100644 --- a/tools/vtview.c +++ b/tools/vtview.c @@ -77,6 +77,7 @@ struct termios saved_tio; drmModeRes *resources; int drm_fd, modes; int test_all_modes = 0, test_preferred_mode = 0; +char *image_name; unsigned int tiling = I915_TILING_X; //tiling = I915_TILING_NONE; int sleep_between_modes = 5; @@ -135,29 +136,30 @@ static void connector_find_preferred_mode(uint32_t connector_id, } c->mode_valid = 1; } - -static void paint_image(cairo_t *cr, const char *file) +struct image_size_location +{ + int img_x; + int img_y; + int img_w; + int img_h; +}; +struct image_size_location isl; +static void paint_image(cairo_t *cr, const char *file, struct image_size_location* isl1) { int img_x, img_y, img_w, img_h, img_w_o, img_h_o; double img_w_scale, img_h_scale; cairo_surface_t *image; - img_y = height * (0.10 ); - img_h = height * 0.08 * 4; - img_w = img_h; - - img_x = (width / 2) - (img_w / 2); - image = cairo_image_surface_create_from_png(file); img_w_o = cairo_image_surface_get_width(image); img_h_o = cairo_image_surface_get_height(image); - cairo_translate(cr, img_x, img_y); + cairo_translate(cr, isl1->img_x, isl1->img_y); - img_w_scale = (double)img_w / (double)img_w_o; - img_h_scale = (double)img_h / (double)img_h_o; + img_w_scale = (double)isl1->img_w / (double)img_w_o; + img_h_scale = (double)isl1->img_h / (double)img_h_o; cairo_scale(cr, img_w_scale, img_h_scale); cairo_set_source_surface(cr, image, 0, 0); @@ -166,8 +168,20 @@ static void paint_image(cairo_t *cr, const char *file) cairo_paint(cr); cairo_surface_destroy(image); } - -static void paint_output_info(struct connector *c, struct igt_fb *fb) +char * str_contact(const char *str1, const char *str2, const char *str3) +{ + char * result; + result = (char*)malloc(strlen(str1) + strlen(str2) + strlen(str3)+ 1); + if(!result){ + printf("Error: malloc failed in concat! \n"); + exit(EXIT_FAILURE); + } + strcpy(result,str1); + strcat(result,str2); + strcat(result,str3); + return result; +} +static void paint_output_info(struct connector *c, struct igt_fb *fb, char *image) { cairo_t *cr = igt_get_cairo_ctx(drm_fd, fb); int l_width = fb->width; @@ -176,9 +190,14 @@ static void paint_output_info(struct connector *c, struct igt_fb *fb) double x, y, top_y; double max_width; int i; + char * img_addr=NULL; + char * separator="/"; - paint_image(cr, IGT_DATADIR"/pass.png"); + if(!image) image="pass.png"; + img_addr=str_contact(IGT_DATADIR,separator,image); + paint_image(cr, img_addr, &isl); + free(img_addr); igt_assert(!cairo_status(cr)); cairo_destroy(cr); @@ -199,11 +218,15 @@ set_mode(struct connector *c) width = c->mode.hdisplay; height = c->mode.vdisplay; + if(!isl.img_y) isl.img_y = height * (0.1 ); + if(!isl.img_h) isl.img_h = height * 0.08 * 4; + if(!isl.img_w) isl.img_w = isl.img_h; + if(!isl.img_x) isl.img_x = (width / 2) - (isl.img_w / 2); fb_id = igt_create_fb(drm_fd, width, height, igt_bpp_depth_to_drm_format(bpp, depth), tiling, &fb_info[current_fb]); - paint_output_info(c, &fb_info[current_fb]); + paint_output_info(c, &fb_info[current_fb], image_name); kmstest_dump_mode(&c->mode); if (drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0, @@ -281,11 +304,11 @@ int update_display(void) return 1; } -static char optstr[] = "3hiaf:s:d:p:mrto:j:"; +static char optstr[] = "3hiaf:s:d:p:mrto:j:l:n:"; static void __attribute__((noreturn)) usage(char *name, char opt) { - igt_info("usage: %s [-hiasdpmtf]\n", name); + igt_info("usage: %s [-hiasdpmtfln]\n", name); igt_info("\t-i\tdump info\n"); igt_info("\t-a\ttest all modes\n"); igt_info("\t-s\t<duration>\tsleep between each mode test\n"); @@ -298,6 +321,8 @@ static void __attribute__((noreturn)) usage(char *name, char opt) igt_info("\t-r\tprint a QR code on the screen whose content is \"pass\" for the automatic test\n"); igt_info("\t-o\t<id of the display>,<number of the mode>\tonly test specified mode on the specified display\n"); igt_info("\t-f\t<clock MHz>,<hdisp>,<hsync-start>,<hsync-end>,<htotal>,\n"); + igt_info("\t-l\t<num,num,num,num>, set image size and location\n"); + igt_info("\t-n\timage name located at tools/\n"); igt_info("\t\t<vdisp>,<vsync-start>,<vsync-end>,<vtotal>\n"); igt_info("\t\ttest force mode\n"); igt_info("\tDefault is to test all modes.\n"); @@ -380,6 +405,8 @@ int main(int argc, char **argv) {"help", 0, 0, 'h'}, { 0, 0, 0, 0 } }; + char delims[] = ","; + char *result = NULL; // igt_skip_on_simulation(); @@ -408,6 +435,17 @@ int main(int argc, char **argv) case 'm': test_preferred_mode = 1; break; + case 'n': + image_name = optarg; + break; + case 'l': + result=strtok(optarg,delims); + isl.img_y = atoi(result); + isl.img_h = atoi(strtok(NULL,delims)); + isl.img_w = atoi(strtok(NULL,delims)); + isl.img_x = atoi(strtok(NULL,delims)); + break; + default: /* fall through */ case 'h': |