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