update credits
[LibreOffice.git] / canvas / source / directx / dx_config.cxx
blob7ecfe52b5c8edf48c86660092cce913ec0184ed5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
29 using namespace com::sun::star;
31 namespace dxcanvas
33 DXCanvasItem::DXCanvasItem() :
34 ConfigItem(
35 "Office.Canvas/DXCanvas",
36 CONFIG_MODE_IMMEDIATE_UPDATE ),
37 maValues(),
38 maMaxTextureSize(),
39 mbBlacklistCurrentDevice(false),
40 mbValuesDirty(false)
42 try
44 uno::Sequence< OUString > aName(1);
45 aName[0] = "DeviceBlacklist";
47 uno::Sequence< uno::Any > aProps( GetProperties( aName ));
48 uno::Sequence< sal_Int32 > aValues;
50 if( aProps.getLength() > 0 &&
51 (aProps[0] >>= aValues) )
53 const sal_Int32* pValues = aValues.getConstArray();
54 const sal_Int32 nNumEntries( aValues.getLength()*sizeof(sal_Int32)/sizeof(DeviceInfo) );
55 for( sal_Int32 i=0; i<nNumEntries; ++i )
57 DeviceInfo aInfo;
58 aInfo.nVendorId = *pValues++;
59 aInfo.nDeviceId = *pValues++;
60 aInfo.nDeviceSubSysId = *pValues++;
61 aInfo.nDeviceRevision = *pValues++;
62 aInfo.nDriverId = *pValues++;
63 aInfo.nDriverVersion = *pValues++;
64 aInfo.nDriverSubVersion = *pValues++;
65 aInfo.nDriverBuildId = *pValues++;
66 maValues.insert(aInfo);
70 aName[0] = "BlacklistCurrentDevice";
71 aProps = GetProperties( aName );
72 if( aProps.getLength() > 0 )
73 aProps[0] >>= mbBlacklistCurrentDevice;
75 aName[0] = "MaxTextureSize";
76 aProps = GetProperties( aName );
77 if( aProps.getLength() > 0 )
78 maMaxTextureSize.reset( aProps[0].get<sal_Int32>() );
79 else
80 maMaxTextureSize.reset();
82 catch( const uno::Exception& )
84 OSL_FAIL( OUStringToOString(
85 comphelper::anyToString( cppu::getCaughtException() ),
86 RTL_TEXTENCODING_UTF8 ).getStr() );
90 DXCanvasItem::~DXCanvasItem()
92 if( !mbValuesDirty )
93 return;
95 try
97 uno::Sequence< OUString > aName(1);
98 aName[0] = "DeviceBlacklist";
100 uno::Sequence< sal_Int32 > aValues( sizeof(DeviceInfo)/sizeof(sal_Int32)*maValues.size() );
102 sal_Int32* pValues = aValues.getArray();
103 ValueSet::const_iterator aIter( maValues.begin() );
104 const ValueSet::const_iterator aEnd( maValues.end() );
105 while( aIter != aEnd )
107 const DeviceInfo& rInfo( *aIter );
108 *pValues++ = rInfo.nVendorId;
109 *pValues++ = rInfo.nDeviceId;
110 *pValues++ = rInfo.nDeviceSubSysId;
111 *pValues++ = rInfo.nDeviceRevision;
112 *pValues++ = rInfo.nDriverId;
113 *pValues++ = rInfo.nDriverVersion;
114 *pValues++ = rInfo.nDriverSubVersion;
115 *pValues++ = rInfo.nDriverBuildId;
116 ++aIter;
119 uno::Sequence< uno::Any > aValue(1);
120 aValue[0] <<= aValues;
121 PutProperties( aName, aValue );
123 catch( const uno::Exception& )
125 OSL_FAIL( OUStringToOString(
126 comphelper::anyToString( cppu::getCaughtException() ),
127 RTL_TEXTENCODING_UTF8 ).getStr() );
131 void DXCanvasItem::Notify( const com::sun::star::uno::Sequence<OUString>& ) {}
132 void DXCanvasItem::Commit() {}
134 bool DXCanvasItem::isDeviceUsable( const DeviceInfo& rDeviceInfo ) const
136 return maValues.find(rDeviceInfo) == maValues.end();
139 bool DXCanvasItem::isBlacklistCurrentDevice() const
141 return mbBlacklistCurrentDevice;
144 void DXCanvasItem::blacklistDevice( const DeviceInfo& rDeviceInfo )
146 mbValuesDirty = true;
147 maValues.insert(rDeviceInfo);
150 void DXCanvasItem::adaptMaxTextureSize( basegfx::B2IVector& io_maxTextureSize ) const
152 if( maMaxTextureSize )
154 io_maxTextureSize.setX(
155 std::min( *maMaxTextureSize,
156 io_maxTextureSize.getX() ));
157 io_maxTextureSize.setY(
158 std::min( *maMaxTextureSize,
159 io_maxTextureSize.getY() ));
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */