Skip to content

Commit

Permalink
Compositor 0.2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AaronDewes committed Aug 22, 2020
1 parent 31aad53 commit 662bb9a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion buildroot/package/compositor/compositor.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions qwindow-compositor/qwindow-compositor.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/">
<file alias="background.jpg">./background.jpg</file>
<qresource>
<file alias="background.jpg">background.jpg</file>
</qresource>
</RCC>
25 changes: 13 additions & 12 deletions qwindow-compositor/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include <QOpenGLTexture>
#include <QOpenGLFunctions>
#include <QMatrix4x4>
#include <QPainter>

#include "compositor.h"
#include <QtWaylandCompositor/qwaylandseat.h>
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion qwindow-compositor/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<View> m_mouseView;
Expand Down

0 comments on commit 662bb9a

Please sign in to comment.