OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/gpu/gpu_data_manager.h" | 5 #include "content/browser/gpu/gpu_data_manager.h" |
6 | 6 |
7 #if defined(OS_MACOSX) | 7 #if defined(OS_MACOSX) |
8 #include <CoreGraphics/CGDisplayConfiguration.h> | 8 #include <CoreGraphics/CGDisplayConfiguration.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/file_util.h" | |
14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
15 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
17 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "base/version.h" | 20 #include "base/version.h" |
20 #include "content/browser/gpu/gpu_blacklist.h" | 21 #include "content/browser/gpu/gpu_blacklist.h" |
21 #include "content/browser/gpu/gpu_process_host.h" | 22 #include "content/browser/gpu/gpu_process_host.h" |
22 #include "content/common/gpu/gpu_messages.h" | 23 #include "content/common/gpu/gpu_messages.h" |
23 #include "content/gpu/gpu_info_collector.h" | 24 #include "content/gpu/gpu_info_collector.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 | 189 |
189 void GpuDataManager::UserFlags::ApplyPolicies() { | 190 void GpuDataManager::UserFlags::ApplyPolicies() { |
190 if (disable_accelerated_compositing_) { | 191 if (disable_accelerated_compositing_) { |
191 disable_accelerated_2d_canvas_ = true; | 192 disable_accelerated_2d_canvas_ = true; |
192 disable_accelerated_layers_ = true; | 193 disable_accelerated_layers_ = true; |
193 } | 194 } |
194 } | 195 } |
195 | 196 |
196 GpuDataManager::GpuDataManager() | 197 GpuDataManager::GpuDataManager() |
197 : complete_gpu_info_already_requested_(false), | 198 : complete_gpu_info_already_requested_(false), |
198 observer_list_(new GpuDataManagerObserverList) { | 199 observer_list_(new GpuDataManagerObserverList), |
200 software_rendering_(false) { | |
199 Initialize(); | 201 Initialize(); |
200 } | 202 } |
201 | 203 |
202 void GpuDataManager::Initialize() { | 204 void GpuDataManager::Initialize() { |
203 // User flags need to be collected before any further initialization. | 205 // User flags need to be collected before any further initialization. |
204 user_flags_.Initialize(); | 206 user_flags_.Initialize(); |
205 | 207 |
206 // Certain tests doesn't go through the browser startup path that | 208 // Certain tests doesn't go through the browser startup path that |
207 // initializes GpuDataManager on FILE thread; therefore, it is initialized | 209 // initializes GpuDataManager on FILE thread; therefore, it is initialized |
208 // on UI thread later, and we skip the preliminary gpu info collection | 210 // on UI thread later, and we skip the preliminary gpu info collection |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 ListValue* feature_status_list = new ListValue(); | 321 ListValue* feature_status_list = new ListValue(); |
320 | 322 |
321 for (size_t i = 0; i < kNumFeatures; ++i) { | 323 for (size_t i = 0; i < kNumFeatures; ++i) { |
322 std::string status; | 324 std::string status; |
323 if (kGpuFeatureInfo[i].disabled) { | 325 if (kGpuFeatureInfo[i].disabled) { |
324 status = "disabled"; | 326 status = "disabled"; |
325 if (kGpuFeatureInfo[i].fallback_to_software) | 327 if (kGpuFeatureInfo[i].fallback_to_software) |
326 status += "_software"; | 328 status += "_software"; |
327 else | 329 else |
328 status += "_off"; | 330 status += "_off"; |
329 } else if (kGpuFeatureInfo[i].blocked || gpu_access_blocked) { | 331 } else if (IsSoftwareRendering()) { |
332 status = "unavailable_software"; | |
333 } else if (kGpuFeatureInfo[i].blocked || | |
334 gpu_access_blocked) { | |
330 status = "unavailable"; | 335 status = "unavailable"; |
331 if (kGpuFeatureInfo[i].fallback_to_software) | 336 if (kGpuFeatureInfo[i].fallback_to_software) |
332 status += "_software"; | 337 status += "_software"; |
333 else | 338 else |
334 status += "_off"; | 339 status += "_off"; |
335 } else { | 340 } else { |
336 status = "enabled"; | 341 status = "enabled"; |
337 if (kGpuFeatureInfo[i].name == "webgl" && | 342 if (kGpuFeatureInfo[i].name == "webgl" && |
338 (user_flags_.disable_accelerated_compositing() || | 343 (user_flags_.disable_accelerated_compositing() || |
339 (flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing))) | 344 (flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing))) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
400 log_messages_.Append(msg); | 405 log_messages_.Append(msg); |
401 } | 406 } |
402 | 407 |
403 const ListValue& GpuDataManager::log_messages() const { | 408 const ListValue& GpuDataManager::log_messages() const { |
404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
405 return log_messages_; | 410 return log_messages_; |
406 } | 411 } |
407 | 412 |
408 GpuFeatureFlags GpuDataManager::GetGpuFeatureFlags() { | 413 GpuFeatureFlags GpuDataManager::GetGpuFeatureFlags() { |
414 if (software_rendering_) { | |
415 GpuFeatureFlags flags; | |
416 | |
417 // Skia's software rendering is probably more efficient than going through | |
418 // software emulation of the GPU, so use that. | |
419 flags.set_flags(GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas); | |
Zhenyao Mo
2011/11/05 00:39:19
What about accelerated_compositing? what about mu
jbauman
2011/11/05 00:49:34
We need accelerated compositing, or webgl will be
Zhenyao Mo
2011/11/05 01:03:58
OK. Multisampling on/off depends on performance.
| |
420 return flags; | |
421 } | |
422 | |
409 return gpu_feature_flags_; | 423 return gpu_feature_flags_; |
410 } | 424 } |
411 | 425 |
412 bool GpuDataManager::GpuAccessAllowed() { | 426 bool GpuDataManager::GpuAccessAllowed() { |
427 if (IsSoftwareRendering()) | |
428 return true; | |
429 | |
413 // We only need to block GPU process if more features are disallowed other | 430 // We only need to block GPU process if more features are disallowed other |
414 // than those in the preliminary gpu feature flags because the latter work | 431 // than those in the preliminary gpu feature flags because the latter work |
415 // through renderer commandline switches. | 432 // through renderer commandline switches. |
416 uint32 mask = (~(preliminary_gpu_feature_flags_.flags())); | 433 uint32 mask = (~(preliminary_gpu_feature_flags_.flags())); |
417 return (gpu_feature_flags_.flags() & mask) == 0; | 434 return (gpu_feature_flags_.flags() & mask) == 0; |
418 } | 435 } |
419 | 436 |
420 void GpuDataManager::AddObserver(Observer* observer) { | 437 void GpuDataManager::AddObserver(Observer* observer) { |
421 observer_list_->AddObserver(observer); | 438 observer_list_->AddObserver(observer); |
422 } | 439 } |
(...skipping 28 matching lines...) Expand all Loading... | |
451 void GpuDataManager::AppendGpuCommandLine( | 468 void GpuDataManager::AppendGpuCommandLine( |
452 CommandLine* command_line) { | 469 CommandLine* command_line) { |
453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
454 DCHECK(command_line); | 471 DCHECK(command_line); |
455 | 472 |
456 uint32 flags = gpu_feature_flags_.flags(); | 473 uint32 flags = gpu_feature_flags_.flags(); |
457 if ((flags & GpuFeatureFlags::kGpuFeatureMultisampling) && | 474 if ((flags & GpuFeatureFlags::kGpuFeatureMultisampling) && |
458 !command_line->HasSwitch(switches::kDisableGLMultisampling)) | 475 !command_line->HasSwitch(switches::kDisableGLMultisampling)) |
459 command_line->AppendSwitch(switches::kDisableGLMultisampling); | 476 command_line->AppendSwitch(switches::kDisableGLMultisampling); |
460 | 477 |
461 if ((flags & (GpuFeatureFlags::kGpuFeatureWebgl | | 478 if (software_rendering_) { |
479 command_line->AppendSwitchASCII(switches::kUseGL, "swiftshader"); | |
480 command_line->AppendSwitchPath(switches::kSwiftShaderPath, | |
481 swiftshader_path_); | |
482 } else if ((flags & (GpuFeatureFlags::kGpuFeatureWebgl | | |
462 GpuFeatureFlags::kGpuFeatureAcceleratedCompositing | | 483 GpuFeatureFlags::kGpuFeatureAcceleratedCompositing | |
463 GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)) && | 484 GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)) && |
464 (user_flags_.use_gl() == "any")) { | 485 (user_flags_.use_gl() == "any")) { |
465 command_line->AppendSwitchASCII( | 486 command_line->AppendSwitchASCII( |
466 switches::kUseGL, gfx::kGLImplementationOSMesaName); | 487 switches::kUseGL, gfx::kGLImplementationOSMesaName); |
467 } else if (!user_flags_.use_gl().empty()) { | 488 } else if (!user_flags_.use_gl().empty()) { |
468 command_line->AppendSwitchASCII(switches::kUseGL, user_flags_.use_gl()); | 489 command_line->AppendSwitchASCII(switches::kUseGL, user_flags_.use_gl()); |
469 } | 490 } |
470 } | 491 } |
471 | 492 |
(...skipping 22 matching lines...) Expand all Loading... | |
494 if (!updated_list->GetVersion( | 515 if (!updated_list->GetVersion( |
495 &updated_version_major, &updated_version_minor)) | 516 &updated_version_major, &updated_version_minor)) |
496 return; | 517 return; |
497 | 518 |
498 uint16 current_version_major, current_version_minor; | 519 uint16 current_version_major, current_version_minor; |
499 bool succeed = gpu_blacklist_->GetVersion( | 520 bool succeed = gpu_blacklist_->GetVersion( |
500 ¤t_version_major, ¤t_version_minor); | 521 ¤t_version_major, ¤t_version_minor); |
501 DCHECK(succeed); | 522 DCHECK(succeed); |
502 if (updated_version_major < current_version_major || | 523 if (updated_version_major < current_version_major || |
503 (updated_version_major == current_version_major && | 524 (updated_version_major == current_version_major && |
504 updated_version_minor <= current_version_minor)) | 525 updated_version_minor <= current_version_minor)) { |
505 return; | 526 return; |
527 } | |
506 | 528 |
507 gpu_blacklist_.reset(updated_list.release()); | 529 gpu_blacklist_.reset(updated_list.release()); |
508 UpdateGpuFeatureFlags(); | 530 UpdateGpuFeatureFlags(); |
509 if (preliminary) | 531 if (preliminary) |
510 preliminary_gpu_feature_flags_ = gpu_feature_flags_; | 532 preliminary_gpu_feature_flags_ = gpu_feature_flags_; |
511 VLOG(1) << "Using software rendering list version " | 533 VLOG(1) << "Using software rendering list version " |
512 << updated_version_major << "." << updated_version_minor; | 534 << updated_version_major << "." << updated_version_minor; |
513 } | 535 } |
514 | 536 |
515 void GpuDataManager::HandleGpuSwitch() { | 537 void GpuDataManager::HandleGpuSwitch() { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
666 histogram_pointer->Add(value); | 688 histogram_pointer->Add(value); |
667 #if defined(OS_WIN) | 689 #if defined(OS_WIN) |
668 histogram_pointer = base::LinearHistogram::FactoryGet( | 690 histogram_pointer = base::LinearHistogram::FactoryGet( |
669 kGpuBlacklistFeatureHistogramNamesWin[i], | 691 kGpuBlacklistFeatureHistogramNamesWin[i], |
670 1, kNumWinSubVersions * kGpuFeatureNumStatus, | 692 1, kNumWinSubVersions * kGpuFeatureNumStatus, |
671 kNumWinSubVersions * kGpuFeatureNumStatus + 1, | 693 kNumWinSubVersions * kGpuFeatureNumStatus + 1, |
672 base::Histogram::kUmaTargetedHistogramFlag); | 694 base::Histogram::kUmaTargetedHistogramFlag); |
673 histogram_pointer->Add(GetGpuBlacklistHistogramValueWin(value)); | 695 histogram_pointer->Add(GetGpuBlacklistHistogramValueWin(value)); |
674 #endif | 696 #endif |
675 } | 697 } |
698 | |
699 EnableSoftwareRenderingIfNecessary(); | |
700 } | |
701 | |
702 void GpuDataManager::RegisterSwiftShaderPath(FilePath path) { | |
703 swiftshader_path_ = path; | |
704 EnableSoftwareRenderingIfNecessary(); | |
705 } | |
706 | |
707 void GpuDataManager::EnableSoftwareRenderingIfNecessary() { | |
708 if (!GpuAccessAllowed()) { | |
Zhenyao Mo
2011/11/05 00:39:19
Even if GpuAccessAllowed() returns true, but if we
jbauman
2011/11/05 00:49:34
It's kind of annoying that this would slow down ac
| |
709 #if defined(ENABLE_SWIFTSHADER) | |
710 FilePath eglpath = swiftshader_path_.AppendASCII("libegl.dll"); | |
711 if (!swiftshader_path_.empty() && file_util::PathExists(eglpath)) | |
Zhenyao Mo
2011/11/05 00:39:19
PathExists should only be called on a thread that
jbauman
2011/11/05 00:49:34
Good point, I can remove this check.
| |
712 software_rendering_ = true; | |
713 #endif | |
714 } | |
676 } | 715 } |
677 | 716 |
717 bool GpuDataManager::IsSoftwareRendering() { | |
718 return software_rendering_; | |
Zhenyao Mo
2011/11/05 00:39:19
Accessor functions should match the variable name.
jbauman
2011/11/05 00:49:34
Ok.
| |
719 } | |
720 | |
678 GpuBlacklist* GpuDataManager::GetGpuBlacklist() const { | 721 GpuBlacklist* GpuDataManager::GetGpuBlacklist() const { |
679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 722 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
680 if (user_flags_.ignore_gpu_blacklist()) | 723 if (user_flags_.ignore_gpu_blacklist()) |
681 return NULL; | 724 return NULL; |
682 // No need to return an empty blacklist. | 725 // No need to return an empty blacklist. |
683 if (gpu_blacklist_.get() != NULL && gpu_blacklist_->max_entry_id() == 0) | 726 if (gpu_blacklist_.get() != NULL && gpu_blacklist_->max_entry_id() == 0) |
684 return NULL; | 727 return NULL; |
685 return gpu_blacklist_.get(); | 728 return gpu_blacklist_.get(); |
686 } | 729 } |
687 | 730 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 bool GpuDataManager::supportsAccelerated2dCanvas() const { | 796 bool GpuDataManager::supportsAccelerated2dCanvas() const { |
754 if (gpu_info_.can_lose_context) | 797 if (gpu_info_.can_lose_context) |
755 return false; | 798 return false; |
756 #if defined(USE_SKIA) | 799 #if defined(USE_SKIA) |
757 return true; | 800 return true; |
758 #else | 801 #else |
759 return false; | 802 return false; |
760 #endif | 803 #endif |
761 } | 804 } |
762 | 805 |
OLD | NEW |