OLD | NEW |
---|---|
1 // Copyright (c) 2012 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.h" | 5 #include "content/browser/gpu/gpu_data_manager_impl_private.h" |
6 | 6 |
7 #if defined(OS_MACOSX) | 7 #if defined(OS_MACOSX) |
8 #include <ApplicationServices/ApplicationServices.h> | 8 #include <ApplicationServices/ApplicationServices.h> |
9 #endif // OS_MACOSX | 9 #endif // OS_MACOSX |
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/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_piece.h" | 20 #include "base/strings/string_piece.h" |
21 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
22 #include "base/values.h" | |
23 #include "base/version.h" | 22 #include "base/version.h" |
24 #include "content/browser/gpu/gpu_process_host.h" | 23 #include "content/browser/gpu/gpu_process_host.h" |
25 #include "content/browser/gpu/gpu_util.h" | 24 #include "content/browser/gpu/gpu_util.h" |
26 #include "content/common/gpu/gpu_messages.h" | 25 #include "content/common/gpu/gpu_messages.h" |
27 #include "content/gpu/gpu_info_collector.h" | 26 #include "content/gpu/gpu_info_collector.h" |
28 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/gpu_data_manager_observer.h" | 28 #include "content/public/browser/gpu_data_manager_observer.h" |
30 #include "content/public/common/content_client.h" | 29 #include "content/public/common/content_client.h" |
31 #include "content/public/common/content_constants.h" | 30 #include "content/public/common/content_constants.h" |
32 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 // Enums for UMA histograms. | 94 // Enums for UMA histograms. |
96 enum BlockStatusHistogram { | 95 enum BlockStatusHistogram { |
97 BLOCK_STATUS_NOT_BLOCKED, | 96 BLOCK_STATUS_NOT_BLOCKED, |
98 BLOCK_STATUS_SPECIFIC_DOMAIN_BLOCKED, | 97 BLOCK_STATUS_SPECIFIC_DOMAIN_BLOCKED, |
99 BLOCK_STATUS_ALL_DOMAINS_BLOCKED, | 98 BLOCK_STATUS_ALL_DOMAINS_BLOCKED, |
100 BLOCK_STATUS_MAX | 99 BLOCK_STATUS_MAX |
101 }; | 100 }; |
102 | 101 |
103 } // namespace anonymous | 102 } // namespace anonymous |
104 | 103 |
105 // static | 104 void GpuDataManagerImplPrivate::InitializeForTesting( |
106 GpuDataManager* GpuDataManager::GetInstance() { | |
107 return GpuDataManagerImpl::GetInstance(); | |
108 } | |
109 | |
110 // static | |
111 GpuDataManagerImpl* GpuDataManagerImpl::GetInstance() { | |
112 return Singleton<GpuDataManagerImpl>::get(); | |
113 } | |
114 | |
115 void GpuDataManagerImpl::InitializeForTesting( | |
116 const std::string& gpu_blacklist_json, | 105 const std::string& gpu_blacklist_json, |
117 const GPUInfo& gpu_info) { | 106 const GPUInfo& gpu_info) { |
118 // This function is for testing only, so disable histograms. | 107 // This function is for testing only, so disable histograms. |
119 update_histograms_ = false; | 108 update_histograms_ = false; |
120 | 109 |
121 InitializeImpl(gpu_blacklist_json, std::string(), std::string(), gpu_info); | 110 InitializeImpl(gpu_blacklist_json, std::string(), std::string(), gpu_info); |
122 } | 111 } |
123 | 112 |
124 bool GpuDataManagerImpl::IsFeatureBlacklisted(int feature) const { | 113 bool GpuDataManagerImplPrivate::IsFeatureBlacklisted(int feature) const { |
125 if (use_swiftshader_) { | 114 if (use_swiftshader_) { |
126 // Skia's software rendering is probably more efficient than going through | 115 // Skia's software rendering is probably more efficient than going through |
127 // software emulation of the GPU, so use that. | 116 // software emulation of the GPU, so use that. |
128 if (feature == GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS) | 117 if (feature == GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS) |
129 return true; | 118 return true; |
130 return false; | 119 return false; |
131 } | 120 } |
132 | 121 |
133 return (blacklisted_features_.count(feature) == 1); | 122 return (blacklisted_features_.count(feature) == 1); |
134 } | 123 } |
135 | 124 |
136 size_t GpuDataManagerImpl::GetBlacklistedFeatureCount() const { | 125 size_t GpuDataManagerImplPrivate::GetBlacklistedFeatureCount() const { |
137 if (use_swiftshader_) | 126 if (use_swiftshader_) |
138 return 1; | 127 return 1; |
139 return blacklisted_features_.size(); | 128 return blacklisted_features_.size(); |
140 } | 129 } |
141 | 130 |
142 void GpuDataManagerImpl::AddGpuSwitchCallback( | 131 void GpuDataManagerImplPrivate::AddGpuSwitchCallback( |
143 const GpuSwitchCallback& callback) { | 132 const GpuSwitchCallback& callback) { |
144 gpu_switch_callbacks_.push_back(callback); | 133 gpu_switch_callbacks_.push_back(callback); |
145 } | 134 } |
146 | 135 |
147 void GpuDataManagerImpl::RemoveGpuSwitchCallback( | 136 void GpuDataManagerImplPrivate::RemoveGpuSwitchCallback( |
148 const GpuSwitchCallback& callback) { | 137 const GpuSwitchCallback& callback) { |
149 for (size_t i = 0; i < gpu_switch_callbacks_.size(); i++) { | 138 for (size_t i = 0; i < gpu_switch_callbacks_.size(); i++) { |
150 if (gpu_switch_callbacks_[i].Equals(callback)) { | 139 if (gpu_switch_callbacks_[i].Equals(callback)) { |
151 gpu_switch_callbacks_.erase(gpu_switch_callbacks_.begin() + i); | 140 gpu_switch_callbacks_.erase(gpu_switch_callbacks_.begin() + i); |
152 return; | 141 return; |
153 } | 142 } |
154 } | 143 } |
155 } | 144 } |
156 | 145 |
157 GPUInfo GpuDataManagerImpl::GetGPUInfo() const { | 146 GPUInfo GpuDataManagerImplPrivate::GetGPUInfo() const { |
158 GPUInfo gpu_info; | 147 return gpu_info_; |
159 { | |
160 base::AutoLock auto_lock(gpu_info_lock_); | |
161 gpu_info = gpu_info_; | |
162 } | |
163 return gpu_info; | |
164 } | 148 } |
165 | 149 |
166 void GpuDataManagerImpl::GetGpuProcessHandles( | 150 void GpuDataManagerImplPrivate::GetGpuProcessHandles( |
167 const GetGpuProcessHandlesCallback& callback) const { | 151 const GpuDataManager::GetGpuProcessHandlesCallback& callback) const { |
168 GpuProcessHost::GetProcessHandles(callback); | 152 GpuProcessHost::GetProcessHandles(callback); |
169 } | 153 } |
170 | 154 |
171 bool GpuDataManagerImpl::GpuAccessAllowed(std::string* reason) const { | 155 bool GpuDataManagerImplPrivate::GpuAccessAllowed( |
156 std::string* reason) const { | |
172 if (use_swiftshader_) | 157 if (use_swiftshader_) |
173 return true; | 158 return true; |
174 | 159 |
175 if (!gpu_info_.gpu_accessible) { | 160 if (!gpu_info_.gpu_accessible) { |
176 if (reason) { | 161 if (reason) { |
177 *reason = "GPU process launch failed."; | 162 *reason = "GPU process launch failed."; |
178 } | 163 } |
179 return false; | 164 return false; |
180 } | 165 } |
181 | 166 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 if (reason) { | 198 if (reason) { |
214 *reason = "All GPU features are blacklisted."; | 199 *reason = "All GPU features are blacklisted."; |
215 } | 200 } |
216 return false; | 201 return false; |
217 #endif | 202 #endif |
218 } | 203 } |
219 | 204 |
220 return true; | 205 return true; |
221 } | 206 } |
222 | 207 |
223 void GpuDataManagerImpl::RequestCompleteGpuInfoIfNeeded() { | 208 void GpuDataManagerImplPrivate::RequestCompleteGpuInfoIfNeeded() { |
224 if (complete_gpu_info_already_requested_ || gpu_info_.finalized) | 209 if (complete_gpu_info_already_requested_ || gpu_info_.finalized) |
225 return; | 210 return; |
226 complete_gpu_info_already_requested_ = true; | 211 complete_gpu_info_already_requested_ = true; |
227 | 212 |
228 GpuProcessHost::SendOnIO( | 213 GpuProcessHost::SendOnIO( |
229 #if defined(OS_WIN) | 214 #if defined(OS_WIN) |
230 GpuProcessHost::GPU_PROCESS_KIND_UNSANDBOXED, | 215 GpuProcessHost::GPU_PROCESS_KIND_UNSANDBOXED, |
231 #else | 216 #else |
232 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | 217 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
233 #endif | 218 #endif |
234 CAUSE_FOR_GPU_LAUNCH_GPUDATAMANAGER_REQUESTCOMPLETEGPUINFOIFNEEDED, | 219 CAUSE_FOR_GPU_LAUNCH_GPUDATAMANAGER_REQUESTCOMPLETEGPUINFOIFNEEDED, |
235 new GpuMsg_CollectGraphicsInfo()); | 220 new GpuMsg_CollectGraphicsInfo()); |
236 } | 221 } |
237 | 222 |
238 bool GpuDataManagerImpl::IsCompleteGpuInfoAvailable() const { | 223 bool GpuDataManagerImplPrivate::IsCompleteGpuInfoAvailable() const { |
239 return gpu_info_.finalized; | 224 return gpu_info_.finalized; |
240 } | 225 } |
241 | 226 |
242 void GpuDataManagerImpl::RequestVideoMemoryUsageStatsUpdate() const { | 227 void GpuDataManagerImplPrivate::RequestVideoMemoryUsageStatsUpdate() const { |
243 GpuProcessHost::SendOnIO( | 228 GpuProcessHost::SendOnIO( |
244 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | 229 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
245 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, | 230 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, |
246 new GpuMsg_GetVideoMemoryUsageStats()); | 231 new GpuMsg_GetVideoMemoryUsageStats()); |
247 } | 232 } |
248 | 233 |
249 bool GpuDataManagerImpl::ShouldUseSwiftShader() const { | 234 bool GpuDataManagerImplPrivate::ShouldUseSwiftShader() const { |
250 return use_swiftshader_; | 235 return use_swiftshader_; |
251 } | 236 } |
252 | 237 |
253 void GpuDataManagerImpl::RegisterSwiftShaderPath(const base::FilePath& path) { | 238 void GpuDataManagerImplPrivate::RegisterSwiftShaderPath( |
239 const base::FilePath& path) { | |
254 swiftshader_path_ = path; | 240 swiftshader_path_ = path; |
255 EnableSwiftShaderIfNecessary(); | 241 EnableSwiftShaderIfNecessary(); |
256 } | 242 } |
257 | 243 |
258 void GpuDataManagerImpl::AddObserver(GpuDataManagerObserver* observer) { | 244 void GpuDataManagerImplPrivate::AddObserver(GpuDataManagerObserver* observer) { |
259 observer_list_->AddObserver(observer); | 245 observer_list_->AddObserver(observer); |
260 } | 246 } |
261 | 247 |
262 void GpuDataManagerImpl::RemoveObserver(GpuDataManagerObserver* observer) { | 248 void GpuDataManagerImplPrivate::RemoveObserver( |
249 GpuDataManagerObserver* observer) { | |
263 observer_list_->RemoveObserver(observer); | 250 observer_list_->RemoveObserver(observer); |
264 } | 251 } |
265 | 252 |
266 void GpuDataManagerImpl::UnblockDomainFrom3DAPIs(const GURL& url) { | 253 void GpuDataManagerImplPrivate::UnblockDomainFrom3DAPIs(const GURL& url) { |
267 // This method must do two things: | 254 // This method must do two things: |
268 // | 255 // |
269 // 1. If the specific domain is blocked, then unblock it. | 256 // 1. If the specific domain is blocked, then unblock it. |
270 // | 257 // |
271 // 2. Reset our notion of how many GPU resets have occurred recently. | 258 // 2. Reset our notion of how many GPU resets have occurred recently. |
272 // This is necessary even if the specific domain was blocked. | 259 // This is necessary even if the specific domain was blocked. |
273 // Otherwise, if we call Are3DAPIsBlocked with the same domain right | 260 // Otherwise, if we call Are3DAPIsBlocked with the same domain right |
274 // after unblocking it, it will probably still be blocked because of | 261 // after unblocking it, it will probably still be blocked because of |
275 // the recent GPU reset caused by that domain. | 262 // the recent GPU reset caused by that domain. |
276 // | 263 // |
277 // These policies could be refined, but at a certain point the behavior | 264 // These policies could be refined, but at a certain point the behavior |
278 // will become difficult to explain. | 265 // will become difficult to explain. |
279 std::string domain = GetDomainFromURL(url); | 266 std::string domain = GetDomainFromURL(url); |
280 | 267 |
281 base::AutoLock auto_lock(gpu_info_lock_); | |
282 blocked_domains_.erase(domain); | 268 blocked_domains_.erase(domain); |
283 timestamps_of_gpu_resets_.clear(); | 269 timestamps_of_gpu_resets_.clear(); |
284 } | 270 } |
285 | 271 |
286 void GpuDataManagerImpl::DisableGpuWatchdog() { | 272 void GpuDataManagerImplPrivate::DisableGpuWatchdog() { |
287 GpuProcessHost::SendOnIO( | 273 GpuProcessHost::SendOnIO( |
288 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | 274 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
289 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, | 275 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, |
290 new GpuMsg_DisableWatchdog); | 276 new GpuMsg_DisableWatchdog); |
291 } | 277 } |
292 | 278 |
293 void GpuDataManagerImpl::SetGLStrings(const std::string& gl_vendor, | 279 void GpuDataManagerImplPrivate::SetGLStrings(const std::string& gl_vendor, |
294 const std::string& gl_renderer, | 280 const std::string& gl_renderer, |
295 const std::string& gl_version) { | 281 const std::string& gl_version) { |
296 if (gl_vendor.empty() && gl_renderer.empty() && gl_version.empty()) | 282 if (gl_vendor.empty() && gl_renderer.empty() && gl_version.empty()) |
297 return; | 283 return; |
298 | 284 |
299 GPUInfo gpu_info; | 285 // If GPUInfo already got GL strings, do nothing. This is for the rare |
300 { | 286 // situation where GPU process collected GL strings before this call. |
301 base::AutoLock auto_lock(gpu_info_lock_); | 287 if (!gpu_info_.gl_vendor.empty() || |
302 // If GPUInfo already got GL strings, do nothing. This is for the rare | 288 !gpu_info_.gl_renderer.empty() || |
303 // situation where GPU process collected GL strings before this call. | 289 !gpu_info_.gl_version_string.empty()) |
304 if (!gpu_info_.gl_vendor.empty() || | 290 return; |
305 !gpu_info_.gl_renderer.empty() || | 291 |
306 !gpu_info_.gl_version_string.empty()) | 292 GPUInfo gpu_info = gpu_info_; |
307 return; | |
308 gpu_info = gpu_info_; | |
309 } | |
310 | 293 |
311 gpu_info.gl_vendor = gl_vendor; | 294 gpu_info.gl_vendor = gl_vendor; |
312 gpu_info.gl_renderer = gl_renderer; | 295 gpu_info.gl_renderer = gl_renderer; |
313 gpu_info.gl_version_string = gl_version; | 296 gpu_info.gl_version_string = gl_version; |
314 | 297 |
315 gpu_info_collector::CollectDriverInfoGL(&gpu_info); | 298 gpu_info_collector::CollectDriverInfoGL(&gpu_info); |
316 | 299 |
317 UpdateGpuInfo(gpu_info); | 300 UpdateGpuInfo(gpu_info); |
318 UpdateGpuSwitchingManager(gpu_info); | 301 UpdateGpuSwitchingManager(gpu_info); |
319 UpdatePreliminaryBlacklistedFeatures(); | 302 UpdatePreliminaryBlacklistedFeatures(); |
320 } | 303 } |
321 | 304 |
322 void GpuDataManagerImpl::GetGLStrings(std::string* gl_vendor, | 305 void GpuDataManagerImplPrivate::GetGLStrings(std::string* gl_vendor, |
323 std::string* gl_renderer, | 306 std::string* gl_renderer, |
324 std::string* gl_version) { | 307 std::string* gl_version) { |
325 DCHECK(gl_vendor && gl_renderer && gl_version); | 308 DCHECK(gl_vendor && gl_renderer && gl_version); |
326 | 309 |
327 base::AutoLock auto_lock(gpu_info_lock_); | |
328 *gl_vendor = gpu_info_.gl_vendor; | 310 *gl_vendor = gpu_info_.gl_vendor; |
329 *gl_renderer = gpu_info_.gl_renderer; | 311 *gl_renderer = gpu_info_.gl_renderer; |
330 *gl_version = gpu_info_.gl_version_string; | 312 *gl_version = gpu_info_.gl_version_string; |
331 } | 313 } |
332 | 314 |
333 | 315 void GpuDataManagerImplPrivate::Initialize() { |
334 void GpuDataManagerImpl::Initialize() { | |
335 TRACE_EVENT0("startup", "GpuDataManagerImpl::Initialize"); | 316 TRACE_EVENT0("startup", "GpuDataManagerImpl::Initialize"); |
336 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 317 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
337 if (command_line->HasSwitch(switches::kSkipGpuDataLoading)) | 318 if (command_line->HasSwitch(switches::kSkipGpuDataLoading)) |
338 return; | 319 return; |
339 | 320 |
340 GPUInfo gpu_info; | 321 GPUInfo gpu_info; |
341 { | 322 { |
342 TRACE_EVENT0("startup", | 323 TRACE_EVENT0("startup", |
343 "GpuDataManagerImpl::Initialize:CollectBasicGraphicsInfo"); | 324 "GpuDataManagerImpl::Initialize:CollectBasicGraphicsInfo"); |
344 gpu_info_collector::CollectBasicGraphicsInfo(&gpu_info); | 325 gpu_info_collector::CollectBasicGraphicsInfo(&gpu_info); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 // have a GPU process, we append the browser process commandline. | 357 // have a GPU process, we append the browser process commandline. |
377 if (command_line->HasSwitch(switches::kSingleProcess) || | 358 if (command_line->HasSwitch(switches::kSingleProcess) || |
378 command_line->HasSwitch(switches::kInProcessGPU)) { | 359 command_line->HasSwitch(switches::kInProcessGPU)) { |
379 if (!gpu_driver_bugs_.empty()) { | 360 if (!gpu_driver_bugs_.empty()) { |
380 command_line->AppendSwitchASCII(switches::kGpuDriverBugWorkarounds, | 361 command_line->AppendSwitchASCII(switches::kGpuDriverBugWorkarounds, |
381 IntSetToString(gpu_driver_bugs_)); | 362 IntSetToString(gpu_driver_bugs_)); |
382 } | 363 } |
383 } | 364 } |
384 } | 365 } |
385 | 366 |
386 void GpuDataManagerImpl::UpdateGpuInfo(const GPUInfo& gpu_info) { | 367 void GpuDataManagerImplPrivate::UpdateGpuInfo(const GPUInfo& gpu_info) { |
387 // No further update of gpu_info if falling back to SwiftShader. | 368 // No further update of gpu_info if falling back to SwiftShader. |
388 if (use_swiftshader_) | 369 if (use_swiftshader_) |
389 return; | 370 return; |
390 | 371 |
391 GPUInfo my_gpu_info; | 372 gpu_info_collector::MergeGPUInfo(&gpu_info_, gpu_info); |
392 { | 373 complete_gpu_info_already_requested_ = |
393 base::AutoLock auto_lock(gpu_info_lock_); | 374 complete_gpu_info_already_requested_ || gpu_info_.finalized; |
394 gpu_info_collector::MergeGPUInfo(&gpu_info_, gpu_info); | |
395 complete_gpu_info_already_requested_ = | |
396 complete_gpu_info_already_requested_ || gpu_info_.finalized; | |
397 my_gpu_info = gpu_info_; | |
398 } | |
399 | 375 |
400 GetContentClient()->SetGpuInfo(my_gpu_info); | 376 GetContentClient()->SetGpuInfo(gpu_info_); |
401 | 377 |
402 if (gpu_blacklist_) { | 378 if (gpu_blacklist_) { |
403 std::set<int> features = gpu_blacklist_->MakeDecision( | 379 std::set<int> features = gpu_blacklist_->MakeDecision( |
404 GpuControlList::kOsAny, std::string(), my_gpu_info); | 380 GpuControlList::kOsAny, std::string(), gpu_info_); |
405 if (update_histograms_) | 381 if (update_histograms_) |
406 UpdateStats(gpu_blacklist_.get(), features); | 382 UpdateStats(gpu_blacklist_.get(), features); |
407 | 383 |
408 UpdateBlacklistedFeatures(features); | 384 UpdateBlacklistedFeatures(features); |
409 } | 385 } |
410 if (gpu_switching_list_) { | 386 if (gpu_switching_list_) { |
411 std::set<int> option = gpu_switching_list_->MakeDecision( | 387 std::set<int> option = gpu_switching_list_->MakeDecision( |
412 GpuControlList::kOsAny, std::string(), my_gpu_info); | 388 GpuControlList::kOsAny, std::string(), gpu_info_); |
413 if (option.size() == 1) { | 389 if (option.size() == 1) { |
414 // Blacklist decision should not overwrite commandline switch from users. | 390 // Blacklist decision should not overwrite commandline switch from users. |
415 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 391 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
416 if (!command_line->HasSwitch(switches::kGpuSwitching)) | 392 if (!command_line->HasSwitch(switches::kGpuSwitching)) |
417 gpu_switching_ = static_cast<GpuSwitchingOption>(*(option.begin())); | 393 gpu_switching_ = static_cast<GpuSwitchingOption>(*(option.begin())); |
418 } | 394 } |
419 } | 395 } |
420 if (gpu_driver_bug_list_) | 396 if (gpu_driver_bug_list_) |
421 gpu_driver_bugs_ = gpu_driver_bug_list_->MakeDecision( | 397 gpu_driver_bugs_ = gpu_driver_bug_list_->MakeDecision( |
422 GpuControlList::kOsAny, std::string(), my_gpu_info); | 398 GpuControlList::kOsAny, std::string(), gpu_info_); |
423 | 399 |
424 // We have to update GpuFeatureType before notify all the observers. | 400 // We have to update GpuFeatureType before notify all the observers. |
425 NotifyGpuInfoUpdate(); | 401 NotifyGpuInfoUpdate(); |
426 } | 402 } |
427 | 403 |
428 void GpuDataManagerImpl::UpdateVideoMemoryUsageStats( | 404 void GpuDataManagerImplPrivate::UpdateVideoMemoryUsageStats( |
429 const GPUVideoMemoryUsageStats& video_memory_usage_stats) { | 405 const GPUVideoMemoryUsageStats& video_memory_usage_stats) { |
430 observer_list_->Notify(&GpuDataManagerObserver::OnVideoMemoryUsageStatsUpdate, | 406 observer_list_->Notify(&GpuDataManagerObserver::OnVideoMemoryUsageStatsUpdate, |
431 video_memory_usage_stats); | 407 video_memory_usage_stats); |
432 } | 408 } |
433 | 409 |
434 void GpuDataManagerImpl::AppendRendererCommandLine( | 410 void GpuDataManagerImplPrivate::AppendRendererCommandLine( |
435 CommandLine* command_line) const { | 411 CommandLine* command_line) const { |
436 DCHECK(command_line); | 412 DCHECK(command_line); |
437 | 413 |
438 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)) { | 414 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)) { |
439 #if !defined(OS_ANDROID) | 415 #if !defined(OS_ANDROID) |
440 if (!command_line->HasSwitch(switches::kDisableExperimentalWebGL)) | 416 if (!command_line->HasSwitch(switches::kDisableExperimentalWebGL)) |
441 command_line->AppendSwitch(switches::kDisableExperimentalWebGL); | 417 command_line->AppendSwitch(switches::kDisableExperimentalWebGL); |
442 #endif | 418 #endif |
443 if (!command_line->HasSwitch(switches::kDisablePepper3d)) | 419 if (!command_line->HasSwitch(switches::kDisablePepper3d)) |
444 command_line->AppendSwitch(switches::kDisablePepper3d); | 420 command_line->AppendSwitch(switches::kDisablePepper3d); |
445 } | 421 } |
446 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_MULTISAMPLING) && | 422 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_MULTISAMPLING) && |
447 !command_line->HasSwitch(switches::kDisableGLMultisampling)) | 423 !command_line->HasSwitch(switches::kDisableGLMultisampling)) |
448 command_line->AppendSwitch(switches::kDisableGLMultisampling); | 424 command_line->AppendSwitch(switches::kDisableGLMultisampling); |
449 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) && | 425 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) && |
450 !command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) | 426 !command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) |
451 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); | 427 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); |
452 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS) && | 428 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS) && |
453 !command_line->HasSwitch(switches::kDisableAccelerated2dCanvas)) | 429 !command_line->HasSwitch(switches::kDisableAccelerated2dCanvas)) |
454 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); | 430 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); |
455 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE) && | 431 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE) && |
456 !command_line->HasSwitch(switches::kDisableAcceleratedVideoDecode)) | 432 !command_line->HasSwitch(switches::kDisableAcceleratedVideoDecode)) |
457 command_line->AppendSwitch(switches::kDisableAcceleratedVideoDecode); | 433 command_line->AppendSwitch(switches::kDisableAcceleratedVideoDecode); |
458 if (ShouldUseSwiftShader()) | 434 if (ShouldUseSwiftShader()) |
459 command_line->AppendSwitch(switches::kDisableFlashFullscreen3d); | 435 command_line->AppendSwitch(switches::kDisableFlashFullscreen3d); |
460 } | 436 } |
461 | 437 |
462 void GpuDataManagerImpl::AppendGpuCommandLine( | 438 void GpuDataManagerImplPrivate::AppendGpuCommandLine( |
463 CommandLine* command_line) const { | 439 CommandLine* command_line) const { |
464 DCHECK(command_line); | 440 DCHECK(command_line); |
465 | 441 |
466 std::string use_gl = | 442 std::string use_gl = |
467 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); | 443 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); |
468 base::FilePath swiftshader_path = | 444 base::FilePath swiftshader_path = |
469 CommandLine::ForCurrentProcess()->GetSwitchValuePath( | 445 CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
470 switches::kSwiftShaderPath); | 446 switches::kSwiftShaderPath); |
471 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_MULTISAMPLING) && | 447 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_MULTISAMPLING) && |
472 !command_line->HasSwitch(switches::kDisableGLMultisampling)) | 448 !command_line->HasSwitch(switches::kDisableGLMultisampling)) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 // http://crbug.com/177611 | 496 // http://crbug.com/177611 |
521 // Thinkpad USB Port Replicator driver causes GPU process to crash when the | 497 // Thinkpad USB Port Replicator driver causes GPU process to crash when the |
522 // sandbox is enabled. http://crbug.com/181665. | 498 // sandbox is enabled. http://crbug.com/181665. |
523 if ((gpu_info_.display_link_version.IsValid() | 499 if ((gpu_info_.display_link_version.IsValid() |
524 && gpu_info_.display_link_version.IsOlderThan("7.2")) || | 500 && gpu_info_.display_link_version.IsOlderThan("7.2")) || |
525 gpu_info_.lenovo_dcute) { | 501 gpu_info_.lenovo_dcute) { |
526 command_line->AppendSwitch(switches::kReduceGpuSandbox); | 502 command_line->AppendSwitch(switches::kReduceGpuSandbox); |
527 } | 503 } |
528 #endif | 504 #endif |
529 | 505 |
530 { | 506 if (gpu_info_.optimus) |
531 base::AutoLock auto_lock(gpu_info_lock_); | 507 command_line->AppendSwitch(switches::kReduceGpuSandbox); |
532 if (gpu_info_.optimus) | 508 if (gpu_info_.amd_switchable) { |
533 command_line->AppendSwitch(switches::kReduceGpuSandbox); | 509 // The image transport surface currently doesn't work with AMD Dynamic |
534 if (gpu_info_.amd_switchable) { | 510 // Switchable graphics. |
535 // The image transport surface currently doesn't work with AMD Dynamic | 511 command_line->AppendSwitch(switches::kReduceGpuSandbox); |
536 // Switchable graphics. | 512 command_line->AppendSwitch(switches::kDisableImageTransportSurface); |
537 command_line->AppendSwitch(switches::kReduceGpuSandbox); | |
538 command_line->AppendSwitch(switches::kDisableImageTransportSurface); | |
539 } | |
540 // Pass GPU and driver information to GPU process. We try to avoid full GPU | |
541 // info collection at GPU process startup, but we need gpu vendor_id, | |
542 // device_id, driver_vendor, driver_version for deciding whether we need to | |
543 // collect full info (on Linux) and for crash reporting purpose. | |
544 command_line->AppendSwitchASCII(switches::kGpuVendorID, | |
545 base::StringPrintf("0x%04x", gpu_info_.gpu.vendor_id)); | |
546 command_line->AppendSwitchASCII(switches::kGpuDeviceID, | |
547 base::StringPrintf("0x%04x", gpu_info_.gpu.device_id)); | |
548 command_line->AppendSwitchASCII(switches::kGpuDriverVendor, | |
549 gpu_info_.driver_vendor); | |
550 command_line->AppendSwitchASCII(switches::kGpuDriverVersion, | |
551 gpu_info_.driver_version); | |
552 } | 513 } |
514 // Pass GPU and driver information to GPU process. We try to avoid full GPU | |
515 // info collection at GPU process startup, but we need gpu vendor_id, | |
516 // device_id, driver_vendor, driver_version for deciding whether we need to | |
517 // collect full info (on Linux) and for crash reporting purpose. | |
518 command_line->AppendSwitchASCII(switches::kGpuVendorID, | |
519 base::StringPrintf("0x%04x", gpu_info_.gpu.vendor_id)); | |
520 command_line->AppendSwitchASCII(switches::kGpuDeviceID, | |
521 base::StringPrintf("0x%04x", gpu_info_.gpu.device_id)); | |
522 command_line->AppendSwitchASCII(switches::kGpuDriverVendor, | |
523 gpu_info_.driver_vendor); | |
524 command_line->AppendSwitchASCII(switches::kGpuDriverVersion, | |
525 gpu_info_.driver_version); | |
553 } | 526 } |
554 | 527 |
555 void GpuDataManagerImpl::AppendPluginCommandLine( | 528 void GpuDataManagerImplPrivate::AppendPluginCommandLine( |
556 CommandLine* command_line) const { | 529 CommandLine* command_line) const { |
557 DCHECK(command_line); | 530 DCHECK(command_line); |
558 | 531 |
559 #if defined(OS_MACOSX) | 532 #if defined(OS_MACOSX) |
560 // TODO(jbauman): Add proper blacklist support for core animation plugins so | 533 // TODO(jbauman): Add proper blacklist support for core animation plugins so |
561 // special-casing this video card won't be necessary. See | 534 // special-casing this video card won't be necessary. See |
562 // http://crbug.com/134015 | 535 // http://crbug.com/134015 |
563 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) || | 536 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) || |
564 CommandLine::ForCurrentProcess()->HasSwitch( | 537 CommandLine::ForCurrentProcess()->HasSwitch( |
565 switches::kDisableAcceleratedCompositing)) { | 538 switches::kDisableAcceleratedCompositing)) { |
566 if (!command_line->HasSwitch( | 539 if (!command_line->HasSwitch( |
567 switches::kDisableCoreAnimationPlugins)) | 540 switches::kDisableCoreAnimationPlugins)) |
568 command_line->AppendSwitch( | 541 command_line->AppendSwitch( |
569 switches::kDisableCoreAnimationPlugins); | 542 switches::kDisableCoreAnimationPlugins); |
570 } | 543 } |
571 #endif | 544 #endif |
572 } | 545 } |
573 | 546 |
574 void GpuDataManagerImpl::UpdateRendererWebPrefs(WebPreferences* prefs) const { | 547 void GpuDataManagerImplPrivate::UpdateRendererWebPrefs( |
548 WebPreferences* prefs) const { | |
575 DCHECK(prefs); | 549 DCHECK(prefs); |
576 | 550 |
577 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)) | 551 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)) |
578 prefs->accelerated_compositing_enabled = false; | 552 prefs->accelerated_compositing_enabled = false; |
579 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)) | 553 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)) |
580 prefs->experimental_webgl_enabled = false; | 554 prefs->experimental_webgl_enabled = false; |
581 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_FLASH3D)) | 555 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_FLASH3D)) |
582 prefs->flash_3d_enabled = false; | 556 prefs->flash_3d_enabled = false; |
583 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_FLASH_STAGE3D)) { | 557 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_FLASH_STAGE3D)) { |
584 prefs->flash_stage3d_enabled = false; | 558 prefs->flash_stage3d_enabled = false; |
(...skipping 15 matching lines...) Expand all Loading... | |
600 // Accelerated video and animation are slower than regular when using | 574 // Accelerated video and animation are slower than regular when using |
601 // SwiftShader. 3D CSS may also be too slow to be worthwhile. | 575 // SwiftShader. 3D CSS may also be too slow to be worthwhile. |
602 if (ShouldUseSwiftShader()) { | 576 if (ShouldUseSwiftShader()) { |
603 prefs->accelerated_compositing_for_video_enabled = false; | 577 prefs->accelerated_compositing_for_video_enabled = false; |
604 prefs->accelerated_compositing_for_animation_enabled = false; | 578 prefs->accelerated_compositing_for_animation_enabled = false; |
605 prefs->accelerated_compositing_for_3d_transforms_enabled = false; | 579 prefs->accelerated_compositing_for_3d_transforms_enabled = false; |
606 prefs->accelerated_compositing_for_plugins_enabled = false; | 580 prefs->accelerated_compositing_for_plugins_enabled = false; |
607 } | 581 } |
608 } | 582 } |
609 | 583 |
610 GpuSwitchingOption GpuDataManagerImpl::GetGpuSwitchingOption() const { | 584 GpuSwitchingOption GpuDataManagerImplPrivate::GetGpuSwitchingOption() const { |
611 if (!ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) | 585 if (!ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) |
612 return GPU_SWITCHING_OPTION_UNKNOWN; | 586 return GPU_SWITCHING_OPTION_UNKNOWN; |
613 return gpu_switching_; | 587 return gpu_switching_; |
614 } | 588 } |
615 | 589 |
616 void GpuDataManagerImpl::DisableHardwareAcceleration() { | 590 void GpuDataManagerImplPrivate::DisableHardwareAcceleration() { |
617 card_blacklisted_ = true; | 591 card_blacklisted_ = true; |
618 | 592 |
619 for (int i = 0; i < NUMBER_OF_GPU_FEATURE_TYPES; ++i) | 593 for (int i = 0; i < NUMBER_OF_GPU_FEATURE_TYPES; ++i) |
620 blacklisted_features_.insert(i); | 594 blacklisted_features_.insert(i); |
621 | 595 |
622 EnableSwiftShaderIfNecessary(); | 596 EnableSwiftShaderIfNecessary(); |
623 NotifyGpuInfoUpdate(); | 597 NotifyGpuInfoUpdate(); |
624 } | 598 } |
625 | 599 |
626 std::string GpuDataManagerImpl::GetBlacklistVersion() const { | 600 std::string GpuDataManagerImplPrivate::GetBlacklistVersion() const { |
627 if (gpu_blacklist_) | 601 if (gpu_blacklist_) |
628 return gpu_blacklist_->version(); | 602 return gpu_blacklist_->version(); |
629 return "0"; | 603 return "0"; |
630 } | 604 } |
631 | 605 |
632 base::ListValue* GpuDataManagerImpl::GetBlacklistReasons() const { | 606 base::ListValue* GpuDataManagerImplPrivate::GetBlacklistReasons() const { |
633 ListValue* reasons = new ListValue(); | 607 ListValue* reasons = new ListValue(); |
634 if (gpu_blacklist_) | 608 if (gpu_blacklist_) |
635 gpu_blacklist_->GetReasons(reasons); | 609 gpu_blacklist_->GetReasons(reasons); |
636 return reasons; | 610 return reasons; |
637 } | 611 } |
638 | 612 |
639 void GpuDataManagerImpl::AddLogMessage( | 613 void GpuDataManagerImplPrivate::AddLogMessage( |
640 int level, const std::string& header, const std::string& message) { | 614 int level, const std::string& header, const std::string& message) { |
641 base::AutoLock auto_lock(log_messages_lock_); | |
642 DictionaryValue* dict = new DictionaryValue(); | 615 DictionaryValue* dict = new DictionaryValue(); |
643 dict->SetInteger("level", level); | 616 dict->SetInteger("level", level); |
644 dict->SetString("header", header); | 617 dict->SetString("header", header); |
645 dict->SetString("message", message); | 618 dict->SetString("message", message); |
646 log_messages_.Append(dict); | 619 log_messages_.Append(dict); |
647 } | 620 } |
648 | 621 |
649 void GpuDataManagerImpl::ProcessCrashed(base::TerminationStatus exit_code) { | 622 void GpuDataManagerImplPrivate::ProcessCrashed( |
623 base::TerminationStatus exit_code) { | |
650 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 624 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
651 BrowserThread::PostTask(BrowserThread::UI, | 625 // This is ok, because observer_list_ is thread-safe, thus |
652 FROM_HERE, | 626 // ProcessCrashed is thread-safe. |
Ken Russell (switch to Gerrit)
2013/05/09 20:21:16
It's hard to reason about the correctness here. Wh
Zhenyao Mo
2013/05/09 23:35:12
Done.
| |
653 base::Bind(&GpuDataManagerImpl::ProcessCrashed, | 627 BrowserThread::PostTask( |
654 base::Unretained(this), | 628 BrowserThread::UI, |
655 exit_code)); | 629 FROM_HERE, |
630 base::Bind(&GpuDataManagerImplPrivate::ProcessCrashed, | |
631 base::Unretained(this), | |
632 exit_code)); | |
656 return; | 633 return; |
657 } | 634 } |
658 observer_list_->Notify(&GpuDataManagerObserver::OnGpuProcessCrashed, | 635 observer_list_->Notify(&GpuDataManagerObserver::OnGpuProcessCrashed, |
659 exit_code); | 636 exit_code); |
660 } | 637 } |
661 | 638 |
662 base::ListValue* GpuDataManagerImpl::GetLogMessages() const { | 639 base::ListValue* GpuDataManagerImplPrivate::GetLogMessages() const { |
663 base::ListValue* value; | 640 base::ListValue* value; |
664 { | 641 value = log_messages_.DeepCopy(); |
665 base::AutoLock auto_lock(log_messages_lock_); | |
666 value = log_messages_.DeepCopy(); | |
667 } | |
668 return value; | 642 return value; |
669 } | 643 } |
670 | 644 |
671 void GpuDataManagerImpl::HandleGpuSwitch() { | 645 void GpuDataManagerImplPrivate::HandleGpuSwitch() { |
672 complete_gpu_info_already_requested_ = false; | 646 complete_gpu_info_already_requested_ = false; |
673 gpu_info_.finalized = false; | 647 gpu_info_.finalized = false; |
674 for (size_t i = 0; i < gpu_switch_callbacks_.size(); ++i) | 648 for (size_t i = 0; i < gpu_switch_callbacks_.size(); ++i) |
675 gpu_switch_callbacks_[i].Run(); | 649 gpu_switch_callbacks_[i].Run(); |
676 } | 650 } |
677 | 651 |
678 #if defined(OS_WIN) | 652 #if defined(OS_WIN) |
679 bool GpuDataManagerImpl::IsUsingAcceleratedSurface() const { | 653 bool GpuDataManagerImplPrivate::IsUsingAcceleratedSurface() const { |
680 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 654 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
681 return false; | 655 return false; |
682 | 656 |
683 if (gpu_info_.amd_switchable) | 657 if (gpu_info_.amd_switchable) |
684 return false; | 658 return false; |
685 if (use_swiftshader_) | 659 if (use_swiftshader_) |
686 return false; | 660 return false; |
687 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 661 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
688 if (command_line->HasSwitch(switches::kDisableImageTransportSurface)) | 662 if (command_line->HasSwitch(switches::kDisableImageTransportSurface)) |
689 return false; | 663 return false; |
690 return !IsFeatureBlacklisted(GPU_FEATURE_TYPE_TEXTURE_SHARING); | 664 return !IsFeatureBlacklisted(GPU_FEATURE_TYPE_TEXTURE_SHARING); |
691 } | 665 } |
692 #endif | 666 #endif |
693 | 667 |
694 void GpuDataManagerImpl::BlockDomainFrom3DAPIs( | 668 void GpuDataManagerImplPrivate::BlockDomainFrom3DAPIs( |
695 const GURL& url, DomainGuilt guilt) { | 669 const GURL& url, GpuDataManagerImpl::DomainGuilt guilt) { |
696 BlockDomainFrom3DAPIsAtTime(url, guilt, base::Time::Now()); | 670 BlockDomainFrom3DAPIsAtTime(url, guilt, base::Time::Now()); |
697 } | 671 } |
698 | 672 |
699 bool GpuDataManagerImpl::Are3DAPIsBlocked(const GURL& url, | 673 bool GpuDataManagerImplPrivate::Are3DAPIsBlocked(const GURL& url, |
700 int render_process_id, | 674 int render_process_id, |
701 int render_view_id, | 675 int render_view_id, |
702 ThreeDAPIType requester) { | 676 ThreeDAPIType requester) { |
703 bool blocked = Are3DAPIsBlockedAtTime(url, base::Time::Now()) != | 677 bool blocked = Are3DAPIsBlockedAtTime(url, base::Time::Now()) != |
704 GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED; | 678 GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED; |
705 if (blocked) { | 679 if (blocked) { |
680 // This is ok, because observer_list_ is thread-safe, thus | |
681 // Notify3DAPIBlocked is thread-safe. | |
Ken Russell (switch to Gerrit)
2013/05/09 20:21:16
Same observation here.
Zhenyao Mo
2013/05/09 23:35:12
Done.
| |
706 BrowserThread::PostTask( | 682 BrowserThread::PostTask( |
707 BrowserThread::UI, FROM_HERE, | 683 BrowserThread::UI, FROM_HERE, |
708 base::Bind(&GpuDataManagerImpl::Notify3DAPIBlocked, | 684 base::Bind(&GpuDataManagerImplPrivate::Notify3DAPIBlocked, |
709 base::Unretained(this), url, render_process_id, | 685 base::Unretained(this), url, render_process_id, |
710 render_view_id, requester)); | 686 render_view_id, requester)); |
711 } | 687 } |
712 | 688 |
713 return blocked; | 689 return blocked; |
714 } | 690 } |
715 | 691 |
716 void GpuDataManagerImpl::DisableDomainBlockingFor3DAPIsForTesting() { | 692 void GpuDataManagerImplPrivate::DisableDomainBlockingFor3DAPIsForTesting() { |
717 domain_blocking_enabled_ = false; | 693 domain_blocking_enabled_ = false; |
718 } | 694 } |
719 | 695 |
720 GpuDataManagerImpl::GpuDataManagerImpl() | 696 GpuDataManagerImplPrivate::GpuDataManagerImplPrivate() |
721 : complete_gpu_info_already_requested_(false), | 697 : complete_gpu_info_already_requested_(false), |
722 gpu_switching_(GPU_SWITCHING_OPTION_AUTOMATIC), | 698 gpu_switching_(GPU_SWITCHING_OPTION_AUTOMATIC), |
723 observer_list_(new GpuDataManagerObserverList), | 699 observer_list_(new GpuDataManagerObserverList), |
724 use_swiftshader_(false), | 700 use_swiftshader_(false), |
725 card_blacklisted_(false), | 701 card_blacklisted_(false), |
726 update_histograms_(true), | 702 update_histograms_(true), |
727 window_count_(0), | 703 window_count_(0), |
728 domain_blocking_enabled_(true) { | 704 domain_blocking_enabled_(true) { |
729 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 705 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
730 if (command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) { | 706 if (command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) { |
731 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); | 707 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); |
732 command_line->AppendSwitch(switches::kDisableAcceleratedLayers); | 708 command_line->AppendSwitch(switches::kDisableAcceleratedLayers); |
733 } | 709 } |
734 if (command_line->HasSwitch(switches::kDisableGpu)) | 710 if (command_line->HasSwitch(switches::kDisableGpu)) |
735 DisableHardwareAcceleration(); | 711 DisableHardwareAcceleration(); |
736 if (command_line->HasSwitch(switches::kGpuSwitching)) { | 712 if (command_line->HasSwitch(switches::kGpuSwitching)) { |
737 std::string option_string = command_line->GetSwitchValueASCII( | 713 std::string option_string = command_line->GetSwitchValueASCII( |
738 switches::kGpuSwitching); | 714 switches::kGpuSwitching); |
739 GpuSwitchingOption option = StringToGpuSwitchingOption(option_string); | 715 GpuSwitchingOption option = StringToGpuSwitchingOption(option_string); |
740 if (option != GPU_SWITCHING_OPTION_UNKNOWN) | 716 if (option != GPU_SWITCHING_OPTION_UNKNOWN) |
741 gpu_switching_ = option; | 717 gpu_switching_ = option; |
742 } | 718 } |
743 | 719 |
744 #if defined(OS_MACOSX) | 720 #if defined(OS_MACOSX) |
745 CGDisplayRegisterReconfigurationCallback(DisplayReconfigCallback, this); | 721 CGDisplayRegisterReconfigurationCallback(DisplayReconfigCallback, this); |
746 #endif // OS_MACOSX | 722 #endif // OS_MACOSX |
747 } | 723 } |
748 | 724 |
749 GpuDataManagerImpl::~GpuDataManagerImpl() { | 725 GpuDataManagerImplPrivate::~GpuDataManagerImplPrivate() { |
750 #if defined(OS_MACOSX) | 726 #if defined(OS_MACOSX) |
751 CGDisplayRemoveReconfigurationCallback(DisplayReconfigCallback, this); | 727 CGDisplayRemoveReconfigurationCallback(DisplayReconfigCallback, this); |
752 #endif | 728 #endif |
753 } | 729 } |
754 | 730 |
755 void GpuDataManagerImpl::InitializeImpl( | 731 void GpuDataManagerImplPrivate::InitializeImpl( |
756 const std::string& gpu_blacklist_json, | 732 const std::string& gpu_blacklist_json, |
757 const std::string& gpu_switching_list_json, | 733 const std::string& gpu_switching_list_json, |
758 const std::string& gpu_driver_bug_list_json, | 734 const std::string& gpu_driver_bug_list_json, |
759 const GPUInfo& gpu_info) { | 735 const GPUInfo& gpu_info) { |
760 std::string browser_version_string = ProcessVersionString( | 736 std::string browser_version_string = ProcessVersionString( |
761 GetContentClient()->GetProduct()); | 737 GetContentClient()->GetProduct()); |
762 CHECK(!browser_version_string.empty()); | 738 CHECK(!browser_version_string.empty()); |
763 | 739 |
764 if (!gpu_blacklist_json.empty()) { | 740 if (!gpu_blacklist_json.empty()) { |
765 gpu_blacklist_.reset(GpuBlacklist::Create()); | 741 gpu_blacklist_.reset(GpuBlacklist::Create()); |
766 gpu_blacklist_->LoadList( | 742 gpu_blacklist_->LoadList( |
767 browser_version_string, gpu_blacklist_json, | 743 browser_version_string, gpu_blacklist_json, |
768 GpuControlList::kCurrentOsOnly); | 744 GpuControlList::kCurrentOsOnly); |
769 } | 745 } |
770 if (!gpu_switching_list_json.empty()) { | 746 if (!gpu_switching_list_json.empty()) { |
771 gpu_switching_list_.reset(GpuSwitchingList::Create()); | 747 gpu_switching_list_.reset(GpuSwitchingList::Create()); |
772 gpu_switching_list_->LoadList( | 748 gpu_switching_list_->LoadList( |
773 browser_version_string, gpu_switching_list_json, | 749 browser_version_string, gpu_switching_list_json, |
774 GpuControlList::kCurrentOsOnly); | 750 GpuControlList::kCurrentOsOnly); |
775 } | 751 } |
776 if (!gpu_driver_bug_list_json.empty()) { | 752 if (!gpu_driver_bug_list_json.empty()) { |
777 gpu_driver_bug_list_.reset(GpuDriverBugList::Create()); | 753 gpu_driver_bug_list_.reset(GpuDriverBugList::Create()); |
778 gpu_driver_bug_list_->LoadList( | 754 gpu_driver_bug_list_->LoadList( |
779 browser_version_string, gpu_driver_bug_list_json, | 755 browser_version_string, gpu_driver_bug_list_json, |
780 GpuControlList::kCurrentOsOnly); | 756 GpuControlList::kCurrentOsOnly); |
781 } | 757 } |
782 | 758 |
783 { | 759 gpu_info_ = gpu_info; |
784 base::AutoLock auto_lock(gpu_info_lock_); | |
785 gpu_info_ = gpu_info; | |
786 } | |
787 UpdateGpuInfo(gpu_info); | 760 UpdateGpuInfo(gpu_info); |
788 UpdateGpuSwitchingManager(gpu_info); | 761 UpdateGpuSwitchingManager(gpu_info); |
789 UpdatePreliminaryBlacklistedFeatures(); | 762 UpdatePreliminaryBlacklistedFeatures(); |
790 } | 763 } |
791 | 764 |
792 void GpuDataManagerImpl::UpdateBlacklistedFeatures( | 765 void GpuDataManagerImplPrivate::UpdateBlacklistedFeatures( |
793 const std::set<int>& features) { | 766 const std::set<int>& features) { |
794 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 767 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
795 blacklisted_features_ = features; | 768 blacklisted_features_ = features; |
796 | 769 |
797 // Force disable using the GPU for these features, even if they would | 770 // Force disable using the GPU for these features, even if they would |
798 // otherwise be allowed. | 771 // otherwise be allowed. |
799 if (card_blacklisted_ || | 772 if (card_blacklisted_ || |
800 command_line->HasSwitch(switches::kBlacklistAcceleratedCompositing)) { | 773 command_line->HasSwitch(switches::kBlacklistAcceleratedCompositing)) { |
801 blacklisted_features_.insert(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING); | 774 blacklisted_features_.insert(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING); |
802 } | 775 } |
803 if (card_blacklisted_ || | 776 if (card_blacklisted_ || |
804 command_line->HasSwitch(switches::kBlacklistWebGL)) { | 777 command_line->HasSwitch(switches::kBlacklistWebGL)) { |
805 blacklisted_features_.insert(GPU_FEATURE_TYPE_WEBGL); | 778 blacklisted_features_.insert(GPU_FEATURE_TYPE_WEBGL); |
806 } | 779 } |
807 | 780 |
808 EnableSwiftShaderIfNecessary(); | 781 EnableSwiftShaderIfNecessary(); |
809 } | 782 } |
810 | 783 |
811 void GpuDataManagerImpl::UpdatePreliminaryBlacklistedFeatures() { | 784 void GpuDataManagerImplPrivate::UpdatePreliminaryBlacklistedFeatures() { |
812 preliminary_blacklisted_features_ = blacklisted_features_; | 785 preliminary_blacklisted_features_ = blacklisted_features_; |
813 } | 786 } |
814 | 787 |
815 void GpuDataManagerImpl::UpdateGpuSwitchingManager(const GPUInfo& gpu_info) { | 788 void GpuDataManagerImplPrivate::UpdateGpuSwitchingManager( |
789 const GPUInfo& gpu_info) { | |
816 ui::GpuSwitchingManager::GetInstance()->SetGpuCount( | 790 ui::GpuSwitchingManager::GetInstance()->SetGpuCount( |
817 gpu_info.secondary_gpus.size() + 1); | 791 gpu_info.secondary_gpus.size() + 1); |
818 | 792 |
819 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) { | 793 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) { |
820 switch (gpu_switching_) { | 794 switch (gpu_switching_) { |
821 case GPU_SWITCHING_OPTION_FORCE_DISCRETE: | 795 case GPU_SWITCHING_OPTION_FORCE_DISCRETE: |
822 ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu(); | 796 ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu(); |
823 break; | 797 break; |
824 case GPU_SWITCHING_OPTION_FORCE_INTEGRATED: | 798 case GPU_SWITCHING_OPTION_FORCE_INTEGRATED: |
825 ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu(); | 799 ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu(); |
826 break; | 800 break; |
827 case GPU_SWITCHING_OPTION_AUTOMATIC: | 801 case GPU_SWITCHING_OPTION_AUTOMATIC: |
828 case GPU_SWITCHING_OPTION_UNKNOWN: | 802 case GPU_SWITCHING_OPTION_UNKNOWN: |
829 break; | 803 break; |
830 } | 804 } |
831 } | 805 } |
832 } | 806 } |
833 | 807 |
834 void GpuDataManagerImpl::NotifyGpuInfoUpdate() { | 808 void GpuDataManagerImplPrivate::NotifyGpuInfoUpdate() { |
835 observer_list_->Notify(&GpuDataManagerObserver::OnGpuInfoUpdate); | 809 observer_list_->Notify(&GpuDataManagerObserver::OnGpuInfoUpdate); |
836 } | 810 } |
837 | 811 |
838 void GpuDataManagerImpl::EnableSwiftShaderIfNecessary() { | 812 void GpuDataManagerImplPrivate::EnableSwiftShaderIfNecessary() { |
839 if (!GpuAccessAllowed(NULL) || | 813 if (!GpuAccessAllowed(NULL) || |
840 blacklisted_features_.count(GPU_FEATURE_TYPE_WEBGL)) { | 814 blacklisted_features_.count(GPU_FEATURE_TYPE_WEBGL)) { |
841 if (!swiftshader_path_.empty() && | 815 if (!swiftshader_path_.empty() && |
842 !CommandLine::ForCurrentProcess()->HasSwitch( | 816 !CommandLine::ForCurrentProcess()->HasSwitch( |
843 switches::kDisableSoftwareRasterizer)) | 817 switches::kDisableSoftwareRasterizer)) |
844 use_swiftshader_ = true; | 818 use_swiftshader_ = true; |
845 } | 819 } |
846 } | 820 } |
847 | 821 |
848 std::string GpuDataManagerImpl::GetDomainFromURL(const GURL& url) const { | 822 std::string GpuDataManagerImplPrivate::GetDomainFromURL( |
823 const GURL& url) const { | |
849 // For the moment, we just use the host, or its IP address, as the | 824 // For the moment, we just use the host, or its IP address, as the |
850 // entry in the set, rather than trying to figure out the top-level | 825 // entry in the set, rather than trying to figure out the top-level |
851 // domain. This does mean that a.foo.com and b.foo.com will be | 826 // domain. This does mean that a.foo.com and b.foo.com will be |
852 // treated independently in the blocking of a given domain, but it | 827 // treated independently in the blocking of a given domain, but it |
853 // would require a third-party library to reliably figure out the | 828 // would require a third-party library to reliably figure out the |
854 // top-level domain from a URL. | 829 // top-level domain from a URL. |
855 if (!url.has_host()) { | 830 if (!url.has_host()) { |
856 return std::string(); | 831 return std::string(); |
857 } | 832 } |
858 | 833 |
859 return url.host(); | 834 return url.host(); |
860 } | 835 } |
861 | 836 |
862 void GpuDataManagerImpl::BlockDomainFrom3DAPIsAtTime( | 837 void GpuDataManagerImplPrivate::BlockDomainFrom3DAPIsAtTime( |
863 const GURL& url, DomainGuilt guilt, base::Time at_time) { | 838 const GURL& url, |
839 GpuDataManagerImpl::DomainGuilt guilt, | |
840 base::Time at_time) { | |
864 if (!domain_blocking_enabled_) | 841 if (!domain_blocking_enabled_) |
865 return; | 842 return; |
866 | 843 |
867 std::string domain = GetDomainFromURL(url); | 844 std::string domain = GetDomainFromURL(url); |
868 | 845 |
869 base::AutoLock auto_lock(gpu_info_lock_); | |
870 DomainBlockEntry& entry = blocked_domains_[domain]; | 846 DomainBlockEntry& entry = blocked_domains_[domain]; |
871 entry.last_guilt = guilt; | 847 entry.last_guilt = guilt; |
872 timestamps_of_gpu_resets_.push_back(at_time); | 848 timestamps_of_gpu_resets_.push_back(at_time); |
873 } | 849 } |
874 | 850 |
875 GpuDataManagerImpl::DomainBlockStatus | 851 GpuDataManagerImpl::DomainBlockStatus |
876 GpuDataManagerImpl::Are3DAPIsBlockedAtTime( | 852 GpuDataManagerImplPrivate::Are3DAPIsBlockedAtTime( |
877 const GURL& url, base::Time at_time) const { | 853 const GURL& url, base::Time at_time) const { |
878 if (!domain_blocking_enabled_) | 854 if (!domain_blocking_enabled_) |
879 return DOMAIN_BLOCK_STATUS_NOT_BLOCKED; | 855 return GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED; |
880 | 856 |
881 // Note: adjusting the policies in this code will almost certainly | 857 // Note: adjusting the policies in this code will almost certainly |
882 // require adjusting the associated unit tests. | 858 // require adjusting the associated unit tests. |
883 std::string domain = GetDomainFromURL(url); | 859 std::string domain = GetDomainFromURL(url); |
884 | 860 |
885 base::AutoLock auto_lock(gpu_info_lock_); | 861 DomainBlockMap::const_iterator iter = blocked_domains_.find(domain); |
886 { | 862 if (iter != blocked_domains_.end()) { |
887 DomainBlockMap::const_iterator iter = blocked_domains_.find(domain); | 863 // Err on the side of caution, and assume that if a particular |
888 if (iter != blocked_domains_.end()) { | 864 // domain shows up in the block map, it's there for a good |
889 // Err on the side of caution, and assume that if a particular | 865 // reason and don't let its presence there automatically expire. |
890 // domain shows up in the block map, it's there for a good | |
891 // reason and don't let its presence there automatically expire. | |
892 | 866 |
893 UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs", | 867 UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs", |
894 BLOCK_STATUS_SPECIFIC_DOMAIN_BLOCKED, | 868 BLOCK_STATUS_SPECIFIC_DOMAIN_BLOCKED, |
895 BLOCK_STATUS_MAX); | 869 BLOCK_STATUS_MAX); |
896 | 870 |
897 return DOMAIN_BLOCK_STATUS_BLOCKED; | 871 return GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED; |
898 } | |
899 } | 872 } |
900 | 873 |
901 // Look at the timestamps of the recent GPU resets to see if there are | 874 // Look at the timestamps of the recent GPU resets to see if there are |
902 // enough within the threshold which would cause us to blacklist all | 875 // enough within the threshold which would cause us to blacklist all |
903 // domains. This doesn't need to be overly precise -- if time goes | 876 // domains. This doesn't need to be overly precise -- if time goes |
904 // backward due to a system clock adjustment, that's fine. | 877 // backward due to a system clock adjustment, that's fine. |
905 // | 878 // |
906 // TODO(kbr): make this pay attention to the TDR thresholds in the | 879 // TODO(kbr): make this pay attention to the TDR thresholds in the |
907 // Windows registry, but make sure it continues to be testable. | 880 // Windows registry, but make sure it continues to be testable. |
908 std::list<base::Time>::iterator iter = timestamps_of_gpu_resets_.begin(); | 881 { |
909 int num_resets_within_timeframe = 0; | 882 std::list<base::Time>::iterator iter = timestamps_of_gpu_resets_.begin(); |
910 while (iter != timestamps_of_gpu_resets_.end()) { | 883 int num_resets_within_timeframe = 0; |
911 base::Time time = *iter; | 884 while (iter != timestamps_of_gpu_resets_.end()) { |
912 base::TimeDelta delta_t = at_time - time; | 885 base::Time time = *iter; |
886 base::TimeDelta delta_t = at_time - time; | |
913 | 887 |
914 // If this entry has "expired", just remove it. | 888 // If this entry has "expired", just remove it. |
915 if (delta_t.InMilliseconds() > kBlockAllDomainsMs) { | 889 if (delta_t.InMilliseconds() > kBlockAllDomainsMs) { |
916 iter = timestamps_of_gpu_resets_.erase(iter); | 890 iter = timestamps_of_gpu_resets_.erase(iter); |
917 continue; | 891 continue; |
892 } | |
893 | |
894 ++num_resets_within_timeframe; | |
895 ++iter; | |
918 } | 896 } |
919 | 897 |
920 ++num_resets_within_timeframe; | 898 if (num_resets_within_timeframe >= kNumResetsWithinDuration) { |
921 ++iter; | 899 UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs", |
922 } | 900 BLOCK_STATUS_ALL_DOMAINS_BLOCKED, |
901 BLOCK_STATUS_MAX); | |
923 | 902 |
924 if (num_resets_within_timeframe >= kNumResetsWithinDuration) { | 903 return GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_ALL_DOMAINS_BLOCKED; |
925 UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs", | 904 } |
926 BLOCK_STATUS_ALL_DOMAINS_BLOCKED, | |
927 BLOCK_STATUS_MAX); | |
928 | |
929 return DOMAIN_BLOCK_STATUS_ALL_DOMAINS_BLOCKED; | |
930 } | 905 } |
931 | 906 |
932 UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs", | 907 UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs", |
933 BLOCK_STATUS_NOT_BLOCKED, | 908 BLOCK_STATUS_NOT_BLOCKED, |
934 BLOCK_STATUS_MAX); | 909 BLOCK_STATUS_MAX); |
935 | 910 |
936 return DOMAIN_BLOCK_STATUS_NOT_BLOCKED; | 911 return GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED; |
937 } | 912 } |
938 | 913 |
939 int64 GpuDataManagerImpl::GetBlockAllDomainsDurationInMs() const { | 914 int64 GpuDataManagerImplPrivate::GetBlockAllDomainsDurationInMs() const { |
940 return kBlockAllDomainsMs; | 915 return kBlockAllDomainsMs; |
941 } | 916 } |
942 | 917 |
943 void GpuDataManagerImpl::Notify3DAPIBlocked(const GURL& url, | 918 void GpuDataManagerImplPrivate::Notify3DAPIBlocked(const GURL& url, |
944 int render_process_id, | 919 int render_process_id, |
945 int render_view_id, | 920 int render_view_id, |
946 ThreeDAPIType requester) { | 921 ThreeDAPIType requester) { |
947 observer_list_->Notify(&GpuDataManagerObserver::DidBlock3DAPIs, | 922 observer_list_->Notify(&GpuDataManagerObserver::DidBlock3DAPIs, |
948 url, render_process_id, render_view_id, requester); | 923 url, render_process_id, render_view_id, requester); |
949 } | 924 } |
950 | 925 |
951 } // namespace content | 926 } // namespace content |
927 | |
OLD | NEW |