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>
This commit is contained in:
Noel Grandin
2021-09-21 10:01:03 +02:00
parent 4ba0460e3c
commit 19d638eaed
13 changed files with 113 additions and 24 deletions

View File

@@ -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())
{

View File

@@ -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()))
{

View File

@@ -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;
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
{
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()
: BasePrimitive2DImplBase(m_aMutex)
{
}
BasePrimitive2D::BasePrimitive2D() {}
BasePrimitive2D::~BasePrimitive2D() {}

View File

@@ -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())

View File

@@ -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())

View File

@@ -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)

View File

@@ -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())
{

View File

@@ -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())
{

View File

@@ -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())

View File

@@ -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();

View File

@@ -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;

View File

@@ -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())
{

View File

@@ -29,17 +29,49 @@
#include <cppuhelper/basemutex.hxx>
#include <basegfx/range/b2drange.hxx>
#include <com/sun/star/graphic/XPrimitive2D.hpp>
#include <mutex>
namespace drawinglayer::geometry
{
class ViewInformation2D;
}
/** This is a custom re-implementation of cppu::WeakComponentImplHelper which uses
std::recursive_mutex and skips parts of the XComponent stuff.
*/
class DRAWINGLAYER_DLLPUBLIC BasePrimitive2DImplBase : public cppu::OWeakObject,
public css::lang::XComponent,
public css::lang::XTypeProvider,
public css::graphic::XPrimitive2D,
public css::util::XAccounting
{
public:
virtual ~BasePrimitive2DImplBase() override;
virtual void SAL_CALL acquire() noexcept override;
virtual void SAL_CALL release() noexcept override;
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& aType) override;
// css::lang::XComponent
virtual void SAL_CALL dispose() override;
virtual void SAL_CALL
addEventListener(css::uno::Reference<css::lang::XEventListener> const& xListener) override;
virtual void SAL_CALL
removeEventListener(css::uno::Reference<css::lang::XEventListener> const& xListener) override;
// css::lang::XTypeProvider
virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
{
return css::uno::Sequence<sal_Int8>();
}
protected:
mutable std::recursive_mutex m_aMutex;
};
namespace drawinglayer::primitive2d
{
typedef cppu::WeakComponentImplHelper<css::graphic::XPrimitive2D, css::util::XAccounting>
BasePrimitive2DImplBase;
/** BasePrimitive2D class
Baseclass for all C++ implementations of css::graphic::XPrimitive2D
@@ -113,8 +145,7 @@ typedef cppu::WeakComponentImplHelper<css::graphic::XPrimitive2D, css::util::XAc
for view-independent primitives which are defined by not using ViewInformation2D
in their get2DDecomposition/getB2DRange implementations.
*/
class DRAWINGLAYER_DLLPUBLIC BasePrimitive2D : protected cppu::BaseMutex,
public BasePrimitive2DImplBase
class DRAWINGLAYER_DLLPUBLIC BasePrimitive2D : public BasePrimitive2DImplBase
{
BasePrimitive2D(const BasePrimitive2D&) = delete;
BasePrimitive2D& operator=(const BasePrimitive2D&) = delete;