1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <canvas/debug.hxx>
22 #include <tools/diagnose_ex.h>
23 #include <canvas/verbosetrace.hxx>
25 #include <rtl/math.hxx>
27 #include <vcl/outdev.hxx>
28 #include <vcl/bitmap.hxx>
29 #include <vcl/alpha.hxx>
30 #include <vcl/bitmapex.hxx>
31 #include <vcl/canvastools.hxx>
33 #include <basegfx/matrix/b2dhommatrix.hxx>
34 #include <basegfx/point/b2dpoint.hxx>
35 #include <basegfx/tools/canvastools.hxx>
36 #include <basegfx/polygon/b2dpolygon.hxx>
37 #include <basegfx/polygon/b2dpolygontools.hxx>
38 #include <basegfx/polygon/b2dpolypolygontools.hxx>
39 #include <basegfx/numeric/ftools.hxx>
41 #include <canvas/canvastools.hxx>
43 #include "canvascustomsprite.hxx"
45 using namespace ::com::sun::star
;
51 CanvasCustomSprite::CanvasCustomSprite( const geometry::RealSize2D
& rSpriteSize
,
52 rendering::XGraphicDevice
& rDevice
,
53 const ::canvas::SpriteSurface::Reference
& rOwningSpriteCanvas
,
54 const OutDevProviderSharedPtr
& rOutDevProvider
,
55 bool bShowSpriteBounds
)
57 ENSURE_OR_THROW( rOwningSpriteCanvas
.get() &&
59 "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
65 static_cast<sal_Int32
>( ::std::max( 1.0,
66 ceil( rSpriteSize
.Width
))), // round up to nearest int,
67 // enforce sprite to have at
68 // least (1,1) pixel size
69 static_cast<sal_Int32
>( ::std::max( 1.0,
70 ceil( rSpriteSize
.Height
))) );
72 // create content backbuffer in screen depth
73 BackBufferSharedPtr
pBackBuffer( new BackBuffer( rOutDevProvider
->getOutDev() ) );
74 pBackBuffer
->setSize( aSize
);
76 // create mask backbuffer, with one bit color depth
77 BackBufferSharedPtr
pBackBufferMask( new BackBuffer( rOutDevProvider
->getOutDev(),
79 pBackBufferMask
->setSize( aSize
);
81 // TODO(F1): Implement alpha vdev (could prolly enable
82 // antialiasing again, then)
84 // disable font antialiasing (causes ugly shadows otherwise)
85 pBackBuffer
->getOutDev().SetAntialiasing( ANTIALIASING_DISABLE_TEXT
);
86 pBackBufferMask
->getOutDev().SetAntialiasing( ANTIALIASING_DISABLE_TEXT
);
88 // set mask vdev drawmode, such that everything is painted
89 // black. That leaves us with a binary image, white for
90 // background, black for painted content
91 pBackBufferMask
->getOutDev().SetDrawMode( DRAWMODE_BLACKLINE
| DRAWMODE_BLACKFILL
| DRAWMODE_BLACKTEXT
|
92 DRAWMODE_BLACKGRADIENT
| DRAWMODE_BLACKBITMAP
);
95 // setup canvas helper
96 // -------------------
98 // always render into back buffer, don't preserve state (it's
99 // our private VDev, after all), have notion of alpha
100 maCanvasHelper
.init( rDevice
,
104 maCanvasHelper
.setBackgroundOutDev( pBackBufferMask
);
107 // setup sprite helper
108 // -------------------
110 maSpriteHelper
.init( rSpriteSize
,
116 // clear sprite to 100% transparent
117 maCanvasHelper
.clear();
120 #define IMPLEMENTATION_NAME "VCLCanvas.CanvasCustomSprite"
121 #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite"
123 OUString SAL_CALL
CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException
)
125 return OUString( IMPLEMENTATION_NAME
);
128 sal_Bool SAL_CALL
CanvasCustomSprite::supportsService( const OUString
& ServiceName
) throw( uno::RuntimeException
)
130 return ServiceName
== SERVICE_NAME
;
133 uno::Sequence
< OUString
> SAL_CALL
CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException
)
135 uno::Sequence
< OUString
> aRet(1);
136 aRet
[0] = OUString( SERVICE_NAME
);
142 void CanvasCustomSprite::redraw( OutputDevice
& rOutDev
,
143 bool bBufferedUpdate
) const
145 SolarMutexGuard aGuard
;
147 redraw( rOutDev
, maSpriteHelper
.getPosPixel(), bBufferedUpdate
);
150 void CanvasCustomSprite::redraw( OutputDevice
& rOutDev
,
151 const ::basegfx::B2DPoint
& rOrigOutputPos
,
152 bool bBufferedUpdate
) const
154 SolarMutexGuard aGuard
;
156 maSpriteHelper
.redraw( rOutDev
,
161 mbSurfaceDirty
= false;
164 bool CanvasCustomSprite::repaint( const GraphicObjectSharedPtr
& rGrf
,
165 const rendering::ViewState
& viewState
,
166 const rendering::RenderState
& renderState
,
169 const GraphicAttr
& rAttr
) const
171 SolarMutexGuard aGuard
;
173 mbSurfaceDirty
= true;
175 return maCanvasHelper
.repaint( rGrf
, viewState
, renderState
, rPt
, rSz
, rAttr
);
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */