Skip to content

Commit 662bb9a

Browse files
committed
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.
1 parent 31aad53 commit 662bb9a

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

buildroot/package/compositor/compositor.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#############################################################
66

77

8-
COMPOSITOR_VERSION = 0.1
8+
COMPOSITOR_VERSION = 0.2
99
COMPOSITOR_SITE = $(TOPDIR)/../qwindow-compositor
1010
COMPOSITOR_SITE_METHOD = local
1111
COMPOSITOR_LICENSE = BSD-3c
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<RCC>
2-
<qresource prefix="/">
3-
<file alias="background.jpg">./background.jpg</file>
2+
<qresource>
3+
<file alias="background.jpg">background.jpg</file>
44
</qresource>
55
</RCC>

qwindow-compositor/window.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include <QOpenGLTexture>
5656
#include <QOpenGLFunctions>
5757
#include <QMatrix4x4>
58+
#include <QPainter>
5859

5960
#include "compositor.h"
6061
#include <QtWaylandCompositor/qwaylandseat.h>
@@ -72,25 +73,25 @@ void Window::setCompositor(Compositor *comp) {
7273

7374
void Window::initializeGL()
7475
{
75-
QImage backgroundImage = QImage(QLatin1String(":/background.jpg")).rgbSwapped();
76-
backgroundImage.invertPixels();
77-
m_backgroundTexture = new QOpenGLTexture(backgroundImage, QOpenGLTexture::DontGenerateMipMaps);
78-
m_backgroundTexture->setMinificationFilter(QOpenGLTexture::Nearest);
79-
m_backgroundImageSize = backgroundImage.size();
8076
m_textureBlitter.create();
8177
m_compositor->create(); // the compositor's hardware integration may depend on GL
8278
}
8379

8480
void Window::drawBackground()
8581
{
86-
for (int y = 0; y < height(); y += m_backgroundImageSize.height()) {
87-
for (int x = 0; x < width(); x += m_backgroundImageSize.width()) {
88-
QMatrix4x4 targetTransform = QOpenGLTextureBlitter::targetTransform(QRect(QPoint(x,y), m_backgroundImageSize), QRect(QPoint(0,0), size()));
89-
m_textureBlitter.blit(m_backgroundTexture->textureId(),
90-
targetTransform,
91-
QOpenGLTextureBlitter::OriginTopLeft);
92-
}
82+
QColor backgroundColor = QColor(0xde, 0xde, 0xde);
83+
QImage backgroundColorImage = QImage(this->geometry().size(), QImage::Format_RGB32);
84+
backgroundColorImage.fill(backgroundColor);
85+
QImage backgroundImage = m_backgroundImage;
86+
if(this->geometry().width() < backgroundImage.width() || this->geometry().height() < backgroundImage.height()) {
87+
backgroundImage = m_backgroundImage.scaled(this->geometry().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
9388
}
89+
QPainter painter(this);
90+
int deltaX = this->geometry().width() - backgroundImage.width();
91+
int deltaY = this->geometry().height() - backgroundImage.height();
92+
painter.drawImage(this->geometry(), backgroundColorImage);
93+
painter.translate(deltaX / 2, deltaY / 2);
94+
painter.drawImage(backgroundImage.rect(), backgroundImage);
9495
}
9596

9697
QPointF Window::getAnchorPosition(const QPointF &position, int resizeEdge, const QSize &windowSize)

qwindow-compositor/window.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private slots:
9595
static QPointF getAnchorPosition(const QPointF &position, int resizeEdge, const QSize &windowSize);
9696

9797
QOpenGLTextureBlitter m_textureBlitter;
98-
QSize m_backgroundImageSize;
98+
QImage m_backgroundImage = QImage(QLatin1String(":/background.jpg"));
9999
QOpenGLTexture *m_backgroundTexture = nullptr;
100100
Compositor *m_compositor = nullptr;
101101
QPointer<View> m_mouseView;

0 commit comments

Comments
 (0)