From patchwork Sat May 25 22:41:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilia Mirkin X-Patchwork-Id: 10961143 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C946113AD for ; Sat, 25 May 2019 22:42:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B946F28AA0 for ; Sat, 25 May 2019 22:42:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADA1528AA4; Sat, 25 May 2019 22:42:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5B48328AA0 for ; Sat, 25 May 2019 22:42:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 52DFD6E193; Sat, 25 May 2019 22:41:59 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by gabe.freedesktop.org (Postfix) with ESMTPS id C30446E193; Sat, 25 May 2019 22:41:55 +0000 (UTC) Received: by mail-qk1-x743.google.com with SMTP id z6so12791517qkl.10; Sat, 25 May 2019 15:41:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=wDArQINw8ELzPUebApXhBW7+seMGLb3SgCZP5Ql0H6Y=; b=F8+JkM3oTWhfrSZUlvaJNEUGa9sNlkfwZvORKEWTr7kuoNtceTbsyDLBu/3CvvkD2t mH8qAa2OMMFFt/E0s8aZXUdoONKsV2TlY8/vQ1yVLYW5iFlbOEw/Uj4rgMUJoE85OAng FOO4XUtKorLJIkRyJSZqoyfnTHa4sdvJp/pExdtmvjoL1R2zZoHzGUmmOIS3HQM7Gi4l FwEeZDp+V3+y0P5RszMZ763HKDreFIbDcMnqd/9Cu05D3PueDTNOIELgiSyDULsYg2vU /dqi9Zte39kUbumTvg7z950Oby8nGfTrn2IgJL9rhstil7LhZc5YIu016YpmS2Kr1jVh k3kw== X-Gm-Message-State: APjAAAWLAIef6oMQrMcxs0k1UsnBd7Pc4gYEMgnC2X7STS+Nx/TorhkO m7w+F+8KjcovHfaGYlCSy78= X-Google-Smtp-Source: APXvYqyXPBVykIL2KpussrJZpxhkHFac4dvDwxIUAid2H7bdyEU0KfSHanMxbufvVupcl/HnWpiRDA== X-Received: by 2002:ae9:e50f:: with SMTP id w15mr3645373qkf.297.1558824114925; Sat, 25 May 2019 15:41:54 -0700 (PDT) Received: from athos.fios-router.home (pool-173-68-20-215.nycmny.fios.verizon.net. [173.68.20.215]) by smtp.gmail.com with ESMTPSA id 102sm1576876qte.52.2019.05.25.15.41.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 15:41:53 -0700 (PDT) From: Ilia Mirkin To: bskeggs@redhat.com Subject: [PATCH 2/2] drm/nouveau/disp/nv50-: fix center/aspect-corrected scaling Date: Sat, 25 May 2019 18:41:49 -0400 Message-Id: <20190525224149.4652-2-imirkin@alum.mit.edu> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525224149.4652-1-imirkin@alum.mit.edu> References: <20190525224149.4652-1-imirkin@alum.mit.edu> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wDArQINw8ELzPUebApXhBW7+seMGLb3SgCZP5Ql0H6Y=; b=hn7RAbnLiunf11fW5kbXqZdnJ3Q4jMMcbeykzhp1vnr7ES3JUdXYw71CU24/qTDbFQ 7nRYNrTcZThibjx3hAjGHNs4Ss+j8bQgkGKmPU3KxbvnbfuRDFbZiqIdwO4T2oUht2S5 ZlaLyAz7BhwgB0wcxdGWaoDn3ogpeuB/LZmotVVRW+/OA+fowCfiNBgaVrEWBDqV4USf yv6/C0zAljsXTUrsSZ+sVT9CSN2feulEOxcVqJq+8pCtia0rc38L9F30mUd2mfr1VANL BlmmuFn7clIHLgcVNMiVuuSrd6XddO4C8Hx47f5Gk4hkWGF35jIPQiV9KqaJdRUb1RBE s3Nw== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Previously center scaling would get scaling applied to it (when it was only supposed to center the image), and aspect-corrected scaling did not always correctly pick whether to reduce width or height for a particular combination of inputs/outputs. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=110660 Signed-off-by: Ilia Mirkin --- Tested on a 1920x1200-native screen with a 640x480 mode (got letter boxes on the side) and 720x400 mode (got letter boxes on top/bottom). drivers/gpu/drm/nouveau/dispnv50/head.c | 28 +++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/nouveau/dispnv50/head.c b/drivers/gpu/drm/nouveau/dispnv50/head.c index ac97ebce5b35..e2207990d3cc 100644 --- a/drivers/gpu/drm/nouveau/dispnv50/head.c +++ b/drivers/gpu/drm/nouveau/dispnv50/head.c @@ -169,14 +169,34 @@ nv50_head_atomic_check_view(struct nv50_head_atom *armh, */ switch (mode) { case DRM_MODE_SCALE_CENTER: - asyh->view.oW = min((u16)umode->hdisplay, asyh->view.oW); - asyh->view.oH = min((u16)umode_vdisplay, asyh->view.oH); - /* fall-through */ + /* NOTE: This will cause scaling when the input is + * larger than the output. + */ + asyh->view.oW = min(asyh->view.iW, asyh->view.oW); + asyh->view.oH = min(asyh->view.iH, asyh->view.oH); + break; case DRM_MODE_SCALE_ASPECT: - if (asyh->view.oH < asyh->view.oW) { + /* Determine whether the scaling should be on width or on + * height. This is done by comparing the aspect ratios of the + * sizes. If the output AR is larger than input AR, that means + * we want to change the width (letterboxed on the + * left/right), otherwise on the height (letterboxed on the + * top/bottom). + * + * E.g. 4:3 (1.333) AR image displayed on a 16:10 (1.6) AR + * screen will have letterboxes on the left/right. However a + * 16:9 (1.777) AR image on that same screen will have + * letterboxes on the top/bottom. + * + * inputAR = iW / iH; outputAR = oW / oH + * outputAR > inputAR is equivalent to oW * iH > iW * oH + */ + if (asyh->view.oW * asyh->view.iH > asyh->view.iW * asyh->view.oH) { + /* Recompute output width, i.e. left/right letterbox */ u32 r = (asyh->view.iW << 19) / asyh->view.iH; asyh->view.oW = ((asyh->view.oH * r) + (r / 2)) >> 19; } else { + /* Recompute output height, i.e. top/bottom letterbox */ u32 r = (asyh->view.iH << 19) / asyh->view.iW; asyh->view.oH = ((asyh->view.oW * r) + (r / 2)) >> 19; }