1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Mozilla Foundation.
19 : * Portions created by the Initial Developer are Copyright (C) 2011
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "prtypes.h"
39 : #include "nsString.h"
40 :
41 : #ifndef __mozilla_widget_GfxDriverInfo_h__
42 : #define __mozilla_widget_GfxDriverInfo_h__
43 :
44 : #define V(a,b,c,d) GFX_DRIVER_VERSION(a,b,c,d)
45 :
46 : // Macros for adding a blocklist item to the static list.
47 : #define APPEND_TO_DRIVER_BLOCKLIST(os, vendor, devices, feature, featureStatus, driverComparator, driverVersion, suggestedVersion) \
48 : mDriverInfo->AppendElement(GfxDriverInfo(os, vendor, devices, feature, featureStatus, driverComparator, driverVersion, suggestedVersion))
49 : #define APPEND_TO_DRIVER_BLOCKLIST2(os, vendor, devices, feature, featureStatus, driverComparator, driverVersion) \
50 : mDriverInfo->AppendElement(GfxDriverInfo(os, vendor, devices, feature, featureStatus, driverComparator, driverVersion))
51 :
52 : namespace mozilla {
53 : namespace widget {
54 :
55 : enum OperatingSystem {
56 : DRIVER_OS_UNKNOWN = 0,
57 : DRIVER_OS_WINDOWS_XP,
58 : DRIVER_OS_WINDOWS_SERVER_2003,
59 : DRIVER_OS_WINDOWS_VISTA,
60 : DRIVER_OS_WINDOWS_7,
61 : DRIVER_OS_LINUX,
62 : DRIVER_OS_OS_X_10_5,
63 : DRIVER_OS_OS_X_10_6,
64 : DRIVER_OS_OS_X_10_7,
65 : DRIVER_OS_ANDROID,
66 : DRIVER_OS_ALL
67 : };
68 :
69 : enum VersionComparisonOp {
70 : DRIVER_LESS_THAN, // driver < version
71 : DRIVER_LESS_THAN_OR_EQUAL, // driver <= version
72 : DRIVER_GREATER_THAN, // driver > version
73 : DRIVER_GREATER_THAN_OR_EQUAL, // driver >= version
74 : DRIVER_EQUAL, // driver == version
75 : DRIVER_NOT_EQUAL, // driver != version
76 : DRIVER_BETWEEN_EXCLUSIVE, // driver > version && driver < versionMax
77 : DRIVER_BETWEEN_INCLUSIVE, // driver >= version && driver <= versionMax
78 : DRIVER_BETWEEN_INCLUSIVE_START, // driver >= version && driver < versionMax
79 : DRIVER_UNKNOWN_COMPARISON
80 : };
81 :
82 : enum DeviceFamily {
83 : IntelGMA500,
84 : IntelGMA900,
85 : IntelGMA950,
86 : IntelGMA3150,
87 : IntelGMAX3000,
88 : IntelGMAX4500HD,
89 : NvidiaBlockD3D9Layers,
90 : RadeonX1000,
91 : Geforce7300GT,
92 : DeviceFamilyMax
93 : };
94 :
95 : enum DeviceVendor {
96 : VendorAll,
97 : VendorIntel,
98 : VendorNVIDIA,
99 : VendorAMD,
100 : VendorATI,
101 : DeviceVendorMax
102 : };
103 :
104 : /* Array of devices to match, or an empty array for all devices */
105 : typedef nsTArray<nsString> GfxDeviceFamily;
106 :
107 : struct GfxDriverInfo
108 76 : {
109 : // If |ownDevices| is true, you are transferring ownership of the devices
110 : // array, and it will be deleted when this GfxDriverInfo is destroyed.
111 : GfxDriverInfo(OperatingSystem os, nsAString& vendor, GfxDeviceFamily* devices,
112 : PRInt32 feature, PRInt32 featureStatus, VersionComparisonOp op,
113 : PRUint64 driverVersion, const char *suggestedVersion = nsnull,
114 : bool ownDevices = false);
115 :
116 : GfxDriverInfo();
117 : GfxDriverInfo(const GfxDriverInfo&);
118 : ~GfxDriverInfo();
119 :
120 : OperatingSystem mOperatingSystem;
121 :
122 : nsString mAdapterVendor;
123 :
124 : static GfxDeviceFamily* const allDevices;
125 : GfxDeviceFamily* mDevices;
126 :
127 : // Whether the mDevices array should be deleted when this structure is
128 : // deallocated. False by default.
129 : bool mDeleteDevices;
130 :
131 : /* A feature from nsIGfxInfo, or all features */
132 : PRInt32 mFeature;
133 : static PRInt32 allFeatures;
134 :
135 : /* A feature status from nsIGfxInfo */
136 : PRInt32 mFeatureStatus;
137 :
138 : VersionComparisonOp mComparisonOp;
139 :
140 : /* versions are assumed to be A.B.C.D packed as 0xAAAABBBBCCCCDDDD */
141 : PRUint64 mDriverVersion;
142 : PRUint64 mDriverVersionMax;
143 : static PRUint64 allDriverVersions;
144 :
145 : const char *mSuggestedVersion;
146 :
147 : static const GfxDeviceFamily* GetDeviceFamily(DeviceFamily id);
148 : static GfxDeviceFamily* mDeviceFamilies[DeviceFamilyMax];
149 :
150 : static const nsAString& GetDeviceVendor(DeviceVendor id);
151 : static nsAString* mDeviceVendors[DeviceVendorMax];
152 : };
153 :
154 : #define GFX_DRIVER_VERSION(a,b,c,d) \
155 : ((PRUint64(a)<<48) | (PRUint64(b)<<32) | (PRUint64(c)<<16) | PRUint64(d))
156 :
157 : inline bool
158 252 : ParseDriverVersion(nsAString& aVersion, PRUint64 *aNumericVersion)
159 : {
160 : #if defined(XP_WIN)
161 : int a, b, c, d;
162 : /* honestly, why do I even bother */
163 : if (sscanf(NS_LossyConvertUTF16toASCII(aVersion).get(),
164 : "%d.%d.%d.%d", &a, &b, &c, &d) != 4)
165 : return false;
166 : if (a < 0 || a > 0xffff) return false;
167 : if (b < 0 || b > 0xffff) return false;
168 : if (c < 0 || c > 0xffff) return false;
169 : if (d < 0 || d > 0xffff) return false;
170 :
171 : *aNumericVersion = GFX_DRIVER_VERSION(a, b, c, d);
172 : #elif defined(ANDROID)
173 : // Can't use aVersion.ToInteger() because that's not compiled into our code
174 : // unless we have XPCOM_GLUE_AVOID_NSPR disabled.
175 : *aNumericVersion = atoi(NS_LossyConvertUTF16toASCII(aVersion).get());
176 : #endif
177 252 : return true;
178 : }
179 :
180 : }
181 : }
182 :
183 : #endif /*__mozilla_widget_GfxDriverInfo_h__ */
|