Kaydet (Commit) cfbc36e2 authored tarafından Pranav Kant's avatar Pranav Kant Kaydeden (comit) Miklos Vajna

lokdocview: Fix memory leaks

Change-Id: I5107e4fa1828145a709e1edffe02831f4faae3c8
Reviewed-on: https://gerrit.libreoffice.org/19676Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 2b9a5748
...@@ -50,7 +50,7 @@ struct LOKDocViewPrivateImpl ...@@ -50,7 +50,7 @@ struct LOKDocViewPrivateImpl
LibreOfficeKit* m_pOffice; LibreOfficeKit* m_pOffice;
LibreOfficeKitDocument* m_pDocument; LibreOfficeKitDocument* m_pDocument;
TileBuffer m_aTileBuffer; std::unique_ptr<TileBuffer> m_pTileBuffer;
GThreadPool* lokThreadPool; GThreadPool* lokThreadPool;
gfloat m_fZoom; gfloat m_fZoom;
...@@ -503,9 +503,8 @@ static gboolean postDocumentLoad(gpointer pData) ...@@ -503,9 +503,8 @@ static gboolean postDocumentLoad(gpointer pData)
// Total number of columns in this document. // Total number of columns in this document.
guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels); guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
priv->m_pTileBuffer = std::unique_ptr<TileBuffer>(new TileBuffer(priv->m_pDocument,
priv->m_aTileBuffer = TileBuffer(priv->m_pDocument, nColumns));
nColumns);
gtk_widget_set_size_request(GTK_WIDGET(pLOKDocView), gtk_widget_set_size_request(GTK_WIDGET(pLOKDocView),
nDocumentWidthPixels, nDocumentWidthPixels,
nDocumentHeightPixels); nDocumentHeightPixels);
...@@ -634,7 +633,7 @@ setTilesInvalid (LOKDocView* pDocView, const GdkRectangle& rRectangle) ...@@ -634,7 +633,7 @@ setTilesInvalid (LOKDocView* pDocView, const GdkRectangle& rRectangle)
for (int j = aStart.y; j < aEnd.y; j++) for (int j = aStart.y; j < aEnd.y; j++)
{ {
GTask* task = g_task_new(pDocView, NULL, NULL, NULL); GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
priv->m_aTileBuffer.setInvalid(i, j, priv->m_fZoom, task, priv->lokThreadPool); priv->m_pTileBuffer->setInvalid(i, j, priv->m_fZoom, task, priv->lokThreadPool);
g_object_unref(task); g_object_unref(task);
} }
} }
...@@ -657,7 +656,7 @@ callback (gpointer pData) ...@@ -657,7 +656,7 @@ callback (gpointer pData)
setTilesInvalid(pDocView, aRectangle); setTilesInvalid(pDocView, aRectangle);
} }
else else
priv->m_aTileBuffer.resetAllTiles(); priv->m_pTileBuffer->resetAllTiles();
gtk_widget_queue_draw(GTK_WIDGET(pDocView)); gtk_widget_queue_draw(GTK_WIDGET(pDocView));
} }
...@@ -923,7 +922,7 @@ renderDocument(LOKDocView* pDocView, cairo_t* pCairo) ...@@ -923,7 +922,7 @@ renderDocument(LOKDocView* pDocView, cairo_t* pCairo)
if (bPaint) if (bPaint)
{ {
GTask* task = g_task_new(pDocView, NULL, NULL, NULL); GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
Tile& currentTile = priv->m_aTileBuffer.getTile(nRow, nColumn, priv->m_fZoom, task, priv->lokThreadPool); Tile& currentTile = priv->m_pTileBuffer->getTile(nRow, nColumn, priv->m_fZoom, task, priv->lokThreadPool);
GdkPixbuf* pPixBuf = currentTile.getBuffer(); GdkPixbuf* pPixBuf = currentTile.getBuffer();
gdk_cairo_set_source_pixbuf (pCairo, pPixBuf, gdk_cairo_set_source_pixbuf (pCairo, pPixBuf,
twipToPixel(aTileRectangleTwips.x, priv->m_fZoom), twipToPixel(aTileRectangleTwips.x, priv->m_fZoom),
...@@ -1484,10 +1483,10 @@ paintTileInThread (gpointer data) ...@@ -1484,10 +1483,10 @@ paintTileInThread (gpointer data)
LOKDocView* pDocView = LOK_DOC_VIEW(g_task_get_source_object(task)); LOKDocView* pDocView = LOK_DOC_VIEW(g_task_get_source_object(task));
LOKDocViewPrivate& priv = getPrivate(pDocView); LOKDocViewPrivate& priv = getPrivate(pDocView);
LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task)); LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task));
TileBuffer& buffer = priv->m_aTileBuffer; std::unique_ptr<TileBuffer>& buffer = priv->m_pTileBuffer;
int index = pLOEvent->m_nPaintTileX * buffer.m_nWidth + pLOEvent->m_nPaintTileY; int index = pLOEvent->m_nPaintTileX * buffer->m_nWidth + pLOEvent->m_nPaintTileY;
if (buffer.m_mTiles.find(index) != buffer.m_mTiles.end() && if (buffer->m_mTiles.find(index) != buffer->m_mTiles.end() &&
buffer.m_mTiles[index].valid) buffer->m_mTiles[index].valid)
return; return;
GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels); GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels);
...@@ -1518,9 +1517,11 @@ paintTileInThread (gpointer data) ...@@ -1518,9 +1517,11 @@ paintTileInThread (gpointer data)
pixelToTwip(nTileSizePixels, pLOEvent->m_fPaintTileZoom)); pixelToTwip(nTileSizePixels, pLOEvent->m_fPaintTileZoom));
//create a mapping for it //create a mapping for it
buffer.m_mTiles[index].setPixbuf(pPixBuf); buffer->m_mTiles[index].setPixbuf(pPixBuf);
buffer.m_mTiles[index].valid = true; buffer->m_mTiles[index].valid = true;
gdk_threads_add_idle(queueDraw, GTK_WIDGET(pDocView)); gdk_threads_add_idle(queueDraw, GTK_WIDGET(pDocView));
g_object_unref(pPixBuf);
} }
...@@ -2129,8 +2130,8 @@ lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom) ...@@ -2129,8 +2130,8 @@ lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom)
// Total number of columns in this document. // Total number of columns in this document.
guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels); guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
priv->m_aTileBuffer = TileBuffer(priv->m_pDocument, priv->m_pTileBuffer = std::unique_ptr<TileBuffer>(new TileBuffer(priv->m_pDocument,
nColumns); nColumns));
gtk_widget_set_size_request(GTK_WIDGET(pDocView), gtk_widget_set_size_request(GTK_WIDGET(pDocView),
nDocumentWidthPixels, nDocumentWidthPixels,
nDocumentHeightPixels); nDocumentHeightPixels);
...@@ -2211,7 +2212,7 @@ SAL_DLLPUBLIC_EXPORT void ...@@ -2211,7 +2212,7 @@ SAL_DLLPUBLIC_EXPORT void
lok_doc_view_reset_view(LOKDocView* pDocView) lok_doc_view_reset_view(LOKDocView* pDocView)
{ {
LOKDocViewPrivate& priv = getPrivate(pDocView); LOKDocViewPrivate& priv = getPrivate(pDocView);
priv->m_aTileBuffer.resetAllTiles(); priv->m_pTileBuffer->resetAllTiles();
priv->m_nLoadProgress = 0.0; priv->m_nLoadProgress = 0.0;
memset(&priv->m_aVisibleCursor, 0, sizeof(priv->m_aVisibleCursor)); memset(&priv->m_aVisibleCursor, 0, sizeof(priv->m_aVisibleCursor));
......
...@@ -35,6 +35,11 @@ GdkPixbuf* Tile::getBuffer() ...@@ -35,6 +35,11 @@ GdkPixbuf* Tile::getBuffer()
void Tile::setPixbuf(GdkPixbuf *buffer) void Tile::setPixbuf(GdkPixbuf *buffer)
{ {
if (m_pBuffer == buffer)
return;
g_clear_object(&m_pBuffer);
if (buffer != NULL)
g_object_ref(buffer);
m_pBuffer = buffer; m_pBuffer = buffer;
} }
......
...@@ -52,7 +52,10 @@ class Tile ...@@ -52,7 +52,10 @@ class Tile
{ {
public: public:
Tile() : valid(false), m_pBuffer(0) {} Tile() : valid(false), m_pBuffer(0) {}
~Tile() { } ~Tile()
{
g_clear_object(&m_pBuffer);
}
/** /**
Tells if this tile is valid or not. Initialised to 0 (invalid) during Tells if this tile is valid or not. Initialised to 0 (invalid) during
...@@ -83,10 +86,11 @@ class TileBuffer ...@@ -83,10 +86,11 @@ class TileBuffer
TileBuffer(LibreOfficeKitDocument *document = 0, TileBuffer(LibreOfficeKitDocument *document = 0,
int columns = 0) int columns = 0)
: m_pLOKDocument(document) : m_pLOKDocument(document)
, m_nWidth(columns) , m_nWidth(columns)
{ {
GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels); GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels);
m_DummyTile.setPixbuf(pPixBuf); m_DummyTile.setPixbuf(pPixBuf);
g_object_unref(pPixBuf);
} }
~TileBuffer() {} ~TileBuffer() {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment