[Libreoffice-commits] .: Branch 'feature/gtk3' - 2 commits - vcl/generic vcl/headless vcl/inc vcl/Library_vcl.mk vcl/Module_vcl.mk vcl/unx

Michael Meeks michael at kemper.freedesktop.org
Fri Sep 30 09:19:43 PDT 2011


 vcl/Library_vcl.mk              |    1 
 vcl/Module_vcl.mk               |    2 
 vcl/generic/app/gendisp.cxx     |  155 ++++++++++++++++++++++++++++++++++++++++
 vcl/headless/svpinst.cxx        |   93 ------------------------
 vcl/inc/generic/gendisp.hxx     |   89 ++++++++++++++++++++++
 vcl/inc/headless/svpinst.hxx    |   30 -------
 vcl/inc/unx/gtk/gtkdata.hxx     |   34 --------
 vcl/inc/unx/gtk/gtkinst.hxx     |    7 -
 vcl/inc/unx/saldisp.hxx         |   46 ++---------
 vcl/unx/generic/app/saldisp.cxx |  125 +-------------------------------
 vcl/unx/gtk/app/gtkdata.cxx     |  134 +++++-----------------------------
 vcl/unx/gtk/app/gtkinst.cxx     |   52 -------------
 12 files changed, 294 insertions(+), 474 deletions(-)

New commits:
commit 7e37c2b6e7129ee84dd0e6777c7b17a50e9fa59a
Author: Michael Meeks <michael.meeks at suse.com>
Date:   Fri Sep 30 17:04:17 2011 +0100

    generic: factor out generic display code, reducing cut+paste+bug

diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 0e884a1..2c1d326 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -266,6 +266,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/window/wrkwin \
     vcl/generic/app/gensys \
     vcl/generic/app/geninst \
+    vcl/generic/app/gendisp \
     vcl/generic/print/bitmap_gfx \
     vcl/generic/print/common_gfx \
     vcl/generic/print/glyphset \
diff --git a/vcl/generic/app/gendisp.cxx b/vcl/generic/app/gendisp.cxx
new file mode 100644
index 0000000..e22835b
--- /dev/null
+++ b/vcl/generic/app/gendisp.cxx
@@ -0,0 +1,155 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_vcl.hxx"
+
+#include <salframe.hxx>
+#include <generic/gendisp.hxx>
+#include <generic/geninst.h>
+
+using ::rtl::OUString;
+
+SalGenericDisplay::SalGenericDisplay()
+{
+    m_pCapture = NULL;
+    m_aEventGuard = osl_createMutex();
+}
+
+SalGenericDisplay::~SalGenericDisplay()
+{
+    if (m_aEventGuard)
+        osl_destroyMutex( m_aEventGuard );
+    m_aEventGuard = NULL;
+}
+
+void SalGenericDisplay::registerFrame( SalFrame* pFrame )
+{
+    m_aFrames.push_front( pFrame );
+}
+
+void SalGenericDisplay::deregisterFrame( SalFrame* pFrame )
+{
+    if( osl_acquireMutex( m_aEventGuard ) )
+    {
+        std::list< SalUserEvent >::iterator it = m_aUserEvents.begin();
+        while ( it != m_aUserEvents.end() )
+        {
+            if( it->m_pFrame == pFrame )
+                it = m_aUserEvents.erase( it );
+            else
+                ++it;
+        }
+        osl_releaseMutex( m_aEventGuard );
+    }
+    else
+        OSL_FAIL( "SalGenericDisplay::deregisterFrame !acquireMutex\n" );
+
+    m_aFrames.remove( pFrame );
+}
+
+bool SalGenericDisplay::DispatchInternalEvent()
+{
+    void* pData = NULL;
+    SalFrame* pFrame = NULL;
+    sal_uInt16 nEvent = 0;
+
+    if( osl_acquireMutex( m_aEventGuard ) )
+    {
+        if( m_aUserEvents.begin() != m_aUserEvents.end() )
+        {
+            pFrame	= m_aUserEvents.front().m_pFrame;
+            pData	= m_aUserEvents.front().m_pData;
+            nEvent	= m_aUserEvents.front().m_nEvent;
+
+            m_aUserEvents.pop_front();
+        }
+        osl_releaseMutex( m_aEventGuard );
+    }
+    else
+        OSL_FAIL( "SalGenericDisplay::Yield !acquireMutex\n" );
+
+    if( pFrame )
+        pFrame->CallCallback( nEvent, pData );
+
+    return pFrame != NULL;
+}
+
+void SalGenericDisplay::SendInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
+{
+    if( osl_acquireMutex( m_aEventGuard ) )
+    {
+        m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) );
+
+        PostUserEvent(); // wakeup the concrete mainloop
+
+        osl_releaseMutex( m_aEventGuard );
+    }
+    else
+        OSL_FAIL( "SalGenericDisplay::SendInternalEvent !acquireMutex\n" );
+}
+
+void SalGenericDisplay::CancelInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
+{
+    if( osl_acquireMutex( m_aEventGuard ) )
+    {
+        if( ! m_aUserEvents.empty() )
+        {
+            std::list< SalUserEvent >::iterator it, next;
+            next = m_aUserEvents.begin();
+            do
+            {
+                it = next++;
+                if( it->m_pFrame    == pFrame   &&
+                    it->m_pData     == pData    &&
+                    it->m_nEvent    == nEvent )
+                {
+                    m_aUserEvents.erase( it );
+                }
+            } while( next != m_aUserEvents.end() );
+        }
+
+        osl_releaseMutex( m_aEventGuard );
+    }
+    else
+        OSL_FAIL( "SalGenericDisplay::CancelInternalEvent !acquireMutex\n" );
+}
+
+bool SalGenericDisplay::HasUserEvents() const
+{
+    bool bRet = false;
+    if( osl_acquireMutex( m_aEventGuard ) )
+    {
+        if( m_aUserEvents.begin() != m_aUserEvents.end() )
+            bRet = true;
+        osl_releaseMutex( m_aEventGuard );
+    }
+    return bRet;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/generic/gendisp.hxx b/vcl/inc/generic/gendisp.hxx
new file mode 100644
index 0000000..e088be8
--- /dev/null
+++ b/vcl/inc/generic/gendisp.hxx
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _VCL_GEN_DISP_HXX
+#define _VCL_GEN_DISP_HXX
+
+#include <sal/types.h>
+#include <osl/mutex.h>
+#include <osl/conditn.hxx>
+#include <salwtype.hxx>
+#include <vcl/dllapi.h>
+#include <tools/gen.hxx>
+#include <list>
+#include <vector>
+
+class SalFrame;
+class VCL_DLLPUBLIC SalGenericDisplay
+{
+    oslMutex m_aEventGuard;
+    struct SalUserEvent
+    {
+        SalFrame*  m_pFrame;
+        void*      m_pData;
+        sal_uInt16 m_nEvent;
+
+        SalUserEvent( SalFrame* pFrame, void* pData,
+                      sal_uInt16 nEvent )
+                : m_pFrame( pFrame ),
+                  m_pData( pData ),
+                  m_nEvent( nEvent )
+        {}
+    };
+    std::list< SalUserEvent > m_aUserEvents;
+protected:
+    SalFrame* m_pCapture;
+    std::list<SalFrame*> m_aFrames;
+public:
+                 SalGenericDisplay();
+    virtual      ~SalGenericDisplay();
+
+    inline void  EventGuardAcquire() { osl_acquireMutex( m_aEventGuard ); }
+    inline void  EventGuardRelease() { osl_releaseMutex( m_aEventGuard ); }
+
+    virtual void registerFrame( SalFrame* pFrame );
+    virtual void deregisterFrame( SalFrame* pFrame );
+
+    // Event handling
+    virtual void PostUserEvent() = 0;
+
+    virtual void SendInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent = SALEVENT_USEREVENT );
+    virtual void CancelInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent );
+    virtual bool DispatchInternalEvent();
+    bool         HasUserEvents() const;
+
+    sal_Bool     MouseCaptured( const SalFrame *pFrameData ) const
+                        { return m_pCapture == pFrameData; }
+    SalFrame*    GetCaptureFrame() const
+                        { return m_pCapture; }
+
+};
+
+#endif // _VCL_GEN_DISP_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/unx/gtk/gtkdata.hxx b/vcl/inc/unx/gtk/gtkdata.hxx
index 22491f4..b242852 100644
--- a/vcl/inc/unx/gtk/gtkdata.hxx
+++ b/vcl/inc/unx/gtk/gtkdata.hxx
@@ -109,7 +109,7 @@ public:
 
     static gboolean userEventFn( gpointer data );
 
-    void PostUserEvent();
+    virtual void PostUserEvent();
     void Yield( bool bWait, bool bHandleAllCurrentEvents );
     GtkSalDisplay *GetDisplay() { return m_pGtkSalDisplay; }
     inline GdkDisplay *GetGdkDisplay();
@@ -121,7 +121,7 @@ inline GtkData* GetGtkSalData()
 class GtkSalFrame;
 
 #if GTK_CHECK_VERSION(3,0,0)
-class GtkSalDisplay
+class GtkSalDisplay : public SalGenericDisplay
 #else
 class GtkSalDisplay : public SalDisplay
 #endif
@@ -139,7 +139,6 @@ public:
 
     GdkDisplay* GetGdkDisplay() const { return m_pGdkDisplay; }
 
-    virtual void registerFrame( SalFrame* pFrame );
     virtual void deregisterFrame( SalFrame* pFrame );
     GdkCursor *getCursor( PointerStyle ePointerStyle );
     virtual int CaptureMouse( SalFrame* pFrame );
@@ -160,38 +159,11 @@ public:
     void errorTrapPush();
     void errorTrapPop();
 
-    inline bool HasMoreEvents()     { return m_aUserEvents.size() > 1; }
-    inline void EventGuardAcquire() { osl_acquireMutex( hEventGuard_ ); }
-    inline void EventGuardRelease() { osl_releaseMutex( hEventGuard_ ); }
+    virtual void PostUserEvent();
 
 #if !GTK_CHECK_VERSION(3,0,0)
     virtual long Dispatch( XEvent *pEvent );
 #else
-    void  SendInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent = SALEVENT_USEREVENT );
-    void  CancelInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent );
-    bool  DispatchInternalEvent();
-
-    SalFrame *m_pCapture;
-    sal_Bool MouseCaptured( const SalFrame *pFrameData ) const
-    { return m_pCapture == pFrameData; }
-    SalFrame*	GetCaptureFrame() const
-    { return m_pCapture; }
-
-    struct SalUserEvent
-    {
-        SalFrame*		m_pFrame;
-        void*			m_pData;
-        sal_uInt16			m_nEvent;
-
-        SalUserEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent = SALEVENT_USEREVENT )
-                : m_pFrame( pFrame ),
-                  m_pData( pData ),
-                  m_nEvent( nEvent )
-        {}
-    };
-
-    oslMutex        hEventGuard_;
-    std::list< SalUserEvent > m_aUserEvents;
     guint32 GetLastUserEventTime( bool /* b */ ) { return GDK_CURRENT_TIME; } // horrible hack
 #endif
 };
diff --git a/vcl/inc/unx/saldisp.hxx b/vcl/inc/unx/saldisp.hxx
index 6aefeff..2a0a1e8 100644
--- a/vcl/inc/unx/saldisp.hxx
+++ b/vcl/inc/unx/saldisp.hxx
@@ -46,6 +46,7 @@ class   SalXLib;
 #include <boost/unordered_map.hpp>
 #include <tools/gen.hxx>
 #include <salwtype.hxx>
+#include <generic/gendisp.hxx>
 
 #include <vclpluginapi.h>
 
@@ -222,11 +223,11 @@ protected:
 public:
     SalXLib();
     virtual         ~SalXLib();
-    virtual void        Init();
+    virtual void    Init();
 
-    virtual void        Yield( bool bWait, bool bHandleAllCurrentEvents );
-    virtual void        Wakeup();
-    virtual void        PostUserEvent();
+    virtual void    Yield( bool bWait, bool bHandleAllCurrentEvents );
+    virtual void    Wakeup();
+    virtual void    PostUserEvent();
 
     virtual void    Insert( int fd, void* data,
                             YieldFunc   pending,
@@ -266,7 +267,7 @@ extern "C" {
     typedef Bool(*X_if_predicate)(Display*,XEvent*,XPointer);
 }
 
-class VCLPLUG_GEN_PUBLIC SalDisplay
+class VCLPLUG_GEN_PUBLIC SalDisplay : public SalGenericDisplay
 {
 public:
     struct RenderEntry
@@ -311,19 +312,6 @@ public:
         m_aRenderData( 1 )
         {}
     };
-// -=-= UserEvent =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-    struct SalUserEvent
-    {
-        SalFrame*       m_pFrame;
-        void*           m_pData;
-        sal_uInt16          m_nEvent;
-
-        SalUserEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent = SALEVENT_USEREVENT )
-                : m_pFrame( pFrame ),
-                  m_pData( pData ),
-                  m_nEvent( nEvent )
-        {}
-    };
 
 protected:
     SalXLib        *pXLib_;
@@ -338,7 +326,7 @@ protected:
     ScreenData      m_aInvalidScreenData;
     Pair            aResolution_;       // [dpi]
     bool            mbExactResolution;
-    sal_uLong           nMaxRequestSize_;   // [byte]
+    sal_uLong       nMaxRequestSize_;   // [byte]
 
     srv_vendor_t    meServerVendor;
     SalWM           eWindowManager_;
@@ -347,14 +335,10 @@ protected:
     sal_Bool            mbLocalIsValid;     // bLocal_ is valid ?
     // until x bytes
 
-    oslMutex        hEventGuard_;
-    std::list< SalUserEvent > m_aUserEvents;
-
     XLIB_Cursor     aPointerCache_[POINTER_COUNT];
-    SalFrame*       m_pCapture;
 
     // Keyboard
-    sal_Bool            bNumLockFromXS_;    // Num Lock handled by X Server
+    sal_Bool        bNumLockFromXS_;    // Num Lock handled by X Server
     int             nNumLockIndex_;     // modifier index in modmap
     int             nNumLockMask_;      // keyevent state mask for
     KeySym          nShiftKeySym_;      // first shift modifier
@@ -392,19 +376,12 @@ public:
 
     virtual ~SalDisplay();
 
-
-    virtual void            registerFrame( SalFrame* pFrame );
-    virtual void            deregisterFrame( SalFrame* pFrame );
     void                    setHaveSystemChildFrame() const
     { pXLib_->setHaveSystemChildFrame(); }
     bool                    getHaveSystemChildFrame() const
     { return pXLib_->getHaveSystemChildFrame(); }
 
     void            Init();
-
-    void            SendInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent = SALEVENT_USEREVENT );
-    void            CancelInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent );
-    bool            DispatchInternalEvent();
     void            PrintInfo() const;
 
 #ifdef DBG_UTIL
@@ -468,11 +445,6 @@ public:
     XLIB_Time       GetLastUserEventTime( bool bAlwaysReget = false ) const;
 
     bool            XIfEventWithTimeout( XEvent*, XPointer, X_if_predicate, long i_nTimeout = 1000 ) const;
-
-    sal_Bool            MouseCaptured( const SalFrame *pFrameData ) const
-    { return m_pCapture == pFrameData; }
-    SalFrame*   GetCaptureFrame() const
-    { return m_pCapture; }
     SalXLib*         GetXLib() const { return pXLib_; }
 
     SalI18N_InputMethod*            GetInputMethod()  const { return mpInputMethod;  }
@@ -497,6 +469,8 @@ public:
     sal_Bool            IsNumLockFromXS() const { return bNumLockFromXS_; }
 
     std::list< SalObject* >& getSalObjects() { return m_aSalObjects; }
+
+    virtual void    PostUserEvent();
 };
 
 // -=-= inlines =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
diff --git a/vcl/unx/generic/app/saldisp.cxx b/vcl/unx/generic/app/saldisp.cxx
index b63cfb9..d1b1e56 100644
--- a/vcl/unx/generic/app/saldisp.cxx
+++ b/vcl/unx/generic/app/saldisp.cxx
@@ -537,10 +537,6 @@ void SalDisplay::doDestruct()
         delete mpInputMethod, mpInputMethod = (SalI18N_InputMethod*)ILLEGAL_POINTER;
         delete mpKbdExtension, mpKbdExtension = (SalI18N_KeyboardExtension*)ILLEGAL_POINTER;
 
-        // do not call anything that could implicitly call back into
-        // this object after this point
-        osl_destroyMutex( hEventGuard_ );
-
         for( unsigned int i = 0; i < m_aScreens.size(); i++ )
         {
             ScreenData& rData = m_aScreens[i];
@@ -561,8 +557,6 @@ void SalDisplay::doDestruct()
             }
         }
 
-        hEventGuard_            = (oslMutex)ILLEGAL_POINTER;
-
         for( size_t i = 0; i < POINTER_COUNT; i++ )
         {
             if( aPointerCache_[i] )
@@ -780,9 +774,7 @@ void SalDisplay::Init()
         aPointerCache_[i] = None;
 
     eWindowManager_     = otherwm;
-    hEventGuard_        = NULL;
     mpFactory           = (AttributeProvider*)NULL;
-    m_pCapture          = NULL;
     m_bXinerama         = false;
 
     int nDisplayScreens = ScreenCount( pDisp_ );
@@ -819,7 +811,6 @@ void SalDisplay::Init()
     SetServerVendor();
     X11SalBitmap::ImplCreateCache();
 
-    hEventGuard_    = osl_createMutex();
     bLocal_         = sal_False; /* dont care, initialize later by
                                 calling SalDisplay::IsLocal() */
     mbLocalIsValid  = sal_False; /* bLocal_ is not yet initialized */
@@ -2064,97 +2055,15 @@ int SalDisplay::CaptureMouse( SalFrame *pCapture )
 // Events
 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-void SalDisplay::SendInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
-{
-    if( osl_acquireMutex( hEventGuard_ ) )
-    {
-        m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) );
-
-        // Notify SalXLib::Yield() of a pending event.
-        pXLib_->PostUserEvent();
-
-        osl_releaseMutex( hEventGuard_ );
-    }
-    else {
-        DBG_ASSERT( 1, "SalDisplay::SendInternalEvent !acquireMutex\n" );
-    }
-}
-
-void SalDisplay::CancelInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
-{
-    if( osl_acquireMutex( hEventGuard_ ) )
-    {
-        if( ! m_aUserEvents.empty() )
-        {
-            std::list< SalUserEvent >::iterator it, next;
-            next = m_aUserEvents.begin();
-            do
-            {
-                it = next++;
-                if( it->m_pFrame    == pFrame   &&
-                    it->m_pData     == pData    &&
-                    it->m_nEvent    == nEvent )
-                {
-                    m_aUserEvents.erase( it );
-                }
-            } while( next != m_aUserEvents.end() );
-        }
-
-        osl_releaseMutex( hEventGuard_ );
-    }
-    else {
-        DBG_ASSERT( 1, "SalDisplay::CancelInternalEvent !acquireMutex\n" );
-    }
-}
-
 sal_Bool SalX11Display::IsEvent()
 {
-    sal_Bool bRet = sal_False;
-
-    if( osl_acquireMutex( hEventGuard_ ) )
-    {
-        if( m_aUserEvents.begin() != m_aUserEvents.end() )
-            bRet = sal_True;
-        osl_releaseMutex( hEventGuard_ );
-    }
-
-    if( bRet || XEventsQueued( pDisp_, QueuedAlready ) )
+    if( HasUserEvents() || XEventsQueued( pDisp_, QueuedAlready ) )
         return sal_True;
 
     XFlush( pDisp_ );
     return sal_False;
 }
 
-bool SalDisplay::DispatchInternalEvent()
-{
-    SalFrame* pFrame = NULL;
-    void* pData = NULL;
-    sal_uInt16 nEvent = 0;
-
-    if( osl_acquireMutex( hEventGuard_ ) )
-    {
-        if( m_aUserEvents.begin() != m_aUserEvents.end() )
-        {
-            pFrame  = m_aUserEvents.front().m_pFrame;
-            pData   = m_aUserEvents.front().m_pData;
-            nEvent  = m_aUserEvents.front().m_nEvent;
-
-            m_aUserEvents.pop_front();
-        }
-        osl_releaseMutex( hEventGuard_ );
-    }
-    else {
-        DBG_ASSERT( 1, "SalDisplay::Yield !acquireMutex\n" );
-    }
-
-    if( pFrame )
-        pFrame->CallCallback( nEvent, pData );
-
-    return pFrame != NULL;
-}
-
-// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
 void SalX11Display::Yield()
 {
     if( DispatchInternalEvent() )
@@ -2581,32 +2490,6 @@ if( XineramaIsActive( pDisp_ ) )
 #endif // USE_XINERAMA
 }
 
-void SalDisplay::registerFrame( SalFrame* pFrame )
-{
-    m_aFrames.push_front( pFrame );
-}
-
-void SalDisplay::deregisterFrame( SalFrame* pFrame )
-{
-    if( osl_acquireMutex( hEventGuard_ ) )
-    {
-        std::list< SalUserEvent >::iterator it = m_aUserEvents.begin();
-        while ( it != m_aUserEvents.end() )
-        {
-            if( it->m_pFrame == pFrame )
-                it = m_aUserEvents.erase( it );
-            else
-                ++it;
-        }
-        osl_releaseMutex( hEventGuard_ );
-    }
-    else {
-        OSL_FAIL( "SalDisplay::deregisterFrame !acquireMutex\n" );
-    }
-
-    m_aFrames.remove( pFrame );
-}
-
 
 extern "C"
 {
@@ -3260,4 +3143,10 @@ Pixel SalColormap::GetPixel( SalColor nSalColor ) const
                          +  ((b+8)/17) ];
 }
 
+void SalDisplay::PostUserEvent()
+{
+    if( pXLib_ )
+        pXLib_->PostUserEvent();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/gtk/app/gtkdata.cxx b/vcl/unx/gtk/app/gtkdata.cxx
index 9132fef..df666c7 100644
--- a/vcl/unx/gtk/app/gtkdata.cxx
+++ b/vcl/unx/gtk/app/gtkdata.cxx
@@ -91,13 +91,9 @@ GtkSalDisplay::GtkSalDisplay( GdkDisplay* pDisplay ) :
 {
     for(int i = 0; i < POINTER_COUNT; i++)
         m_aCursors[ i ] = NULL;
-#if GTK_CHECK_VERSION(3,0,0)
-    m_pCapture = NULL;
-    hEventGuard_ = osl_createMutex();
-#else
+#if !GTK_CHECK_VERSION(3,0,0)
     m_bUseRandRWrapper = false; // use gdk signal instead
     Init ();
-    hEventGuard_ = NULL;
 #endif
 
     gdk_window_add_filter( NULL, call_filterGdkEvent, this );
@@ -121,10 +117,6 @@ GtkSalDisplay::~GtkSalDisplay()
     for(int i = 0; i < POINTER_COUNT; i++)
         if( m_aCursors[ i ] )
             gdk_cursor_unref( m_aCursors[ i ] );
-
-    if (hEventGuard_)
-        osl_destroyMutex( hEventGuard_ );
-    hEventGuard_ = NULL;
 }
 
 void GtkSalDisplay::errorTrapPush()
@@ -141,25 +133,6 @@ void GtkSalDisplay::errorTrapPop()
 #endif
 }
 
-void GtkSalDisplay::registerFrame( SalFrame* pFrame )
-{
-#if !GTK_CHECK_VERSION(3,0,0)
-    SalDisplay::registerFrame( pFrame );
-#endif
-}
-
-void GtkSalDisplay::deregisterFrame( SalFrame* pFrame )
-{
-    if( m_pCapture == pFrame )
-    {
-        static_cast<GtkSalFrame*>(m_pCapture)->grabPointer( FALSE );
-        m_pCapture = NULL;
-    }
-#if !GTK_CHECK_VERSION(3,0,0)
-    SalDisplay::deregisterFrame( pFrame );
-#endif
-}
-
 extern "C" {
 
 void signalKeysChanged( GdkKeymap*, gpointer data )
@@ -610,7 +583,7 @@ void GtkData::Yield( bool bWait, bool bHandleAllCurrentEvents )
      * fits the vcl event model (see e.g. the generic plugin).
      */
     bool bDispatchThread = false;
-    gboolean wasEvent = FALSE;
+    bool bWasEvent = false;
     {
         // release YieldMutex (and re-acquire at block end)
         YieldMutexReleaser aReleaser;
@@ -619,7 +592,6 @@ void GtkData::Yield( bool bWait, bool bHandleAllCurrentEvents )
         else if( ! bWait )
             return; // someone else is waiting already, return
 
-
         if( bDispatchThread )
         {
             int nMaxEvents = bHandleAllCurrentEvents ? 100 : 1;
@@ -628,13 +600,13 @@ void GtkData::Yield( bool bWait, bool bHandleAllCurrentEvents )
             {
                 wasOneEvent = g_main_context_iteration( NULL, FALSE );
                 if( wasOneEvent )
-                    wasEvent = TRUE;
+                    bWasEvent = true;
             }
-            if( bWait && ! wasEvent )
-                wasEvent = g_main_context_iteration( NULL, TRUE );
+            if( bWait && ! bWasEvent )
+                bWasEvent = g_main_context_iteration( NULL, TRUE ) != 0;
         }
         else if( bWait )
-           {
+        {
             /* #i41693# in case the dispatch thread hangs in join
              * for this thread the condition will never be set
              * workaround: timeout of 1 second a emergency exit
@@ -649,7 +621,7 @@ void GtkData::Yield( bool bWait, bool bHandleAllCurrentEvents )
     if( bDispatchThread )
     {
         osl_releaseMutex( m_aDispatchMutex );
-        if( wasEvent )
+        if( bWasEvent )
             osl_setCondition( m_aDispatchCondition ); // trigger non dispatch thread yields
     }
 }
@@ -858,7 +830,7 @@ gboolean GtkData::userEventFn( gpointer data )
 #endif
         pThis->m_pGtkSalDisplay->EventGuardAcquire();
 
-        if( !pThis->m_pGtkSalDisplay->HasMoreEvents() )
+        if( !pThis->m_pGtkSalDisplay->HasUserEvents() )
         {
             if( pThis->m_pUserEvent )
             {
@@ -878,81 +850,6 @@ gboolean GtkData::userEventFn( gpointer data )
     return bContinue;
 }
 
-#if GTK_CHECK_VERSION(3,0,0)
-
-// FIXME: cut/paste from saldisp.cxx - needs some re-factoring love
-bool GtkSalDisplay::DispatchInternalEvent()
-{
-    SalFrame* pFrame = NULL;
-    void* pData = NULL;
-    sal_uInt16 nEvent = 0;
-
-    if( osl_acquireMutex( hEventGuard_ ) )
-    {
-        if( m_aUserEvents.begin() != m_aUserEvents.end() )
-        {
-            pFrame	= m_aUserEvents.front().m_pFrame;
-            pData	= m_aUserEvents.front().m_pData;
-            nEvent	= m_aUserEvents.front().m_nEvent;
-
-            m_aUserEvents.pop_front();
-        }
-        osl_releaseMutex( hEventGuard_ );
-    }
-    else {
-        DBG_ASSERT( 1, "SalDisplay::Yield !acquireMutex\n" );
-    }
-
-    if( pFrame )
-        pFrame->CallCallback( nEvent, pData );
-
-    return pFrame != NULL;
-}
-
-void GtkSalDisplay::SendInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
-{
-    if( osl_acquireMutex( hEventGuard_ ) )
-    {
-        m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) );
-
-        // Notify GtkData::Yield() of a pending event.
-        GetGtkSalData()->PostUserEvent();
-
-        osl_releaseMutex( hEventGuard_ );
-    }
-    else {
-        DBG_ASSERT( 1, "SalDisplay::SendInternalEvent !acquireMutex\n" );
-    }
-}
-
-void GtkSalDisplay::CancelInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
-{
-    if( osl_acquireMutex( hEventGuard_ ) )
-    {
-        if( ! m_aUserEvents.empty() )
-        {
-            std::list< SalUserEvent >::iterator it, next;
-            next = m_aUserEvents.begin();
-            do
-            {
-                it = next++;
-                if( it->m_pFrame    == pFrame   &&
-                    it->m_pData     == pData    &&
-                    it->m_nEvent    == nEvent )
-                {
-                    m_aUserEvents.erase( it );
-                }
-            } while( next != m_aUserEvents.end() );
-        }
-
-        osl_releaseMutex( hEventGuard_ );
-    }
-    else
-        DBG_ASSERT( 1, "SalDisplay::CancelInternalEvent !acquireMutex\n" );
-}
-
-#endif
-
 extern "C" {
     static gboolean call_userEventFn( void *data )
     {
@@ -976,4 +873,19 @@ void GtkData::PostUserEvent()
     }
 }
 
+void GtkSalDisplay::PostUserEvent()
+{
+    GetGtkSalData()->PostUserEvent();
+}
+
+void GtkSalDisplay::deregisterFrame( SalFrame* pFrame )
+{
+    if( m_pCapture == pFrame )
+    {
+        static_cast<GtkSalFrame*>(m_pCapture)->grabPointer( FALSE );
+        m_pCapture = NULL;
+    }
+    SalGenericDisplay::deregisterFrame( pFrame );
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit af151f2de22773d00cf6f1784e21c5667bec2652
Author: Michael Meeks <michael.meeks at suse.com>
Date:   Fri Sep 30 15:46:24 2011 +0100

    generic: share sal yield mutex properly

diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 9985987..0a91f87 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -31,7 +31,6 @@ $(eval $(call gb_Module_Module,vcl))
 
 $(eval $(call gb_Module_add_targets,vcl,\
     Library_vcl \
-    Library_vclplug_svp \
     StaticLibrary_vclmain \
     Package_inc \
 	Package_afmhash \
@@ -40,6 +39,7 @@ $(eval $(call gb_Module_add_targets,vcl,\
 
 ifeq ($(GUIBASE),unx)
 $(eval $(call gb_Module_add_targets,vcl,\
+    Library_vclplug_svp \
     Library_vclplug_gen \
     Library_desktop_detector \
 ))
diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx
index 182cf86..b3e8683 100644
--- a/vcl/headless/svpinst.cxx
+++ b/vcl/headless/svpinst.cxx
@@ -53,7 +53,7 @@ extern "C"
 {
     SAL_DLLPUBLIC_EXPORT SalInstance* create_SalInstance()
     {
-        SvpSalInstance* pInstance = new SvpSalInstance();
+        SvpSalInstance* pInstance = new SvpSalInstance( new SalYieldMutex() );
         SalData* pSalData = new SalData();
         pSalData->m_pInstance = pInstance;
         SetSalData( pSalData );
@@ -77,8 +77,8 @@ bool SvpSalInstance::isFrameAlive( const SalFrame* pFrame ) const
 
 SvpSalInstance* SvpSalInstance::s_pDefaultInstance = NULL;
 
-SvpSalInstance::SvpSalInstance() :
-    SalGenericInstance( new SalYieldMutex() )
+SvpSalInstance::SvpSalInstance( SalYieldMutex *pMutex ) :
+    SalGenericInstance( pMutex )
 {
     m_aTimeout.tv_sec       = 0;
     m_aTimeout.tv_usec      = 0;
@@ -304,51 +304,6 @@ SalBitmap* SvpSalInstance::CreateSalBitmap()
     return new SvpSalBitmap();
 }
 
-osl::SolarMutex* SvpSalInstance::GetYieldMutex()
-{
-    return &m_aYieldMutex;
-}
-
-sal_uLong SvpSalInstance::ReleaseYieldMutex()
-{
-    if ( m_aYieldMutex.GetThreadId() ==
-         osl::Thread::getCurrentIdentifier() )
-    {
-        sal_uLong nCount = m_aYieldMutex.GetAcquireCount();
-        sal_uLong n = nCount;
-        while ( n )
-        {
-            m_aYieldMutex.release();
-            n--;
-        }
-
-        return nCount;
-    }
-    else
-        return 0;
-}
-
-void SvpSalInstance::AcquireYieldMutex( sal_uLong nCount )
-{
-    while ( nCount )
-    {
-        m_aYieldMutex.acquire();
-        nCount--;
-    }
-}
-
-bool SvpSalInstance::CheckYieldMutex()
-{
-    bool bRet = true;
-
-    if ( m_aYieldMutex.GetThreadId() != ::osl::Thread::getCurrentIdentifier() )
-    {
-        bRet = false;
-    }
-
-    return bRet;
-}
-
 void SvpSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
 {
     // first, check for already queued events.
@@ -453,48 +408,6 @@ void* SvpSalInstance::GetConnectionIdentifier( ConnectionIdentifierType& rReturn
     return const_cast<char*>("");
 }
 
-// -------------------------------------------------------------------------
-//
-// SalYieldMutex
-//
-// -------------------------------------------------------------------------
-
-SvpSalYieldMutex::SvpSalYieldMutex()
-{
-    mnCount     = 0;
-    mnThreadId  = 0;
-}
-
-void SvpSalYieldMutex::acquire()
-{
-    SolarMutexObject::acquire();
-    mnThreadId = osl::Thread::getCurrentIdentifier();
-    mnCount++;
-}
-
-void SvpSalYieldMutex::release()
-{
-    if ( mnThreadId == osl::Thread::getCurrentIdentifier() )
-    {
-        if ( mnCount == 1 )
-            mnThreadId = 0;
-        mnCount--;
-    }
-    SolarMutexObject::release();
-}
-
-sal_Bool SvpSalYieldMutex::tryToAcquire()
-{
-    if ( SolarMutexObject::tryToAcquire() )
-    {
-        mnThreadId = osl::Thread::getCurrentIdentifier();
-        mnCount++;
-        return sal_True;
-    }
-    else
-        return sal_False;
-}
-
 // ---------------
 // - SalTimer -
 // ---------------
diff --git a/vcl/inc/headless/svpinst.hxx b/vcl/inc/headless/svpinst.hxx
index 34a9c7f..d3307ab 100644
--- a/vcl/inc/headless/svpinst.hxx
+++ b/vcl/inc/headless/svpinst.hxx
@@ -46,27 +46,6 @@
 #define VIRTUAL_DESKTOP_HEIGHT 768
 #define VIRTUAL_DESKTOP_DEPTH 24
 
-// -------------------------------------------------------------------------
-// SalYieldMutex
-// -------------------------------------------------------------------------
-
-class SvpSalYieldMutex : public ::vcl::SolarMutexObject
-{
-protected:
-    sal_uLong                                       mnCount;
-    oslThreadIdentifier mnThreadId;
-
-public:
-                                                SvpSalYieldMutex();
-
-    virtual void                                acquire();
-    virtual void                                release();
-    virtual sal_Bool                            tryToAcquire();
-
-    sal_uLong                                       GetAcquireCount() const { return mnCount; }
-    oslThreadIdentifier GetThreadId() const { return mnThreadId; }
-};
-
 // ---------------
 // - SalTimer -
 // ---------------
@@ -92,7 +71,6 @@ class SvpSalInstance : public SalGenericInstance
     timeval             m_aTimeout;
     sal_uLong               m_nTimeoutMS;
     int                 m_pTimeoutFDS[2];
-    SvpSalYieldMutex    m_aYieldMutex;
 
     // internal event queue
     struct SalUserEvent
@@ -118,7 +96,7 @@ class SvpSalInstance : public SalGenericInstance
 public:
     static SvpSalInstance* s_pDefaultInstance;
 
-    SvpSalInstance();
+    SvpSalInstance( SalYieldMutex *pMutex );
     virtual ~SvpSalInstance();
 
     void PostEvent( const SalFrame* pFrame, void* pData, sal_uInt16 nEvent );
@@ -177,12 +155,6 @@ public:
     // SalBitmap
     virtual SalBitmap*      CreateSalBitmap();
 
-    // YieldMutex
-    virtual osl::SolarMutex* GetYieldMutex();
-    virtual sal_uLong           ReleaseYieldMutex();
-    virtual void            AcquireYieldMutex( sal_uLong nCount );
-    virtual bool            CheckYieldMutex();
-
     // wait next event and dispatch
     // must returned by UserEvent (SalFrame::PostEvent)
     // and timer
diff --git a/vcl/inc/unx/gtk/gtkinst.hxx b/vcl/inc/unx/gtk/gtkinst.hxx
index e6e0076..e27042a 100644
--- a/vcl/inc/unx/gtk/gtkinst.hxx
+++ b/vcl/inc/unx/gtk/gtkinst.hxx
@@ -82,10 +82,9 @@ public:
 #if GTK_CHECK_VERSION(3,0,0)
 class GtkInstance : public SvpSalInstance
 {
-    SalYieldMutex *mpSalYieldMutex;
 public:
     GtkInstance( SalYieldMutex* pMutex )
-        : SvpSalInstance(), mpSalYieldMutex( pMutex )
+        : SvpSalInstance( pMutex )
 #else
 class GtkInstance : public X11SalInstance
 {
@@ -108,10 +107,6 @@ public:
                                                      const SystemGraphicsData* );
     virtual SalBitmap*			CreateSalBitmap();
 
-    virtual osl::SolarMutex*    GetYieldMutex();
-    virtual sal_uIntPtr			ReleaseYieldMutex();
-    virtual void				AcquireYieldMutex( sal_uIntPtr nCount );
-    virtual bool                CheckYieldMutex();
     virtual void                Yield( bool bWait, bool bHandleAllCurrentEvents );
     virtual bool				AnyInput( sal_uInt16 nType );
 };
diff --git a/vcl/unx/gtk/app/gtkinst.cxx b/vcl/unx/gtk/app/gtkinst.cxx
index 284c0d3..19abff4 100644
--- a/vcl/unx/gtk/app/gtkinst.cxx
+++ b/vcl/unx/gtk/app/gtkinst.cxx
@@ -443,59 +443,7 @@ SalBitmap* GtkInstance::CreateSalBitmap()
 
 SalTimer* GtkInstance::CreateSalTimer()
 {
-#if GTK_CHECK_VERSION(3,0,0)
     return new GtkSalTimer();
-#else
-    return X11SalInstance::CreateSalTimer();
-#endif
-}
-
-// FIXME: these should all be in a more generic, shared base of unix's salinst.cxx
-
-osl::SolarMutex* GtkInstance::GetYieldMutex()
-{
-    return mpSalYieldMutex;
-}
-
-sal_uIntPtr GtkInstance::ReleaseYieldMutex()
-{
-    SalYieldMutex* pYieldMutex = mpSalYieldMutex;
-    if ( pYieldMutex->GetThreadId() ==
-         osl::Thread::getCurrentIdentifier() )
-    {
-        sal_uLong nCount = pYieldMutex->GetAcquireCount();
-        sal_uLong n = nCount;
-        while ( n )
-        {
-            pYieldMutex->release();
-            n--;
-        }
-
-        return nCount;
-    }
-    else
-        return 0;
-}
-
-void GtkInstance::AcquireYieldMutex( sal_uIntPtr nCount )
-{
-    SalYieldMutex* pYieldMutex = mpSalYieldMutex;
-    while ( nCount )
-    {
-        pYieldMutex->acquire();
-        nCount--;
-    }
-}
-
-bool GtkInstance::CheckYieldMutex()
-{
-    bool bRet = true;
-
-    SalYieldMutex* pYieldMutex = mpSalYieldMutex;
-    if ( pYieldMutex->GetThreadId() != osl::Thread::getCurrentIdentifier() )
-        bRet = false;
-
-    return bRet;
 }
 
 void GtkInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )


More information about the Libreoffice-commits mailing list