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>
28#include <osl/diagnose.h>
30
31#include "dx_config.hxx"
32
33using namespace com::sun::star;
34
35namespace dxcanvas
36{
38 ConfigItem(
39 "Office.Canvas/DXCanvas",
41 maValues(),
42 maMaxTextureSize(),
43 mbDenylistCurrentDevice(false),
44 mbValuesDirty(false)
45 {
46 try
47 {
48 uno::Sequence< uno::Any > aProps( GetProperties( { "DeviceDenylist" } ));
49 uno::Sequence< sal_Int32 > aValues;
50
51 if( aProps.getLength() > 0 &&
52 (aProps[0] >>= aValues) )
53 {
54 const sal_Int32* pValues = aValues.getConstArray();
55 const sal_Int32 nNumEntries( aValues.getLength()*sizeof(sal_Int32)/sizeof(DeviceInfo) );
56 for( sal_Int32 i=0; i<nNumEntries; ++i )
57 {
58 DeviceInfo aInfo;
59 aInfo.nVendorId = *pValues++;
60 aInfo.nDeviceId = *pValues++;
61 aInfo.nDeviceSubSysId = *pValues++;
62 aInfo.nDeviceRevision = *pValues++;
63 aInfo.nDriverId = *pValues++;
64 aInfo.nDriverVersion = *pValues++;
65 aInfo.nDriverSubVersion = *pValues++;
66 aInfo.nDriverBuildId = *pValues++;
67 maValues.insert(aInfo);
68 }
69 }
70
71 aProps = GetProperties( { "DenylistCurrentDevice" } );
72 if( aProps.getLength() > 0 )
73 aProps[0] >>= mbDenylistCurrentDevice;
74
75 aProps = GetProperties( { "MaxTextureSize" } );
76 if( aProps.getLength() > 0 )
77 maMaxTextureSize = aProps[0].get<sal_Int32>();
78 else
79 maMaxTextureSize.reset();
80 }
81 catch( const uno::Exception& )
82 {
83 TOOLS_WARN_EXCEPTION( "canvas", "" );
84 }
85 }
86
88 {
89 if( !mbValuesDirty )
90 return;
91
92 try
93 {
94 uno::Sequence< sal_Int32 > aValues( sizeof(DeviceInfo)/sizeof(sal_Int32)*maValues.size() );
95
96 sal_Int32* pValues = aValues.getArray();
97 for( const auto& rValueSet : maValues )
98 {
99 const DeviceInfo& rInfo( rValueSet );
100 *pValues++ = rInfo.nVendorId;
101 *pValues++ = rInfo.nDeviceId;
102 *pValues++ = rInfo.nDeviceSubSysId;
103 *pValues++ = rInfo.nDeviceRevision;
104 *pValues++ = rInfo.nDriverId;
105 *pValues++ = rInfo.nDriverVersion;
106 *pValues++ = rInfo.nDriverSubVersion;
107 *pValues++ = rInfo.nDriverBuildId;
108 }
109
110 PutProperties({"DeviceDenylist"}, {css::uno::Any(aValues)});
111 }
112 catch( const uno::Exception& )
113 {
114 TOOLS_WARN_EXCEPTION( "canvas", "" );
115 }
116 }
117
118 void DXCanvasItem::Notify( const css::uno::Sequence<OUString>& ) {}
120
121 bool DXCanvasItem::isDeviceUsable( const DeviceInfo& rDeviceInfo ) const
122 {
123 return maValues.find(rDeviceInfo) == maValues.end();
124 }
125
127 {
129 }
130
131 void DXCanvasItem::denylistDevice( const DeviceInfo& rDeviceInfo )
132 {
133 mbValuesDirty = true;
134 maValues.insert(rDeviceInfo);
135 }
136
138 {
139 if( maMaxTextureSize )
140 {
141 io_maxTextureSize.setX(
142 std::min( *maMaxTextureSize,
143 io_maxTextureSize.getX() ));
144 io_maxTextureSize.setY(
145 std::min( *maMaxTextureSize,
146 io_maxTextureSize.getY() ));
147 }
148 }
149
150}
151
152/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
ValueVectorType maValues
TYPE getX() const
void setY(TYPE fY)
TYPE getY() const
void setX(TYPE fX)
bool isDeviceUsable(const DeviceInfo &rDeviceInfo) const
Definition: dx_config.cxx:121
~DXCanvasItem() override
Definition: dx_config.cxx:87
void adaptMaxTextureSize(basegfx::B2IVector &io_maxTextureSize) const
Definition: dx_config.cxx:137
std::optional< sal_Int32 > maMaxTextureSize
Definition: dx_config.hxx:74
bool isDenylistCurrentDevice() const
Definition: dx_config.cxx:126
virtual void ImplCommit() override
Definition: dx_config.cxx:119
void denylistDevice(const DeviceInfo &rDeviceInfo)
Definition: dx_config.cxx:131
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
Definition: dx_config.cxx:118
static bool PutProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues, bool bAllLocales)
static css::uno::Sequence< css::uno::Any > GetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, bool bAllLocales)
ConfigItemMode
#define TOOLS_WARN_EXCEPTION(area, stream)
NONE
int i