• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 CHROME_BROWSER_GPU_DATA_MANAGER_H_
6 #define CHROME_BROWSER_GPU_DATA_MANAGER_H_
7 #pragma once
8 
9 #include <set>
10 #include <string>
11 
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/singleton.h"
15 #include "base/synchronization/lock.h"
16 #include "base/values.h"
17 #include "content/common/gpu/gpu_info.h"
18 #include "content/common/gpu_feature_flags.h"
19 
20 class CommandLine;
21 class GpuBlacklist;
22 
23 class GpuDataManager {
24  public:
25   // Getter for the singleton. This will return NULL on failure.
26   static GpuDataManager* GetInstance();
27 
28   // Requests complete GPUinfo if it has not already been requested
29   void RequestCompleteGpuInfoIfNeeded();
30 
31   // Only update if the current GPUInfo is not finalized.
32   void UpdateGpuInfo(const GPUInfo& gpu_info);
33 
34   const GPUInfo& gpu_info() const;
35 
36   // Returns status of various GPU features. Return type is
37   // GpuBlacklist::GetFeatureStatus, or NULL if blacklist is
38   // uninitialized. Caller is responsible for deleting the returned value.
39   Value* GetFeatureStatus();
40 
41   std::string GetBlacklistVersion() const;
42 
43   void AddLogMessage(Value* msg);
44 
45   const ListValue& log_messages() const;
46 
47   // Can be called on any thread.
48   GpuFeatureFlags GetGpuFeatureFlags();
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   bool GpuAccessAllowed();
57 
58   // Add a callback.
59   void AddGpuInfoUpdateCallback(Callback0::Type* callback);
60 
61   // Remove a callback.
62   // Returns true if removed, or false if it was not found.
63   bool RemoveGpuInfoUpdateCallback(Callback0::Type* callback);
64 
65   // Inserting disable-feature switches into renderer process command-line
66   // in correspondance to preliminary gpu feature flags.
67   void AppendRendererCommandLine(CommandLine* command_line);
68 
69   // Gives ownership of the latest blacklist.  This is always called on the UI
70   // thread.
71   void UpdateGpuBlacklist(GpuBlacklist* gpu_blacklist);
72 
73  private:
74   friend struct DefaultSingletonTraits<GpuDataManager>;
75 
76   GpuDataManager();
77   virtual ~GpuDataManager();
78 
79   // Check if we should go ahead and use gpu blacklist.
80   // If not, return NULL; otherwise, update and return the current list.
81   GpuBlacklist* GetGpuBlacklist();
82 
83   // If flags hasn't been set and GPUInfo is available, run through blacklist
84   // and compute the flags.
85   void UpdateGpuFeatureFlags();
86 
87   // Call all callbacks.
88   void RunGpuInfoUpdateCallbacks();
89 
90   bool complete_gpu_info_already_requested_;
91 
92   bool gpu_feature_flags_set_;
93   GpuFeatureFlags gpu_feature_flags_;
94 
95   GPUInfo gpu_info_;
96   mutable base::Lock gpu_info_lock_;
97 
98   scoped_ptr<GpuBlacklist> gpu_blacklist_;
99 
100   // Map of callbacks.
101   std::set<Callback0::Type*> gpu_info_update_callbacks_;
102 
103   ListValue log_messages_;
104 
105   DISALLOW_COPY_AND_ASSIGN(GpuDataManager);
106 };
107 
108 #endif  // CHROME_BROWSER_GPU_DATA_MANAGER_H_
109