From 8b15f59639d779b1e7b5e40cdc623db8c23cc5f4 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 11 Jul 2022 12:11:19 +1000 Subject: [PATCH] Force use of raster masking in layout designer preview The vector masking (while great for output quality) is much slower, so for the layout designer preview renders we just use the faster raster approach. --- python/core/auto_additions/qgis.py | 5 ++++- python/core/auto_generated/qgis.sip.in | 1 + src/core/layout/qgslayoutitemmap.cpp | 2 ++ src/core/maprenderer/qgsmaprenderercustompainterjob.cpp | 2 +- src/core/maprenderer/qgsmaprendererjob.cpp | 5 +++-- src/core/qgis.h | 1 + 6 files changed, 12 insertions(+), 4 deletions(-) diff --git a/python/core/auto_additions/qgis.py b/python/core/auto_additions/qgis.py index f540ed774ddf..1b1489104d6b 100644 --- a/python/core/auto_additions/qgis.py +++ b/python/core/auto_additions/qgis.py @@ -1214,7 +1214,10 @@ QgsMapSettings.SkipSymbolRendering = Qgis.MapSettingsFlag.SkipSymbolRendering QgsMapSettings.SkipSymbolRendering.is_monkey_patched = True QgsMapSettings.SkipSymbolRendering.__doc__ = "Disable symbol rendering while still drawing labels if enabled (since QGIS 3.24)" -Qgis.MapSettingsFlag.__doc__ = 'Flags which adjust the way maps are rendered.\n\n.. versionadded:: 3.22\n\n' + '* ``Antialiasing``: ' + Qgis.MapSettingsFlag.Antialiasing.__doc__ + '\n' + '* ``DrawEditingInfo``: ' + Qgis.MapSettingsFlag.DrawEditingInfo.__doc__ + '\n' + '* ``ForceVectorOutput``: ' + Qgis.MapSettingsFlag.ForceVectorOutput.__doc__ + '\n' + '* ``UseAdvancedEffects``: ' + Qgis.MapSettingsFlag.UseAdvancedEffects.__doc__ + '\n' + '* ``DrawLabeling``: ' + Qgis.MapSettingsFlag.DrawLabeling.__doc__ + '\n' + '* ``UseRenderingOptimization``: ' + Qgis.MapSettingsFlag.UseRenderingOptimization.__doc__ + '\n' + '* ``DrawSelection``: ' + Qgis.MapSettingsFlag.DrawSelection.__doc__ + '\n' + '* ``DrawSymbolBounds``: ' + Qgis.MapSettingsFlag.DrawSymbolBounds.__doc__ + '\n' + '* ``RenderMapTile``: ' + Qgis.MapSettingsFlag.RenderMapTile.__doc__ + '\n' + '* ``RenderPartialOutput``: ' + Qgis.MapSettingsFlag.RenderPartialOutput.__doc__ + '\n' + '* ``RenderPreviewJob``: ' + Qgis.MapSettingsFlag.RenderPreviewJob.__doc__ + '\n' + '* ``RenderBlocking``: ' + Qgis.MapSettingsFlag.RenderBlocking.__doc__ + '\n' + '* ``LosslessImageRendering``: ' + Qgis.MapSettingsFlag.LosslessImageRendering.__doc__ + '\n' + '* ``Render3DMap``: ' + Qgis.MapSettingsFlag.Render3DMap.__doc__ + '\n' + '* ``HighQualityImageTransforms``: ' + Qgis.MapSettingsFlag.HighQualityImageTransforms.__doc__ + '\n' + '* ``SkipSymbolRendering``: ' + Qgis.MapSettingsFlag.SkipSymbolRendering.__doc__ +QgsMapSettings.ForceRasterMasks = Qgis.MapSettingsFlag.ForceRasterMasks +QgsMapSettings.ForceRasterMasks.is_monkey_patched = True +QgsMapSettings.ForceRasterMasks.__doc__ = "Force symbol masking to be applied using a raster method. This is considerably faster when compared to the vector method, but results in a inferior quality output. (since QGIS 3.26.1)" +Qgis.MapSettingsFlag.__doc__ = 'Flags which adjust the way maps are rendered.\n\n.. versionadded:: 3.22\n\n' + '* ``Antialiasing``: ' + Qgis.MapSettingsFlag.Antialiasing.__doc__ + '\n' + '* ``DrawEditingInfo``: ' + Qgis.MapSettingsFlag.DrawEditingInfo.__doc__ + '\n' + '* ``ForceVectorOutput``: ' + Qgis.MapSettingsFlag.ForceVectorOutput.__doc__ + '\n' + '* ``UseAdvancedEffects``: ' + Qgis.MapSettingsFlag.UseAdvancedEffects.__doc__ + '\n' + '* ``DrawLabeling``: ' + Qgis.MapSettingsFlag.DrawLabeling.__doc__ + '\n' + '* ``UseRenderingOptimization``: ' + Qgis.MapSettingsFlag.UseRenderingOptimization.__doc__ + '\n' + '* ``DrawSelection``: ' + Qgis.MapSettingsFlag.DrawSelection.__doc__ + '\n' + '* ``DrawSymbolBounds``: ' + Qgis.MapSettingsFlag.DrawSymbolBounds.__doc__ + '\n' + '* ``RenderMapTile``: ' + Qgis.MapSettingsFlag.RenderMapTile.__doc__ + '\n' + '* ``RenderPartialOutput``: ' + Qgis.MapSettingsFlag.RenderPartialOutput.__doc__ + '\n' + '* ``RenderPreviewJob``: ' + Qgis.MapSettingsFlag.RenderPreviewJob.__doc__ + '\n' + '* ``RenderBlocking``: ' + Qgis.MapSettingsFlag.RenderBlocking.__doc__ + '\n' + '* ``LosslessImageRendering``: ' + Qgis.MapSettingsFlag.LosslessImageRendering.__doc__ + '\n' + '* ``Render3DMap``: ' + Qgis.MapSettingsFlag.Render3DMap.__doc__ + '\n' + '* ``HighQualityImageTransforms``: ' + Qgis.MapSettingsFlag.HighQualityImageTransforms.__doc__ + '\n' + '* ``SkipSymbolRendering``: ' + Qgis.MapSettingsFlag.SkipSymbolRendering.__doc__ + '\n' + '* ``ForceRasterMasks``: ' + Qgis.MapSettingsFlag.ForceRasterMasks.__doc__ # -- QgsMapSettings.Flags = Qgis.MapSettingsFlags Qgis.MapSettingsFlag.baseClass = Qgis diff --git a/python/core/auto_generated/qgis.sip.in b/python/core/auto_generated/qgis.sip.in index 0c9ba12d0c7c..ea8632a77eba 100644 --- a/python/core/auto_generated/qgis.sip.in +++ b/python/core/auto_generated/qgis.sip.in @@ -804,6 +804,7 @@ The development version Render3DMap, HighQualityImageTransforms, SkipSymbolRendering, + ForceRasterMasks, }; typedef QFlags MapSettingsFlags; diff --git a/src/core/layout/qgslayoutitemmap.cpp b/src/core/layout/qgslayoutitemmap.cpp index 409a6089a126..524133ad1ea7 100644 --- a/src/core/layout/qgslayoutitemmap.cpp +++ b/src/core/layout/qgslayoutitemmap.cpp @@ -1526,6 +1526,8 @@ QgsMapSettings QgsLayoutItemMap::mapSettings( const QgsRectangle &extent, QSizeF { // preview render - always use optimization jobMapSettings.setFlag( Qgis::MapSettingsFlag::UseRenderingOptimization, true ); + // in a preview render we disable vector masking, as that is considerably slower vs raster masking + jobMapSettings.setFlag( Qgis::MapSettingsFlag::ForceRasterMasks, true ); jobMapSettings.setRendererUsage( Qgis::RendererUsage::View ); } diff --git a/src/core/maprenderer/qgsmaprenderercustompainterjob.cpp b/src/core/maprenderer/qgsmaprenderercustompainterjob.cpp index d78c79403cf0..6eff928fb0c5 100644 --- a/src/core/maprenderer/qgsmaprenderercustompainterjob.cpp +++ b/src/core/maprenderer/qgsmaprenderercustompainterjob.cpp @@ -428,7 +428,7 @@ void QgsMapRendererCustomPainterJob::doRender() } } - bool forceVector = mSettings.testFlag( Qgis::MapSettingsFlag::ForceVectorOutput ); + bool forceVector = mSettings.testFlag( Qgis::MapSettingsFlag::ForceVectorOutput ) && !mSettings.testFlag( Qgis::MapSettingsFlag::ForceRasterMasks ); composeSecondPass( mSecondPassLayerJobs, mLabelJob, forceVector ); if ( !forceVector ) diff --git a/src/core/maprenderer/qgsmaprendererjob.cpp b/src/core/maprenderer/qgsmaprendererjob.cpp index 6b31dac5f809..0b7b15e2761b 100644 --- a/src/core/maprenderer/qgsmaprendererjob.cpp +++ b/src/core/maprenderer/qgsmaprendererjob.cpp @@ -603,7 +603,8 @@ std::vector< LayerRenderJob > QgsMapRendererJob::prepareSecondPassJobs( std::vec // and the list of source layers that have a mask QHash, QList>> maskedSymbolLayers; - const bool forceVector = mapSettings().testFlag( Qgis::MapSettingsFlag::ForceVectorOutput ); + const bool forceVector = mapSettings().testFlag( Qgis::MapSettingsFlag::ForceVectorOutput ) + && !mapSettings().testFlag( Qgis::MapSettingsFlag::ForceRasterMasks ); // First up, create a mapping of layer id to jobs. We need this to filter out any masking // which refers to layers which we aren't rendering as part of this map render @@ -873,7 +874,7 @@ std::vector< LayerRenderJob > QgsMapRendererJob::prepareSecondPassJobs( std::vec void QgsMapRendererJob::initSecondPassJobs( std::vector< LayerRenderJob > &secondPassJobs, LabelRenderJob &labelJob ) const { - if ( !mapSettings().testFlag( Qgis::MapSettingsFlag::ForceVectorOutput ) ) + if ( !mapSettings().testFlag( Qgis::MapSettingsFlag::ForceVectorOutput ) || mapSettings().testFlag( Qgis::MapSettingsFlag::ForceRasterMasks ) ) return; for ( LayerRenderJob &job : secondPassJobs ) diff --git a/src/core/qgis.h b/src/core/qgis.h index cb79cf672d46..d30ab3dacc4b 100644 --- a/src/core/qgis.h +++ b/src/core/qgis.h @@ -1334,6 +1334,7 @@ class CORE_EXPORT Qgis Render3DMap = 0x2000, //!< Render is for a 3D map HighQualityImageTransforms = 0x4000, //!< Enable high quality image transformations, which results in better appearance of scaled or rotated raster components of a map (since QGIS 3.24) SkipSymbolRendering = 0x8000, //!< Disable symbol rendering while still drawing labels if enabled (since QGIS 3.24) + ForceRasterMasks = 0x10000, //!< Force symbol masking to be applied using a raster method. This is considerably faster when compared to the vector method, but results in a inferior quality output. (since QGIS 3.26.1) }; //! Map settings flags Q_DECLARE_FLAGS( MapSettingsFlags, MapSettingsFlag ) SIP_MONKEYPATCH_FLAGS_UNNEST( QgsMapSettings, Flags )