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 
22 #include <memory>
23 
27 #include <rtl/math.hxx>
28 #include <tools/diagnose_ex.h>
29 
30 #include <canvas/canvastools.hxx>
31 
33 #include "dx_impltools.hxx"
34 #include "dx_spritecanvas.hxx"
35 
36 using namespace ::com::sun::star;
37 
38 namespace dxcanvas
39 {
40  CanvasCustomSprite::CanvasCustomSprite( const css::geometry::RealSize2D& rSpriteSize,
41  const SpriteCanvasRef& rRefDevice,
42  const IDXRenderModuleSharedPtr& rRenderModule,
43  const std::shared_ptr<canvas::ISurfaceProxyManager>& rSurfaceProxy,
44  bool bShowSpriteBounds ) :
45  mpSpriteCanvas( rRefDevice ),
46  mpSurface()
47  {
48  ENSURE_OR_THROW( rRefDevice.get(),
49  "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
50 
51  mpSurface = std::make_shared<DXSurfaceBitmap>(
53  ::canvas::tools::roundUp( rSpriteSize.Width ),
54  ::canvas::tools::roundUp( rSpriteSize.Height )),
55  rSurfaceProxy,
56  rRenderModule,
57  true);
58 
59  maCanvasHelper.setDevice( *rRefDevice );
60  maCanvasHelper.setTarget( mpSurface );
61 
62  maSpriteHelper.init( rSpriteSize,
63  rRefDevice,
64  rRenderModule,
65  mpSurface,
66  bShowSpriteBounds );
67 
68  // clear sprite to 100% transparent
69  maCanvasHelper.clear();
70  }
71 
73  {
74  ::osl::MutexGuard aGuard( m_aMutex );
75 
76  mpSurface.reset();
77  mpSpriteCanvas.clear();
78 
79  // forward to parent
81  }
82 
84  {
85  return "DXCanvas.CanvasCustomSprite";
86  }
87 
88  sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const OUString& ServiceName )
89  {
90  return cppu::supportsService( this, ServiceName );
91  }
92 
93  uno::Sequence< OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames()
94  {
95  return { "com.sun.star.rendering.CanvasCustomSprite" };
96  }
97 
99  {
100  ::osl::MutexGuard aGuard( m_aMutex );
101 
102  maSpriteHelper.redraw( mbSurfaceDirty );
103  }
104 }
105 
106 /* 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:442
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