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