From patchwork Wed Aug 20 10:54:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Wood X-Patchwork-Id: 4748971 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B58C4C0338 for ; Wed, 20 Aug 2014 10:54:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8E5C72015A for ; Wed, 20 Aug 2014 10:54:19 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 254352015E for ; Wed, 20 Aug 2014 10:54:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8BF886E221; Wed, 20 Aug 2014 03:54:17 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-we0-f177.google.com (mail-we0-f177.google.com [74.125.82.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 294A66E35D for ; Wed, 20 Aug 2014 03:54:14 -0700 (PDT) Received: by mail-we0-f177.google.com with SMTP id w62so7713571wes.36 for ; Wed, 20 Aug 2014 03:54:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=O/ZfjfFZp/G38lBOffP/1a2ArYwClPSA5utVUgZs0gA=; b=K/3BCZxsq5Pu8S/jBg66hKMjtuZ/pJKl4IxZXrFb0tQOFWnfGybQW+YG3S1Jzhh8Z/ pEsf8RtGnAEwXw9oAc5L6EanteGSosjxflOLXM8H+YnAJBCO+dyUXeBNUG6Gboupc886 EY198rVPNjphwFnZa9+xu0JuuzM0Qi4RyJ5Ma2SBcxOC+oplwEbXXEQdWo/CjsbCzlDj JjdO/UU9P0HN+EqJo2bCNQDN4wDJnPekm26RD0lDOo4r+2L2+/sXGwQNOgDasKLLqfRY +uOzjxYHdDuVhmcBqWt9dRLavlHo4RalemLibxFJipUEMS1KTHnPnYg2gzCwneVPb8dh 0UyQ== X-Gm-Message-State: ALoCoQn8tVexHklAGRe3tE9g0IjUXvWUJmwvyFnufF0f6hwik3LlWiCmL0ba2jQcE87/w92Vp7fq X-Received: by 10.180.97.129 with SMTP id ea1mr14112683wib.29.1408532053283; Wed, 20 Aug 2014 03:54:13 -0700 (PDT) Received: from pistachio.icx.intel.com ([83.217.123.106]) by mx.google.com with ESMTPSA id fa10sm1101615wjd.42.2014.08.20.03.54.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Aug 2014 03:54:12 -0700 (PDT) From: Thomas Wood To: intel-gfx@lists.freedesktop.org Date: Wed, 20 Aug 2014 11:54:08 +0100 Message-Id: <1408532049-9215-2-git-send-email-thomas.wood@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1408532049-9215-1-git-send-email-thomas.wood@intel.com> References: <1408532049-9215-1-git-send-email-thomas.wood@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 2/3] lib: move create_stereo_fb from testdisplay to igt_fb X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move create_stereo_fb from testdisplay to igt_create_stereo_fb in igt_fb so that it can be used in other tests. Signed-off-by: Thomas Wood --- lib/Makefile.am | 4 +- lib/igt_fb.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_fb.h | 2 + lib/igt_kms.h | 1 + tests/testdisplay.c | 116 +--------------------------------------------- 5 files changed, 138 insertions(+), 116 deletions(-) diff --git a/lib/Makefile.am b/lib/Makefile.am index 001ecab..36cf2d3 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -7,7 +7,9 @@ noinst_LTLIBRARIES = libintel_tools.la noinst_HEADERS = check-ndebug.h AM_CPPFLAGS = -I$(top_srcdir) -AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) +AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) \ + -DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\" + LDADD = $(CAIRO_LIBS) AM_CFLAGS += $(CAIRO_CFLAGS) diff --git a/lib/igt_fb.c b/lib/igt_fb.c index d07af0d..9a13969 100644 --- a/lib/igt_fb.c +++ b/lib/igt_fb.c @@ -507,6 +507,137 @@ unsigned int igt_create_color_fb(int fd, int width, int height, return fb_id; } + +struct box { + int x, y, width, height; +}; + +struct stereo_fb_layout { + int fb_width, fb_height; + struct box left, right; +}; + +static void box_init(struct box *box, int x, int y, int bwidth, int bheight) +{ + box->x = x; + box->y = y; + box->width = bwidth; + box->height = bheight; +} + + +static void stereo_fb_layout_from_mode(struct stereo_fb_layout *layout, + drmModeModeInfo *mode) +{ + unsigned int format = mode->flags & DRM_MODE_FLAG_3D_MASK; + const int hdisplay = mode->hdisplay, vdisplay = mode->vdisplay; + int middle; + + switch (format) { + case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM: + layout->fb_width = hdisplay; + layout->fb_height = vdisplay; + + middle = vdisplay / 2; + box_init(&layout->left, 0, 0, hdisplay, middle); + box_init(&layout->right, + 0, middle, hdisplay, vdisplay - middle); + break; + case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF: + layout->fb_width = hdisplay; + layout->fb_height = vdisplay; + + middle = hdisplay / 2; + box_init(&layout->left, 0, 0, middle, vdisplay); + box_init(&layout->right, + middle, 0, hdisplay - middle, vdisplay); + break; + case DRM_MODE_FLAG_3D_FRAME_PACKING: + { + int vactive_space = mode->vtotal - vdisplay; + + layout->fb_width = hdisplay; + layout->fb_height = 2 * vdisplay + vactive_space; + + box_init(&layout->left, + 0, 0, hdisplay, vdisplay); + box_init(&layout->right, + 0, vdisplay + vactive_space, hdisplay, vdisplay); + break; + } + default: + igt_assert(0); + } +} +static const char *stereo_mode_str(drmModeModeInfo *mode) +{ + unsigned int layout = mode->flags & DRM_MODE_FLAG_3D_MASK; + + switch (layout) { + case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM: + return "TB"; + case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF: + return "SbSH"; + case DRM_MODE_FLAG_3D_FRAME_PACKING: + return "FP"; + default: + igt_assert(0); + } +} + +/** + * igt_create_stereo_fb: + * @drm_fd: open i915 drm file descriptor + * @mode: A stero 3D mode. + * + * Create a framebuffer for use with the stereo 3D mode specified by @mode. + * + * Returns: + * The kms id of the created framebuffer on success or a negative error code on + * failure. + */ +unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode) +{ + struct stereo_fb_layout layout; + cairo_t *cr; + uint32_t fb_id; + struct igt_fb fb; + + /* config */ + int bpp = 32; + int depth = 32; + bool enable_tiling = false; + + stereo_fb_layout_from_mode(&layout, mode); + fb_id = igt_create_fb(drm_fd, layout.fb_width, layout.fb_height, + igt_bpp_depth_to_drm_format(bpp, depth), + enable_tiling, &fb); + cr = igt_get_cairo_ctx(drm_fd, &fb); + + igt_paint_image(cr, IGT_DATADIR"1080p-left.png", + layout.left.x, layout.left.y, + layout.left.width, layout.left.height); + igt_paint_image(cr, IGT_DATADIR"1080p-right.png", + layout.right.x, layout.right.y, + layout.right.width, layout.right.height); + + cairo_destroy(cr); + + { + char buffer[64]; + + snprintf(buffer, sizeof(buffer), "%dx%d@%dHz-%s.png", + mode->hdisplay, + mode->vdisplay, + mode->vrefresh, + stereo_mode_str(mode)); + + igt_write_fb_to_png(drm_fd, &fb, buffer); + } + + return fb_id; +} + static cairo_format_t drm_format_to_cairo(uint32_t drm_format) { struct format_desc_struct *f; diff --git a/lib/igt_fb.h b/lib/igt_fb.h index f5110d4..16f6040 100644 --- a/lib/igt_fb.h +++ b/lib/igt_fb.h @@ -72,6 +72,8 @@ unsigned int igt_create_color_fb(int fd, int width, int height, uint32_t format, bool tiled, double r, double g, double b, struct igt_fb *fb /* out */); +unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode); + void igt_remove_fb(int fd, struct igt_fb *fb); /* cairo-based painting */ diff --git a/lib/igt_kms.h b/lib/igt_kms.h index 921afef..abf4bcf 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -166,6 +166,7 @@ bool kmstest_get_property(int drm_fd, uint32_t object_id, uint32_t object_type, drmModePropertyPtr *prop); void kmstest_unset_all_crtcs(int drm_fd, drmModeResPtr resources); + /* * A small modeset API */ diff --git a/tests/testdisplay.c b/tests/testdisplay.c index 89ee110..f3471af 100644 --- a/tests/testdisplay.c +++ b/tests/testdisplay.c @@ -409,125 +409,11 @@ set_mode(struct connector *c) drmModeFreeConnector(c->connector); } -struct box { - int x, y, width, height; -}; - -struct stereo_fb_layout { - int fb_width, fb_height; - struct box left, right; -}; - -static void box_init(struct box *box, int x, int y, int bwidth, int bheight) -{ - box->x = x; - box->y = y; - box->width = bwidth; - box->height = bheight; -} - -static void stereo_fb_layout_from_mode(struct stereo_fb_layout *layout, - drmModeModeInfo *mode) -{ - unsigned int format = mode->flags & DRM_MODE_FLAG_3D_MASK; - const int hdisplay = mode->hdisplay, vdisplay = mode->vdisplay; - int middle; - - switch (format) { - case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM: - layout->fb_width = hdisplay; - layout->fb_height = vdisplay; - - middle = vdisplay / 2; - box_init(&layout->left, 0, 0, hdisplay, middle); - box_init(&layout->right, - 0, middle, hdisplay, vdisplay - middle); - break; - case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF: - layout->fb_width = hdisplay; - layout->fb_height = vdisplay; - - middle = hdisplay / 2; - box_init(&layout->left, 0, 0, middle, vdisplay); - box_init(&layout->right, - middle, 0, hdisplay - middle, vdisplay); - break; - case DRM_MODE_FLAG_3D_FRAME_PACKING: - { - int vactive_space = mode->vtotal - vdisplay; - - layout->fb_width = hdisplay; - layout->fb_height = 2 * vdisplay + vactive_space; - - box_init(&layout->left, - 0, 0, hdisplay, vdisplay); - box_init(&layout->right, - 0, vdisplay + vactive_space, hdisplay, vdisplay); - break; - } - default: - igt_assert(0); - } -} - -static const char *stereo_mode_str(drmModeModeInfo *mode) -{ - unsigned int layout = mode->flags & DRM_MODE_FLAG_3D_MASK; - - switch (layout) { - case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM: - return "TB"; - case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF: - return "SbSH"; - case DRM_MODE_FLAG_3D_FRAME_PACKING: - return "FP"; - default: - igt_assert(0); - } -} - -static uint32_t create_stereo_fb(drmModeModeInfo *mode, struct igt_fb *fb) -{ - struct stereo_fb_layout layout; - cairo_t *cr; - uint32_t fb_id; - - stereo_fb_layout_from_mode(&layout, mode); - fb_id = igt_create_fb(drm_fd, layout.fb_width, layout.fb_height, - igt_bpp_depth_to_drm_format(bpp, depth), - enable_tiling, fb); - cr = igt_get_cairo_ctx(drm_fd, fb); - - igt_paint_image(cr, IGT_DATADIR"/1080p-left.png", - layout.left.x, layout.left.y, - layout.left.width, layout.left.height); - igt_paint_image(cr, IGT_DATADIR"/1080p-right.png", - layout.right.x, layout.right.y, - layout.right.width, layout.right.height); - - cairo_destroy(cr); - - { - char buffer[64]; - - snprintf(buffer, sizeof(buffer), "%dx%d@%dHz-%s.png", - mode->hdisplay, - mode->vdisplay, - mode->vrefresh, - stereo_mode_str(mode)); - - igt_write_fb_to_png(drm_fd, fb, buffer); - } - - return fb_id; -} - static void do_set_stereo_mode(struct connector *c) { uint32_t fb_id; - struct igt_fb fb_info; - fb_id = create_stereo_fb(&c->mode, &fb_info); + fb_id = igt_create_stereo_fb(drm_fd, &c->mode); igt_warn_on_f(drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0, &c->id, 1, &c->mode), "failed to set mode (%dx%d@%dHz): %s\n", width, height, c->mode.vrefresh, strerror(errno));