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>
This commit is contained in:
parent
f0435ab1a4
commit
597278685a
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -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()); }
|
||||
|
@ -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)
|
||||
|
@ -154,7 +154,7 @@ public:
|
||||
|
||||
void setMask(const QRegion ®ion) override;
|
||||
|
||||
int scale() const;
|
||||
qreal scale() const;
|
||||
qreal devicePixelRatio() const override;
|
||||
|
||||
void requestActivateWindow() override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user