libreofficekit/source/gtk/lokdocview.cxx | 10 +++++- libreofficekit/source/gtk/tilebuffer.cxx | 48 +++++++++++++++++++++++++++++-- libreofficekit/source/gtk/tilebuffer.hxx | 19 ++++++++++-- 3 files changed, 72 insertions(+), 5 deletions(-)
New commits: commit aa8e645df85fbf1ea9695c90c2a0c6317367557b Author: Pranav Kant <[email protected]> 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..9923484 100644 --- a/libreofficekit/source/gtk/tilebuffer.cxx +++ b/libreofficekit/source/gtk/tilebuffer.cxx @@ -73,10 +73,54 @@ void TileBuffer::setInvalid(int x, int y) } } -Tile& TileBuffer::getTile(int x, int y, float aZoom) +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& 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[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..ee8bef7 100644 --- a/libreofficekit/source/gtk/tilebuffer.hxx +++ b/libreofficekit/source/gtk/tilebuffer.hxx @@ -104,7 +104,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,7 +117,7 @@ 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. @@ -126,6 +126,21 @@ class TileBuffer int m_nWidth; }; +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: */ _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
