cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / slideshow / source / engine / shapes / viewshape.hxx
blobe77b8e27ba984f5a343c171eba503cd032116d4d
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 <o3tl/typed_flags_set.hxx>
29 #include <tools.hxx>
30 #include <shapeattributelayer.hxx>
31 #include <animatedsprite.hxx>
32 #include <viewlayer.hxx>
33 #include <doctreenode.hxx>
35 #include <vector>
36 #include <memory>
38 enum class UpdateFlags
40 NONE = 0x00,
41 Transformation = 0x01,
42 Clip = 0x02,
43 Alpha = 0x04,
44 Position = 0x08,
45 Content = 0x10,
46 Force = 0x20,
48 namespace o3tl {
49 template<> struct typed_flags<UpdateFlags> : is_typed_flags<UpdateFlags, 0x3f> {};
54 namespace slideshow::internal
56 /** This class is the viewable representation of a draw
57 document's XShape, associated to a specific View
59 The class is able to render the associated XShape on
60 View implementations.
62 class ViewShape
64 public:
65 /** Create a ViewShape for the given View
67 @param rView
68 The associated View object.
70 explicit ViewShape( ViewLayerSharedPtr xViewLayer );
72 ///Forbid copy construction
73 ViewShape(const ViewShape&) = delete;
74 /// Forbid copy assignment
75 ViewShape& operator=(const ViewShape&) = delete;
77 /** Query the associated view layer of this shape
79 const ViewLayerSharedPtr& getViewLayer() const;
81 /** Query dimension of a safety border around the shape for AA
83 If the view performs antialiasing, this method
84 calculates a safety border around the shape, in the
85 shape coordinate system, which is guaranteed to
86 include every pixel touched when rendering the shape.
88 ::basegfx::B2DSize getAntialiasingBorder() const;
91 // animation methods
94 /** Notify the ViewShape that an animation starts now
96 This method enters animation mode on the associate
97 target view. The shape can be animated in parallel on
98 different views.
100 void enterAnimationMode();
102 /** Notify the ViewShape that it is no longer animated
104 This methods ends animation mode on the associate
105 target view
107 void leaveAnimationMode();
110 // render methods
113 struct RenderArgs
115 /** Create render argument struct
117 @param rOrigBounds
118 The initial shape bounds
120 @param rUpdateBounds
121 The area covered by the shape
123 @param rBounds
124 The current shape bounds
126 @param rAttr
127 The current shape attribute set. Can be NULL, for
128 default attributes. Attention: stored as a reference,
129 thus, parameter object must stay valid!
131 @param rSubsets
132 Vector of subset rendering ranges. Attention:
133 stored as a reference, thus, parameter object must
134 stay valid!
136 @param nPrio
137 Shape priority
139 RenderArgs( const ::basegfx::B2DRectangle& rOrigBounds,
140 const ::basegfx::B2DRectangle& rUpdateBounds,
141 const ::basegfx::B2DRectangle& rBounds,
142 const ::basegfx::B2DRectangle& rUnitBounds,
143 const ShapeAttributeLayerSharedPtr& rAttr,
144 const VectorOfDocTreeNodes& rSubsets,
145 double nPrio ) :
146 maOrigBounds( rOrigBounds ),
147 maUpdateBounds( rUpdateBounds ),
148 maBounds( rBounds ),
149 maUnitBounds( rUnitBounds ),
150 mrAttr( rAttr ),
151 mrSubsets( rSubsets ),
152 mnShapePriority( nPrio )
156 const ::basegfx::B2DRectangle maOrigBounds;
157 const ::basegfx::B2DRectangle maUpdateBounds;
158 const ::basegfx::B2DRectangle maBounds;
159 const ::basegfx::B2DRectangle maUnitBounds;
160 const ShapeAttributeLayerSharedPtr& mrAttr;
161 const VectorOfDocTreeNodes& mrSubsets;
162 const double mnShapePriority;
165 /** Update the ViewShape
167 This method updates the ViewShape on the associated
168 view. If the shape is currently animated, the render
169 target is the sprite, otherwise the view's
170 canvas. This method does not render anything, if the
171 update flags are 0.
173 @param rMtf
174 The metafile representation of the shape
176 @param rArgs
177 Parameter structure, containing all necessary arguments
179 @param nUpdateFlags
180 Bitmask of things to update. Use FORCE to force a repaint.
182 @param bIsVisible
183 When false, the shape is fully invisible (and possibly
184 don't need to be painted)
186 @return whether the rendering finished successfully.
188 bool update( const GDIMetaFileSharedPtr& rMtf,
189 const RenderArgs& rArgs,
190 UpdateFlags nUpdateFlags,
191 bool bIsVisible ) const;
193 /** Retrieve renderer for given canvas and metafile.
195 If necessary, the renderer is created or updated for
196 the metafile and attribute layer.
198 @return a renderer that renders to the given
199 destination canvas
201 ::cppcanvas::RendererSharedPtr getRenderer( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
202 const GDIMetaFileSharedPtr& rMtf,
203 const ShapeAttributeLayerSharedPtr& rAttr ) const;
206 private:
207 struct RendererCacheEntry
209 RendererCacheEntry() :
210 mpDestinationCanvas(),
211 mpRenderer(),
212 mpMtf(),
213 mpLastBitmap(),
214 mpLastBitmapCanvas()
218 const ::cppcanvas::CanvasSharedPtr& getDestinationCanvas() const
220 return mpDestinationCanvas;
223 ::cppcanvas::CanvasSharedPtr mpDestinationCanvas;
224 ::cppcanvas::RendererSharedPtr mpRenderer;
225 GDIMetaFileSharedPtr mpMtf;
226 ::cppcanvas::BitmapSharedPtr mpLastBitmap;
227 ::cppcanvas::BitmapCanvasSharedPtr mpLastBitmapCanvas;
230 typedef ::std::vector< RendererCacheEntry > RendererCacheVector;
233 /** Prefetch Renderer for given canvas
235 static bool prefetch( RendererCacheEntry& io_rCacheEntry,
236 const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
237 const GDIMetaFileSharedPtr& rMtf,
238 const ShapeAttributeLayerSharedPtr& rAttr );
240 /** Draw with prefetched Renderer to stored canvas
242 This method draws prefetched Renderer to its
243 associated canvas (which happens to be mpLastCanvas).
245 bool draw( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
246 const GDIMetaFileSharedPtr& rMtf,
247 const ShapeAttributeLayerSharedPtr& rAttr,
248 const ::basegfx::B2DHomMatrix& rTransform,
249 const ::basegfx::B2DPolyPolygon* pClip,
250 const VectorOfDocTreeNodes& rSubsets ) const;
252 /** Render shape to an active sprite
254 bool renderSprite( const ViewLayerSharedPtr& rViewLayer,
255 const GDIMetaFileSharedPtr& rMtf,
256 const ::basegfx::B2DRectangle& rOrigBounds,
257 const ::basegfx::B2DRectangle& rBounds,
258 const ::basegfx::B2DRectangle& rUnitBounds,
259 UpdateFlags nUpdateFlags,
260 const ShapeAttributeLayerSharedPtr& pAttr,
261 const VectorOfDocTreeNodes& rSubsets,
262 double nPrio,
263 bool bIsVisible ) const;
265 /** Render shape to given canvas
267 bool render( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
268 const GDIMetaFileSharedPtr& rMtf,
269 const ::basegfx::B2DRectangle& rBounds,
270 const ::basegfx::B2DRectangle& rUpdateBounds,
271 UpdateFlags nUpdateFlags,
272 const ShapeAttributeLayerSharedPtr& pAttr,
273 const VectorOfDocTreeNodes& rSubsets,
274 bool bIsVisible ) const;
276 enum{ MAX_RENDER_CACHE_ENTRIES=2 };
278 /** Retrieve a valid iterator to renderer cache entry
280 This method ensures that an internal limit of
281 MAX_RENDER_CACHE_ENTRIES is not exceeded.
283 @param rDestinationCanvas
284 Destination canvas to retrieve cache entry for
286 @return a valid iterator to a renderer cache entry for
287 the given canvas. The entry might be
288 default-constructed (if newly added)
290 RendererCacheVector::iterator getCacheEntry( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas ) const;
292 void invalidateRenderer() const;
294 /** The view layer this object is part of.
296 Needed for sprite creation
298 ViewLayerSharedPtr mpViewLayer;
300 /// A set of cached mtf/canvas combinations
301 mutable RendererCacheVector maRenderers;
303 /// The sprite object
304 mutable AnimatedSpriteSharedPtr mpSprite;
306 /// If true, render() calls go to the sprite
307 mutable bool mbAnimationMode;
309 /// If true, shape needs full repaint (and the sprite a setup, if any)
310 mutable bool mbForceUpdate;
313 typedef ::std::shared_ptr< ViewShape > ViewShapeSharedPtr;
317 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_VIEWSHAPE_HXX
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */