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 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include <basegfx/point/b2dpoint.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <comphelper/diagnose_ex.hxx>
27 #include <canvas/canvastools.hxx>
30 #include "cairo_canvascustomsprite.hxx"
31 #include "cairo_spritecanvas.hxx"
34 using namespace ::cairo
;
35 using namespace ::com::sun::star
;
39 CanvasCustomSprite::CanvasCustomSprite( const css::geometry::RealSize2D
& rSpriteSize
,
40 const SpriteCanvasRef
& rRefDevice
) :
41 mpSpriteCanvas( rRefDevice
),
42 maSize( ::canvas::tools::roundUp( rSpriteSize
.Width
),
43 ::canvas::tools::roundUp( rSpriteSize
.Height
) )
45 ENSURE_OR_THROW( rRefDevice
,
46 "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
48 SAL_INFO( "canvas.cairo", "sprite size: " << ::canvas::tools::roundUp( rSpriteSize
.Width
) << ", " << ::canvas::tools::roundUp( rSpriteSize
.Height
));
50 mpBufferSurface
= mpSpriteCanvas
->createSurface( maSize
, CAIRO_CONTENT_COLOR_ALPHA
);
52 maCanvasHelper
.init( maSize
,
55 maCanvasHelper
.setSurface( mpBufferSurface
, true );
57 maSpriteHelper
.init( rSpriteSize
,
59 maSpriteHelper
.setSurface( mpBufferSurface
);
61 // clear sprite to 100% transparent
62 maCanvasHelper
.clear();
65 void CanvasCustomSprite::disposeThis()
67 ::osl::MutexGuard
aGuard( m_aMutex
);
69 mpSpriteCanvas
.clear();
70 mpBufferSurface
.reset();
73 CanvasCustomSpriteBaseT::disposeThis();
76 void CanvasCustomSprite::redraw( const CairoSharedPtr
& pCairo
,
77 bool bBufferedUpdate
) const
79 ::osl::MutexGuard
aGuard( m_aMutex
);
81 redraw( pCairo
, maSpriteHelper
.getPosPixel(), bBufferedUpdate
);
84 void CanvasCustomSprite::redraw( const CairoSharedPtr
& pCairo
,
85 const ::basegfx::B2DPoint
& rOrigOutputPos
,
86 bool bBufferedUpdate
) const
88 ::osl::MutexGuard
aGuard( m_aMutex
);
90 maSpriteHelper
.redraw( pCairo
,
95 mbSurfaceDirty
= false;
98 bool CanvasCustomSprite::repaint( const SurfaceSharedPtr
& pSurface
,
99 const rendering::ViewState
& viewState
,
100 const rendering::RenderState
& renderState
)
102 return maCanvasHelper
.repaint( pSurface
, viewState
, renderState
);
105 SurfaceSharedPtr
CanvasCustomSprite::getSurface()
107 return mpBufferSurface
;
110 SurfaceSharedPtr
CanvasCustomSprite::createSurface( const ::basegfx::B2ISize
& rSize
, int aContent
)
112 return mpSpriteCanvas
->createSurface(rSize
,aContent
);
115 SurfaceSharedPtr
CanvasCustomSprite::createSurface( ::Bitmap
& rBitmap
)
117 return mpSpriteCanvas
->createSurface(rBitmap
);
120 SurfaceSharedPtr
CanvasCustomSprite::changeSurface()
122 SAL_INFO( "canvas.cairo", "replacing sprite background surface");
124 mpBufferSurface
= mpSpriteCanvas
->createSurface( maSize
, CAIRO_CONTENT_COLOR
);
125 maSpriteHelper
.setSurface( mpBufferSurface
);
127 return mpBufferSurface
;
130 OutputDevice
* CanvasCustomSprite::getOutputDevice()
132 return mpSpriteCanvas
->getOutputDevice();
135 OUString SAL_CALL
CanvasCustomSprite::getImplementationName()
137 return u
"CairoCanvas.CanvasCustomSprite"_ustr
;
140 sal_Bool SAL_CALL
CanvasCustomSprite::supportsService( const OUString
& ServiceName
)
142 return cppu::supportsService( this, ServiceName
);
145 uno::Sequence
< OUString
> SAL_CALL
CanvasCustomSprite::getSupportedServiceNames()
147 return { u
"com.sun.star.rendering.CanvasCustomSprite"_ustr
};
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */