Kaydet (Commit) 0c85109e authored tarafından Thomas Arnhold's avatar Thomas Arnhold Kaydeden (comit) Thorsten Behrens

fdo#62525: use cow_wrapper for ViewInformation2D

Change-Id: Ide3bce3257c9fed7bbda7276dfb55fa179d74fdd
Reviewed-on: https://gerrit.libreoffice.org/3183Tested-by: 's avatarThorsten Behrens <tbehrens@suse.com>
Reviewed-by: 's avatarThorsten Behrens <tbehrens@suse.com>
üst 9ab44f12
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <com/sun/star/uno/Sequence.h> #include <com/sun/star/uno/Sequence.h>
#include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/drawing/XDrawPage.hpp> #include <com/sun/star/drawing/XDrawPage.hpp>
#include <o3tl/cow_wrapper.hxx>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// predefines // predefines
...@@ -58,9 +59,12 @@ namespace drawinglayer ...@@ -58,9 +59,12 @@ namespace drawinglayer
*/ */
class DRAWINGLAYER_DLLPUBLIC ViewInformation2D class DRAWINGLAYER_DLLPUBLIC ViewInformation2D
{ {
public:
typedef o3tl::cow_wrapper< ImpViewInformation2D, o3tl::ThreadSafeRefCountingPolicy > ImplType;
private: private:
/// pointer to private implementation class /// pointer to private implementation class
ImpViewInformation2D* mpViewInformation2D; ImplType mpViewInformation2D;
public: public:
/** Constructor: Create a ViewInformation2D /** Constructor: Create a ViewInformation2D
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <basegfx/tools/canvastools.hxx> #include <basegfx/tools/canvastools.hxx>
#include <com/sun/star/geometry/AffineMatrix2D.hpp> #include <com/sun/star/geometry/AffineMatrix2D.hpp>
#include <com/sun/star/geometry/RealRectangle2D.hpp> #include <com/sun/star/geometry/RealRectangle2D.hpp>
#include <rtl/instance.hxx>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
...@@ -42,9 +43,6 @@ namespace drawinglayer ...@@ -42,9 +43,6 @@ namespace drawinglayer
// two memory regions for pairs of ViewInformation2D/ImpViewInformation2D // two memory regions for pairs of ViewInformation2D/ImpViewInformation2D
friend class ::drawinglayer::geometry::ViewInformation2D; friend class ::drawinglayer::geometry::ViewInformation2D;
// the refcounter. 0 means exclusively used
sal_uInt32 mnRefCount;
protected: protected:
// the object transformation // the object transformation
basegfx::B2DHomMatrix maObjectTransformation; basegfx::B2DHomMatrix maObjectTransformation;
...@@ -261,8 +259,7 @@ namespace drawinglayer ...@@ -261,8 +259,7 @@ namespace drawinglayer
const uno::Reference< drawing::XDrawPage >& rxDrawPage, const uno::Reference< drawing::XDrawPage >& rxDrawPage,
double fViewTime, double fViewTime,
const uno::Sequence< beans::PropertyValue >& rExtendedParameters) const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
: mnRefCount(0), : maObjectTransformation(rObjectTransformation),
maObjectTransformation(rObjectTransformation),
maViewTransformation(rViewTransformation), maViewTransformation(rViewTransformation),
maObjectToViewTransformation(), maObjectToViewTransformation(),
maInverseObjectToViewTransformation(), maInverseObjectToViewTransformation(),
...@@ -278,8 +275,7 @@ namespace drawinglayer ...@@ -278,8 +275,7 @@ namespace drawinglayer
} }
explicit ImpViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters) explicit ImpViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
: mnRefCount(0), : maObjectTransformation(),
maObjectTransformation(),
maViewTransformation(), maViewTransformation(),
maObjectToViewTransformation(), maObjectToViewTransformation(),
maInverseObjectToViewTransformation(), maInverseObjectToViewTransformation(),
...@@ -295,8 +291,7 @@ namespace drawinglayer ...@@ -295,8 +291,7 @@ namespace drawinglayer
} }
ImpViewInformation2D() ImpViewInformation2D()
: mnRefCount(0), : maObjectTransformation(),
maObjectTransformation(),
maViewTransformation(), maViewTransformation(),
maObjectToViewTransformation(), maObjectToViewTransformation(),
maInverseObjectToViewTransformation(), maInverseObjectToViewTransformation(),
...@@ -407,21 +402,6 @@ namespace drawinglayer ...@@ -407,21 +402,6 @@ namespace drawinglayer
&& mfViewTime == rCandidate.mfViewTime && mfViewTime == rCandidate.mfViewTime
&& mxExtendedInformation == rCandidate.mxExtendedInformation); && mxExtendedInformation == rCandidate.mxExtendedInformation);
} }
static ImpViewInformation2D* get_global_default()
{
static ImpViewInformation2D* pDefault = 0;
if(!pDefault)
{
pDefault = new ImpViewInformation2D();
// never delete; start with RefCount 1, not 0
pDefault->mnRefCount++;
}
return pDefault;
}
}; };
} // end of anonymous namespace } // end of anonymous namespace
} // end of namespace drawinglayer } // end of namespace drawinglayer
...@@ -432,6 +412,12 @@ namespace drawinglayer ...@@ -432,6 +412,12 @@ namespace drawinglayer
{ {
namespace geometry namespace geometry
{ {
namespace
{
struct theGlobalDefault :
public rtl::Static< ViewInformation2D::ImplType, theGlobalDefault > {};
}
ViewInformation2D::ViewInformation2D( ViewInformation2D::ViewInformation2D(
const basegfx::B2DHomMatrix& rObjectTransformation, const basegfx::B2DHomMatrix& rObjectTransformation,
const basegfx::B2DHomMatrix& rViewTransformation, const basegfx::B2DHomMatrix& rViewTransformation,
...@@ -439,7 +425,7 @@ namespace drawinglayer ...@@ -439,7 +425,7 @@ namespace drawinglayer
const uno::Reference< drawing::XDrawPage >& rxDrawPage, const uno::Reference< drawing::XDrawPage >& rxDrawPage,
double fViewTime, double fViewTime,
const uno::Sequence< beans::PropertyValue >& rExtendedParameters) const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
: mpViewInformation2D(new ImpViewInformation2D( : mpViewInformation2D(ImpViewInformation2D(
rObjectTransformation, rObjectTransformation,
rViewTransformation, rViewTransformation,
rViewport, rViewport,
...@@ -450,74 +436,38 @@ namespace drawinglayer ...@@ -450,74 +436,38 @@ namespace drawinglayer
} }
ViewInformation2D::ViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters) ViewInformation2D::ViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
: mpViewInformation2D(new ImpViewInformation2D(rViewParameters)) : mpViewInformation2D(ImpViewInformation2D(rViewParameters))
{ {
} }
ViewInformation2D::ViewInformation2D() ViewInformation2D::ViewInformation2D()
: mpViewInformation2D(ImpViewInformation2D::get_global_default()) : mpViewInformation2D(theGlobalDefault::get())
{ {
mpViewInformation2D->mnRefCount++;
} }
ViewInformation2D::ViewInformation2D(const ViewInformation2D& rCandidate) ViewInformation2D::ViewInformation2D(const ViewInformation2D& rCandidate)
: mpViewInformation2D(rCandidate.mpViewInformation2D) : mpViewInformation2D(rCandidate.mpViewInformation2D)
{ {
::osl::Mutex m_mutex;
mpViewInformation2D->mnRefCount++;
} }
ViewInformation2D::~ViewInformation2D() ViewInformation2D::~ViewInformation2D()
{ {
::osl::Mutex m_mutex;
if(mpViewInformation2D->mnRefCount)
{
mpViewInformation2D->mnRefCount--;
}
else
{
delete mpViewInformation2D;
}
} }
bool ViewInformation2D::isDefault() const bool ViewInformation2D::isDefault() const
{ {
return mpViewInformation2D == ImpViewInformation2D::get_global_default(); return mpViewInformation2D.same_object(theGlobalDefault::get());
} }
ViewInformation2D& ViewInformation2D::operator=(const ViewInformation2D& rCandidate) ViewInformation2D& ViewInformation2D::operator=(const ViewInformation2D& rCandidate)
{ {
::osl::Mutex m_mutex;
if(mpViewInformation2D->mnRefCount)
{
mpViewInformation2D->mnRefCount--;
}
else
{
delete mpViewInformation2D;
}
mpViewInformation2D = rCandidate.mpViewInformation2D; mpViewInformation2D = rCandidate.mpViewInformation2D;
mpViewInformation2D->mnRefCount++;
return *this; return *this;
} }
bool ViewInformation2D::operator==(const ViewInformation2D& rCandidate) const bool ViewInformation2D::operator==(const ViewInformation2D& rCandidate) const
{ {
if(rCandidate.mpViewInformation2D == mpViewInformation2D) return rCandidate.mpViewInformation2D == mpViewInformation2D;
{
return true;
}
if(rCandidate.isDefault() != isDefault())
{
return false;
}
return (*rCandidate.mpViewInformation2D == *mpViewInformation2D);
} }
const basegfx::B2DHomMatrix& ViewInformation2D::getObjectTransformation() const const basegfx::B2DHomMatrix& ViewInformation2D::getObjectTransformation() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment