From patchwork Fri Aug 26 09:22:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 9301055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0D2EE607F0 for ; Fri, 26 Aug 2016 09:38:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3942295C0 for ; Fri, 26 Aug 2016 09:38:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8548295FC; Fri, 26 Aug 2016 09:38:21 +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=-3.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_WEB, T_DKIM_INVALID 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 83ABD295C0 for ; Fri, 26 Aug 2016 09:38:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 92B9E6E3BE; Fri, 26 Aug 2016 09:38:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf0-x241.google.com (mail-lf0-x241.google.com [IPv6:2a00:1450:4010:c07::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id F2B646E386 for ; Fri, 26 Aug 2016 09:29:37 +0000 (UTC) Received: by mail-lf0-x241.google.com with SMTP id f93so3497413lfi.0 for ; Fri, 26 Aug 2016 02:29:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=n+JVahnzhm1NMtSl1dTecQTZoSlsMJ9dvTCIXs5yYzA=; b=bcNJWGylD8E/tPBUCaZb3dPGDVHCJhIK9tueijBRLZvHmDCPRp/NfByfwU3kOmCxs2 bPrAPb6eGXq33k/Cxnbh6Gn/IwRSKMEERXMmxlN/35q0ewDRNU5nqTdgoKL1+f4QItZp BEmNuTE6CL8INCuNA4Ssoz2t/FZEMOMWuEMa0F9qNiZ7+obkpbQNDq+S7T36IGARujoD WBftXs83/i9n9nvyNdrK0tiWXSOytxh7Tn28400OZ51fDe/Fp9+VaAbxLa21avFO9+zO CY/V3meNcFwLs90wRIjkQuRTI/AYjANmB4S2cSSES+q4V1iTSTTEVM+Ud6mM/1oXFDFU SwFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=n+JVahnzhm1NMtSl1dTecQTZoSlsMJ9dvTCIXs5yYzA=; b=bESM5aqi8zJ7zkPjnk1QsbOo8ZkXkPw7zLHLWSbYjOp09/Z3QuYE4OPvkJqWi6//hm QuTZN9OKtrCuAxWAb5PMgrVAu5fgypI+wk53u5aTUm0z1O9ZYXWByu66VPuaeI6Gn21M 4Jb9qPh/hnw+NgwCtlvBwpjmdS5ECUs1GrpBa3Am3sJSHmezwE2Ro/AYCS9qgHJ2cceu +5t5/fJq4dkcNLwJPB3kNqK3zyGMws28i7hEfbFfC6hmm23RsAGXq4Od27KIjYK/f8vG PaEzHZaSb+6uYYU675ITfhzaMwViKr9Kh0qf2d7yjjKpx6vtDZOoA1lsbU/4HoFnBV52 /S7A== X-Gm-Message-State: AE9vXwNH1q5al1y9N97HjA89MmnNXymRI4MvJMu22IV5hKOPKluY+DwMsM6Eyw914/DncQ== X-Received: by 10.25.160.15 with SMTP id j15mr673473lfe.109.1472203776187; Fri, 26 Aug 2016 02:29:36 -0700 (PDT) Received: from localhost.localdomain (ppp109-252-52-17.pppoe.spdop.ru. [109.252.52.17]) by smtp.gmail.com with ESMTPSA id h31sm3747486ljh.27.2016.08.26.02.29.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Aug 2016 02:29:35 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding Subject: [PATCH] drm/tegra: dc: Apply clipping to the overlay plane Date: Fri, 26 Aug 2016 12:22:26 +0300 Message-Id: <20160826092433.23771-1-digetx@gmail.com> X-Mailer: git-send-email 2.9.3 X-Mailman-Approved-At: Fri, 26 Aug 2016 09:38:09 +0000 Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Overlay plane should be clipped, otherwise overlay output gets distorted once plane crosses display boundary. As a "side effect" this patch also adds a sanity check for the primary plane, insuring that it covers whole display area. Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/tegra/dc.c | 85 ++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c index 4010d69..ddac53c 100644 --- a/drivers/gpu/drm/tegra/dc.c +++ b/drivers/gpu/drm/tegra/dc.c @@ -480,31 +480,24 @@ static const struct drm_plane_funcs tegra_primary_plane_funcs = { .atomic_destroy_state = tegra_plane_atomic_destroy_state, }; -static int tegra_plane_state_add(struct tegra_plane *plane, - struct drm_plane_state *state) +static void tegra_plane_state_add(struct tegra_plane *plane, + struct drm_crtc_state *crtc_state) { - struct drm_crtc_state *crtc_state; - struct tegra_dc_state *tegra; - - /* Propagate errors from allocation or locking failures. */ - crtc_state = drm_atomic_get_crtc_state(state->state, state->crtc); - if (IS_ERR(crtc_state)) - return PTR_ERR(crtc_state); - - tegra = to_dc_state(crtc_state); + struct tegra_dc_state *tegra = to_dc_state(crtc_state); tegra->planes |= WIN_A_ACT_REQ << plane->index; - - return 0; } static int tegra_plane_atomic_check(struct drm_plane *plane, - struct drm_plane_state *state) + struct drm_plane_state *state, + bool overlay) { struct tegra_plane_state *plane_state = to_tegra_plane_state(state); struct tegra_bo_tiling *tiling = &plane_state->tiling; struct tegra_plane *tegra = to_tegra_plane(plane); struct tegra_dc *dc = to_tegra_dc(state->crtc); + struct drm_crtc_state *crtc_state; + struct drm_rect clip; int err; /* no need for further checks if the plane is being disabled */ @@ -538,13 +531,38 @@ static int tegra_plane_atomic_check(struct drm_plane *plane, } } - err = tegra_plane_state_add(tegra, state); + /* propagate errors from allocation or locking failures. */ + crtc_state = drm_atomic_get_crtc_state(state->state, state->crtc); + if (IS_ERR(crtc_state)) + return PTR_ERR(crtc_state); + + /* check plane for visibility and apply clipping */ + clip.x1 = 0; + clip.y1 = 0; + clip.x2 = crtc_state->mode.hdisplay; + clip.y2 = crtc_state->mode.vdisplay; + + err = drm_plane_helper_check_state(state, &clip, 0, INT_MAX, + overlay, true); if (err < 0) return err; + if (!state->visible) { + DRM_ERROR("hardware doesn't handle invisible plane\n"); + return -EINVAL; + } + + tegra_plane_state_add(tegra, crtc_state); + return 0; } +static int tegra_primary_plane_atomic_check(struct drm_plane *plane, + struct drm_plane_state *state) +{ + return tegra_plane_atomic_check(plane, state, false); +} + static void tegra_plane_atomic_update(struct drm_plane *plane, struct drm_plane_state *old_state) { @@ -560,14 +578,14 @@ static void tegra_plane_atomic_update(struct drm_plane *plane, return; memset(&window, 0, sizeof(window)); - window.src.x = plane->state->src_x >> 16; - window.src.y = plane->state->src_y >> 16; - window.src.w = plane->state->src_w >> 16; - window.src.h = plane->state->src_h >> 16; - window.dst.x = plane->state->crtc_x; - window.dst.y = plane->state->crtc_y; - window.dst.w = plane->state->crtc_w; - window.dst.h = plane->state->crtc_h; + window.src.x = plane->state->src.x1 >> 16; + window.src.y = plane->state->src.y1 >> 16; + window.src.w = drm_rect_width(&plane->state->src) >> 16; + window.src.h = drm_rect_height(&plane->state->src) >> 16; + window.dst.x = plane->state->dst.x1; + window.dst.y = plane->state->dst.y1; + window.dst.w = drm_rect_width(&plane->state->dst); + window.dst.h = drm_rect_height(&plane->state->dst); window.bits_per_pixel = fb->bits_per_pixel; window.bottom_up = tegra_fb_is_bottom_up(fb); @@ -620,7 +638,7 @@ static void tegra_plane_atomic_disable(struct drm_plane *plane, } static const struct drm_plane_helper_funcs tegra_primary_plane_helper_funcs = { - .atomic_check = tegra_plane_atomic_check, + .atomic_check = tegra_primary_plane_atomic_check, .atomic_update = tegra_plane_atomic_update, .atomic_disable = tegra_plane_atomic_disable, }; @@ -675,7 +693,7 @@ static int tegra_cursor_atomic_check(struct drm_plane *plane, struct drm_plane_state *state) { struct tegra_plane *tegra = to_tegra_plane(plane); - int err; + struct drm_crtc_state *crtc_state; /* no need for further checks if the plane is being disabled */ if (!state->crtc) @@ -694,9 +712,12 @@ static int tegra_cursor_atomic_check(struct drm_plane *plane, state->crtc_w != 128 && state->crtc_w != 256) return -EINVAL; - err = tegra_plane_state_add(tegra, state); - if (err < 0) - return err; + /* propagate errors from allocation or locking failures. */ + crtc_state = drm_atomic_get_crtc_state(state->state, state->crtc); + if (IS_ERR(crtc_state)) + return PTR_ERR(crtc_state); + + tegra_plane_state_add(tegra, crtc_state); return 0; } @@ -857,8 +878,14 @@ static const uint32_t tegra_overlay_plane_formats[] = { DRM_FORMAT_YUV422, }; +static int tegra_overlay_plane_atomic_check(struct drm_plane *plane, + struct drm_plane_state *state) +{ + return tegra_plane_atomic_check(plane, state, true); +} + static const struct drm_plane_helper_funcs tegra_overlay_plane_helper_funcs = { - .atomic_check = tegra_plane_atomic_check, + .atomic_check = tegra_overlay_plane_atomic_check, .atomic_update = tegra_plane_atomic_update, .atomic_disable = tegra_plane_atomic_disable, };