|
|
135360 |
From a8675df04f316dce72483c62f578467dfb446493 Mon Sep 17 00:00:00 2001
|
|
|
135360 |
From: Pranav Kant <pranavk@gnome.org>
|
|
|
135360 |
Date: Thu, 4 Jun 2015 01:44:47 +0530
|
|
|
135360 |
Subject: [PATCH 013/398] lokdocview: Use maps instead of vector
|
|
|
135360 |
|
|
|
135360 |
Using vector each tile needs to be allocated memory irrespective of
|
|
|
135360 |
whether tile is required or not. This approach fails when we zoom in to
|
|
|
135360 |
a very high level to have thousands of tiles due to lot of memory
|
|
|
135360 |
required. Using maps instead of vector takes care of this, and only
|
|
|
135360 |
allocates Tiles when required.
|
|
|
135360 |
|
|
|
135360 |
Change-Id: I523f815618451a7f014e28258e0de7b1c0693370
|
|
|
135360 |
(cherry picked from commit cc78267f274a42d268b1d56d0a83888dc69a4c91)
|
|
|
135360 |
---
|
|
|
135360 |
libreofficekit/source/gtk/tilebuffer.cxx | 17 +++++++++--------
|
|
|
135360 |
libreofficekit/source/gtk/tilebuffer.hxx | 8 +++-----
|
|
|
135360 |
2 files changed, 12 insertions(+), 13 deletions(-)
|
|
|
135360 |
|
|
|
135360 |
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
|
|
|
135360 |
index ca66ae904f71..e1b5b3294cc5 100644
|
|
|
135360 |
--- a/libreofficekit/source/gtk/tilebuffer.cxx
|
|
|
135360 |
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
|
|
|
135360 |
@@ -41,22 +41,22 @@ void TileBuffer::tile_buffer_set_zoom(float newZoomFactor, int rows, int columns
|
|
|
135360 |
// set new buffer width and height
|
|
|
135360 |
m_nWidth = columns;
|
|
|
135360 |
m_nHeight = rows;
|
|
|
135360 |
- m_aTiles.resize(m_nWidth * m_nHeight);
|
|
|
135360 |
}
|
|
|
135360 |
|
|
|
135360 |
void TileBuffer::tile_buffer_reset_all_tiles()
|
|
|
135360 |
{
|
|
|
135360 |
- for (size_t i = 0; i < m_aTiles.size(); i++)
|
|
|
135360 |
+ std::map<int, Tile>::iterator it = m_mTiles.begin();
|
|
|
135360 |
+ for (; it != m_mTiles.end(); it++)
|
|
|
135360 |
{
|
|
|
135360 |
- m_aTiles[i].tile_release();
|
|
|
135360 |
+ it->second.tile_release();
|
|
|
135360 |
}
|
|
|
135360 |
- m_aTiles.clear();
|
|
|
135360 |
+ m_mTiles.clear();
|
|
|
135360 |
}
|
|
|
135360 |
|
|
|
135360 |
Tile& TileBuffer::tile_buffer_get_tile(int x, int y)
|
|
|
135360 |
{
|
|
|
135360 |
int index = x * m_nWidth + y;
|
|
|
135360 |
- if(!m_aTiles[index].valid)
|
|
|
135360 |
+ if(m_mTiles.find(index) == m_mTiles.end())
|
|
|
135360 |
{
|
|
|
135360 |
GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, m_nTileSize, m_nTileSize);
|
|
|
135360 |
if (!pPixBuf){
|
|
|
135360 |
@@ -77,11 +77,12 @@ Tile& TileBuffer::tile_buffer_get_tile(int x, int y)
|
|
|
135360 |
// Size of the tile, depends on the zoom factor and the tile position only.
|
|
|
135360 |
pixelToTwip(m_nTileSize, m_fZoomFactor), pixelToTwip(m_nTileSize, m_fZoomFactor));
|
|
|
135360 |
|
|
|
135360 |
- m_aTiles[index].tile_set_pixbuf(pPixBuf);
|
|
|
135360 |
- m_aTiles[index].valid = 1;
|
|
|
135360 |
+ //create a mapping for it
|
|
|
135360 |
+ m_mTiles[index].tile_set_pixbuf(pPixBuf);
|
|
|
135360 |
+ m_mTiles[index].valid = 1;
|
|
|
135360 |
}
|
|
|
135360 |
|
|
|
135360 |
- return m_aTiles[index];
|
|
|
135360 |
+ return m_mTiles[index];
|
|
|
135360 |
}
|
|
|
135360 |
|
|
|
135360 |
void Tile::tile_set_pixbuf(GdkPixbuf *buffer)
|
|
|
135360 |
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
|
|
|
135360 |
index a5ed0dc8ec61..0bc2d38dd641 100644
|
|
|
135360 |
--- a/libreofficekit/source/gtk/tilebuffer.hxx
|
|
|
135360 |
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
|
|
|
135360 |
@@ -12,7 +12,7 @@
|
|
|
135360 |
|
|
|
135360 |
#include <gdk/gdkkeysyms.h>
|
|
|
135360 |
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
135360 |
-#include <vector>
|
|
|
135360 |
+#include <map>
|
|
|
135360 |
|
|
|
135360 |
#define LOK_USE_UNSTABLE_API
|
|
|
135360 |
#include <LibreOfficeKit/LibreOfficeKit.h>
|
|
|
135360 |
@@ -55,9 +55,7 @@ public:
|
|
|
135360 |
, m_fZoomFactor(1)
|
|
|
135360 |
, m_nWidth(columns)
|
|
|
135360 |
, m_nHeight(rows)
|
|
|
135360 |
- {
|
|
|
135360 |
- m_aTiles.resize(rows * columns);
|
|
|
135360 |
- }
|
|
|
135360 |
+ { }
|
|
|
135360 |
|
|
|
135360 |
~TileBuffer() {}
|
|
|
135360 |
|
|
|
135360 |
@@ -69,7 +67,7 @@ private:
|
|
|
135360 |
LibreOfficeKitDocument *m_pLOKDocument;
|
|
|
135360 |
int m_nTileSize;
|
|
|
135360 |
float m_fZoomFactor;
|
|
|
135360 |
- std::vector<Tile> m_aTiles;
|
|
|
135360 |
+ std::map<int, Tile> m_mTiles;
|
|
|
135360 |
//TODO: Also set width and height when document size changes
|
|
|
135360 |
int m_nWidth;
|
|
|
135360 |
int m_nHeight;
|
|
|
135360 |
--
|
|
|
135360 |
2.12.0
|
|
|
135360 |
|