From patchwork Mon Mar 23 17:35:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3281 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7B3FD62C88 for ; Mon, 23 Mar 2020 18:36:21 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2150DA31 for ; Mon, 23 Mar 2020 18:36:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584984981; bh=CXKOfeBu+kJFTHGU7KKKu3mJrQaaF4nK76CNfVRNetY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=k/gcgtpKnLr2HeGGG6b1qyIpuIj4z4ErXwJRVhAp3CzNdXIMc0p75Dh3h1lFJKfC5 XwexqbRrt5cGIjk4R6Hm7QNqrQSWlVQT72wHIs3QIWboWMGc4H8mQ+pO1bBzKZWUX9 wY996NOf9K9yKp2zYutb5FlILEWe93Zq6nSWomYo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Mar 2020 19:35:53 +0200 Message-Id: <20200323173559.21109-16-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200323173559.21109-1-laurent.pinchart@ideasonboard.com> References: <20200323173559.21109-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 15/21] qcam: viewfinder: Make the viewfinder hold a reference to a buffer 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: , X-List-Received-Date: Mon, 23 Mar 2020 17:36:26 -0000 The viewfinder is currently expected to render frames to the screen synchronously in the display() function, or at least to copy data so that the buffer can be queued in a new request when the function returns. This prevents optimisations when the capture format is identical to the display format. Make the viewfinder take ownership of the buffer, and notify of its release through a signal. The release is currently still synchronous, this will be addressed in a subsequent patch. Rename the ViewFinder::display() function to render() to better describe its purpose, as it's meant to start the rendering and not display the frame synchronously. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/qcam/main_window.cpp | 13 ++++--------- src/qcam/main_window.h | 4 ++-- src/qcam/meson.build | 1 + src/qcam/viewfinder.cpp | 5 +++-- src/qcam/viewfinder.h | 7 ++++++- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 3711a02c7fdc..e872bdd7ba86 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -63,6 +63,8 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options) connect(&titleTimer_, SIGNAL(timeout()), this, SLOT(updateTitle())); viewfinder_ = new ViewFinder(this); + connect(viewfinder_, &ViewFinder::renderComplete, + this, &MainWindow::queueRequest); setCentralWidget(viewfinder_); adjustSize(); @@ -518,15 +520,8 @@ void MainWindow::processCapture() << "timestamp:" << metadata.timestamp << "fps:" << fixed << qSetRealNumberPrecision(2) << fps; - /* Display the buffer and requeue it to the camera. */ - display(buffer); - - queueRequest(buffer); -} - -void MainWindow::display(FrameBuffer *buffer) -{ - viewfinder_->display(buffer, &mappedBuffers_[buffer]); + /* Render the frame on the viewfinder. */ + viewfinder_->render(buffer, &mappedBuffers_[buffer]); } void MainWindow::queueRequest(FrameBuffer *buffer) diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 33522115b6be..5d6251c83070 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -55,6 +55,8 @@ private Q_SLOTS: void saveImageAs(); + void queueRequest(FrameBuffer *buffer); + private: int createToolbars(); @@ -66,8 +68,6 @@ private: void requestComplete(Request *request); void processCapture(); - void display(FrameBuffer *buffer); - void queueRequest(FrameBuffer *buffer); /* UI elements */ QToolBar *toolbar_; diff --git a/src/qcam/meson.build b/src/qcam/meson.build index 214bfb12aabb..c256d06f8ccf 100644 --- a/src/qcam/meson.build +++ b/src/qcam/meson.build @@ -8,6 +8,7 @@ qcam_sources = files([ qcam_moc_headers = files([ 'main_window.h', + 'viewfinder.h', ]) qcam_resources = files([ diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp index b8feabd5d189..2a35932e0b79 100644 --- a/src/qcam/viewfinder.cpp +++ b/src/qcam/viewfinder.cpp @@ -25,8 +25,7 @@ ViewFinder::~ViewFinder() delete image_; } -void ViewFinder::display(const libcamera::FrameBuffer *buffer, - MappedBuffer *map) +void ViewFinder::render(libcamera::FrameBuffer *buffer, MappedBuffer *map) { if (buffer->planes().size() != 1) { qWarning() << "Multi-planar buffers are not supported"; @@ -44,6 +43,8 @@ void ViewFinder::display(const libcamera::FrameBuffer *buffer, converter_.convert(static_cast(map->memory), buffer->metadata().planes[0].bytesused, image_); update(); + + renderComplete(buffer); } QImage ViewFinder::getCurrentImage() diff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h index 735a6b67e91d..784fcceda5bd 100644 --- a/src/qcam/viewfinder.h +++ b/src/qcam/viewfinder.h @@ -27,15 +27,20 @@ struct MappedBuffer { class ViewFinder : public QWidget { + Q_OBJECT + public: ViewFinder(QWidget *parent); ~ViewFinder(); int setFormat(const libcamera::PixelFormat &format, const QSize &size); - void display(const libcamera::FrameBuffer *buffer, MappedBuffer *map); + void render(libcamera::FrameBuffer *buffer, MappedBuffer *map); QImage getCurrentImage(); +Q_SIGNALS: + void renderComplete(libcamera::FrameBuffer *buffer); + protected: void paintEvent(QPaintEvent *) override; QSize sizeHint() const override;