1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_VIEWSHAPE_HXX
#define INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_VIEWSHAPE_HXX
#include <cppcanvas/renderer.hxx>
#include <cppcanvas/bitmap.hxx>
#include <basegfx/range/b2drectangle.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <tools.hxx>
#include <shapeattributelayer.hxx>
#include <animatedsprite.hxx>
#include <viewlayer.hxx>
#include <doctreenode.hxx>
#include <vector>
#include <memory>
enum class UpdateFlags
{
NONE = 0x00,
Transformation = 0x01,
Clip = 0x02,
Alpha = 0x04,
Position = 0x08,
Content = 0x10,
Force = 0x20,
};
namespace o3tl {
template<> struct typed_flags<UpdateFlags> : is_typed_flags<UpdateFlags, 0x3f> {};
}
namespace slideshow
{
namespace internal
{
/** This class is the viewable representation of a draw
document's XShape, associated to a specific View
The class is able to render the associated XShape on
View implementations.
*/
class ViewShape
{
public:
/** Create a ViewShape for the given View
@param rView
The associated View object.
*/
explicit ViewShape( const ViewLayerSharedPtr& rViewLayer );
///Forbid copy construction
ViewShape(const ViewShape&) = delete;
/// Forbid copy assignment
ViewShape& operator=(const ViewShape&) = delete;
/** Query the associated view layer of this shape
*/
const ViewLayerSharedPtr& getViewLayer() const;
/** Query dimension of a safety border around the shape for AA
If the view performs antialiasing, this method
calculates a safety border around the shape, in the
shape coordinate system, which is guaranteed to
include every pixel touched when rendering the shape.
*/
::basegfx::B2DSize getAntialiasingBorder() const;
// animation methods
/** Notify the ViewShape that an animation starts now
This method enters animation mode on the associate
target view. The shape can be animated in parallel on
different views.
*/
void enterAnimationMode();
/** Notify the ViewShape that it is no longer animated
This methods ends animation mode on the associate
target view
*/
void leaveAnimationMode();
// render methods
struct RenderArgs
{
/** Create render argument struct
@param rOrigBounds
The initial shape bounds
@param rUpdateBounds
The area covered by the shape
@param rBounds
The current shape bounds
@param rAttr
The current shape attribute set. Can be NULL, for
default attributes. Attention: stored as a reference,
thus, parameter object must stay valid!
@param rSubsets
Vector of subset rendering ranges. Attention:
stored as a reference, thus, parameter object must
stay valid!
@param nPrio
Shape priority
*/
RenderArgs( const ::basegfx::B2DRectangle& rOrigBounds,
const ::basegfx::B2DRectangle& rUpdateBounds,
const ::basegfx::B2DRectangle& rBounds,
const ::basegfx::B2DRectangle& rUnitBounds,
const ShapeAttributeLayerSharedPtr& rAttr,
const VectorOfDocTreeNodes& rSubsets,
double nPrio ) :
maOrigBounds( rOrigBounds ),
maUpdateBounds( rUpdateBounds ),
maBounds( rBounds ),
maUnitBounds( rUnitBounds ),
mrAttr( rAttr ),
mrSubsets( rSubsets ),
mnShapePriority( nPrio )
{
}
const ::basegfx::B2DRectangle maOrigBounds;
const ::basegfx::B2DRectangle maUpdateBounds;
const ::basegfx::B2DRectangle maBounds;
const ::basegfx::B2DRectangle maUnitBounds;
const ShapeAttributeLayerSharedPtr& mrAttr;
const VectorOfDocTreeNodes& mrSubsets;
const double mnShapePriority;
};
/** Update the ViewShape
This method updates the ViewShape on the associated
view. If the shape is currently animated, the render
target is the sprite, otherwise the view's
canvas. This method does not render anything, if the
update flags are 0.
@param rMtf
The metafile representation of the shape
@param rArgs
Parameter structure, containing all necessary arguments
@param nUpdateFlags
Bitmask of things to update. Use FORCE to force a repaint.
@param bIsVisible
When false, the shape is fully invisible (and possibly
don't need to be painted)
@return whether the rendering finished successfully.
*/
bool update( const GDIMetaFileSharedPtr& rMtf,
const RenderArgs& rArgs,
UpdateFlags nUpdateFlags,
bool bIsVisible ) const;
/** Retrieve renderer for given canvas and metafile.
If necessary, the renderer is created or updated for
the metafile and attribute layer.
@return a renderer that renders to the given
destination canvas
*/
::cppcanvas::RendererSharedPtr getRenderer( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
const GDIMetaFileSharedPtr& rMtf,
const ShapeAttributeLayerSharedPtr& rAttr ) const;
private:
struct RendererCacheEntry
{
RendererCacheEntry() :
mpDestinationCanvas(),
mpRenderer(),
mpMtf(),
mpLastBitmap(),
mpLastBitmapCanvas()
{
}
const ::cppcanvas::CanvasSharedPtr& getDestinationCanvas() const
{
return mpDestinationCanvas;
}
::cppcanvas::CanvasSharedPtr mpDestinationCanvas;
::cppcanvas::RendererSharedPtr mpRenderer;
GDIMetaFileSharedPtr mpMtf;
::cppcanvas::BitmapSharedPtr mpLastBitmap;
::cppcanvas::BitmapCanvasSharedPtr mpLastBitmapCanvas;
};
typedef ::std::vector< RendererCacheEntry > RendererCacheVector;
/** Prefetch Renderer for given canvas
*/
static bool prefetch( RendererCacheEntry& io_rCacheEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
const GDIMetaFileSharedPtr& rMtf,
const ShapeAttributeLayerSharedPtr& rAttr );
/** Draw with prefetched Renderer to stored canvas
This method draws prefetched Renderer to its
associated canvas (which happens to be mpLastCanvas).
*/
bool draw( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
const GDIMetaFileSharedPtr& rMtf,
const ShapeAttributeLayerSharedPtr& rAttr,
const ::basegfx::B2DHomMatrix& rTransform,
const ::basegfx::B2DPolyPolygon* pClip,
const VectorOfDocTreeNodes& rSubsets ) const;
/** Render shape to an active sprite
*/
bool renderSprite( const ViewLayerSharedPtr& rViewLayer,
const GDIMetaFileSharedPtr& rMtf,
const ::basegfx::B2DRectangle& rOrigBounds,
const ::basegfx::B2DRectangle& rBounds,
const ::basegfx::B2DRectangle& rUnitBounds,
UpdateFlags nUpdateFlags,
const ShapeAttributeLayerSharedPtr& pAttr,
const VectorOfDocTreeNodes& rSubsets,
double nPrio,
bool bIsVisible ) const;
/** Render shape to given canvas
*/
bool render( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
const GDIMetaFileSharedPtr& rMtf,
const ::basegfx::B2DRectangle& rBounds,
const ::basegfx::B2DRectangle& rUpdateBounds,
UpdateFlags nUpdateFlags,
const ShapeAttributeLayerSharedPtr& pAttr,
const VectorOfDocTreeNodes& rSubsets,
bool bIsVisible ) const;
enum{ MAX_RENDER_CACHE_ENTRIES=2 };
/** Retrieve a valid iterator to renderer cache entry
This method ensures that an internal limit of
MAX_RENDER_CACHE_ENTRIES is not exceeded.
@param rDestinationCanvas
Destination canvas to retrieve cache entry for
@return a valid iterator to a renderer cache entry for
the given canvas. The entry might be
default-constructed (if newly added)
*/
RendererCacheVector::iterator getCacheEntry( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas ) const;
void invalidateRenderer() const;
/** The view layer this object is part of.
Needed for sprite creation
*/
ViewLayerSharedPtr const mpViewLayer;
/// A set of cached mtf/canvas combinations
mutable RendererCacheVector maRenderers;
/// The sprite object
mutable AnimatedSpriteSharedPtr mpSprite;
/// If true, render() calls go to the sprite
mutable bool mbAnimationMode;
/// If true, shape needs full repaint (and the sprite a setup, if any)
mutable bool mbForceUpdate;
};
typedef ::std::shared_ptr< ViewShape > ViewShapeSharedPtr;
}
}
#endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_VIEWSHAPE_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|