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