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#ifndef CONTENT_PUBLIC_BROWSER_GPU_DATA_MANAGER_H_
6#define CONTENT_PUBLIC_BROWSER_GPU_DATA_MANAGER_H_
7
8#include <list>
9#include <string>
10
11#include "base/callback_forward.h"
12#include "base/process/process.h"
13#include "content/common/content_export.h"
14
15class GURL;
16
17namespace base {
18class FilePath;
19class ListValue;
20}
21
22namespace gpu {
23struct GPUInfo;
24}
25
26namespace content {
27
28class GpuDataManagerObserver;
29
30// This class is fully thread-safe.
31class GpuDataManager {
32 public:
33  typedef base::Callback<void(const std::list<base::ProcessHandle>&)>
34      GetGpuProcessHandlesCallback;
35
36  // Getter for the singleton.
37  CONTENT_EXPORT static GpuDataManager* GetInstance();
38
39  virtual void InitializeForTesting(const std::string& gpu_blacklist_json,
40                                    const gpu::GPUInfo& gpu_info) = 0;
41
42  virtual bool IsFeatureBlacklisted(int feature) const = 0;
43
44  virtual gpu::GPUInfo GetGPUInfo() const = 0;
45
46  // Retrieves a list of process handles for all gpu processes.
47  virtual void GetGpuProcessHandles(
48      const GetGpuProcessHandlesCallback& callback) const = 0;
49
50  // This indicator might change because we could collect more GPU info or
51  // because the GPU blacklist could be updated.
52  // If this returns false, any further GPU access, including launching GPU
53  // process, establish GPU channel, and GPU info collection, should be
54  // blocked.
55  // Can be called on any thread.
56  // If |reason| is not NULL and GPU access is blocked, upon return, |reason|
57  // contains a description of the reason why GPU access is blocked.
58  virtual bool GpuAccessAllowed(std::string* reason) const = 0;
59
60  // Requests complete GPU info if it has not already been requested
61  virtual void RequestCompleteGpuInfoIfNeeded() = 0;
62
63  // Check if basic and context GPU info have been collected.
64  virtual bool IsEssentialGpuInfoAvailable() const = 0;
65
66  // On Windows, besides basic and context GPU info, it also checks if
67  // DxDiagnostics have been collected.
68  // On other platforms, it's the same as IsEsentialGpuInfoAvailable().
69  virtual bool IsCompleteGpuInfoAvailable() const = 0;
70
71  // Requests that the GPU process report its current video memory usage stats,
72  // which can be retrieved via the GPU data manager's on-update function.
73  virtual void RequestVideoMemoryUsageStatsUpdate() const = 0;
74
75  // Returns true if SwiftShader should be used.
76  virtual bool ShouldUseSwiftShader() const = 0;
77
78  // Register a path to SwiftShader.
79  virtual void RegisterSwiftShaderPath(const base::FilePath& path) = 0;
80
81  // Returns current state about WARP, which may be due to command-line
82  // arguments or saved state.
83  virtual bool ShouldUseWarp() const = 0;
84
85  // Registers/unregister |observer|.
86  virtual void AddObserver(GpuDataManagerObserver* observer) = 0;
87  virtual void RemoveObserver(GpuDataManagerObserver* observer) = 0;
88
89  // Allows a given domain previously blocked from accessing 3D APIs
90  // to access them again.
91  virtual void UnblockDomainFrom3DAPIs(const GURL& url) = 0;
92
93  // Disable the gpu process watchdog thread.
94  virtual void DisableGpuWatchdog() = 0;
95
96  // Set GL strings. This triggers a re-calculation of GPU blacklist
97  // decision.
98  virtual void SetGLStrings(const std::string& gl_vendor,
99                            const std::string& gl_renderer,
100                            const std::string& gl_version) = 0;
101
102  // Obtain collected GL strings.
103  virtual void GetGLStrings(std::string* gl_vendor,
104                            std::string* gl_renderer,
105                            std::string* gl_version) = 0;
106
107  // Turn off all hardware acceleration.
108  virtual void DisableHardwareAcceleration() = 0;
109
110  // Whether the browser compositor can be used.
111  virtual bool CanUseGpuBrowserCompositor() const = 0;
112
113 protected:
114  virtual ~GpuDataManager() {}
115};
116
117};  // namespace content
118
119#endif  // CONTENT_PUBLIC_BROWSER_GPU_DATA_MANAGER_H_
120