Return-Path: Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2042.outbound.protection.outlook.com [40.107.92.42]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5B53210E256 for ; Mon, 18 Apr 2022 22:19:35 +0000 (UTC) From: David Zhang To: Date: Mon, 18 Apr 2022 18:18:17 -0400 Message-ID: <20220418221820.2490163-2-dingchen.zhang@amd.com> In-Reply-To: <20220418221820.2490163-1-dingchen.zhang@amd.com> References: <20220418221820.2490163-1-dingchen.zhang@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Subject: [igt-dev] [PATCH v2 1/4] tests/amdgpu/amd_psr: add helper to draw cursor pattern List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: [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 Cc: Harry Wentland Cc: Leo Li Cc: Jay Pillai Cc: Wayne Lin Signed-off-by: David Zhang --- tests/amdgpu/amd_psr.c | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/amdgpu/amd_psr.c b/tests/amdgpu/amd_psr.c index d4bfb7bb..e3a2cb4a 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) { -- 2.25.1