[Libreoffice-commits] core.git: Branch 'feature/gsoc-tiled-rendering' - 2 commits - libreofficekit/source

Pranav Kant pranavk at gnome.org
Tue Jul 21 09:55:01 PDT 2015


Rebased ref, commits from common ancestor:
commit 2501f24e42353ae86c3ebcf4b39d493d9a1ca77c
Author: Pranav Kant <pranavk at gnome.org>
Date:   Sun Jul 19 23:05:43 2015 +0530

    lokdocview: [WIP] Async. request for tile on tile invalidation
    
    Change-Id: I57db9e3adf26996e6e1e105b8b95f53e88e7760f

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 3662f0d..e2568fa 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -520,7 +520,7 @@ setTilesInvalid (LOKDocView* pDocView, const GdkRectangle& rRectangle)
 
     for (int i = aStart.x; i < aEnd.x; i++)
         for (int j = aStart.y; j < aEnd.y; j++)
-            priv->m_aTileBuffer.setInvalid(i, j);
+            priv->m_aTileBuffer.setInvalid(i, j, priv->m_fZoom);
 }
 
 static gboolean
@@ -742,7 +742,7 @@ renderGraphicHandle(LOKDocView* pDocView,
 }
 
 static void
-rdcb(GObject* source_object, GAsyncResult* res, gpointer)
+rdcb(GObject* source_object, GAsyncResult*, gpointer)
 {
     LOKDocView* pDocView = LOK_DOC_VIEW(source_object);
     gtk_widget_queue_draw(GTK_WIDGET(pDocView));
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
index 43050c0..d488f8b 100644
--- a/libreofficekit/source/gtk/tilebuffer.cxx
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
@@ -27,7 +27,7 @@ float twipToPixel(float fInput, float zoom)
     return fInput / 1440.0f * DPI * zoom;
 }
 
-static void getTileFunc(GTask* task, gpointer source_object, gpointer task_data, GCancellable*)
+static void getTileFunc(GTask*, gpointer, gpointer task_data, GCancellable*)
 {
     GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels);
     GetTileCallbackData* pCallback = static_cast<GetTileCallbackData*>(task_data);
@@ -96,13 +96,17 @@ void TileBuffer::resetAllTiles()
     }
 }
 
-void TileBuffer::setInvalid(int x, int y)
+void TileBuffer::setInvalid(int x, int y, float fZoom)
 {
     int index = x * m_nWidth + y;
     g_info("Setting tile invalid (%d, %d)", x, y);
     if (m_mTiles.find(index) != m_mTiles.end())
     {
         m_mTiles[index].valid = false;
+        GTask* task = g_task_new(this, NULL, NULL, NULL);
+        GetTileCallbackData* pCallback = new GetTileCallbackData(x, y, fZoom, this);
+        g_task_set_task_data(task, pCallback, g_free);
+        g_task_run_in_thread(task, getTileFunc);
     }
 }
 
@@ -119,33 +123,11 @@ Tile& TileBuffer::getTile(int x, int y, float aZoom, GTask* task)
     }
     else if(m_mTiles.find(index) == m_mTiles.end())
     {
-
-        GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels);
-        if (!pPixBuf)
-        {
-            g_info ("Error allocating memory to pixbuf");
-            return m_mTiles[index];
-        }
-
-        unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
-        GdkRectangle aTileRectangle;
-        aTileRectangle.x = pixelToTwip(nTileSizePixels, aZoom) * y;
-        aTileRectangle.y = pixelToTwip(nTileSizePixels, aZoom) * x;
-
-        g_test_timer_start();
-        m_pLOKDocument->pClass->paintTile(m_pLOKDocument,
-                                          pBuffer,
-                                          nTileSizePixels, nTileSizePixels,
-                                          aTileRectangle.x, aTileRectangle.y,
-                                          pixelToTwip(nTileSizePixels, aZoom),
-                                          pixelToTwip(nTileSizePixels, aZoom));
-
-        double elapsedTime = g_test_timer_elapsed();
-        g_info ("Rendered (%d, %d) in %f seconds", x, y, elapsedTime);
-
-        //create a mapping for it
-        m_mTiles[index].setPixbuf(pPixBuf);
-        m_mTiles[index].valid = true;
+        GetTileCallbackData* pCallback = new GetTileCallbackData(x, y, aZoom, this);
+        g_task_set_task_data(task, pCallback, g_free);
+        g_info ("running in thread new tile");
+        g_task_run_in_thread(task, getTileFunc);
+        return m_DummyTile;
     }
 
     return m_mTiles[index];
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
index 5204d40..50de72d 100644
--- a/libreofficekit/source/gtk/tilebuffer.hxx
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
@@ -118,7 +118,7 @@ class TileBuffer
        @param x the position of tile along x-axis
        @param y the position of tile along y-axis
      */
-    void setInvalid(int x, int y);
+    void setInvalid(int x, int y, float zoom);
 
 
     /// Contains the reference to the LOK Document that this tile buffer is for.
commit a6918763ca5603ca2c7371295a07f4701fc40214
Author: Pranav Kant <pranavk at gnome.org>
Date:   Sun Jul 19 01:03:56 2015 +0530

    WIP: Trying to make paintTile async
    
    Change-Id: I6a1a261709e503a2f286f126f686e23fcdbcf85c

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 08c8485..3662f0d 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -741,6 +741,12 @@ renderGraphicHandle(LOKDocView* pDocView,
     }
 }
 
+static void
+rdcb(GObject* source_object, GAsyncResult* res, gpointer)
+{
+    LOKDocView* pDocView = LOK_DOC_VIEW(source_object);
+    gtk_widget_queue_draw(GTK_WIDGET(pDocView));
+}
 
 static gboolean
 renderDocument(LOKDocView* pDocView, cairo_t* pCairo)
@@ -790,7 +796,9 @@ renderDocument(LOKDocView* pDocView, cairo_t* pCairo)
 
             if (bPaint)
             {
-                Tile& currentTile = priv->m_aTileBuffer.getTile(nRow, nColumn, priv->m_fZoom);
+                GTask* task = g_task_new(pDocView, NULL, rdcb, NULL);
+                Tile& currentTile = priv->m_aTileBuffer.getTile(nRow, nColumn, priv->m_fZoom, task);
+
                 GdkPixbuf* pPixBuf = currentTile.getBuffer();
                 gdk_cairo_set_source_pixbuf (pCairo, pPixBuf,
                                              twipToPixel(aTileRectangleTwips.x, priv->m_fZoom),
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
index 60aa16f..43050c0 100644
--- a/libreofficekit/source/gtk/tilebuffer.cxx
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
@@ -27,6 +27,42 @@ float twipToPixel(float fInput, float zoom)
     return fInput / 1440.0f * DPI * zoom;
 }
 
+static void getTileFunc(GTask* task, gpointer source_object, gpointer task_data, GCancellable*)
+{
+    GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels);
+    GetTileCallbackData* pCallback = static_cast<GetTileCallbackData*>(task_data);
+    TileBuffer* buffer = pCallback->m_pBuffer;
+    int index = pCallback->m_nX * buffer->m_nWidth + pCallback->m_nY;
+    if (!pPixBuf)
+    {
+        g_info ("Error allocating memory to pixbuf");
+        return;
+    }
+
+    unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
+    GdkRectangle aTileRectangle;
+    aTileRectangle.x = pixelToTwip(nTileSizePixels, pCallback->m_fZoom) * pCallback->m_nY;
+    aTileRectangle.y = pixelToTwip(nTileSizePixels, pCallback->m_fZoom) * pCallback->m_nX;
+
+    g_test_timer_start();
+    buffer->m_pLOKDocument->pClass->paintTile(buffer->m_pLOKDocument,
+                                      pBuffer,
+                                      nTileSizePixels, nTileSizePixels,
+                                      aTileRectangle.x, aTileRectangle.y,
+                                      pixelToTwip(nTileSizePixels, pCallback->m_fZoom),
+                                      pixelToTwip(nTileSizePixels, pCallback->m_fZoom));
+
+    double elapsedTime = g_test_timer_elapsed();
+    g_info ("Rendered (%d, %d) in %f seconds",
+            pCallback->m_nX,
+            pCallback->m_nY,
+            elapsedTime);
+
+    //create a mapping for it
+    buffer->m_mTiles[index].setPixbuf(pPixBuf);
+    buffer->m_mTiles[index].valid = true;
+}
+
 /* ----------------------------
    Tile class member functions
    ----------------------------
@@ -56,9 +92,8 @@ void TileBuffer::resetAllTiles()
     std::map<int, Tile>::iterator it = m_mTiles.begin();
     for (; it != m_mTiles.end(); ++it)
     {
-        it->second.release();
+        it->second.valid = false;
     }
-    m_mTiles.clear();
 }
 
 void TileBuffer::setInvalid(int x, int y)
@@ -68,15 +103,21 @@ void TileBuffer::setInvalid(int x, int y)
     if (m_mTiles.find(index) != m_mTiles.end())
     {
         m_mTiles[index].valid = false;
-        m_mTiles[index].release();
-        m_mTiles.erase(index);
     }
 }
 
-Tile& TileBuffer::getTile(int x, int y, float aZoom)
+Tile& TileBuffer::getTile(int x, int y, float aZoom, GTask* task)
 {
     int index = x * m_nWidth + y;
-    if(m_mTiles.find(index) == m_mTiles.end() || !m_mTiles[index].valid)
+
+    if (m_mTiles.find(index) != m_mTiles.end() && !m_mTiles[index].valid)
+    {
+        GetTileCallbackData* pCallback = new GetTileCallbackData(x, y, aZoom, this);
+        g_task_set_task_data(task, pCallback, g_free);
+        g_task_run_in_thread(task, getTileFunc);
+        return m_mTiles[index];
+    }
+    else if(m_mTiles.find(index) == m_mTiles.end())
     {
 
         GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels);
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
index 6e6c0be..5204d40 100644
--- a/libreofficekit/source/gtk/tilebuffer.hxx
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
@@ -86,7 +86,10 @@ class TileBuffer
             int columns)
      : m_pLOKDocument(document)
         , m_nWidth(columns)
-    {  }
+    {
+        GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels);
+        m_DummyTile.setPixbuf(pPixBuf);
+    }
 
     ~TileBuffer() {}
 
@@ -104,7 +107,7 @@ class TileBuffer
 
        @return the tile at the mentioned position (x, y)
      */
-    Tile& getTile(int x, int y, float aZoom);
+    Tile& getTile(int x, int y, float aZoom, GTask*);
     /// Destroys all the tiles in the tile buffer; also frees the memory allocated
     /// for all the Tile objects.
     void resetAllTiles();
@@ -117,15 +120,32 @@ class TileBuffer
      */
     void setInvalid(int x, int y);
 
- private:
+
     /// Contains the reference to the LOK Document that this tile buffer is for.
     LibreOfficeKitDocument *m_pLOKDocument;
     /// Stores all the tiles cached by this tile buffer.
     std::map<int, Tile> m_mTiles;
     /// Width of the current tile buffer (number of columns)
     int m_nWidth;
+    /// Dummy tile
+    Tile m_DummyTile;
 };
 
+struct GetTileCallbackData
+{
+    int m_nX;
+    int m_nY;
+    float m_fZoom;
+    TileBuffer* m_pBuffer;
+
+    GetTileCallbackData(int x, int y, float zoom, TileBuffer* buffer)
+        : m_nX(x),
+          m_nY(y),
+          m_fZoom(zoom),
+          m_pBuffer(buffer) { }
+};
+
+
 #endif // INCLUDED_TILEBUFFER_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list