build fix
[LibreOffice.git] / libreofficekit / source / gtk / tilebuffer.cxx
blobbded6b1ad85363315f5b920ad0ee3625745628a5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "tilebuffer.hxx"
13 /* ------------------
14 Utility functions
15 ------------------
17 float pixelToTwip(float fInput, float zoom)
19 return (fInput / DPI / zoom) * 1440.0f;
22 float twipToPixel(float fInput, float zoom)
24 return fInput / 1440.0f * DPI * zoom;
27 /* ----------------------------
28 Tile class member functions
29 ----------------------------
31 cairo_surface_t* Tile::getBuffer()
33 return m_pBuffer;
36 void Tile::setSurface(cairo_surface_t *buffer)
38 if (m_pBuffer == buffer)
39 return;
40 if (m_pBuffer)
41 cairo_surface_destroy(m_pBuffer);
42 if (buffer != nullptr)
43 cairo_surface_reference(buffer);
44 m_pBuffer = buffer;
47 /* ----------------------------------
48 TileBuffer class member functions
49 ----------------------------------
51 void TileBuffer::resetAllTiles()
53 std::map<int, Tile>::iterator it = m_mTiles.begin();
54 for (; it != m_mTiles.end(); ++it)
56 it->second.valid = false;
60 void TileBuffer::setInvalid(int x, int y, float fZoom, GTask* task,
61 GThreadPool* lokThreadPool)
63 int index = x * m_nWidth + y;
64 GError* error = nullptr;
65 if (m_mTiles.find(index) != m_mTiles.end())
67 m_mTiles[index].valid = false;
69 LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE);
70 pLOEvent->m_nPaintTileX = x;
71 pLOEvent->m_nPaintTileY = y;
72 pLOEvent->m_fPaintTileZoom = fZoom;
73 g_task_set_task_data(task, pLOEvent, LOEvent::destroy);
74 g_thread_pool_push(lokThreadPool, g_object_ref(task), &error);
75 if (error != nullptr)
77 g_warning("Unable to call LOK_PAINT_TILE: %s", error->message);
78 g_clear_error(&error);
83 Tile& TileBuffer::getTile(int x, int y, GTask* task,
84 GThreadPool* lokThreadPool)
86 int index = x * m_nWidth + y;
87 GError* error = nullptr;
89 if (m_mTiles.find(index) != m_mTiles.end() && !m_mTiles[index].valid)
91 g_thread_pool_push(lokThreadPool, g_object_ref(task), &error);
92 if (error != nullptr)
94 g_warning("Unable to call LOK_PAINT_TILE: %s", error->message);
95 g_clear_error(&error);
97 return m_mTiles[index];
99 else if(m_mTiles.find(index) == m_mTiles.end())
101 g_thread_pool_push(lokThreadPool, g_object_ref(task), &error);
102 if (error != nullptr)
104 g_warning("Unable to call LOK_PAINT_TILE: %s", error->message);
105 g_clear_error(&error);
107 return m_DummyTile;
110 return m_mTiles[index];
113 void LOEvent::destroy(void* pMemory)
115 LOEvent* pLOEvent = static_cast<LOEvent*>(pMemory);
116 delete pLOEvent;
119 GQuark
120 LOKTileBufferErrorQuark(void)
122 return g_quark_from_static_string("lok-tilebuffer-error");
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */