1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef GPU_CONFIG_GPU_TEST_CONFIG_H_
6 #define GPU_CONFIG_GPU_TEST_CONFIG_H_
7 
8 #include <stdint.h>
9 
10 #include <string>
11 #include <vector>
12 
13 #include "base/compiler_specific.h"
14 #include "gpu/gpu_export.h"
15 
16 namespace gpu {
17 
18 struct GPUInfo;
19 
20 class GPU_EXPORT GPUTestConfig {
21  public:
22   enum OS {
23     kOsUnknown = 0,
24     kOsWinXP = 1 << 0,
25     kOsWinVista = 1 << 1,
26     kOsWin7 = 1 << 2,
27     kOsWin8 = 1 << 3,
28     kOsWin10 = 1 << 4,
29     kOsWin = kOsWinXP | kOsWinVista | kOsWin7 | kOsWin8 | kOsWin10,
30     // Jump over a few bits for future Windows versions.
31     kOsMacLeopard = 1 << 10,
32     kOsMacSnowLeopard = 1 << 11,
33     kOsMacLion = 1 << 12,
34     kOsMacMountainLion = 1 << 13,
35     kOsMacMavericks = 1 << 14,
36     kOsMacYosemite = 1 << 15,
37     kOsMacElCapitan = 1 << 16,
38     kOsMacSierra = 1 << 17,
39     kOsMacHighSierra = 1 << 18,
40     kOsMacMojave = 1 << 19,
41     kOsMacCatalina = 1 << 20,
42     kOsMac = kOsMacLeopard | kOsMacSnowLeopard | kOsMacLion |
43              kOsMacMountainLion | kOsMacMavericks | kOsMacYosemite |
44              kOsMacElCapitan | kOsMacSierra | kOsMacHighSierra | kOsMacMojave |
45              kOsMacCatalina,
46     // Jump over a few bits for future OSX versions.
47     kOsLinux = 1 << 25,
48     kOsChromeOS = 1 << 26,
49     kOsAndroid = 1 << 27,
50     kOsFuchsia = 1 << 28,
51     // If we run out of bits, please retire older OS versions, like WinXP,
52     // MacLeopard, etc., for which we no longer have bots.
53   };
54 
55   enum BuildType {
56     kBuildTypeUnknown = 0,
57     kBuildTypeRelease = 1 << 0,
58     kBuildTypeDebug = 1 << 1,
59   };
60 
61   enum API {
62     kAPIUnknown = 0,
63     kAPID3D9 = 1 << 0,
64     kAPID3D11 = 1 << 1,
65     kAPIGLDesktop = 1 << 2,
66     kAPIGLES = 1 << 3,
67   };
68 
69   GPUTestConfig();
70   GPUTestConfig(const GPUTestConfig& other);
71   virtual ~GPUTestConfig();
72 
73   void set_os(int32_t os);
74   void set_gpu_device_id(uint32_t id);
75   void set_build_type(int32_t build_type);
76   void set_api(int32_t api);
77 
78   virtual void AddGPUVendor(uint32_t gpu_vendor);
79 
os()80   int32_t os() const { return os_; }
gpu_vendor()81   const std::vector<uint32_t>& gpu_vendor() const { return gpu_vendor_; }
gpu_device_id()82   uint32_t gpu_device_id() const { return gpu_device_id_; }
build_type()83   int32_t build_type() const { return build_type_; }
api()84   int32_t api() const { return api_; }
85 
86   // Check if the config is valid. For example, if gpu_device_id_ is set, but
87   // gpu_vendor_ is unknown, then it's invalid.
88   virtual bool IsValid() const;
89 
90   // Check if two configs overlap, i.e., if there exists a config that matches
91   // both configs.
92   bool OverlapsWith(const GPUTestConfig& config) const;
93 
94  protected:
95   void ClearGPUVendor();
96 
97  private:
98   // operating system.
99   int32_t os_;
100 
101   // GPU vendor.
102   std::vector<uint32_t> gpu_vendor_;
103 
104   // GPU device id (unique to each vendor).
105   uint32_t gpu_device_id_;
106 
107   // Release or Debug.
108   int32_t build_type_;
109 
110   // Back-end rendering APIs.
111   int32_t api_;
112 };
113 
114 class GPU_EXPORT GPUTestBotConfig : public GPUTestConfig {
115  public:
116   GPUTestBotConfig() = default;
117   ~GPUTestBotConfig() override;
118 
119   // This should only be called when no gpu_vendor is added.
120   void AddGPUVendor(uint32_t gpu_vendor) override;
121 
122   // Return false if gpu_info does not have valid vendor_id and device_id.
123   bool SetGPUInfo(const GPUInfo& gpu_info);
124 
125   // Check if the bot config is valid, i.e., if it is one valid test-bot
126   // environment. For example, if a field is unknown, or if OS is not one
127   // fully defined OS, then it's valid.
128   bool IsValid() const override;
129 
130   // Check if a bot config matches a test config, i.e., the test config is a
131   // superset of the bot config.
132   bool Matches(const GPUTestConfig& config) const;
133   bool Matches(const std::string& config_data) const;
134 
135   // Setup the config with the current gpu testing environment.
136   // If gpu_info is nullptr, collect GPUInfo first.
137   bool LoadCurrentConfig(const GPUInfo* gpu_info);
138 
139   // Check if this bot's config matches |config_data| or any of the |configs|.
140   static bool CurrentConfigMatches(const std::string& config_data);
141   static bool CurrentConfigMatches(const std::vector<std::string>& configs);
142 
143   // Check if the bot has blacklisted all GPU features.
144   static bool GpuBlacklistedOnBot();
145 };
146 
147 }  // namespace gpu
148 
149 #endif  // GPU_CONFIG_GPU_TEST_CONFIG_H_
150