Branch libreoffice-5-0-4
[LibreOffice.git] / canvas / source / directx / dx_canvascustomsprite.cxx
blob1be4db519080ed7de7d895fb6fab70b0bfef834a
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 <ctype.h>
22 #include <canvas/debug.hxx>
23 #include <canvas/verbosetrace.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <tools/diagnose_ex.h>
27 #include <rtl/math.hxx>
29 #include <canvas/canvastools.hxx>
31 #include <basegfx/matrix/b2dhommatrix.hxx>
32 #include <basegfx/point/b2dpoint.hxx>
34 #include "dx_canvascustomsprite.hxx"
35 #include "dx_spritecanvas.hxx"
36 #include "dx_impltools.hxx"
38 using namespace ::com::sun::star;
40 namespace dxcanvas
42 CanvasCustomSprite::CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& rSpriteSize,
43 const SpriteCanvasRef& rRefDevice,
44 const IDXRenderModuleSharedPtr& rRenderModule,
45 const ::canvas::ISurfaceProxyManagerSharedPtr& rSurfaceProxy,
46 bool bShowSpriteBounds ) :
47 mpSpriteCanvas( rRefDevice ),
48 mpSurface()
50 ENSURE_OR_THROW( rRefDevice.get(),
51 "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
53 mpSurface.reset(
54 new DXSurfaceBitmap(
55 ::basegfx::B2IVector(
56 ::canvas::tools::roundUp( rSpriteSize.Width ),
57 ::canvas::tools::roundUp( rSpriteSize.Height )),
58 rSurfaceProxy,
59 rRenderModule,
60 true));
62 maCanvasHelper.setDevice( *rRefDevice.get() );
63 maCanvasHelper.setTarget( mpSurface );
65 maSpriteHelper.init( rSpriteSize,
66 rRefDevice,
67 rRenderModule,
68 mpSurface,
69 bShowSpriteBounds );
71 // clear sprite to 100% transparent
72 maCanvasHelper.clear();
75 void CanvasCustomSprite::disposeThis()
77 ::osl::MutexGuard aGuard( m_aMutex );
79 mpSurface.reset();
80 mpSpriteCanvas.clear();
82 // forward to parent
83 CanvasCustomSpriteBaseT::disposeThis();
86 OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException )
88 return OUString( "DXCanvas.CanvasCustomSprite" );
91 sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException )
93 return cppu::supportsService( this, ServiceName );
96 uno::Sequence< OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException )
98 uno::Sequence< OUString > aRet(1);
99 aRet[0] = "com.sun.star.rendering.CanvasCustomSprite";
101 return aRet;
104 void CanvasCustomSprite::redraw() const
106 ::osl::MutexGuard aGuard( m_aMutex );
108 maSpriteHelper.redraw( mbSurfaceDirty );
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */