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