Kaydet (Commit) 78bec2b6 authored tarafından Thomas Arnhold's avatar Thomas Arnhold

fdo#62525: use cow_wrapper for ViewInformation3D

Change-Id: I4f304febfedfa4a5a89d996fe276a9413d0ef855
üst 0c85109e
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <sal/config.h> #include <sal/config.h>
#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 <o3tl/cow_wrapper.hxx>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// predefines // predefines
...@@ -56,9 +57,12 @@ namespace drawinglayer ...@@ -56,9 +57,12 @@ namespace drawinglayer
*/ */
class DRAWINGLAYER_DLLPUBLIC ViewInformation3D class DRAWINGLAYER_DLLPUBLIC ViewInformation3D
{ {
public:
typedef o3tl::cow_wrapper< ImpViewInformation3D, o3tl::ThreadSafeRefCountingPolicy > ImplType;
private: private:
/// pointer to private implementation class /// pointer to private implementation class
ImpViewInformation3D* mpViewInformation3D; ImplType mpViewInformation3D;
public: public:
/** Constructor: Create a ViewInformation3D /** Constructor: Create a ViewInformation3D
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <com/sun/star/geometry/AffineMatrix3D.hpp> #include <com/sun/star/geometry/AffineMatrix3D.hpp>
#include <com/sun/star/geometry/RealRectangle3D.hpp> #include <com/sun/star/geometry/RealRectangle3D.hpp>
#include <basegfx/tools/canvastools.hxx> #include <basegfx/tools/canvastools.hxx>
#include <rtl/instance.hxx>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
...@@ -43,9 +44,6 @@ namespace drawinglayer ...@@ -43,9 +44,6 @@ namespace drawinglayer
// two memory regions for pairs of ViewInformation3D/ImpViewInformation3D // two memory regions for pairs of ViewInformation3D/ImpViewInformation3D
friend class ::drawinglayer::geometry::ViewInformation3D; friend class ::drawinglayer::geometry::ViewInformation3D;
// the refcounter. 0 means exclusively used
sal_uInt32 mnRefCount;
// the 3D transformations // the 3D transformations
// Object to World. This may change and being adapted when entering 3D transformation // Object to World. This may change and being adapted when entering 3D transformation
// groups // groups
...@@ -351,8 +349,7 @@ namespace drawinglayer ...@@ -351,8 +349,7 @@ namespace drawinglayer
const basegfx::B3DHomMatrix& rDeviceToView, const basegfx::B3DHomMatrix& rDeviceToView,
double fViewTime, double fViewTime,
const uno::Sequence< beans::PropertyValue >& rExtendedParameters) const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
: mnRefCount(0), : maObjectTransformation(rObjectTransformation),
maObjectTransformation(rObjectTransformation),
maOrientation(rOrientation), maOrientation(rOrientation),
maProjection(rProjection), maProjection(rProjection),
maDeviceToView(rDeviceToView), maDeviceToView(rDeviceToView),
...@@ -364,8 +361,7 @@ namespace drawinglayer ...@@ -364,8 +361,7 @@ namespace drawinglayer
} }
explicit ImpViewInformation3D(const uno::Sequence< beans::PropertyValue >& rViewParameters) explicit ImpViewInformation3D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
: mnRefCount(0), : maObjectTransformation(),
maObjectTransformation(),
maOrientation(), maOrientation(),
maProjection(), maProjection(),
maDeviceToView(), maDeviceToView(),
...@@ -377,8 +373,7 @@ namespace drawinglayer ...@@ -377,8 +373,7 @@ namespace drawinglayer
} }
ImpViewInformation3D() ImpViewInformation3D()
: mnRefCount(0), : maObjectTransformation(),
maObjectTransformation(),
maOrientation(), maOrientation(),
maProjection(), maProjection(),
maDeviceToView(), maDeviceToView(),
...@@ -433,21 +428,6 @@ namespace drawinglayer ...@@ -433,21 +428,6 @@ namespace drawinglayer
&& mfViewTime == rCandidate.mfViewTime && mfViewTime == rCandidate.mfViewTime
&& mxExtendedInformation == rCandidate.mxExtendedInformation); && mxExtendedInformation == rCandidate.mxExtendedInformation);
} }
static ImpViewInformation3D* get_global_default()
{
static ImpViewInformation3D* pDefault = 0;
if(!pDefault)
{
pDefault = new ImpViewInformation3D();
// 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
...@@ -458,6 +438,12 @@ namespace drawinglayer ...@@ -458,6 +438,12 @@ namespace drawinglayer
{ {
namespace geometry namespace geometry
{ {
namespace
{
struct theGlobalDefault :
public rtl::Static< ViewInformation3D::ImplType, theGlobalDefault > {};
}
ViewInformation3D::ViewInformation3D( ViewInformation3D::ViewInformation3D(
const basegfx::B3DHomMatrix& rObjectObjectTransformation, const basegfx::B3DHomMatrix& rObjectObjectTransformation,
const basegfx::B3DHomMatrix& rOrientation, const basegfx::B3DHomMatrix& rOrientation,
...@@ -465,81 +451,45 @@ namespace drawinglayer ...@@ -465,81 +451,45 @@ namespace drawinglayer
const basegfx::B3DHomMatrix& rDeviceToView, const basegfx::B3DHomMatrix& rDeviceToView,
double fViewTime, double fViewTime,
const uno::Sequence< beans::PropertyValue >& rExtendedParameters) const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
: mpViewInformation3D(new ImpViewInformation3D( : mpViewInformation3D(ImpViewInformation3D(
rObjectObjectTransformation, rOrientation, rProjection, rObjectObjectTransformation, rOrientation, rProjection,
rDeviceToView, fViewTime, rExtendedParameters)) rDeviceToView, fViewTime, rExtendedParameters))
{ {
} }
ViewInformation3D::ViewInformation3D(const uno::Sequence< beans::PropertyValue >& rViewParameters) ViewInformation3D::ViewInformation3D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
: mpViewInformation3D(new ImpViewInformation3D(rViewParameters)) : mpViewInformation3D(ImpViewInformation3D(rViewParameters))
{ {
} }
ViewInformation3D::ViewInformation3D() ViewInformation3D::ViewInformation3D()
: mpViewInformation3D(ImpViewInformation3D::get_global_default()) : mpViewInformation3D(theGlobalDefault::get())
{ {
mpViewInformation3D->mnRefCount++;
} }
ViewInformation3D::ViewInformation3D(const ViewInformation3D& rCandidate) ViewInformation3D::ViewInformation3D(const ViewInformation3D& rCandidate)
: mpViewInformation3D(rCandidate.mpViewInformation3D) : mpViewInformation3D(rCandidate.mpViewInformation3D)
{ {
::osl::Mutex m_mutex;
mpViewInformation3D->mnRefCount++;
} }
ViewInformation3D::~ViewInformation3D() ViewInformation3D::~ViewInformation3D()
{ {
::osl::Mutex m_mutex;
if(mpViewInformation3D->mnRefCount)
{
mpViewInformation3D->mnRefCount--;
}
else
{
delete mpViewInformation3D;
}
} }
bool ViewInformation3D::isDefault() const bool ViewInformation3D::isDefault() const
{ {
return mpViewInformation3D == ImpViewInformation3D::get_global_default(); return mpViewInformation3D.same_object(theGlobalDefault::get());
} }
ViewInformation3D& ViewInformation3D::operator=(const ViewInformation3D& rCandidate) ViewInformation3D& ViewInformation3D::operator=(const ViewInformation3D& rCandidate)
{ {
::osl::Mutex m_mutex;
if(mpViewInformation3D->mnRefCount)
{
mpViewInformation3D->mnRefCount--;
}
else
{
delete mpViewInformation3D;
}
mpViewInformation3D = rCandidate.mpViewInformation3D; mpViewInformation3D = rCandidate.mpViewInformation3D;
mpViewInformation3D->mnRefCount++;
return *this; return *this;
} }
bool ViewInformation3D::operator==(const ViewInformation3D& rCandidate) const bool ViewInformation3D::operator==(const ViewInformation3D& rCandidate) const
{ {
if(rCandidate.mpViewInformation3D == mpViewInformation3D) return rCandidate.mpViewInformation3D == mpViewInformation3D;
{
return true;
}
if(rCandidate.isDefault() != isDefault())
{
return false;
}
return (*rCandidate.mpViewInformation3D == *mpViewInformation3D);
} }
const basegfx::B3DHomMatrix& ViewInformation3D::getObjectTransformation() const const basegfx::B3DHomMatrix& ViewInformation3D::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