diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-09-21 10:01:03 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-09-21 15:34:21 +0200 |
commit | 19d638eaedf84cefadf55d561c3c36df33fed6fe (patch) | |
tree | 3f2b157d60c8db2d06eac5f86140da582f1da13f /drawinglayer | |
parent | 4ba0460e3cf3ce33794090968fd4c906422bbd25 (diff) |
reduce cost of BasePrimitive2D (tdf#125892)
the default WeakComponentImplHelper wants to allocate two child objects
(osl::Mutex and BroadcastHelper).
So use a custom re-implemenation that does not need to allocate any
child objects.
Change-Id: I288e58558398e39daa0d4b11e0b60a924445240d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122381
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'drawinglayer')
12 files changed, 76 insertions, 18 deletions
diff --git a/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx b/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx index 896f85d81f1e..301d501e6e32 100644 --- a/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx +++ b/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx @@ -33,7 +33,7 @@ void BufferedDecompositionPrimitive2D::get2DDecomposition( Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { - ::osl::MutexGuard aGuard(m_aMutex); + std::unique_lock aGuard(m_aMutex); if (getBuffered2DDecomposition().empty()) { diff --git a/drawinglayer/source/primitive2d/backgroundcolorprimitive2d.cxx b/drawinglayer/source/primitive2d/backgroundcolorprimitive2d.cxx index 90ff831da005..f13b92bc4ddb 100644 --- a/drawinglayer/source/primitive2d/backgroundcolorprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/backgroundcolorprimitive2d.cxx @@ -67,7 +67,7 @@ namespace drawinglayer::primitive2d void BackgroundColorPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); if(!getBuffered2DDecomposition().empty() && (maLastViewport != rViewInformation.getViewport())) { diff --git a/drawinglayer/source/primitive2d/baseprimitive2d.cxx b/drawinglayer/source/primitive2d/baseprimitive2d.cxx index 61cd0923ad3d..71a13346beff 100644 --- a/drawinglayer/source/primitive2d/baseprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/baseprimitive2d.cxx @@ -24,15 +24,73 @@ #include <drawinglayer/geometry/viewinformation2d.hxx> #include <basegfx/utils/canvastools.hxx> #include <comphelper/sequence.hxx> +#include <cppuhelper/queryinterface.hxx> using namespace css; -namespace drawinglayer::primitive2d +BasePrimitive2DImplBase::~BasePrimitive2DImplBase() {} + +css::uno::Any BasePrimitive2DImplBase::queryInterface(css::uno::Type const& rType) +{ + css::uno::Any aReturn = ::cppu::queryInterface( + rType, static_cast<uno::XWeak*>(this), static_cast<lang::XComponent*>(this), + static_cast<lang::XTypeProvider*>(this), static_cast<graphic::XPrimitive2D*>(this), + static_cast<util::XAccounting*>(this)); + if (aReturn.hasValue()) + return aReturn; + return OWeakObject::queryInterface(rType); +} + +void BasePrimitive2DImplBase::acquire() noexcept { OWeakObject::acquire(); } + +void BasePrimitive2DImplBase::release() noexcept { -BasePrimitive2D::BasePrimitive2D() - : BasePrimitive2DImplBase(m_aMutex) + if (osl_atomic_decrement(&m_refCount) != 0) + return; + + // ensure no other references are created, via the weak connection point, from now on + disposeWeakConnectionPoint(); + // restore reference count: + osl_atomic_increment(&m_refCount); + // if (! rBHelper.bDisposed) { + // try { + // dispose(); + // } + // catch (RuntimeException const& exc) { // don't break throw () + // SAL_WARN( "cppuhelper", exc ); + // } + // OSL_ASSERT( rBHelper.bDisposed ); + // } + OWeakObject::release(); +} + +void BasePrimitive2DImplBase::dispose() {} + +void BasePrimitive2DImplBase::addEventListener( + css::uno::Reference<css::lang::XEventListener> const&) { + assert(false); } +void BasePrimitive2DImplBase::removeEventListener( + css::uno::Reference<css::lang::XEventListener> const&) +{ + assert(false); +} + +css::uno::Sequence<css::uno::Type> BasePrimitive2DImplBase::getTypes() +{ + static const css::uno::Sequence<uno::Type> aTypeList{ + cppu::UnoType<uno::XWeak>::get(), cppu::UnoType<lang::XComponent>::get(), + cppu::UnoType<lang::XTypeProvider>::get(), cppu::UnoType<graphic::XPrimitive2D>::get(), + cppu::UnoType<util::XAccounting>::get() + }; + + return aTypeList; +} + +namespace drawinglayer::primitive2d +{ +BasePrimitive2D::BasePrimitive2D() {} BasePrimitive2D::~BasePrimitive2D() {} diff --git a/drawinglayer/source/primitive2d/controlprimitive2d.cxx b/drawinglayer/source/primitive2d/controlprimitive2d.cxx index c5ece360e5e8..92f0ed5cf464 100644 --- a/drawinglayer/source/primitive2d/controlprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/controlprimitive2d.cxx @@ -317,7 +317,7 @@ namespace drawinglayer::primitive2d { // this primitive is view-dependent related to the scaling. If scaling has changed, // destroy existing decomposition. To detect change, use size of unit size in view coordinates - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); const basegfx::B2DVector aNewScaling(rViewInformation.getObjectToViewTransformation() * basegfx::B2DVector(1.0, 1.0)); if(!getBuffered2DDecomposition().empty()) diff --git a/drawinglayer/source/primitive2d/embedded3dprimitive2d.cxx b/drawinglayer/source/primitive2d/embedded3dprimitive2d.cxx index fd2510915811..0b217adf6b49 100644 --- a/drawinglayer/source/primitive2d/embedded3dprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/embedded3dprimitive2d.cxx @@ -35,7 +35,7 @@ namespace drawinglayer::primitive2d { bool Embedded3DPrimitive2D::impGetShadow3D() const { - osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); // create on demand if(!mbShadow3DChecked && !getChildren3D().empty()) diff --git a/drawinglayer/source/primitive2d/fillhatchprimitive2d.cxx b/drawinglayer/source/primitive2d/fillhatchprimitive2d.cxx index d527b9cf2539..666f5459ed39 100644 --- a/drawinglayer/source/primitive2d/fillhatchprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/fillhatchprimitive2d.cxx @@ -173,7 +173,7 @@ namespace drawinglayer::primitive2d void FillHatchPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance()); if(bAdaptDistance) diff --git a/drawinglayer/source/primitive2d/gridprimitive2d.cxx b/drawinglayer/source/primitive2d/gridprimitive2d.cxx index a43e8af9fb71..64816b076862 100644 --- a/drawinglayer/source/primitive2d/gridprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/gridprimitive2d.cxx @@ -305,7 +305,7 @@ namespace drawinglayer::primitive2d void GridPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); if(!getBuffered2DDecomposition().empty()) { diff --git a/drawinglayer/source/primitive2d/helplineprimitive2d.cxx b/drawinglayer/source/primitive2d/helplineprimitive2d.cxx index 71b372d36164..0db4f37470c2 100644 --- a/drawinglayer/source/primitive2d/helplineprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/helplineprimitive2d.cxx @@ -155,7 +155,7 @@ namespace drawinglayer::primitive2d void HelplinePrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); if(!getBuffered2DDecomposition().empty()) { diff --git a/drawinglayer/source/primitive2d/polygonprimitive2d.cxx b/drawinglayer/source/primitive2d/polygonprimitive2d.cxx index 9919658940e1..184f72fdb810 100644 --- a/drawinglayer/source/primitive2d/polygonprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/polygonprimitive2d.cxx @@ -165,7 +165,7 @@ void PolygonMarkerPrimitive2D::get2DDecomposition( Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { - ::osl::MutexGuard aGuard(m_aMutex); + std::unique_lock aGuard(m_aMutex); bool bNeedNewDecomposition(false); if (!getBuffered2DDecomposition().empty()) diff --git a/drawinglayer/source/primitive2d/primitivetools2d.cxx b/drawinglayer/source/primitive2d/primitivetools2d.cxx index da0a378a0089..61e060e5ecfa 100644 --- a/drawinglayer/source/primitive2d/primitivetools2d.cxx +++ b/drawinglayer/source/primitive2d/primitivetools2d.cxx @@ -26,7 +26,7 @@ namespace drawinglayer::primitive2d { void DiscreteMetricDependentPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); // get the current DiscreteUnit, look at X and Y and use the maximum const basegfx::B2DVector aDiscreteVector(rViewInformation.getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 1.0)); @@ -53,7 +53,7 @@ namespace drawinglayer::primitive2d void ViewportDependentPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); // get the current Viewport const basegfx::B2DRange& rViewport = rViewInformation.getViewport(); @@ -76,7 +76,7 @@ namespace drawinglayer::primitive2d void ViewTransformationDependentPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); // get the current ViewTransformation const basegfx::B2DHomMatrix& rViewTransformation = rViewInformation.getViewTransformation(); @@ -99,7 +99,7 @@ namespace drawinglayer::primitive2d void ObjectAndViewTransformationDependentPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); // get the current ViewTransformation const basegfx::B2DHomMatrix& rViewTransformation = rViewInformation.getViewTransformation(); diff --git a/drawinglayer/source/primitive2d/sceneprimitive2d.cxx b/drawinglayer/source/primitive2d/sceneprimitive2d.cxx index a1a38aa735af..cde119d514ba 100644 --- a/drawinglayer/source/primitive2d/sceneprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/sceneprimitive2d.cxx @@ -128,7 +128,7 @@ namespace drawinglayer::primitive2d { bool ScenePrimitive2D::impGetShadow3D() const { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); // create on demand if(!mbShadow3DChecked && !getChildren3D().empty()) @@ -626,7 +626,7 @@ namespace drawinglayer::primitive2d void ScenePrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); // get the involved ranges (see helper method calculateDiscreteSizes for details) basegfx::B2DRange aDiscreteRange; diff --git a/drawinglayer/source/primitive2d/texteffectprimitive2d.cxx b/drawinglayer/source/primitive2d/texteffectprimitive2d.cxx index e68be6b28391..5d6425fc77e5 100644 --- a/drawinglayer/source/primitive2d/texteffectprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/texteffectprimitive2d.cxx @@ -213,7 +213,7 @@ void TextEffectPrimitive2D::get2DDecomposition( Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { - ::osl::MutexGuard aGuard(m_aMutex); + std::unique_lock aGuard(m_aMutex); if (!getBuffered2DDecomposition().empty()) { |