LibreOffice Module canvas (master)  1
dx_config.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sal/config.h>
21 #include <sal/log.hxx>
22 
24 #include <com/sun/star/uno/Any.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
27 #include <cppuhelper/exc_hlp.hxx>
28 #include <osl/diagnose.h>
29 #include <tools/diagnose_ex.h>
30 
31 #include "dx_config.hxx"
32 
33 using namespace com::sun::star;
34 
35 namespace dxcanvas
36 {
37  DXCanvasItem::DXCanvasItem() :
38  ConfigItem(
39  "Office.Canvas/DXCanvas",
41  maValues(),
42  maMaxTextureSize(),
43  mbDenylistCurrentDevice(false),
44  mbValuesDirty(false)
45  {
46  try
47  {
48  uno::Sequence< OUString > aName { "DeviceDenylist" };
49 
50  uno::Sequence< uno::Any > aProps( GetProperties( aName ));
51  uno::Sequence< sal_Int32 > aValues;
52 
53  if( aProps.getLength() > 0 &&
54  (aProps[0] >>= aValues) )
55  {
56  const sal_Int32* pValues = aValues.getConstArray();
57  const sal_Int32 nNumEntries( aValues.getLength()*sizeof(sal_Int32)/sizeof(DeviceInfo) );
58  for( sal_Int32 i=0; i<nNumEntries; ++i )
59  {
60  DeviceInfo aInfo;
61  aInfo.nVendorId = *pValues++;
62  aInfo.nDeviceId = *pValues++;
63  aInfo.nDeviceSubSysId = *pValues++;
64  aInfo.nDeviceRevision = *pValues++;
65  aInfo.nDriverId = *pValues++;
66  aInfo.nDriverVersion = *pValues++;
67  aInfo.nDriverSubVersion = *pValues++;
68  aInfo.nDriverBuildId = *pValues++;
69  maValues.insert(aInfo);
70  }
71  }
72 
73  aName[0] = "DenylistCurrentDevice";
74  aProps = GetProperties( aName );
75  if( aProps.getLength() > 0 )
76  aProps[0] >>= mbDenylistCurrentDevice;
77 
78  aName[0] = "MaxTextureSize";
79  aProps = GetProperties( aName );
80  if( aProps.getLength() > 0 )
81  maMaxTextureSize = aProps[0].get<sal_Int32>();
82  else
83  maMaxTextureSize.reset();
84  }
85  catch( const uno::Exception& )
86  {
87  TOOLS_WARN_EXCEPTION( "canvas", "" );
88  }
89  }
90 
92  {
93  if( !mbValuesDirty )
94  return;
95 
96  try
97  {
98  uno::Sequence< sal_Int32 > aValues( sizeof(DeviceInfo)/sizeof(sal_Int32)*maValues.size() );
99 
100  sal_Int32* pValues = aValues.getArray();
101  for( const auto& rValueSet : maValues )
102  {
103  const DeviceInfo& rInfo( rValueSet );
104  *pValues++ = rInfo.nVendorId;
105  *pValues++ = rInfo.nDeviceId;
106  *pValues++ = rInfo.nDeviceSubSysId;
107  *pValues++ = rInfo.nDeviceRevision;
108  *pValues++ = rInfo.nDriverId;
109  *pValues++ = rInfo.nDriverVersion;
110  *pValues++ = rInfo.nDriverSubVersion;
111  *pValues++ = rInfo.nDriverBuildId;
112  }
113 
114  PutProperties({"DeviceDenylist"}, {css::uno::Any(aValues)});
115  }
116  catch( const uno::Exception& )
117  {
118  TOOLS_WARN_EXCEPTION( "canvas", "" );
119  }
120  }
121 
122  void DXCanvasItem::Notify( const css::uno::Sequence<OUString>& ) {}
124 
125  bool DXCanvasItem::isDeviceUsable( const DeviceInfo& rDeviceInfo ) const
126  {
127  return maValues.find(rDeviceInfo) == maValues.end();
128  }
129 
131  {
133  }
134 
135  void DXCanvasItem::denylistDevice( const DeviceInfo& rDeviceInfo )
136  {
137  mbValuesDirty = true;
138  maValues.insert(rDeviceInfo);
139  }
140 
141  void DXCanvasItem::adaptMaxTextureSize( basegfx::B2IVector& io_maxTextureSize ) const
142  {
143  if( maMaxTextureSize )
144  {
145  io_maxTextureSize.setX(
147  io_maxTextureSize.getX() ));
148  io_maxTextureSize.setY(
150  io_maxTextureSize.getY() ));
151  }
152  }
153 
154 }
155 
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
~DXCanvasItem() override
Definition: dx_config.cxx:91
std::optional< sal_Int32 > maMaxTextureSize
Definition: dx_config.hxx:74
void setY(sal_Int32 fY)
ConfigItemMode
void denylistDevice(const DeviceInfo &rDeviceInfo)
Definition: dx_config.cxx:135
virtual void ImplCommit() override
Definition: dx_config.cxx:123
ValueVectorType maValues
NONE
#define min(a, b)
Definition: dx_winstuff.hxx:48
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
Definition: dx_config.cxx:122
bool isDeviceUsable(const DeviceInfo &rDeviceInfo) const
Definition: dx_config.cxx:125
#define TOOLS_WARN_EXCEPTION(area, stream)
int i
bool PutProperties(const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues)
sal_Int32 getX() const
void adaptMaxTextureSize(basegfx::B2IVector &io_maxTextureSize) const
Definition: dx_config.cxx:141
css::uno::Sequence< css::uno::Any > GetProperties(const css::uno::Sequence< OUString > &rNames)
const PropertyValue * pValues
OUString aName
sal_Int32 getY() const
void setX(sal_Int32 fX)
bool isDenylistCurrentDevice() const
Definition: dx_config.cxx:130