diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/qwaylandbuffer_p.h | 1 | ||||
-rw-r--r-- | src/client/qwaylandscreen.cpp | 20 | ||||
-rw-r--r-- | src/client/qwaylandscreen_p.h | 4 | ||||
-rw-r--r-- | src/client/qwaylandshmbackingstore.cpp | 18 | ||||
-rw-r--r-- | src/client/qwaylandshmbackingstore_p.h | 3 | ||||
-rw-r--r-- | src/client/qwaylandwindow.cpp | 17 | ||||
-rw-r--r-- | src/client/qwaylandwindow_p.h | 3 |
7 files changed, 57 insertions, 9 deletions
diff --git a/src/client/qwaylandbuffer_p.h b/src/client/qwaylandbuffer_p.h index 2bb9990f..0c9903f5 100644 --- a/src/client/qwaylandbuffer_p.h +++ b/src/client/qwaylandbuffer_p.h @@ -58,6 +58,7 @@ public: virtual ~QWaylandBuffer() { } wl_buffer *buffer() {return mBuffer;} virtual QSize size() const = 0; + virtual int scale() const { return 1; } protected: struct wl_buffer *mBuffer; diff --git a/src/client/qwaylandscreen.cpp b/src/client/qwaylandscreen.cpp index 6e48c442..675c8404 100644 --- a/src/client/qwaylandscreen.cpp +++ b/src/client/qwaylandscreen.cpp @@ -59,6 +59,7 @@ QWaylandScreen::QWaylandScreen(QWaylandDisplay *waylandDisplay, int version, uin , m_outputId(id) , mWaylandDisplay(waylandDisplay) , mExtendedOutput(0) + , mScale(1) , mDepth(32) , mRefreshRate(60000) , mTransform(-1) @@ -83,7 +84,9 @@ QWaylandDisplay * QWaylandScreen::display() const QRect QWaylandScreen::geometry() const { - return mGeometry; + // Scale geometry for QScreen. This makes window and screen + // geometry be in the same coordinate system. + return QRect(mGeometry.topLeft(), mGeometry.size() / mScale); } int QWaylandScreen::depth() const @@ -127,6 +130,16 @@ Qt::ScreenOrientation QWaylandScreen::orientation() const return m_orientation; } +int QWaylandScreen::scale() const +{ + return mScale; +} + +qreal QWaylandScreen::devicePixelRatio() const +{ + return qreal(mScale); +} + qreal QWaylandScreen::refreshRate() const { return mRefreshRate / 1000.f; @@ -188,6 +201,11 @@ void QWaylandScreen::output_geometry(int32_t x, int32_t y, mGeometry.moveTopLeft(QPoint(x, y)); } +void QWaylandScreen::output_scale(int32_t factor) +{ + mScale = factor; +} + void QWaylandScreen::output_done() { // the done event is sent after all the geometry and the mode events are sent, diff --git a/src/client/qwaylandscreen_p.h b/src/client/qwaylandscreen_p.h index d3173e0c..d0c5d710 100644 --- a/src/client/qwaylandscreen_p.h +++ b/src/client/qwaylandscreen_p.h @@ -72,6 +72,8 @@ public: void setOrientationUpdateMask(Qt::ScreenOrientations mask); Qt::ScreenOrientation orientation() const; + int scale() const; + qreal devicePixelRatio() const Q_DECL_OVERRIDE; qreal refreshRate() const; QString name() const { return mOutputName; } @@ -95,12 +97,14 @@ private: const QString &make, const QString &model, int32_t transform) Q_DECL_OVERRIDE; + void output_scale(int32_t factor) Q_DECL_OVERRIDE; void output_done() Q_DECL_OVERRIDE; int m_outputId; QWaylandDisplay *mWaylandDisplay; QWaylandExtendedOutput *mExtendedOutput; QRect mGeometry; + int mScale; int mDepth; int mRefreshRate; int mTransform; diff --git a/src/client/qwaylandshmbackingstore.cpp b/src/client/qwaylandshmbackingstore.cpp index d407335d..9ec80013 100644 --- a/src/client/qwaylandshmbackingstore.cpp +++ b/src/client/qwaylandshmbackingstore.cpp @@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE QWaylandShmBuffer::QWaylandShmBuffer(QWaylandDisplay *display, - const QSize &size, QImage::Format format) + const QSize &size, QImage::Format format, int scale) : mMarginsImage(0) { int stride = size.width() * 4; @@ -87,6 +87,8 @@ QWaylandShmBuffer::QWaylandShmBuffer(QWaylandDisplay *display, } mImage = QImage(data, size.width(), size.height(), stride, format); + mImage.setDevicePixelRatio(qreal(scale)); + mShmPool = wl_shm_create_pool(display->shm(), fd, alloc); mBuffer = wl_shm_pool_create_buffer(mShmPool,0, size.width(), size.height(), stride, WL_SHM_FORMAT_ARGB8888); @@ -101,8 +103,10 @@ QWaylandShmBuffer::~QWaylandShmBuffer(void) wl_shm_pool_destroy(mShmPool); } -QImage *QWaylandShmBuffer::imageInsideMargins(const QMargins &margins) +QImage *QWaylandShmBuffer::imageInsideMargins(const QMargins &marginsIn) { + QMargins margins = marginsIn * int(mImage.devicePixelRatio()); + if (!margins.isNull() && margins != mMargins) { if (mMarginsImage) { delete mMarginsImage; @@ -112,6 +116,7 @@ QImage *QWaylandShmBuffer::imageInsideMargins(const QMargins &margins) int b_s_width = mImage.size().width() - margins.left() - margins.right(); int b_s_height = mImage.size().height() - margins.top() - margins.bottom(); mMarginsImage = new QImage(b_s_data, b_s_width,b_s_height,mImage.bytesPerLine(),mImage.format()); + mMarginsImage->setDevicePixelRatio(mImage.devicePixelRatio()); } if (margins.isNull()) { delete mMarginsImage; @@ -228,7 +233,7 @@ void QWaylandShmBackingStore::flush(QWindow *window, const QRegion ®ion, cons if (damageAll) { //need to damage it all, otherwise the attach offset may screw up - waylandWindow()->damage(QRect(QPoint(0,0),mFrontBuffer->size())); + waylandWindow()->damage(QRect(QPoint(0,0), window->size())); } else { QVector<QRect> rects = region.rects(); for (int i = 0; i < rects.size(); i++) { @@ -249,7 +254,8 @@ void QWaylandShmBackingStore::resize(const QSize &size, const QRegion &) void QWaylandShmBackingStore::resize(const QSize &size) { QMargins margins = windowDecorationMargins(); - QSize sizeWithMargins = size + QSize(margins.left()+margins.right(),margins.top()+margins.bottom()); + int scale = waylandWindow()->scale(); + QSize sizeWithMargins = (size + QSize(margins.left()+margins.right(),margins.top()+margins.bottom())) * scale; QImage::Format format = QPlatformScreen::platformScreenForWindow(window())->format(); @@ -260,7 +266,7 @@ void QWaylandShmBackingStore::resize(const QSize &size) delete mBackBuffer; //we delete the attached buffer when we flush } - mBackBuffer = new QWaylandShmBuffer(mDisplay, sizeWithMargins, format); + mBackBuffer = new QWaylandShmBuffer(mDisplay, sizeWithMargins, format, scale); if (windowDecoration() && window()->isVisible()) windowDecoration()->update(); @@ -354,7 +360,7 @@ void QWaylandShmBackingStore::done(void *data, wl_callback *callback, uint32_t t delete window->attached(); } window->attachOffset(self->mFrontBuffer); - window->damage(QRect(QPoint(0,0),self->mFrontBuffer->size())); + window->damage(QRect(QPoint(0,0),window->geometry().size())); window->commit(); } } diff --git a/src/client/qwaylandshmbackingstore_p.h b/src/client/qwaylandshmbackingstore_p.h index 1212e52f..b1e326c3 100644 --- a/src/client/qwaylandshmbackingstore_p.h +++ b/src/client/qwaylandshmbackingstore_p.h @@ -57,9 +57,10 @@ class QWaylandWindow; class Q_WAYLAND_CLIENT_EXPORT QWaylandShmBuffer : public QWaylandBuffer { public: QWaylandShmBuffer(QWaylandDisplay *display, - const QSize &size, QImage::Format format); + const QSize &size, QImage::Format format, int scale = 1); ~QWaylandShmBuffer(); QSize size() const { return mImage.size(); } + int scale() const Q_DECL_OVERRIDE { return int(mImage.devicePixelRatio()); } QImage *image() { return &mImage; } QImage *imageInsideMargins(const QMargins &margins); diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp index 9f7bdda1..fd06972f 100644 --- a/src/client/qwaylandwindow.cpp +++ b/src/client/qwaylandwindow.cpp @@ -126,6 +126,12 @@ QWaylandWindow::QWaylandWindow(QWindow *window) mShellSurface->setTopLevel(); } + // Enable high-dpi rendering. Scale() returns the screen scale factor and will + // 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 (mDisplay->compositorVersion() >= 3) + set_buffer_scale(scale()); + setOrientationMask(window->screen()->orientationUpdateMask()); setWindowFlags(window->flags()); setGeometry_helper(window->geometry()); @@ -369,7 +375,6 @@ void QWaylandWindow::requestResize() void QWaylandWindow::attach(QWaylandBuffer *buffer, int x, int y) { mBuffer = buffer; - if (mBuffer) attach(mBuffer->buffer(), x, y); else @@ -707,6 +712,16 @@ bool QWaylandWindow::isExposed() const return QPlatformWindow::isExposed(); } +int QWaylandWindow::scale() const +{ + return screen()->scale(); +} + +qreal QWaylandWindow::devicePixelRatio() const +{ + return screen()->devicePixelRatio(); +} + bool QWaylandWindow::setMouseGrabEnabled(bool grab) { if (window()->type() != Qt::Popup) { diff --git a/src/client/qwaylandwindow_p.h b/src/client/qwaylandwindow_p.h index 0c55cd88..0d982d43 100644 --- a/src/client/qwaylandwindow_p.h +++ b/src/client/qwaylandwindow_p.h @@ -142,6 +142,9 @@ public: void setMask(const QRegion ®ion) Q_DECL_OVERRIDE; + int scale() const; + qreal devicePixelRatio() const Q_DECL_OVERRIDE; + void requestActivateWindow() Q_DECL_OVERRIDE; bool isExposed() const Q_DECL_OVERRIDE; void unfocus(); |