From patchwork Mon Feb 7 15:00:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Curtin X-Patchwork-Id: 15338 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id F1DA7BDCBF for ; Mon, 7 Feb 2022 15:01:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 18E1561070; Mon, 7 Feb 2022 16:01:22 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="YcGu80MM"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A72C960E58 for ; Mon, 7 Feb 2022 16:01:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644246078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+/ce/bTMCeXhfBG/CcISIXicWhiLJVLPvUfdMeodz2M=; b=YcGu80MML/VtK8115p+pFA3sf+vEg6AZGkVKhGbHaxpAjr8bhARIwQrOOuGAXhtSUuFmkB XgBlE+C4j7b7bvHFyCDRoKfpnMTBY4LsRjuK0m+bYhXG0JCGISTtAyqkdW5Tq+Fwp1M+Cc MvVoOmkGAIT+bchEKqctpQj9nnXJIeM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-650-6V6I3cOVN6KVxR2cNlBSIw-1; Mon, 07 Feb 2022 10:01:16 -0500 X-MC-Unique: 6V6I3cOVN6KVxR2cNlBSIw-1 Received: by mail-wm1-f72.google.com with SMTP id l4-20020a05600c4f0400b0037bb2ce79d8so4089894wmq.9 for ; Mon, 07 Feb 2022 07:01:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+/ce/bTMCeXhfBG/CcISIXicWhiLJVLPvUfdMeodz2M=; b=LNJcjvZ7uf7/ITWdpfshdmRdqTaSzNIsdyXyvfvERHnJZmczA2UFCIRxeC/ffmwAj+ MP3zQB1qzZiwxZKWqZxxSTBvdRBMv+JPduPHJdqQNhZBSPjXoUxWQE3goVhh9MkNoF5f dIW8NKC+OUvC0qgkCRPjz31UKuQnahz4jAq+GLf3aVg8EMnGBVqm0QTpqvUWLx+poYJp lss/ov8ux2Vn8NQM9UNvVUUCusyNDs0JAyAHx6YtYUaNRcTbtIAd+UffDXnvvtBKSrqO GyDLvhlibNRaU0vbByUzOWw+hz/xGYsgvdxpgsqH9/OWyc70EFv3OEpb1o7+T9IWMQts OoCQ== X-Gm-Message-State: AOAM532OUcNNIVJ1foRgt4D800tTTST1vZSirymKrOP4Ne5R0rG60P8Y N+fl0wlxqS0JITzqSeE0RV/auVsOmsIbVNMIt6RtP2WbGx83LgPgw4qPyXUQJZ8kThaLtYjwEhq EZMQwf547KIe5x4+Wc6pT/T2qNfHDvXDTnoQQr2KXU5eMofPcZEtSLf+gyOL//on0tznEzUq6he xsid9Nf568 X-Received: by 2002:adf:e0c9:: with SMTP id m9mr10026200wri.435.1644246074411; Mon, 07 Feb 2022 07:01:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJwsvSzRq76c0fr9OegFlqaCPxvQJt4Lc21TUGSYQm7LeXRtQjtOC09PIBYU33oEloam5HaQ/A== X-Received: by 2002:adf:e0c9:: with SMTP id m9mr10026177wri.435.1644246074133; Mon, 07 Feb 2022 07:01:14 -0800 (PST) Received: from p1.Home ([2001:8a0:6724:4500:a69c:e66f:828e:b340]) by smtp.gmail.com with ESMTPSA id b2sm11112320wri.88.2022.02.07.07.01.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 07:01:13 -0800 (PST) From: Eric Curtin To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Feb 2022 15:00:59 +0000 Message-Id: <20220207150059.22515-1-ecurtin@redhat.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [libcamera-devel] [PATCH v2] cam: kms_sink: Remove limitation that camera and display must match X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" There is a limitation that requires input and output to be pixel for pixel identical in terms of height and width. Remove this limitation to enable more hardware that doesn't match exactly in terms of pixels. Centralize the image. This works for the case where camera output has more pixels than the display and vice-versa. In the case where there are too many pixels for the display, we take the most central part of the image cropping out the border. Signed-off-by: Eric Curtin --- Changes in v2: - Tested and support drawing from negative pixel range kernel parameter (video=960x540@60) was useful here src/cam/kms_sink.cpp | 32 ++++++++++++++------------------ src/cam/kms_sink.h | 2 ++ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/cam/kms_sink.cpp b/src/cam/kms_sink.cpp index 973cd370..8eb51454 100644 --- a/src/cam/kms_sink.cpp +++ b/src/cam/kms_sink.cpp @@ -113,24 +113,20 @@ int KMSSink::configure(const libcamera::CameraConfiguration &config) const libcamera::StreamConfiguration &cfg = config.at(0); const std::vector &modes = connector_->modes(); - const auto iter = std::find_if(modes.begin(), modes.end(), - [&](const DRM::Mode &mode) { - return mode.hdisplay == cfg.size.width && - mode.vdisplay == cfg.size.height; - }); - if (iter == modes.end()) { - std::cerr - << "No mode matching " << cfg.size.toString() - << std::endl; - return -EINVAL; - } int ret = configurePipeline(cfg.pixelFormat); if (ret < 0) return ret; - mode_ = &*iter; + mode_ = &modes[0]; size_ = cfg.size; + + // We need to cast for the case where the camera output has more + // pixels than the display, in this case we start drawing from a + // negative pixel point to crop out the content to display just + // the middle part. + x_ = (mode_->hdisplay - static_cast(size_.width)) / 2; + y_ = (mode_->vdisplay - static_cast(size_.height)) / 2; stride_ = cfg.stride; return 0; @@ -297,12 +293,12 @@ bool KMSSink::processRequest(libcamera::Request *camRequest) drmRequest->addProperty(plane_, "CRTC_ID", crtc_->id()); drmRequest->addProperty(plane_, "SRC_X", 0 << 16); drmRequest->addProperty(plane_, "SRC_Y", 0 << 16); - drmRequest->addProperty(plane_, "SRC_W", mode_->hdisplay << 16); - drmRequest->addProperty(plane_, "SRC_H", mode_->vdisplay << 16); - drmRequest->addProperty(plane_, "CRTC_X", 0); - drmRequest->addProperty(plane_, "CRTC_Y", 0); - drmRequest->addProperty(plane_, "CRTC_W", mode_->hdisplay); - drmRequest->addProperty(plane_, "CRTC_H", mode_->vdisplay); + drmRequest->addProperty(plane_, "SRC_W", size_.width << 16); + drmRequest->addProperty(plane_, "SRC_H", size_.height << 16); + drmRequest->addProperty(plane_, "CRTC_X", x_); + drmRequest->addProperty(plane_, "CRTC_Y", y_); + drmRequest->addProperty(plane_, "CRTC_W", size_.width); + drmRequest->addProperty(plane_, "CRTC_H", size_.height); flags |= DRM::AtomicRequest::FlagAllowModeset; } diff --git a/src/cam/kms_sink.h b/src/cam/kms_sink.h index 4a0a872c..2c16182c 100644 --- a/src/cam/kms_sink.h +++ b/src/cam/kms_sink.h @@ -61,6 +61,8 @@ private: libcamera::PixelFormat format_; libcamera::Size size_; unsigned int stride_; + int x_; // Where to start drawing camera output + int y_; // Where to start drawing camera output std::map> buffers_;