summaryrefslogtreecommitdiffstats
path: root/src/multimediawidgets/qvideowidget.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-08-24 14:15:42 +0200
committerLars Knoll <lars.knoll@qt.io>2021-08-26 16:29:09 +0200
commit9f69cf3f2e4d3ed643f2a8a412a9ad1ff07d21a5 (patch)
tree2349ad7c936c98dbf6ed27da98d36ddc12b9e154 /src/multimediawidgets/qvideowidget.cpp
parente2e282f19ea53dddcddd0364e60482c50a172b62 (diff)
Implement HW accelerated rendering for QVideoWidget using QVideoWindow
Refactor QVideoWidget to implement HW accelerated rendering by simply embedding a QVideoWindow as a child and making it transparent for input, so the input events continue to go to the QVideoWidget. Pick-to: 6.2 Change-Id: I0dd02ebb784a1d6a51e56aa6b629df0b947292ac Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/multimediawidgets/qvideowidget.cpp')
-rw-r--r--src/multimediawidgets/qvideowidget.cpp81
1 files changed, 15 insertions, 66 deletions
diff --git a/src/multimediawidgets/qvideowidget.cpp b/src/multimediawidgets/qvideowidget.cpp
index 29670c8ef..3be42b73d 100644
--- a/src/multimediawidgets/qvideowidget.cpp
+++ b/src/multimediawidgets/qvideowidget.cpp
@@ -43,6 +43,7 @@
#include <QtCore/qobject.h>
#include <QtMultimedia/qtmultimediaglobal.h>
#include <qvideosink.h>
+#include <private/qvideowindow_p.h>
#include <qobject.h>
#include <qvideoframeformat.h>
@@ -64,12 +65,6 @@ using namespace Qt;
QT_BEGIN_NAMESPACE
-void QVideoWidgetPrivate::_q_newFrame(const QVideoFrame &frame)
-{
- lastFrame = frame;
- q_ptr->update();
-}
-
/*!
\class QVideoWidget
@@ -100,11 +95,13 @@ QVideoWidget::QVideoWidget(QWidget *parent)
, d_ptr(new QVideoWidgetPrivate)
{
d_ptr->q_ptr = this;
- d_ptr->videoSink = new QVideoSink(this);
-
- connect(d_ptr->videoSink, SIGNAL(newVideoFrame(const QVideoFrame &)), this, SLOT(_q_newFrame(const QVideoFrame &)));
+ d_ptr->videoWindow = new QVideoWindow;
+ d_ptr->videoWindow->setFlag(Qt::WindowTransparentForInput, true);
+ d_ptr->windowContainer = QWidget::createWindowContainer(d_ptr->videoWindow, this, Qt::WindowTransparentForInput);
+ d_ptr->windowContainer->move(0, 0);
+ d_ptr->windowContainer->resize(size());
- setAttribute(Qt::WA_UpdatesDisabled);
+ connect(d_ptr->videoWindow, &QVideoWindow::aspectRatioModeChanged, this, &QVideoWidget::aspectRatioModeChanged);
}
/*!
@@ -112,12 +109,13 @@ QVideoWidget::QVideoWidget(QWidget *parent)
*/
QVideoWidget::~QVideoWidget()
{
+ delete d_ptr->videoWindow;
delete d_ptr;
}
QVideoSink *QVideoWidget::videoSink() const
{
- return d_ptr->videoSink;
+ return d_ptr->videoWindow->videoSink();
}
/*!
@@ -127,17 +125,12 @@ QVideoSink *QVideoWidget::videoSink() const
Qt::AspectRatioMode QVideoWidget::aspectRatioMode() const
{
- return d_func()->aspectRatioMode;
+ return d_ptr->videoWindow->aspectRatioMode();
}
void QVideoWidget::setAspectRatioMode(Qt::AspectRatioMode mode)
{
- Q_D(QVideoWidget);
-
- if (mode == d->aspectRatioMode)
- return;
- d->aspectRatioMode = mode;
- emit aspectRatioModeChanged(mode);
+ d_ptr->videoWindow->setAspectRatioMode(mode);
}
/*!
@@ -182,13 +175,9 @@ void QVideoWidget::setFullScreen(bool fullScreen)
*/
QSize QVideoWidget::sizeHint() const
{
- Q_D(const QVideoWidget);
-
- if (d->videoSink) {
- auto size = d->videoSink->videoSize();
- if (size.isValid())
- return size;
- }
+ auto size = videoSink()->videoSize();
+ if (size.isValid())
+ return size;
return QWidget::sizeHint();
}
@@ -239,6 +228,7 @@ void QVideoWidget::hideEvent(QHideEvent *event)
*/
void QVideoWidget::resizeEvent(QResizeEvent *event)
{
+ d_ptr->windowContainer->resize(event->size());
QWidget::resizeEvent(event);
}
@@ -250,47 +240,6 @@ void QVideoWidget::moveEvent(QMoveEvent * /*event*/)
{
}
-/*!
- \reimp
- Handles the paint \a event.
- */
-void QVideoWidget::paintEvent(QPaintEvent *event)
-{
- // ###
- return;
-
- Q_D(QVideoWidget);
-
- if (d->videoSink && d->lastFrame.isValid()) {
- QPainter painter(this);
- QVideoFrame::PaintOptions options = {
- Qt::black, d->aspectRatioMode
- };
- d->lastFrame.paint(&painter, rect(), options);
- return;
- } else if (testAttribute(Qt::WA_OpaquePaintEvent)) {
- QPainter painter(this);
- painter.fillRect(event->rect(), Qt::black);
- }
-}
-
-#if defined(Q_OS_WIN)
-bool QVideoWidget::nativeEvent(const QByteArray &eventType, void *message, qintptr *result)
-{
- Q_D(QVideoWidget);
- Q_UNUSED(eventType);
- Q_UNUSED(result);
-
- MSG *mes = reinterpret_cast<MSG *>(message);
- if (mes->message == WM_PAINT || mes->message == WM_ERASEBKGND) {
-// if (d->windowBackend)
-// d->windowBackend->showEvent();
- }
-
- return false;
-}
-#endif
-
QT_END_NAMESPACE
#include "moc_qvideowidget.cpp"