LibreOffice Module libreofficekit (master) 1
tilebuffer.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#ifndef INCLUDED_TILEBUFFER_HXX
11#define INCLUDED_TILEBUFFER_HXX
12
13#include <cairo.h>
14#include <gio/gio.h>
15#include <glib.h>
16
17#include <map>
18
19#define LOK_TILEBUFFER_ERROR (LOKTileBufferErrorQuark())
20
21// Lets use a square of side 256 pixels for each tile.
22const int nTileSizePixels = 256;
23
32float pixelToTwip(float fInput, float zoom);
33
42float twipToPixel(float fInput, float zoom);
43
47GQuark LOKTileBufferErrorQuark(void);
48
53class Tile
54{
55public:
57 : valid(false)
58 , m_pBuffer(nullptr)
59 {
60 }
62 {
63 if (m_pBuffer)
64 cairo_surface_destroy(m_pBuffer);
65 }
66
71 bool valid;
72
77
78private:
81};
82
91{
92public:
93 TileBuffer(int columns = 0, int scale = 1)
94 : m_nWidth(columns)
95 {
96 cairo_surface_t* pSurface = cairo_image_surface_create(
97 CAIRO_FORMAT_ARGB32, nTileSizePixels * scale, nTileSizePixels * scale);
98 m_DummyTile.setSurface(pSurface);
99 cairo_surface_destroy(pSurface);
100 }
101
119 Tile& getTile(int x, int y, GTask* task, GThreadPool* pool);
120
121 /*
122 Takes ownership of the surface and sets it on a tile at a given location
123 */
124 void setTile(int x, int y, cairo_surface_t* surface);
125
127 bool hasValidTile(int x, int y);
128
131 void resetAllTiles();
144 void setInvalid(int x, int y, float zoom, GTask* task, GThreadPool*);
145
146private:
148 std::map<int, Tile> m_mTiles;
153};
154
155enum
156{
168
169enum
170{
174
183{
186
189 const gchar* m_pCommand;
193
195 gboolean m_bEdit;
196
199
202
209
217
227
234
242
244 explicit LOEvent(int type)
245 : m_nType(type)
246 , m_pCommand(nullptr)
247 , m_pArguments(nullptr)
248 , m_bNotifyWhenFinished(false)
249 , m_bEdit(false)
250 , m_nPartMode(0)
251 , m_nPart(0)
252 , m_nKeyEvent(0)
253 , m_nCharCode(0)
254 , m_nKeyCode(0)
255 , m_nPaintTileX(0)
256 , m_nPaintTileY(0)
258 , m_pTileBuffer(nullptr)
272 {
273 }
274
276 static void destroy(void* pMemory);
277};
278
279#endif // INCLUDED_TILEBUFFER_HXX
280
281/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _cairo_surface cairo_surface_t
This class represents the tile buffer which is responsible for managing, reusing and caching all the ...
Definition: tilebuffer.hxx:91
void setInvalid(int x, int y, float zoom, GTask *task, GThreadPool *)
Marks the tile as invalid.
Definition: tilebuffer.cxx:62
void setTile(int x, int y, cairo_surface_t *surface)
Definition: tilebuffer.cxx:115
void resetAllTiles()
Destroys all the tiles in the tile buffer; also frees the memory allocated for all the Tile objects.
Definition: tilebuffer.cxx:54
bool hasValidTile(int x, int y)
Returns true if a valid tile exists at this location.
Definition: tilebuffer.cxx:123
int m_nWidth
Width of the current tile buffer (number of columns)
Definition: tilebuffer.hxx:150
Tile m_DummyTile
Dummy tile.
Definition: tilebuffer.hxx:152
Tile & getTile(int x, int y, GTask *task, GThreadPool *pool)
Gets the underlying Tile object for given position.
Definition: tilebuffer.cxx:85
TileBuffer(int columns=0, int scale=1)
Definition: tilebuffer.hxx:93
std::map< int, Tile > m_mTiles
Stores all the tiles cached by this tile buffer.
Definition: tilebuffer.hxx:148
This class represents a single tile in the tile buffer.
Definition: tilebuffer.hxx:54
cairo_surface_t * getBuffer()
Function to get the pointer to enclosing cairo_surface_t.
Definition: tilebuffer.cxx:34
cairo_surface_t * m_pBuffer
Pixel buffer data for this tile.
Definition: tilebuffer.hxx:80
~Tile()
Definition: tilebuffer.hxx:61
void setSurface(cairo_surface_t *)
Used to set the pixel buffer of this object.
Definition: tilebuffer.cxx:39
bool valid
Tells if this tile is valid or not.
Definition: tilebuffer.hxx:71
Tile()
Definition: tilebuffer.hxx:56
sal_Int32 scale
A struct that we use to store the data about the LOK call.
Definition: tilebuffer.hxx:183
float m_fPaintTileZoom
Definition: tilebuffer.hxx:214
int m_nSetGraphicSelectionX
Definition: tilebuffer.hxx:231
int m_nPostMouseEventY
Definition: tilebuffer.hxx:222
gchar * m_pArguments
Definition: tilebuffer.hxx:190
int m_nTilePixelHeight
Definition: tilebuffer.hxx:238
int m_nPostMouseEventButton
Definition: tilebuffer.hxx:224
static void destroy(void *pMemory)
Wrapper around delete to help GLib.
Definition: tilebuffer.cxx:130
int m_nPaintTileY
Definition: tilebuffer.hxx:213
gboolean m_bEdit
set_edit parameter
Definition: tilebuffer.hxx:195
int m_nPaintTileX
Definition: tilebuffer.hxx:212
int m_nTileTwipWidth
Definition: tilebuffer.hxx:239
LOEvent(int type)
Constructor to instantiate an object of type type.
Definition: tilebuffer.hxx:244
int m_nCharCode
Definition: tilebuffer.hxx:206
int m_nTilePixelWidth
Definition: tilebuffer.hxx:237
int m_nTileTwipHeight
Definition: tilebuffer.hxx:240
int m_nKeyEvent
Definition: tilebuffer.hxx:205
int m_nPartMode
set_partmode parameter
Definition: tilebuffer.hxx:198
int m_nPostMouseEventX
Definition: tilebuffer.hxx:221
int m_nPart
set_part parameter
Definition: tilebuffer.hxx:201
TileBuffer * m_pTileBuffer
Definition: tilebuffer.hxx:215
int m_nSetGraphicSelectionType
Definition: tilebuffer.hxx:230
int m_nSetGraphicSelectionY
Definition: tilebuffer.hxx:232
int m_nPostMouseEventModifier
Definition: tilebuffer.hxx:225
int m_nPostMouseEventType
Definition: tilebuffer.hxx:220
int m_nType
To identify the type of LOK call.
Definition: tilebuffer.hxx:185
int m_nKeyCode
Definition: tilebuffer.hxx:207
gboolean m_bNotifyWhenFinished
Definition: tilebuffer.hxx:191
const gchar * m_pCommand
Definition: tilebuffer.hxx:189
int m_nPostMouseEventCount
Definition: tilebuffer.hxx:223
const int nTileSizePixels
Definition: tilebuffer.hxx:22
GQuark LOKTileBufferErrorQuark(void)
Gets GQuark identifying this tile buffer errors.
Definition: tilebuffer.cxx:137
@ LOK_POST_COMMAND
Definition: tilebuffer.hxx:158
@ LOK_POST_MOUSE_EVENT
Definition: tilebuffer.hxx:164
@ LOK_SET_PART
Definition: tilebuffer.hxx:161
@ LOK_LOAD_DOC
Definition: tilebuffer.hxx:157
@ LOK_SET_CLIENT_ZOOM
Definition: tilebuffer.hxx:166
@ LOK_SET_EDIT
Definition: tilebuffer.hxx:159
@ LOK_POST_KEY
Definition: tilebuffer.hxx:162
@ LOK_SET_GRAPHIC_SELECTION
Definition: tilebuffer.hxx:165
@ LOK_PAINT_TILE
Definition: tilebuffer.hxx:163
@ LOK_SET_PARTMODE
Definition: tilebuffer.hxx:160
float pixelToTwip(float fInput, float zoom)
Converts the pixel value to zoom independent twip value.
Definition: tilebuffer.cxx:20
@ LOK_TILEBUFFER_CHANGED
Definition: tilebuffer.hxx:171
@ LOK_TILEBUFFER_MEMORY
Definition: tilebuffer.hxx:172
float twipToPixel(float fInput, float zoom)
Converts the zoom independent twip value pixel value.
Definition: tilebuffer.cxx:25
ResultType type