Blame SOURCES/0261-lokdocview-Separate-painting-and-saving-of-tiles.patch

135360
From a47531dc2f5b90eedb4afb4dd2b3b52fb5a59365 Mon Sep 17 00:00:00 2001
135360
From: Pranav Kant <pranavk@libreoffice.org>
135360
Date: Sun, 1 Nov 2015 13:22:25 +0530
135360
Subject: [PATCH 261/398] lokdocview: Separate "painting" and "saving" of tiles
135360
135360
Lets separate the task of painting the tile, and saving the tile
135360
in tile buffer using GAsyncReadyCallback. This will provide us
135360
with better control over tiles -- cancelling the painting operation,
135360
and filtering tiles that should not be saved in the tile buffer.
135360
135360
Change-Id: I6aae928d8cc0c906034570ed0e9a054763d493a3
135360
Reviewed-on: https://gerrit.libreoffice.org/19725
135360
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
135360
(cherry picked from commit de0c7e1783edc6a36037f2657f823dc9812c0804)
135360
---
135360
 libreofficekit/source/gtk/lokdocview.cxx | 56 ++++++++++++++++++++++++++++----
135360
 libreofficekit/source/gtk/tilebuffer.cxx | 10 ------
135360
 2 files changed, 49 insertions(+), 17 deletions(-)
135360
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index 2ec27305af4e..867c0d165448 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -873,6 +873,47 @@ renderGraphicHandle(LOKDocView* pDocView,
135360
     }
135360
 }
135360
 
135360
+/// Finishes the paint tile operation and returns the result, if any
135360
+static gpointer
135360
+paintTileFinish(LOKDocView* pDocView, GAsyncResult* res, GError **error)
135360
+{
135360
+    GTask* task = G_TASK(res);
135360
+
135360
+    g_return_val_if_fail(LOK_IS_DOC_VIEW(pDocView), NULL);
135360
+    g_return_val_if_fail(g_task_is_valid(res, pDocView), NULL);
135360
+    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
135360
+
135360
+    return g_task_propagate_pointer(task, error);
135360
+}
135360
+
135360
+/// Callback called in the main UI thread when paintTileInThread in LOK thread has finished
135360
+static void
135360
+paintTileCallback(GObject* sourceObject, GAsyncResult* res, gpointer userData)
135360
+{
135360
+    LOKDocView* pDocView = LOK_DOC_VIEW(sourceObject);
135360
+    LOKDocViewPrivate& priv = getPrivate(pDocView);
135360
+    LOEvent* pLOEvent = static_cast<LOEvent*>(userData);
135360
+    std::unique_ptr<TileBuffer>& buffer = priv->m_pTileBuffer;
135360
+    int index = pLOEvent->m_nPaintTileX * buffer->m_nWidth + pLOEvent->m_nPaintTileY;
135360
+    GError* error;
135360
+
135360
+    error = NULL;
135360
+    GdkPixbuf* pPixBuf = static_cast<GdkPixbuf*>(paintTileFinish(pDocView, res, &error));
135360
+    if (error != NULL)
135360
+    {
135360
+        g_warning("Unable to get painted GdkPixbuf: %s", error->message);
135360
+        g_error_free(error);
135360
+        return;
135360
+    }
135360
+
135360
+    buffer->m_mTiles[index].setPixbuf(pPixBuf);
135360
+    buffer->m_mTiles[index].valid = true;
135360
+    gdk_threads_add_idle(queueDraw, GTK_WIDGET(pDocView));
135360
+
135360
+    g_object_unref(pPixBuf);
135360
+}
135360
+
135360
+
135360
 static gboolean
135360
 renderDocument(LOKDocView* pDocView, cairo_t* pCairo)
135360
 {
135360
@@ -921,7 +962,13 @@ renderDocument(LOKDocView* pDocView, cairo_t* pCairo)
135360
 
135360
             if (bPaint)
135360
             {
135360
-                GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
135360
+                LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE);
135360
+                pLOEvent->m_nPaintTileX = nRow;
135360
+                pLOEvent->m_nPaintTileY = nColumn;
135360
+                pLOEvent->m_fPaintTileZoom = priv->m_fZoom;
135360
+                GTask* task = g_task_new(pDocView, NULL, paintTileCallback, pLOEvent);
135360
+                g_task_set_task_data(task, pLOEvent, LOEvent::destroy);
135360
+
135360
                 Tile& currentTile = priv->m_pTileBuffer->getTile(nRow, nColumn, priv->m_fZoom, task, priv->lokThreadPool);
135360
                 GdkPixbuf* pPixBuf = currentTile.getBuffer();
135360
                 gdk_cairo_set_source_pixbuf (pCairo, pPixBuf,
135360
@@ -1516,12 +1563,7 @@ paintTileInThread (gpointer data)
135360
                                          pixelToTwip(nTileSizePixels, pLOEvent->m_fPaintTileZoom),
135360
                                          pixelToTwip(nTileSizePixels, pLOEvent->m_fPaintTileZoom));
135360
 
135360
-    //create a mapping for it
135360
-    buffer->m_mTiles[index].setPixbuf(pPixBuf);
135360
-    buffer->m_mTiles[index].valid = true;
135360
-    gdk_threads_add_idle(queueDraw, GTK_WIDGET(pDocView));
135360
-
135360
-    g_object_unref(pPixBuf);
135360
+    g_task_return_pointer(task, pPixBuf, g_object_unref);
135360
 }
135360
 
135360
 
135360
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
135360
index 811fcc61ef46..6c9847674e53 100644
135360
--- a/libreofficekit/source/gtk/tilebuffer.cxx
135360
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
135360
@@ -93,11 +93,6 @@ Tile& TileBuffer::getTile(int x, int y, float fZoom, GTask* task,
135360
 
135360
     if (m_mTiles.find(index) != m_mTiles.end() && !m_mTiles[index].valid)
135360
     {
135360
-        LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE);
135360
-        pLOEvent->m_nPaintTileX = x;
135360
-        pLOEvent->m_nPaintTileY = y;
135360
-        pLOEvent->m_fPaintTileZoom = fZoom;
135360
-        g_task_set_task_data(task, pLOEvent, LOEvent::destroy);
135360
         g_thread_pool_push(lokThreadPool, g_object_ref(task), &error);
135360
         if (error != NULL)
135360
         {
135360
@@ -108,11 +103,6 @@ Tile& TileBuffer::getTile(int x, int y, float fZoom, GTask* task,
135360
     }
135360
     else if(m_mTiles.find(index) == m_mTiles.end())
135360
     {
135360
-        LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE);
135360
-        pLOEvent->m_nPaintTileX = x;
135360
-        pLOEvent->m_nPaintTileY = y;
135360
-        pLOEvent->m_fPaintTileZoom = fZoom;
135360
-        g_task_set_task_data(task, pLOEvent, LOEvent::destroy);
135360
         g_thread_pool_push(lokThreadPool, g_object_ref(task), &error);
135360
         if (error != NULL)
135360
         {
135360
-- 
135360
2.12.0
135360