From 662bb9ad89ad4df2cc8d36cffd12ccfb4be3aab5 Mon Sep 17 00:00:00 2001 From: Aaron Dewes Date: Sat, 22 Aug 2020 14:38:56 +0200 Subject: [PATCH] Compositor 0.2 I'm developing a custom wayland compositor for the QT5 port. This is Version 0.2, which fixes the scalling of the background if the background is smaller or bigger than the screen. --- buildroot/package/compositor/compositor.mk | 2 +- qwindow-compositor/qwindow-compositor.qrc | 4 ++-- qwindow-compositor/window.cpp | 25 +++++++++++----------- qwindow-compositor/window.h | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/buildroot/package/compositor/compositor.mk b/buildroot/package/compositor/compositor.mk index 0b549ad8c..2621fb381 100644 --- a/buildroot/package/compositor/compositor.mk +++ b/buildroot/package/compositor/compositor.mk @@ -5,7 +5,7 @@ ############################################################# -COMPOSITOR_VERSION = 0.1 +COMPOSITOR_VERSION = 0.2 COMPOSITOR_SITE = $(TOPDIR)/../qwindow-compositor COMPOSITOR_SITE_METHOD = local COMPOSITOR_LICENSE = BSD-3c diff --git a/qwindow-compositor/qwindow-compositor.qrc b/qwindow-compositor/qwindow-compositor.qrc index 509859d70..a147b6639 100644 --- a/qwindow-compositor/qwindow-compositor.qrc +++ b/qwindow-compositor/qwindow-compositor.qrc @@ -1,5 +1,5 @@ - - ./background.jpg + + background.jpg diff --git a/qwindow-compositor/window.cpp b/qwindow-compositor/window.cpp index c439d20a8..eeb8bca70 100644 --- a/qwindow-compositor/window.cpp +++ b/qwindow-compositor/window.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #include "compositor.h" #include @@ -72,25 +73,25 @@ void Window::setCompositor(Compositor *comp) { void Window::initializeGL() { - QImage backgroundImage = QImage(QLatin1String(":/background.jpg")).rgbSwapped(); - backgroundImage.invertPixels(); - m_backgroundTexture = new QOpenGLTexture(backgroundImage, QOpenGLTexture::DontGenerateMipMaps); - m_backgroundTexture->setMinificationFilter(QOpenGLTexture::Nearest); - m_backgroundImageSize = backgroundImage.size(); m_textureBlitter.create(); m_compositor->create(); // the compositor's hardware integration may depend on GL } void Window::drawBackground() { - for (int y = 0; y < height(); y += m_backgroundImageSize.height()) { - for (int x = 0; x < width(); x += m_backgroundImageSize.width()) { - QMatrix4x4 targetTransform = QOpenGLTextureBlitter::targetTransform(QRect(QPoint(x,y), m_backgroundImageSize), QRect(QPoint(0,0), size())); - m_textureBlitter.blit(m_backgroundTexture->textureId(), - targetTransform, - QOpenGLTextureBlitter::OriginTopLeft); - } + QColor backgroundColor = QColor(0xde, 0xde, 0xde); + QImage backgroundColorImage = QImage(this->geometry().size(), QImage::Format_RGB32); + backgroundColorImage.fill(backgroundColor); + QImage backgroundImage = m_backgroundImage; + if(this->geometry().width() < backgroundImage.width() || this->geometry().height() < backgroundImage.height()) { + backgroundImage = m_backgroundImage.scaled(this->geometry().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); } + QPainter painter(this); + int deltaX = this->geometry().width() - backgroundImage.width(); + int deltaY = this->geometry().height() - backgroundImage.height(); + painter.drawImage(this->geometry(), backgroundColorImage); + painter.translate(deltaX / 2, deltaY / 2); + painter.drawImage(backgroundImage.rect(), backgroundImage); } QPointF Window::getAnchorPosition(const QPointF &position, int resizeEdge, const QSize &windowSize) diff --git a/qwindow-compositor/window.h b/qwindow-compositor/window.h index c16e726bf..d7301bcc6 100644 --- a/qwindow-compositor/window.h +++ b/qwindow-compositor/window.h @@ -95,7 +95,7 @@ private slots: static QPointF getAnchorPosition(const QPointF &position, int resizeEdge, const QSize &windowSize); QOpenGLTextureBlitter m_textureBlitter; - QSize m_backgroundImageSize; + QImage m_backgroundImage = QImage(QLatin1String(":/background.jpg")); QOpenGLTexture *m_backgroundTexture = nullptr; Compositor *m_compositor = nullptr; QPointer m_mouseView;