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

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