From patchwork Fri Jul 20 12:50:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1220961 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 630B83FC33 for ; Fri, 20 Jul 2012 12:57:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 47D35A10A1 for ; Fri, 20 Jul 2012 05:57:58 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [95.142.166.194]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E7019EAFB for ; Fri, 20 Jul 2012 05:50:48 -0700 (PDT) Received: from avalon.ideasonboard.com (unknown [91.178.183.173]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9E85735A8C for ; Fri, 20 Jul 2012 14:50:44 +0200 (CEST) From: Laurent Pinchart To: dri-devel@lists.freedesktop.org Subject: [PATCH 6/7] modetest: Move connector and plane parsing to separate functions Date: Fri, 20 Jul 2012 14:50:47 +0200 Message-Id: <1342788648-28528-8-git-send-email-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1342788648-28528-1-git-send-email-laurent.pinchart@ideasonboard.com> References: <1342788648-28528-1-git-send-email-laurent.pinchart@ideasonboard.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org This will make it easier to add additional parameters to the connector and plane arguments. Signed-off-by: Laurent Pinchart --- tests/modetest/modetest.c | 63 +++++++++++++++++++++++++------------------- 1 files changed, 36 insertions(+), 27 deletions(-) diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index 2b3ffbc..3e0af17 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -503,6 +503,7 @@ struct plane { uint32_t w, h; unsigned int fb_id; char format_str[5]; /* need to leave room for terminating \0 */ + unsigned int fourcc; }; static void @@ -1602,16 +1603,10 @@ set_plane(struct kms_driver *kms, struct connector *c, struct plane *p) uint32_t handles[4], pitches[4], offsets[4] = {0}; /* we only use [0] */ uint32_t plane_id = 0; struct kms_bo *plane_bo; - uint32_t plane_flags = 0, format; + uint32_t plane_flags = 0; int ret, crtc_x, crtc_y, crtc_w, crtc_h; unsigned int i; - format = format_fourcc(p->format_str); - if (format == 0) { - fprintf(stderr, "Unknown format: %s\n", p->format_str); - return -1; - } - /* find an unused plane which can be connected to our crtc */ plane_resources = drmModeGetPlaneResources(fd); if (!plane_resources) { @@ -1642,13 +1637,13 @@ set_plane(struct kms_driver *kms, struct connector *c, struct plane *p) return -1; } - plane_bo = create_test_buffer(kms, format, p->w, p->h, handles, + plane_bo = create_test_buffer(kms, p->fourcc, p->w, p->h, handles, pitches, offsets, PATTERN_TILES); if (plane_bo == NULL) return -1; /* just use single plane format for now.. */ - if (drmModeAddFB2(fd, p->w, p->h, format, + if (drmModeAddFB2(fd, p->w, p->h, p->fourcc, handles, pitches, offsets, &p->fb_id, plane_flags)) { fprintf(stderr, "failed to add fb: %s\n", strerror(errno)); return -1; @@ -1825,6 +1820,36 @@ extern char *optarg; extern int optind, opterr, optopt; static char optstr[] = "ecpmfs:P:v"; +static int parse_connector(struct connector *c, const char *arg) +{ + c->crtc = -1; + + if (sscanf(arg, "%d:%64s", &c->id, &c->mode_str) == 2) + return 0; + + if (sscanf(arg, "%d@%d:%64s", &c->id, &c->crtc, &c->mode_str) == 3) + return 0; + + return -1; +} + +static int parse_plane(struct plane *p, const char *arg) +{ + strcpy(p->format_str, "XR24"); + + if (sscanf(arg, "%d:%dx%d@%4s", &p->con_id, &p->w, &p->h, &p->format_str) != 4 && + sscanf(arg, "%d:%dx%d", &p->con_id, &p->w, &p->h) != 3) + return -1; + + p->fourcc = format_fourcc(p->format_str); + if (p->fourcc == 0) { + fprintf(stderr, "unknown format %s\n", p->format_str); + return -1; + } + + return 0; +} + void usage(char *name) { fprintf(stderr, "usage: %s [-ecpmf]\n", name); @@ -1899,28 +1924,12 @@ int main(int argc, char **argv) test_vsync = 1; break; case 's': - con_args[count].crtc = -1; - if (sscanf(optarg, "%d:%64s", - &con_args[count].id, - con_args[count].mode_str) != 2 && - sscanf(optarg, "%d@%d:%64s", - &con_args[count].id, - &con_args[count].crtc, - con_args[count].mode_str) != 3) + if (parse_connector(&con_args[count], optarg) < 0) usage(argv[0]); count++; break; case 'P': - strcpy(plane_args[plane_count].format_str, "XR24"); - if (sscanf(optarg, "%d:%dx%d@%4s", - &plane_args[plane_count].con_id, - &plane_args[plane_count].w, - &plane_args[plane_count].h, - plane_args[plane_count].format_str) != 4 && - sscanf(optarg, "%d:%dx%d", - &plane_args[plane_count].con_id, - &plane_args[plane_count].w, - &plane_args[plane_count].h) != 3) + if (parse_plane(&plane_args[plane_count], optarg) < 0) usage(argv[0]); plane_count++; break;