Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / canvas / source / vcl / canvascustomsprite.cxx
blob316176f6ac2451731552b25e33396a5db4fbf690
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 .
21 #include <sal/config.h>
23 #include <basegfx/point/b2dpoint.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <comphelper/diagnose_ex.hxx>
26 #include <vcl/outdev.hxx>
28 #include "canvascustomsprite.hxx"
30 using namespace ::com::sun::star;
33 namespace vclcanvas
36 CanvasCustomSprite::CanvasCustomSprite( const geometry::RealSize2D& rSpriteSize,
37 rendering::XGraphicDevice& rDevice,
38 const ::canvas::SpriteSurface::Reference& rOwningSpriteCanvas,
39 const OutDevProviderSharedPtr& rOutDevProvider,
40 bool bShowSpriteBounds )
42 ENSURE_OR_THROW( rOwningSpriteCanvas &&
43 rOutDevProvider,
44 "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
46 // setup back buffer
49 const ::Size aSize(
50 static_cast<sal_Int32>( std::max( 1.0,
51 ceil( rSpriteSize.Width ))), // round up to nearest int,
52 // enforce sprite to have at
53 // least (1,1) pixel size
54 static_cast<sal_Int32>( std::max( 1.0,
55 ceil( rSpriteSize.Height ))) );
57 // create content backbuffer in screen depth
58 BackBufferSharedPtr pBackBuffer = std::make_shared<BackBuffer>( rOutDevProvider->getOutDev() );
59 pBackBuffer->setSize( aSize );
61 // create mask backbuffer
62 BackBufferSharedPtr pBackBufferMask = std::make_shared<BackBuffer>( rOutDevProvider->getOutDev() );
63 pBackBufferMask->setSize( aSize );
65 // TODO(F1): Implement alpha vdev (could prolly enable
66 // antialiasing again, then)
68 // disable font antialiasing (causes ugly shadows otherwise)
69 pBackBuffer->getOutDev().SetAntialiasing( AntialiasingFlags::DisableText );
70 pBackBufferMask->getOutDev().SetAntialiasing( AntialiasingFlags::DisableText );
72 // set mask vdev drawmode, such that everything is painted
73 // black. That leaves us with a binary image, white for
74 // background, black for painted content
75 pBackBufferMask->getOutDev().SetDrawMode( DrawModeFlags::BlackLine | DrawModeFlags::BlackFill | DrawModeFlags::BlackText |
76 DrawModeFlags::BlackGradient | DrawModeFlags::BlackBitmap );
79 // setup canvas helper
82 // always render into back buffer, don't preserve state (it's
83 // our private VDev, after all), have notion of alpha
84 maCanvasHelper.init( rDevice,
85 pBackBuffer,
86 false,
87 true );
88 maCanvasHelper.setBackgroundOutDev( pBackBufferMask );
91 // setup sprite helper
94 maSpriteHelper.init( rSpriteSize,
95 rOwningSpriteCanvas,
96 pBackBuffer,
97 pBackBufferMask,
98 bShowSpriteBounds );
100 // clear sprite to 100% transparent
101 maCanvasHelper.clear();
104 OUString SAL_CALL CanvasCustomSprite::getImplementationName()
106 return u"VCLCanvas.CanvasCustomSprite"_ustr;
109 sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const OUString& ServiceName )
111 return cppu::supportsService( this, ServiceName );
114 uno::Sequence< OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames()
116 return { u"com.sun.star.rendering.CanvasCustomSprite"_ustr };
119 // Sprite
120 void CanvasCustomSprite::redraw( OutputDevice& rOutDev,
121 bool bBufferedUpdate ) const
123 SolarMutexGuard aGuard;
125 redraw( rOutDev, maSpriteHelper.getPosPixel(), bBufferedUpdate );
128 void CanvasCustomSprite::redraw( OutputDevice& rOutDev,
129 const ::basegfx::B2DPoint& rOrigOutputPos,
130 bool bBufferedUpdate ) const
132 SolarMutexGuard aGuard;
134 maSpriteHelper.redraw( rOutDev,
135 rOrigOutputPos,
136 mbSurfaceDirty,
137 bBufferedUpdate );
139 mbSurfaceDirty = false;
142 bool CanvasCustomSprite::repaint( const GraphicObjectSharedPtr& rGrf,
143 const rendering::ViewState& viewState,
144 const rendering::RenderState& renderState,
145 const ::Point& rPt,
146 const ::Size& rSz,
147 const GraphicAttr& rAttr ) const
149 SolarMutexGuard aGuard;
151 mbSurfaceDirty = true;
153 return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */