1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include <com/sun/star/awt/XTopWindow.hpp>
24 #include <com/sun/star/lang/NoSupportException.hpp>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <comphelper/diagnose_ex.hxx>
28 #include "spritecanvas.hxx"
29 #include "outdevholder.hxx"
30 #include "windowoutdevholder.hxx"
33 using namespace ::com::sun::star
;
37 SpriteCanvas::SpriteCanvas( const uno::Sequence
< uno::Any
>& aArguments
,
38 const uno::Reference
< uno::XComponentContext
>& /*rxContext*/ ) :
39 maArguments(aArguments
)
43 void SpriteCanvas::initialize()
45 SolarMutexGuard aGuard
;
47 // #i64742# Only call initialize when not in probe mode
48 if( !maArguments
.hasElements() )
51 SAL_INFO("canvas.vcl", "SpriteCanvas created" );
53 // add our own property to GraphicDevice
54 maPropHelper
.addProperties(
55 ::canvas::PropertySetHelper::MakeMap
57 [this]() { return this->maCanvasHelper
.isUnsafeScrolling(); },
58 [this](css::uno::Any
const& aAny
) mutable { this->maCanvasHelper
.enableUnsafeScrolling(aAny
); } )
60 [this]() { return this->maCanvasHelper
.isSpriteBounds(); },
61 [this](css::uno::Any
const& aAny
) mutable { this->maCanvasHelper
.enableSpriteBounds(aAny
); } ));
63 SAL_INFO("canvas.vcl", "VCLSpriteCanvas::initialize called" );
65 ENSURE_ARG_OR_THROW( maArguments
.hasElements(),
66 "VCLSpriteCanvas::initialize: wrong number of arguments" );
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
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" );
81 maArguments
[0] >>= nPtr
;
83 OutputDevice
* pOutDev
= reinterpret_cast<OutputDevice
*>(nPtr
);
85 throw lang::NoSupportException(u
"Passed OutDev invalid!"_ustr
, nullptr);
87 uno::Reference
< awt::XWindow
> xParentWindow
;
88 maArguments
[3] >>= xParentWindow
;
90 OutDevProviderSharedPtr pOutDevProvider
;
91 if( xParentWindow
.is())
92 pOutDevProvider
= std::make_shared
<WindowOutDevHolder
>(xParentWindow
);
94 pOutDevProvider
= std::make_shared
<OutDevHolder
>(*pOutDev
);
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(),
104 false, // no OutDev state preservation
105 false ); // no alpha on surface
107 maArguments
.realloc(0);
110 SpriteCanvas::~SpriteCanvas()
112 SAL_INFO("canvas.vcl", "SpriteCanvas destroyed" );
116 void SpriteCanvas::disposeThis()
118 SolarMutexGuard aGuard
;
121 SpriteCanvasBaseT::disposeThis();
124 sal_Bool SAL_CALL
SpriteCanvas::showBuffer( sal_Bool bUpdateAll
)
126 return updateScreen( bUpdateAll
);
129 sal_Bool SAL_CALL
SpriteCanvas::switchBuffer( sal_Bool bUpdateAll
)
131 return updateScreen( bUpdateAll
);
134 sal_Bool SAL_CALL
SpriteCanvas::updateScreen( sal_Bool bUpdateAll
)
136 SolarMutexGuard aGuard
;
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
,
145 OUString SAL_CALL
SpriteCanvas::getServiceName( )
147 return u
"com.sun.star.rendering.SpriteCanvas.VCL"_ustr
;
151 css::uno::Sequence
<OUString
> SpriteCanvas::getSupportedServiceNames()
153 return { SpriteCanvas::getServiceName() };
155 OUString
SpriteCanvas::getImplementationName()
157 return u
"com.sun.star.comp.rendering.SpriteCanvas.VCL"_ustr
;
159 sal_Bool
SpriteCanvas::supportsService(const OUString
& sServiceName
)
161 return cppu::supportsService(this, sServiceName
);
164 bool SpriteCanvas::repaint( const GraphicObjectSharedPtr
& rGrf
,
165 const rendering::ViewState
& viewState
,
166 const rendering::RenderState
& renderState
,
169 const GraphicAttr
& rAttr
) const
171 SolarMutexGuard aGuard
;
173 return maCanvasHelper
.repaint( rGrf
, viewState
, renderState
, rPt
, rSz
, rAttr
);
177 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
178 com_sun_star_comp_rendering_SpriteCanvas_VCL_get_implementation(
179 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& args
)
181 rtl::Reference
<vclcanvas::SpriteCanvas
> p
= new vclcanvas::SpriteCanvas(args
, context
);
183 return cppu::acquire(p
.get());
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */