Blame SOURCES/0089-lokdocview-Don-t-use-extern-variable-lokThreadPool.patch

f325b2
From ade489c20e735224810e79ede6ef37bbbe8d56c0 Mon Sep 17 00:00:00 2001
f325b2
From: Pranav Kant <pranavk@gnome.org>
f325b2
Date: Wed, 29 Jul 2015 21:41:56 +0530
f325b2
Subject: [PATCH 089/398] lokdocview: Don't use extern variable: lokThreadPool
f325b2
f325b2
Change-Id: Ia208e3309bb64baf71ceb97cdf1b3b57b6120353
f325b2
(cherry picked from commit 4df957f7255cf2ddce47a088dd30f945db6975be)
f325b2
---
f325b2
 libreofficekit/source/gtk/lokdocview.cxx | 53 +++++++++++++++++---------------
f325b2
 libreofficekit/source/gtk/tilebuffer.cxx |  8 ++---
f325b2
 libreofficekit/source/gtk/tilebuffer.hxx | 15 +++++++--
f325b2
 3 files changed, 44 insertions(+), 32 deletions(-)
f325b2
f325b2
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
f325b2
index bdae55fc54e0..364590167f56 100644
f325b2
--- a/libreofficekit/source/gtk/lokdocview.cxx
f325b2
+++ b/libreofficekit/source/gtk/lokdocview.cxx
f325b2
@@ -49,6 +49,7 @@ struct _LOKDocViewPrivate
f325b2
     LibreOfficeKitDocument* m_pDocument;
f325b2
 
f325b2
     TileBuffer m_aTileBuffer;
f325b2
+    GThreadPool* lokThreadPool;
f325b2
 
f325b2
     gfloat m_fZoom;
f325b2
     glong m_nDocumentWidthTwips;
f325b2
@@ -152,8 +153,6 @@ G_DEFINE_TYPE_WITH_CODE (LOKDocView, lok_doc_view, GTK_TYPE_DRAWING_AREA,
f325b2
 #pragma GCC diagnostic pop
f325b2
 #endif
f325b2
 
f325b2
-GThreadPool* lokThreadPool;
f325b2
-
f325b2
 /// Helper struct used to pass the data from soffice thread -> main thread.
f325b2
 struct CallbackData
f325b2
 {
f325b2
@@ -308,7 +307,7 @@ signalKey (GtkWidget* pWidget, GdkEventKey* pEvent)
f325b2
         pLOEvent->m_nCharCode = nCharCode;
f325b2
         pLOEvent->m_nKeyCode  = nKeyCode;
f325b2
         g_task_set_task_data(task, pLOEvent, g_free);
f325b2
-        g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+        g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
         g_object_unref(task);
f325b2
     }
f325b2
     else
f325b2
@@ -319,7 +318,7 @@ signalKey (GtkWidget* pWidget, GdkEventKey* pEvent)
f325b2
         pLOEvent->m_nCharCode = nCharCode;
f325b2
         pLOEvent->m_nKeyCode  = nKeyCode;
f325b2
         g_task_set_task_data(task, pLOEvent, g_free);
f325b2
-        g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+        g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
         g_object_unref(task);
f325b2
     }
f325b2
 
f325b2
@@ -487,7 +486,7 @@ setTilesInvalid (LOKDocView* pDocView, const GdkRectangle& rRectangle)
f325b2
         for (int j = aStart.y; j < aEnd.y; j++)
f325b2
         {
f325b2
             GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
f325b2
-            priv->m_aTileBuffer.setInvalid(i, j, priv->m_fZoom, task);
f325b2
+            priv->m_aTileBuffer.setInvalid(i, j, priv->m_fZoom, task, priv->lokThreadPool);
f325b2
             g_object_unref(task);
f325b2
         }
f325b2
     }
f325b2
@@ -762,7 +761,7 @@ renderDocument(LOKDocView* pDocView, cairo_t* pCairo)
f325b2
             if (bPaint)
f325b2
             {
f325b2
                 GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
f325b2
-                Tile& currentTile = priv->m_aTileBuffer.getTile(nRow, nColumn, priv->m_fZoom, task);
f325b2
+                Tile& currentTile = priv->m_aTileBuffer.getTile(nRow, nColumn, priv->m_fZoom, task, priv->lokThreadPool);
f325b2
                 GdkPixbuf* pPixBuf = currentTile.getBuffer();
f325b2
                 gdk_cairo_set_source_pixbuf (pCairo, pPixBuf,
f325b2
                                              twipToPixel(aTileRectangleTwips.x, priv->m_fZoom),
f325b2
@@ -900,7 +899,7 @@ lok_doc_view_signal_button(GtkWidget* pWidget, GdkEventButton* pEvent)
f325b2
                 pLOEvent->m_nSetGraphicSelectionY = pixelToTwip(pEvent->y, priv->m_fZoom);
f325b2
                 g_task_set_task_data(task, pLOEvent, g_free);
f325b2
 
f325b2
-                g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+                g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
                 g_object_unref(task);
f325b2
 
f325b2
                 return FALSE;
f325b2
@@ -919,7 +918,7 @@ lok_doc_view_signal_button(GtkWidget* pWidget, GdkEventButton* pEvent)
f325b2
             pLOEvent->m_nSetGraphicSelectionY = pixelToTwip(pEvent->y, priv->m_fZoom);
f325b2
             g_task_set_task_data(task, pLOEvent, g_free);
f325b2
 
f325b2
-            g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+            g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
             g_object_unref(task);
f325b2
 
f325b2
             return FALSE;
f325b2
@@ -968,7 +967,7 @@ lok_doc_view_signal_button(GtkWidget* pWidget, GdkEventButton* pEvent)
f325b2
                     pLOEvent->m_nSetGraphicSelectionY = pixelToTwip(priv->m_aGraphicHandleRects[i].y + priv->m_aGraphicHandleRects[i].height / 2, priv->m_fZoom);
f325b2
                     g_task_set_task_data(task, pLOEvent, g_free);
f325b2
 
f325b2
-                    g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+                    g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
                     g_object_unref(task);
f325b2
 
f325b2
                     return FALSE;
f325b2
@@ -996,7 +995,7 @@ lok_doc_view_signal_button(GtkWidget* pWidget, GdkEventButton* pEvent)
f325b2
         pLOEvent->m_nPostMouseEventCount = nCount;
f325b2
         g_task_set_task_data(task, pLOEvent, g_free);
f325b2
 
f325b2
-        g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+        g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
         g_object_unref(task);
f325b2
         break;
f325b2
     }
f325b2
@@ -1014,7 +1013,7 @@ lok_doc_view_signal_button(GtkWidget* pWidget, GdkEventButton* pEvent)
f325b2
         pLOEvent->m_nPostMouseEventCount = nCount;
f325b2
         g_task_set_task_data(task, pLOEvent, g_free);
f325b2
 
f325b2
-        g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+        g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
         g_object_unref(task);
f325b2
         break;
f325b2
     }
f325b2
@@ -1101,7 +1100,7 @@ lok_doc_view_signal_motion (GtkWidget* pWidget, GdkEventMotion* pEvent)
f325b2
         pLOEvent->m_nSetGraphicSelectionY = pixelToTwip(pEvent->y, priv->m_fZoom);
f325b2
         g_task_set_task_data(task, pLOEvent, g_free);
f325b2
 
f325b2
-        g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+        g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
         g_object_unref(task);
f325b2
 
f325b2
         return FALSE;
f325b2
@@ -1117,7 +1116,7 @@ lok_doc_view_signal_motion (GtkWidget* pWidget, GdkEventMotion* pEvent)
f325b2
     pLOEvent->m_nPostMouseEventCount = 1;
f325b2
     g_task_set_task_data(task, pLOEvent, g_free);
f325b2
 
f325b2
-    g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+    g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
     g_object_unref(task);
f325b2
 
f325b2
     return FALSE;
f325b2
@@ -1355,6 +1354,12 @@ static void lok_doc_view_init (LOKDocView* pDocView)
f325b2
                           |GDK_BUTTON_MOTION_MASK
f325b2
                           |GDK_KEY_PRESS_MASK
f325b2
                           |GDK_KEY_RELEASE_MASK);
f325b2
+
f325b2
+    priv->lokThreadPool = g_thread_pool_new(lokThreadFunc,
f325b2
+                                            NULL,
f325b2
+                                            1,
f325b2
+                                            FALSE,
f325b2
+                                            NULL);
f325b2
 }
f325b2
 
f325b2
 static void lok_doc_view_set_property (GObject* object, guint propId, const GValue *value, GParamSpec *pspec)
f325b2
@@ -1738,12 +1743,6 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
f325b2
                      g_cclosure_marshal_VOID__STRING,
f325b2
                      G_TYPE_NONE, 1,
f325b2
                      G_TYPE_STRING);
f325b2
-
f325b2
-    lokThreadPool = g_thread_pool_new(lokThreadFunc,
f325b2
-                                      NULL,
f325b2
-                                      1,
f325b2
-                                      FALSE,
f325b2
-                                      NULL);
f325b2
 }
f325b2
 
f325b2
 /**
f325b2
@@ -1806,7 +1805,7 @@ lok_doc_view_open_document (LOKDocView* pDocView,
f325b2
     priv->m_aDocPath = pPath;
f325b2
     g_task_set_task_data(task, pLOEvent, g_free);
f325b2
 
f325b2
-    g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+    g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
     g_object_unref(task);
f325b2
 }
f325b2
 
f325b2
@@ -1878,12 +1877,14 @@ lok_doc_view_get_part (LOKDocView* pDocView)
f325b2
 SAL_DLLPUBLIC_EXPORT void
f325b2
 lok_doc_view_set_part (LOKDocView* pDocView, int nPart)
f325b2
 {
f325b2
+    LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
f325b2
     GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
f325b2
     LOEvent* pLOEvent = new LOEvent(LOK_SET_PART);
f325b2
+
f325b2
     pLOEvent->m_nPart = nPart;
f325b2
     g_task_set_task_data(task, pLOEvent, g_free);
f325b2
 
f325b2
-    g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+    g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
     g_object_unref(task);
f325b2
 }
f325b2
 
f325b2
@@ -1898,12 +1899,13 @@ SAL_DLLPUBLIC_EXPORT void
f325b2
 lok_doc_view_set_partmode(LOKDocView* pDocView,
f325b2
                           int nPartMode)
f325b2
 {
f325b2
+    LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
f325b2
     GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
f325b2
     LOEvent* pLOEvent = new LOEvent(LOK_SET_PARTMODE);
f325b2
     pLOEvent->m_nPartMode = nPartMode;
f325b2
     g_task_set_task_data(task, pLOEvent, g_free);
f325b2
 
f325b2
-    g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+    g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
     g_object_unref(task);
f325b2
 }
f325b2
 
f325b2
@@ -1926,12 +1928,13 @@ SAL_DLLPUBLIC_EXPORT void
f325b2
 lok_doc_view_set_edit(LOKDocView* pDocView,
f325b2
                       gboolean bEdit)
f325b2
 {
f325b2
+    LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
f325b2
     GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
f325b2
     LOEvent* pLOEvent = new LOEvent(LOK_SET_EDIT);
f325b2
     pLOEvent->m_bEdit = bEdit;
f325b2
     g_task_set_task_data(task, pLOEvent, g_free);
f325b2
 
f325b2
-    g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+    g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
     g_object_unref(task);
f325b2
 }
f325b2
 
f325b2
@@ -1961,14 +1964,14 @@ lok_doc_view_post_command (LOKDocView* pDocView,
f325b2
                            const gchar* pCommand,
f325b2
                            const gchar* pArguments)
f325b2
 {
f325b2
-
f325b2
+    LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
f325b2
     GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
f325b2
     LOEvent* pLOEvent = new LOEvent(LOK_POST_COMMAND);
f325b2
     pLOEvent->m_pCommand = pCommand;
f325b2
     pLOEvent->m_pArguments  = g_strdup(pArguments);
f325b2
 
f325b2
     g_task_set_task_data(task, pLOEvent, g_free);
f325b2
-    g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
f325b2
+    g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), NULL);
f325b2
     g_object_unref(task);
f325b2
 }
f325b2
 
f325b2
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
f325b2
index 21ea58b0faff..85f6eb0422c2 100644
f325b2
--- a/libreofficekit/source/gtk/tilebuffer.cxx
f325b2
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
f325b2
@@ -13,8 +13,6 @@
f325b2
 #define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
f325b2
 #endif
f325b2
 
f325b2
-extern GThreadPool* lokThreadPool;
f325b2
-
f325b2
 /* ------------------
f325b2
    Utility functions
f325b2
    ------------------
f325b2
@@ -62,7 +60,8 @@ void TileBuffer::resetAllTiles()
f325b2
     }
f325b2
 }
f325b2
 
f325b2
-void TileBuffer::setInvalid(int x, int y, float fZoom, GTask* task)
f325b2
+void TileBuffer::setInvalid(int x, int y, float fZoom, GTask* task,
f325b2
+                            GThreadPool* lokThreadPool)
f325b2
 {
f325b2
     int index = x * m_nWidth + y;
f325b2
     g_info("Setting tile invalid (%d, %d)", x, y);
f325b2
@@ -79,7 +78,8 @@ void TileBuffer::setInvalid(int x, int y, float fZoom, GTask* task)
f325b2
     }
f325b2
 }
f325b2
 
f325b2
-Tile& TileBuffer::getTile(int x, int y, float fZoom, GTask* task)
f325b2
+Tile& TileBuffer::getTile(int x, int y, float fZoom, GTask* task,
f325b2
+                          GThreadPool* lokThreadPool)
f325b2
 {
f325b2
     int index = x * m_nWidth + y;
f325b2
 
f325b2
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
f325b2
index b00724367b8d..d4e7120e6587 100644
f325b2
--- a/libreofficekit/source/gtk/tilebuffer.hxx
f325b2
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
f325b2
@@ -103,11 +103,15 @@ class TileBuffer
f325b2
 
f325b2
        @param x the tile along the x-axis of the buffer
f325b2
        @param y the tile along the y-axis of the buffer
f325b2
-       @param aZoom This function needs the zoom factor to draw the tile using paintTile()
f325b2
+       @param aZoom current zoom factor of the document
f325b2
+       @param task GTask object containing the necessary data
f325b2
+       @param pool GThreadPool managed by the widget instance used for all the
f325b2
+       LOK calls made by widget. It is needed here because getTile invokes one
f325b2
+       of the LOK call : paintTile.
f325b2
 
f325b2
        @return the tile at the mentioned position (x, y)
f325b2
      */
f325b2
-    Tile& getTile(int x, int y, float aZoom, GTask* task);
f325b2
+    Tile& getTile(int x, int y, float aZoom, GTask* task, GThreadPool* pool);
f325b2
     /// Destroys all the tiles in the tile buffer; also frees the memory allocated
f325b2
     /// for all the Tile objects.
f325b2
     void resetAllTiles();
f325b2
@@ -117,8 +121,13 @@ class TileBuffer
f325b2
 
f325b2
        @param x the position of tile along x-axis
f325b2
        @param y the position of tile along y-axis
f325b2
+       @param zoom zoom factor of the document
f325b2
+       @param task GTask object containing the necessary data
f325b2
+       @param pool GThreadPool managed by the widget instance used for all the
f325b2
+       LOK calls made by widget. It is needed here because setInvalid() invokes one
f325b2
+       of the LOK call : paintTile.
f325b2
      */
f325b2
-    void setInvalid(int x, int y, float zoom, GTask* task);
f325b2
+    void setInvalid(int x, int y, float zoom, GTask* task, GThreadPool*);
f325b2
 
f325b2
     /// Contains the reference to the LOK Document that this tile buffer is for.
f325b2
     LibreOfficeKitDocument *m_pLOKDocument;
f325b2
-- 
f325b2
2.12.0
f325b2