diff options
author | Jüri Valdmann <juri.valdmann@qt.io> | 2020-07-08 10:29:54 +0200 |
---|---|---|
committer | Jüri Valdmann <juri.valdmann@qt.io> | 2020-07-15 14:38:47 +0200 |
commit | 333a302974216a8f943696f7916a4a944f89b51b (patch) | |
tree | 2b2647cc99718051e4bfd9b47b08f1d953b56270 /src | |
parent | 63dd1416ef90773d6302608c0a27f91bca7338ac (diff) |
Implement more Compositor methods for software mode
Add implementations of devicePixelRatio, textureSize, hasAlphaChannel
also for software mode. Rename textureSize to just size.
Change-Id: I5c515e4fed3330e0ecbfc17e7ec092245a13e619
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/compositor/compositor.cpp | 18 | ||||
-rw-r--r-- | src/core/compositor/compositor.h | 18 | ||||
-rw-r--r-- | src/core/compositor/display_gl_output_surface.cpp | 2 | ||||
-rw-r--r-- | src/core/compositor/display_gl_output_surface.h | 2 | ||||
-rw-r--r-- | src/core/compositor/display_software_output_surface.cpp | 12 | ||||
-rw-r--r-- | src/webengine/render_widget_host_view_qt_delegate_quick.cpp | 11 | ||||
-rw-r--r-- | src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp | 11 |
7 files changed, 36 insertions, 38 deletions
diff --git a/src/core/compositor/compositor.cpp b/src/core/compositor/compositor.cpp index c45c02844..655126f20 100644 --- a/src/core/compositor/compositor.cpp +++ b/src/core/compositor/compositor.cpp @@ -172,12 +172,6 @@ Compositor::Handle<Compositor::Observer> Compositor::observer() return nullptr; } -float Compositor::devicePixelRatio() -{ - Q_UNREACHABLE(); - return 1; -} - QImage Compositor::image() { Q_UNREACHABLE(); @@ -195,18 +189,6 @@ int Compositor::textureId() return 0; } -QSize Compositor::textureSize() -{ - Q_UNREACHABLE(); - return {}; -} - -bool Compositor::hasAlphaChannel() -{ - Q_UNREACHABLE(); - return false; -} - // static void Compositor::unlockBindings() { diff --git a/src/core/compositor/compositor.h b/src/core/compositor/compositor.h index d10cf2ef6..316178891 100644 --- a/src/core/compositor/compositor.h +++ b/src/core/compositor/compositor.h @@ -147,7 +147,19 @@ public: // Ratio of pixels to DIPs. // // Don't use the devicePixelRatio of QImage, it's always 1. - virtual float devicePixelRatio(); + virtual float devicePixelRatio() = 0; + + // Size of frame in pixels. + virtual QSize size() = 0; + + // Whether frame needs an alpha channel. + // + // In software mode, the image format can be either + // QImage::Format_ARGB32_Premultiplied or + // QImage::Format_RGBA8888_Premultiplied + // + // In OpenGL mode, the texture format is either GL_RGBA or GL_RGB. + virtual bool hasAlphaChannel() = 0; // (Software) QImage of the frame. // @@ -160,10 +172,8 @@ public: // (OpenGL) Wait on texture fence in Qt's current OpenGL context. virtual void waitForTexture(); - // (OpenGL) Properties of the current frame. + // (OpenGL) Texture of the frame. virtual int textureId(); - virtual QSize textureSize(); - virtual bool hasAlphaChannel(); protected: Compositor(Type type) : m_type(type) { } diff --git a/src/core/compositor/display_gl_output_surface.cpp b/src/core/compositor/display_gl_output_surface.cpp index f736bba79..05653149e 100644 --- a/src/core/compositor/display_gl_output_surface.cpp +++ b/src/core/compositor/display_gl_output_surface.cpp @@ -323,7 +323,7 @@ int DisplayGLOutputSurface::textureId() return m_frontBuffer ? m_frontBuffer->serviceId : 0; } -QSize DisplayGLOutputSurface::textureSize() +QSize DisplayGLOutputSurface::size() { return m_frontBuffer ? toQt(m_frontBuffer->shape.sizeInPixels) : QSize(); } diff --git a/src/core/compositor/display_gl_output_surface.h b/src/core/compositor/display_gl_output_surface.h index 678d0cf5c..6b1b2e043 100644 --- a/src/core/compositor/display_gl_output_surface.h +++ b/src/core/compositor/display_gl_output_surface.h @@ -91,7 +91,7 @@ public: void swapFrame() override; void waitForTexture() override; int textureId() override; - QSize textureSize() override; + QSize size() override; bool hasAlphaChannel() override; float devicePixelRatio() override; diff --git a/src/core/compositor/display_software_output_surface.cpp b/src/core/compositor/display_software_output_surface.cpp index b1a357615..218bff94a 100644 --- a/src/core/compositor/display_software_output_surface.cpp +++ b/src/core/compositor/display_software_output_surface.cpp @@ -67,6 +67,8 @@ public: void swapFrame() override; QImage image() override; float devicePixelRatio() override; + QSize size() override; + bool hasAlphaChannel() override; private: mutable QMutex m_mutex; @@ -154,6 +156,16 @@ float DisplaySoftwareOutputSurface::Device::devicePixelRatio() return m_imageDevicePixelRatio; } +QSize DisplaySoftwareOutputSurface::Device::size() +{ + return m_image.size(); +} + +bool DisplaySoftwareOutputSurface::Device::hasAlphaChannel() +{ + return m_image.format() == QImage::Format_ARGB32_Premultiplied; +} + DisplaySoftwareOutputSurface::DisplaySoftwareOutputSurface() : SoftwareOutputSurface(std::make_unique<Device>()) {} diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp index 9ed660f2e..60340079f 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp @@ -357,17 +357,14 @@ QSGNode *RenderWidgetHostViewQtDelegateQuick::updatePaintNode(QSGNode *oldNode, comp->swapFrame(); + QSize texSize = comp->size(); + QSizeF texSizeInDips = QSizeF(texSize) / comp->devicePixelRatio(); + node->setRect(QRectF(QPointF(0, 0), texSizeInDips)); + if (comp->type() == Compositor::Type::Software) { QImage image = comp->image(); - float pixPerDip = comp->devicePixelRatio(); - QSizeF sizeInDips = QSizeF(image.size()) / pixPerDip; - node->setRect(QRectF(QPointF(0, 0), sizeInDips)); node->setTexture(win->createTextureFromImage(image)); } else if (comp->type() == Compositor::Type::OpenGL) { - QSize texSize = comp->textureSize(); - float pixPerDip = comp->devicePixelRatio(); - QSizeF sizeInDips = QSizeF(texSize) / pixPerDip; - node->setRect(QRectF(QPointF(0, 0), sizeInDips)); QQuickWindow::CreateTextureOptions texOpts; if (comp->hasAlphaChannel()) texOpts.setFlag(QQuickWindow::TextureHasAlphaChannel); diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp index 853553c47..f9a7b036e 100644 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp @@ -119,17 +119,14 @@ protected: comp->swapFrame(); + QSize texSize = comp->size(); + QSizeF texSizeInDips = QSizeF(texSize) / comp->devicePixelRatio(); + node->setRect(QRectF(QPointF(0, 0), texSizeInDips)); + if (comp->type() == Compositor::Type::Software) { QImage image = comp->image(); - float pixPerDip = comp->devicePixelRatio(); - QSizeF sizeInDips = QSizeF(image.size()) / pixPerDip; - node->setRect(QRectF(QPointF(0, 0), sizeInDips)); node->setTexture(win->createTextureFromImage(image)); } else if (comp->type() == Compositor::Type::OpenGL) { - QSize texSize = comp->textureSize(); - float pixPerDip = comp->devicePixelRatio(); - QSizeF sizeInDips = QSizeF(texSize) / pixPerDip; - node->setRect(QRectF(QPointF(0, 0), sizeInDips)); QQuickWindow::CreateTextureOptions texOpts; if (comp->hasAlphaChannel()) texOpts.setFlag(QQuickWindow::TextureHasAlphaChannel); |