Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raster canvas items render at wrong scale with High DPI devices #46882

Closed
2 tasks done
jlayt opened this issue Jan 18, 2022 · 7 comments
Closed
2 tasks done

Raster canvas items render at wrong scale with High DPI devices #46882

jlayt opened this issue Jan 18, 2022 · 7 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Map and Legend Related to map or legend rendering Regression Something which used to work, but doesn't anymore

Comments

@jlayt
Copy link

jlayt commented Jan 18, 2022

What is the bug or the crash?

In the latest 3.22.3 release on Retina Macs, GeoTIFFs are being rendered on canvas at the wrong scale and position and very fuzzy. Using the query tool shows that the data itself still has the correct extent. Using the measure tool the scale appears to be out by a factor of 2 times, which I believe is the usual scaling factor applied by Macs on Retina / High DPI screens? Setting "Respect Screen DPI" and restarting has no effect.

QGIS 3.22.2 and 3.16.16 render correctly, as do non-Retina Macs using v3.22.3. Tested on both macOS 11.6 and 12.1. I am unable to test on Windows or Linux High DPI devices at this time, but could do so this evening if required.

I suspect some recent patches to use devicePixelRatio to set dotsPerMeter may be at fault, see commits 7c97dbb and 9a8824e in PR #46515 to fix Issue #44426, which appears in 3.22.3 but is not in 3.16.16.

Steps to reproduce the issue

  1. Create new project with correct CRS, in our case EPSG:27700
  2. Add known valid raster
  3. Map canvas auto-zooms to valid extent of loaded raster. In 3.22.2 this displays the full raster at correct scale, in 3.22.3 the displayed raster is offset from the auto-zoom canvas view, is fuzzy, and at the wrong scale.
  4. Using the Measure Tool to measure known points displayed on the raster in 3.22.3 produces distances 2 times that of 3.22.2
  5. Using the Identify Features tool, clicking outside the displayed raster but inside the real extent returns valid results, while clicking outside the real extent but inside the displayed raster returns no results.

Versions

QGIS version 3.22.3-Białowieża QGIS code revision 1628765
Qt version 5.15.2
Python version 3.9.5
GDAL/OGR version 3.3.2
PROJ version 8.1.1
EPSG Registry database version v10.028 (2021-07-07)
GEOS version 3.9.1-CAPI-1.14.2
SQLite version 3.35.2
PDAL version 2.3.0
PostgreSQL client version 12.3
SpatiaLite version 5.0.1
QWT version 6.1.6
QScintilla2 version 2.11.5
OS version macOS 12.1
       
Active Python plugins
numericalDigitize 0.4.6
slyr_community 3.2.1
VectorBender 0.2.1
PluginMaker 0.1
LPGetLibraryInfo 3.0.2
AnotherDXF2Shape 1.2.3
plaingeometryeditor 3.0.0
LPMaps 4.0.1
ArkSpatial 3.3.6
pluginbuilder3 3.2.1
pre_ex_builder 0.5
MemoryLayerSaver 4.0.4
LPFigureBuilder 3.2.0
plugin_reloader 0.9.1
survey_import 0.1.3
processing 2.12.99
sagaprovider 2.12.99
grassprovider 2.12.99
db_manager 0.1.20
MetaSearch 0.3.5

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

  • I tried with a new QGIS profile

Additional context

No response

@jlayt jlayt added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jan 18, 2022
@gioman gioman added the macOS label Jan 18, 2022
@gioman gioman changed the title Raster canvas items render at wrong scale on Mac High DPI devices Raster canvas items render at wrong scale on macOS with High DPI devices Jan 18, 2022
@gioman gioman added Regression Something which used to work, but doesn't anymore Map and Legend Related to map or legend rendering labels Jan 18, 2022
@fgianoli
Copy link

I am experiencing the same issue on Windows with QGIS 3.22.3
The rasters are not displayed at the right scale.
I also have a High DPI device, but I don't understand if the issue could be related to the screen resolution.

@gioman could you please update the issue removing the macOS label?

There is any test that I can do in order to help?

@jlayt
Copy link
Author

jlayt commented Jan 20, 2022

I did test on a Lenovo laptop, Windows 10, 2880x1800 resolution and 200% scaling reported in the Display settings, and it rendered correctly. I suspect it may be hardware or driver specific on Windows then. My laptop has both Intel Xe and NVidia MX450 graphics, I'm not sure which is being used at the time. @fgianoli Can you update with your hardware details and scaling?

I was unable to test on Linux as my distro is only on 3.22.0.

I'll try dig into the devicePixelRatio() code some more to see where it's getting the details from.

@gioman gioman changed the title Raster canvas items render at wrong scale on macOS with High DPI devices Raster canvas items render at wrong scale with High DPI devices Jan 20, 2022
@gioman gioman removed the macOS label Jan 20, 2022
@fgianoli
Copy link

Thanks @jlayt

I have a DELL XPS 7390, running Windows 10 Pro
Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz.
Resolution 3840x2160 and 300% of scaling.
GPU Intel(R) UHD Graphic

@fgianoli
Copy link

fgianoli commented Jan 20, 2022

I don't know if these settings could be related to the issues, but I added some Windows Env variables in order to see correctly the QGIS GUI as described in this post post

QT_AUTO_SCREEN_SCALE_FACTOR = 0
QT_SCREEN_SCALE_FACTOR = 2

@jlayt
Copy link
Author

jlayt commented Jan 20, 2022

Looking at QgsMapSettings::devicePixelRatio(), it is a float that defaults to 1.0 unless overridden. This appears to happen in QgsMapCanvas::updateDevicePixelFromScreen() where it always gets set from QPaintDevice::devicePixelRatio(). Note that this returns an integer value, QPaintDevice::devicePixelRatioF() should be used to get a float, I'm not sure if that affects anything though as it's usually 2.0 for high dpi.

Next, QgsMapCanvas::updateDevicePixelFromScreen() checks if QgsSettingsRegistryGui::settingsRespectScreenDPI is set, and if so sets QgsMapSettings::outputDpi() to the physical DPI of the screen, otherwise to the logical DPI. The latter is commented as "Fallback: compatibility with QGIS <= 3.20; always assume low dpi screens". `Does this mean QgsMapSettings has an inconsistent devicePixelRatio set to a High DPI ratio, but an outputDpi set to a low DPI? Again, not sure if that's an issue or not, as setting settingsRespectScreenDPI seems to make no difference for me (but Macs do fake a lot of this stuff...).

It still seems a little weird that in QgsMapRendererJob::allocateImage() the QImage already has the devicePixelRatio set from the QgsMapSettings, so why the extra * devicePixelRatio is needed to set the dotsPerMeter I'm not sure. If I had to guess, I'd say 7c97dbb needs reverting? Then again, all this dpi stuff does hurts my brain, there's a reason I mostly hacked on QtCore!

I am trying to run the nightly to get debug output that logs the various numbers involved, but can't seem to produce it, anyone have hints on how that works on Mac?

@nyalldawson
Copy link
Collaborator

Should be fixed by #46931

@jlayt
Copy link
Author

jlayt commented Jan 26, 2022

Tested the nightly and can confirm this resolves out issues, many thanks Nyall!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Map and Legend Related to map or legend rendering Regression Something which used to work, but doesn't anymore
Projects
None yet
Development

No branches or pull requests

4 participants