summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJungi Byun <jungi.byun@lge.com>2021-01-27 08:24:23 +0900
committerElvis Lee <kwangwoong.lee@lge.com>2021-03-25 15:30:21 +0900
commitcf98abbc6ae9ba9373803ffe193f839324e0c80b (patch)
tree0c51b19bfeccd13a9e8c62e3c2986ac5e5c83b8e
parente08b25efe4a7bec1004696bd23d9f8959158bd60 (diff)
downloadqtwayland-cf98abbc6ae9ba9373803ffe193f839324e0c80b.tar.gz
Replace scale with devicePixelRatio for non-integer scaling
The 'scale' event from wayland cannot support non-integer scaling which was originally supported in Qt. As default, devicePixelRatio follows the 'scale' so that the high DPI still works as the mechanism in Wayland. But if non-integer scaling factor such as 150% is needed, it can be supported to override the devicePixelRatio. Change-Id: I63a04db27bd521264b6d0904e1ddd05a572dc970 Reviewed-by: Elvis Lee <kwangwoong.lee@lge.com> Reviewed-by: Jungi Byun <jungi.byun@lge.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
-rw-r--r--src/client/qwaylandabstractdecoration.cpp2
-rw-r--r--src/client/qwaylandshmbackingstore.cpp6
-rw-r--r--src/client/qwaylandshmbackingstore_p.h2
-rw-r--r--src/client/qwaylandwindow.cpp16
-rw-r--r--src/client/qwaylandwindow_p.h2
-rw-r--r--src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp2
6 files changed, 15 insertions, 15 deletions
diff --git a/src/client/qwaylandabstractdecoration.cpp b/src/client/qwaylandabstractdecoration.cpp
index b6ee43c9..be0a31df 100644
--- a/src/client/qwaylandabstractdecoration.cpp
+++ b/src/client/qwaylandabstractdecoration.cpp
@@ -122,7 +122,7 @@ const QImage &QWaylandAbstractDecoration::contentImage()
if (d->m_isDirty) {
// Update the decoration backingstore
- const int bufferScale = waylandWindow()->scale();
+ const qreal bufferScale = waylandWindow()->scale();
const QSize imageSize = waylandWindow()->surfaceSize() * bufferScale;
d->m_decorationContentImage = QImage(imageSize, QImage::Format_ARGB32_Premultiplied);
// Only scale by buffer scale, not QT_SCALE_FACTOR etc.
diff --git a/src/client/qwaylandshmbackingstore.cpp b/src/client/qwaylandshmbackingstore.cpp
index dc7ff670..7e1e9bb9 100644
--- a/src/client/qwaylandshmbackingstore.cpp
+++ b/src/client/qwaylandshmbackingstore.cpp
@@ -68,7 +68,7 @@ QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
QWaylandShmBuffer::QWaylandShmBuffer(QWaylandDisplay *display,
- const QSize &size, QImage::Format format, int scale)
+ const QSize &size, QImage::Format format, qreal scale)
{
int stride = size.width() * 4;
int alloc = stride * size.height();
@@ -108,7 +108,7 @@ QWaylandShmBuffer::QWaylandShmBuffer(QWaylandDisplay *display,
QWaylandShm* shm = display->shm();
wl_shm_format wl_format = shm->formatFrom(format);
mImage = QImage(data, size.width(), size.height(), stride, format);
- mImage.setDevicePixelRatio(qreal(scale));
+ mImage.setDevicePixelRatio(scale);
mShmPool = wl_shm_create_pool(shm->object(), fd, alloc);
init(wl_shm_pool_create_buffer(mShmPool,0, size.width(), size.height(),
@@ -271,7 +271,7 @@ QWaylandShmBuffer *QWaylandShmBackingStore::getBuffer(const QSize &size)
void QWaylandShmBackingStore::resize(const QSize &size)
{
QMargins margins = windowDecorationMargins();
- int scale = waylandWindow()->scale();
+ qreal scale = waylandWindow()->scale();
QSize sizeWithMargins = (size + QSize(margins.left()+margins.right(),margins.top()+margins.bottom())) * scale;
// We look for a free buffer to draw into. If the buffer is not the last buffer we used,
diff --git a/src/client/qwaylandshmbackingstore_p.h b/src/client/qwaylandshmbackingstore_p.h
index e01632da..f3fae438 100644
--- a/src/client/qwaylandshmbackingstore_p.h
+++ b/src/client/qwaylandshmbackingstore_p.h
@@ -71,7 +71,7 @@ class QWaylandWindow;
class Q_WAYLAND_CLIENT_EXPORT QWaylandShmBuffer : public QWaylandBuffer {
public:
QWaylandShmBuffer(QWaylandDisplay *display,
- const QSize &size, QImage::Format format, int scale = 1);
+ const QSize &size, QImage::Format format, qreal scale = 1);
~QWaylandShmBuffer() override;
QSize size() const override { return mImage.size(); }
int scale() const override { return int(mImage.devicePixelRatio()); }
diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp
index 330c84a4..f5dbd02a 100644
--- a/src/client/qwaylandwindow.cpp
+++ b/src/client/qwaylandwindow.cpp
@@ -189,7 +189,7 @@ void QWaylandWindow::initWindow()
// typically be integer 1 (normal-dpi) or 2 (high-dpi). Call set_buffer_scale()
// to inform the compositor that high-resolution buffers will be provided.
if (mSurface->version() >= 3)
- mSurface->set_buffer_scale(scale());
+ mSurface->set_buffer_scale(mScale);
setWindowFlags(window()->flags());
QRect geometry = windowGeometry();
@@ -571,9 +571,9 @@ void QWaylandWindow::attachOffset(QWaylandBuffer *buffer)
void QWaylandWindow::damage(const QRect &rect)
{
- const int s = scale();
+ const qreal s = scale();
if (mSurface->version() >= 4)
- mSurface->damage_buffer(s * rect.x(), s * rect.y(), s * rect.width(), s * rect.height());
+ mSurface->damage_buffer(qFloor(s * rect.x()), qFloor(s * rect.y()), qCeil(s * rect.width()), qCeil(s * rect.height()));
else
mSurface->damage(rect.x(), rect.y(), rect.width(), rect.height());
}
@@ -610,9 +610,9 @@ void QWaylandWindow::commit(QWaylandBuffer *buffer, const QRegion &damage)
attachOffset(buffer);
if (mSurface->version() >= 4) {
- const int s = scale();
+ const qreal s = scale();
for (const QRect &rect: damage)
- mSurface->damage_buffer(s * rect.x(), s * rect.y(), s * rect.width(), s * rect.height());
+ mSurface->damage_buffer(qFloor(s * rect.x()), qFloor(s * rect.y()), qCeil(s * rect.width()), qCeil(s * rect.height()));
} else {
for (const QRect &rect: damage)
mSurface->damage(rect.x(), rect.y(), rect.width(), rect.height());
@@ -1071,14 +1071,14 @@ bool QWaylandWindow::isActive() const
return mDisplay->isWindowActivated(this);
}
-int QWaylandWindow::scale() const
+qreal QWaylandWindow::scale() const
{
- return mScale;
+ return devicePixelRatio();
}
qreal QWaylandWindow::devicePixelRatio() const
{
- return mScale;
+ return qreal(mScale);
}
bool QWaylandWindow::setMouseGrabEnabled(bool grab)
diff --git a/src/client/qwaylandwindow_p.h b/src/client/qwaylandwindow_p.h
index c323618b..b82bbe99 100644
--- a/src/client/qwaylandwindow_p.h
+++ b/src/client/qwaylandwindow_p.h
@@ -154,7 +154,7 @@ public:
void setMask(const QRegion &region) override;
- int scale() const;
+ qreal scale() const;
qreal devicePixelRatio() const override;
void requestActivateWindow() override;
diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp
index 68f95d30..9e6c1188 100644
--- a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp
+++ b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp
@@ -196,7 +196,7 @@ public:
QOpenGLTextureCache *cache = QOpenGLTextureCache::cacheForContext(m_context->context());
QSize surfaceSize = window->surfaceSize();
- int scale = window->scale() ;
+ qreal scale = window->scale() ;
glViewport(0, 0, surfaceSize.width() * scale, surfaceSize.height() * scale);
//Draw Decoration