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, with one bit color depth
62  BackBufferSharedPtr pBackBufferMask = std::make_shared<BackBuffer>( rOutDevProvider->getOutDev(),
63  true );
64  pBackBufferMask->setSize( aSize );
65 
66  // TODO(F1): Implement alpha vdev (could prolly enable
67  // antialiasing again, then)
68 
69  // disable font antialiasing (causes ugly shadows otherwise)
70  pBackBuffer->getOutDev().SetAntialiasing( AntialiasingFlags::DisableText );
71  pBackBufferMask->getOutDev().SetAntialiasing( AntialiasingFlags::DisableText );
72 
73  // set mask vdev drawmode, such that everything is painted
74  // black. That leaves us with a binary image, white for
75  // background, black for painted content
76  pBackBufferMask->getOutDev().SetDrawMode( DrawModeFlags::BlackLine | DrawModeFlags::BlackFill | DrawModeFlags::BlackText |
77  DrawModeFlags::BlackGradient | DrawModeFlags::BlackBitmap );
78 
79 
80  // setup canvas helper
81 
82 
83  // always render into back buffer, don't preserve state (it's
84  // our private VDev, after all), have notion of alpha
85  maCanvasHelper.init( rDevice,
86  pBackBuffer,
87  false,
88  true );
89  maCanvasHelper.setBackgroundOutDev( pBackBufferMask );
90 
91 
92  // setup sprite helper
93 
94 
95  maSpriteHelper.init( rSpriteSize,
96  rOwningSpriteCanvas,
97  pBackBuffer,
98  pBackBufferMask,
99  bShowSpriteBounds );
100 
101  // clear sprite to 100% transparent
102  maCanvasHelper.clear();
103  }
104 
106  {
107  return "VCLCanvas.CanvasCustomSprite";
108  }
109 
110  sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const OUString& ServiceName )
111  {
112  return cppu::supportsService( this, ServiceName );
113  }
114 
115  uno::Sequence< OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames()
116  {
117  return { "com.sun.star.rendering.CanvasCustomSprite" };
118  }
119 
120  // Sprite
122  bool bBufferedUpdate ) const
123  {
124  SolarMutexGuard aGuard;
125 
126  redraw( rOutDev, maSpriteHelper.getPosPixel(), bBufferedUpdate );
127  }
128 
130  const ::basegfx::B2DPoint& rOrigOutputPos,
131  bool bBufferedUpdate ) const
132  {
133  SolarMutexGuard aGuard;
134 
135  maSpriteHelper.redraw( rOutDev,
136  rOrigOutputPos,
138  bBufferedUpdate );
139 
140  mbSurfaceDirty = false;
141  }
142 
144  const rendering::ViewState& viewState,
145  const rendering::RenderState& renderState,
146  const ::Point& rPt,
147  const ::Size& rSz,
148  const GraphicAttr& rAttr ) const
149  {
150  SolarMutexGuard aGuard;
151 
152  mbSurfaceDirty = true;
153 
154  return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
155  }
156 
157 }
158 
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< OutDevProvider > OutDevProviderSharedPtr
#define max(a, b)
Definition: dx_winstuff.hxx:45
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:54
unsigned char sal_Bool
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
CanvasHelper maCanvasHelper
Definition: canvasbase.hxx:442
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