| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/gpu/gpu_feature_checker.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "build/build_config.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/gpu_data_manager.h" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 // A false return value is always valid, but a true one is only valid if full | |
| 15 // GPU info has been collected in a GPU process. | |
| 16 bool IsFeatureAllowed(content::GpuDataManager* manager, | |
| 17 gpu::GpuFeatureType feature) { | |
| 18 return (manager->GpuAccessAllowed(NULL) && | |
| 19 !manager->IsFeatureBlacklisted(feature)); | |
| 20 } | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 GPUFeatureChecker::GPUFeatureChecker(gpu::GpuFeatureType feature, | |
| 25 FeatureAvailableCallback callback) | |
| 26 : feature_(feature), | |
| 27 callback_(callback) { | |
| 28 } | |
| 29 | |
| 30 GPUFeatureChecker::~GPUFeatureChecker() { | |
| 31 } | |
| 32 | |
| 33 void GPUFeatureChecker::CheckGPUFeatureAvailability() { | |
| 34 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 35 | |
| 36 bool finalized = true; | |
| 37 #if defined(OS_LINUX) | |
| 38 // On Windows and Mac, so far we can always make the final WebGL blacklisting | |
| 39 // decision based on partial GPU info; on Linux, we need to launch the GPU | |
| 40 // process to collect full GPU info and make the final decision. | |
| 41 finalized = false; | |
| 42 #endif | |
| 43 | |
| 44 content::GpuDataManager* manager = content::GpuDataManager::GetInstance(); | |
| 45 if (manager->IsEssentialGpuInfoAvailable()) | |
| 46 finalized = true; | |
| 47 | |
| 48 bool feature_allowed = IsFeatureAllowed(manager, feature_); | |
| 49 if (!feature_allowed) | |
| 50 finalized = true; | |
| 51 | |
| 52 if (finalized) { | |
| 53 callback_.Run(feature_allowed); | |
| 54 } else { | |
| 55 // Matched with a Release in OnGpuInfoUpdate. | |
| 56 AddRef(); | |
| 57 | |
| 58 manager->AddObserver(this); | |
| 59 manager->RequestCompleteGpuInfoIfNeeded(); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 void GPUFeatureChecker::OnGpuInfoUpdate() { | |
| 64 content::GpuDataManager* manager = content::GpuDataManager::GetInstance(); | |
| 65 manager->RemoveObserver(this); | |
| 66 bool feature_allowed = IsFeatureAllowed(manager, feature_); | |
| 67 callback_.Run(feature_allowed); | |
| 68 | |
| 69 // Matches the AddRef in HasFeature(). | |
| 70 Release(); | |
| 71 } | |
| OLD | NEW |