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