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