update dev300-m58
[ooovba.git] / canvas / source / directx / dx_config.cxx
blob08d5a69422c2fdfeb0620796aaca7d890ad7395a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dx_config.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include "dx_config.hxx"
36 #include <com/sun/star/uno/Any.hxx>
37 #include <com/sun/star/uno/Sequence.hxx>
38 #include <comphelper/anytostring.hxx>
39 #include <basegfx/vector/b2ivector.hxx>
40 #include <cppuhelper/exc_hlp.hxx>
42 using namespace com::sun::star;
44 namespace dxcanvas
46 DXCanvasItem::DXCanvasItem() :
47 ConfigItem(
48 ::rtl::OUString(
49 RTL_CONSTASCII_USTRINGPARAM( "Office.Canvas/DXCanvas" )),
50 CONFIG_MODE_IMMEDIATE_UPDATE ),
51 maValues(),
52 maMaxTextureSize(),
53 mbBlacklistCurrentDevice(false),
54 mbValuesDirty(false)
56 try
58 uno::Sequence< ::rtl::OUString > aName(1);
59 aName[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DeviceBlacklist" ));
61 uno::Sequence< uno::Any > aProps( GetProperties( aName ));
62 uno::Sequence< sal_Int32 > aValues;
64 if( aProps.getLength() > 0 &&
65 (aProps[0] >>= aValues) )
67 const sal_Int32* pValues = aValues.getConstArray();
68 const sal_Int32 nNumEntries( aValues.getLength()*sizeof(sal_Int32)/sizeof(DeviceInfo) );
69 for( sal_Int32 i=0; i<nNumEntries; ++i )
71 DeviceInfo aInfo;
72 aInfo.nVendorId = *pValues++;
73 aInfo.nDeviceId = *pValues++;
74 aInfo.nDeviceSubSysId = *pValues++;
75 aInfo.nDeviceRevision = *pValues++;
76 aInfo.nDriverId = *pValues++;
77 aInfo.nDriverVersion = *pValues++;
78 aInfo.nDriverSubVersion = *pValues++;
79 aInfo.nDriverBuildId = *pValues++;
80 maValues.insert(aInfo);
84 aName[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BlacklistCurrentDevice" ));
85 aProps = GetProperties( aName );
86 if( aProps.getLength() > 0 )
87 aProps[0] >>= mbBlacklistCurrentDevice;
89 aName[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxTextureSize" ));
90 aProps = GetProperties( aName );
91 if( aProps.getLength() > 0 )
92 maMaxTextureSize.reset( aProps[0].get<sal_Int32>() );
93 else
94 maMaxTextureSize.reset();
96 catch( uno::Exception& )
98 OSL_ENSURE( false,
99 rtl::OUStringToOString(
100 comphelper::anyToString( cppu::getCaughtException() ),
101 RTL_TEXTENCODING_UTF8 ).getStr() );
105 DXCanvasItem::~DXCanvasItem()
107 if( !mbValuesDirty )
108 return;
112 uno::Sequence< ::rtl::OUString > aName(1);
113 aName[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DeviceBlacklist" ));
115 uno::Sequence< sal_Int32 > aValues( sizeof(DeviceInfo)/sizeof(sal_Int32)*maValues.size() );
117 sal_Int32* pValues = aValues.getArray();
118 ValueSet::const_iterator aIter( maValues.begin() );
119 const ValueSet::const_iterator aEnd( maValues.end() );
120 while( aIter != aEnd )
122 const DeviceInfo& rInfo( *aIter );
123 *pValues++ = rInfo.nVendorId;
124 *pValues++ = rInfo.nDeviceId;
125 *pValues++ = rInfo.nDeviceSubSysId;
126 *pValues++ = rInfo.nDeviceRevision;
127 *pValues++ = rInfo.nDriverId;
128 *pValues++ = rInfo.nDriverVersion;
129 *pValues++ = rInfo.nDriverSubVersion;
130 *pValues++ = rInfo.nDriverBuildId;
131 ++aIter;
134 uno::Sequence< uno::Any > aValue(1);
135 aValue[0] <<= aValues;
136 PutProperties( aName, aValue );
138 catch( uno::Exception& )
140 OSL_ENSURE( false,
141 rtl::OUStringToOString(
142 comphelper::anyToString( cppu::getCaughtException() ),
143 RTL_TEXTENCODING_UTF8 ).getStr() );
147 bool DXCanvasItem::isDeviceUsable( const DeviceInfo& rDeviceInfo ) const
149 return maValues.find(rDeviceInfo) == maValues.end();
152 bool DXCanvasItem::isBlacklistCurrentDevice() const
154 return mbBlacklistCurrentDevice;
157 void DXCanvasItem::blacklistDevice( const DeviceInfo& rDeviceInfo )
159 mbValuesDirty = true;
160 maValues.insert(rDeviceInfo);
163 void DXCanvasItem::adaptMaxTextureSize( basegfx::B2IVector& io_maxTextureSize ) const
165 if( maMaxTextureSize )
167 io_maxTextureSize.setX(
168 std::min( *maMaxTextureSize,
169 io_maxTextureSize.getX() ));
170 io_maxTextureSize.setY(
171 std::min( *maMaxTextureSize,
172 io_maxTextureSize.getY() ));