Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't modify text format paint effects in place
Avoids race conditions when multiple threads are rendering the same
text format which contains paint effects

Fixes #37938

(cherry picked from commit 51d8ad7)
  • Loading branch information
nyalldawson committed Jul 27, 2020
1 parent 7cdbfc3 commit 520d3da
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
Expand Up @@ -555,7 +555,7 @@ Sets the join style used for drawing the background shape.
.. seealso:: :py:func:`joinStyle`
%End

QgsPaintEffect *paintEffect() const;
const QgsPaintEffect *paintEffect() const;
%Docstring
Returns the current paint effect for the background shape.

Expand Down
Expand Up @@ -223,7 +223,7 @@ Write settings into a DOM element.
.. seealso:: :py:func:`readXml`
%End

QgsPaintEffect *paintEffect() const;
const QgsPaintEffect *paintEffect() const;
%Docstring
Returns the current paint effect for the buffer.

Expand Down
2 changes: 1 addition & 1 deletion src/core/textrenderer/qgstextbackgroundsettings.cpp
Expand Up @@ -284,7 +284,7 @@ void QgsTextBackgroundSettings::setJoinStyle( Qt::PenJoinStyle style )
d->joinStyle = style;
}

QgsPaintEffect *QgsTextBackgroundSettings::paintEffect() const
const QgsPaintEffect *QgsTextBackgroundSettings::paintEffect() const
{
return d->paintEffect.get();
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/textrenderer/qgstextbackgroundsettings.h
Expand Up @@ -475,7 +475,7 @@ class CORE_EXPORT QgsTextBackgroundSettings
* \returns paint effect
* \see setPaintEffect()
*/
QgsPaintEffect *paintEffect() const;
const QgsPaintEffect *paintEffect() const;

/**
* Sets the current paint \a effect for the background shape.
Expand Down
2 changes: 1 addition & 1 deletion src/core/textrenderer/qgstextbuffersettings.cpp
Expand Up @@ -134,7 +134,7 @@ void QgsTextBufferSettings::setBlendMode( QPainter::CompositionMode mode )
d->blendMode = mode;
}

QgsPaintEffect *QgsTextBufferSettings::paintEffect() const
const QgsPaintEffect *QgsTextBufferSettings::paintEffect() const
{
return d->paintEffect.get();
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/textrenderer/qgstextbuffersettings.h
Expand Up @@ -212,7 +212,7 @@ class CORE_EXPORT QgsTextBufferSettings
* \returns paint effect
* \see setPaintEffect()
*/
QgsPaintEffect *paintEffect() const;
const QgsPaintEffect *paintEffect() const;

/**
* Sets the current paint \a effect for the buffer.
Expand Down
13 changes: 8 additions & 5 deletions src/core/textrenderer/qgstextrenderer.cpp
Expand Up @@ -327,12 +327,13 @@ double QgsTextRenderer::drawBuffer( QgsRenderContext &context, const QgsTextRend
if ( buffer.paintEffect() && buffer.paintEffect()->enabled() )
{
context.setPainter( &buffp );
std::unique_ptr< QgsPaintEffect > tmpEffect( buffer.paintEffect()->clone() );

buffer.paintEffect()->begin( context );
tmpEffect->begin( context );
context.painter()->setPen( pen );
context.painter()->setBrush( tmpColor );
context.painter()->drawPath( path );
buffer.paintEffect()->end( context );
tmpEffect->end( context );

context.setPainter( p );
}
Expand Down Expand Up @@ -616,9 +617,11 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer

QPainter *prevP = context.painter();
QPainter *p = context.painter();
std::unique_ptr< QgsPaintEffect > tmpEffect;
if ( background.paintEffect() && background.paintEffect()->enabled() )
{
background.paintEffect()->begin( context );
tmpEffect.reset( background.paintEffect()->clone() );
tmpEffect->begin( context );
p = context.painter();
}

Expand Down Expand Up @@ -986,9 +989,9 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer
}
}

if ( background.paintEffect() && background.paintEffect()->enabled() )
if ( tmpEffect )
{
background.paintEffect()->end( context );
tmpEffect->end( context );
context.setPainter( prevP );
}
}
Expand Down

0 comments on commit 520d3da

Please sign in to comment.