[Libreoffice-commits] core.git: libreofficekit/source

Pranav Kant pranavk at gnome.org
Tue Aug 4 05:56:21 PDT 2015


 libreofficekit/source/gtk/lokdocview.cxx |   53 ++++++++++++++++---------------
 libreofficekit/source/gtk/tilebuffer.cxx |    8 ++--
 libreofficekit/source/gtk/tilebuffer.hxx |   15 +++++++-
 3 files changed, 44 insertions(+), 32 deletions(-)

New commits:
commit 4df957f7255cf2ddce47a088dd30f945db6975be
Author: Pranav Kant <pranavk at gnome.org>
Date:   Wed Jul 29 21:41:56 2015 +0530

    lokdocview: Don't use extern variable: lokThreadPool
    
    Change-Id: Ia208e3309bb64baf71ceb97cdf1b3b57b6120353

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


More information about the Libreoffice-commits mailing list