LibreOffice Module canvas (master)  1
dx_canvascustomsprite.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 <sal/config.h>
21 
25 #include <rtl/math.hxx>
26 #include <tools/diagnose_ex.h>
27 
28 #include <canvas/canvastools.hxx>
29 
31 #include "dx_impltools.hxx"
32 #include "dx_spritecanvas.hxx"
33 
34 using namespace ::com::sun::star;
35 
36 namespace dxcanvas
37 {
38  CanvasCustomSprite::CanvasCustomSprite( const css::geometry::RealSize2D& rSpriteSize,
39  const SpriteCanvasRef& rRefDevice,
40  const IDXRenderModuleSharedPtr& rRenderModule,
41  const std::shared_ptr<canvas::ISurfaceProxyManager>& rSurfaceProxy,
42  bool bShowSpriteBounds ) :
43  mpSpriteCanvas( rRefDevice ),
44  mpSurface()
45  {
46  ENSURE_OR_THROW( rRefDevice.get(),
47  "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
48 
49  mpSurface.reset(
50  new DXSurfaceBitmap(
52  ::canvas::tools::roundUp( rSpriteSize.Width ),
53  ::canvas::tools::roundUp( rSpriteSize.Height )),
54  rSurfaceProxy,
55  rRenderModule,
56  true));
57 
58  maCanvasHelper.setDevice( *rRefDevice );
59  maCanvasHelper.setTarget( mpSurface );
60 
61  maSpriteHelper.init( rSpriteSize,
62  rRefDevice,
63  rRenderModule,
64  mpSurface,
65  bShowSpriteBounds );
66 
67  // clear sprite to 100% transparent
68  maCanvasHelper.clear();
69  }
70 
72  {
73  ::osl::MutexGuard aGuard( m_aMutex );
74 
75  mpSurface.reset();
76  mpSpriteCanvas.clear();
77 
78  // forward to parent
80  }
81 
83  {
84  return "DXCanvas.CanvasCustomSprite";
85  }
86 
87  sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const OUString& ServiceName )
88  {
89  return cppu::supportsService( this, ServiceName );
90  }
91 
92  uno::Sequence< OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames()
93  {
94  return { "com.sun.star.rendering.CanvasCustomSprite" };
95  }
96 
98  {
99  ::osl::MutexGuard aGuard( m_aMutex );
100 
101  maSpriteHelper.redraw( mbSurfaceDirty );
102  }
103 }
104 
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
osl::Mutex m_aMutex
SpriteCanvasRef mpSpriteCanvas
MUST hold here, too, since BitmapCanvasHelper only contains a raw pointer (without refcounting) ...
std::shared_ptr< IDXRenderModule > IDXRenderModuleSharedPtr
const cppcanvas::SpriteCanvasSharedPtr mpSpriteCanvas
CanvasCustomSprite(const css::geometry::RealSize2D &rSpriteSize, const SpriteCanvasRef &rRefDevice, const IDXRenderModuleSharedPtr &rRenderModule, const std::shared_ptr< canvas::ISurfaceProxyManager > &rSurfaceProxy, bool bShowSpriteBounds)
Create a custom sprite.
virtual void disposeThis() override
Object is being disposed.
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual void disposeThis() override
Object is being disposed.
unsigned char sal_Bool
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
CanvasHelper maCanvasHelper
Definition: canvasbase.hxx:443
virtual void redraw() const override
#define ENSURE_OR_THROW(c, m)
sal_Int32 roundUp(const double &rVal)
Round given floating point value up to next integer.
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
DXSurfaceBitmapSharedPtr mpSurface
COMReference< surface_type > mpSurface