From e49737c15007b74b0c2decef8e1af2895d2fee89 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 20 Aug 2021 15:30:22 +0200 Subject: Canvas: Add a means to override the DPR used via an environment variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Morten Johan Sørvig Reviewed-by: Shawn Rutledge (cherry picked from commit b0193908258f315a5736edcbc2a034d3194d42c9) Reviewed-by: Qt Cherry-pick Bot --- src/quick/items/context2d/qquickcontext2dtexture.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/quick/items/context2d/qquickcontext2dtexture.cpp b/src/quick/items/context2d/qquickcontext2dtexture.cpp index 69ed7e5a6d..4248c192a9 100644 --- a/src/quick/items/context2d/qquickcontext2dtexture.cpp +++ b/src/quick/items/context2d/qquickcontext2dtexture.cpp @@ -165,8 +165,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())), -- cgit v1.2.3