lib: refactor kmstest_create_fb

Factor out parts that will be used by an upcoming patch adding
kmstest_create_fb2.

Also call the fb paint functions directly, there is not much
point in passing a function pointer for that.

Signed-off-by: Imre Deak <imre.deak@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>
This commit is contained in:
Imre Deak
2013-05-24 17:26:54 +03:00
parent bfb0cdd668
commit f68d964c57
4 changed files with 153 additions and 95 deletions
+18 -12
View File
@@ -844,10 +844,13 @@ static void connector_find_preferred_mode(uint32_t connector_id, int crtc_idx,
o->mode_valid = 1;
}
static void
paint_flip_mode(cairo_t *cr, int width, int height, void *priv)
static void paint_flip_mode(struct kmstest_fb *fb, bool odd_frame)
{
bool odd_frame = (bool) priv;
cairo_t *cr = kmstest_get_cairo_ctx(drm_fd, fb);
int width = fb->width;
int height = fb->height;
kmstest_paint_test_pattern(cr, width, height);
if (odd_frame)
cairo_rectangle(cr, width/4, height/2, width/4, height/8);
@@ -856,6 +859,8 @@ paint_flip_mode(cairo_t *cr, int width, int height, void *priv)
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_fill(cr);
assert(!cairo_status(cr));
}
static int
@@ -991,20 +996,21 @@ static void run_test_on_crtc(struct test_output *o, int crtc_idx, int duration)
o->fb_width *= 2;
o->fb_ids[0] = kmstest_create_fb(drm_fd, o->fb_width, o->fb_height,
o->bpp, o->depth, false, &o->fb_info[0],
paint_flip_mode, (void *)false);
o->bpp, o->depth, false, &o->fb_info[0]);
o->fb_ids[1] = kmstest_create_fb(drm_fd, o->fb_width, o->fb_height,
o->bpp, o->depth, false, &o->fb_info[1],
paint_flip_mode, (void *)true);
o->bpp, o->depth, false, &o->fb_info[1]);
o->fb_ids[2] = kmstest_create_fb(drm_fd, o->fb_width, o->fb_height,
o->bpp, o->depth, true, &o->fb_info[2],
paint_flip_mode, (void *)true);
o->bpp, o->depth, true, &o->fb_info[2]);
if (!o->fb_ids[0] || !o->fb_ids[1] || !o->fb_ids[2]) {
fprintf(stderr, "failed to create fbs\n");
exit(3);
}
paint_flip_mode(&o->fb_info[0], false);
paint_flip_mode(&o->fb_info[1], true);
paint_flip_mode(&o->fb_info[2], true);
set_y_tiling(o, 2);
kmstest_dump_mode(&o->mode);
@@ -1044,9 +1050,9 @@ static void run_test_on_crtc(struct test_output *o, int crtc_idx, int duration)
fprintf(stdout, "\n%s on crtc %d, connector %d: PASSED\n\n",
o->test_name, o->crtc, o->id);
kmstest_remove_fb(drm_fd, o->fb_ids[2]);
kmstest_remove_fb(drm_fd, o->fb_ids[1]);
kmstest_remove_fb(drm_fd, o->fb_ids[0]);
kmstest_remove_fb(drm_fd, &o->fb_info[2]);
kmstest_remove_fb(drm_fd, &o->fb_info[1]);
kmstest_remove_fb(drm_fd, &o->fb_info[0]);
last_connector = NULL;
+10 -5
View File
@@ -258,15 +258,18 @@ static void paint_image(cairo_t *cr, const char *file)
cairo_surface_destroy(image);
}
static void
paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
static void paint_output_info(struct connector *c, struct kmstest_fb *fb)
{
struct connector *c = priv;
cairo_t *cr = kmstest_get_cairo_ctx(drm_fd, fb);
int l_width = fb->width;
int l_height = fb->height;
double str_width;
double x, y, top_y;
double max_width;
int i;
kmstest_paint_test_pattern(cr, l_width, l_height);
cairo_select_font_face(cr, "Helvetica",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
@@ -308,6 +311,8 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
if (qr_code)
paint_image(cr, "./pass.png");
assert(!cairo_status(cr));
}
static void sighandler(int signo)
@@ -362,8 +367,8 @@ set_mode(struct connector *c)
height = c->mode.vdisplay;
fb_id = kmstest_create_fb(drm_fd, width, height, bpp, depth,
enable_tiling, &fb_info,
paint_output_info, c);
enable_tiling, &fb_info);
paint_output_info(c, &fb_info);
fb_ptr = gem_mmap(drm_fd, fb_info.gem_handle,
fb_info.size, PROT_READ | PROT_WRITE);