[Libreoffice-commits] core.git: Branch 'feature/gsoc-tiled-rendering' - libreofficekit/source

Pranav Kant pranavk at gnome.org
Wed Jun 3 13:20:59 PDT 2015


 libreofficekit/source/gtk/tilebuffer.cxx |   17 +++++++++--------
 libreofficekit/source/gtk/tilebuffer.hxx |    8 +++-----
 2 files changed, 12 insertions(+), 13 deletions(-)

New commits:
commit 99070af0cdda393f5edc4601d37e9947b3afceb5
Author: Pranav Kant <pranavk at gnome.org>
Date:   Thu Jun 4 01:44:47 2015 +0530

    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

diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
index ca66ae90..e1b5b32 100644
--- a/libreofficekit/source/gtk/tilebuffer.cxx
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
@@ -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)
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
index a5ed0dc..0bc2d38 100644
--- a/libreofficekit/source/gtk/tilebuffer.hxx
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
@@ -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;


More information about the Libreoffice-commits mailing list