summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zhang <dingchen.zhang@amd.com>2022-04-26 10:29:03 -0400
committerDavid Zhang <dingchen.zhang@amd.com>2022-04-27 09:13:55 -0400
commit1bc4e7c3759ec8bc50f2633839d8edd23ab426ae (patch)
tree2bd756e5a6e4b5be8828410ae954426e9c779afd
parent8da0e93c79b1431349cd789f4c1771ae27949488 (diff)
tests/amdgpu/amd_psr: add helper to draw cursor pattern
[why & how] For amdgpu PSR-SU validation, we'd create and test cursor update use case as well. To emulate a mouse-like cursor movement, we'd define a helper to draw a cursor pattern. - helper draw the cursor pattern as an 45-degrees rotated arrow - for the region of arrow, set alpha to 1 to make cursor foreground and always on the top - for rest of the non-arrow region, set alpha to 0 to make it as background Cc: Rodrigo Siqueira <rodrigo.siqueira@amd.com> Cc: Harry Wentland <harry.wentland@amd.com> Cc: Leo Li <sunpeng.li@amd.com> Cc: Jay Pillai <aurabindo.pillai@amd.com> Cc: Wayne Lin <wayne.lin@amd.com> Signed-off-by: David Zhang <dingchen.zhang@amd.com> Reviewed-by: Aurabindo Pillai <aurabindo.pillai@amd.com>
-rw-r--r--tests/amdgpu/amd_psr.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/amdgpu/amd_psr.c b/tests/amdgpu/amd_psr.c
index d4bfb7bb024a..e3a2cb4ad848 100644
--- a/tests/amdgpu/amd_psr.c
+++ b/tests/amdgpu/amd_psr.c
@@ -81,6 +81,53 @@ static void draw_color_alpha(igt_fb_t *fb, int x, int y, int w, int h,
igt_put_cairo_ctx(cr);
}
+/* draw a cursor pattern assuming the FB given is square w/ FORMAT ARGB */
+static void draw_color_cursor(igt_fb_t *fb, int size, double r, double g, double b)
+{
+ cairo_t *cr = igt_get_cairo_ctx(fb->fd, fb);
+ int x, y, line_w;
+
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+
+ /*
+ * draw cursor
+ * recall that alpha blending value:
+ * - 0, output pixel is the background
+ * - 1, output pixel is simply the foreground
+ * - (0, 1), mix of background + foreground
+ */
+
+ /* set cursor FB to background first */
+ igt_paint_color_alpha(cr, 0, 0, size, size, 1.0, 1.0, 1.0, .0);
+
+ /*
+ * draw cursur pattern w/ alpha set to 1
+ * - 1. draw triangle part
+ * - 2. draw rectangle part
+ */
+ for (x = y = 0, line_w = size / 2; line_w > 0; ++y, --line_w)
+ igt_paint_color_alpha(cr, x, y, line_w, 1, r, g, b, 1.0);
+
+ /*
+ * draw rectangle part, split into three geometry parts
+ * - triangle
+ * - rhombus
+ * - reversed triangle
+ */
+ for (x = size * 3 / 8, y = size / 8, line_w = 1; y < size * 3 / 8; --x, ++y, line_w += 2)
+ igt_paint_color_alpha(cr, x, y, line_w, 1, r, g, b, 1.0);
+
+ for (x = size / 8, y = size * 3 / 8; y < size * 3 / 4; ++x, ++y)
+ igt_paint_color_alpha(cr, x, y, line_w, 1, r, g, b, 1.0);
+
+ for (; line_w > 0; ++x, ++y, line_w -= 2)
+ igt_paint_color_alpha(cr, x, y, line_w, 1, r, g, b, 1.0);
+
+ cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+
+ igt_put_cairo_ctx(cr);
+}
+
/* Common test setup. */
static void test_init(data_t *data)
{