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/public/browser/gpu_data_manager_observer.h" | 14 #include "content/public/browser/gpu_data_manager_observer.h" |
15 #include "gpu/config/gpu_feature_type.h" | 15 #include "gpu/config/gpu_feature_type.h" |
16 #include "gpu/config/gpu_info.h" | 16 #include "gpu/config/gpu_info.h" |
17 #include "gpu/config/gpu_switches.h" | 17 #include "gpu/config/gpu_switches.h" |
18 #include "gpu/ipc/common/memory_stats.h" | 18 #include "gpu/ipc/common/memory_stats.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/gl/gl_features.h" |
20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
21 | 22 |
22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
23 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
24 #endif | 25 #endif |
25 | 26 |
26 #define LONG_STRING_CONST(...) #__VA_ARGS__ | 27 #define LONG_STRING_CONST(...) #__VA_ARGS__ |
27 | 28 |
28 namespace content { | 29 namespace content { |
29 namespace { | 30 namespace { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 173 } |
173 ); | 174 ); |
174 | 175 |
175 gpu::GPUInfo gpu_info; | 176 gpu::GPUInfo gpu_info; |
176 gpu_info.gpu.vendor_id = 0x10de; | 177 gpu_info.gpu.vendor_id = 0x10de; |
177 gpu_info.gpu.device_id = 0x0640; | 178 gpu_info.gpu.device_id = 0x0640; |
178 manager->InitializeForTesting(blacklist_json, gpu_info); | 179 manager->InitializeForTesting(blacklist_json, gpu_info); |
179 | 180 |
180 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 181 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
181 EXPECT_TRUE(reason.empty()); | 182 EXPECT_TRUE(reason.empty()); |
| 183 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
| 184 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); |
| 185 EXPECT_FALSE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)); |
| 186 #else |
182 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 187 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
183 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)); | 188 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)); |
| 189 #endif |
184 | 190 |
185 gpu_info.gl_vendor = "NVIDIA"; | 191 gpu_info.gl_vendor = "NVIDIA"; |
186 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; | 192 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; |
187 manager->UpdateGpuInfo(gpu_info); | 193 manager->UpdateGpuInfo(gpu_info); |
| 194 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
| 195 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
| 196 EXPECT_TRUE(reason.empty()); |
| 197 #else |
188 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); | 198 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); |
189 EXPECT_FALSE(reason.empty()); | 199 EXPECT_FALSE(reason.empty()); |
| 200 #endif |
190 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); | 201 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); |
191 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)); | 202 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
| 203 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL2)); |
| 204 #else |
| 205 EXPECT_FALSE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL2)); |
| 206 #endif |
192 EXPECT_TRUE(manager->IsFeatureBlacklisted( | 207 EXPECT_TRUE(manager->IsFeatureBlacklisted( |
193 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); | 208 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); |
194 } | 209 } |
195 | 210 |
196 TEST_F(GpuDataManagerImplPrivateTest, GpuSideBlacklistingWebGL) { | 211 TEST_F(GpuDataManagerImplPrivateTest, GpuSideBlacklistingWebGL) { |
197 // If a feature is allowed in preliminary step (browser side), but | 212 // If a feature is allowed in preliminary step (browser side), but |
198 // disabled when GPU process launches and collects full GPU info, | 213 // disabled when GPU process launches and collects full GPU info, |
199 // it's too late to let renderer know, so we basically block all GPU | 214 // it's too late to let renderer know, so we basically block all GPU |
200 // access, to be on the safe side. | 215 // access, to be on the safe side. |
201 ScopedGpuDataManagerImplPrivate manager; | 216 ScopedGpuDataManagerImplPrivate manager; |
(...skipping 25 matching lines...) Expand all Loading... |
227 } | 242 } |
228 ); | 243 ); |
229 | 244 |
230 gpu::GPUInfo gpu_info; | 245 gpu::GPUInfo gpu_info; |
231 gpu_info.gpu.vendor_id = 0x10de; | 246 gpu_info.gpu.vendor_id = 0x10de; |
232 gpu_info.gpu.device_id = 0x0640; | 247 gpu_info.gpu.device_id = 0x0640; |
233 manager->InitializeForTesting(blacklist_json, gpu_info); | 248 manager->InitializeForTesting(blacklist_json, gpu_info); |
234 | 249 |
235 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 250 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
236 EXPECT_TRUE(reason.empty()); | 251 EXPECT_TRUE(reason.empty()); |
| 252 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
| 253 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); |
| 254 #else |
237 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 255 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 256 #endif |
238 EXPECT_TRUE(manager->IsFeatureBlacklisted( | 257 EXPECT_TRUE(manager->IsFeatureBlacklisted( |
239 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); | 258 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); |
240 | 259 |
241 gpu_info.gl_vendor = "NVIDIA"; | 260 gpu_info.gl_vendor = "NVIDIA"; |
242 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; | 261 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; |
243 manager->UpdateGpuInfo(gpu_info); | 262 manager->UpdateGpuInfo(gpu_info); |
244 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 263 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
245 EXPECT_TRUE(reason.empty()); | 264 EXPECT_TRUE(reason.empty()); |
| 265 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
| 266 EXPECT_TRUE(manager->ShouldUseSwiftShader()); |
| 267 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); |
| 268 #else |
| 269 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
246 EXPECT_EQ(3u, manager->GetBlacklistedFeatureCount()); | 270 EXPECT_EQ(3u, manager->GetBlacklistedFeatureCount()); |
| 271 #endif |
247 EXPECT_TRUE(manager->IsFeatureBlacklisted( | 272 EXPECT_TRUE(manager->IsFeatureBlacklisted( |
248 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); | 273 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); |
| 274 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
| 275 EXPECT_FALSE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)); |
| 276 #else |
249 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)); | 277 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)); |
| 278 #endif |
250 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL2)); | 279 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL2)); |
251 } | 280 } |
252 | 281 |
253 TEST_F(GpuDataManagerImplPrivateTest, GpuSideExceptions) { | 282 TEST_F(GpuDataManagerImplPrivateTest, GpuSideExceptions) { |
254 ScopedGpuDataManagerImplPrivate manager; | 283 ScopedGpuDataManagerImplPrivate manager; |
255 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 284 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
256 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 285 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
257 | 286 |
258 const std::string blacklist_json = LONG_STRING_CONST( | 287 const std::string blacklist_json = LONG_STRING_CONST( |
259 { | 288 { |
(...skipping 13 matching lines...) Expand all Loading... |
273 } | 302 } |
274 ] | 303 ] |
275 } | 304 } |
276 ); | 305 ); |
277 gpu::GPUInfo gpu_info; | 306 gpu::GPUInfo gpu_info; |
278 gpu_info.gpu.vendor_id = 0x10de; | 307 gpu_info.gpu.vendor_id = 0x10de; |
279 gpu_info.gpu.device_id = 0x0640; | 308 gpu_info.gpu.device_id = 0x0640; |
280 manager->InitializeForTesting(blacklist_json, gpu_info); | 309 manager->InitializeForTesting(blacklist_json, gpu_info); |
281 | 310 |
282 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 311 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 312 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
| 313 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); |
| 314 #else |
283 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 315 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 316 #endif |
284 | 317 |
285 // Now assume gpu process launches and full GPU info is collected. | 318 // Now assume gpu process launches and full GPU info is collected. |
286 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; | 319 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; |
287 manager->UpdateGpuInfo(gpu_info); | 320 manager->UpdateGpuInfo(gpu_info); |
288 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 321 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
289 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 322 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
290 } | 323 } |
291 | 324 |
292 TEST_F(GpuDataManagerImplPrivateTest, DisableHardwareAcceleration) { | 325 TEST_F(GpuDataManagerImplPrivateTest, DisableHardwareAcceleration) { |
293 ScopedGpuDataManagerImplPrivate manager; | 326 ScopedGpuDataManagerImplPrivate manager; |
294 manager->InitializeForTesting("", gpu::GPUInfo()); | 327 manager->InitializeForTesting("", gpu::GPUInfo()); |
295 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 328 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
296 std::string reason; | 329 std::string reason; |
297 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 330 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
298 EXPECT_TRUE(reason.empty()); | 331 EXPECT_TRUE(reason.empty()); |
299 | 332 |
300 manager->DisableHardwareAcceleration(); | 333 manager->DisableHardwareAcceleration(); |
| 334 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
| 335 EXPECT_TRUE(manager->ShouldUseSwiftShader()); |
| 336 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
| 337 EXPECT_TRUE(reason.empty()); |
| 338 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); |
| 339 #else |
| 340 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
301 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); | 341 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); |
302 EXPECT_FALSE(reason.empty()); | 342 EXPECT_FALSE(reason.empty()); |
303 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), | 343 EXPECT_EQ(12u, manager->GetBlacklistedFeatureCount()); |
304 manager->GetBlacklistedFeatureCount()); | 344 #endif |
305 } | 345 } |
306 | 346 |
307 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering) { | 347 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering) { |
308 // Blacklist, then register SwiftShader. | 348 // Blacklist, then register SwiftShader. |
309 ScopedGpuDataManagerImplPrivate manager; | 349 ScopedGpuDataManagerImplPrivate manager; |
310 manager->InitializeForTesting("", gpu::GPUInfo()); | 350 manager->InitializeForTesting("", gpu::GPUInfo()); |
311 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 351 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
312 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 352 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
313 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | 353 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
314 | 354 |
315 manager->DisableHardwareAcceleration(); | 355 manager->DisableHardwareAcceleration(); |
316 EXPECT_FALSE(manager->GpuAccessAllowed(NULL)); | 356 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
317 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | |
318 | |
319 // If SwiftShader is enabled, even if we blacklist GPU, | |
320 // GPU process is still allowed. | |
321 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); | |
322 manager->RegisterSwiftShaderPath(test_path); | |
323 EXPECT_TRUE(manager->ShouldUseSwiftShader()); | 357 EXPECT_TRUE(manager->ShouldUseSwiftShader()); |
324 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 358 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
325 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 359 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); |
| 360 #else |
| 361 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
| 362 EXPECT_FALSE(manager->GpuAccessAllowed(NULL)); |
| 363 EXPECT_EQ(12u, manager->GetBlacklistedFeatureCount()); |
| 364 #endif |
326 EXPECT_TRUE(manager->IsFeatureBlacklisted( | 365 EXPECT_TRUE(manager->IsFeatureBlacklisted( |
327 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); | 366 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); |
| 367 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL2)); |
328 } | 368 } |
329 | 369 |
330 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering2) { | 370 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering2) { |
331 // Register SwiftShader, then blacklist. | 371 // Register SwiftShader, then blacklist. |
332 ScopedGpuDataManagerImplPrivate manager; | 372 ScopedGpuDataManagerImplPrivate manager; |
333 manager->InitializeForTesting("", gpu::GPUInfo()); | 373 manager->InitializeForTesting("", gpu::GPUInfo()); |
334 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 374 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
335 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 375 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
336 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | 376 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
337 | 377 |
338 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); | |
339 manager->RegisterSwiftShaderPath(test_path); | |
340 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | |
341 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | |
342 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | |
343 | |
344 manager->DisableHardwareAcceleration(); | 378 manager->DisableHardwareAcceleration(); |
| 379 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
345 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 380 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
346 EXPECT_TRUE(manager->ShouldUseSwiftShader()); | 381 EXPECT_TRUE(manager->ShouldUseSwiftShader()); |
347 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 382 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); |
| 383 #else |
| 384 EXPECT_FALSE(manager->GpuAccessAllowed(NULL)); |
| 385 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
| 386 EXPECT_EQ(12u, manager->GetBlacklistedFeatureCount()); |
| 387 #endif |
348 EXPECT_TRUE(manager->IsFeatureBlacklisted( | 388 EXPECT_TRUE(manager->IsFeatureBlacklisted( |
349 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); | 389 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); |
| 390 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL2)); |
350 } | 391 } |
351 | 392 |
352 TEST_F(GpuDataManagerImplPrivateTest, GpuInfoUpdate) { | 393 TEST_F(GpuDataManagerImplPrivateTest, GpuInfoUpdate) { |
353 ScopedGpuDataManagerImpl manager; | 394 ScopedGpuDataManagerImpl manager; |
354 | 395 |
355 TestObserver observer; | 396 TestObserver observer; |
356 manager->AddObserver(&observer); | 397 manager->AddObserver(&observer); |
357 | 398 |
358 { | 399 { |
359 base::RunLoop run_loop; | 400 base::RunLoop run_loop; |
360 run_loop.RunUntilIdle(); | 401 run_loop.RunUntilIdle(); |
361 } | 402 } |
362 EXPECT_FALSE(observer.gpu_info_updated()); | 403 EXPECT_FALSE(observer.gpu_info_updated()); |
363 | 404 |
364 gpu::GPUInfo gpu_info; | 405 gpu::GPUInfo gpu_info; |
365 manager->UpdateGpuInfo(gpu_info); | 406 manager->UpdateGpuInfo(gpu_info); |
366 { | 407 { |
367 base::RunLoop run_loop; | 408 base::RunLoop run_loop; |
368 run_loop.RunUntilIdle(); | 409 run_loop.RunUntilIdle(); |
369 } | 410 } |
370 EXPECT_TRUE(observer.gpu_info_updated()); | 411 EXPECT_TRUE(observer.gpu_info_updated()); |
371 } | 412 } |
372 | 413 |
373 TEST_F(GpuDataManagerImplPrivateTest, NoGpuInfoUpdateWithSwiftShader) { | 414 TEST_F(GpuDataManagerImplPrivateTest, NoGpuInfoUpdateWithSwiftShader) { |
374 ScopedGpuDataManagerImpl manager; | 415 ScopedGpuDataManagerImpl manager; |
375 manager->InitializeForTesting("", gpu::GPUInfo()); | 416 manager->InitializeForTesting("", gpu::GPUInfo()); |
376 | 417 |
377 manager->DisableHardwareAcceleration(); | 418 manager->DisableHardwareAcceleration(); |
378 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); | 419 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
379 manager->RegisterSwiftShaderPath(test_path); | |
380 EXPECT_TRUE(manager->ShouldUseSwiftShader()); | 420 EXPECT_TRUE(manager->ShouldUseSwiftShader()); |
381 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 421 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); |
| 422 #else |
| 423 EXPECT_FALSE(manager->ShouldUseSwiftShader()); |
| 424 EXPECT_FALSE(manager->GpuAccessAllowed(NULL)); |
| 425 #endif |
382 | 426 |
383 { | 427 { |
384 base::RunLoop run_loop; | 428 base::RunLoop run_loop; |
385 run_loop.RunUntilIdle(); | 429 run_loop.RunUntilIdle(); |
386 } | 430 } |
387 | 431 |
388 TestObserver observer; | 432 TestObserver observer; |
389 manager->AddObserver(&observer); | 433 manager->AddObserver(&observer); |
390 { | 434 { |
391 base::RunLoop run_loop; | 435 base::RunLoop run_loop; |
392 run_loop.RunUntilIdle(); | 436 run_loop.RunUntilIdle(); |
393 } | 437 } |
394 EXPECT_FALSE(observer.gpu_info_updated()); | 438 EXPECT_FALSE(observer.gpu_info_updated()); |
395 | 439 |
396 gpu::GPUInfo gpu_info; | 440 gpu::GPUInfo gpu_info; |
397 manager->UpdateGpuInfo(gpu_info); | 441 manager->UpdateGpuInfo(gpu_info); |
398 { | 442 { |
399 base::RunLoop run_loop; | 443 base::RunLoop run_loop; |
400 run_loop.RunUntilIdle(); | 444 run_loop.RunUntilIdle(); |
401 } | 445 } |
402 EXPECT_FALSE(observer.gpu_info_updated()); | 446 EXPECT_TRUE(observer.gpu_info_updated()); |
403 } | 447 } |
404 | 448 |
405 TEST_F(GpuDataManagerImplPrivateTest, GPUVideoMemoryUsageStatsUpdate) { | 449 TEST_F(GpuDataManagerImplPrivateTest, GPUVideoMemoryUsageStatsUpdate) { |
406 ScopedGpuDataManagerImpl manager; | 450 ScopedGpuDataManagerImpl manager; |
407 | 451 |
408 TestObserver observer; | 452 TestObserver observer; |
409 manager->AddObserver(&observer); | 453 manager->AddObserver(&observer); |
410 | 454 |
411 { | 455 { |
412 base::RunLoop run_loop; | 456 base::RunLoop run_loop; |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 } | 785 } |
742 ] | 786 ] |
743 } | 787 } |
744 ); | 788 ); |
745 | 789 |
746 gpu::GPUInfo gpu_info; | 790 gpu::GPUInfo gpu_info; |
747 gpu_info.gpu.vendor_id = 0x10de; | 791 gpu_info.gpu.vendor_id = 0x10de; |
748 gpu_info.gpu.device_id = 0x0640; | 792 gpu_info.gpu.device_id = 0x0640; |
749 manager->InitializeForTesting(blacklist_json, gpu_info); | 793 manager->InitializeForTesting(blacklist_json, gpu_info); |
750 | 794 |
751 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES), | 795 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
752 manager->GetBlacklistedFeatureCount()); | 796 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); |
753 // TODO(zmo): remove the Linux specific behavior once we fix | |
754 // crbug.com/238466. | |
755 #if defined(OS_LINUX) | |
756 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 797 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); |
757 EXPECT_TRUE(reason.empty()); | 798 EXPECT_TRUE(reason.empty()); |
758 #else | 799 #else |
759 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); | 800 EXPECT_EQ(12u, manager->GetBlacklistedFeatureCount()); |
760 EXPECT_FALSE(reason.empty()); | |
761 #endif | 801 #endif |
762 } | 802 } |
763 | 803 |
764 TEST_F(GpuDataManagerImplPrivateTest, UpdateActiveGpu) { | 804 TEST_F(GpuDataManagerImplPrivateTest, UpdateActiveGpu) { |
765 ScopedGpuDataManagerImpl manager; | 805 ScopedGpuDataManagerImpl manager; |
766 | 806 |
767 const std::string blacklist_json = LONG_STRING_CONST( | 807 const std::string blacklist_json = LONG_STRING_CONST( |
768 { | 808 { |
769 "name": "gpu blacklist", | 809 "name": "gpu blacklist", |
770 "version": "0.1", | 810 "version": "0.1", |
(...skipping 18 matching lines...) Expand all Loading... |
789 gpu::GPUInfo::GPUDevice intel_gpu; | 829 gpu::GPUInfo::GPUDevice intel_gpu; |
790 intel_gpu.vendor_id = 0x8086; | 830 intel_gpu.vendor_id = 0x8086; |
791 intel_gpu.device_id = 0x04a1; | 831 intel_gpu.device_id = 0x04a1; |
792 intel_gpu.active = true; | 832 intel_gpu.active = true; |
793 gpu_info.secondary_gpus.push_back(intel_gpu); | 833 gpu_info.secondary_gpus.push_back(intel_gpu); |
794 | 834 |
795 manager->InitializeForTesting(blacklist_json, gpu_info); | 835 manager->InitializeForTesting(blacklist_json, gpu_info); |
796 TestObserver observer; | 836 TestObserver observer; |
797 manager->AddObserver(&observer); | 837 manager->AddObserver(&observer); |
798 | 838 |
| 839 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
| 840 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); |
| 841 #else |
799 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 842 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 843 #endif |
800 | 844 |
801 // Update with the same Intel GPU active. | 845 // Update with the same Intel GPU active. |
802 EXPECT_FALSE(manager->UpdateActiveGpu(0x8086, 0x04a1)); | 846 EXPECT_FALSE(manager->UpdateActiveGpu(0x8086, 0x04a1)); |
803 { | 847 { |
804 base::RunLoop run_loop; | 848 base::RunLoop run_loop; |
805 run_loop.RunUntilIdle(); | 849 run_loop.RunUntilIdle(); |
806 } | 850 } |
807 EXPECT_FALSE(observer.gpu_info_updated()); | 851 EXPECT_FALSE(observer.gpu_info_updated()); |
| 852 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
| 853 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); |
| 854 #else |
808 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 855 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 856 #endif |
809 | 857 |
810 // Set NVIDIA GPU to be active. | 858 // Set NVIDIA GPU to be active. |
811 EXPECT_TRUE(manager->UpdateActiveGpu(0x10de, 0x0640)); | 859 EXPECT_TRUE(manager->UpdateActiveGpu(0x10de, 0x0640)); |
812 { | 860 { |
813 base::RunLoop run_loop; | 861 base::RunLoop run_loop; |
814 run_loop.RunUntilIdle(); | 862 run_loop.RunUntilIdle(); |
815 } | 863 } |
816 EXPECT_TRUE(observer.gpu_info_updated()); | 864 EXPECT_TRUE(observer.gpu_info_updated()); |
817 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 865 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
818 | 866 |
819 observer.Reset(); | 867 observer.Reset(); |
820 EXPECT_FALSE(observer.gpu_info_updated()); | 868 EXPECT_FALSE(observer.gpu_info_updated()); |
821 | 869 |
822 // Update with the same NVIDIA GPU active. | 870 // Update with the same NVIDIA GPU active. |
823 EXPECT_FALSE(manager->UpdateActiveGpu(0x10de, 0x0640)); | 871 EXPECT_FALSE(manager->UpdateActiveGpu(0x10de, 0x0640)); |
824 { | 872 { |
825 base::RunLoop run_loop; | 873 base::RunLoop run_loop; |
826 run_loop.RunUntilIdle(); | 874 run_loop.RunUntilIdle(); |
827 } | 875 } |
828 EXPECT_FALSE(observer.gpu_info_updated()); | 876 EXPECT_FALSE(observer.gpu_info_updated()); |
829 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 877 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); |
830 | 878 |
831 // Set Intel GPU to be active. | 879 // Set Intel GPU to be active. |
832 EXPECT_TRUE(manager->UpdateActiveGpu(0x8086, 0x04a1)); | 880 EXPECT_TRUE(manager->UpdateActiveGpu(0x8086, 0x04a1)); |
833 { | 881 { |
834 base::RunLoop run_loop; | 882 base::RunLoop run_loop; |
835 run_loop.RunUntilIdle(); | 883 run_loop.RunUntilIdle(); |
836 } | 884 } |
837 EXPECT_TRUE(observer.gpu_info_updated()); | 885 EXPECT_TRUE(observer.gpu_info_updated()); |
| 886 #if BUILDFLAG(ENABLE_SWIFTSHADER) |
| 887 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); |
| 888 #else |
838 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 889 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); |
| 890 #endif |
839 } | 891 } |
840 | 892 |
841 } // namespace content | 893 } // namespace content |
OLD | NEW |