[Libreoffice-commits] core.git: drawinglayer/inc drawinglayer/source

Thomas Arnhold thomas at arnhold.org
Wed Apr 3 03:14:26 PDT 2013


 drawinglayer/inc/drawinglayer/geometry/viewinformation3d.hxx |    6 
 drawinglayer/source/geometry/viewinformation3d.cxx           |   80 ++---------
 2 files changed, 20 insertions(+), 66 deletions(-)

New commits:
commit 78bec2b6f40144277464a64a9851d1dc940ed336
Author: Thomas Arnhold <thomas at arnhold.org>
Date:   Wed Apr 3 12:12:57 2013 +0200

    fdo#62525: use cow_wrapper for ViewInformation3D
    
    Change-Id: I4f304febfedfa4a5a89d996fe276a9413d0ef855

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


More information about the Libreoffice-commits mailing list