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 "content/browser/gpu/gpu_data_manager_impl_private.h" | 5 #include "content/browser/gpu/gpu_data_manager_impl_private.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 void DisplayReconfigCallback(CGDirectDisplayID display, | 210 void DisplayReconfigCallback(CGDirectDisplayID display, |
211 CGDisplayChangeSummaryFlags flags, | 211 CGDisplayChangeSummaryFlags flags, |
212 void* gpu_data_manager) { | 212 void* gpu_data_manager) { |
213 if (flags == kCGDisplayBeginConfigurationFlag) | 213 if (flags == kCGDisplayBeginConfigurationFlag) |
214 return; // This call contains no information about the display change | 214 return; // This call contains no information about the display change |
215 | 215 |
216 GpuDataManagerImpl* manager = | 216 GpuDataManagerImpl* manager = |
217 reinterpret_cast<GpuDataManagerImpl*>(gpu_data_manager); | 217 reinterpret_cast<GpuDataManagerImpl*>(gpu_data_manager); |
218 DCHECK(manager); | 218 DCHECK(manager); |
219 | 219 |
| 220 // Display change. |
| 221 bool display_changed = false; |
220 uint32_t displayCount; | 222 uint32_t displayCount; |
221 CGGetActiveDisplayList(0, NULL, &displayCount); | 223 CGGetActiveDisplayList(0, NULL, &displayCount); |
222 | |
223 bool fireGpuSwitch = flags & kCGDisplayAddFlag; | |
224 | |
225 if (displayCount != manager->GetDisplayCount()) { | 224 if (displayCount != manager->GetDisplayCount()) { |
226 manager->SetDisplayCount(displayCount); | 225 manager->SetDisplayCount(displayCount); |
227 fireGpuSwitch = true; | 226 display_changed = true; |
228 } | 227 } |
229 | 228 |
230 if (fireGpuSwitch) | 229 // Gpu change. |
| 230 bool gpu_changed = false; |
| 231 if (flags & kCGDisplayAddFlag) { |
| 232 uint32 vendor_id, device_id; |
| 233 if (gpu::CollectGpuID(&vendor_id, &device_id) == gpu::kGpuIDSuccess) { |
| 234 gpu_changed = manager->UpdateActiveGpu(vendor_id, device_id); |
| 235 } |
| 236 } |
| 237 |
| 238 if (display_changed || gpu_changed) |
231 manager->HandleGpuSwitch(); | 239 manager->HandleGpuSwitch(); |
232 } | 240 } |
233 #endif // OS_MACOSX | 241 #endif // OS_MACOSX |
234 | 242 |
235 #if defined(OS_ANDROID) | 243 #if defined(OS_ANDROID) |
236 void ApplyAndroidWorkarounds(const gpu::GPUInfo& gpu_info, | 244 void ApplyAndroidWorkarounds(const gpu::GPUInfo& gpu_info, |
237 CommandLine* command_line) { | 245 CommandLine* command_line) { |
238 std::string vendor(StringToLowerASCII(gpu_info.gl_vendor)); | 246 std::string vendor(StringToLowerASCII(gpu_info.gl_vendor)); |
239 std::string renderer(StringToLowerASCII(gpu_info.gl_renderer)); | 247 std::string renderer(StringToLowerASCII(gpu_info.gl_renderer)); |
240 bool is_img = | 248 bool is_img = |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 base::DictionaryValue* dict = new base::DictionaryValue(); | 883 base::DictionaryValue* dict = new base::DictionaryValue(); |
876 dict->SetInteger("level", log_messages_[ii].level); | 884 dict->SetInteger("level", log_messages_[ii].level); |
877 dict->SetString("header", log_messages_[ii].header); | 885 dict->SetString("header", log_messages_[ii].header); |
878 dict->SetString("message", log_messages_[ii].message); | 886 dict->SetString("message", log_messages_[ii].message); |
879 value->Append(dict); | 887 value->Append(dict); |
880 } | 888 } |
881 return value; | 889 return value; |
882 } | 890 } |
883 | 891 |
884 void GpuDataManagerImplPrivate::HandleGpuSwitch() { | 892 void GpuDataManagerImplPrivate::HandleGpuSwitch() { |
885 // Check if the active gpu has changed. | 893 GpuDataManagerImpl::UnlockedSession session(owner_); |
886 uint32 vendor_id, device_id; | 894 observer_list_->Notify(&GpuDataManagerObserver::OnGpuSwitching); |
887 gpu::GPUInfo::GPUDevice* active = NULL; | 895 } |
888 gpu::GPUInfo::GPUDevice* old_active = NULL; | 896 |
889 if (gpu::CollectGpuID(&vendor_id, &device_id) == gpu::kGpuIDSuccess) { | 897 bool GpuDataManagerImplPrivate::UpdateActiveGpu( |
| 898 uint32 vendor_id, uint32 device_id) { |
| 899 if (gpu_info_.gpu.vendor_id == vendor_id && |
| 900 gpu_info_.gpu.device_id == device_id) { |
| 901 // The primary GPU is active. |
890 if (gpu_info_.gpu.active) | 902 if (gpu_info_.gpu.active) |
891 old_active = &gpu_info_.gpu; | 903 return false; |
892 if (gpu_info_.gpu.vendor_id == vendor_id && | 904 gpu_info_.gpu.active = true; |
893 gpu_info_.gpu.device_id == device_id) | 905 for (size_t ii = 0; ii < gpu_info_.secondary_gpus.size(); ++ii) |
894 active = &gpu_info_.gpu; | 906 gpu_info_.secondary_gpus[ii].active = false; |
| 907 } else { |
| 908 // A secondary GPU is active. |
895 for (size_t ii = 0; ii < gpu_info_.secondary_gpus.size(); ++ii) { | 909 for (size_t ii = 0; ii < gpu_info_.secondary_gpus.size(); ++ii) { |
896 gpu::GPUInfo::GPUDevice& gpu = gpu_info_.secondary_gpus[ii]; | 910 if (gpu_info_.secondary_gpus[ii].vendor_id == vendor_id && |
897 if (gpu.active) | 911 gpu_info_.secondary_gpus[ii].device_id == device_id) { |
898 old_active = &gpu; | 912 if (gpu_info_.secondary_gpus[ii].active) |
899 if (gpu.vendor_id == vendor_id && gpu.device_id == device_id) | 913 return false; |
900 active = &gpu; | 914 gpu_info_.secondary_gpus[ii].active = true; |
| 915 } else { |
| 916 gpu_info_.secondary_gpus[ii].active = false; |
| 917 } |
901 } | 918 } |
902 DCHECK(active && old_active); | 919 gpu_info_.gpu.active = false; |
903 if (active != old_active) { // A different GPU is used. | |
904 old_active->active = false; | |
905 active->active = true; | |
906 UpdateGpuInfoHelper(); | |
907 } | |
908 } | 920 } |
909 { | 921 UpdateGpuInfoHelper(); |
910 GpuDataManagerImpl::UnlockedSession session(owner_); | 922 return true; |
911 observer_list_->Notify(&GpuDataManagerObserver::OnGpuSwitching); | |
912 } | |
913 } | 923 } |
914 | 924 |
915 bool GpuDataManagerImplPrivate::CanUseGpuBrowserCompositor() const { | 925 bool GpuDataManagerImplPrivate::CanUseGpuBrowserCompositor() const { |
916 return !ShouldUseSwiftShader() && | 926 return !ShouldUseSwiftShader() && |
917 !IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) && | 927 !IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) && |
918 !IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FORCE_COMPOSITING_MODE); | 928 !IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FORCE_COMPOSITING_MODE); |
919 } | 929 } |
920 | 930 |
921 void GpuDataManagerImplPrivate::BlockDomainFrom3DAPIs( | 931 void GpuDataManagerImplPrivate::BlockDomainFrom3DAPIs( |
922 const GURL& url, GpuDataManagerImpl::DomainGuilt guilt) { | 932 const GURL& url, GpuDataManagerImpl::DomainGuilt guilt) { |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 | 1200 |
1191 void GpuDataManagerImplPrivate::OnGpuProcessInitFailure() { | 1201 void GpuDataManagerImplPrivate::OnGpuProcessInitFailure() { |
1192 gpu_process_accessible_ = false; | 1202 gpu_process_accessible_ = false; |
1193 gpu_info_.finalized = true; | 1203 gpu_info_.finalized = true; |
1194 complete_gpu_info_already_requested_ = true; | 1204 complete_gpu_info_already_requested_ = true; |
1195 // Some observers might be waiting. | 1205 // Some observers might be waiting. |
1196 NotifyGpuInfoUpdate(); | 1206 NotifyGpuInfoUpdate(); |
1197 } | 1207 } |
1198 | 1208 |
1199 } // namespace content | 1209 } // namespace content |
OLD | NEW |