Files
libreoffice/libreofficekit/source/gtk/tilebuffer.cxx
Pranav Kant de0c7e1783 lokdocview: Separate "painting" and "saving" of tiles
Lets separate the task of painting the tile, and saving the tile
in tile buffer using GAsyncReadyCallback. This will provide us
with better control over tiles -- cancelling the painting operation,
and filtering tiles that should not be saved in the tile buffer.

Change-Id: I6aae928d8cc0c906034570ed0e9a054763d493a3
Reviewed-on: https://gerrit.libreoffice.org/19725
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
2015-11-03 10:18:29 +00:00

119 lines
3.0 KiB
C++

/* -*- 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"
/* ------------------
Utility functions
------------------
*/
float pixelToTwip(float fInput, float zoom)
{
return (fInput / DPI / zoom) * 1440.0f;
}
float twipToPixel(float fInput, float zoom)
{
return fInput / 1440.0f * DPI * zoom;
}
/* ----------------------------
Tile class member functions
----------------------------
*/
GdkPixbuf* Tile::getBuffer()
{
return m_pBuffer;
}
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;
}
/* ----------------------------------
TileBuffer class member functions
----------------------------------
*/
void TileBuffer::resetAllTiles()
{
std::map<int, Tile>::iterator it = m_mTiles.begin();
for (; it != m_mTiles.end(); ++it)
{
it->second.valid = false;
}
}
void TileBuffer::setInvalid(int x, int y, float fZoom, GTask* task,
GThreadPool* lokThreadPool)
{
int index = x * m_nWidth + y;
GError* error = NULL;
if (m_mTiles.find(index) != m_mTiles.end())
{
m_mTiles[index].valid = false;
LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE);
pLOEvent->m_nPaintTileX = x;
pLOEvent->m_nPaintTileY = y;
pLOEvent->m_fPaintTileZoom = fZoom;
g_task_set_task_data(task, pLOEvent, LOEvent::destroy);
g_thread_pool_push(lokThreadPool, g_object_ref(task), &error);
if (error != NULL)
{
g_warning("Unable to call LOK_PAINT_TILE: %s", error->message);
g_clear_error(&error);
}
}
}
Tile& TileBuffer::getTile(int x, int y, float fZoom, GTask* task,
GThreadPool* lokThreadPool)
{
int index = x * m_nWidth + y;
GError* error = NULL;
if (m_mTiles.find(index) != m_mTiles.end() && !m_mTiles[index].valid)
{
g_thread_pool_push(lokThreadPool, g_object_ref(task), &error);
if (error != NULL)
{
g_warning("Unable to call LOK_PAINT_TILE: %s", error->message);
g_clear_error(&error);
}
return m_mTiles[index];
}
else if(m_mTiles.find(index) == m_mTiles.end())
{
g_thread_pool_push(lokThreadPool, g_object_ref(task), &error);
if (error != NULL)
{
g_warning("Unable to call LOK_PAINT_TILE: %s", error->message);
g_clear_error(&error);
}
return m_DummyTile;
}
return m_mTiles[index];
}
void LOEvent::destroy(void* pMemory)
{
LOEvent* pLOEvent = static_cast<LOEvent*>(pMemory);
delete pLOEvent;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */