LibreOffice Module canvas (master)  1
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 
21 #include <sal/config.h>
22 
25 #include <tools/diagnose_ex.h>
26 #include <vcl/outdev.hxx>
27 
28 #include "canvascustomsprite.hxx"
29 
30 using namespace ::com::sun::star;
31 
32 
33 namespace vclcanvas
34 {
35 
36  CanvasCustomSprite::CanvasCustomSprite( const geometry::RealSize2D& rSpriteSize,
37  rendering::XGraphicDevice& rDevice,
38  const ::canvas::SpriteSurface::Reference& rOwningSpriteCanvas,
39  const OutDevProviderSharedPtr& rOutDevProvider,
40  bool bShowSpriteBounds )
41  {
42  ENSURE_OR_THROW( rOwningSpriteCanvas &&
43  rOutDevProvider,
44  "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
45 
46  // setup back buffer
47 
48 
49  const ::Size aSize(
50  static_cast<sal_Int32>( std::max( 1.0,
51  ceil( rSpriteSize.Width ))), // round up to nearest int,
52  // enforce sprite to have at
53  // least (1,1) pixel size
54  static_cast<sal_Int32>( std::max( 1.0,
55  ceil( rSpriteSize.Height ))) );
56 
57  // create content backbuffer in screen depth
58  BackBufferSharedPtr pBackBuffer = std::make_shared<BackBuffer>( rOutDevProvider->getOutDev() );
59  pBackBuffer->setSize( aSize );
60 
61  // create mask backbuffer
62  BackBufferSharedPtr pBackBufferMask = std::make_shared<BackBuffer>( rOutDevProvider->getOutDev() );
63  pBackBufferMask->setSize( aSize );
64 
65  // TODO(F1): Implement alpha vdev (could prolly enable
66  // antialiasing again, then)
67 
68  // disable font antialiasing (causes ugly shadows otherwise)
69  pBackBuffer->getOutDev().SetAntialiasing( AntialiasingFlags::DisableText );
70  pBackBufferMask->getOutDev().SetAntialiasing( AntialiasingFlags::DisableText );
71 
72  // set mask vdev drawmode, such that everything is painted
73  // black. That leaves us with a binary image, white for
74  // background, black for painted content
75  pBackBufferMask->getOutDev().SetDrawMode( DrawModeFlags::BlackLine | DrawModeFlags::BlackFill | DrawModeFlags::BlackText |
76  DrawModeFlags::BlackGradient | DrawModeFlags::BlackBitmap );
77 
78 
79  // setup canvas helper
80 
81 
82  // always render into back buffer, don't preserve state (it's
83  // our private VDev, after all), have notion of alpha
84  maCanvasHelper.init( rDevice,
85  pBackBuffer,
86  false,
87  true );
88  maCanvasHelper.setBackgroundOutDev( pBackBufferMask );
89 
90 
91  // setup sprite helper
92 
93 
94  maSpriteHelper.init( rSpriteSize,
95  rOwningSpriteCanvas,
96  pBackBuffer,
97  pBackBufferMask,
98  bShowSpriteBounds );
99 
100  // clear sprite to 100% transparent
101  maCanvasHelper.clear();
102  }
103 
105  {
106  return "VCLCanvas.CanvasCustomSprite";
107  }
108 
109  sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const OUString& ServiceName )
110  {
111  return cppu::supportsService( this, ServiceName );
112  }
113 
114  uno::Sequence< OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames()
115  {
116  return { "com.sun.star.rendering.CanvasCustomSprite" };
117  }
118 
119  // Sprite
121  bool bBufferedUpdate ) const
122  {
123  SolarMutexGuard aGuard;
124 
125  redraw( rOutDev, maSpriteHelper.getPosPixel(), bBufferedUpdate );
126  }
127 
129  const ::basegfx::B2DPoint& rOrigOutputPos,
130  bool bBufferedUpdate ) const
131  {
132  SolarMutexGuard aGuard;
133 
134  maSpriteHelper.redraw( rOutDev,
135  rOrigOutputPos,
137  bBufferedUpdate );
138 
139  mbSurfaceDirty = false;
140  }
141 
143  const rendering::ViewState& viewState,
144  const rendering::RenderState& renderState,
145  const ::Point& rPt,
146  const ::Size& rSz,
147  const GraphicAttr& rAttr ) const
148  {
149  SolarMutexGuard aGuard;
150 
151  mbSurfaceDirty = true;
152 
153  return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
154  }
155 
156 }
157 
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< OutDevProvider > OutDevProviderSharedPtr
#define max(a, b)
Definition: dx_winstuff.hxx:43
virtual void redraw(OutputDevice &rOutDev, bool bBufferedUpdate) const override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::shared_ptr< GraphicObject > GraphicObjectSharedPtr
std::shared_ptr< BackBuffer > BackBufferSharedPtr
Definition: backbuffer.hxx:47
unsigned char sal_Bool
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
CanvasHelper maCanvasHelper
Definition: canvasbase.hxx:441
CanvasCustomSprite(const css::geometry::RealSize2D &rSpriteSize, css::rendering::XGraphicDevice &rDevice, const ::canvas::SpriteSurface::Reference &rOwningSpriteCanvas, const OutDevProviderSharedPtr &rOutDevProvider, bool bShowSpriteBounds)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
#define ENSURE_OR_THROW(c, m)
virtual bool repaint(const GraphicObjectSharedPtr &rGrf, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState, const ::Point &rPt, const ::Size &rSz, const GraphicAttr &rAttr) const override