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

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