From patchwork Fri Aug 21 16:16:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Show Liu X-Patchwork-Id: 9357 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 2B4C5BD87C for ; Fri, 21 Aug 2020 16:16:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EAC1261FE7; Fri, 21 Aug 2020 18:16:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="KSrFtMls"; dkim-atps=neutral Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 12E9F60383 for ; Fri, 21 Aug 2020 18:16:35 +0200 (CEST) Received: by mail-pj1-x1042.google.com with SMTP id t6so1028315pjr.0 for ; Fri, 21 Aug 2020 09:16:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AABaVwCLWJKMc3x6nrrpXEKPsBtmSlwX7fcsA/Kyxpg=; b=KSrFtMlsKdInzHkSnuHHxn0VbrRL6d6UFxUdHo9C1cZ/7j/vczunbIJEAxfKYr+aLr OuFxQoWUxKnpgzbReSWXxESzjUygVrA2tjAPne30Z++oBZWdCE/PM6joFDoyUZqrLK+g ed1yIRIa+EV1eN2M/i4bzeUfLmdRmRgQLSlC4LSCdvmf41hCASUzI4A1wnsp6VPQxLcS 7SOi2iZjWBCz95rQ++mMdgLkQoweykVrsvB1pE0yp0+hsP7PymJnIxlDPrknA50ZW6c2 8+IdjnmwgZ8/Y9EMKuwKvx0HPSeSq7K7a8Ll61kXUYeeDqOeNIbYgm0icWFlEqCdKYqX DOGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AABaVwCLWJKMc3x6nrrpXEKPsBtmSlwX7fcsA/Kyxpg=; b=YxTJ2M+bFAFsDBFkHjJXiP199urZ9HvbcFkO+RXbNQH8g3w59JzoHZKLnIMSphRB1k tRVz+rg6MkSOnyDOWGnO2Lh5iFvvNinMAAlZB71CURnuONPmmhfcB55nP7eQYaY0wsAn X0dK60vVYr1zTm61ILy5jsoSL8daYUEaEBcNjLLx7uTRgyb4WT5vP/oMto8+76UKHW83 UPw+CuSFDJAI0ZVoiWX2hXOEGOZQg1YvxlhtSiKVEI79WKT/YExYhCq11jF5f7FviZbj M2n/p7912F5WKzc3nBM72/Qum6LVR3IEDPtvHw1TUPzjgaEDyJxJlPFyC6HI69+2SS8G kp2A== X-Gm-Message-State: AOAM533V4HZg1Ki96KfEtvELHCYZQxND1RQtXj5TXnm6fMAOTEokg9/i 9iCxLShIYFrLiHG2Xt50nrdTbzHR2OPaOA== X-Google-Smtp-Source: ABdhPJw/0ms84Nj8v3JhE3XSPQP8sAsRpMREyjWEjDQFAY5sSl0S8DiAsRZvHjyJQyANxzvWVbi8fA== X-Received: by 2002:a17:90a:db96:: with SMTP id h22mr3089527pjv.28.1598026593458; Fri, 21 Aug 2020 09:16:33 -0700 (PDT) Received: from localhost.localdomain (2001-b011-200c-3405-5522-d8a8-1333-f09d.dynamic-ip6.hinet.net. [2001:b011:200c:3405:5522:d8a8:1333:f09d]) by smtp.gmail.com with ESMTPSA id h15sm2524184pjf.54.2020.08.21.09.16.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 09:16:33 -0700 (PDT) From: Show Liu To: libcamera-devel@lists.libcamera.org Date: Sat, 22 Aug 2020 00:16:02 +0800 Message-Id: <20200821161602.5093-4-show.liu@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200821161602.5093-1-show.liu@linaro.org> References: <20200821161602.5093-1-show.liu@linaro.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 3/3] qcam: use the OpenGL renderer as NV family YUV format converter 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" qcam: use the OpenGL renderer as NV family YUV format converter Signed-off-by: Show Liu --- src/qcam/main.cpp | 3 +++ src/qcam/main_window.cpp | 2 ++ src/qcam/main_window.h | 1 + src/qcam/viewfinder.cpp | 46 +++++++++++++++++++++++++++++++++------- src/qcam/viewfinder.h | 10 +++++++++ 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp index b3468cb..a336486 100644 --- a/src/qcam/main.cpp +++ b/src/qcam/main.cpp @@ -35,6 +35,9 @@ OptionsParser::Options parseOptions(int argc, char *argv[]) "help"); parser.addOption(OptStream, &streamKeyValue, "Set configuration of a camera stream", "stream", true); + parser.addOption(OptRender, OptionString, + "Choose the render type use qt|gles", "render", + ArgumentRequired, "render"); OptionsParser::Options options = parser.parse(argc, argv); if (options.isSet(OptHelp)) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 7503537..26e8a69 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -106,6 +106,8 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options) connect(&titleTimer_, SIGNAL(timeout()), this, SLOT(updateTitle())); viewfinder_ = new ViewFinder(this); + if (options_.isSet(OptRender)) + viewfinder_->setRender(options_[OptRender].toString().c_str()); connect(viewfinder_, &ViewFinder::renderComplete, this, &MainWindow::queueRequest); setCentralWidget(viewfinder_); diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 3d21779..ecc9938 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -38,6 +38,7 @@ enum { OptCamera = 'c', OptHelp = 'h', OptStream = 's', + OptRender = 'r', }; class CaptureRequest diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp index dcf8a15..7e2b7a7 100644 --- a/src/qcam/viewfinder.cpp +++ b/src/qcam/viewfinder.cpp @@ -20,6 +20,7 @@ #include #include "format_converter.h" +#include "renderer.h" static const QMap nativeFormats { @@ -34,13 +35,15 @@ static const QMap nativeFormats }; ViewFinder::ViewFinder(QWidget *parent) - : QWidget(parent), buffer_(nullptr) + : QWidget(parent), buffer_(nullptr), renderer_(nullptr) { icon_ = QIcon(":camera-off.svg"); } ViewFinder::~ViewFinder() { + if (renderer_) + delete renderer_; } const QList &ViewFinder::nativeFormats() const @@ -59,14 +62,26 @@ int ViewFinder::setFormat(const libcamera::PixelFormat &format, * the destination image. */ if (!::nativeFormats.contains(format)) { - int ret = converter_.configure(format, size); - if (ret < 0) - return ret; + if ((renderType_ == RenderGLES) && + renderer_->configure(format, size)) { + qInfo() << "Using OpenGL shader format conversion from " + << format.toString().c_str(); + } else { + int ret = converter_.configure(format, size); + if (ret < 0) + return ret; + + image_ = QImage(size, QImage::Format_RGB32); - image_ = QImage(size, QImage::Format_RGB32); + qInfo() << "Using software format conversion from" + << format.toString().c_str(); - qInfo() << "Using software format conversion from" - << format.toString().c_str(); + if (renderType_ == RenderGLES) { + renderType_ = RenderQT; + qInfo() << "Using QT rendering due to " + << "OpenGL shader configure failed."; + } + } } else { qInfo() << "Zero-copy enabled"; } @@ -111,7 +126,11 @@ void ViewFinder::render(libcamera::FrameBuffer *buffer, MappedBuffer *map) * Otherwise, convert the format and release the frame * buffer immediately. */ - converter_.convert(memory, size, &image_); + if (renderType_ == RenderGLES) { + renderer_->render(memory); + image_ = QImage(renderer_->toImage()); + } else + converter_.convert(memory, size, &image_); } } @@ -179,3 +198,14 @@ QSize ViewFinder::sizeHint() const { return size_.isValid() ? size_ : QSize(640, 480); } + +void ViewFinder::setRender(std::string render_type) +{ + if (render_type == "gles") { + renderer_ = new Renderer(); + renderer_->initializeGL(); + renderType_ = RenderGLES; + } else { + renderType_ = RenderQT; + } +} diff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h index 26a1320..ed09c1e 100644 --- a/src/qcam/viewfinder.h +++ b/src/qcam/viewfinder.h @@ -20,6 +20,7 @@ #include #include "format_converter.h" +#include "renderer.h" class QImage; @@ -28,6 +29,11 @@ struct MappedBuffer { size_t size; }; +enum RenderType { + RenderGLES, + RenderQT, +}; + class ViewFinder : public QWidget { Q_OBJECT @@ -43,6 +49,7 @@ public: void stop(); QImage getCurrentImage(); + void setRender(std::string render_type); Q_SIGNALS: void renderComplete(libcamera::FrameBuffer *buffer); @@ -66,6 +73,9 @@ private: libcamera::FrameBuffer *buffer_; QImage image_; QMutex mutex_; /* Prevent concurrent access to image_ */ + + Renderer *renderer_; /* OpenGL renderer */ + RenderType renderType_; }; #endif /* __QCAM_VIEWFINDER__ */