Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp327591pxb; Thu, 5 Nov 2020 00:41:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmPjGMLCl3ECvTuKVTNceD6MMoC7MpVW4oF+jW5mywAma+Y0X2KTuZKn7s6JPPzFq3n2QA X-Received: by 2002:a50:8a9c:: with SMTP id j28mr1420235edj.254.1604565689941; Thu, 05 Nov 2020 00:41:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604565689; cv=none; d=google.com; s=arc-20160816; b=SqaJu0E/CRBZHQzHNp+N7lXov9yX/i/2bFpDpm9CC+6ItDJrJFzZXh6unL6OUbVliM HLg9Gb5wNb9+JU1HPWMauxuis+pKObBYjKliH6+pxir49MwRQdcihFQFUZCWaF7Lifj8 sBw4ct6lRWYBO8LxmKhQfZO5eZ6HlcuTEc6McTMx8AQ3FVbDGyzrcT2zWeJKEJlYx/eS iIswo+r5lmSR1KQMQmmeLr51ORAOo9zjbSArhIEpJ7hjTttSzWrF5cLN9O9/swznMJb/ 4zcr5o+vHWY8ZlOpDWJuvziWVPvd8E+7Ql3W1drEgJpX/yADQRkmMhu9axoUTy5bOV9q A1pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=6wjeZnWcVcVQOaETF/+YhonHe5WT40YdCCI3nlOtIAg=; b=OumILbI+WpoA6AKavnIGKNa+KYSN7AXfbEqXE2rX6XGSBD0p4JtRv0PToNtLh43k73 TY9q/vNMQVT3vaXS9KAf0/MNWmRyTmLuYh1lwNBWo/JCEBUjpElBODIZXTjwrlRszYR2 eLFHrf51R6MG157s0+EEMoak4VM2TQmQVR8iVsjcJE6aBL+8pUM9BdYD3sJ4UFtROCzX 0dTAt3oKUgzWx5pSAPVk3uhz5/bTj6vnlAAi8p0KtjY442phA6ra5WDmhxOlKTPEKT7t Y5tDdQcZRALwKQNrNo7vioJA7SukL5w73cuuqNCSHcM9Vr0AZ/1nmCpp/m1wZ/z8lWAc ++2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a17si700373eda.321.2020.11.05.00.41.07; Thu, 05 Nov 2020 00:41:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728855AbgKEIjS (ORCPT + 99 others); Thu, 5 Nov 2020 03:39:18 -0500 Received: from aposti.net ([89.234.176.197]:41310 "EHLO aposti.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727114AbgKEIjR (ORCPT ); Thu, 5 Nov 2020 03:39:17 -0500 From: Paul Cercueil To: David Airlie , Daniel Vetter Cc: Sam Ravnborg , od@zcrc.me, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Paul Cercueil Subject: [PATCH] drm/ingenic: ipu: Search for scaling coefs up to 102% of the screen Date: Thu, 5 Nov 2020 08:39:05 +0000 Message-Id: <20201105083905.8780-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Increase the scaled image's theorical width/height until we find a configuration that has valid scaling coefficients, up to 102% of the screen's resolution. This makes sure that we can scale from almost every resolution possible at the cost of a very small distorsion. The CRTC_W / CRTC_H are not modified. This algorithm was already in place but would not try to go above the screen's resolution, and as a result would only work if the CRTC_W / CRTC_H were smaller than the screen resolution. It will now try until it reaches 102% of the screen's resolution. Signed-off-by: Paul Cercueil --- drivers/gpu/drm/ingenic/ingenic-ipu.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/ingenic/ingenic-ipu.c b/drivers/gpu/drm/ingenic/ingenic-ipu.c index fc8c6e970ee3..e52777ef85fd 100644 --- a/drivers/gpu/drm/ingenic/ingenic-ipu.c +++ b/drivers/gpu/drm/ingenic/ingenic-ipu.c @@ -516,7 +516,7 @@ static void ingenic_ipu_plane_atomic_update(struct drm_plane *plane, static int ingenic_ipu_plane_atomic_check(struct drm_plane *plane, struct drm_plane_state *state) { - unsigned int num_w, denom_w, num_h, denom_h, xres, yres; + unsigned int num_w, denom_w, num_h, denom_h, xres, yres, max_w, max_h; struct ingenic_ipu *ipu = plane_to_ingenic_ipu(plane); struct drm_crtc *crtc = state->crtc ?: plane->state->crtc; struct drm_crtc_state *crtc_state; @@ -558,19 +558,26 @@ static int ingenic_ipu_plane_atomic_check(struct drm_plane *plane, xres = state->src_w >> 16; yres = state->src_h >> 16; - /* Adjust the coefficients until we find a valid configuration */ - for (denom_w = xres, num_w = state->crtc_w; - num_w <= crtc_state->mode.hdisplay; num_w++) + /* + * Increase the scaled image's theorical width/height until we find a + * configuration that has valid scaling coefficients, up to 102% of the + * screen's resolution. This makes sure that we can scale from almost + * every resolution possible at the cost of a very small distorsion. + * The CRTC_W / CRTC_H are not modified. + */ + max_w = crtc_state->mode.hdisplay * 102 / 100; + max_h = crtc_state->mode.vdisplay * 102 / 100; + + for (denom_w = xres, num_w = state->crtc_w; num_w <= max_w; num_w++) if (!reduce_fraction(&num_w, &denom_w)) break; - if (num_w > crtc_state->mode.hdisplay) + if (num_w > max_w) return -EINVAL; - for (denom_h = yres, num_h = state->crtc_h; - num_h <= crtc_state->mode.vdisplay; num_h++) + for (denom_h = yres, num_h = state->crtc_h; num_h <= max_h; num_h++) if (!reduce_fraction(&num_h, &denom_h)) break; - if (num_h > crtc_state->mode.vdisplay) + if (num_h > max_h) return -EINVAL; ipu->num_w = num_w; -- 2.28.0