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_
13 #include "base/compiler_specific.h"
14 #include "base/event_types.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_vector.h"
17 #include "base/observer_list.h"
18 #include "ui/display/display_export.h"
19 #include "ui/display/types/chromeos/native_display_delegate.h"
20 #include "ui/gfx/geometry/point.h"
21 #include "ui/gfx/geometry/size.h"
23 // Forward declarations for Xlib and Xrandr.
24 // This is so unused X definitions don't pollute the namespace.
25 typedef unsigned long XID;
32 typedef struct _XDisplay Display;
33 struct _XRROutputInfo;
34 typedef _XRROutputInfo XRROutputInfo;
35 struct _XRRScreenResources;
36 typedef _XRRScreenResources XRRScreenResources;
38 typedef _XRRCrtcGamma XRRCrtcGamma;
43 class DisplaySnapshotX11;
44 class NativeDisplayEventDispatcherX11;
46 class DISPLAY_EXPORT NativeDisplayDelegateX11 : public NativeDisplayDelegate {
48 // Helper class that allows NativeDisplayEventDispatcherX11 and
49 // NativeDisplayDelegateX11::PlatformEventObserverX11 to interact with this
50 // class or with mocks in tests.
51 class HelperDelegate {
53 virtual ~HelperDelegate() {}
55 // Tells XRandR to update its configuration in response to |event|, an
56 // RRScreenChangeNotify event.
57 virtual void UpdateXRandRConfiguration(const base::NativeEvent& event) = 0;
59 // Returns the list of current outputs. This is used to discard duplicate
61 virtual const std::vector<DisplaySnapshot*>& GetCachedDisplays() const = 0;
63 // Notify |observers_| that a change in configuration has occurred.
64 virtual void NotifyDisplayObservers() = 0;
67 NativeDisplayDelegateX11();
68 virtual ~NativeDisplayDelegateX11();
70 // NativeDisplayDelegate overrides:
71 virtual void Initialize() OVERRIDE;
72 virtual void GrabServer() OVERRIDE;
73 virtual void UngrabServer() OVERRIDE;
74 virtual void SyncWithServer() OVERRIDE;
75 virtual void SetBackgroundColor(uint32_t color_argb) OVERRIDE;
76 virtual void ForceDPMSOn() OVERRIDE;
77 virtual std::vector<DisplaySnapshot*> GetDisplays() OVERRIDE;
78 virtual void AddMode(const DisplaySnapshot& output,
79 const DisplayMode* mode) OVERRIDE;
80 virtual bool Configure(const DisplaySnapshot& output,
81 const DisplayMode* mode,
82 const gfx::Point& origin) OVERRIDE;
83 virtual void CreateFrameBuffer(const gfx::Size& size) OVERRIDE;
84 virtual bool GetHDCPState(const DisplaySnapshot& output,
85 HDCPState* state) OVERRIDE;
86 virtual bool SetHDCPState(const DisplaySnapshot& output,
87 HDCPState state) OVERRIDE;
88 virtual std::vector<ColorCalibrationProfile>
89 GetAvailableColorCalibrationProfiles(
90 const DisplaySnapshot& output) OVERRIDE;
91 virtual bool SetColorCalibrationProfile(
92 const DisplaySnapshot& output,
93 ColorCalibrationProfile new_profile) OVERRIDE;
94 virtual void AddObserver(NativeDisplayObserver* observer) OVERRIDE;
95 virtual void RemoveObserver(NativeDisplayObserver* observer) OVERRIDE;
98 class HelperDelegateX11;
99 class PlatformEventObserverX11;
101 // Parses all the modes made available by |screen_|.
104 // Helper method for GetOutputs() that returns an OutputSnapshot struct based
105 // on the passed-in information.
106 DisplaySnapshotX11* InitDisplaySnapshot(RROutput id,
108 RRCrtc* last_used_crtc,
111 // Destroys unused CRTCs.
112 void DestroyUnusedCrtcs();
114 // Parks used CRTCs in a way which allows a framebuffer resize. This is faster
115 // than turning them off, resizing, then turning them back on.
116 // |min_screen_size| represent the smallest size between the current
117 // framebuffer size and the requested framebuffer size.
118 void UpdateCrtcsForNewFramebuffer(const gfx::Size& min_screen_size);
120 bool ConfigureCrtc(RRCrtc crtc, RRMode mode, RROutput output, int x, int y);
122 // Returns whether |id| is configured to preserve aspect when scaling.
123 bool IsOutputAspectPreservingScaling(RROutput id);
125 // Creates the gamma ramp for |new_profile|, or NULL if it doesn't exist.
126 // The caller should take the ownership.
127 XRRCrtcGamma* CreateGammaRampForProfile(
128 const DisplaySnapshotX11& x11_output,
129 ColorCalibrationProfile new_profile);
131 void DrawBackground();
136 // Initialized when the server is grabbed and freed when it's ungrabbed.
137 XRRScreenResources* screen_;
139 std::map<RRMode, DisplayModeX11*> modes_;
141 // Every time GetOutputs() is called we cache the updated list of outputs in
142 // |cached_outputs_| so that we can check for duplicate events rather than
144 ScopedVector<DisplaySnapshot> cached_outputs_;
146 scoped_ptr<HelperDelegate> helper_delegate_;
148 // Processes X11 display events associated with the root window and notifies
149 // |observers_| when a display change has occurred.
150 scoped_ptr<NativeDisplayEventDispatcherX11> platform_event_dispatcher_;
152 // Processes X11 display events that have no X11 window associated with it.
153 scoped_ptr<PlatformEventObserverX11> platform_event_observer_;
155 // List of observers waiting for display configuration change events.
156 ObserverList<NativeDisplayObserver> observers_;
158 // A background color used during boot time + multi displays.
159 uint32_t background_color_argb_;
161 DISALLOW_COPY_AND_ASSIGN(NativeDisplayDelegateX11);
166 #endif // UI_DISPLAY_CHROMEOS_X11_NATIVE_DISPLAY_DELEGATE_X11_H_