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_
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.
32 struct _XRROutputInfo
;
33 typedef _XRROutputInfo XRROutputInfo
;
34 struct _XRRScreenResources
;
35 typedef _XRRScreenResources XRRScreenResources
;
37 typedef _XRRCrtcGamma XRRCrtcGamma
;
40 void XRRFreeScreenResources(XRRScreenResources
* resources
);
46 class DisplaySnapshotX11
;
47 class NativeDisplayEventDispatcherX11
;
49 class DISPLAY_EXPORT NativeDisplayDelegateX11
: public NativeDisplayDelegate
{
51 // Helper class that allows NativeDisplayEventDispatcherX11 and
52 // NativeDisplayDelegateX11::PlatformEventObserverX11 to interact with this
53 // class or with mocks in tests.
54 class HelperDelegate
{
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
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 bool TakeDisplayControl() override
;
78 bool RelinquishDisplayControl() override
;
79 void SyncWithServer() override
;
80 void SetBackgroundColor(uint32_t color_argb
) override
;
81 void ForceDPMSOn() override
;
82 void GetDisplays(const GetDisplaysCallback
& callback
) override
;
83 void AddMode(const DisplaySnapshot
& output
, const DisplayMode
* mode
) override
;
84 void Configure(const DisplaySnapshot
& output
,
85 const DisplayMode
* mode
,
86 const gfx::Point
& origin
,
87 const ConfigureCallback
& callback
) override
;
88 void CreateFrameBuffer(const gfx::Size
& size
) override
;
89 bool GetHDCPState(const DisplaySnapshot
& output
, HDCPState
* state
) override
;
90 bool SetHDCPState(const DisplaySnapshot
& output
, HDCPState state
) override
;
91 std::vector
<ColorCalibrationProfile
> GetAvailableColorCalibrationProfiles(
92 const DisplaySnapshot
& output
) override
;
93 bool SetColorCalibrationProfile(const DisplaySnapshot
& output
,
94 ColorCalibrationProfile new_profile
) override
;
95 void AddObserver(NativeDisplayObserver
* observer
) override
;
96 void RemoveObserver(NativeDisplayObserver
* observer
) override
;
99 class HelperDelegateX11
;
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 std::set
<RRCrtc
>* last_used_crtcs
,
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.
139 gfx::XObjectDeleter
<XRRScreenResources
, void, XRRFreeScreenResources
>>
142 std::map
<RRMode
, DisplayModeX11
*> modes_
;
144 // Every time GetOutputs() is called we cache the updated list of outputs in
145 // |cached_outputs_| so that we can check for duplicate events rather than
147 ScopedVector
<DisplaySnapshot
> cached_outputs_
;
149 scoped_ptr
<HelperDelegate
> helper_delegate_
;
151 // Processes X11 display events associated with the root window and notifies
152 // |observers_| when a display change has occurred.
153 scoped_ptr
<NativeDisplayEventDispatcherX11
> platform_event_dispatcher_
;
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_