gpucapabilitieswindows.h 7.92 KB
Newer Older
schultezub's avatar
schultezub committed
1
2
/**********************************************************************
 *                                                                    *
3
4
5
6
 * cgt - CAMP Graphics Toolbox, Copyright (C) 2012-2014               *
 *     Chair for Computer Aided Medical Procedures                    *
 *     Technische Universitaet Muenchen, Germany.                     *
 *     <http://campar.in.tum.de/>                                     *
schultezub's avatar
schultezub committed
7
 *                                                                    *
8
9
10
11
 * forked from tgt - Tiny Graphics Toolbox, Copyright (C) 2006-2011   *
 *     Visualization and Computer Graphics Group, Department of       *
 *     Computer Science, University of Muenster, Germany.             *
 *     <http://viscg.uni-muenster.de>                                 *
schultezub's avatar
schultezub committed
12
 *                                                                    *
13
 * This file is part of the cgt library. This library is free         *
schultezub's avatar
schultezub committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * software; you can redistribute it and/or modify it under the terms *
 * of the GNU Lesser General Public License version 2.1 as published  *
 * by the Free Software Foundation.                                   *
 *                                                                    *
 * This library is distributed in the hope that it will be useful,    *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the       *
 * GNU Lesser General Public License for more details.                *
 *                                                                    *
 * You should have received a copy of the GNU Lesser General Public   *
 * License in the file "LICENSE.txt" along with this library.         *
 * If not, see <http://www.gnu.org/licenses/>.                        *
 *                                                                    *
 **********************************************************************/

29
30
#ifndef CGT_GPUCAPABILITIESWINDOWS_H
#define CGT_GPUCAPABILITIESWINDOWS_H
schultezub's avatar
schultezub committed
31
32
33
34

#ifdef _MSC_VER

#include "gpucapabilities.h"
35
36
#include "cgt/singleton.h"
#include "cgt/types.h"
schultezub's avatar
schultezub committed
37

38
#ifdef CGT_WITH_WMI
schultezub's avatar
schultezub committed
39
40
41
42
    #include <wbemidl.h>
    #include <comdef.h>
#endif

43
namespace cgt {
schultezub's avatar
schultezub committed
44
45
46

class GpuCapabilitiesWindows;
#ifdef DLL_TEMPLATE_INST
47
template class CGT_API Singleton<GpuCapabilitiesWindows>;
schultezub's avatar
schultezub committed
48
49
50
51
52
53
54
55
56
57
58
59
60
#endif

/**
 * A singleton that performs Windows specific hardware detection. It provides
 * information about:
 *  - Graphics driver version and date
 *  - Size of graphics memory
 *  - Driver settings
 *
 * The information is collected from several sources like
 * Windows Management Instrumentation (WMI), Windows registry,
 * and driver dlls.
 *
61
 * @note WMI is only used if CGT_WITH_WMI is defined
schultezub's avatar
schultezub committed
62
 */
63
class CGT_API GpuCapabilitiesWindows : public cgt::GpuCapabilities, public Singleton<GpuCapabilitiesWindows> {
schultezub's avatar
schultezub committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
public:
    using Singleton<GpuCapabilitiesWindows>::init;
    using Singleton<GpuCapabilitiesWindows>::isInited;
    using Singleton<GpuCapabilitiesWindows>::deinit;

    /**
     * Holds several representations of a Windows file version.
     *
     * Windows file versions are usually represented as a string
     * of the form d1.d2.d3.d4 where d1,d2,d3,d4 are 16-bit unsigned integers,
     * e.g. 6.14.10.6389.
     */
    struct FileVersion {
        int d1, d2, d3, d4;             ///< Parts d1,d2,d3,d4 of the file version, separated
        std::string versionString;      ///< String representation of file version: 'd1.d2.d3.d4'
        uint64_t version;               ///< Binary representation of file version: d1d2d3d4
    };

    /**
     * Contains the graphics driver's version and date.
     */
    struct GraphicsDriverInformation {
        FileVersion driverVersion;      ///< Version of driver dll (the dll is vendor specific)
        std::string driverDate;         ///< Date of last modification of driver dll, format: YYYY-MM-DD
    };

    /**
     * Constructor performs the WMI initialization,
92
     * if compiled with WMI support (CGT_WITH_WMI).
schultezub's avatar
schultezub committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
     */
    GpuCapabilitiesWindows();

    /**
     * The destructor closes the WMI connection, if it is open.
     */
    virtual ~GpuCapabilitiesWindows();

    /**
     * Returns information about the graphics driver,
     * retrieved from driver dlls (NVIDIA and ATI only).
     *
     * The Windows Management Instrumentation (WMI) is used as
     * fallback option only since it turned out to be less reliable than
     * querying the graphics driver directly.
     */
    GraphicsDriverInformation getGraphicsDriverInformation();

    /**
     * @see getGraphicsDriverInformation
     */
    FileVersion getDriverVersion();

    /**
     * @see getGraphicsDriverInformation
     */
    std::string getDriverDate();

    /**
     * Returns the size of the graphics memory in MB. This
     * information is obtained by querying the
     * Windows Management Instrumentation (WMI), hence it is
     * vendor independent.
     *
127
     * If voreen was compiled without WMI support (CGT_WITH_WMI) or the WMI data retrieval fails,
schultezub's avatar
schultezub committed
128
129
130
131
132
133
134
135
     * the information is read from the registry. If both methods fail, -1 is returned.
     */
    int getVideoRamSize();

    virtual void logCapabilities(bool extensionsString = false, bool osString = true);

protected:

136
    static std::string loggerCat_;
schultezub's avatar
schultezub committed
137

138
#ifdef CGT_WITH_WMI
schultezub's avatar
schultezub committed
139
140
141
142
143
144
145
146
147
148
149
150
151
152

    /**
     * Has to be called before a \sa WMIquery() can be done.
     *
     * @return true, if WMI initialization succeeded
     *
     */
    bool WMIinit();

    /**
     * Closes the WMI connection. Call this after finished wmi queries.
     *
     * @return true, if WMI deinitialization succeeded
     *
153
     * @warning function is only defined if CGT_WITH_WMI is set!
schultezub's avatar
schultezub committed
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
     */
    bool WMIdeinit();

    /**
     * Returns whether the WMI connection has been setup.
     */
    bool isWMIinited() const;

    /**
     * This function is used to query the Windows
     * Management Instrumentation (WMI).
     *
     * @see http://msdn2.microsoft.com/en-us/library/aa394582(VS.85).aspx
     *
     * @return the query result as a pointer to a VARIANT type,
     *         or NULL if the query was unsuccessful. The return value has to be freed
     *         by the caller by \c VariantClear().
     *
     * @note Instead of calling this function directly, use \sa WMIqueryStr and \sa WMIqueryInt,
     *       which return result values of a specific type.
     */
    VARIANT* WMIquery(std::string wmiclass, std::string attribute);

    /**
     * WMI query returning a string. \sa WMIquery.
     */
    std::string WMIqueryStr(std::string wmiclass, std::string attribute);

    /**
     * WMI query returning an int. \sa WMIquery.
     */
    int WMIqueryInt(std::string wmiclass, std::string attribute);

    /**
     * Converts a STL string to a STL wide-string.
     */
    static std::wstring str2wstr(const std::string& s);

    /**
     * Converts a STL wide-string to a STL string.
     */
    static std::string wstr2str(const std::wstring& s);

#endif

    /**
     * Detects the Windows file version of a file.
     *
     * @param filename complete path to the file
     *
     * @see FileVersion
     */
    FileVersion getFileVersion(std::string filename);

    /**
     * Detects the date of a file.
     *
     * @param filename complete path to the file
     *
     * @return file date as string in the form YYYY-MM-DD, e.g. 2007-12-15
     */
    std::string getFileDate(std::string filename);


private:

    // Internal helper functions
    bool parseFileVersionString(FileVersion &fileVersion);
    bool createFileVersionFromDigits(FileVersion &fileVersion);
    bool createVersionStringFromDigits(FileVersion &fileVersion);

    DWORD readVRAMSizeFromReg();
    char* findPrimaryDevicesKey();

228
#ifdef CGT_WITH_WMI
schultezub's avatar
schultezub committed
229
230
231
232
233
234
235
236
237
   // WMI internals. Should not be touched outside the present WMI functions.
   IWbemLocator* pIWbemLocator_;
   IWbemServices* pWbemServices_;
#endif

    int videoRamSize_;

};

238
} // namespace cgt
schultezub's avatar
schultezub committed
239

240
#define GpuCapsWin cgt::Singleton<cgt::GpuCapabilitiesWindows>::getRef()
schultezub's avatar
schultezub committed
241
242
243

#endif //_MSC_VER

244
#endif // CGT_GPUCAPABILITIESWINDOWS_H