From 52f1f622d742bd6064375484e40d3105d0110e87 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Tue, 12 Nov 2019 21:18:16 +0000 Subject: lokdocview: encapsulate tile buffer properly. Change-Id: I59d690fbde67f4985246f13b992e962d11b7b07f Reviewed-on: https://gerrit.libreoffice.org/82556 Reviewed-by: Michael Meeks Tested-by: Michael Meeks --- libreofficekit/source/gtk/lokdocview.cxx | 9 ++------- libreofficekit/source/gtk/tilebuffer.cxx | 15 +++++++++++++++ libreofficekit/source/gtk/tilebuffer.hxx | 10 ++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) (limited to 'libreofficekit') diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 1e989d03f5ae..6f12438fde57 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -1533,7 +1533,6 @@ paintTileCallback(GObject* sourceObject, GAsyncResult* res, gpointer userData) LOKDocViewPrivate& priv = getPrivate(pDocView); LOEvent* pLOEvent = static_cast(userData); std::unique_ptr& buffer = priv->m_pTileBuffer; - int index = pLOEvent->m_nPaintTileX * buffer->m_nWidth + pLOEvent->m_nPaintTileY; GError* error; error = nullptr; @@ -1550,8 +1549,7 @@ paintTileCallback(GObject* sourceObject, GAsyncResult* res, gpointer userData) return; } - buffer->m_mTiles[index].setSurface(pSurface); - buffer->m_mTiles[index].valid = true; + buffer->setTile(pLOEvent->m_nPaintTileX, pLOEvent->m_nPaintTileY, pSurface); gdk_threads_add_idle(queueDraw, GTK_WIDGET(pDocView)); cairo_surface_destroy(pSurface); @@ -2338,9 +2336,7 @@ paintTileInThread (gpointer data) return; } std::unique_ptr& buffer = priv->m_pTileBuffer; - int index = pLOEvent->m_nPaintTileX * buffer->m_nWidth + pLOEvent->m_nPaintTileY; - if (buffer->m_mTiles.find(index) != buffer->m_mTiles.end() && - buffer->m_mTiles[index].valid) + if (buffer->hasValidTile(pLOEvent->m_nPaintTileX, pLOEvent->m_nPaintTileY)) return; cairo_surface_t *pSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, nTileSizePixels, nTileSizePixels); @@ -3511,7 +3507,6 @@ lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom) long nDocumentHeightPixels = twipToPixel(priv->m_nDocumentHeightTwips, fZoom); // Total number of columns in this document. guint nColumns = ceil(static_cast(nDocumentWidthPixels) / nTileSizePixels); - priv->m_pTileBuffer = std::unique_ptr(new TileBuffer(nColumns)); gtk_widget_set_size_request(GTK_WIDGET(pDocView), nDocumentWidthPixels, diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx index 9085ba06ac2c..82f0253d9e82 100644 --- a/libreofficekit/source/gtk/tilebuffer.cxx +++ b/libreofficekit/source/gtk/tilebuffer.cxx @@ -109,6 +109,21 @@ Tile& TileBuffer::getTile(int x, int y, GTask* task, return m_mTiles[index]; } +void TileBuffer::setTile(int x, int y, cairo_surface_t *surface) +{ + int index = x * m_nWidth + y; + + m_mTiles[index].setSurface(surface); + m_mTiles[index].valid = true; +} + +bool TileBuffer::hasValidTile(int x, int y) +{ + int index = x * m_nWidth + y; + auto it = m_mTiles.find(index); + return (it != m_mTiles.end()) && it->second.valid; +} + void LOEvent::destroy(void* pMemory) { LOEvent* pLOEvent = static_cast(pMemory); diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx index 88961cc1f44d..fccc6211acc3 100644 --- a/libreofficekit/source/gtk/tilebuffer.hxx +++ b/libreofficekit/source/gtk/tilebuffer.hxx @@ -116,6 +116,15 @@ class TileBuffer @return the tile at the mentioned position (x, y) */ Tile& getTile(int x, int y, GTask* task, GThreadPool* pool); + + /* + Takes ownership of the surface and sets it on a tile at a given location + */ + void setTile(int x, int y, cairo_surface_t *surface); + + /// Returns true if a valid tile exists at this location + bool hasValidTile(int x, int y); + /// Destroys all the tiles in the tile buffer; also frees the memory allocated /// for all the Tile objects. void resetAllTiles(); @@ -133,6 +142,7 @@ class TileBuffer */ void setInvalid(int x, int y, float zoom, GTask* task, GThreadPool*); +private: /// Stores all the tiles cached by this tile buffer. std::map m_mTiles; /// Width of the current tile buffer (number of columns) -- cgit