summaryrefslogtreecommitdiff
path: root/libreofficekit/source/gtk/tilebuffer.cxx
diff options
context:
space:
mode:
authorPranav Kant <pranavk@gnome.org>2015-06-04 00:06:46 +0530
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-06-09 10:44:21 +0200
commit42dc4f3ed8b7b41597dd9851c31dee4d0e352f46 (patch)
treeed27bc3f45cd0ed9678f56260fa978b696af1886 /libreofficekit/source/gtk/tilebuffer.cxx
parenta13d4671bf1f557b3104e745277554ed11b3e6da (diff)
Add tile buffering support
The TileBuffer class now manages all the tiles. The tile rendering calls to LO core is also managed by this class. Change-Id: Ic667a93dcf1c097e0601c0496e8a083c4742e8cb
Diffstat (limited to 'libreofficekit/source/gtk/tilebuffer.cxx')
-rw-r--r--libreofficekit/source/gtk/tilebuffer.cxx90
1 files changed, 90 insertions, 0 deletions
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
new file mode 100644
index 000000000000..ca66ae904f71
--- /dev/null
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
@@ -0,0 +1,90 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "tilebuffer.hxx"
+
+static const int DPI = 96;
+
+static float pixelToTwip(float fInput, float zoom)
+{
+ return (fInput / DPI / zoom) * 1440.0f;
+}
+
+static float twipToPixel(float fInput, float zoom)
+{
+ return fInput / 1440.0f * DPI * zoom;
+}
+
+GdkPixbuf* Tile::tile_get_buffer()
+{
+ return m_pBuffer;
+}
+
+void Tile::tile_release()
+{
+ gdk_pixbuf_unref(m_pBuffer);
+ m_pBuffer = NULL;
+}
+
+void TileBuffer::tile_buffer_set_zoom(float newZoomFactor, int rows, int columns)
+{
+ m_fZoomFactor = newZoomFactor;
+
+ tile_buffer_reset_all_tiles();
+
+ // 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++)
+ {
+ m_aTiles[i].tile_release();
+ }
+ m_aTiles.clear();
+}
+
+Tile& TileBuffer::tile_buffer_get_tile(int x, int y)
+{
+ int index = x * m_nWidth + y;
+ if(!m_aTiles[index].valid)
+ {
+ GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, m_nTileSize, m_nTileSize);
+ if (!pPixBuf){
+ g_info ("error allocating memory to pixbuf");
+ }
+ unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
+ GdkRectangle aTileRectangle;
+ aTileRectangle.x = pixelToTwip(m_nTileSize, m_fZoomFactor) * y;
+ aTileRectangle.y = pixelToTwip(m_nTileSize, m_fZoomFactor) * x;
+
+ g_info ("rendering (%d %d)", x, y);
+ m_pLOKDocument->pClass->paintTile(m_pLOKDocument,
+ // Buffer and its size, depends on the position only.
+ pBuffer,
+ m_nTileSize, m_nTileSize,
+ // Position of the tile.
+ aTileRectangle.x, aTileRectangle.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;
+ }
+
+ return m_aTiles[index];
+}
+
+void Tile::tile_set_pixbuf(GdkPixbuf *buffer)
+{
+ m_pBuffer = buffer;
+}