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 <basegfx/vector/b2ivector.hxx>
24 #include <com/sun/star/uno/Any.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <comphelper/anytostring.hxx>
27 #include <cppuhelper/exc_hlp.hxx>
28 #include <osl/diagnose.h>
29 #include <tools/diagnose_ex.h>
31 #include "dx_config.hxx"
33 using namespace com::sun::star
;
37 DXCanvasItem::DXCanvasItem() :
39 "Office.Canvas/DXCanvas",
40 ConfigItemMode::NONE
),
43 mbDenylistCurrentDevice(false),
48 uno::Sequence
< uno::Any
> aProps( GetProperties( { "DeviceDenylist" } ));
49 uno::Sequence
< sal_Int32
> aValues
;
51 if( aProps
.getLength() > 0 &&
52 (aProps
[0] >>= aValues
) )
54 const sal_Int32
* pValues
= aValues
.getConstArray();
55 const sal_Int32
nNumEntries( aValues
.getLength()*sizeof(sal_Int32
)/sizeof(DeviceInfo
) );
56 for( sal_Int32 i
=0; i
<nNumEntries
; ++i
)
59 aInfo
.nVendorId
= *pValues
++;
60 aInfo
.nDeviceId
= *pValues
++;
61 aInfo
.nDeviceSubSysId
= *pValues
++;
62 aInfo
.nDeviceRevision
= *pValues
++;
63 aInfo
.nDriverId
= *pValues
++;
64 aInfo
.nDriverVersion
= *pValues
++;
65 aInfo
.nDriverSubVersion
= *pValues
++;
66 aInfo
.nDriverBuildId
= *pValues
++;
67 maValues
.insert(aInfo
);
71 aProps
= GetProperties( { "DenylistCurrentDevice" } );
72 if( aProps
.getLength() > 0 )
73 aProps
[0] >>= mbDenylistCurrentDevice
;
75 aProps
= GetProperties( { "MaxTextureSize" } );
76 if( aProps
.getLength() > 0 )
77 maMaxTextureSize
= aProps
[0].get
<sal_Int32
>();
79 maMaxTextureSize
.reset();
81 catch( const uno::Exception
& )
83 TOOLS_WARN_EXCEPTION( "canvas", "" );
87 DXCanvasItem::~DXCanvasItem()
94 uno::Sequence
< sal_Int32
> aValues( sizeof(DeviceInfo
)/sizeof(sal_Int32
)*maValues
.size() );
96 sal_Int32
* pValues
= aValues
.getArray();
97 for( const auto& rValueSet
: maValues
)
99 const DeviceInfo
& rInfo( rValueSet
);
100 *pValues
++ = rInfo
.nVendorId
;
101 *pValues
++ = rInfo
.nDeviceId
;
102 *pValues
++ = rInfo
.nDeviceSubSysId
;
103 *pValues
++ = rInfo
.nDeviceRevision
;
104 *pValues
++ = rInfo
.nDriverId
;
105 *pValues
++ = rInfo
.nDriverVersion
;
106 *pValues
++ = rInfo
.nDriverSubVersion
;
107 *pValues
++ = rInfo
.nDriverBuildId
;
110 PutProperties({"DeviceDenylist"}, {css::uno::Any(aValues
)});
112 catch( const uno::Exception
& )
114 TOOLS_WARN_EXCEPTION( "canvas", "" );
118 void DXCanvasItem::Notify( const css::uno::Sequence
<OUString
>& ) {}
119 void DXCanvasItem::ImplCommit() {}
121 bool DXCanvasItem::isDeviceUsable( const DeviceInfo
& rDeviceInfo
) const
123 return maValues
.find(rDeviceInfo
) == maValues
.end();
126 bool DXCanvasItem::isDenylistCurrentDevice() const
128 return mbDenylistCurrentDevice
;
131 void DXCanvasItem::denylistDevice( const DeviceInfo
& rDeviceInfo
)
133 mbValuesDirty
= true;
134 maValues
.insert(rDeviceInfo
);
137 void DXCanvasItem::adaptMaxTextureSize( basegfx::B2IVector
& io_maxTextureSize
) const
139 if( maMaxTextureSize
)
141 io_maxTextureSize
.setX(
142 std::min( *maMaxTextureSize
,
143 io_maxTextureSize
.getX() ));
144 io_maxTextureSize
.setY(
145 std::min( *maMaxTextureSize
,
146 io_maxTextureSize
.getY() ));
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */