[Libreoffice-commits] core.git: vcl/inc vcl/unx

Jan-Marek Glogowski glogow at fbihome.de
Thu Jul 13 15:02:45 UTC 2017


 vcl/inc/unx/gtk/gtkinst.hxx  |    4 ++--
 vcl/unx/gtk/gtkdata.cxx      |   12 +++++++++---
 vcl/unx/gtk/gtkinst.cxx      |   25 +++++++++----------------
 vcl/unx/gtk3/gtk3gtkdata.cxx |   12 +++++++++---
 4 files changed, 29 insertions(+), 24 deletions(-)

New commits:
commit de0acf13b2dee2f7ad25de43f17acab73f1c7eac
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date:   Thu Jul 13 16:05:56 2017 +0200

    GTK+ convert to a single-shot timer
    
    Simplified version of commit
      3e20ce802ee2ab49c4f2a98880f6e999657686bb
    
    Since we're missing g_source_get_ready_time in our baseline, this
    can't change the complex implementation, but still drops the timer
    array and uses a single-shot timer, like all other backends.
    
    Change-Id: I0641da8d0db71785c505957533a9069924808cd4

diff --git a/vcl/inc/unx/gtk/gtkinst.hxx b/vcl/inc/unx/gtk/gtkinst.hxx
index 4c86a3d62867..1585c778afac 100644
--- a/vcl/inc/unx/gtk/gtkinst.hxx
+++ b/vcl/inc/unx/gtk/gtkinst.hxx
@@ -233,12 +233,12 @@ public:
             const cairo_font_options_t* GetLastSeenCairoFontOptions();
                                    void ResetLastSeenCairoFontOptions();
 
-    void                        RemoveTimer (SalTimer *pTimer);
+    void                        RemoveTimer ();
 
     std::shared_ptr<vcl::unx::GtkPrintWrapper> const & getPrintWrapper() const;
 
 private:
-    std::vector<GtkSalTimer *>  m_aTimers;
+    GtkSalTimer *m_pTimer;
 #if GTK_CHECK_VERSION(3,0,0)
     std::unordered_map< GdkAtom, css::uno::Reference<css::uno::XInterface> > m_aClipboards;
 #endif
diff --git a/vcl/unx/gtk/gtkdata.cxx b/vcl/unx/gtk/gtkdata.cxx
index e5278f157698..6bb9f04e3bae 100644
--- a/vcl/unx/gtk/gtkdata.cxx
+++ b/vcl/unx/gtk/gtkdata.cxx
@@ -652,6 +652,10 @@ bool GtkData::ErrorTrapPop( bool bIgnoreError )
     return gdk_error_trap_pop () != 0;
 }
 
+#if !GLIB_CHECK_VERSION(2,32,0)
+#define G_SOURCE_REMOVE FALSE
+#endif
+
 extern "C" {
 
     struct SalGtkTimeoutSource {
@@ -732,7 +736,7 @@ extern "C" {
         if( pSVData->maSchedCtx.mpSalTimer )
             pSVData->maSchedCtx.mpSalTimer->CallCallback();
 
-        return TRUE;
+        return G_SOURCE_REMOVE;
     }
 
     static GSourceFuncs sal_gtk_timeout_funcs =
@@ -777,13 +781,13 @@ GtkSalTimer::GtkSalTimer()
 GtkSalTimer::~GtkSalTimer()
 {
     GtkInstance *pInstance = static_cast<GtkInstance *>(GetSalData()->m_pInstance);
-    pInstance->RemoveTimer( this );
+    pInstance->RemoveTimer();
     Stop();
 }
 
 bool GtkSalTimer::Expired()
 {
-    if( !m_pTimeout )
+    if( !m_pTimeout || g_source_is_destroyed( &m_pTimeout->aParent ) )
         return false;
 
     gint nDummy = 0;
@@ -796,6 +800,8 @@ void GtkSalTimer::Start( sal_uLong nMS )
 {
     // glib is not 64bit safe in this regard.
     assert( nMS <= G_MAXINT );
+    if ( nMS > G_MAXINT )
+        nMS = G_MAXINT;
     m_nTimeoutMS = nMS; // for restarting
     Stop(); // FIXME: ideally re-use an existing m_pTimeout
     m_pTimeout = create_sal_gtk_timeout( this );
diff --git a/vcl/unx/gtk/gtkinst.cxx b/vcl/unx/gtk/gtkinst.cxx
index 034b634a0f79..db0aa9b783e4 100644
--- a/vcl/unx/gtk/gtkinst.cxx
+++ b/vcl/unx/gtk/gtkinst.cxx
@@ -156,6 +156,7 @@ GtkInstance::GtkInstance( SalYieldMutex* pMutex )
 #else
     : X11SalInstance( pMutex )
 #endif
+    , m_pTimer(nullptr)
     , bNeedsInit(true)
     , m_pLastCairoFontOptions(nullptr)
 {
@@ -194,8 +195,7 @@ void GtkInstance::EnsureInit()
 
 GtkInstance::~GtkInstance()
 {
-    while( !m_aTimers.empty() )
-        delete *m_aTimers.begin();
+    assert( nullptr == m_pTimer );
     DeInitAtkBridge();
     ResetLastSeenCairoFontOptions();
 }
@@ -397,18 +397,16 @@ void         GtkInstance::DestroyMenuItem( SalMenuItem* )        {}
 SalTimer* GtkInstance::CreateSalTimer()
 {
     EnsureInit();
-    GtkSalTimer *pTimer = new GtkSalTimer();
-    m_aTimers.push_back( pTimer );
-    return pTimer;
+    assert( nullptr == m_pTimer );
+    if ( nullptr == m_pTimer )
+        m_pTimer = new GtkSalTimer();
+    return m_pTimer;
 }
 
-void GtkInstance::RemoveTimer (SalTimer *pTimer)
+void GtkInstance::RemoveTimer ()
 {
     EnsureInit();
-    std::vector<GtkSalTimer *>::iterator it;
-    it = std::find( m_aTimers.begin(), m_aTimers.end(), pTimer );
-    if( it != m_aTimers.end() )
-        m_aTimers.erase( it );
+    m_pTimer = nullptr;
 }
 
 bool GtkInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong const nReleased)
@@ -422,12 +420,7 @@ bool GtkInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong co
 bool GtkInstance::IsTimerExpired()
 {
     EnsureInit();
-    for( std::vector<GtkSalTimer *>::iterator it = m_aTimers.begin();
-         it != m_aTimers.end(); ++it )
-        if( (*it)->Expired() )
-            return true;
-
-    return false;
+    return (m_pTimer && m_pTimer->Expired());
 }
 
 bool GtkInstance::AnyInput( VclInputFlags nType )
diff --git a/vcl/unx/gtk3/gtk3gtkdata.cxx b/vcl/unx/gtk3/gtk3gtkdata.cxx
index 3e074489bfd5..ba56d5e6ec7f 100644
--- a/vcl/unx/gtk3/gtk3gtkdata.cxx
+++ b/vcl/unx/gtk3/gtk3gtkdata.cxx
@@ -614,6 +614,10 @@ bool GtkData::ErrorTrapPop( bool bIgnoreError )
     return gdk_error_trap_pop () != 0;
 }
 
+#if !GLIB_CHECK_VERSION(2,32,0)
+#define G_SOURCE_REMOVE FALSE
+#endif
+
 extern "C" {
 
     struct SalGtkTimeoutSource {
@@ -694,7 +698,7 @@ extern "C" {
         if( pSVData->maSchedCtx.mpSalTimer )
             pSVData->maSchedCtx.mpSalTimer->CallCallback();
 
-        return TRUE;
+        return G_SOURCE_REMOVE;
     }
 
     static GSourceFuncs sal_gtk_timeout_funcs =
@@ -739,13 +743,13 @@ GtkSalTimer::GtkSalTimer()
 GtkSalTimer::~GtkSalTimer()
 {
     GtkInstance *pInstance = static_cast<GtkInstance *>(GetSalData()->m_pInstance);
-    pInstance->RemoveTimer( this );
+    pInstance->RemoveTimer();
     Stop();
 }
 
 bool GtkSalTimer::Expired()
 {
-    if( !m_pTimeout )
+    if( !m_pTimeout || g_source_is_destroyed( &m_pTimeout->aParent ) )
         return false;
 
     gint nDummy = 0;
@@ -758,6 +762,8 @@ void GtkSalTimer::Start( sal_uLong nMS )
 {
     // glib is not 64bit safe in this regard.
     assert( nMS <= G_MAXINT );
+    if ( nMS > G_MAXINT )
+        nMS = G_MAXINT;
     m_nTimeoutMS = nMS; // for restarting
     Stop(); // FIXME: ideally re-use an existing m_pTimeout
     m_pTimeout = create_sal_gtk_timeout( this );


More information about the Libreoffice-commits mailing list