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 .
21 #include "dx_config.hxx"
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <comphelper/anytostring.hxx>
26 #include <basegfx/vector/b2ivector.hxx>
27 #include <cppuhelper/exc_hlp.hxx>
28 #include <osl/diagnose.h>
30 using namespace com::sun::star
;
34 DXCanvasItem::DXCanvasItem() :
36 "Office.Canvas/DXCanvas",
37 ConfigItemMode::ImmediateUpdate
),
40 mbBlacklistCurrentDevice(false),
45 uno::Sequence
< OUString
> aName(1);
46 aName
[0] = "DeviceBlacklist";
48 uno::Sequence
< uno::Any
> aProps( GetProperties( aName
));
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 aName
[0] = "BlacklistCurrentDevice";
72 aProps
= GetProperties( aName
);
73 if( aProps
.getLength() > 0 )
74 aProps
[0] >>= mbBlacklistCurrentDevice
;
76 aName
[0] = "MaxTextureSize";
77 aProps
= GetProperties( aName
);
78 if( aProps
.getLength() > 0 )
79 maMaxTextureSize
.reset( aProps
[0].get
<sal_Int32
>() );
81 maMaxTextureSize
.reset();
83 catch( const uno::Exception
& )
85 OSL_FAIL( OUStringToOString(
86 comphelper::anyToString( cppu::getCaughtException() ),
87 RTL_TEXTENCODING_UTF8
).getStr() );
91 DXCanvasItem::~DXCanvasItem()
98 uno::Sequence
< OUString
> aName(1);
99 aName
[0] = "DeviceBlacklist";
101 uno::Sequence
< sal_Int32
> aValues( sizeof(DeviceInfo
)/sizeof(sal_Int32
)*maValues
.size() );
103 sal_Int32
* pValues
= aValues
.getArray();
104 ValueSet::const_iterator
aIter( maValues
.begin() );
105 const ValueSet::const_iterator
aEnd( maValues
.end() );
106 while( aIter
!= aEnd
)
108 const DeviceInfo
& rInfo( *aIter
);
109 *pValues
++ = rInfo
.nVendorId
;
110 *pValues
++ = rInfo
.nDeviceId
;
111 *pValues
++ = rInfo
.nDeviceSubSysId
;
112 *pValues
++ = rInfo
.nDeviceRevision
;
113 *pValues
++ = rInfo
.nDriverId
;
114 *pValues
++ = rInfo
.nDriverVersion
;
115 *pValues
++ = rInfo
.nDriverSubVersion
;
116 *pValues
++ = rInfo
.nDriverBuildId
;
120 uno::Sequence
< uno::Any
> aValue(1);
121 aValue
[0] <<= aValues
;
122 PutProperties( aName
, aValue
);
124 catch( const uno::Exception
& )
126 OSL_FAIL( OUStringToOString(
127 comphelper::anyToString( cppu::getCaughtException() ),
128 RTL_TEXTENCODING_UTF8
).getStr() );
132 void DXCanvasItem::Notify( const com::sun::star::uno::Sequence
<OUString
>& ) {}
133 void DXCanvasItem::ImplCommit() {}
135 bool DXCanvasItem::isDeviceUsable( const DeviceInfo
& rDeviceInfo
) const
137 return maValues
.find(rDeviceInfo
) == maValues
.end();
140 bool DXCanvasItem::isBlacklistCurrentDevice() const
142 return mbBlacklistCurrentDevice
;
145 void DXCanvasItem::blacklistDevice( const DeviceInfo
& rDeviceInfo
)
147 mbValuesDirty
= true;
148 maValues
.insert(rDeviceInfo
);
151 void DXCanvasItem::adaptMaxTextureSize( basegfx::B2IVector
& io_maxTextureSize
) const
153 if( maMaxTextureSize
)
155 io_maxTextureSize
.setX(
156 std::min( *maMaxTextureSize
,
157 io_maxTextureSize
.getX() ));
158 io_maxTextureSize
.setY(
159 std::min( *maMaxTextureSize
,
160 io_maxTextureSize
.getY() ));
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */