Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / shapes / viewshape.hxx
blob74eb3b9af6c280921705a70c6f666c61612f679f
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_VIEWSHAPE_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_VIEWSHAPE_HXX
23 #include <cppcanvas/renderer.hxx>
24 #include <cppcanvas/bitmap.hxx>
26 #include <basegfx/range/b2drectangle.hxx>
27 #include <basegfx/polygon/b2dpolygon.hxx>
28 #include <o3tl/typed_flags_set.hxx>
30 #include <tools.hxx>
31 #include <shapeattributelayer.hxx>
32 #include <animatedsprite.hxx>
33 #include <viewlayer.hxx>
34 #include <doctreenode.hxx>
36 #include <vector>
37 #include <memory>
39 enum class UpdateFlags
41 NONE = 0x00,
42 Transformation = 0x01,
43 Clip = 0x02,
44 Alpha = 0x04,
45 Position = 0x08,
46 Content = 0x10,
47 Force = 0x20,
49 namespace o3tl {
50 template<> struct typed_flags<UpdateFlags> : is_typed_flags<UpdateFlags, 0x3f> {};
55 namespace slideshow
57 namespace internal
59 /** This class is the viewable representation of a draw
60 document's XShape, associated to a specific View
62 The class is able to render the associated XShape on
63 View implementations.
65 class ViewShape
67 public:
68 /** Create a ViewShape for the given View
70 @param rView
71 The associated View object.
73 explicit ViewShape( const ViewLayerSharedPtr& rViewLayer );
75 ///Forbid copy construction
76 ViewShape(const ViewShape&) = delete;
77 /// Forbid copy assignment
78 ViewShape& operator=(const ViewShape&) = delete;
80 /** Query the associated view layer of this shape
82 const ViewLayerSharedPtr& getViewLayer() const;
84 /** Query dimension of a safety border around the shape for AA
86 If the view performs antialiasing, this method
87 calculates a safety border around the shape, in the
88 shape coordinate system, which is guaranteed to
89 include every pixel touched when rendering the shape.
91 ::basegfx::B2DSize getAntialiasingBorder() const;
94 // animation methods
97 /** Notify the ViewShape that an animation starts now
99 This method enters animation mode on the associate
100 target view. The shape can be animated in parallel on
101 different views.
103 @return whether the mode change finished successfully.
105 bool enterAnimationMode();
107 /** Notify the ViewShape that it is no longer animated
109 This methods ends animation mode on the associate
110 target view
112 void leaveAnimationMode();
115 // render methods
118 struct RenderArgs
120 /** Create render argument struct
122 @param rOrigBounds
123 The initial shape bounds
125 @param rUpdateBounds
126 The area covered by the shape
128 @param rBounds
129 The current shape bounds
131 @param rAttr
132 The current shape attribute set. Can be NULL, for
133 default attributes. Attention: stored as a reference,
134 thus, parameter object must stay valid!
136 @param rSubsets
137 Vector of subset rendering ranges. Attention:
138 stored as a reference, thus, parameter object must
139 stay valid!
141 @param nPrio
142 Shape priority
144 RenderArgs( const ::basegfx::B2DRectangle& rOrigBounds,
145 const ::basegfx::B2DRectangle& rUpdateBounds,
146 const ::basegfx::B2DRectangle& rBounds,
147 const ::basegfx::B2DRectangle& rUnitBounds,
148 const ShapeAttributeLayerSharedPtr& rAttr,
149 const VectorOfDocTreeNodes& rSubsets,
150 double nPrio ) :
151 maOrigBounds( rOrigBounds ),
152 maUpdateBounds( rUpdateBounds ),
153 maBounds( rBounds ),
154 maUnitBounds( rUnitBounds ),
155 mrAttr( rAttr ),
156 mrSubsets( rSubsets ),
157 mnShapePriority( nPrio )
161 const ::basegfx::B2DRectangle maOrigBounds;
162 const ::basegfx::B2DRectangle maUpdateBounds;
163 const ::basegfx::B2DRectangle maBounds;
164 const ::basegfx::B2DRectangle maUnitBounds;
165 const ShapeAttributeLayerSharedPtr& mrAttr;
166 const VectorOfDocTreeNodes& mrSubsets;
167 const double mnShapePriority;
170 /** Update the ViewShape
172 This method updates the ViewShape on the associated
173 view. If the shape is currently animated, the render
174 target is the sprite, otherwise the view's
175 canvas. This method does not render anything, if the
176 update flags are 0.
178 @param rMtf
179 The metafile representation of the shape
181 @param rArgs
182 Parameter structure, containing all necessary arguments
184 @param nUpdateFlags
185 Bitmask of things to update. Use FORCE to force a repaint.
187 @param bIsVisible
188 When false, the shape is fully invisible (and possibly
189 don't need to be painted)
191 @return whether the rendering finished successfully.
193 bool update( const GDIMetaFileSharedPtr& rMtf,
194 const RenderArgs& rArgs,
195 UpdateFlags nUpdateFlags,
196 bool bIsVisible ) const;
198 /** Retrieve renderer for given canvas and metafile.
200 If necessary, the renderer is created or updated for
201 the metafile and attribute layer.
203 @return a renderer that renders to the given
204 destination canvas
206 ::cppcanvas::RendererSharedPtr getRenderer( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
207 const GDIMetaFileSharedPtr& rMtf,
208 const ShapeAttributeLayerSharedPtr& rAttr ) const;
211 private:
212 struct RendererCacheEntry
214 RendererCacheEntry() :
215 mpDestinationCanvas(),
216 mpRenderer(),
217 mpMtf(),
218 mpLastBitmap(),
219 mpLastBitmapCanvas()
223 const ::cppcanvas::CanvasSharedPtr& getDestinationCanvas() const
225 return mpDestinationCanvas;
228 ::cppcanvas::CanvasSharedPtr mpDestinationCanvas;
229 ::cppcanvas::RendererSharedPtr mpRenderer;
230 GDIMetaFileSharedPtr mpMtf;
231 ::cppcanvas::BitmapSharedPtr mpLastBitmap;
232 ::cppcanvas::BitmapCanvasSharedPtr mpLastBitmapCanvas;
235 typedef ::std::vector< RendererCacheEntry > RendererCacheVector;
238 /** Prefetch Renderer for given canvas
240 static bool prefetch( RendererCacheEntry& io_rCacheEntry,
241 const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
242 const GDIMetaFileSharedPtr& rMtf,
243 const ShapeAttributeLayerSharedPtr& rAttr );
245 /** Draw with prefetched Renderer to stored canvas
247 This method draws prefetched Renderer to its
248 associated canvas (which happens to be mpLastCanvas).
250 bool draw( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
251 const GDIMetaFileSharedPtr& rMtf,
252 const ShapeAttributeLayerSharedPtr& rAttr,
253 const ::basegfx::B2DHomMatrix& rTransform,
254 const ::basegfx::B2DPolyPolygon* pClip,
255 const VectorOfDocTreeNodes& rSubsets ) const;
257 /** Render shape to an active sprite
259 bool renderSprite( const ViewLayerSharedPtr& rViewLayer,
260 const GDIMetaFileSharedPtr& rMtf,
261 const ::basegfx::B2DRectangle& rOrigBounds,
262 const ::basegfx::B2DRectangle& rBounds,
263 const ::basegfx::B2DRectangle& rUnitBounds,
264 UpdateFlags nUpdateFlags,
265 const ShapeAttributeLayerSharedPtr& pAttr,
266 const VectorOfDocTreeNodes& rSubsets,
267 double nPrio,
268 bool bIsVisible ) const;
270 /** Render shape to given canvas
272 bool render( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
273 const GDIMetaFileSharedPtr& rMtf,
274 const ::basegfx::B2DRectangle& rBounds,
275 const ::basegfx::B2DRectangle& rUpdateBounds,
276 UpdateFlags nUpdateFlags,
277 const ShapeAttributeLayerSharedPtr& pAttr,
278 const VectorOfDocTreeNodes& rSubsets,
279 bool bIsVisible ) const;
281 enum{ MAX_RENDER_CACHE_ENTRIES=2 };
283 /** Retrieve a valid iterator to renderer cache entry
285 This method ensures that an internal limit of
286 MAX_RENDER_CACHE_ENTRIES is not exceeded.
288 @param rDestinationCanvas
289 Destination canvas to retrieve cache entry for
291 @return a valid iterator to a renderer cache entry for
292 the given canvas. The entry might be
293 default-constructed (if newly added)
295 RendererCacheVector::iterator getCacheEntry( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas ) const;
297 void invalidateRenderer() const;
299 /** The view layer this object is part of.
301 Needed for sprite creation
303 ViewLayerSharedPtr mpViewLayer;
305 /// A set of cached mtf/canvas combinations
306 mutable RendererCacheVector maRenderers;
308 /// The sprite object
309 mutable AnimatedSpriteSharedPtr mpSprite;
311 /// If true, render() calls go to the sprite
312 mutable bool mbAnimationMode;
314 /// If true, shape needs full repaint (and the sprite a setup, if any)
315 mutable bool mbForceUpdate;
318 typedef ::std::shared_ptr< ViewShape > ViewShapeSharedPtr;
323 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_VIEWSHAPE_HXX
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */