summaryrefslogtreecommitdiff
path: root/tests/kms_rotation_crc.c
diff options
context:
space:
mode:
authorDamien Lespiau <damien.lespiau@intel.com>2014-07-08 12:49:03 +0100
committerDamien Lespiau <damien.lespiau@intel.com>2014-07-11 15:12:22 +0100
commit92b29b18ca62d1e1cadf338f1b883a49d3e63a01 (patch)
treef14e9ba857fff2eeb689ce8472c8fd52ade194a6 /tests/kms_rotation_crc.c
parent78fac765238e4b21dd21cf2d105f26955a2f41d8 (diff)
kms_rotation_crc: Factor out the square drawing function
Making function to the similar things is very common in programming. Let's do it once again. Cairo being a drawing library, it can be used to do the rotation! Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Diffstat (limited to 'tests/kms_rotation_crc.c')
-rw-r--r--tests/kms_rotation_crc.c65
1 files changed, 35 insertions, 30 deletions
diff --git a/tests/kms_rotation_crc.c b/tests/kms_rotation_crc.c
index eb633263..5f499d7b 100644
--- a/tests/kms_rotation_crc.c
+++ b/tests/kms_rotation_crc.c
@@ -31,6 +31,7 @@
#include <stdint.h>
#include <stddef.h>
#include <fcntl.h>
+#include <math.h>
#include "drmtest.h"
#include "igt_debugfs.h"
@@ -65,15 +66,39 @@ typedef struct {
int rotate;
} data_t;
+static void
+paint_squares(data_t *data, struct igt_fb *fb, drmModeModeInfo *mode,
+ uint32_t rotation)
+{
+ cairo_t *cr;
+ int w, h;
+
+ w = mode->hdisplay;
+ h = mode->vdisplay;
+
+ cr = igt_get_cairo_ctx(data->gfx_fd, &data->fb);
+
+ if (rotation == DRM_ROTATE_180) {
+ cairo_translate(cr, w, h);
+ cairo_rotate(cr, M_PI);
+ }
+
+ /* Paint with 4 squares of Red, Green, White, Blue Clockwise */
+ igt_paint_color(cr, 0, 0, w/2, h/2, 1.0, 0.0, 0.0);
+ igt_paint_color(cr, (w/2)-1, 0, w/2, h/2, 0.0, 1.0, 0.0);
+ igt_paint_color(cr, 0, (h/2)-1, w/2, h/2, 0.0, 0.0, 1.0);
+ igt_paint_color(cr, (w/2)-1, (h/2)-1, w/2, h/2, 1.0, 1.0, 1.0);
+
+ cairo_destroy(cr);
+}
+
static bool prepare_crtc(data_t *data)
{
drmModeModeInfo *mode;
igt_display_t *display = &data->display;
igt_output_t *output = data->output;
- cairo_t *cr;
igt_plane_t *primary, *sprite;
int fb_id;
- int w, h;
igt_output_set_pipe(output, data->pipe);
igt_display_commit(display);
@@ -98,8 +123,6 @@ static bool prepare_crtc(data_t *data)
case DRM_PLANE_TYPE_OVERLAY: /* Sprite */
igt_info("Sprite plane\n");
mode = igt_output_get_mode(output);
- w = mode->hdisplay;
- h = mode->vdisplay;
fb_id = igt_create_fb(data->gfx_fd,
mode->hdisplay, mode->vdisplay,
@@ -107,13 +130,9 @@ static bool prepare_crtc(data_t *data)
false, /* tiled */
&data->fb);
igt_assert(fb_id);
- cr = igt_get_cairo_ctx(data->gfx_fd, &data->fb);
- /* Paint rotated image of 4 colors */
- igt_paint_color(cr, (w/2)-1, (h/2)-1, w/2, h/2, 1.0, 0.0, 0.0);
- igt_paint_color(cr, 0, (h/2)-1, w/2, h/2, 0.0, 1.0, 0.0);
- igt_paint_color(cr, (w/2)-1, 0, w/2, h/2, 0.0, 0.0, 1.0);
- igt_paint_color(cr, 0, 0, w/2, h/2, 1.0, 1.0, 1.0);
+ paint_squares(data, &data->fb, mode, DRM_ROTATE_180);
+
sprite = igt_output_get_plane(output, IGT_PLANE_2);
igt_plane_set_fb(sprite, &data->fb);
igt_display_commit(display);
@@ -121,12 +140,8 @@ static bool prepare_crtc(data_t *data)
/* Collect reference crc */
igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc[1]);
- /* Paint with 4 squares of Red, Green, White, Blue Clockwise */
- igt_paint_color(cr, 0, 0, w/2, h/2, 1.0, 0.0, 0.0);
- igt_paint_color(cr, (w/2)-1, 0, w/2, h/2, 0.0, 1.0, 0.0);
- igt_paint_color(cr, 0, (h/2)-1, w/2, h/2, 0.0, 0.0, 1.0);
- igt_paint_color(cr, (w/2)-1, (h/2)-1, w/2, h/2, 1.0, 1.0, 1.0);
- cairo_destroy(cr);
+ paint_squares(data, &data->fb, mode, DRM_ROTATE_0);
+
sprite = igt_output_get_plane(output, IGT_PLANE_2);
igt_plane_set_fb(sprite, &data->fb);
igt_display_commit(display);
@@ -135,8 +150,6 @@ static bool prepare_crtc(data_t *data)
case DRM_PLANE_TYPE_PRIMARY: /* Primary */
igt_info("Primary plane\n");
mode = igt_output_get_mode(output);
- w = mode->hdisplay;
- h = mode->vdisplay;
fb_id = igt_create_fb(data->gfx_fd,
mode->hdisplay, mode->vdisplay,
@@ -144,13 +157,9 @@ static bool prepare_crtc(data_t *data)
false, /* tiled */
&data->fb);
igt_assert(fb_id);
- cr = igt_get_cairo_ctx(data->gfx_fd, &data->fb);
- /* Paint rotated image of 4 colors */
- igt_paint_color(cr, (w/2)-1, (h/2)-1, w/2, h/2, 1.0, 0.2, 0.2);
- igt_paint_color(cr, 0, (h/2)-1, w/2, h/2, 0.2, 1.0, 0.2);
- igt_paint_color(cr, (w/2)-1, 0, w/2, h/2, 0.2, 0.2, 1.0);
- igt_paint_color(cr, 0, 0, w/2, h/2, 0.8, 0.8, 0.8);
+ paint_squares(data, &data->fb, mode, DRM_ROTATE_180);
+
primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
igt_plane_set_fb(primary, &data->fb);
igt_display_commit(display);
@@ -158,12 +167,8 @@ static bool prepare_crtc(data_t *data)
/* Collect reference crc */
igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc[0]);
- /* Paint with 4 squares of Red, Green, White, Blue Clockwise */
- igt_paint_color(cr, 0, 0, w/2, h/2, 1.0, 0.2, 0.2);
- igt_paint_color(cr, (w/2)-1, 0, w/2, h/2, 0.2, 1.0, 0.2);
- igt_paint_color(cr, 0, (h/2)-1, w/2, h/2, 0.2, 0.2, 1.0);
- igt_paint_color(cr, (w/2)-1, (h/2)-1, w/2, h/2, 0.8, 0.8, 0.8);
- cairo_destroy(cr);
+ paint_squares(data, &data->fb, mode, DRM_ROTATE_0);
+
primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
igt_plane_set_fb(primary, &data->fb);
igt_display_commit(display);