summaryrefslogtreecommitdiffstats
path: root/libreofficekit
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2019-11-12 21:18:16 +0000
committerMichael Meeks <michael.meeks@collabora.com>2019-11-13 11:23:59 +0100
commit1654152b5ed110b8bec491fd300257f09ed77504 (patch)
treeb71bbf5b199d8fbf3ea98352661bc0a400dea042 /libreofficekit
parentlok: calc: switch row / column / grouping data to pixels. (diff)
downloadcore-1654152b5ed110b8bec491fd300257f09ed77504.tar.gz
core-1654152b5ed110b8bec491fd300257f09ed77504.zip
lokdocview: encapsulate tile buffer properly.
Change-Id: I59d690fbde67f4985246f13b992e962d11b7b07f Reviewed-on: https://gerrit.libreoffice.org/82573 Tested-by: Jenkins Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/source/gtk/lokdocview.cxx9
-rw-r--r--libreofficekit/source/gtk/tilebuffer.cxx15
-rw-r--r--libreofficekit/source/gtk/tilebuffer.hxx10
3 files changed, 27 insertions, 7 deletions
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 0e710d5faf27..2c2951637f01 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -1538,7 +1538,6 @@ paintTileCallback(GObject* sourceObject, GAsyncResult* res, gpointer userData)
LOKDocViewPrivate& priv = getPrivate(pDocView);
LOEvent* pLOEvent = static_cast<LOEvent*>(userData);
std::unique_ptr<TileBuffer>& buffer = priv->m_pTileBuffer;
- int index = pLOEvent->m_nPaintTileX * buffer->m_nWidth + pLOEvent->m_nPaintTileY;
GError* error;
error = nullptr;
@@ -1555,8 +1554,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);
@@ -2343,9 +2341,7 @@ paintTileInThread (gpointer data)
return;
}
std::unique_ptr<TileBuffer>& 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);
@@ -3516,7 +3512,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<double>(nDocumentWidthPixels) / nTileSizePixels);
-
priv->m_pTileBuffer = std::make_unique<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<LOEvent*>(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<int, Tile> m_mTiles;
/// Width of the current tile buffer (number of columns)