summaryrefslogtreecommitdiffstats
path: root/src/gui/painting
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/painting')
-rw-r--r--src/gui/painting/qbackingstore.cpp44
-rw-r--r--src/gui/painting/qpaintdevice.cpp9
-rw-r--r--src/gui/painting/qpaintdevice.h8
-rw-r--r--src/gui/painting/qpainter.cpp2
-rw-r--r--src/gui/painting/qpainter_p.h2
5 files changed, 55 insertions, 10 deletions
diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp
index 19074e4c47..9c51a86484 100644
--- a/src/gui/painting/qbackingstore.cpp
+++ b/src/gui/painting/qbackingstore.cpp
@@ -38,22 +38,26 @@
#include <qpa/qplatformintegration.h>
#include <qscreen.h>
#include <qdebug.h>
+#include <qscopedpointer.h>
#include <private/qguiapplication_p.h>
#include <private/qwindow_p.h>
+#include <private/qhighdpiscaling_p.h>
+
QT_BEGIN_NAMESPACE
class QBackingStorePrivate
{
public:
QBackingStorePrivate(QWindow *w)
- : window(w)
+ : window(w), highDpiBackingstore(0)
{
}
QWindow *window;
QPlatformBackingStore *platformBackingStore;
+ QScopedPointer<QImage> highDpiBackingstore;
QRegion staticContents;
QSize size;
};
@@ -102,7 +106,7 @@ void QBackingStore::flush(const QRegion &region, QWindow *win, const QPoint &off
}
#endif
- d_ptr->platformBackingStore->flush(win, region, offset);
+ d_ptr->platformBackingStore->flush(win, qHighDpiToDevicePixels(region, d_ptr->window), offset);
}
/*!
@@ -112,7 +116,35 @@ void QBackingStore::flush(const QRegion &region, QWindow *win, const QPoint &off
*/
QPaintDevice *QBackingStore::paintDevice()
{
- return d_ptr->platformBackingStore->paintDevice();
+ QPaintDevice *device = d_ptr->platformBackingStore->paintDevice();
+
+ // When QtGui is applying a high-dpi scale factor the backing store
+ // creates a "large" backing store image. This image needs to be
+ // painted on as a high-dpi image, which is done by setting
+ // devicePixelRatio. Do this on a separate image instance that shares
+ // the image data to avoid having the new devicePxielRatio be propagated
+ // back to the platform plugin.
+ if (QHighDpiScaling::isActive() && device->devType() == QInternal::Image) {
+ QImage *source = reinterpret_cast<QImage *>(device);
+ const bool needsNewImage = d_ptr->highDpiBackingstore.isNull()
+ || source->data_ptr() != d_ptr->highDpiBackingstore->data_ptr()
+ || source->size() != d_ptr->highDpiBackingstore->size()
+ || source->devicePixelRatio() != d_ptr->highDpiBackingstore->devicePixelRatio();
+ if (needsNewImage) {
+ qCDebug(lcScaling) << "QBackingStore::paintDevice new backingstore:";
+ qCDebug(lcScaling) << " source size" << source->size() << "dpr" << source->devicePixelRatio();
+ d_ptr->highDpiBackingstore.reset(
+ new QImage(source->bits(), source->width(), source->height(), source->format()));
+ qreal targetDevicePixelRatio = d_ptr->window->devicePixelRatio();
+ d_ptr->highDpiBackingstore->setDevicePixelRatio(targetDevicePixelRatio);
+ qCDebug(lcScaling) <<" destinaion size" << d_ptr->highDpiBackingstore->size()
+ << "dpr" << targetDevicePixelRatio;
+ }
+
+ return d_ptr->highDpiBackingstore.data();
+ }
+
+ return device;
}
/*!
@@ -150,7 +182,7 @@ QWindow* QBackingStore::window() const
void QBackingStore::beginPaint(const QRegion &region)
{
- d_ptr->platformBackingStore->beginPaint(region);
+ d_ptr->platformBackingStore->beginPaint(qHighDpiToDevicePixels(region, d_ptr->window));
}
/*!
@@ -171,7 +203,7 @@ void QBackingStore::endPaint()
void QBackingStore::resize(const QSize &size)
{
d_ptr->size = size;
- d_ptr->platformBackingStore->resize(size, d_ptr->staticContents);
+ d_ptr->platformBackingStore->resize(qHighDpiToDevicePixels(size, d_ptr->window), d_ptr->staticContents);
}
/*!
@@ -194,7 +226,7 @@ bool QBackingStore::scroll(const QRegion &area, int dx, int dy)
Q_UNUSED(dx);
Q_UNUSED(dy);
- return d_ptr->platformBackingStore->scroll(area, dx, dy);
+ return d_ptr->platformBackingStore->scroll(qHighDpiToDevicePixels(area, d_ptr->window), qHighDpiToDevicePixels(dx, d_ptr->window), qHighDpiToDevicePixels(dy, d_ptr->window));
}
void QBackingStore::setStaticContents(const QRegion &region)
diff --git a/src/gui/painting/qpaintdevice.cpp b/src/gui/painting/qpaintdevice.cpp
index 36e0bbe223..4ee3d91ea3 100644
--- a/src/gui/painting/qpaintdevice.cpp
+++ b/src/gui/painting/qpaintdevice.cpp
@@ -41,6 +41,8 @@ QPaintDevice::QPaintDevice()
painters = 0;
}
+qreal QPaintDevice::devicePixelRatioFScale = 10000000.0;
+
QPaintDevice::~QPaintDevice()
{
if (paintingActive())
@@ -79,7 +81,13 @@ Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, QPaintDevice
int QPaintDevice::metric(PaintDeviceMetric m) const
{
+ // Fallback: A subclass has not implemented PdmDevicePixelRatioScaled but might
+ // have implemented PdmDevicePixelRatio.
+ if (m == PdmDevicePixelRatioScaled)
+ return this->metric(PdmDevicePixelRatio) * devicePixelRatioFScale;
+
qWarning("QPaintDevice::metrics: Device has no metric information");
+
if (m == PdmDpiX) {
return 72;
} else if (m == PdmDpiY) {
@@ -95,4 +103,5 @@ int QPaintDevice::metric(PaintDeviceMetric m) const
}
}
+
QT_END_NAMESPACE
diff --git a/src/gui/painting/qpaintdevice.h b/src/gui/painting/qpaintdevice.h
index 7c756c66de..819116c585 100644
--- a/src/gui/painting/qpaintdevice.h
+++ b/src/gui/painting/qpaintdevice.h
@@ -58,7 +58,8 @@ public:
PdmDpiY,
PdmPhysicalDpiX,
PdmPhysicalDpiY,
- PdmDevicePixelRatio
+ PdmDevicePixelRatio,
+ PdmDevicePixelRatioScaled
};
virtual ~QPaintDevice();
@@ -76,9 +77,13 @@ public:
int physicalDpiX() const { return metric(PdmPhysicalDpiX); }
int physicalDpiY() const { return metric(PdmPhysicalDpiY); }
int devicePixelRatio() const { return metric(PdmDevicePixelRatio); }
+ qreal devicePixelRatioF() const { return metric(PdmDevicePixelRatioScaled) / devicePixelRatioFScale; }
int colorCount() const { return metric(PdmNumColors); }
int depth() const { return metric(PdmDepth); }
+ // ### Classes that are not QPaintDevice subclasses are implementing metric()
+ // ### There needs to be some kind of (semi)-public API.
+ static qreal devicePixelRatioFScale;
protected:
QPaintDevice();
virtual int metric(PaintDeviceMetric metric) const;
@@ -87,7 +92,6 @@ protected:
virtual QPainter *sharedPainter() const;
ushort painters; // refcount
-
private:
Q_DISABLE_COPY(QPaintDevice)
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index 973c9da96c..70862ea583 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -219,7 +219,7 @@ QTransform QPainterPrivate::viewTransform() const
return QTransform();
}
-int QPainterPrivate::effectiveDevicePixelRatio() const
+qreal QPainterPrivate::effectiveDevicePixelRatio() const
{
// Special cases for devices that does not support PdmDevicePixelRatio go here:
if (device->devType() == QInternal::Printer)
diff --git a/src/gui/painting/qpainter_p.h b/src/gui/painting/qpainter_p.h
index 7c32dc1694..fdad8e2460 100644
--- a/src/gui/painting/qpainter_p.h
+++ b/src/gui/painting/qpainter_p.h
@@ -241,7 +241,7 @@ public:
}
QTransform viewTransform() const;
- int effectiveDevicePixelRatio() const;
+ qreal effectiveDevicePixelRatio() const;
QTransform hidpiScaleTransform() const;
static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev);
void detachPainterPrivate(QPainter *q);