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
;
100 // Parses all the modes made available by |screen_|.
103 // Helper method for GetOutputs() that returns an OutputSnapshot struct based
104 // on the passed-in information.
105 DisplaySnapshotX11
* InitDisplaySnapshot(RROutput id
,
107 RRCrtc
* last_used_crtc
,
110 // Destroys unused CRTCs.
111 void DestroyUnusedCrtcs();
113 // Parks used CRTCs in a way which allows a framebuffer resize. This is faster
114 // than turning them off, resizing, then turning them back on.
115 // |min_screen_size| represent the smallest size between the current
116 // framebuffer size and the requested framebuffer size.
117 void UpdateCrtcsForNewFramebuffer(const gfx::Size
& min_screen_size
);
119 bool ConfigureCrtc(RRCrtc crtc
, RRMode mode
, RROutput output
, int x
, int y
);
121 // Returns whether |id| is configured to preserve aspect when scaling.
122 bool IsOutputAspectPreservingScaling(RROutput id
);
124 // Creates the gamma ramp for |new_profile|, or NULL if it doesn't exist.
125 // The caller should take the ownership.
126 XRRCrtcGamma
* CreateGammaRampForProfile(
127 const DisplaySnapshotX11
& x11_output
,
128 ColorCalibrationProfile new_profile
);
130 void DrawBackground();
135 // Initialized when the server is grabbed and freed when it's ungrabbed.
136 XRRScreenResources
* screen_
;
138 std::map
<RRMode
, DisplayModeX11
*> modes_
;
140 // Every time GetOutputs() is called we cache the updated list of outputs in
141 // |cached_outputs_| so that we can check for duplicate events rather than
143 ScopedVector
<DisplaySnapshot
> cached_outputs_
;
145 scoped_ptr
<HelperDelegate
> helper_delegate_
;
147 // Processes X11 display events associated with the root window and notifies
148 // |observers_| when a display change has occurred.
149 scoped_ptr
<NativeDisplayEventDispatcherX11
> platform_event_dispatcher_
;
151 // List of observers waiting for display configuration change events.
152 ObserverList
<NativeDisplayObserver
> observers_
;
154 // A background color used during boot time + multi displays.
155 uint32_t background_color_argb_
;
157 DISALLOW_COPY_AND_ASSIGN(NativeDisplayDelegateX11
);
162 #endif // UI_DISPLAY_CHROMEOS_X11_NATIVE_DISPLAY_DELEGATE_X11_H_