1*25ea7f45SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*25ea7f45SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*25ea7f45SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*25ea7f45SAndrew Rist * distributed with this work for additional information 6*25ea7f45SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*25ea7f45SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*25ea7f45SAndrew Rist * "License"); you may not use this file except in compliance 9*25ea7f45SAndrew Rist * with the License. You may obtain a copy of the License at 10*25ea7f45SAndrew Rist * 11*25ea7f45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*25ea7f45SAndrew Rist * 13*25ea7f45SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*25ea7f45SAndrew Rist * software distributed under the License is distributed on an 15*25ea7f45SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*25ea7f45SAndrew Rist * KIND, either express or implied. See the License for the 17*25ea7f45SAndrew Rist * specific language governing permissions and limitations 18*25ea7f45SAndrew Rist * under the License. 19*25ea7f45SAndrew Rist * 20*25ea7f45SAndrew Rist *************************************************************/ 21*25ea7f45SAndrew Rist 22*25ea7f45SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_canvas.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "dx_config.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 30cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 31cdf0e10cSrcweir #include <comphelper/anytostring.hxx> 32cdf0e10cSrcweir #include <basegfx/vector/b2ivector.hxx> 33cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir using namespace com::sun::star; 36cdf0e10cSrcweir 37cdf0e10cSrcweir namespace dxcanvas 38cdf0e10cSrcweir { DXCanvasItem()39cdf0e10cSrcweir DXCanvasItem::DXCanvasItem() : 40cdf0e10cSrcweir ConfigItem( 41cdf0e10cSrcweir ::rtl::OUString( 42cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "Office.Canvas/DXCanvas" )), 43cdf0e10cSrcweir CONFIG_MODE_IMMEDIATE_UPDATE ), 44cdf0e10cSrcweir maValues(), 45cdf0e10cSrcweir maMaxTextureSize(), 46cdf0e10cSrcweir mbBlacklistCurrentDevice(false), 47cdf0e10cSrcweir mbValuesDirty(false) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir try 50cdf0e10cSrcweir { 51cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aName(1); 52cdf0e10cSrcweir aName[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DeviceBlacklist" )); 53cdf0e10cSrcweir 54cdf0e10cSrcweir uno::Sequence< uno::Any > aProps( GetProperties( aName )); 55cdf0e10cSrcweir uno::Sequence< sal_Int32 > aValues; 56cdf0e10cSrcweir 57cdf0e10cSrcweir if( aProps.getLength() > 0 && 58cdf0e10cSrcweir (aProps[0] >>= aValues) ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir const sal_Int32* pValues = aValues.getConstArray(); 61cdf0e10cSrcweir const sal_Int32 nNumEntries( aValues.getLength()*sizeof(sal_Int32)/sizeof(DeviceInfo) ); 62cdf0e10cSrcweir for( sal_Int32 i=0; i<nNumEntries; ++i ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir DeviceInfo aInfo; 65cdf0e10cSrcweir aInfo.nVendorId = *pValues++; 66cdf0e10cSrcweir aInfo.nDeviceId = *pValues++; 67cdf0e10cSrcweir aInfo.nDeviceSubSysId = *pValues++; 68cdf0e10cSrcweir aInfo.nDeviceRevision = *pValues++; 69cdf0e10cSrcweir aInfo.nDriverId = *pValues++; 70cdf0e10cSrcweir aInfo.nDriverVersion = *pValues++; 71cdf0e10cSrcweir aInfo.nDriverSubVersion = *pValues++; 72cdf0e10cSrcweir aInfo.nDriverBuildId = *pValues++; 73cdf0e10cSrcweir maValues.insert(aInfo); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir aName[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BlacklistCurrentDevice" )); 78cdf0e10cSrcweir aProps = GetProperties( aName ); 79cdf0e10cSrcweir if( aProps.getLength() > 0 ) 80cdf0e10cSrcweir aProps[0] >>= mbBlacklistCurrentDevice; 81cdf0e10cSrcweir 82cdf0e10cSrcweir aName[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxTextureSize" )); 83cdf0e10cSrcweir aProps = GetProperties( aName ); 84cdf0e10cSrcweir if( aProps.getLength() > 0 ) 85cdf0e10cSrcweir maMaxTextureSize.reset( aProps[0].get<sal_Int32>() ); 86cdf0e10cSrcweir else 87cdf0e10cSrcweir maMaxTextureSize.reset(); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir catch( uno::Exception& ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir OSL_ENSURE( false, 92cdf0e10cSrcweir rtl::OUStringToOString( 93cdf0e10cSrcweir comphelper::anyToString( cppu::getCaughtException() ), 94cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ).getStr() ); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir } 97cdf0e10cSrcweir ~DXCanvasItem()98cdf0e10cSrcweir DXCanvasItem::~DXCanvasItem() 99cdf0e10cSrcweir { 100cdf0e10cSrcweir if( !mbValuesDirty ) 101cdf0e10cSrcweir return; 102cdf0e10cSrcweir 103cdf0e10cSrcweir try 104cdf0e10cSrcweir { 105cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aName(1); 106cdf0e10cSrcweir aName[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DeviceBlacklist" )); 107cdf0e10cSrcweir 108cdf0e10cSrcweir uno::Sequence< sal_Int32 > aValues( sizeof(DeviceInfo)/sizeof(sal_Int32)*maValues.size() ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir sal_Int32* pValues = aValues.getArray(); 111cdf0e10cSrcweir ValueSet::const_iterator aIter( maValues.begin() ); 112cdf0e10cSrcweir const ValueSet::const_iterator aEnd( maValues.end() ); 113cdf0e10cSrcweir while( aIter != aEnd ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir const DeviceInfo& rInfo( *aIter ); 116cdf0e10cSrcweir *pValues++ = rInfo.nVendorId; 117cdf0e10cSrcweir *pValues++ = rInfo.nDeviceId; 118cdf0e10cSrcweir *pValues++ = rInfo.nDeviceSubSysId; 119cdf0e10cSrcweir *pValues++ = rInfo.nDeviceRevision; 120cdf0e10cSrcweir *pValues++ = rInfo.nDriverId; 121cdf0e10cSrcweir *pValues++ = rInfo.nDriverVersion; 122cdf0e10cSrcweir *pValues++ = rInfo.nDriverSubVersion; 123cdf0e10cSrcweir *pValues++ = rInfo.nDriverBuildId; 124cdf0e10cSrcweir ++aIter; 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir uno::Sequence< uno::Any > aValue(1); 128cdf0e10cSrcweir aValue[0] <<= aValues; 129cdf0e10cSrcweir PutProperties( aName, aValue ); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir catch( uno::Exception& ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir OSL_ENSURE( false, 134cdf0e10cSrcweir rtl::OUStringToOString( 135cdf0e10cSrcweir comphelper::anyToString( cppu::getCaughtException() ), 136cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ).getStr() ); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } 139cdf0e10cSrcweir Notify(const com::sun::star::uno::Sequence<rtl::OUString> &)140cdf0e10cSrcweir void DXCanvasItem::Notify( const com::sun::star::uno::Sequence<rtl::OUString>& ) {} Commit()141cdf0e10cSrcweir void DXCanvasItem::Commit() {} 142cdf0e10cSrcweir isDeviceUsable(const DeviceInfo & rDeviceInfo) const143cdf0e10cSrcweir bool DXCanvasItem::isDeviceUsable( const DeviceInfo& rDeviceInfo ) const 144cdf0e10cSrcweir { 145cdf0e10cSrcweir return maValues.find(rDeviceInfo) == maValues.end(); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir isBlacklistCurrentDevice() const148cdf0e10cSrcweir bool DXCanvasItem::isBlacklistCurrentDevice() const 149cdf0e10cSrcweir { 150cdf0e10cSrcweir return mbBlacklistCurrentDevice; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir blacklistDevice(const DeviceInfo & rDeviceInfo)153cdf0e10cSrcweir void DXCanvasItem::blacklistDevice( const DeviceInfo& rDeviceInfo ) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir mbValuesDirty = true; 156cdf0e10cSrcweir maValues.insert(rDeviceInfo); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir adaptMaxTextureSize(basegfx::B2IVector & io_maxTextureSize) const159cdf0e10cSrcweir void DXCanvasItem::adaptMaxTextureSize( basegfx::B2IVector& io_maxTextureSize ) const 160cdf0e10cSrcweir { 161cdf0e10cSrcweir if( maMaxTextureSize ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir io_maxTextureSize.setX( 164cdf0e10cSrcweir std::min( *maMaxTextureSize, 165cdf0e10cSrcweir io_maxTextureSize.getX() )); 166cdf0e10cSrcweir io_maxTextureSize.setY( 167cdf0e10cSrcweir std::min( *maMaxTextureSize, 168cdf0e10cSrcweir io_maxTextureSize.getY() )); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir } 173