nss: upgrade to release 3.73
[LibreOffice.git] / libreofficekit / source / gtk / tilebuffer.hxx
blob79fa48c555dbd3bb08da3caaa06d5fb3d0c3100d
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 #ifndef INCLUDED_TILEBUFFER_HXX
11 #define INCLUDED_TILEBUFFER_HXX
13 #include <cairo.h>
14 #include <gio/gio.h>
15 #include <glib.h>
17 #include <map>
19 #define LOK_TILEBUFFER_ERROR (LOKTileBufferErrorQuark())
21 // We know that VirtualDevices use a DPI of 96.
22 const int DPI = 96;
23 // Lets use a square of side 256 pixels for each tile.
24 const int nTileSizePixels = 256;
26 /**
27 Converts the pixel value to zoom independent twip value.
29 @param fInput value to convert
30 @param zoom the current zoom level
32 @return the pixels value corresponding to given twip value
34 float pixelToTwip(float fInput, float zoom);
36 /**
37 Converts the zoom independent twip value pixel value.
39 @param fInput value to convert
40 @param zoom the current zoom level
42 @return the twip value corresponding to given pixel value
44 float twipToPixel(float fInput, float zoom);
46 /**
47 Gets GQuark identifying this tile buffer errors
49 GQuark LOKTileBufferErrorQuark(void);
51 /**
52 This class represents a single tile in the tile buffer.
53 It encloses a reference to GdkPixBuf containing the pixel data of the tile.
55 class Tile
57 public:
58 Tile()
59 : valid(false)
60 , m_pBuffer(nullptr)
63 ~Tile()
65 if (m_pBuffer)
66 cairo_surface_destroy(m_pBuffer);
69 /**
70 Tells if this tile is valid or not. Initialised to 0 (invalid) during
71 object creation.
73 bool valid;
75 /// Function to get the pointer to enclosing cairo_surface_t
76 cairo_surface_t* getBuffer();
77 /// Used to set the pixel buffer of this object
78 void setSurface(cairo_surface_t*);
80 private:
81 /// Pixel buffer data for this tile
82 cairo_surface_t* m_pBuffer;
85 /**
86 This class represents the tile buffer which is responsible for managing,
87 reusing and caching all the already rendered tiles. If the given tile is not
88 present in the buffer, call to LOK Document's (m_pLOKDocument) paintTile
89 method is made which fetches the rendered tile from LO core and store it in
90 buffer for future reuse.
92 class TileBuffer
94 public:
95 TileBuffer(int columns = 0, int scale = 1)
96 : m_nWidth(columns)
98 cairo_surface_t* pSurface = cairo_image_surface_create(
99 CAIRO_FORMAT_ARGB32, nTileSizePixels * scale, nTileSizePixels * scale);
100 m_DummyTile.setSurface(pSurface);
101 cairo_surface_destroy(pSurface);
105 Gets the underlying Tile object for given position. The position (0, 0)
106 points to the left top most tile of the buffer.
108 If the tile is not cached by the tile buffer, it makes a paintTile call
109 to LO core asking to render the given tile. It then stores the tile for
110 future reuse.
112 @param x the tile along the x-axis of the buffer
113 @param y the tile along the y-axis of the buffer
114 @param task GTask object containing the necessary data
115 @param pool GThreadPool managed by the widget instance used for all the
116 LOK calls made by widget. It is needed here because getTile invokes one
117 of the LOK call : paintTile.
119 @return the tile at the mentioned position (x, y)
121 Tile& getTile(int x, int y, GTask* task, GThreadPool* pool);
124 Takes ownership of the surface and sets it on a tile at a given location
126 void setTile(int x, int y, cairo_surface_t* surface);
128 /// Returns true if a valid tile exists at this location
129 bool hasValidTile(int x, int y);
131 /// Destroys all the tiles in the tile buffer; also frees the memory allocated
132 /// for all the Tile objects.
133 void resetAllTiles();
135 Marks the tile as invalid. The tile (0, 0) is the left topmost tile in
136 the tile buffer.
138 @param x the position of tile along x-axis
139 @param y the position of tile along y-axis
140 @param zoom zoom factor of the document
141 @param task GTask object containing the necessary data
142 @param pool GThreadPool managed by the widget instance used for all the
143 LOK calls made by widget. It is needed here because setInvalid() invokes one
144 of the LOK call : paintTile.
146 void setInvalid(int x, int y, float zoom, GTask* task, GThreadPool*);
148 private:
149 /// Stores all the tiles cached by this tile buffer.
150 std::map<int, Tile> m_mTiles;
151 /// Width of the current tile buffer (number of columns)
152 int m_nWidth;
153 /// Dummy tile
154 Tile m_DummyTile;
157 enum
159 LOK_LOAD_DOC,
160 LOK_POST_COMMAND,
161 LOK_SET_EDIT,
162 LOK_SET_PARTMODE,
163 LOK_SET_PART,
164 LOK_POST_KEY,
165 LOK_PAINT_TILE,
166 LOK_POST_MOUSE_EVENT,
167 LOK_SET_GRAPHIC_SELECTION,
168 LOK_SET_CLIENT_ZOOM
171 enum
173 LOK_TILEBUFFER_CHANGED,
174 LOK_TILEBUFFER_MEMORY
178 A struct that we use to store the data about the LOK call.
180 Object of this type is passed with all the LOK calls,
181 so that they can be identified. Additionally, it also contains
182 the data that LOK call needs.
184 struct LOEvent
186 /// To identify the type of LOK call
187 int m_nType;
189 /// @name post_command parameters
190 ///@{
191 const gchar* m_pCommand;
192 gchar* m_pArguments;
193 gboolean m_bNotifyWhenFinished;
194 ///@}
196 /// set_edit parameter
197 gboolean m_bEdit;
199 /// set_partmode parameter
200 int m_nPartMode;
202 /// set_part parameter
203 int m_nPart;
205 /// @name postKeyEvent parameters
206 ///@{
207 int m_nKeyEvent;
208 int m_nCharCode;
209 int m_nKeyCode;
210 ///@}
212 /// @name paintTile parameters
213 ///@{
214 int m_nPaintTileX;
215 int m_nPaintTileY;
216 float m_fPaintTileZoom;
217 TileBuffer* m_pTileBuffer;
218 ///@}
220 /// @name postMouseEvent parameters
221 ///@{
222 int m_nPostMouseEventType;
223 int m_nPostMouseEventX;
224 int m_nPostMouseEventY;
225 int m_nPostMouseEventCount;
226 int m_nPostMouseEventButton;
227 int m_nPostMouseEventModifier;
228 ///@}
230 /// @name setGraphicSelection parameters
231 ///@{
232 int m_nSetGraphicSelectionType;
233 int m_nSetGraphicSelectionX;
234 int m_nSetGraphicSelectionY;
235 ///@}
237 /// @name setClientView parameters
238 ///@{
239 int m_nTilePixelWidth;
240 int m_nTilePixelHeight;
241 int m_nTileTwipWidth;
242 int m_nTileTwipHeight;
243 ///@}
245 /// Constructor to instantiate an object of type `type`.
246 explicit LOEvent(int type)
247 : m_nType(type)
248 , m_pCommand(nullptr)
249 , m_pArguments(nullptr)
250 , m_bNotifyWhenFinished(false)
251 , m_bEdit(false)
252 , m_nPartMode(0)
253 , m_nPart(0)
254 , m_nKeyEvent(0)
255 , m_nCharCode(0)
256 , m_nKeyCode(0)
257 , m_nPaintTileX(0)
258 , m_nPaintTileY(0)
259 , m_fPaintTileZoom(0)
260 , m_pTileBuffer(nullptr)
261 , m_nPostMouseEventType(0)
262 , m_nPostMouseEventX(0)
263 , m_nPostMouseEventY(0)
264 , m_nPostMouseEventCount(0)
265 , m_nPostMouseEventButton(0)
266 , m_nPostMouseEventModifier(0)
267 , m_nSetGraphicSelectionType(0)
268 , m_nSetGraphicSelectionX(0)
269 , m_nSetGraphicSelectionY(0)
270 , m_nTilePixelWidth(0)
271 , m_nTilePixelHeight(0)
272 , m_nTileTwipWidth(0)
273 , m_nTileTwipHeight(0)
277 /// Wrapper around delete to help GLib.
278 static void destroy(void* pMemory);
281 #endif // INCLUDED_TILEBUFFER_HXX
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */