Home | History | Annotate | Download | only in gl
      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 UI_GL_GPU_SWITCHING_MANAGER_H_
      6 #define UI_GL_GPU_SWITCHING_MANAGER_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/memory/singleton.h"
     11 #include "ui/gl/gl_export.h"
     12 #include "ui/gl/gpu_preference.h"
     13 
     14 #if defined(OS_MACOSX)
     15 #include <OpenGL/OpenGL.h>
     16 #endif  // OS_MACOSX
     17 
     18 namespace ui {
     19 
     20 class GL_EXPORT GpuSwitchingManager {
     21  public:
     22   // Getter for the singleton. This will return NULL on failure.
     23   static GpuSwitchingManager* GetInstance();
     24 
     25   // Set the switching option to PreferIntegratedGpu.
     26   void ForceUseOfIntegratedGpu();
     27   // Set the switching option to PreferDiscreteGpu; switch to discrete GPU
     28   // immediately on Mac where dual GPU switching is supported.
     29   void ForceUseOfDiscreteGpu();
     30 
     31   // If no GPU is forced, return the original GpuPreference; otherwise, return
     32   // the forced GPU.
     33   gfx::GpuPreference AdjustGpuPreference(gfx::GpuPreference gpu_preference);
     34 
     35   // In the browser process, the value for this flag is computed the first time
     36   // this function is called.
     37   // In the GPU process, the value is passed from the browser process using the
     38   // --supports-dual-gpus commandline switch.
     39   bool SupportsDualGpus();
     40 
     41   void SetGpuCount(size_t gpu_count);
     42 
     43  private:
     44   friend struct DefaultSingletonTraits<GpuSwitchingManager>;
     45 
     46   GpuSwitchingManager();
     47   virtual ~GpuSwitchingManager();
     48 
     49 #if defined(OS_MACOSX)
     50   void SwitchToDiscreteGpuMac();
     51 
     52   CGLPixelFormatObj discrete_pixel_format_;
     53 #endif  // OS_MACOSX
     54 
     55   gfx::GpuPreference gpu_switching_option_;
     56   bool gpu_switching_option_set_;
     57 
     58   bool supports_dual_gpus_;
     59   bool supports_dual_gpus_set_;
     60 
     61   size_t gpu_count_;
     62 
     63   DISALLOW_COPY_AND_ASSIGN(GpuSwitchingManager);
     64 };
     65 
     66 }  // namespace ui
     67 
     68 #endif  // UI_GL_GPU_SWITCHING_MANAGER_H_
     69