| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "content/browser/gpu/gpu_data_manager_impl_private.h" | 13 #include "content/browser/gpu/gpu_data_manager_impl_private.h" |
| 14 #include "content/browser/gpu/gpu_data_manager_testing_autogen.h" |
| 15 #include "content/browser/gpu/gpu_data_manager_testing_entry_enums_autogen.h" |
| 14 #include "content/public/browser/gpu_data_manager_observer.h" | 16 #include "content/public/browser/gpu_data_manager_observer.h" |
| 15 #include "gpu/config/gpu_feature_type.h" | 17 #include "gpu/config/gpu_feature_type.h" |
| 16 #include "gpu/config/gpu_info.h" | 18 #include "gpu/config/gpu_info.h" |
| 17 #include "gpu/config/gpu_switches.h" | 19 #include "gpu/config/gpu_switches.h" |
| 18 #include "gpu/ipc/common/memory_stats.h" | 20 #include "gpu/ipc/common/memory_stats.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 21 | 23 |
| 22 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 23 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 69 } |
| 68 | 70 |
| 69 static GURL GetDomain2ForTesting() { | 71 static GURL GetDomain2ForTesting() { |
| 70 return GURL("http://bar.com/"); | 72 return GURL("http://bar.com/"); |
| 71 } | 73 } |
| 72 | 74 |
| 73 } // namespace anonymous | 75 } // namespace anonymous |
| 74 | 76 |
| 75 class GpuDataManagerImplPrivateTest : public testing::Test { | 77 class GpuDataManagerImplPrivateTest : public testing::Test { |
| 76 public: | 78 public: |
| 77 GpuDataManagerImplPrivateTest() { } | 79 GpuDataManagerImplPrivateTest() {} |
| 78 | |
| 79 ~GpuDataManagerImplPrivateTest() override {} | 80 ~GpuDataManagerImplPrivateTest() override {} |
| 80 | 81 |
| 81 protected: | 82 protected: |
| 82 // scoped_ptr doesn't work with GpuDataManagerImpl because its | 83 // scoped_ptr doesn't work with GpuDataManagerImpl because its |
| 83 // destructor is private. GpuDataManagerImplPrivateTest is however a friend | 84 // destructor is private. GpuDataManagerImplPrivateTest is however a friend |
| 84 // so we can make a little helper class here. | 85 // so we can make a little helper class here. |
| 85 class ScopedGpuDataManagerImpl { | 86 class ScopedGpuDataManagerImpl { |
| 86 public: | 87 public: |
| 87 ScopedGpuDataManagerImpl() : impl_(new GpuDataManagerImpl()) { | 88 ScopedGpuDataManagerImpl() : impl_(new GpuDataManagerImpl()) { |
| 88 EXPECT_TRUE(impl_); | 89 EXPECT_TRUE(impl_); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // If a feature is allowed in preliminary step (browser side), but | 144 // If a feature is allowed in preliminary step (browser side), but |
| 144 // disabled when GPU process launches and collects full GPU info, | 145 // disabled when GPU process launches and collects full GPU info, |
| 145 // it's too late to let renderer know, so we basically block all GPU | 146 // it's too late to let renderer know, so we basically block all GPU |
| 146 // access, to be on the safe side. | 147 // access, to be on the safe side. |
| 147 ScopedGpuDataManagerImplPrivate manager; | 148 ScopedGpuDataManagerImplPrivate manager; |
| 148 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 149 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
| 149 std::string reason; | 150 std::string reason; |
| 150 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 151 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
| 151 EXPECT_TRUE(reason.empty()); | 152 EXPECT_TRUE(reason.empty()); |
| 152 | 153 |
| 153 const std::string blacklist_json = LONG_STRING_CONST( | 154 const gpu::GpuControlList::Entry kEntries[] = { |
| 154 { | 155 gpu::kGpuDataManagerTestingEntries |
| 155 "name": "gpu blacklist", | 156 [gpu::kGpuDataManagerImplPrivateTest_GpuSideBlacklisting_0], |
| 156 "version": "0.1", | 157 gpu::kGpuDataManagerTestingEntries |
| 157 "entries": [ | 158 [gpu::kGpuDataManagerImplPrivateTest_GpuSideBlacklisting_1], |
| 158 { | 159 }; |
| 159 "id": 1, | 160 const gpu::GpuControlListData kData("1.0", 2, kEntries); |
| 160 "features": [ | |
| 161 "accelerated_webgl" | |
| 162 ] | |
| 163 }, | |
| 164 { | |
| 165 "id": 2, | |
| 166 "gl_renderer": ".*GeForce.*", | |
| 167 "features": [ | |
| 168 "accelerated_2d_canvas" | |
| 169 ] | |
| 170 } | |
| 171 ] | |
| 172 } | |
| 173 ); | |
| 174 | 161 |
| 175 gpu::GPUInfo gpu_info; | 162 gpu::GPUInfo gpu_info; |
| 176 gpu_info.gpu.vendor_id = 0x10de; | 163 gpu_info.gpu.vendor_id = 0x10de; |
| 177 gpu_info.gpu.device_id = 0x0640; | 164 gpu_info.gpu.device_id = 0x0640; |
| 178 manager->InitializeForTesting(blacklist_json, gpu_info); | 165 manager->InitializeForTesting(kData, gpu_info); |
| 179 | 166 |
| 180 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 167 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
| 181 EXPECT_TRUE(reason.empty()); | 168 EXPECT_TRUE(reason.empty()); |
| 182 if (manager->ShouldUseSwiftShader()) { | 169 if (manager->ShouldUseSwiftShader()) { |
| 183 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), | 170 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), |
| 184 manager->GetBlacklistedFeatureCount()); | 171 manager->GetBlacklistedFeatureCount()); |
| 185 } else { | 172 } else { |
| 186 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 173 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 187 } | 174 } |
| 188 EXPECT_TRUE( | 175 EXPECT_TRUE( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 213 // If a feature is allowed in preliminary step (browser side), but | 200 // If a feature is allowed in preliminary step (browser side), but |
| 214 // disabled when GPU process launches and collects full GPU info, | 201 // disabled when GPU process launches and collects full GPU info, |
| 215 // it's too late to let renderer know, so we basically block all GPU | 202 // it's too late to let renderer know, so we basically block all GPU |
| 216 // access, to be on the safe side. | 203 // access, to be on the safe side. |
| 217 ScopedGpuDataManagerImplPrivate manager; | 204 ScopedGpuDataManagerImplPrivate manager; |
| 218 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 205 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
| 219 std::string reason; | 206 std::string reason; |
| 220 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 207 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
| 221 EXPECT_TRUE(reason.empty()); | 208 EXPECT_TRUE(reason.empty()); |
| 222 | 209 |
| 223 const std::string blacklist_json = LONG_STRING_CONST( | 210 const gpu::GpuControlList::Entry kEntries[] = { |
| 224 { | 211 gpu::kGpuDataManagerTestingEntries |
| 225 "name": "gpu blacklist", | 212 [gpu::kGpuDataManagerImplPrivateTest_GpuSideBlacklistingWebGL_0], |
| 226 "version": "0.1", | 213 gpu::kGpuDataManagerTestingEntries |
| 227 "entries": [ | 214 [gpu::kGpuDataManagerImplPrivateTest_GpuSideBlacklistingWebGL_1], |
| 228 { | 215 }; |
| 229 "id": 1, | 216 const gpu::GpuControlListData kData("1.0", 2, kEntries); |
| 230 "features": [ | |
| 231 "accelerated_2d_canvas" | |
| 232 ] | |
| 233 }, | |
| 234 { | |
| 235 "id": 2, | |
| 236 "gl_renderer": ".*GeForce.*", | |
| 237 "features": [ | |
| 238 "accelerated_webgl", | |
| 239 "webgl2" | |
| 240 ] | |
| 241 } | |
| 242 ] | |
| 243 } | |
| 244 ); | |
| 245 | 217 |
| 246 gpu::GPUInfo gpu_info; | 218 gpu::GPUInfo gpu_info; |
| 247 gpu_info.gpu.vendor_id = 0x10de; | 219 gpu_info.gpu.vendor_id = 0x10de; |
| 248 gpu_info.gpu.device_id = 0x0640; | 220 gpu_info.gpu.device_id = 0x0640; |
| 249 manager->InitializeForTesting(blacklist_json, gpu_info); | 221 manager->InitializeForTesting(kData, gpu_info); |
| 250 | 222 |
| 251 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 223 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
| 252 EXPECT_TRUE(reason.empty()); | 224 EXPECT_TRUE(reason.empty()); |
| 253 if (manager->ShouldUseSwiftShader()) { | 225 if (manager->ShouldUseSwiftShader()) { |
| 254 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), | 226 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), |
| 255 manager->GetBlacklistedFeatureCount()); | 227 manager->GetBlacklistedFeatureCount()); |
| 256 } else { | 228 } else { |
| 257 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 229 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 258 } | 230 } |
| 259 EXPECT_TRUE(manager->IsFeatureBlacklisted( | 231 EXPECT_TRUE(manager->IsFeatureBlacklisted( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 275 EXPECT_TRUE( | 247 EXPECT_TRUE( |
| 276 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL)); | 248 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL)); |
| 277 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL2)); | 249 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL2)); |
| 278 } | 250 } |
| 279 | 251 |
| 280 TEST_F(GpuDataManagerImplPrivateTest, GpuSideExceptions) { | 252 TEST_F(GpuDataManagerImplPrivateTest, GpuSideExceptions) { |
| 281 ScopedGpuDataManagerImplPrivate manager; | 253 ScopedGpuDataManagerImplPrivate manager; |
| 282 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 254 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
| 283 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 255 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 284 | 256 |
| 285 const std::string blacklist_json = LONG_STRING_CONST( | 257 const gpu::GpuControlList::Entry kEntries[] = { |
| 286 { | 258 gpu::kGpuDataManagerTestingEntries |
| 287 "name": "gpu blacklist", | 259 [gpu::kGpuDataManagerImplPrivateTest_GpuSideException], |
| 288 "version": "0.1", | 260 }; |
| 289 "entries": [ | 261 const gpu::GpuControlListData kData("1.0", 1, kEntries); |
| 290 { | 262 |
| 291 "id": 1, | |
| 292 "exceptions": [ | |
| 293 { | |
| 294 "gl_renderer": ".*GeForce.*" | |
| 295 } | |
| 296 ], | |
| 297 "features": [ | |
| 298 "accelerated_webgl" | |
| 299 ] | |
| 300 } | |
| 301 ] | |
| 302 } | |
| 303 ); | |
| 304 gpu::GPUInfo gpu_info; | 263 gpu::GPUInfo gpu_info; |
| 305 gpu_info.gpu.vendor_id = 0x10de; | 264 gpu_info.gpu.vendor_id = 0x10de; |
| 306 gpu_info.gpu.device_id = 0x0640; | 265 gpu_info.gpu.device_id = 0x0640; |
| 307 manager->InitializeForTesting(blacklist_json, gpu_info); | 266 manager->InitializeForTesting(kData, gpu_info); |
| 308 | 267 |
| 309 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 268 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 310 EXPECT_EQ(manager->ShouldUseSwiftShader() | 269 EXPECT_EQ(manager->ShouldUseSwiftShader() |
| 311 ? static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES) | 270 ? static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES) |
| 312 : 1u, | 271 : 1u, |
| 313 manager->GetBlacklistedFeatureCount()); | 272 manager->GetBlacklistedFeatureCount()); |
| 314 | 273 |
| 315 // Now assume gpu process launches and full GPU info is collected. | 274 // Now assume gpu process launches and full GPU info is collected. |
| 316 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; | 275 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; |
| 317 manager->UpdateGpuInfo(gpu_info); | 276 manager->UpdateGpuInfo(gpu_info); |
| 318 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 277 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 319 // Since SwiftShader was enabled by first gpu_info, UpdateGpuInfo | 278 // Since SwiftShader was enabled by first gpu_info, UpdateGpuInfo |
| 320 // should have failed and SwiftShader should still be active | 279 // should have failed and SwiftShader should still be active |
| 321 EXPECT_EQ(manager->ShouldUseSwiftShader() | 280 EXPECT_EQ(manager->ShouldUseSwiftShader() |
| 322 ? static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES) | 281 ? static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES) |
| 323 : 0u, | 282 : 0u, |
| 324 manager->GetBlacklistedFeatureCount()); | 283 manager->GetBlacklistedFeatureCount()); |
| 325 } | 284 } |
| 326 | 285 |
| 327 TEST_F(GpuDataManagerImplPrivateTest, DisableHardwareAcceleration) { | 286 TEST_F(GpuDataManagerImplPrivateTest, DisableHardwareAcceleration) { |
| 328 ScopedGpuDataManagerImplPrivate manager; | 287 ScopedGpuDataManagerImplPrivate manager; |
| 329 manager->InitializeForTesting("", gpu::GPUInfo()); | 288 const gpu::GpuControlListData kData; |
| 289 manager->InitializeForTesting(kData, gpu::GPUInfo()); |
| 330 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 290 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
| 331 std::string reason; | 291 std::string reason; |
| 332 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 292 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
| 333 EXPECT_TRUE(reason.empty()); | 293 EXPECT_TRUE(reason.empty()); |
| 334 | 294 |
| 335 manager->DisableHardwareAcceleration(); | 295 manager->DisableHardwareAcceleration(); |
| 336 if (manager->ShouldUseSwiftShader()) { | 296 if (manager->ShouldUseSwiftShader()) { |
| 337 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 297 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
| 338 EXPECT_TRUE(reason.empty()); | 298 EXPECT_TRUE(reason.empty()); |
| 339 } else { | 299 } else { |
| 340 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); | 300 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); |
| 341 EXPECT_FALSE(reason.empty()); | 301 EXPECT_FALSE(reason.empty()); |
| 342 } | 302 } |
| 343 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), | 303 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), |
| 344 manager->GetBlacklistedFeatureCount()); | 304 manager->GetBlacklistedFeatureCount()); |
| 345 } | 305 } |
| 346 | 306 |
| 347 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering) { | 307 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering) { |
| 348 // Blacklist, then register SwiftShader. | 308 // Blacklist, then register SwiftShader. |
| 349 ScopedGpuDataManagerImplPrivate manager; | 309 ScopedGpuDataManagerImplPrivate manager; |
| 350 manager->InitializeForTesting("", gpu::GPUInfo()); | 310 const gpu::GpuControlListData kData; |
| 311 manager->InitializeForTesting(kData, gpu::GPUInfo()); |
| 351 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 312 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
| 352 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 313 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 353 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | 314 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
| 354 | 315 |
| 355 manager->DisableHardwareAcceleration(); | 316 manager->DisableHardwareAcceleration(); |
| 356 EXPECT_EQ(manager->ShouldUseSwiftShader(), manager->GpuAccessAllowed(NULL)); | 317 EXPECT_EQ(manager->ShouldUseSwiftShader(), manager->GpuAccessAllowed(NULL)); |
| 357 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), | 318 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), |
| 358 manager->GetBlacklistedFeatureCount()); | 319 manager->GetBlacklistedFeatureCount()); |
| 359 EXPECT_TRUE(manager->IsFeatureBlacklisted( | 320 EXPECT_TRUE(manager->IsFeatureBlacklisted( |
| 360 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); | 321 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); |
| 361 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL2)); | 322 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL2)); |
| 362 } | 323 } |
| 363 | 324 |
| 364 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering2) { | 325 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering2) { |
| 365 // Register SwiftShader, then blacklist. | 326 // Register SwiftShader, then blacklist. |
| 366 ScopedGpuDataManagerImplPrivate manager; | 327 ScopedGpuDataManagerImplPrivate manager; |
| 367 manager->InitializeForTesting("", gpu::GPUInfo()); | 328 const gpu::GpuControlListData kData; |
| 329 manager->InitializeForTesting(kData, gpu::GPUInfo()); |
| 368 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 330 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
| 369 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 331 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 370 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | 332 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
| 371 | 333 |
| 372 manager->DisableHardwareAcceleration(); | 334 manager->DisableHardwareAcceleration(); |
| 373 if (manager->ShouldUseSwiftShader()) { | 335 if (manager->ShouldUseSwiftShader()) { |
| 374 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 336 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 375 } else { | 337 } else { |
| 376 EXPECT_FALSE(manager->GpuAccessAllowed(NULL)); | 338 EXPECT_FALSE(manager->GpuAccessAllowed(NULL)); |
| 377 } | 339 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 398 manager->UpdateGpuInfo(gpu_info); | 360 manager->UpdateGpuInfo(gpu_info); |
| 399 { | 361 { |
| 400 base::RunLoop run_loop; | 362 base::RunLoop run_loop; |
| 401 run_loop.RunUntilIdle(); | 363 run_loop.RunUntilIdle(); |
| 402 } | 364 } |
| 403 EXPECT_TRUE(observer.gpu_info_updated()); | 365 EXPECT_TRUE(observer.gpu_info_updated()); |
| 404 } | 366 } |
| 405 | 367 |
| 406 TEST_F(GpuDataManagerImplPrivateTest, NoGpuInfoUpdateWithSwiftShader) { | 368 TEST_F(GpuDataManagerImplPrivateTest, NoGpuInfoUpdateWithSwiftShader) { |
| 407 ScopedGpuDataManagerImpl manager; | 369 ScopedGpuDataManagerImpl manager; |
| 408 manager->InitializeForTesting("", gpu::GPUInfo()); | 370 const gpu::GpuControlListData kData; |
| 371 manager->InitializeForTesting(kData, gpu::GPUInfo()); |
| 409 | 372 |
| 410 manager->DisableHardwareAcceleration(); | 373 manager->DisableHardwareAcceleration(); |
| 411 if (manager->ShouldUseSwiftShader()) { | 374 if (manager->ShouldUseSwiftShader()) { |
| 412 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 375 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 413 } else { | 376 } else { |
| 414 EXPECT_FALSE(manager->GpuAccessAllowed(NULL)); | 377 EXPECT_FALSE(manager->GpuAccessAllowed(NULL)); |
| 415 } | 378 } |
| 416 | 379 |
| 417 { | 380 { |
| 418 base::RunLoop run_loop; | 381 base::RunLoop run_loop; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 #if defined(OS_LINUX) | 550 #if defined(OS_LINUX) |
| 588 TEST_F(GpuDataManagerImplPrivateTest, SetGLStrings) { | 551 TEST_F(GpuDataManagerImplPrivateTest, SetGLStrings) { |
| 589 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; | 552 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; |
| 590 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; | 553 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; |
| 591 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; | 554 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; |
| 592 | 555 |
| 593 ScopedGpuDataManagerImplPrivate manager; | 556 ScopedGpuDataManagerImplPrivate manager; |
| 594 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 557 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
| 595 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 558 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 596 | 559 |
| 597 const std::string blacklist_json = LONG_STRING_CONST( | 560 const gpu::GpuControlList::Entry kEntries[] = { |
| 598 { | 561 gpu::kGpuDataManagerTestingEntries |
| 599 "name": "gpu blacklist", | 562 [gpu::kGpuDataManagerImplPrivateTest_SetGLStrings], |
| 600 "version": "0.1", | 563 }; |
| 601 "entries": [ | 564 const gpu::GpuControlListData kData("1.0", 1, kEntries); |
| 602 { | 565 |
| 603 "id": 1, | |
| 604 "vendor_id": "0x8086", | |
| 605 "exceptions": [ | |
| 606 { | |
| 607 "device_id": ["0x0042"], | |
| 608 "driver_version": { | |
| 609 "op": ">=", | |
| 610 "value": "8.0.2" | |
| 611 } | |
| 612 } | |
| 613 ], | |
| 614 "features": [ | |
| 615 "accelerated_webgl" | |
| 616 ] | |
| 617 } | |
| 618 ] | |
| 619 } | |
| 620 ); | |
| 621 gpu::GPUInfo gpu_info; | 566 gpu::GPUInfo gpu_info; |
| 622 gpu_info.gpu.vendor_id = 0x8086; | 567 gpu_info.gpu.vendor_id = 0x8086; |
| 623 gpu_info.gpu.device_id = 0x0042; | 568 gpu_info.gpu.device_id = 0x0042; |
| 624 manager->InitializeForTesting(blacklist_json, gpu_info); | 569 manager->InitializeForTesting(kData, gpu_info); |
| 625 | 570 |
| 626 // Not enough GPUInfo. | 571 // Not enough GPUInfo. |
| 627 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 572 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 628 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 573 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 629 | 574 |
| 630 // Now assume browser gets GL strings from local state. | 575 // Now assume browser gets GL strings from local state. |
| 631 // The entry applies, blacklist more features than from the preliminary step. | 576 // The entry applies, blacklist more features than from the preliminary step. |
| 632 // However, GPU process is not blocked because this is all browser side and | 577 // However, GPU process is not blocked because this is all browser side and |
| 633 // happens before renderer launching. | 578 // happens before renderer launching. |
| 634 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801); | 579 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801); |
| 635 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 580 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 636 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 581 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 637 EXPECT_TRUE( | 582 EXPECT_TRUE( |
| 638 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL)); | 583 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL)); |
| 639 } | 584 } |
| 640 | 585 |
| 641 TEST_F(GpuDataManagerImplPrivateTest, SetGLStringsNoEffects) { | 586 TEST_F(GpuDataManagerImplPrivateTest, SetGLStringsNoEffects) { |
| 642 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; | 587 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; |
| 643 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; | 588 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; |
| 644 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; | 589 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; |
| 645 const char* kGLVersionMesa802 = "2.1 Mesa 8.0.2-DEVEL"; | 590 const char* kGLVersionMesa802 = "2.1 Mesa 8.0.2-DEVEL"; |
| 646 | 591 |
| 647 ScopedGpuDataManagerImplPrivate manager; | 592 ScopedGpuDataManagerImplPrivate manager; |
| 648 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 593 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
| 649 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 594 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 650 | 595 |
| 651 const std::string blacklist_json = LONG_STRING_CONST( | 596 const gpu::GpuControlList::Entry kEntries[] = { |
| 652 { | 597 gpu::kGpuDataManagerTestingEntries |
| 653 "name": "gpu blacklist", | 598 [gpu::kGpuDataManagerImplPrivateTest_SetGLStringsNoEffects], |
| 654 "version": "0.1", | 599 }; |
| 655 "entries": [ | 600 const gpu::GpuControlListData kData("1.0", 1, kEntries); |
| 656 { | 601 |
| 657 "id": 1, | |
| 658 "vendor_id": "0x8086", | |
| 659 "exceptions": [ | |
| 660 { | |
| 661 "device_id": ["0x0042"], | |
| 662 "driver_version": { | |
| 663 "op": ">=", | |
| 664 "value": "8.0.2" | |
| 665 } | |
| 666 } | |
| 667 ], | |
| 668 "features": [ | |
| 669 "accelerated_webgl" | |
| 670 ] | |
| 671 } | |
| 672 ] | |
| 673 } | |
| 674 ); | |
| 675 gpu::GPUInfo gpu_info; | 602 gpu::GPUInfo gpu_info; |
| 676 gpu_info.gpu.vendor_id = 0x8086; | 603 gpu_info.gpu.vendor_id = 0x8086; |
| 677 gpu_info.gpu.device_id = 0x0042; | 604 gpu_info.gpu.device_id = 0x0042; |
| 678 gpu_info.gl_vendor = kGLVendorMesa; | 605 gpu_info.gl_vendor = kGLVendorMesa; |
| 679 gpu_info.gl_renderer = kGLRendererMesa; | 606 gpu_info.gl_renderer = kGLRendererMesa; |
| 680 gpu_info.gl_version = kGLVersionMesa801; | 607 gpu_info.gl_version = kGLVersionMesa801; |
| 681 gpu_info.driver_vendor = "Mesa"; | 608 gpu_info.driver_vendor = "Mesa"; |
| 682 gpu_info.driver_version = "8.0.1"; | 609 gpu_info.driver_version = "8.0.1"; |
| 683 manager->InitializeForTesting(blacklist_json, gpu_info); | 610 manager->InitializeForTesting(kData, gpu_info); |
| 684 | 611 |
| 685 // Full GPUInfo, the entry applies. | 612 // Full GPUInfo, the entry applies. |
| 686 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 613 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 687 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 614 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 688 EXPECT_TRUE( | 615 EXPECT_TRUE( |
| 689 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL)); | 616 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL)); |
| 690 | 617 |
| 691 // Now assume browser gets GL strings from local state. | 618 // Now assume browser gets GL strings from local state. |
| 692 // SetGLStrings() has no effects because GPUInfo already got these strings. | 619 // SetGLStrings() has no effects because GPUInfo already got these strings. |
| 693 // (Otherwise the entry should not apply.) | 620 // (Otherwise the entry should not apply.) |
| 694 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa802); | 621 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa802); |
| 695 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 622 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 696 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 623 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 697 EXPECT_TRUE( | 624 EXPECT_TRUE( |
| 698 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL)); | 625 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL)); |
| 699 } | 626 } |
| 700 | 627 |
| 701 TEST_F(GpuDataManagerImplPrivateTest, SetGLStringsDefered) { | 628 TEST_F(GpuDataManagerImplPrivateTest, SetGLStringsDefered) { |
| 702 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; | 629 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; |
| 703 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; | 630 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; |
| 704 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; | 631 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; |
| 705 | 632 |
| 706 ScopedGpuDataManagerImplPrivate manager; | 633 ScopedGpuDataManagerImplPrivate manager; |
| 707 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 634 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
| 708 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 635 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 709 | 636 |
| 710 const std::string blacklist_json = LONG_STRING_CONST({ | 637 const gpu::GpuControlList::Entry kEntries[] = { |
| 711 "name" : "gpu blacklist", | 638 gpu::kGpuDataManagerTestingEntries |
| 712 "version" : "0.1", | 639 [gpu::kGpuDataManagerImplPrivateTest_SetGLStringsDefered], |
| 713 "entries" : [ { | 640 }; |
| 714 "id" : 1, | 641 const gpu::GpuControlListData kData("1.0", 1, kEntries); |
| 715 "vendor_id" : "0x8086", | |
| 716 "device_id" : ["0x0042"], | |
| 717 "driver_vendor" : "Mesa", | |
| 718 "driver_version" : {"op" : ">=", "value" : "8.0.0"}, | |
| 719 "features" : ["accelerated_webgl"] | |
| 720 } ] | |
| 721 }); | |
| 722 | 642 |
| 723 // Check that it is allowed to call SetGLStrings before Initialize. | 643 // Check that it is allowed to call SetGLStrings before Initialize. |
| 724 | 644 |
| 725 // Assume browser gets GL strings from local state. | 645 // Assume browser gets GL strings from local state. |
| 726 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801); | 646 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801); |
| 727 | 647 |
| 728 gpu::GPUInfo gpu_info; | 648 gpu::GPUInfo gpu_info; |
| 729 gpu_info.gpu.vendor_id = 0x8086; | 649 gpu_info.gpu.vendor_id = 0x8086; |
| 730 gpu_info.gpu.device_id = 0x0042; | 650 gpu_info.gpu.device_id = 0x0042; |
| 731 manager->InitializeForTesting(blacklist_json, gpu_info); | 651 manager->InitializeForTesting(kData, gpu_info); |
| 732 | 652 |
| 733 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 653 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 734 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 654 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 735 EXPECT_TRUE( | 655 EXPECT_TRUE( |
| 736 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL)); | 656 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL)); |
| 737 } | 657 } |
| 738 #endif // OS_LINUX | 658 #endif // OS_LINUX |
| 739 | 659 |
| 740 TEST_F(GpuDataManagerImplPrivateTest, GpuDriverBugListSingle) { | 660 TEST_F(GpuDataManagerImplPrivateTest, GpuDriverBugListSingle) { |
| 741 ScopedGpuDataManagerImplPrivate manager; | 661 ScopedGpuDataManagerImplPrivate manager; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 764 EXPECT_STREQ("5,7", args.c_str()); | 684 EXPECT_STREQ("5,7", args.c_str()); |
| 765 } | 685 } |
| 766 | 686 |
| 767 TEST_F(GpuDataManagerImplPrivateTest, BlacklistAllFeatures) { | 687 TEST_F(GpuDataManagerImplPrivateTest, BlacklistAllFeatures) { |
| 768 ScopedGpuDataManagerImplPrivate manager; | 688 ScopedGpuDataManagerImplPrivate manager; |
| 769 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 689 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
| 770 std::string reason; | 690 std::string reason; |
| 771 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 691 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
| 772 EXPECT_TRUE(reason.empty()); | 692 EXPECT_TRUE(reason.empty()); |
| 773 | 693 |
| 774 const std::string blacklist_json = LONG_STRING_CONST( | 694 const gpu::GpuControlList::Entry kEntries[] = { |
| 775 { | 695 gpu::kGpuDataManagerTestingEntries |
| 776 "name": "gpu blacklist", | 696 [gpu::kGpuDataManagerImplPrivateTest_BlacklistAllFeatures], |
| 777 "version": "0.1", | 697 }; |
| 778 "entries": [ | 698 const gpu::GpuControlListData kData("1.0", 1, kEntries); |
| 779 { | |
| 780 "id": 1, | |
| 781 "features": [ | |
| 782 "all" | |
| 783 ] | |
| 784 } | |
| 785 ] | |
| 786 } | |
| 787 ); | |
| 788 | 699 |
| 789 gpu::GPUInfo gpu_info; | 700 gpu::GPUInfo gpu_info; |
| 790 gpu_info.gpu.vendor_id = 0x10de; | 701 gpu_info.gpu.vendor_id = 0x10de; |
| 791 gpu_info.gpu.device_id = 0x0640; | 702 gpu_info.gpu.device_id = 0x0640; |
| 792 manager->InitializeForTesting(blacklist_json, gpu_info); | 703 manager->InitializeForTesting(kData, gpu_info); |
| 793 | 704 |
| 794 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), | 705 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), |
| 795 manager->GetBlacklistedFeatureCount()); | 706 manager->GetBlacklistedFeatureCount()); |
| 796 if (manager->ShouldUseSwiftShader()) { | 707 if (manager->ShouldUseSwiftShader()) { |
| 797 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 708 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
| 798 EXPECT_TRUE(reason.empty()); | 709 EXPECT_TRUE(reason.empty()); |
| 799 } | 710 } |
| 800 } | 711 } |
| 801 | 712 |
| 802 TEST_F(GpuDataManagerImplPrivateTest, UpdateActiveGpu) { | 713 TEST_F(GpuDataManagerImplPrivateTest, UpdateActiveGpu) { |
| 803 ScopedGpuDataManagerImpl manager; | 714 ScopedGpuDataManagerImpl manager; |
| 804 | 715 |
| 805 const std::string blacklist_json = LONG_STRING_CONST( | 716 const gpu::GpuControlList::Entry kEntries[] = { |
| 806 { | 717 gpu::kGpuDataManagerTestingEntries |
| 807 "name": "gpu blacklist", | 718 [gpu::kGpuDataManagerImplPrivateTest_UpdateActiveGpu], |
| 808 "version": "0.1", | 719 }; |
| 809 "entries": [ | 720 const gpu::GpuControlListData kData("1.0", 1, kEntries); |
| 810 { | |
| 811 "id": 1, | |
| 812 "vendor_id": "0x8086", | |
| 813 "multi_gpu_category": "active", | |
| 814 "features": [ | |
| 815 "accelerated_webgl" | |
| 816 ] | |
| 817 } | |
| 818 ] | |
| 819 } | |
| 820 ); | |
| 821 | 721 |
| 822 // Two GPUs, the secondary Intel GPU is active. | 722 // Two GPUs, the secondary Intel GPU is active. |
| 823 gpu::GPUInfo gpu_info; | 723 gpu::GPUInfo gpu_info; |
| 824 gpu_info.gpu.vendor_id = 0x10de; | 724 gpu_info.gpu.vendor_id = 0x10de; |
| 825 gpu_info.gpu.device_id = 0x0640; | 725 gpu_info.gpu.device_id = 0x0640; |
| 826 gpu_info.gpu.active = false; | 726 gpu_info.gpu.active = false; |
| 827 gpu::GPUInfo::GPUDevice intel_gpu; | 727 gpu::GPUInfo::GPUDevice intel_gpu; |
| 828 intel_gpu.vendor_id = 0x8086; | 728 intel_gpu.vendor_id = 0x8086; |
| 829 intel_gpu.device_id = 0x04a1; | 729 intel_gpu.device_id = 0x04a1; |
| 830 intel_gpu.active = true; | 730 intel_gpu.active = true; |
| 831 gpu_info.secondary_gpus.push_back(intel_gpu); | 731 gpu_info.secondary_gpus.push_back(intel_gpu); |
| 832 | 732 |
| 833 manager->InitializeForTesting(blacklist_json, gpu_info); | 733 manager->InitializeForTesting(kData, gpu_info); |
| 834 TestObserver observer; | 734 TestObserver observer; |
| 835 manager->AddObserver(&observer); | 735 manager->AddObserver(&observer); |
| 836 | 736 |
| 837 if (manager->ShouldUseSwiftShader()) { | 737 if (manager->ShouldUseSwiftShader()) { |
| 838 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), | 738 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), |
| 839 manager->GetBlacklistedFeatureCount()); | 739 manager->GetBlacklistedFeatureCount()); |
| 840 } else { | 740 } else { |
| 841 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 741 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 842 } | 742 } |
| 843 | 743 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 EXPECT_TRUE(observer.gpu_info_updated()); | 795 EXPECT_TRUE(observer.gpu_info_updated()); |
| 896 if (manager->ShouldUseSwiftShader()) { | 796 if (manager->ShouldUseSwiftShader()) { |
| 897 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), | 797 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), |
| 898 manager->GetBlacklistedFeatureCount()); | 798 manager->GetBlacklistedFeatureCount()); |
| 899 } else { | 799 } else { |
| 900 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 800 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 901 } | 801 } |
| 902 } | 802 } |
| 903 | 803 |
| 904 } // namespace content | 804 } // namespace content |
| OLD | NEW |