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 #ifndef INCLUDED_TILEBUFFER_HXX
11 #define INCLUDED_TILEBUFFER_HXX
19 #define LOK_TILEBUFFER_ERROR (LOKTileBufferErrorQuark())
21 // We know that VirtualDevices use a DPI of 96.
23 // Lets use a square of side 256 pixels for each tile.
24 const int nTileSizePixels
= 256;
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
);
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
);
47 Gets GQuark identifying this tile buffer errors
49 GQuark
LOKTileBufferErrorQuark(void);
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.
66 cairo_surface_destroy(m_pBuffer
);
70 Tells if this tile is valid or not. Initialised to 0 (invalid) during
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
*);
81 /// Pixel buffer data for this tile
82 cairo_surface_t
* m_pBuffer
;
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.
95 TileBuffer(int columns
= 0, int scale
= 1)
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
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
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
*);
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)
166 LOK_POST_MOUSE_EVENT
,
167 LOK_SET_GRAPHIC_SELECTION
,
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.
186 /// To identify the type of LOK call
189 /// @name post_command parameters
191 const gchar
* m_pCommand
;
193 gboolean m_bNotifyWhenFinished
;
196 /// set_edit parameter
199 /// set_partmode parameter
202 /// set_part parameter
205 /// @name postKeyEvent parameters
212 /// @name paintTile parameters
216 float m_fPaintTileZoom
;
217 TileBuffer
* m_pTileBuffer
;
220 /// @name postMouseEvent parameters
222 int m_nPostMouseEventType
;
223 int m_nPostMouseEventX
;
224 int m_nPostMouseEventY
;
225 int m_nPostMouseEventCount
;
226 int m_nPostMouseEventButton
;
227 int m_nPostMouseEventModifier
;
230 /// @name setGraphicSelection parameters
232 int m_nSetGraphicSelectionType
;
233 int m_nSetGraphicSelectionX
;
234 int m_nSetGraphicSelectionY
;
237 /// @name setClientView parameters
239 int m_nTilePixelWidth
;
240 int m_nTilePixelHeight
;
241 int m_nTileTwipWidth
;
242 int m_nTileTwipHeight
;
245 /// Constructor to instantiate an object of type `type`.
246 explicit LOEvent(int type
)
248 , m_pCommand(nullptr)
249 , m_pArguments(nullptr)
250 , m_bNotifyWhenFinished(false)
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: */