Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / content / browser / gpu / gpu_data_manager_impl_private.h
1 // Copyright (c) 2013 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_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_
6 #define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_
7
8 #include <list>
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
13
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/singleton.h"
16 #include "base/observer_list_threadsafe.h"
17 #include "content/browser/gpu/gpu_data_manager_impl.h"
18 #include "gpu/config/gpu_blacklist.h"
19 #include "gpu/config/gpu_driver_bug_list.h"
20
21 namespace base {
22 class CommandLine;
23 }
24
25 namespace content {
26
27 class CONTENT_EXPORT GpuDataManagerImplPrivate {
28  public:
29   static GpuDataManagerImplPrivate* Create(GpuDataManagerImpl* owner);
30
31   void InitializeForTesting(
32       const std::string& gpu_blacklist_json,
33       const gpu::GPUInfo& gpu_info);
34   bool IsFeatureBlacklisted(int feature) const;
35   bool IsDriverBugWorkaroundActive(int feature) const;
36   gpu::GPUInfo GetGPUInfo() const;
37   void GetGpuProcessHandles(
38       const GpuDataManager::GetGpuProcessHandlesCallback& callback) const;
39   bool GpuAccessAllowed(std::string* reason) const;
40   void RequestCompleteGpuInfoIfNeeded();
41   bool IsCompleteGpuInfoAvailable() const;
42   void RequestVideoMemoryUsageStatsUpdate() const;
43   bool ShouldUseSwiftShader() const;
44   void RegisterSwiftShaderPath(const base::FilePath& path);
45   void AddObserver(GpuDataManagerObserver* observer);
46   void RemoveObserver(GpuDataManagerObserver* observer);
47   void UnblockDomainFrom3DAPIs(const GURL& url);
48   void DisableGpuWatchdog();
49   void SetGLStrings(const std::string& gl_vendor,
50                     const std::string& gl_renderer,
51                     const std::string& gl_version);
52   void GetGLStrings(std::string* gl_vendor,
53                     std::string* gl_renderer,
54                     std::string* gl_version);
55   void DisableHardwareAcceleration();
56
57   void Initialize();
58
59   void UpdateGpuInfo(const gpu::GPUInfo& gpu_info);
60
61   void UpdateVideoMemoryUsageStats(
62       const GPUVideoMemoryUsageStats& video_memory_usage_stats);
63
64   void AppendRendererCommandLine(base::CommandLine* command_line) const;
65
66   void AppendGpuCommandLine(base::CommandLine* command_line) const;
67
68   void AppendPluginCommandLine(base::CommandLine* command_line) const;
69
70   void UpdateRendererWebPrefs(WebPreferences* prefs) const;
71
72   std::string GetBlacklistVersion() const;
73   std::string GetDriverBugListVersion() const;
74
75   void GetBlacklistReasons(base::ListValue* reasons) const;
76
77   void GetDriverBugWorkarounds(base::ListValue* workarounds) const;
78
79   void AddLogMessage(int level,
80                      const std::string& header,
81                      const std::string& message);
82
83   void ProcessCrashed(base::TerminationStatus exit_code);
84
85   base::ListValue* GetLogMessages() const;
86
87   void HandleGpuSwitch();
88
89   bool CanUseGpuBrowserCompositor() const;
90
91   void BlockDomainFrom3DAPIs(
92       const GURL& url, GpuDataManagerImpl::DomainGuilt guilt);
93   bool Are3DAPIsBlocked(const GURL& url,
94                         int render_process_id,
95                         int render_view_id,
96                         ThreeDAPIType requester);
97
98   void DisableDomainBlockingFor3DAPIsForTesting();
99
100   void Notify3DAPIBlocked(const GURL& url,
101                           int render_process_id,
102                           int render_view_id,
103                           ThreeDAPIType requester);
104
105   size_t GetBlacklistedFeatureCount() const;
106
107   void SetDisplayCount(unsigned int display_count);
108   unsigned int GetDisplayCount() const;
109
110   void OnGpuProcessInitFailure();
111
112   virtual ~GpuDataManagerImplPrivate();
113
114  private:
115   friend class GpuDataManagerImplPrivateTest;
116
117   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
118                            GpuSideBlacklisting);
119   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
120                            GpuSideExceptions);
121   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
122                            DisableHardwareAcceleration);
123   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
124                            SwiftShaderRendering);
125   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
126                            SwiftShaderRendering2);
127   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
128                            GpuInfoUpdate);
129   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
130                            NoGpuInfoUpdateWithSwiftShader);
131   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
132                            GPUVideoMemoryUsageStatsUpdate);
133   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
134                            BlockAllDomainsFrom3DAPIs);
135   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
136                            UnblockGuiltyDomainFrom3DAPIs);
137   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
138                            UnblockDomainOfUnknownGuiltFrom3DAPIs);
139   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
140                            UnblockOtherDomainFrom3DAPIs);
141   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
142                            UnblockThisDomainFrom3DAPIs);
143 #if defined(OS_LINUX)
144   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
145                            SetGLStrings);
146   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
147                            SetGLStringsNoEffects);
148 #endif
149   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
150                            GpuDriverBugListSingle);
151   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
152                            GpuDriverBugListMultiple);
153   FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
154                            BlacklistAllFeatures);
155
156   struct DomainBlockEntry {
157     GpuDataManagerImpl::DomainGuilt last_guilt;
158   };
159
160   typedef std::map<std::string, DomainBlockEntry> DomainBlockMap;
161
162   typedef ObserverListThreadSafe<GpuDataManagerObserver>
163       GpuDataManagerObserverList;
164
165   struct LogMessage {
166     int level;
167     std::string header;
168     std::string message;
169
170     LogMessage(int _level,
171                const std::string& _header,
172                const std::string& _message)
173         : level(_level),
174           header(_header),
175           message(_message) { }
176   };
177
178   explicit GpuDataManagerImplPrivate(GpuDataManagerImpl* owner);
179
180   void InitializeImpl(const std::string& gpu_blacklist_json,
181                       const std::string& gpu_driver_bug_list_json,
182                       const gpu::GPUInfo& gpu_info);
183
184   void UpdateGpuInfoHelper();
185
186   void UpdateBlacklistedFeatures(const std::set<int>& features);
187
188   // This should only be called once at initialization time, when preliminary
189   // gpu info is collected.
190   void UpdatePreliminaryBlacklistedFeatures();
191
192   // Update the GPU switching status.
193   // This should only be called once at initialization time.
194   void UpdateGpuSwitchingManager(const gpu::GPUInfo& gpu_info);
195
196   // Notify all observers whenever there is a GPU info update.
197   void NotifyGpuInfoUpdate();
198
199   // Try to switch to SwiftShader rendering, if possible and necessary.
200   void EnableSwiftShaderIfNecessary();
201
202   // Helper to extract the domain from a given URL.
203   std::string GetDomainFromURL(const GURL& url) const;
204
205   // Implementation functions for blocking of 3D graphics APIs, used
206   // for unit testing.
207   void BlockDomainFrom3DAPIsAtTime(const GURL& url,
208                                    GpuDataManagerImpl::DomainGuilt guilt,
209                                    base::Time at_time);
210   GpuDataManagerImpl::DomainBlockStatus Are3DAPIsBlockedAtTime(
211       const GURL& url, base::Time at_time) const;
212   int64 GetBlockAllDomainsDurationInMs() const;
213
214   bool complete_gpu_info_already_requested_;
215
216   std::set<int> blacklisted_features_;
217   std::set<int> preliminary_blacklisted_features_;
218
219   std::set<int> gpu_driver_bugs_;
220
221   gpu::GPUInfo gpu_info_;
222
223   scoped_ptr<gpu::GpuBlacklist> gpu_blacklist_;
224   scoped_ptr<gpu::GpuDriverBugList> gpu_driver_bug_list_;
225
226   const scoped_refptr<GpuDataManagerObserverList> observer_list_;
227
228   std::vector<LogMessage> log_messages_;
229
230   bool use_swiftshader_;
231
232   base::FilePath swiftshader_path_;
233
234   // Current card force-blacklisted due to GPU crashes, or disabled through
235   // the --disable-gpu commandline switch.
236   bool card_blacklisted_;
237
238   // We disable histogram stuff in testing, especially in unit tests because
239   // they cause random failures.
240   bool update_histograms_;
241
242   // Number of currently open windows, to be used in gpu memory allocation.
243   int window_count_;
244
245   DomainBlockMap blocked_domains_;
246   mutable std::list<base::Time> timestamps_of_gpu_resets_;
247   bool domain_blocking_enabled_;
248
249   GpuDataManagerImpl* owner_;
250
251   unsigned int display_count_;
252
253   bool gpu_process_accessible_;
254
255   bool use_software_compositor_;
256
257   // True if all future Initialize calls should be ignored.
258   bool finalized_;
259
260   DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImplPrivate);
261 };
262
263 }  // namespace content
264
265 #endif  // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_
266