aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2021-08-20 15:30:22 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-08-25 20:28:51 +0000
commit0d2ce93a9014c69f45785bff1bba8e4dc5917163 (patch)
tree8abb0a005f70c3c1c8d1d834dcf96cc6f1c761ef
parentc36a437331198035e5a50a59d6b8df860761a37f (diff)
Canvas: Add a means to override the DPR used via an environment variable
Overriding the DPR enables the system to not use as much memory and resources that a low-end device or mobile might have a limited amount of for rendering the Canvas item. In a situation where the user is aware of the consequences and impact of forcing the DPR to be different to the canvas window's DPR then this can be useful in those situations. By having the environment variable to override the DPR then it makes it possible for those needing this right away in all versions of Qt, so we add this now with a view to add API for this at a later date. Change-Id: Icafaa04a15678e2c7f24bc791026676f476a6ced Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit b0193908258f315a5736edcbc2a034d3194d42c9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quick/items/context2d/qquickcontext2dtexture.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/quick/items/context2d/qquickcontext2dtexture.cpp b/src/quick/items/context2d/qquickcontext2dtexture.cpp
index e111f908d0..71a5e414f6 100644
--- a/src/quick/items/context2d/qquickcontext2dtexture.cpp
+++ b/src/quick/items/context2d/qquickcontext2dtexture.cpp
@@ -120,8 +120,15 @@ void QQuickContext2DTexture::setItem(QQuickCanvasItem* item)
bool QQuickContext2DTexture::setCanvasWindow(const QRect& r)
{
- qreal canvasDevicePixelRatio = (m_item && m_item->window()) ?
- m_item->window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio();
+ bool ok = false;
+ static qreal overriddenDevicePixelRatio =
+ !qEnvironmentVariableIsEmpty("QT_CANVAS_OVERRIDE_DEVICEPIXELRATIO") ?
+ qgetenv("QT_CANVAS_OVERRIDE_DEVICEPIXELRATIO").toFloat(&ok) : 0.0;
+ qreal canvasDevicePixelRatio = overriddenDevicePixelRatio;
+ if (overriddenDevicePixelRatio == 0.0) {
+ canvasDevicePixelRatio = (m_item && m_item->window()) ?
+ m_item->window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio();
+ }
if (!qFuzzyCompare(m_canvasDevicePixelRatio, canvasDevicePixelRatio)) {
qCDebug(lcCanvas, "%s device pixel ratio %.1lf -> %.1lf",
(m_item->objectName().isEmpty() ? "Canvas" : qPrintable(m_item->objectName())),