From patchwork Thu May 17 22:08:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 10407791 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 563A360247 for ; Thu, 17 May 2018 22:08:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3ABA127F90 for ; Thu, 17 May 2018 22:08:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BA4C283B0; Thu, 17 May 2018 22:08:23 +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 8913727F90 for ; Thu, 17 May 2018 22:08:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4FA4F6EBCC; Thu, 17 May 2018 22:08:20 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-oi0-f53.google.com (mail-oi0-f53.google.com [209.85.218.53]) by gabe.freedesktop.org (Postfix) with ESMTPS id 098DF6EBD9 for ; Thu, 17 May 2018 22:08:19 +0000 (UTC) Received: by mail-oi0-f53.google.com with SMTP id p62-v6so5418946oie.10 for ; Thu, 17 May 2018 15:08:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=V9LNysd1ey2vo13SvL3qrCcNzZ3H0Q2OhxztLfIJfRY=; b=VvnF/5vYIs38DRiPbMhrWoYXuq4nFv8ayZti89zg+/ittfZaproudOpFqKbaqHC24q +4soINl1n0J+XrpjrwcgH3ZT+GXvPVxfFowXhqzJHu+5Rla3naZRNIkW6nEnX7EEH0Si 5twcgftoYHMxiSpOmKbOlfpJeKyzRcpebwHl9FV/FvWTSpwGxBv8WM3/h2ebwvXMLcYZ J5fiY2F0gFrzQyF1h2ThA3Ddsa1t+6OquamIM7W/GtAESgJe+GCqL+W5VAY6Deqno3un H2rTTc8Ma2IcT3R2MkAT5Vc254Tx15aqQ5I1kg8N3/Q5LqWuLDQt5L0v1VOKglGmph/E Qh8w== X-Gm-Message-State: ALKqPwc6fgBDnthK7AZmFnD+e15+KsQMzxxj6AH9/7zKWtDpYcnRfLPb QRUxOqmj/Q7tBCxQrD4ZXcVvZVE= X-Google-Smtp-Source: AB8JxZpPeUms8PnRTdS+aDPf5WSyRQlKrFjRyUIu4wCQ+3MouOkqugiIRttZYi9/0GSiz4B/ON45sg== X-Received: by 2002:aca:2b13:: with SMTP id i19-v6mr4084196oik.292.1526594898019; Thu, 17 May 2018 15:08:18 -0700 (PDT) Received: from xps15.herring.priv (216-188-254-6.dyn.grandenetworks.net. [216.188.254.6]) by smtp.googlemail.com with ESMTPSA id n14-v6sm3128728otf.8.2018.05.17.15.08.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 May 2018 15:08:17 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org, Stefan Schake , John Stultz , Sean Paul , Alexandru-Cosmin Gheorghe , Robert Foss Subject: [PATCH hwc] drm_hwcomposer: Support assigning planes in ValidateDisplay Date: Thu, 17 May 2018 17:08:16 -0500 Message-Id: <20180517220816.31504-1-robh@kernel.org> X-Mailer: git-send-email 2.17.0 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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP In order to assign planes to layers in ValidateDisplay, testing compositing with a DRM atomic modeset test is needed as PresentDisplay is too late. This means most of PresentDisplay needs to be run from ValidateDisplay, so refactor PresentDisplay and plumb a test flag down the stack. Signed-off-by: Rob Herring --- Based on my GL comp removal work. Adding atomic test path turned out to be easier than using the Planner directly. drmdisplaycompositor.cpp | 4 +- drmdisplaycompositor.h | 2 +- drmhwctwo.cpp | 79 ++++++++++++++++++++++++++++++++++------ drmhwctwo.h | 1 + 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/drmdisplaycompositor.cpp b/drmdisplaycompositor.cpp index 2f9f6c6772da..ceee6b1a4bd6 100644 --- a/drmdisplaycompositor.cpp +++ b/drmdisplaycompositor.cpp @@ -469,7 +469,7 @@ void DrmDisplayCompositor::ApplyFrame( } int DrmDisplayCompositor::ApplyComposition( - std::unique_ptr composition) { + std::unique_ptr composition, bool test) { int ret = 0; switch (composition->type()) { case DRM_COMPOSITION_TYPE_FRAME: @@ -481,6 +481,8 @@ int DrmDisplayCompositor::ApplyComposition( ALOGE("Commit test failed for display %d, FIXME", display_); return ret; } + if (test) + return 0; } ApplyFrame(std::move(composition), ret); diff --git a/drmdisplaycompositor.h b/drmdisplaycompositor.h index ed46873c3409..7c5ebb005dc4 100644 --- a/drmdisplaycompositor.h +++ b/drmdisplaycompositor.h @@ -43,7 +43,7 @@ class DrmDisplayCompositor { int Init(DrmResources *drm, int display); std::unique_ptr CreateComposition() const; - int ApplyComposition(std::unique_ptr composition); + int ApplyComposition(std::unique_ptr composition, bool test); int Composite(); void Dump(std::ostringstream *out) const; diff --git a/drmhwctwo.cpp b/drmhwctwo.cpp index deaf14363e8c..19f73e721154 100644 --- a/drmhwctwo.cpp +++ b/drmhwctwo.cpp @@ -480,8 +480,7 @@ void DrmHwcTwo::HwcDisplay::AddFenceToRetireFence(int fd) { } } -HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *retire_fence) { - supported(__func__); +HWC2::Error DrmHwcTwo::HwcDisplay::CreateComposition(bool test) { std::vector layers_map; layers_map.emplace_back(); DrmCompositionDisplayLayersMap &map = layers_map.back(); @@ -494,7 +493,13 @@ HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *retire_fence) { uint32_t client_z_order = 0; std::map z_map; for (std::pair &l : layers_) { - switch (l.second.validated_type()) { + HWC2::Composition comp_type; + if (test) + comp_type = l.second.sf_type(); + else + comp_type = l.second.validated_type(); + + switch (comp_type) { case HWC2::Composition::Device: z_map.emplace(std::make_pair(l.second.z_order(), &l.second)); break; @@ -510,6 +515,10 @@ HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *retire_fence) { if (use_client_layer) z_map.emplace(std::make_pair(client_z_order, &client_layer_)); + if (z_map.empty()) + return HWC2::Error::BadLayer; + + // now that they're ordered by z, add them to the composition for (std::pair &l : z_map) { DrmHwcLayer layer; @@ -521,10 +530,6 @@ HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *retire_fence) { } map.layers.emplace_back(std::move(layer)); } - if (map.layers.empty()) { - *retire_fence = -1; - return HWC2::Error::None; - } std::unique_ptr composition = compositor_.CreateComposition(); @@ -555,13 +560,29 @@ HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *retire_fence) { i = overlay_planes.erase(i); } - AddFenceToRetireFence(composition->take_out_fence()); + if (!test) + AddFenceToRetireFence(composition->take_out_fence()); - ret = compositor_.ApplyComposition(std::move(composition)); + ret = compositor_.ApplyComposition(std::move(composition), test); if (ret) { ALOGE("Failed to apply the frame composition ret=%d", ret); return HWC2::Error::BadParameter; } + return HWC2::Error::None; +} + +HWC2::Error DrmHwcTwo::HwcDisplay::PresentDisplay(int32_t *retire_fence) { + supported(__func__); + HWC2::Error ret; + + ret = CreateComposition(false); + if (ret == HWC2::Error::BadLayer) { + // Can we really have no client or device layers? + *retire_fence = -1; + return HWC2::Error::None; + } + if (ret != HWC2::Error::None) + return ret; // The retire fence returned here is for the last frame, so return it and // promote the next retire fence @@ -586,7 +607,7 @@ HWC2::Error DrmHwcTwo::HwcDisplay::SetActiveConfig(hwc2_config_t config) { compositor_.CreateComposition(); composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_); int ret = composition->SetDisplayMode(*mode); - ret = compositor_.ApplyComposition(std::move(composition)); + ret = compositor_.ApplyComposition(std::move(composition), false); if (ret) { ALOGE("Failed to queue dpms composition on %d", ret); return HWC2::Error::BadConfig; @@ -666,7 +687,7 @@ HWC2::Error DrmHwcTwo::HwcDisplay::SetPowerMode(int32_t mode_in) { compositor_.CreateComposition(); composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_); composition->SetDpmsMode(dpms_value); - int ret = compositor_.ApplyComposition(std::move(composition)); + int ret = compositor_.ApplyComposition(std::move(composition), false); if (ret) { ALOGE("Failed to apply the dpms composition ret=%d", ret); return HWC2::Error::BadParameter; @@ -683,11 +704,47 @@ HWC2::Error DrmHwcTwo::HwcDisplay::SetVsyncEnabled(int32_t enabled) { HWC2::Error DrmHwcTwo::HwcDisplay::ValidateDisplay(uint32_t *num_types, uint32_t *num_requests) { supported(__func__); + size_t plane_count = 0; *num_types = 0; *num_requests = 0; + size_t avail_planes = primary_planes_.size() + overlay_planes_.size(); + + HWC2::Error ret; + + for (std::pair &l : layers_) + l.second.set_validated_type(HWC2::Composition::Invalid); + + ret = CreateComposition(true); + if (ret != HWC2::Error::None) + // Assume the test failed due to overlay planes + avail_planes = 1; + + std::map z_map; + for (std::pair &l : layers_) { + if (l.second.sf_type() == HWC2::Composition::Device) + z_map.emplace(std::make_pair(l.second.z_order(), &l.second)); + } + + /* + * If more layers then planes, save one plane + * for client composited layers + */ + if (avail_planes < layers_.size()) + avail_planes--; + + for (std::pair &l : z_map) { + if (!avail_planes--) + break; + l.second->set_validated_type(HWC2::Composition::Device); + } + for (std::pair &l : layers_) { DrmHwcTwo::HwcLayer &layer = l.second; switch (layer.sf_type()) { + case HWC2::Composition::Device: + if (layer.validated_type() == HWC2::Composition::Device) + break; + // fall thru case HWC2::Composition::SolidColor: case HWC2::Composition::Cursor: case HWC2::Composition::Sideband: diff --git a/drmhwctwo.h b/drmhwctwo.h index 0490e2ac7f85..bbf55d9a08bc 100644 --- a/drmhwctwo.h +++ b/drmhwctwo.h @@ -171,6 +171,7 @@ class DrmHwcTwo : public hwc2_device_t { float *min_luminance); HWC2::Error GetReleaseFences(uint32_t *num_elements, hwc2_layer_t *layers, int32_t *fences); + HWC2::Error CreateComposition(bool test); HWC2::Error PresentDisplay(int32_t *retire_fence); HWC2::Error SetActiveConfig(hwc2_config_t config); HWC2::Error SetClientTarget(buffer_handle_t target, int32_t acquire_fence,