kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

Blame SOURCES/0136-lokdocview-avoid-GTK-calls-in-openDocumentInThread.patch

f325b2
From 9ba754a4df93b5d92eb871c9e37e9430da563cdc Mon Sep 17 00:00:00 2001
f325b2
From: Miklos Vajna <vmiklos@collabora.co.uk>
f325b2
Date: Tue, 15 Sep 2015 15:36:51 +0200
f325b2
Subject: [PATCH 136/398] lokdocview: avoid GTK+ calls in
f325b2
 openDocumentInThread()
f325b2
f325b2
GTK+ calls should be made from the main thread.
f325b2
f325b2
Change-Id: Idcfa46d427d6e35fc544246a691bafc72f75a74c
f325b2
(cherry picked from commit e6e5c248e52524ddaddc6d1a2627f10f169d0167)
f325b2
---
f325b2
 libreofficekit/source/gtk/lokdocview.cxx | 57 +++++++++++++++++++-------------
f325b2
 1 file changed, 34 insertions(+), 23 deletions(-)
f325b2
f325b2
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
f325b2
index 3cce40a94217..0b0b5e9d9659 100644
f325b2
--- a/libreofficekit/source/gtk/lokdocview.cxx
f325b2
+++ b/libreofficekit/source/gtk/lokdocview.cxx
f325b2
@@ -143,6 +143,7 @@ enum
f325b2
 static guint doc_view_signals[LAST_SIGNAL] = { 0 };
f325b2
 
f325b2
 static void lok_doc_view_initable_iface_init (GInitableIface *iface);
f325b2
+static void callbackWorker (int nType, const char* pPayload, void* pData);
f325b2
 
f325b2
 SAL_DLLPUBLIC_EXPORT GType lok_doc_view_get_type();
f325b2
 #ifdef __GNUC__
f325b2
@@ -380,6 +381,37 @@ static gboolean queueDraw(gpointer pData)
f325b2
     return G_SOURCE_REMOVE;
f325b2
 }
f325b2
 
f325b2
+/// Set up LOKDocView after the document is loaded, invoked on the main thread by openDocumentInThread() running in a thread.
f325b2
+static gboolean postDocumentLoad(gpointer pData)
f325b2
+{
f325b2
+    LOKDocView* pLOKDocView = static_cast<LOKDocView*>(pData);
f325b2
+    LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(pLOKDocView));
f325b2
+
f325b2
+    priv->m_pDocument->pClass->initializeForRendering(priv->m_pDocument);
f325b2
+    priv->m_pDocument->pClass->registerCallback(priv->m_pDocument, callbackWorker, pLOKDocView);
f325b2
+    priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips);
f325b2
+    g_timeout_add(600, handleTimeout, pLOKDocView);
f325b2
+
f325b2
+    float zoom = priv->m_fZoom;
f325b2
+    long nDocumentWidthTwips = priv->m_nDocumentWidthTwips;
f325b2
+    long nDocumentHeightTwips = priv->m_nDocumentHeightTwips;
f325b2
+    long nDocumentWidthPixels = twipToPixel(nDocumentWidthTwips, zoom);
f325b2
+    long nDocumentHeightPixels = twipToPixel(nDocumentHeightTwips, zoom);
f325b2
+    // Total number of columns in this document.
f325b2
+    guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
f325b2
+
f325b2
+
f325b2
+    priv->m_aTileBuffer = TileBuffer(priv->m_pDocument,
f325b2
+                                     nColumns);
f325b2
+    gtk_widget_set_size_request(GTK_WIDGET(pLOKDocView),
f325b2
+                                nDocumentWidthPixels,
f325b2
+                                nDocumentHeightPixels);
f325b2
+    gtk_widget_set_can_focus(GTK_WIDGET(pLOKDocView), TRUE);
f325b2
+    gtk_widget_grab_focus(GTK_WIDGET(pLOKDocView));
f325b2
+
f325b2
+    return G_SOURCE_REMOVE;
f325b2
+}
f325b2
+
f325b2
 /// Implementation of the global callback handler, invoked by globalCallback();
f325b2
 static gboolean
f325b2
 globalCallback (gpointer pData)
f325b2
@@ -617,8 +649,7 @@ callback (gpointer pData)
f325b2
     return G_SOURCE_REMOVE;
f325b2
 }
f325b2
 
f325b2
-static void
f325b2
-callbackWorker (int nType, const char* pPayload, void* pData)
f325b2
+static void callbackWorker (int nType, const char* pPayload, void* pData)
f325b2
 {
f325b2
     LOKDocView* pDocView = LOK_DOC_VIEW (pData);
f325b2
 
f325b2
@@ -1193,27 +1224,7 @@ openDocumentInThread (gpointer data)
f325b2
     }
f325b2
     else
f325b2
     {
f325b2
-        priv->m_pDocument->pClass->initializeForRendering(priv->m_pDocument);
f325b2
-        priv->m_pDocument->pClass->registerCallback(priv->m_pDocument, callbackWorker, pDocView);
f325b2
-        priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips);
f325b2
-        g_timeout_add(600, handleTimeout, pDocView);
f325b2
-
f325b2
-        float zoom = priv->m_fZoom;
f325b2
-        long nDocumentWidthTwips = priv->m_nDocumentWidthTwips;
f325b2
-        long nDocumentHeightTwips = priv->m_nDocumentHeightTwips;
f325b2
-        long nDocumentWidthPixels = twipToPixel(nDocumentWidthTwips, zoom);
f325b2
-        long nDocumentHeightPixels = twipToPixel(nDocumentHeightTwips, zoom);
f325b2
-        // Total number of columns in this document.
f325b2
-        guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
f325b2
-
f325b2
-
f325b2
-        priv->m_aTileBuffer = TileBuffer(priv->m_pDocument,
f325b2
-                                         nColumns);
f325b2
-        gtk_widget_set_size_request(GTK_WIDGET(pDocView),
f325b2
-                                    nDocumentWidthPixels,
f325b2
-                                    nDocumentHeightPixels);
f325b2
-        gtk_widget_set_can_focus(GTK_WIDGET(pDocView), TRUE);
f325b2
-        gtk_widget_grab_focus(GTK_WIDGET(pDocView));
f325b2
+        gdk_threads_add_idle(postDocumentLoad, pDocView);
f325b2
         g_task_return_boolean (task, true);
f325b2
     }
f325b2
 }
f325b2
-- 
f325b2
2.12.0
f325b2