Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp5847023ybn; Sun, 29 Sep 2019 07:01:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpAb4vzMDHdwT6VhZhqhGlnbI5lN0Z+5qY6sn1fXqz7s4MXkyJrX6uhTgVqopxVTdYtAPZ X-Received: by 2002:a50:9402:: with SMTP id p2mr14670273eda.111.1569765675588; Sun, 29 Sep 2019 07:01:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569765675; cv=none; d=google.com; s=arc-20160816; b=E7+ruzxjIDAljdOXax9egW3EoHBT/kRFL6FXXGc7TaMPppJk3aBm/rthy0sw5eoNgU /ECtEpLg12dd89wM/2wzkBttaP/jqBAdmclyM51mbAic/HZMFIMl4peHKVYdpFRc/7ZG GPs/b6g162jy+t3tFOgrvAnGIi2xP/iqZKXzli+KhopdddvYpP2n4u0miY1JxiXMNLSZ WsBX+sFFq3Z0/ka+iVQ3xDe88UhZZPgE/lb23npf4lYSl/AO/8ZN3Paz1yAHoyS7rXGi VEHvCLGz84/wg/bWOZTBYYu3cqNk7vE5UDc/e2cfZMw+AYJ8RF8TmSkDcDTxGlDcHJLE 6LeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D5+i2wMyL9BDnS+nIAxlWsjyaOIEA//nzy388dXZJDU=; b=WHDOZ99H4qWV8g9GGIYMHzki6RKs9QxiacajcLJzzdiaSfm3Jzyo0omdsngCUoGgVQ MuXFWL7HKKu4qYel2GD+im11wpRAgJMJ6crJR+kshv76x/tY0aFis29LmWrOQkZXwGvk fZUBBEztsFzaBU57OM0TpueaiUm6SagkGU19oUFN2JtAfk253JnE3IjQSJx7+WS2fLlo 0jzgX1/hrRE3gFh+Za2PtiZRxQNQz9eBds6aswU/vqS22KdPpSQ4RCSmbbx/cV/dcWV8 zONHUprwP8ZrcKSj1tnBKz74+TiPJqdKjzG2i4HhnUR+4cyoxkjnyq5n/0z7WigG1p7w hu6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="fPcsS/gL"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u23si5515780ejr.204.2019.09.29.07.00.51; Sun, 29 Sep 2019 07:01:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="fPcsS/gL"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729223AbfI2OAH (ORCPT + 99 others); Sun, 29 Sep 2019 10:00:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:41640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729545AbfI2OAE (ORCPT ); Sun, 29 Sep 2019 10:00:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F2E2E21835; Sun, 29 Sep 2019 14:00:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569765603; bh=wqdPdG1t5Mk1aHnax6epbpMt8if7rIZmNdAUg59W+/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fPcsS/gLrpB4sMf9Isc4CGvJkgNsyrAoXt87Ijpir7hMzkCQB5z582qA5ZRqjqkn+ ffn1z5c/uWvrjF9wiaaI/RCBhduV/55mSJXs5QCDGFU9pYb4eXTOpxqMEkF4YvuwCX rDDCsibozdqYIteUyVbewLqbD5qgGyDoWdUmYRHw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ilia Mirkin , Ben Skeggs , Sasha Levin Subject: [PATCH 4.19 58/63] drm/nouveau/disp/nv50-: fix center/aspect-corrected scaling Date: Sun, 29 Sep 2019 15:54:31 +0200 Message-Id: <20190929135041.002602169@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190929135031.382429403@linuxfoundation.org> References: <20190929135031.382429403@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilia Mirkin [ Upstream commit 533f4752407543f488a9118d817b8c504352b6fb ] 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 Signed-off-by: Ben Skeggs Signed-off-by: Sasha Levin --- 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 d81a99bb2ac31..b041ffb3af270 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; } -- 2.20.1