1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include "tilebuffer.hxx"
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()
36 void Tile::setSurface(cairo_surface_t
*buffer
)
38 if (m_pBuffer
== buffer
)
41 cairo_surface_destroy(m_pBuffer
);
42 if (buffer
!= nullptr)
43 cairo_surface_reference(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())
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
);
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
);
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
);
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
);
134 LOKTileBufferErrorQuark()
136 return g_quark_from_static_string("lok-tilebuffer-error");
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */