Rebased ref, commits from common ancestor: commit 00d94c3a423ab524f0b47c265eeea09f97f0424e Author: Pranav Kant <pran...@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..763da59 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 diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx index 7815aa1..1cb2465 100644 --- a/libreofficekit/source/gtk/tilebuffer.cxx +++ b/libreofficekit/source/gtk/tilebuffer.cxx @@ -61,15 +61,7 @@ void TileBuffer::resetAllTiles() m_mTiles.clear(); } -void TileBuffer::setInvalid(int x, int y) -{ - 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; - } -} + static void getTileFunc(GTask* task, gpointer source_object, gpointer task_data, GCancellable*) { @@ -107,47 +99,38 @@ static void getTileFunc(GTask* task, gpointer source_object, gpointer task_data, buffer->m_mTiles[index].valid = true; } +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); + } +} + 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_info ("running in thread"); g_task_run_in_thread(task, getTileFunc); return m_mTiles[index]; } - else if(m_mTiles.find(index) == m_mTiles.end()) + 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 ab6486c68811db815c95195d3401911d6b5562f2 Author: Pranav Kant <pran...@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..7815aa1 100644 --- a/libreofficekit/source/gtk/tilebuffer.cxx +++ b/libreofficekit/source/gtk/tilebuffer.cxx @@ -68,15 +68,58 @@ 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) +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.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_info ("running in thread"); + 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: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits