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 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 DictionaryValue* NewDescriptionValuePair(const std::string& desc, | 55 DictionaryValue* NewDescriptionValuePair(const std::string& desc, |
56 Value* value) { | 56 Value* value) { |
57 DictionaryValue* dict = new DictionaryValue(); | 57 DictionaryValue* dict = new DictionaryValue(); |
58 dict->SetString("description", desc); | 58 dict->SetString("description", desc); |
59 dict->Set("value", value); | 59 dict->Set("value", value); |
60 return dict; | 60 return dict; |
61 } | 61 } |
62 | 62 |
| 63 Value* NewStatusValue(const char* name, const char* status) { |
| 64 DictionaryValue* value = new DictionaryValue(); |
| 65 value->SetString("name", name); |
| 66 value->SetString("status", status); |
| 67 return value; |
| 68 } |
| 69 |
| 70 bool UseGLIsOSMesaOrAny() { |
| 71 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 72 std::string gl = browser_command_line.GetSwitchValueASCII(switches::kUseGL); |
| 73 return (gl == "any" || gl == gfx::kGLImplementationOSMesaName); |
| 74 } |
| 75 |
63 #if defined(OS_WIN) | 76 #if defined(OS_WIN) |
64 enum WinSubVersion { | 77 enum WinSubVersion { |
65 kWinOthers = 0, | 78 kWinOthers = 0, |
66 kWinXP, | 79 kWinXP, |
67 kWinVista, | 80 kWinVista, |
68 kWin7, | 81 kWin7, |
69 kNumWinSubVersions | 82 kNumWinSubVersions |
70 }; | 83 }; |
71 | 84 |
72 // Output DxDiagNode tree as nested array of {description,value} pairs | 85 // Output DxDiagNode tree as nested array of {description,value} pairs |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 187 |
175 UpdateGpuFeatureFlags(); | 188 UpdateGpuFeatureFlags(); |
176 } | 189 } |
177 | 190 |
178 const GPUInfo& GpuDataManager::gpu_info() const { | 191 const GPUInfo& GpuDataManager::gpu_info() const { |
179 base::AutoLock auto_lock(gpu_info_lock_); | 192 base::AutoLock auto_lock(gpu_info_lock_); |
180 return gpu_info_; | 193 return gpu_info_; |
181 } | 194 } |
182 | 195 |
183 Value* GpuDataManager::GetFeatureStatus() { | 196 Value* GpuDataManager::GetFeatureStatus() { |
184 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 197 const CommandLine& browser_command_line = |
185 if (gpu_blacklist_.get()) | 198 *CommandLine::ForCurrentProcess(); |
186 return gpu_blacklist_->GetFeatureStatus(GpuAccessAllowed(), | 199 bool gpu_access_allowed = GpuAccessAllowed(); |
187 browser_command_line.HasSwitch( | 200 bool disable_accelerated_compositing = browser_command_line.HasSwitch( |
188 switches::kDisableAcceleratedCompositing), | 201 switches::kDisableAcceleratedCompositing); |
189 browser_command_line.HasSwitch( | 202 bool disable_accelerated_2D_canvas = browser_command_line.HasSwitch( |
190 switches::kDisableAccelerated2dCanvas), | 203 switches::kDisableAccelerated2dCanvas); |
191 browser_command_line.HasSwitch(switches::kDisableExperimentalWebGL), | 204 bool disable_experimental_webgl = browser_command_line.HasSwitch( |
192 browser_command_line.HasSwitch(switches::kDisableGLMultisampling)); | 205 switches::kDisableExperimentalWebGL); |
193 return NULL; | 206 bool disable_multisampling = browser_command_line.HasSwitch( |
| 207 switches::kDisableGLMultisampling); |
| 208 |
| 209 uint32 flags = GetGpuFeatureFlags().flags(); |
| 210 DictionaryValue* status = new DictionaryValue(); |
| 211 |
| 212 // Build the feature_status field. |
| 213 { |
| 214 ListValue* feature_status_list = new ListValue(); |
| 215 |
| 216 // 2d_canvas. |
| 217 if (!gpu_access_allowed) { |
| 218 if (disable_accelerated_2D_canvas) |
| 219 feature_status_list->Append(NewStatusValue("2d_canvas", |
| 220 "software")); |
| 221 else |
| 222 feature_status_list->Append(NewStatusValue("2d_canvas", |
| 223 "unavailable_software")); |
| 224 } else if (!disable_accelerated_2D_canvas) { |
| 225 if ((flags & GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas) != 0) |
| 226 feature_status_list->Append(NewStatusValue("2d_canvas", |
| 227 "unavailable_software")); |
| 228 else if (disable_accelerated_compositing) |
| 229 feature_status_list->Append(NewStatusValue("2d_canvas", |
| 230 "disabled_software")); |
| 231 else |
| 232 feature_status_list->Append(NewStatusValue("2d_canvas", |
| 233 "enabled")); |
| 234 } else { |
| 235 feature_status_list->Append(NewStatusValue("2d_canvas", |
| 236 "software")); |
| 237 } |
| 238 |
| 239 // 3d css and compositing. |
| 240 if (!gpu_access_allowed) { |
| 241 feature_status_list->Append(NewStatusValue("3d_css", |
| 242 "unavailable_off")); |
| 243 feature_status_list->Append(NewStatusValue("compositing", |
| 244 "unavailable_software")); |
| 245 } else if (disable_accelerated_compositing) { |
| 246 feature_status_list->Append(NewStatusValue("3d_css", |
| 247 "unavailable_off")); |
| 248 feature_status_list->Append(NewStatusValue("compositing", |
| 249 "disabled_software")); |
| 250 } else if ((flags & |
| 251 GpuFeatureFlags::kGpuFeatureAcceleratedCompositing) != 0) { |
| 252 feature_status_list->Append(NewStatusValue("3d_css", |
| 253 "unavailable_off")); |
| 254 feature_status_list->Append(NewStatusValue("compositing", |
| 255 "disabled_software")); |
| 256 } else { |
| 257 feature_status_list->Append(NewStatusValue("3d_css", |
| 258 "enabled")); |
| 259 feature_status_list->Append(NewStatusValue("compositing", |
| 260 "enabled")); |
| 261 } |
| 262 |
| 263 // webgl |
| 264 if (!gpu_access_allowed) |
| 265 feature_status_list->Append(NewStatusValue("webgl", |
| 266 "unavailable_off")); |
| 267 else if (disable_experimental_webgl) |
| 268 feature_status_list->Append(NewStatusValue("webgl", |
| 269 "disabled_off")); |
| 270 else if ((flags & GpuFeatureFlags::kGpuFeatureWebgl) != 0) |
| 271 feature_status_list->Append(NewStatusValue("webgl", |
| 272 "unavailable_off")); |
| 273 else if (disable_accelerated_compositing) |
| 274 feature_status_list->Append(NewStatusValue("webgl", |
| 275 "enabled_readback")); |
| 276 else |
| 277 feature_status_list->Append(NewStatusValue("webgl", |
| 278 "enabled")); |
| 279 |
| 280 // multisampling |
| 281 if (!gpu_access_allowed) |
| 282 feature_status_list->Append(NewStatusValue("multisampling", |
| 283 "unavailable_off")); |
| 284 else if (disable_multisampling) |
| 285 feature_status_list->Append(NewStatusValue("multisampling", |
| 286 "disabled_off")); |
| 287 else if ((flags & GpuFeatureFlags::kGpuFeatureMultisampling) != 0) |
| 288 feature_status_list->Append(NewStatusValue("multisampling", |
| 289 "disabled_off")); |
| 290 else |
| 291 feature_status_list->Append(NewStatusValue("multisampling", |
| 292 "enabled")); |
| 293 |
| 294 status->Set("featureStatus", feature_status_list); |
| 295 } |
| 296 |
| 297 // Build the problems list. |
| 298 { |
| 299 ListValue* problem_list = new ListValue(); |
| 300 if (!gpu_access_allowed) { |
| 301 DictionaryValue* problem = new DictionaryValue(); |
| 302 problem->SetString("description", |
| 303 "GPU process was unable to boot. Access to GPU disallowed."); |
| 304 problem->Set("crBugs", new ListValue()); |
| 305 problem->Set("webkitBugs", new ListValue()); |
| 306 problem_list->Append(problem); |
| 307 } |
| 308 if (disable_accelerated_2D_canvas) { |
| 309 DictionaryValue* problem = new DictionaryValue(); |
| 310 problem->SetString("description", |
| 311 "Accelerated 2D canvas has been disabled at the command line"); |
| 312 problem->Set("crBugs", new ListValue()); |
| 313 problem->Set("webkitBugs", new ListValue()); |
| 314 problem_list->Append(problem); |
| 315 } |
| 316 if (disable_accelerated_compositing) { |
| 317 DictionaryValue* problem = new DictionaryValue(); |
| 318 problem->SetString("description", |
| 319 "Accelerated compositing has been disabled, either via about:flags " |
| 320 "or command line. This adversely affects performance of all hardware " |
| 321 " accelerated features."); |
| 322 problem->Set("crBugs", new ListValue()); |
| 323 problem->Set("webkitBugs", new ListValue()); |
| 324 problem_list->Append(problem); |
| 325 } |
| 326 if (disable_experimental_webgl) { |
| 327 DictionaryValue* problem = new DictionaryValue(); |
| 328 problem->SetString("description", |
| 329 "WebGL has been disabled, either via about:flags " |
| 330 "or command line"); |
| 331 problem->Set("crBugs", new ListValue()); |
| 332 problem->Set("webkitBugs", new ListValue()); |
| 333 problem_list->Append(problem); |
| 334 } |
| 335 if (disable_multisampling) { |
| 336 DictionaryValue* problem = new DictionaryValue(); |
| 337 problem->SetString("description", |
| 338 "Multisampling has been disabled, either via about:flags " |
| 339 "or command line"); |
| 340 problem->Set("crBugs", new ListValue()); |
| 341 problem->Set("webkitBugs", new ListValue()); |
| 342 problem_list->Append(problem); |
| 343 } |
| 344 GpuBlacklist* blacklist = GetGpuBlacklist(); |
| 345 if (blacklist && (!UseGLIsOSMesaOrAny())) |
| 346 blacklist->GetBlacklistReasons(problem_list); |
| 347 status->Set("problems", problem_list); |
| 348 } |
| 349 return status; |
194 } | 350 } |
195 | 351 |
196 std::string GpuDataManager::GetBlacklistVersion() const { | 352 std::string GpuDataManager::GetBlacklistVersion() const { |
197 if (gpu_blacklist_.get() != NULL) { | 353 if (gpu_blacklist_.get() != NULL) { |
198 uint16 version_major, version_minor; | 354 uint16 version_major, version_minor; |
199 if (gpu_blacklist_->GetVersion(&version_major, | 355 if (gpu_blacklist_->GetVersion(&version_major, |
200 &version_minor)) { | 356 &version_minor)) { |
201 std::string version_string = | 357 std::string version_string = |
202 base::UintToString(static_cast<unsigned>(version_major)) + | 358 base::UintToString(static_cast<unsigned>(version_major)) + |
203 "." + | 359 "." + |
204 base::UintToString(static_cast<unsigned>(version_minor)); | 360 base::UintToString(static_cast<unsigned>(version_minor)); |
205 return version_string; | 361 return version_string; |
206 } | 362 } |
207 } | 363 } |
208 return ""; | 364 return ""; |
209 } | 365 } |
210 | 366 |
211 void GpuDataManager::AddLogMessage(Value* msg) { | 367 void GpuDataManager::AddLogMessage(Value* msg) { |
212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
213 log_messages_.Append(msg); | 369 log_messages_.Append(msg); |
214 } | 370 } |
215 | 371 |
216 const ListValue& GpuDataManager::log_messages() const { | 372 const ListValue& GpuDataManager::log_messages() const { |
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
218 return log_messages_; | 374 return log_messages_; |
219 } | 375 } |
220 | 376 |
221 GpuFeatureFlags GpuDataManager::GetGpuFeatureFlags() { | 377 GpuFeatureFlags GpuDataManager::GetGpuFeatureFlags() { |
| 378 if (UseGLIsOSMesaOrAny()) |
| 379 return GpuFeatureFlags(); |
222 return gpu_feature_flags_; | 380 return gpu_feature_flags_; |
223 } | 381 } |
224 | 382 |
225 bool GpuDataManager::GpuAccessAllowed() { | 383 bool GpuDataManager::GpuAccessAllowed() { |
| 384 if (UseGLIsOSMesaOrAny()) |
| 385 return true; |
| 386 |
226 // We only need to block GPU process if more features are disallowed other | 387 // We only need to block GPU process if more features are disallowed other |
227 // than those in the preliminary gpu feature flags because the latter work | 388 // than those in the preliminary gpu feature flags because the latter work |
228 // through renderer commandline switches. | 389 // through renderer commandline switches. |
229 uint32 mask = (~(preliminary_gpu_feature_flags_.flags())); | 390 uint32 mask = (~(preliminary_gpu_feature_flags_.flags())); |
230 return (gpu_feature_flags_.flags() & mask) == 0; | 391 return (gpu_feature_flags_.flags() & mask) == 0; |
231 } | 392 } |
232 | 393 |
233 void GpuDataManager::AddGpuInfoUpdateCallback(Callback0::Type* callback) { | 394 void GpuDataManager::AddGpuInfoUpdateCallback(Callback0::Type* callback) { |
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
235 gpu_info_update_callbacks_.insert(callback); | 396 gpu_info_update_callbacks_.insert(callback); |
(...skipping 26 matching lines...) Expand all Loading... |
262 !command_line->HasSwitch(switches::kDisableGLMultisampling)) | 423 !command_line->HasSwitch(switches::kDisableGLMultisampling)) |
263 command_line->AppendSwitch(switches::kDisableGLMultisampling); | 424 command_line->AppendSwitch(switches::kDisableGLMultisampling); |
264 if ((flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing) && | 425 if ((flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing) && |
265 !command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) | 426 !command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) |
266 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); | 427 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); |
267 if ((flags & GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas) && | 428 if ((flags & GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas) && |
268 !command_line->HasSwitch(switches::kDisableAccelerated2dCanvas)) | 429 !command_line->HasSwitch(switches::kDisableAccelerated2dCanvas)) |
269 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); | 430 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); |
270 } | 431 } |
271 | 432 |
| 433 void GpuDataManager::AppendGpuCommandLine( |
| 434 CommandLine* command_line) { |
| 435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 436 DCHECK(command_line); |
| 437 |
| 438 uint32 flags = gpu_feature_flags_.flags(); |
| 439 if ((flags & GpuFeatureFlags::kGpuFeatureMultisampling) && |
| 440 !command_line->HasSwitch(switches::kDisableGLMultisampling)) |
| 441 command_line->AppendSwitch(switches::kDisableGLMultisampling); |
| 442 |
| 443 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 444 if ((flags & (GpuFeatureFlags::kGpuFeatureWebgl | |
| 445 GpuFeatureFlags::kGpuFeatureAcceleratedCompositing | |
| 446 GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)) && |
| 447 (browser_command_line.GetSwitchValueASCII( |
| 448 switches::kUseGL) == "any")) { |
| 449 command_line->AppendSwitchASCII( |
| 450 switches::kUseGL, gfx::kGLImplementationOSMesaName); |
| 451 } else if (browser_command_line.HasSwitch(switches::kUseGL)) { |
| 452 command_line->AppendSwitchASCII(switches::kUseGL, |
| 453 browser_command_line.GetSwitchValueASCII(switches::kUseGL)); |
| 454 } |
| 455 } |
| 456 |
272 void GpuDataManager::SetBuiltInGpuBlacklist(GpuBlacklist* built_in_list) { | 457 void GpuDataManager::SetBuiltInGpuBlacklist(GpuBlacklist* built_in_list) { |
273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
274 DCHECK(built_in_list); | 459 DCHECK(built_in_list); |
275 uint16 version_major, version_minor; | 460 uint16 version_major, version_minor; |
276 bool succeed = built_in_list->GetVersion( | 461 bool succeed = built_in_list->GetVersion( |
277 &version_major, &version_minor); | 462 &version_major, &version_minor); |
278 DCHECK(succeed); | 463 DCHECK(succeed); |
279 gpu_blacklist_.reset(built_in_list); | 464 gpu_blacklist_.reset(built_in_list); |
280 UpdateGpuFeatureFlags(); | 465 UpdateGpuFeatureFlags(); |
281 preliminary_gpu_feature_flags_ = gpu_feature_flags_; | 466 preliminary_gpu_feature_flags_ = gpu_feature_flags_; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 histogram_pointer->Add( | 653 histogram_pointer->Add( |
469 GetGpuBlacklistHistogramValueWin( | 654 GetGpuBlacklistHistogramValueWin( |
470 (flags & kGpuFeatures[i]) ? true : false)); | 655 (flags & kGpuFeatures[i]) ? true : false)); |
471 #endif | 656 #endif |
472 } | 657 } |
473 } | 658 } |
474 | 659 |
475 GpuBlacklist* GpuDataManager::GetGpuBlacklist() { | 660 GpuBlacklist* GpuDataManager::GetGpuBlacklist() { |
476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
477 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 662 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
478 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) || | 663 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist)) |
479 browser_command_line.GetSwitchValueASCII( | |
480 switches::kUseGL) == gfx::kGLImplementationOSMesaName) | |
481 return NULL; | 664 return NULL; |
482 // No need to return an empty blacklist. | 665 // No need to return an empty blacklist. |
483 if (gpu_blacklist_.get() != NULL && gpu_blacklist_->max_entry_id() == 0) | 666 if (gpu_blacklist_.get() != NULL && gpu_blacklist_->max_entry_id() == 0) |
484 return NULL; | 667 return NULL; |
485 return gpu_blacklist_.get(); | 668 return gpu_blacklist_.get(); |
486 } | 669 } |
OLD | NEW |