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 .
22 #include <com/sun/star/rendering/XBufferController.hpp>
23 #include <com/sun/star/rendering/XLinePolyPolygon2D.hpp>
24 #include <com/sun/star/rendering/XBezierPolyPolygon2D.hpp>
25 #include <com/sun/star/rendering/XBitmap.hpp>
26 #include <com/sun/star/rendering/XVolatileBitmap.hpp>
28 #include <rtl/ref.hxx>
30 #include <parametricpolypolygon.hxx>
31 #include <propertysethelper.hxx>
32 #include <verifyinput.hxx>
34 namespace com::sun::star::beans
{ class XPropertySetInfo
; }
35 namespace com::sun::star::lang
{ class XMultiServiceFactory
; }
36 namespace com::sun::star::rendering
{ class XColorSpace
; }
39 /* Definition of GraphicDeviceBase class */
43 /** Helper template base class for XGraphicDevice implementations.
45 This base class provides partial implementations of the
46 XGraphicDevice-related interface, such as XColorSpace.
48 This template basically interposes itself between the full
49 interface you implement (i.e. not restricted to XGraphicDevice
50 etc.). The problem with UNO partial interface implementation
51 actually is, that you cannot do it the plain way, since
52 deriving from a common base subclass always introduces the
53 whole set of pure virtuals, that your baseclass helper just
54 overridden) and your implementation class. You then only have
55 to implement the functionality <em>besides</em>
56 XGraphicDevice. If you want to support the optional debug
57 XUpdatable interface, also add that to the base classes
58 (client code will call the corresponding update() method,
59 whenever a burst of animations is over).
63 typedef ::cppu::WeakComponentImplHelper < css::rendering::XGraphicDevice,
64 css::rendering::XColorSpace,
65 css::rendering::XPropertySet,
66 css::lang::XServiceInfo,
67 css::lang::XServiceName > GraphicDeviceBase_Base;
68 typedef ::canvas::internal::GraphicDeviceBase< GraphicDeviceBase, DeviceHelper > ExampleDevice_Base;
70 class ExampleDevice : public ExampleDevice_Base
76 Base class to use, most probably the
77 WeakComponentImplHelper template with the appropriate
78 interfaces. At least XGraphicDevice should be among them (why else
79 would you use this template, then?). Base class must have an
80 Base( const Mutex& ) constructor (like the
81 WeakComponentImplHelper template has). As the very least,
82 the base class must be derived from uno::XInterface, as some
83 error reporting mechanisms rely on that.
86 Device helper implementation for the backend in question. This
87 object will be held as a member of this template class, and
88 basically gets forwarded all XGraphicDevice API calls that
89 could not be handled generically.
92 Lock strategy to use. Defaults to using the
93 DisambiguationHelper-provided lock. Every time one of the methods is
94 entered, an object of type Mutex is created with m_aMutex as
95 the sole parameter, and destroyed again when the method scope
99 Optional unambiguous base class for XInterface of Base. It's
100 sometimes necessary to specify this parameter, e.g. if Base
101 derives from multiple UNO interface (were each provides its
102 own version of XInterface, making the conversion ambiguous)
104 template< class Base
,
106 class Mutex
=::osl::MutexGuard
,
107 class UnambiguousBase
=css::uno::XInterface
> class GraphicDeviceBase
:
111 typedef Base BaseType
;
112 typedef Mutex MutexType
;
113 typedef UnambiguousBase UnambiguousBaseType
;
115 typedef ::rtl::Reference
< GraphicDeviceBase
> Reference
;
117 GraphicDeviceBase() :
119 mbDumpScreenContent(false)
121 maPropHelper
.initProperties(
122 PropertySetHelper::InputMap
{
123 {"HardwareAcceleration",
124 { [this] () { return this->maDeviceHelper
.isAccelerated(); }, {} } },
126 { [this] () { return this->maDeviceHelper
.getDeviceHandle(); }, {} } },
128 { [this] () { return this->maDeviceHelper
.getSurfaceHandle(); }, {} } },
129 {"DumpScreenContent",
130 { [this] () { return this->getDumpScreenContent(); },
131 [this] (css::uno::Any
const& rAny
) { this->setDumpScreenContent(rAny
); } } } } );
134 virtual void disposeThis() override
136 MutexType
aGuard( BaseType::m_aMutex
);
138 maDeviceHelper
.disposing();
140 // pass on to base class
141 BaseType::disposeThis();
145 virtual css::uno::Reference
< css::rendering::XBufferController
> SAL_CALL
getBufferController( ) override
147 return css::uno::Reference
< css::rendering::XBufferController
>();
150 virtual css::uno::Reference
< css::rendering::XColorSpace
> SAL_CALL
getDeviceColorSpace( ) override
152 MutexType
aGuard( BaseType::m_aMutex
);
154 return maDeviceHelper
.getColorSpace();
157 virtual css::geometry::RealSize2D SAL_CALL
getPhysicalResolution() override
159 MutexType
aGuard( BaseType::m_aMutex
);
161 return maDeviceHelper
.getPhysicalResolution();
164 virtual css::geometry::RealSize2D SAL_CALL
getPhysicalSize() override
166 MutexType
aGuard( BaseType::m_aMutex
);
168 return maDeviceHelper
.getPhysicalSize();
171 virtual css::uno::Reference
< css::rendering::XLinePolyPolygon2D
> SAL_CALL
createCompatibleLinePolyPolygon( const css::uno::Sequence
< css::uno::Sequence
< css::geometry::RealPoint2D
> >& points
) override
173 MutexType
aGuard( BaseType::m_aMutex
);
175 return maDeviceHelper
.createCompatibleLinePolyPolygon( this, points
);
178 virtual css::uno::Reference
< css::rendering::XBezierPolyPolygon2D
> SAL_CALL
createCompatibleBezierPolyPolygon( const css::uno::Sequence
< css::uno::Sequence
< css::geometry::RealBezierSegment2D
> >& points
) override
180 MutexType
aGuard( BaseType::m_aMutex
);
182 return maDeviceHelper
.createCompatibleBezierPolyPolygon( this, points
);
185 virtual css::uno::Reference
< css::rendering::XBitmap
> SAL_CALL
createCompatibleBitmap( const css::geometry::IntegerSize2D
& size
) override
187 tools::verifyBitmapSize(size
,
189 static_cast< UnambiguousBaseType
* >(this));
191 MutexType
aGuard( BaseType::m_aMutex
);
193 return maDeviceHelper
.createCompatibleBitmap( this, size
);
196 virtual css::uno::Reference
< css::rendering::XVolatileBitmap
> SAL_CALL
createVolatileBitmap( const css::geometry::IntegerSize2D
& size
) override
198 tools::verifyBitmapSize(size
,
200 static_cast< UnambiguousBaseType
* >(this));
202 MutexType
aGuard( BaseType::m_aMutex
);
204 return maDeviceHelper
.createVolatileBitmap( this, size
);
207 virtual css::uno::Reference
< css::rendering::XBitmap
> SAL_CALL
createCompatibleAlphaBitmap( const css::geometry::IntegerSize2D
& size
) override
209 tools::verifyBitmapSize(size
,
211 static_cast< UnambiguousBaseType
* >(this));
213 MutexType
aGuard( BaseType::m_aMutex
);
215 return maDeviceHelper
.createCompatibleAlphaBitmap( this, size
);
218 virtual css::uno::Reference
< css::rendering::XVolatileBitmap
> SAL_CALL
createVolatileAlphaBitmap( const css::geometry::IntegerSize2D
& size
) override
220 tools::verifyBitmapSize(size
,
222 static_cast< UnambiguousBaseType
* >(this));
224 MutexType
aGuard( BaseType::m_aMutex
);
226 return maDeviceHelper
.createVolatileAlphaBitmap( this, size
);
229 virtual css::uno::Reference
< css::lang::XMultiServiceFactory
> SAL_CALL
getParametricPolyPolygonFactory( ) override
234 virtual sal_Bool SAL_CALL
hasFullScreenMode( ) override
239 virtual sal_Bool SAL_CALL
enterFullScreenMode( sal_Bool
) override
244 // XMultiServiceFactory
245 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstance( const OUString
& aServiceSpecifier
) override
247 return css::uno::Reference
< css::rendering::XParametricPolyPolygon2D
>(
248 ParametricPolyPolygon::create(this,
250 css::uno::Sequence
< css::uno::Any
>()));
253 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstanceWithArguments( const OUString
& aServiceSpecifier
, const css::uno::Sequence
< css::uno::Any
>& Arguments
) override
255 return css::uno::Reference
< css::rendering::XParametricPolyPolygon2D
>(
256 ParametricPolyPolygon::create(this,
261 virtual css::uno::Sequence
< OUString
> SAL_CALL
getAvailableServiceNames( ) override
263 return ParametricPolyPolygon::getAvailableServiceNames();
268 virtual void SAL_CALL
update() override
270 MutexType
aGuard( BaseType::m_aMutex
);
272 if( mbDumpScreenContent
)
273 maDeviceHelper
.dumpScreenContent();
278 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
280 MutexType
aGuard( BaseType::m_aMutex
);
281 return maPropHelper
.getPropertySetInfo();
284 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
,
285 const css::uno::Any
& aValue
) override
287 MutexType
aGuard( BaseType::m_aMutex
);
288 maPropHelper
.setPropertyValue( aPropertyName
, aValue
);
291 virtual css::uno::Any SAL_CALL
getPropertyValue( const OUString
& aPropertyName
) override
293 MutexType
aGuard( BaseType::m_aMutex
);
294 return maPropHelper
.getPropertyValue( aPropertyName
);
297 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
,
298 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
300 MutexType
aGuard( BaseType::m_aMutex
);
301 maPropHelper
.addPropertyChangeListener( aPropertyName
,
305 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& ,
306 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& ) override
310 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& aPropertyName
,
311 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& xListener
) override
313 MutexType
aGuard( BaseType::m_aMutex
);
314 maPropHelper
.addVetoableChangeListener( aPropertyName
,
318 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& ,
319 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& ) override
324 ~GraphicDeviceBase() {} // we're a ref-counted UNO class. _We_ destroy ourselves.
326 css::uno::Any
getDumpScreenContent() const
328 return css::uno::Any( mbDumpScreenContent
);
331 void setDumpScreenContent( const css::uno::Any
& rAny
)
333 // TODO(Q1): this was mbDumpScreenContent =
334 // rAny.get<bool>(), only that gcc3.3 wouldn't eat it
335 rAny
>>= mbDumpScreenContent
;
338 DeviceHelper maDeviceHelper
;
339 PropertySetHelper maPropHelper
;
340 bool mbDumpScreenContent
;
343 GraphicDeviceBase( const GraphicDeviceBase
& ) = delete;
344 GraphicDeviceBase
& operator=( const GraphicDeviceBase
& ) = delete;
348 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */