LibreOffice Module vcl (master) 1
AnimationRenderer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <memory>
22
23#include <vcl/virdev.hxx>
24#include <vcl/window.hxx>
25#include <tools/helpers.hxx>
26
27#include <window.h>
28
30 const Point& rPt, const Size& rSz,
31 sal_uLong nRendererId,
32 OutputDevice* pFirstFrameOutDev ) :
33 mpParent ( pParent ),
34 mpRenderContext ( pFirstFrameOutDev ? pFirstFrameOutDev : pOut ),
35 mnRendererId ( nRendererId ),
36 maOriginPt ( rPt ),
37 maLogicalSize ( rSz ),
38 maSizePx ( mpRenderContext->LogicToPixel( maLogicalSize ) ),
39 maClip ( mpRenderContext->GetClipRegion() ),
41 mpRestore ( VclPtr<VirtualDevice>::Create() ),
42 mnActIndex ( 0 ),
43 meLastDisposal ( Disposal::Back ),
44 mbIsPaused ( false ),
45 mbIsMarked ( false ),
46 mbIsMirroredHorizontally( maLogicalSize.Width() < 0 ),
47 mbIsMirroredVertically( maLogicalSize.Height() < 0 )
48{
50
51 // Mirrored horizontally?
53 {
57 }
58 else
59 {
62 }
63
64 // Mirrored vertically?
66 {
70 }
71 else
72 {
75 }
76
77 // save background
80
81 // Initialize drawing to actual position
83
84 // If first frame OutputDevice is set, update variables now for real OutputDevice
85 if( pFirstFrameOutDev )
86 {
89 }
90}
91
93{
96
98}
99
100bool AnimationRenderer::matches(const OutputDevice* pOut, tools::Long nRendererId) const
101{
102 return (!pOut || pOut == mpRenderContext) && (nRendererId == 0 || nRendererId == mnRendererId);
103}
104
105void AnimationRenderer::getPosSize( const AnimationFrame& rAnimationFrame, Point& rPosPix, Size& rSizePix )
106{
107 const Size& rAnmSize = mpParent->GetDisplaySizePixel();
108 Point aPt2( rAnimationFrame.maPositionPixel.X() + rAnimationFrame.maSizePixel.Width() - 1,
109 rAnimationFrame.maPositionPixel.Y() + rAnimationFrame.maSizePixel.Height() - 1 );
110 double fFactX, fFactY;
111
112 // calculate x scaling
113 if( rAnmSize.Width() > 1 )
114 fFactX = static_cast<double>( maSizePx.Width() - 1 ) / ( rAnmSize.Width() - 1 );
115 else
116 fFactX = 1.0;
117
118 // calculate y scaling
119 if( rAnmSize.Height() > 1 )
120 fFactY = static_cast<double>( maSizePx.Height() - 1 ) / ( rAnmSize.Height() - 1 );
121 else
122 fFactY = 1.0;
123
124 rPosPix.setX( FRound( rAnimationFrame.maPositionPixel.X() * fFactX ) );
125 rPosPix.setY( FRound( rAnimationFrame.maPositionPixel.Y() * fFactY ) );
126
127 aPt2.setX( FRound( aPt2.X() * fFactX ) );
128 aPt2.setY( FRound( aPt2.Y() * fFactY ) );
129
130 rSizePix.setWidth( aPt2.X() - rPosPix.X() + 1 );
131 rSizePix.setHeight( aPt2.Y() - rPosPix.Y() + 1 );
132
133 // Mirrored horizontally?
135 rPosPix.setX( maSizePx.Width() - 1 - aPt2.X() );
136
137 // Mirrored vertically?
139 rPosPix.setY( maSizePx.Height() - 1 - aPt2.Y() );
140}
141
143{
145
148 {
149 vcl::Window* pWindow = static_cast<vcl::WindowOutputDevice*>(mpRenderContext.get())->GetOwnerWindow();
150 pGuard.reset(new vcl::PaintBufferGuard(pWindow->ImplGetWindowImpl()->mpFrameData, pWindow));
151 pRenderContext = pGuard->GetRenderContext();
152 }
153
155 std::optional<vcl::Region> xOldClip;
156 if (!maClip.IsNull())
157 xOldClip = pRenderContext->GetClipRegion();
158
159 aVDev->SetOutputSizePixel( maSizePx, false );
160 nIndex = std::min( nIndex, static_cast<sal_uLong>(mpParent->Count()) - 1 );
161
162 for( sal_uLong i = 0; i <= nIndex; i++ )
163 draw( i, aVDev.get() );
164
165 if (xOldClip)
166 pRenderContext->SetClipRegion( maClip );
167
168 pRenderContext->DrawOutDev( maDispPt, maDispSz, Point(), maSizePx, *aVDev );
169 if (pGuard)
170 pGuard->SetPaintRect(tools::Rectangle(maDispPt, maDispSz));
171
172 if (xOldClip)
173 pRenderContext->SetClipRegion(*xOldClip);
174}
175
177{
179
181 if (!pVDev && mpRenderContext->GetOutDevType() == OUTDEV_WINDOW)
182 {
183 vcl::Window* pWindow = static_cast<vcl::WindowOutputDevice*>(mpRenderContext.get())->GetOwnerWindow();
184 pGuard.reset(new vcl::PaintBufferGuard(pWindow->ImplGetWindowImpl()->mpFrameData, pWindow));
185 pRenderContext = pGuard->GetRenderContext();
186 }
187
188 tools::Rectangle aOutRect( pRenderContext->PixelToLogic( Point() ), pRenderContext->GetOutputSize() );
189
190 // check, if output lies out of display
192 {
193 setMarked( true );
194 }
195 else if( !mbIsPaused )
196 {
198 Point aPosPix;
199 Point aBmpPosPix;
200 Size aSizePix;
201 Size aBmpSizePix;
202 const sal_uLong nLastPos = mpParent->Count() - 1;
203 mnActIndex = std::min( nIndex, nLastPos );
204 const AnimationFrame& rAnimationFrame = mpParent->Get( static_cast<sal_uInt16>( mnActIndex ) );
205
206 getPosSize( rAnimationFrame, aPosPix, aSizePix );
207
208 // Mirrored horizontally?
210 {
211 aBmpPosPix.setX( aPosPix.X() + aSizePix.Width() - 1 );
212 aBmpSizePix.setWidth( -aSizePix.Width() );
213 }
214 else
215 {
216 aBmpPosPix.setX( aPosPix.X() );
217 aBmpSizePix.setWidth( aSizePix.Width() );
218 }
219
220 // Mirrored vertically?
222 {
223 aBmpPosPix.setY( aPosPix.Y() + aSizePix.Height() - 1 );
224 aBmpSizePix.setHeight( -aSizePix.Height() );
225 }
226 else
227 {
228 aBmpPosPix.setY( aPosPix.Y() );
229 aBmpSizePix.setHeight( aSizePix.Height() );
230 }
231
232 // get output device
233 if( !pVDev )
234 {
236 pDev->SetOutputSizePixel( maSizePx, false );
237 pDev->DrawOutDev( Point(), maSizePx, maDispPt, maDispSz, *pRenderContext );
238 }
239 else
240 pDev = pVDev;
241
242 // restore background after each run
243 if( !nIndex )
244 {
246 maRestPt = Point();
248 }
249
250 // restore
252 {
255 else
257 }
258
259 meLastDisposal = rAnimationFrame.meDisposal;
260 maRestPt = aPosPix;
261 maRestSz = aSizePix;
262
263 // What do we need to restore the next time?
264 // Put it into a bitmap if needed, else delete
265 // SaveBitmap to conserve memory
267 mpRestore->SetOutputSizePixel( Size( 1, 1 ), false );
268 else
269 {
271 mpRestore->DrawOutDev( Point(), maRestSz, aPosPix, aSizePix, *pDev );
272 }
273
274 pDev->DrawBitmapEx( aBmpPosPix, aBmpSizePix, rAnimationFrame.maBitmapEx );
275
276 if( !pVDev )
277 {
278 std::optional<vcl::Region> xOldClip;
279 if (!maClip.IsNull())
280 xOldClip = pRenderContext->GetClipRegion();
281
282 if (xOldClip)
283 pRenderContext->SetClipRegion( maClip );
284
285 pRenderContext->DrawOutDev( maDispPt, maDispSz, Point(), maSizePx, *pDev );
286 if (pGuard)
287 pGuard->SetPaintRect(tools::Rectangle(maDispPt, maDispSz));
288
289 if( xOldClip)
290 {
291 pRenderContext->SetClipRegion(*xOldClip);
292 xOldClip.reset();
293 }
294
295 pDev.disposeAndClear();
296 pRenderContext->Flush();
297 }
298 }
299}
300
302{
303 const bool bOldPause = mbIsPaused;
304
306
307 mbIsPaused = false;
309 mbIsPaused = bOldPause;
310}
311
313{
314 AnimationData* pDataItem = new AnimationData;
315
316 pDataItem->maOriginStartPt = maOriginPt;
317 pDataItem->maStartSize = maLogicalSize;
318 pDataItem->mpRenderContext = mpRenderContext;
319 pDataItem->mpRendererData = const_cast<AnimationRenderer *>(this);
320 pDataItem->mnRendererId = mnRendererId;
321 pDataItem->mbIsPaused = mbIsPaused;
322
323 return pDataItem;
324}
325
326/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Disposal
SharedBitmapDescriptor mpBackground
AnimationRenderer(Animation *pParent, OutputDevice *pOut, const Point &rPt, const Size &rSz, sal_uLong nRendererId, OutputDevice *pFirstFrameOutDev=nullptr)
void setMarked(bool bIsMarked)
VclPtr< OutputDevice > mpRenderContext
void getPosSize(const AnimationFrame &rAnm, Point &rPosPix, Size &rSizePix)
AnimationData * createAnimationData() const
bool matches(const OutputDevice *pOut, tools::Long nRendererId) const
VclPtr< VirtualDevice > mpBackground
void drawToIndex(sal_uLong nIndex)
void draw(sal_uLong nIndex, VirtualDevice *pVDev=nullptr)
VclPtr< VirtualDevice > mpRestore
SAL_DLLPRIVATE sal_uLong ImplGetCurPos() const
Definition: Animation.hxx:95
size_t Count() const
Definition: Animation.hxx:71
static SAL_DLLPRIVATE void ImplIncAnimCount()
Definition: Animation.hxx:93
const Size & GetDisplaySizePixel() const
Definition: Animation.hxx:57
const AnimationFrame & Get(sal_uInt16 nAnimation) const
Definition: Animation.cxx:434
static SAL_DLLPRIVATE void ImplDecAnimCount()
Definition: Animation.hxx:94
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:170
virtual void SaveBackground(VirtualDevice &rSaveDevice, const Point &rPos, const Size &rSize, const Size &rBackgroundSize) const
vcl::Region GetClipRegion() const
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
Definition: bitmapex.cxx:33
virtual void DrawOutDev(const Point &rDestPt, const Size &rDestSize, const Point &rSrcPt, const Size &rSrcSize)
Definition: outdev.cxx:417
OutDevType GetOutDevType() const
Definition: outdev.hxx:406
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
constexpr tools::Long X() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: vclptr.hxx:58
void disposeAndClear()
Definition: vclptr.hxx:200
void reset(reference_type *pBody)
Definition: vclptr.hxx:153
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
static VclPtr< reference_type > Create(Arg &&... arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
bool SetOutputSizePixel(const Size &rNewSize, bool bErase=true, bool bAlphaMaskTransparent=false)
Definition: virdev.cxx:405
ImplFrameData * mpFrameData
Definition: window.h:228
tools::Rectangle & Intersection(const tools::Rectangle &rRect)
constexpr bool IsEmpty() const
Sets up the buffer to have settings matching the window, and restores the original state in the dtor.
Definition: window.h:405
bool IsNull() const
Definition: region.hxx:99
SAL_DLLPRIVATE WindowImpl * ImplGetWindowImpl() const
Definition: window.hxx:528
RegionData_Impl * mpParent
tools::Long FRound(double fVal)
sal_Int32 nIndex
int i
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
long Long
std::unique_ptr< PaintBufferGuard, o3tl::default_delete< PaintBufferGuard > > PaintBufferGuardPtr
Definition: window.h:422
@ OUTDEV_WINDOW
Definition: outdev.hxx:145
basegfx::B2DPolyPolygon maClip
sal_uIntPtr sal_uLong
VclPtr< OutputDevice > mpRenderContext
tools::Long mnRendererId
oslFileHandle & pOut