Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ui / display / chromeos / x11 / native_display_delegate_x11.h
blobfadcf5635a23e46098f42f7dfd2bfa088b026a37
1 // Copyright 2014 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_DISPLAY_CHROMEOS_X11_NATIVE_DISPLAY_DELEGATE_X11_H_
6 #define UI_DISPLAY_CHROMEOS_X11_NATIVE_DISPLAY_DELEGATE_X11_H_
8 #include <stdint.h>
10 #include <map>
11 #include <set>
12 #include <vector>
14 #include "base/compiler_specific.h"
15 #include "base/event_types.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/scoped_vector.h"
18 #include "base/observer_list.h"
19 #include "ui/display/display_export.h"
20 #include "ui/display/types/native_display_delegate.h"
21 #include "ui/gfx/geometry/point.h"
22 #include "ui/gfx/geometry/size.h"
23 #include "ui/gfx/x/x11_types.h"
25 // Forward declarations for Xlib and Xrandr.
26 // This is so unused X definitions don't pollute the namespace.
27 typedef XID RROutput;
28 typedef XID RRCrtc;
29 typedef XID RRMode;
30 typedef XID Window;
32 struct _XRROutputInfo;
33 typedef _XRROutputInfo XRROutputInfo;
34 struct _XRRScreenResources;
35 typedef _XRRScreenResources XRRScreenResources;
36 struct _XRRCrtcGamma;
37 typedef _XRRCrtcGamma XRRCrtcGamma;
39 extern "C" {
40 void XRRFreeScreenResources(XRRScreenResources* resources);
43 namespace ui {
45 class DisplayModeX11;
46 class DisplaySnapshotX11;
47 class NativeDisplayEventDispatcherX11;
49 class DISPLAY_EXPORT NativeDisplayDelegateX11 : public NativeDisplayDelegate {
50 public:
51 // Helper class that allows NativeDisplayEventDispatcherX11 and
52 // NativeDisplayDelegateX11::PlatformEventObserverX11 to interact with this
53 // class or with mocks in tests.
54 class HelperDelegate {
55 public:
56 virtual ~HelperDelegate() {}
58 // Tells XRandR to update its configuration in response to |event|, an
59 // RRScreenChangeNotify event.
60 virtual void UpdateXRandRConfiguration(const base::NativeEvent& event) = 0;
62 // Returns the list of current outputs. This is used to discard duplicate
63 // events.
64 virtual const std::vector<DisplaySnapshot*>& GetCachedDisplays() const = 0;
66 // Notify |observers_| that a change in configuration has occurred.
67 virtual void NotifyDisplayObservers() = 0;
70 NativeDisplayDelegateX11();
71 ~NativeDisplayDelegateX11() override;
73 // NativeDisplayDelegate overrides:
74 void Initialize() override;
75 void GrabServer() override;
76 void UngrabServer() override;
77 void TakeDisplayControl(const DisplayControlCallback& callback) override;
78 void RelinquishDisplayControl(
79 const DisplayControlCallback& callback) override;
80 void SyncWithServer() override;
81 void SetBackgroundColor(uint32_t color_argb) override;
82 void ForceDPMSOn() override;
83 void GetDisplays(const GetDisplaysCallback& callback) override;
84 void AddMode(const DisplaySnapshot& output, const DisplayMode* mode) override;
85 void Configure(const DisplaySnapshot& output,
86 const DisplayMode* mode,
87 const gfx::Point& origin,
88 const ConfigureCallback& callback) override;
89 void CreateFrameBuffer(const gfx::Size& size) override;
90 void GetHDCPState(const DisplaySnapshot& output,
91 const GetHDCPStateCallback& callback) override;
92 void SetHDCPState(const DisplaySnapshot& output,
93 HDCPState state,
94 const SetHDCPStateCallback& callback) override;
95 std::vector<ColorCalibrationProfile> GetAvailableColorCalibrationProfiles(
96 const DisplaySnapshot& output) override;
97 bool SetColorCalibrationProfile(const DisplaySnapshot& output,
98 ColorCalibrationProfile new_profile) override;
99 bool SetGammaRamp(const ui::DisplaySnapshot& output,
100 const std::vector<GammaRampRGBEntry>& lut) override;
101 void AddObserver(NativeDisplayObserver* observer) override;
102 void RemoveObserver(NativeDisplayObserver* observer) override;
104 private:
105 class HelperDelegateX11;
107 // Parses all the modes made available by |screen_|.
108 void InitModes();
110 // Helper method for GetOutputs() that returns an OutputSnapshot struct based
111 // on the passed-in information.
112 DisplaySnapshotX11* InitDisplaySnapshot(RROutput id,
113 XRROutputInfo* info,
114 std::set<RRCrtc>* last_used_crtcs,
115 int index);
117 // Destroys unused CRTCs.
118 void DestroyUnusedCrtcs();
120 // Parks used CRTCs in a way which allows a framebuffer resize. This is faster
121 // than turning them off, resizing, then turning them back on.
122 // |min_screen_size| represent the smallest size between the current
123 // framebuffer size and the requested framebuffer size.
124 void UpdateCrtcsForNewFramebuffer(const gfx::Size& min_screen_size);
126 bool ConfigureCrtc(RRCrtc crtc, RRMode mode, RROutput output, int x, int y);
128 // Helper functions that perform the actual HDCP requests.
129 bool GetHDCPState(const DisplaySnapshot& output, HDCPState* state);
130 bool SetHDCPState(const DisplaySnapshot& output, HDCPState state);
132 // Returns whether |id| is configured to preserve aspect when scaling.
133 bool IsOutputAspectPreservingScaling(RROutput id);
135 // Creates the gamma ramp for |new_profile|, or NULL if it doesn't exist.
136 // The caller should take the ownership.
137 XRRCrtcGamma* CreateGammaRampForProfile(
138 const DisplaySnapshotX11& x11_output,
139 ColorCalibrationProfile new_profile);
141 void DrawBackground();
143 XDisplay* display_;
144 Window window_;
146 // Initialized when the server is grabbed and freed when it's ungrabbed.
147 gfx::XScopedPtr<
148 XRRScreenResources,
149 gfx::XObjectDeleter<XRRScreenResources, void, XRRFreeScreenResources>>
150 screen_;
152 std::map<RRMode, DisplayModeX11*> modes_;
154 // Every time GetOutputs() is called we cache the updated list of outputs in
155 // |cached_outputs_| so that we can check for duplicate events rather than
156 // propagate them.
157 ScopedVector<DisplaySnapshot> cached_outputs_;
159 scoped_ptr<HelperDelegate> helper_delegate_;
161 // Processes X11 display events associated with the root window and notifies
162 // |observers_| when a display change has occurred.
163 scoped_ptr<NativeDisplayEventDispatcherX11> platform_event_dispatcher_;
165 // List of observers waiting for display configuration change events.
166 base::ObserverList<NativeDisplayObserver> observers_;
168 // A background color used during boot time + multi displays.
169 uint32_t background_color_argb_;
171 DISALLOW_COPY_AND_ASSIGN(NativeDisplayDelegateX11);
174 } // namespace ui
176 #endif // UI_DISPLAY_CHROMEOS_X11_NATIVE_DISPLAY_DELEGATE_X11_H_