nss: upgrade to release 3.73
[LibreOffice.git] / libreofficekit / source / gtk / tilebuffer.cxx
blob6836031661bc1b3c2b48b75138e9e1bea28e67ed
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 for (auto & tile : m_mTiles)
55 tile.second.valid = false;
59 void TileBuffer::setInvalid(int x, int y, float fZoom, GTask* task,
60 GThreadPool* lokThreadPool)
62 int index = x * m_nWidth + y;
63 GError* error = nullptr;
64 if (m_mTiles.find(index) == m_mTiles.end())
65 return;
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);
82 Tile& TileBuffer::getTile(int x, int y, GTask* task,
83 GThreadPool* lokThreadPool)
85 int index = x * m_nWidth + y;
86 GError* error = nullptr;
88 if (m_mTiles.find(index) != m_mTiles.end() && !m_mTiles[index].valid)
90 g_thread_pool_push(lokThreadPool, g_object_ref(task), &error);
91 if (error != nullptr)
93 g_warning("Unable to call LOK_PAINT_TILE: %s", error->message);
94 g_clear_error(&error);
96 return m_mTiles[index];
98 else if(m_mTiles.find(index) == m_mTiles.end())
100 g_thread_pool_push(lokThreadPool, g_object_ref(task), &error);
101 if (error != nullptr)
103 g_warning("Unable to call LOK_PAINT_TILE: %s", error->message);
104 g_clear_error(&error);
106 return m_DummyTile;
109 return m_mTiles[index];
112 void TileBuffer::setTile(int x, int y, cairo_surface_t *surface)
114 int index = x * m_nWidth + y;
116 m_mTiles[index].setSurface(surface);
117 m_mTiles[index].valid = true;
120 bool TileBuffer::hasValidTile(int x, int y)
122 int index = x * m_nWidth + y;
123 auto it = m_mTiles.find(index);
124 return (it != m_mTiles.end()) && it->second.valid;
127 void LOEvent::destroy(void* pMemory)
129 LOEvent* pLOEvent = static_cast<LOEvent*>(pMemory);
130 delete pLOEvent;
133 GQuark
134 LOKTileBufferErrorQuark()
136 return g_quark_from_static_string("lok-tilebuffer-error");
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */