LibreOffice Module canvas (master)  1
spritecanvas.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 #include <sal/log.hxx>
22 
23 #include <com/sun/star/awt/XTopWindow.hpp>
25 #include <tools/diagnose_ex.h>
26 
27 #include "spritecanvas.hxx"
28 #include "windowoutdevholder.hxx"
29 
30 
31 using namespace ::com::sun::star;
32 
33 namespace vclcanvas
34 {
35  SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
36  const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
37  maArguments(aArguments)
38  {
39  }
40 
41  void SpriteCanvas::initialize()
42  {
43  SolarMutexGuard aGuard;
44 
45  // #i64742# Only call initialize when not in probe mode
46  if( !maArguments.hasElements() )
47  return;
48 
49  SAL_INFO("canvas.vcl", "SpriteCanvas created" );
50 
51  // add our own property to GraphicDevice
52  maPropHelper.addProperties(
54  ("UnsafeScrolling",
55  [this]() { return this->maCanvasHelper.isUnsafeScrolling(); },
56  [this](css::uno::Any const& aAny) mutable { this->maCanvasHelper.enableUnsafeScrolling(aAny); } )
57  ("SpriteBounds",
58  [this]() { return this->maCanvasHelper.isSpriteBounds(); },
59  [this](css::uno::Any const& aAny) mutable { this->maCanvasHelper.enableSpriteBounds(aAny); } ));
60 
61  SAL_INFO("canvas.vcl", "VCLSpriteCanvas::initialize called" );
62 
63  ENSURE_ARG_OR_THROW( maArguments.hasElements(),
64  "VCLSpriteCanvas::initialize: wrong number of arguments" );
65 
66  /* maArguments:
67  0: ptr to creating instance (Window or VirtualDevice)
68  1: current bounds of creating instance
69  2: bool, denoting always on top state for Window (always false for VirtualDevice)
70  3: XWindow for creating Window (or empty for VirtualDevice)
71  4: SystemGraphicsData as a streamed Any
72  */
73  ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
74  maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
75  maArguments[3].getValueTypeClass() == uno::TypeClass_INTERFACE,
76  "VCLSpriteCanvas::initialize: wrong number of arguments, or wrong types" );
77 
78  uno::Reference< awt::XWindow > xParentWindow;
79  maArguments[3] >>= xParentWindow;
80 
81  OutDevProviderSharedPtr pOutDev = std::make_shared<WindowOutDevHolder>(xParentWindow);
82 
83  // setup helper
84  maDeviceHelper.init( pOutDev );
85  setWindow(uno::Reference<awt::XWindow2>(xParentWindow, uno::UNO_QUERY_THROW));
86  maCanvasHelper.init( maDeviceHelper.getBackBuffer(),
87  *this,
88  maRedrawManager,
89  false, // no OutDev state preservation
90  false ); // no alpha on surface
91 
92  maArguments.realloc(0);
93  }
94 
95  SpriteCanvas::~SpriteCanvas()
96  {
97  SAL_INFO("canvas.vcl", "SpriteCanvas destroyed" );
98  }
99 
100 
101  void SpriteCanvas::disposeThis()
102  {
103  SolarMutexGuard aGuard;
104 
105  // forward to parent
106  SpriteCanvasBaseT::disposeThis();
107  }
108 
109  sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll )
110  {
111  return updateScreen( bUpdateAll );
112  }
113 
114  sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll )
115  {
116  return updateScreen( bUpdateAll );
117  }
118 
119  sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll )
120  {
121  SolarMutexGuard aGuard;
122 
123  // avoid repaints on hidden window (hidden: not mapped to
124  // screen). Return failure, since the screen really has _not_
125  // been updated (caller should try again later)
126  return mbIsVisible && maCanvasHelper.updateScreen(bUpdateAll,
127  mbSurfaceDirty);
128  }
129 
130  OUString SAL_CALL SpriteCanvas::getServiceName( )
131  {
132  return "com.sun.star.rendering.SpriteCanvas.VCL";
133  }
134 
135  // XServiceInfo
136  css::uno::Sequence<OUString> SpriteCanvas::getSupportedServiceNames()
137  {
138  return { SpriteCanvas::getServiceName() };
139  }
140  OUString SpriteCanvas::getImplementationName()
141  {
142  return "com.sun.star.comp.rendering.SpriteCanvas.VCL";
143  }
144  sal_Bool SpriteCanvas::supportsService(const OUString& sServiceName)
145  {
146  return cppu::supportsService(this, sServiceName);
147  }
148 
149  bool SpriteCanvas::repaint( const GraphicObjectSharedPtr& rGrf,
150  const rendering::ViewState& viewState,
151  const rendering::RenderState& renderState,
152  const ::Point& rPt,
153  const ::Size& rSz,
154  const GraphicAttr& rAttr ) const
155  {
156  SolarMutexGuard aGuard;
157 
158  return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
159  }
160 }
161 
162 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
164  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
165 {
166  auto p = new vclcanvas::SpriteCanvas(args, context);
167  cppu::acquire(p);
168  p->initialize();
169  return static_cast<cppu::OWeakObject*>(p);
170 }
171 
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< OutDevProvider > OutDevProviderSharedPtr
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::shared_ptr< GraphicObject > GraphicObjectSharedPtr
Product of this component's factory.
unsigned char sal_Bool
#define ENSURE_ARG_OR_THROW(c, m)
SpriteCanvas(const css::uno::Sequence< css::uno::Any > &aArguments, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
#define SAL_INFO(area, stream)
void * p
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_rendering_SpriteCanvas_VCL_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)