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" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 226 |
227 // Now assume gpu process launches and full GPU info is collected. | 227 // Now assume gpu process launches and full GPU info is collected. |
228 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; | 228 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; |
229 manager->UpdateGpuInfo(gpu_info); | 229 manager->UpdateGpuInfo(gpu_info); |
230 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 230 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
231 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 231 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
232 } | 232 } |
233 | 233 |
234 TEST_F(GpuDataManagerImplPrivateTest, DisableHardwareAcceleration) { | 234 TEST_F(GpuDataManagerImplPrivateTest, DisableHardwareAcceleration) { |
235 ScopedGpuDataManagerImplPrivate manager; | 235 ScopedGpuDataManagerImplPrivate manager; |
| 236 manager->InitializeForTesting("", gpu::GPUInfo()); |
236 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 237 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
237 std::string reason; | 238 std::string reason; |
238 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 239 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
239 EXPECT_TRUE(reason.empty()); | 240 EXPECT_TRUE(reason.empty()); |
240 | 241 |
241 manager->DisableHardwareAcceleration(); | 242 manager->DisableHardwareAcceleration(); |
242 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); | 243 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); |
243 EXPECT_FALSE(reason.empty()); | 244 EXPECT_FALSE(reason.empty()); |
244 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), | 245 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), |
245 manager->GetBlacklistedFeatureCount()); | 246 manager->GetBlacklistedFeatureCount()); |
246 } | 247 } |
247 | 248 |
248 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering) { | 249 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering) { |
249 // Blacklist, then register SwiftShader. | 250 // Blacklist, then register SwiftShader. |
250 ScopedGpuDataManagerImplPrivate manager; | 251 ScopedGpuDataManagerImplPrivate manager; |
| 252 manager->InitializeForTesting("", gpu::GPUInfo()); |
251 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 253 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
252 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 254 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
253 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | 255 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
254 | 256 |
255 manager->DisableHardwareAcceleration(); | 257 manager->DisableHardwareAcceleration(); |
256 EXPECT_FALSE(manager->GpuAccessAllowed(NULL)); | 258 EXPECT_FALSE(manager->GpuAccessAllowed(NULL)); |
257 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | 259 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
258 | 260 |
259 // If SwiftShader is enabled, even if we blacklist GPU, | 261 // If SwiftShader is enabled, even if we blacklist GPU, |
260 // GPU process is still allowed. | 262 // GPU process is still allowed. |
261 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); | 263 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); |
262 manager->RegisterSwiftShaderPath(test_path); | 264 manager->RegisterSwiftShaderPath(test_path); |
263 EXPECT_TRUE(manager->ShouldUseSwiftShader()); | 265 EXPECT_TRUE(manager->ShouldUseSwiftShader()); |
264 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 266 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
265 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 267 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
266 EXPECT_TRUE(manager->IsFeatureBlacklisted( | 268 EXPECT_TRUE(manager->IsFeatureBlacklisted( |
267 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); | 269 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); |
268 } | 270 } |
269 | 271 |
270 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering2) { | 272 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering2) { |
271 // Register SwiftShader, then blacklist. | 273 // Register SwiftShader, then blacklist. |
272 ScopedGpuDataManagerImplPrivate manager; | 274 ScopedGpuDataManagerImplPrivate manager; |
| 275 manager->InitializeForTesting("", gpu::GPUInfo()); |
273 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 276 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
274 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 277 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
275 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | 278 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
276 | 279 |
277 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); | 280 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); |
278 manager->RegisterSwiftShaderPath(test_path); | 281 manager->RegisterSwiftShaderPath(test_path); |
279 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 282 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
280 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 283 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
281 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | 284 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
282 | 285 |
(...skipping 21 matching lines...) Expand all Loading... |
304 manager->UpdateGpuInfo(gpu_info); | 307 manager->UpdateGpuInfo(gpu_info); |
305 { | 308 { |
306 base::RunLoop run_loop; | 309 base::RunLoop run_loop; |
307 run_loop.RunUntilIdle(); | 310 run_loop.RunUntilIdle(); |
308 } | 311 } |
309 EXPECT_TRUE(observer.gpu_info_updated()); | 312 EXPECT_TRUE(observer.gpu_info_updated()); |
310 } | 313 } |
311 | 314 |
312 TEST_F(GpuDataManagerImplPrivateTest, NoGpuInfoUpdateWithSwiftShader) { | 315 TEST_F(GpuDataManagerImplPrivateTest, NoGpuInfoUpdateWithSwiftShader) { |
313 ScopedGpuDataManagerImpl manager; | 316 ScopedGpuDataManagerImpl manager; |
| 317 manager->InitializeForTesting("", gpu::GPUInfo()); |
314 | 318 |
315 manager->DisableHardwareAcceleration(); | 319 manager->DisableHardwareAcceleration(); |
316 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); | 320 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); |
317 manager->RegisterSwiftShaderPath(test_path); | 321 manager->RegisterSwiftShaderPath(test_path); |
318 EXPECT_TRUE(manager->ShouldUseSwiftShader()); | 322 EXPECT_TRUE(manager->ShouldUseSwiftShader()); |
319 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 323 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
320 | 324 |
321 { | 325 { |
322 base::RunLoop run_loop; | 326 base::RunLoop run_loop; |
323 run_loop.RunUntilIdle(); | 327 run_loop.RunUntilIdle(); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)); | 590 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)); |
587 | 591 |
588 // Now assume browser gets GL strings from local state. | 592 // Now assume browser gets GL strings from local state. |
589 // SetGLStrings() has no effects because GPUInfo already got these strings. | 593 // SetGLStrings() has no effects because GPUInfo already got these strings. |
590 // (Otherwise the entry should not apply.) | 594 // (Otherwise the entry should not apply.) |
591 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa802); | 595 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa802); |
592 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 596 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
593 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 597 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
594 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)); | 598 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)); |
595 } | 599 } |
| 600 |
| 601 TEST_F(GpuDataManagerImplPrivateTest, SetGLStringsDefered) { |
| 602 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; |
| 603 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; |
| 604 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; |
| 605 |
| 606 ScopedGpuDataManagerImplPrivate manager; |
| 607 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
| 608 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 609 |
| 610 const std::string blacklist_json = LONG_STRING_CONST({ |
| 611 "name" : "gpu blacklist", |
| 612 "version" : "0.1", |
| 613 "entries" : [ { |
| 614 "id" : 1, |
| 615 "vendor_id" : "0x8086", |
| 616 "device_id" : ["0x0042"], |
| 617 "driver_vendor" : "Mesa", |
| 618 "driver_version" : {"op" : ">=", "value" : "8.0.0"}, |
| 619 "features" : ["webgl"] |
| 620 } ] |
| 621 }); |
| 622 |
| 623 // Check that it is allowed to call SetGLStrings before Initialize. |
| 624 |
| 625 // Assume browser gets GL strings from local state. |
| 626 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801); |
| 627 |
| 628 gpu::GPUInfo gpu_info; |
| 629 gpu_info.gpu.vendor_id = 0x8086; |
| 630 gpu_info.gpu.device_id = 0x0042; |
| 631 manager->InitializeForTesting(blacklist_json, gpu_info); |
| 632 |
| 633 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 634 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 635 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)); |
| 636 } |
596 #endif // OS_LINUX | 637 #endif // OS_LINUX |
597 | 638 |
598 TEST_F(GpuDataManagerImplPrivateTest, GpuDriverBugListSingle) { | 639 TEST_F(GpuDataManagerImplPrivateTest, GpuDriverBugListSingle) { |
599 ScopedGpuDataManagerImplPrivate manager; | 640 ScopedGpuDataManagerImplPrivate manager; |
600 manager->gpu_driver_bugs_.insert(5); | 641 manager->gpu_driver_bugs_.insert(5); |
601 | 642 |
602 base::CommandLine command_line(0, NULL); | 643 base::CommandLine command_line(0, NULL); |
603 manager->AppendGpuCommandLine(&command_line); | 644 manager->AppendGpuCommandLine(&command_line); |
604 | 645 |
605 EXPECT_TRUE(command_line.HasSwitch(switches::kGpuDriverBugWorkarounds)); | 646 EXPECT_TRUE(command_line.HasSwitch(switches::kGpuDriverBugWorkarounds)); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 EXPECT_TRUE(manager->UpdateActiveGpu(0x8086, 0x04a1)); | 774 EXPECT_TRUE(manager->UpdateActiveGpu(0x8086, 0x04a1)); |
734 { | 775 { |
735 base::RunLoop run_loop; | 776 base::RunLoop run_loop; |
736 run_loop.RunUntilIdle(); | 777 run_loop.RunUntilIdle(); |
737 } | 778 } |
738 EXPECT_TRUE(observer.gpu_info_updated()); | 779 EXPECT_TRUE(observer.gpu_info_updated()); |
739 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 780 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
740 } | 781 } |
741 | 782 |
742 } // namespace content | 783 } // namespace content |
OLD | NEW |