Chromium Code Reviews| 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" | |
| 12 #include "base/bind_helpers.h" | |
| 11 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 12 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 13 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 14 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
| 15 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| 17 #include "base/version.h" | 19 #include "base/version.h" |
| 18 #include "content/browser/browser_thread.h" | 20 #include "content/browser/browser_thread.h" |
| 19 #include "content/browser/gpu/gpu_blacklist.h" | 21 #include "content/browser/gpu/gpu_blacklist.h" |
| 20 #include "content/browser/gpu/gpu_process_host.h" | 22 #include "content/browser/gpu/gpu_process_host.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 } | 182 } |
| 181 | 183 |
| 182 void GpuDataManager::UserFlags::ApplyPolicies() { | 184 void GpuDataManager::UserFlags::ApplyPolicies() { |
| 183 if (disable_accelerated_compositing_) { | 185 if (disable_accelerated_compositing_) { |
| 184 disable_accelerated_2d_canvas_ = true; | 186 disable_accelerated_2d_canvas_ = true; |
| 185 disable_accelerated_layers_ = true; | 187 disable_accelerated_layers_ = true; |
| 186 } | 188 } |
| 187 } | 189 } |
| 188 | 190 |
| 189 GpuDataManager::GpuDataManager() | 191 GpuDataManager::GpuDataManager() |
| 190 : complete_gpu_info_already_requested_(false) { | 192 : complete_gpu_info_already_requested_(false), |
| 193 observer_list_(new GpuDataManagerObserverList) { | |
| 191 Initialize(); | 194 Initialize(); |
| 192 } | 195 } |
| 193 | 196 |
| 194 void GpuDataManager::Initialize() { | 197 void GpuDataManager::Initialize() { |
| 195 // Certain tests doesn't go through the browser startup path that | 198 // Certain tests doesn't go through the browser startup path that |
| 196 // initializes GpuDataManager on FILE thread; therefore, it is initialized | 199 // initializes GpuDataManager on FILE thread; therefore, it is initialized |
| 197 // on UI thread later, and we skip the preliminary gpu info collection | 200 // on UI thread later, and we skip the preliminary gpu info collection |
| 198 // in such situation. | 201 // in such situation. |
| 199 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | 202 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 200 content::GPUInfo gpu_info; | 203 content::GPUInfo gpu_info; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 new GpuMsg_CollectGraphicsInfo()); | 235 new GpuMsg_CollectGraphicsInfo()); |
| 233 } | 236 } |
| 234 | 237 |
| 235 void GpuDataManager::UpdateGpuInfo(const content::GPUInfo& gpu_info) { | 238 void GpuDataManager::UpdateGpuInfo(const content::GPUInfo& gpu_info) { |
| 236 { | 239 { |
| 237 base::AutoLock auto_lock(gpu_info_lock_); | 240 base::AutoLock auto_lock(gpu_info_lock_); |
| 238 if (!Merge(&gpu_info_, gpu_info)) | 241 if (!Merge(&gpu_info_, gpu_info)) |
| 239 return; | 242 return; |
| 240 } | 243 } |
| 241 | 244 |
| 242 RunGpuInfoUpdateCallbacks(); | 245 NotifyGpuInfoUpdate(); |
| 243 | 246 |
| 244 { | 247 { |
| 245 base::AutoLock auto_lock(gpu_info_lock_); | 248 base::AutoLock auto_lock(gpu_info_lock_); |
| 246 content::GetContentClient()->SetGpuInfo(gpu_info_); | 249 content::GetContentClient()->SetGpuInfo(gpu_info_); |
| 247 } | 250 } |
| 248 | 251 |
| 249 UpdateGpuFeatureFlags(); | 252 UpdateGpuFeatureFlags(); |
| 250 } | 253 } |
| 251 | 254 |
| 252 const content::GPUInfo& GpuDataManager::gpu_info() const { | 255 const content::GPUInfo& GpuDataManager::gpu_info() const { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 if (UseGLIsOSMesaOrAny()) | 406 if (UseGLIsOSMesaOrAny()) |
| 404 return true; | 407 return true; |
| 405 | 408 |
| 406 // We only need to block GPU process if more features are disallowed other | 409 // We only need to block GPU process if more features are disallowed other |
| 407 // than those in the preliminary gpu feature flags because the latter work | 410 // than those in the preliminary gpu feature flags because the latter work |
| 408 // through renderer commandline switches. | 411 // through renderer commandline switches. |
| 409 uint32 mask = (~(preliminary_gpu_feature_flags_.flags())); | 412 uint32 mask = (~(preliminary_gpu_feature_flags_.flags())); |
| 410 return (gpu_feature_flags_.flags() & mask) == 0; | 413 return (gpu_feature_flags_.flags() & mask) == 0; |
| 411 } | 414 } |
| 412 | 415 |
| 413 void GpuDataManager::AddGpuInfoUpdateCallback(Callback0::Type* callback) { | 416 void GpuDataManager::AddObserver(Observer* observer) { |
| 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 417 observer_list_->AddObserver(observer); |
| 415 gpu_info_update_callbacks_.insert(callback); | |
| 416 } | 418 } |
| 417 | 419 |
| 418 bool GpuDataManager::RemoveGpuInfoUpdateCallback(Callback0::Type* callback) { | 420 void GpuDataManager::RemoveObserver(Observer* observer) { |
| 419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 421 observer_list_->RemoveObserver(observer); |
| 420 std::set<Callback0::Type*>::iterator i = | |
| 421 gpu_info_update_callbacks_.find(callback); | |
| 422 if (i != gpu_info_update_callbacks_.end()) { | |
| 423 gpu_info_update_callbacks_.erase(i); | |
| 424 return true; | |
| 425 } | |
| 426 return false; | |
| 427 } | 422 } |
| 428 | 423 |
| 429 void GpuDataManager::AppendRendererCommandLine( | 424 void GpuDataManager::AppendRendererCommandLine( |
| 430 CommandLine* command_line) { | 425 CommandLine* command_line) { |
| 431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 432 DCHECK(command_line); | 427 DCHECK(command_line); |
| 433 | 428 |
| 434 uint32 flags = gpu_feature_flags_.flags(); | 429 uint32 flags = gpu_feature_flags_.flags(); |
| 435 if ((flags & GpuFeatureFlags::kGpuFeatureWebgl)) { | 430 if ((flags & GpuFeatureFlags::kGpuFeatureWebgl)) { |
| 436 if (!command_line->HasSwitch(switches::kDisableExperimentalWebGL)) | 431 if (!command_line->HasSwitch(switches::kDisableExperimentalWebGL)) |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 if (gpu_info().dx_diagnostics.children.size()) | 558 if (gpu_info().dx_diagnostics.children.size()) |
| 564 dx_info = DxDiagNodeToList(gpu_info().dx_diagnostics); | 559 dx_info = DxDiagNodeToList(gpu_info().dx_diagnostics); |
| 565 else | 560 else |
| 566 dx_info = Value::CreateNullValue(); | 561 dx_info = Value::CreateNullValue(); |
| 567 info->Set("diagnostics", dx_info); | 562 info->Set("diagnostics", dx_info); |
| 568 #endif | 563 #endif |
| 569 | 564 |
| 570 return info; | 565 return info; |
| 571 } | 566 } |
| 572 | 567 |
| 573 void GpuDataManager::RunGpuInfoUpdateCallbacks() { | 568 void GpuDataManager::NotifyGpuInfoUpdate() { |
| 574 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 569 observer_list_->Notify(&GpuDataManager::Observer::OnGpuInfoUpdate); |
| 575 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 576 NewRunnableMethod(this, &GpuDataManager::RunGpuInfoUpdateCallbacks)); | |
| 577 return; | |
| 578 } | |
| 579 | |
| 580 std::set<Callback0::Type*>::iterator i = gpu_info_update_callbacks_.begin(); | |
| 581 for (; i != gpu_info_update_callbacks_.end(); ++i) { | |
| 582 (*i)->Run(); | |
| 583 } | |
| 584 } | 570 } |
| 585 | 571 |
| 586 void GpuDataManager::UpdateGpuFeatureFlags() { | 572 void GpuDataManager::UpdateGpuFeatureFlags() { |
| 587 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 573 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 588 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 574 BrowserThread::PostTask( |
| 589 NewRunnableMethod(this, &GpuDataManager::UpdateGpuFeatureFlags)); | 575 BrowserThread::UI, FROM_HERE, |
| 576 base::Bind(&GpuDataManager::UpdateGpuFeatureFlags, | |
| 577 base::Unretained(this))); | |
|
James Hawkins
2011/10/25 23:36:52
Is base::Unretained() really needed here? The con
csilv
2011/10/26 00:02:47
So, in the original implementation NewRunnableMeth
James Hawkins
2011/10/26 00:21:29
Gotcha.
| |
| 590 return; | 578 return; |
| 591 } | 579 } |
| 592 | 580 |
| 593 GpuBlacklist* gpu_blacklist = GetGpuBlacklist(); | 581 GpuBlacklist* gpu_blacklist = GetGpuBlacklist(); |
| 594 // We don't set a lock around modifying gpu_feature_flags_ since it's just an | 582 // We don't set a lock around modifying gpu_feature_flags_ since it's just an |
| 595 // int. | 583 // int. |
| 596 if (!gpu_blacklist) { | 584 if (!gpu_blacklist) { |
| 597 gpu_feature_flags_.set_flags(0); | 585 gpu_feature_flags_.set_flags(0); |
| 598 return; | 586 return; |
| 599 } | 587 } |
| 600 | 588 |
| 601 { | 589 { |
| 602 base::AutoLock auto_lock(gpu_info_lock_); | 590 base::AutoLock auto_lock(gpu_info_lock_); |
| 603 gpu_feature_flags_ = gpu_blacklist->DetermineGpuFeatureFlags( | 591 gpu_feature_flags_ = gpu_blacklist->DetermineGpuFeatureFlags( |
| 604 GpuBlacklist::kOsAny, NULL, gpu_info_); | 592 GpuBlacklist::kOsAny, NULL, gpu_info_); |
| 605 } | 593 } |
| 606 | 594 |
| 607 // Notify clients that GpuInfo state has changed | 595 // Notify clients that GpuInfo state has changed |
| 608 RunGpuInfoUpdateCallbacks(); | 596 NotifyGpuInfoUpdate(); |
| 609 | 597 |
| 610 uint32 flags = gpu_feature_flags_.flags(); | 598 uint32 flags = gpu_feature_flags_.flags(); |
| 611 uint32 max_entry_id = gpu_blacklist->max_entry_id(); | 599 uint32 max_entry_id = gpu_blacklist->max_entry_id(); |
| 612 bool disabled = false; | 600 bool disabled = false; |
| 613 if (flags == 0) { | 601 if (flags == 0) { |
| 614 UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerEntry", | 602 UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerEntry", |
| 615 0, max_entry_id + 1); | 603 0, max_entry_id + 1); |
| 616 } else { | 604 } else { |
| 617 std::vector<uint32> flag_entries; | 605 std::vector<uint32> flag_entries; |
| 618 gpu_blacklist->GetGpuFeatureFlagEntries( | 606 gpu_blacklist->GetGpuFeatureFlagEntries( |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 #if defined(OS_WIN) | 743 #if defined(OS_WIN) |
| 756 if (object->dx_diagnostics.values.size() == 0 && | 744 if (object->dx_diagnostics.values.size() == 0 && |
| 757 object->dx_diagnostics.children.size() == 0) { | 745 object->dx_diagnostics.children.size() == 0) { |
| 758 object->dx_diagnostics = other.dx_diagnostics; | 746 object->dx_diagnostics = other.dx_diagnostics; |
| 759 changed = true; | 747 changed = true; |
| 760 } | 748 } |
| 761 #endif | 749 #endif |
| 762 } | 750 } |
| 763 return changed; | 751 return changed; |
| 764 } | 752 } |
| OLD | NEW |