Correctly track texture cleared state for sharing
[chromium-blink-merge.git] / ui / display / chromeos / x11 / native_display_delegate_x11.h
blob09bf22f1037df5a7405ebef4664d31f1e23a0e65
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"
24 // Forward declarations for Xlib and Xrandr.
25 // This is so unused X definitions don't pollute the namespace.
26 typedef unsigned long XID;
27 typedef XID RROutput;
28 typedef XID RRCrtc;
29 typedef XID RRMode;
30 typedef XID Window;
32 struct _XDisplay;
33 typedef struct _XDisplay Display;
34 struct _XRROutputInfo;
35 typedef _XRROutputInfo XRROutputInfo;
36 struct _XRRScreenResources;
37 typedef _XRRScreenResources XRRScreenResources;
38 struct _XRRCrtcGamma;
39 typedef _XRRCrtcGamma XRRCrtcGamma;
41 namespace ui {
43 class DisplayModeX11;
44 class DisplaySnapshotX11;
45 class NativeDisplayEventDispatcherX11;
47 class DISPLAY_EXPORT NativeDisplayDelegateX11 : public NativeDisplayDelegate {
48 public:
49 // Helper class that allows NativeDisplayEventDispatcherX11 and
50 // NativeDisplayDelegateX11::PlatformEventObserverX11 to interact with this
51 // class or with mocks in tests.
52 class HelperDelegate {
53 public:
54 virtual ~HelperDelegate() {}
56 // Tells XRandR to update its configuration in response to |event|, an
57 // RRScreenChangeNotify event.
58 virtual void UpdateXRandRConfiguration(const base::NativeEvent& event) = 0;
60 // Returns the list of current outputs. This is used to discard duplicate
61 // events.
62 virtual const std::vector<DisplaySnapshot*>& GetCachedDisplays() const = 0;
64 // Notify |observers_| that a change in configuration has occurred.
65 virtual void NotifyDisplayObservers() = 0;
68 NativeDisplayDelegateX11();
69 ~NativeDisplayDelegateX11() override;
71 // NativeDisplayDelegate overrides:
72 void Initialize() override;
73 void GrabServer() override;
74 void UngrabServer() override;
75 bool TakeDisplayControl() override;
76 bool RelinquishDisplayControl() override;
77 void SyncWithServer() override;
78 void SetBackgroundColor(uint32_t color_argb) override;
79 void ForceDPMSOn() override;
80 void GetDisplays(const GetDisplaysCallback& callback) override;
81 void AddMode(const DisplaySnapshot& output, const DisplayMode* mode) override;
82 void Configure(const DisplaySnapshot& output,
83 const DisplayMode* mode,
84 const gfx::Point& origin,
85 const ConfigureCallback& callback) override;
86 void CreateFrameBuffer(const gfx::Size& size) override;
87 bool GetHDCPState(const DisplaySnapshot& output, HDCPState* state) override;
88 bool SetHDCPState(const DisplaySnapshot& output, HDCPState state) override;
89 std::vector<ColorCalibrationProfile> GetAvailableColorCalibrationProfiles(
90 const DisplaySnapshot& output) override;
91 bool SetColorCalibrationProfile(const DisplaySnapshot& output,
92 ColorCalibrationProfile new_profile) override;
93 void AddObserver(NativeDisplayObserver* observer) override;
94 void RemoveObserver(NativeDisplayObserver* observer) override;
96 private:
97 class HelperDelegateX11;
99 // Parses all the modes made available by |screen_|.
100 void InitModes();
102 // Helper method for GetOutputs() that returns an OutputSnapshot struct based
103 // on the passed-in information.
104 DisplaySnapshotX11* InitDisplaySnapshot(RROutput id,
105 XRROutputInfo* info,
106 std::set<RRCrtc>* last_used_crtcs,
107 int index);
109 // Destroys unused CRTCs.
110 void DestroyUnusedCrtcs();
112 // Parks used CRTCs in a way which allows a framebuffer resize. This is faster
113 // than turning them off, resizing, then turning them back on.
114 // |min_screen_size| represent the smallest size between the current
115 // framebuffer size and the requested framebuffer size.
116 void UpdateCrtcsForNewFramebuffer(const gfx::Size& min_screen_size);
118 bool ConfigureCrtc(RRCrtc crtc, RRMode mode, RROutput output, int x, int y);
120 // Returns whether |id| is configured to preserve aspect when scaling.
121 bool IsOutputAspectPreservingScaling(RROutput id);
123 // Creates the gamma ramp for |new_profile|, or NULL if it doesn't exist.
124 // The caller should take the ownership.
125 XRRCrtcGamma* CreateGammaRampForProfile(
126 const DisplaySnapshotX11& x11_output,
127 ColorCalibrationProfile new_profile);
129 void DrawBackground();
131 Display* display_;
132 Window window_;
134 // Initialized when the server is grabbed and freed when it's ungrabbed.
135 XRRScreenResources* screen_;
137 std::map<RRMode, DisplayModeX11*> modes_;
139 // Every time GetOutputs() is called we cache the updated list of outputs in
140 // |cached_outputs_| so that we can check for duplicate events rather than
141 // propagate them.
142 ScopedVector<DisplaySnapshot> cached_outputs_;
144 scoped_ptr<HelperDelegate> helper_delegate_;
146 // Processes X11 display events associated with the root window and notifies
147 // |observers_| when a display change has occurred.
148 scoped_ptr<NativeDisplayEventDispatcherX11> platform_event_dispatcher_;
150 // List of observers waiting for display configuration change events.
151 ObserverList<NativeDisplayObserver> observers_;
153 // A background color used during boot time + multi displays.
154 uint32_t background_color_argb_;
156 DISALLOW_COPY_AND_ASSIGN(NativeDisplayDelegateX11);
159 } // namespace ui
161 #endif // UI_DISPLAY_CHROMEOS_X11_NATIVE_DISPLAY_DELEGATE_X11_H_