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

lokdocview: Use maps instead of vector

Using vector each tile needs to be allocated memory irrespective of
whether tile is required or not. This approach fails when we zoom in to
a very high level to have thousands of tiles due to lot of memory
required. Using maps instead of vector takes care of this, and only
allocates Tiles when required.

Change-Id: I523f815618451a7f014e28258e0de7b1c0693370
üst 42dc4f3e
......@@ -41,22 +41,22 @@ void TileBuffer::tile_buffer_set_zoom(float newZoomFactor, int rows, int columns
// set new buffer width and height
m_nWidth = columns;
m_nHeight = rows;
m_aTiles.resize(m_nWidth * m_nHeight);
}
void TileBuffer::tile_buffer_reset_all_tiles()
{
for (size_t i = 0; i < m_aTiles.size(); i++)
std::map<int, Tile>::iterator it = m_mTiles.begin();
for (; it != m_mTiles.end(); it++)
{
m_aTiles[i].tile_release();
it->second.tile_release();
}
m_aTiles.clear();
m_mTiles.clear();
}
Tile& TileBuffer::tile_buffer_get_tile(int x, int y)
{
int index = x * m_nWidth + y;
if(!m_aTiles[index].valid)
if(m_mTiles.find(index) == m_mTiles.end())
{
GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, m_nTileSize, m_nTileSize);
if (!pPixBuf){
......@@ -77,11 +77,12 @@ Tile& TileBuffer::tile_buffer_get_tile(int x, int y)
// Size of the tile, depends on the zoom factor and the tile position only.
pixelToTwip(m_nTileSize, m_fZoomFactor), pixelToTwip(m_nTileSize, m_fZoomFactor));
m_aTiles[index].tile_set_pixbuf(pPixBuf);
m_aTiles[index].valid = 1;
//create a mapping for it
m_mTiles[index].tile_set_pixbuf(pPixBuf);
m_mTiles[index].valid = 1;
}
return m_aTiles[index];
return m_mTiles[index];
}
void Tile::tile_set_pixbuf(GdkPixbuf *buffer)
......
......@@ -12,7 +12,7 @@
#include <gdk/gdkkeysyms.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <vector>
#include <map>
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKit.h>
......@@ -55,9 +55,7 @@ public:
, m_fZoomFactor(1)
, m_nWidth(columns)
, m_nHeight(rows)
{
m_aTiles.resize(rows * columns);
}
{ }
~TileBuffer() {}
......@@ -69,7 +67,7 @@ private:
LibreOfficeKitDocument *m_pLOKDocument;
int m_nTileSize;
float m_fZoomFactor;
std::vector<Tile> m_aTiles;
std::map<int, Tile> m_mTiles;
//TODO: Also set width and height when document size changes
int m_nWidth;
int m_nHeight;
......
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