Fix WindowAndroid leak in Android WebView
[chromium-blink-merge.git] / ui / gl / gpu_switching_manager.h
bloba6a810f8bf1473ec31b1926db0ce7c4a60ab1b4f
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.
5 #ifndef UI_GL_GPU_SWITCHING_MANAGER_H_
6 #define UI_GL_GPU_SWITCHING_MANAGER_H_
8 #include <vector>
10 #include "base/memory/singleton.h"
11 #include "base/observer_list.h"
12 #include "ui/gl/gl_export.h"
13 #include "ui/gl/gpu_preference.h"
14 #include "ui/gl/gpu_switching_observer.h"
16 namespace ui {
18 class GL_EXPORT GpuSwitchingManager {
19 public:
20 // Getter for the singleton. This will return NULL on failure.
21 static GpuSwitchingManager* GetInstance();
23 // Set the switching option to PreferIntegratedGpu.
24 void ForceUseOfIntegratedGpu();
25 // Set the switching option to PreferDiscreteGpu; switch to discrete GPU
26 // immediately on Mac where dual GPU switching is supported.
27 void ForceUseOfDiscreteGpu();
29 // If no GPU is forced, return the original GpuPreference; otherwise, return
30 // the forced GPU.
31 gfx::GpuPreference AdjustGpuPreference(gfx::GpuPreference gpu_preference);
33 // In the browser process, the value for this flag is computed the first time
34 // this function is called.
35 // In the GPU process, the value is passed from the browser process using the
36 // --supports-dual-gpus commandline switch.
37 bool SupportsDualGpus();
39 void SetGpuCount(size_t gpu_count);
41 void AddObserver(GpuSwitchingObserver* observer);
42 void RemoveObserver(GpuSwitchingObserver* observer);
44 // Called when a GPU switch is noticed by the system. In the browser process
45 // this is occurs as a result of a system observer. In the GPU process, this
46 // occurs as a result of an IPC from the browser. The system observer is kept
47 // in the browser process only so that any workarounds or blacklisting can
48 // be applied there.
49 void NotifyGpuSwitched();
51 private:
52 friend struct DefaultSingletonTraits<GpuSwitchingManager>;
54 GpuSwitchingManager();
55 virtual ~GpuSwitchingManager();
57 #if defined(OS_MACOSX)
58 void SwitchToDiscreteGpuMac();
59 #endif // OS_MACOSX
61 gfx::GpuPreference gpu_switching_option_;
62 bool gpu_switching_option_set_;
64 bool supports_dual_gpus_;
65 bool supports_dual_gpus_set_;
67 size_t gpu_count_;
69 struct PlatformSpecific;
70 scoped_ptr<PlatformSpecific> platform_specific_;
72 ObserverList<GpuSwitchingObserver> observer_list_;
74 DISALLOW_COPY_AND_ASSIGN(GpuSwitchingManager);
77 } // namespace ui
79 #endif // UI_GL_GPU_SWITCHING_MANAGER_H_