| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_DISPLAY_CHROMEOS_X11_NATIVE_DISPLAY_DELEGATE_X11_H_ | 5 #ifndef UI_DISPLAY_CHROMEOS_X11_NATIVE_DISPLAY_DELEGATE_X11_H_ |
| 6 #define UI_DISPLAY_CHROMEOS_X11_NATIVE_DISPLAY_DELEGATE_X11_H_ | 6 #define UI_DISPLAY_CHROMEOS_X11_NATIVE_DISPLAY_DELEGATE_X11_H_ |
| 7 | 7 |
| 8 #include <map> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/event_types.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/observer_list.h" |
| 12 #include "ui/display/chromeos/native_display_delegate.h" | 17 #include "ui/display/chromeos/native_display_delegate.h" |
| 18 #include "ui/gfx/geometry/point.h" |
| 19 #include "ui/gfx/geometry/size.h" |
| 13 | 20 |
| 21 // Forward declarations for Xlib and Xrandr. |
| 22 // This is so unused X definitions don't pollute the namespace. |
| 23 typedef unsigned long XID; |
| 24 typedef XID RROutput; |
| 25 typedef XID RRCrtc; |
| 26 typedef XID RRMode; |
| 14 typedef XID Window; | 27 typedef XID Window; |
| 15 | 28 |
| 16 struct _XDisplay; | 29 struct _XDisplay; |
| 17 typedef struct _XDisplay Display; | 30 typedef struct _XDisplay Display; |
| 18 struct _XRROutputInfo; | 31 struct _XRROutputInfo; |
| 19 typedef _XRROutputInfo XRROutputInfo; | 32 typedef _XRROutputInfo XRROutputInfo; |
| 20 struct _XRRScreenResources; | 33 struct _XRRScreenResources; |
| 21 typedef _XRRScreenResources XRRScreenResources; | 34 typedef _XRRScreenResources XRRScreenResources; |
| 22 | 35 |
| 23 namespace ui { | 36 namespace ui { |
| 24 | 37 |
| 38 class DisplayModeX11; |
| 39 class DisplaySnapshotX11; |
| 25 class NativeDisplayEventDispatcherX11; | 40 class NativeDisplayEventDispatcherX11; |
| 26 | 41 |
| 27 class NativeDisplayDelegateX11 : public NativeDisplayDelegate { | 42 class DISPLAY_EXPORT NativeDisplayDelegateX11 : public NativeDisplayDelegate { |
| 28 public: | 43 public: |
| 29 // Helper class that allows NativeDisplayEventDispatcherX11 and | 44 // Helper class that allows NativeDisplayEventDispatcherX11 and |
| 30 // NativeDisplayDelegateX11::MessagePumpObserverX11 to interact with this | 45 // NativeDisplayDelegateX11::MessagePumpObserverX11 to interact with this |
| 31 // class or with mocks in tests. | 46 // class or with mocks in tests. |
| 32 class HelperDelegate { | 47 class HelperDelegate { |
| 33 public: | 48 public: |
| 34 virtual ~HelperDelegate() {} | 49 virtual ~HelperDelegate() {} |
| 35 | 50 |
| 36 // Tells XRandR to update its configuration in response to |event|, an | 51 // Tells XRandR to update its configuration in response to |event|, an |
| 37 // RRScreenChangeNotify event. | 52 // RRScreenChangeNotify event. |
| 38 virtual void UpdateXRandRConfiguration(const base::NativeEvent& event) = 0; | 53 virtual void UpdateXRandRConfiguration(const base::NativeEvent& event) = 0; |
| 39 | 54 |
| 40 // Returns the list of current outputs. This is used to discard duplicate | 55 // Returns the list of current outputs. This is used to discard duplicate |
| 41 // events. | 56 // events. |
| 42 virtual const std::vector<OutputConfigurator::OutputSnapshot>& | 57 virtual const std::vector<DisplaySnapshot*>& GetCachedOutputs() const = 0; |
| 43 GetCachedOutputs() const = 0; | |
| 44 | 58 |
| 45 // Notify |observers_| that a change in configuration has occurred. | 59 // Notify |observers_| that a change in configuration has occurred. |
| 46 virtual void NotifyDisplayObservers() = 0; | 60 virtual void NotifyDisplayObservers() = 0; |
| 47 }; | 61 }; |
| 48 | 62 |
| 49 NativeDisplayDelegateX11(); | 63 NativeDisplayDelegateX11(); |
| 50 virtual ~NativeDisplayDelegateX11(); | 64 virtual ~NativeDisplayDelegateX11(); |
| 51 | 65 |
| 52 // OutputConfigurator::Delegate overrides: | 66 // OutputConfigurator::Delegate overrides: |
| 53 virtual void Initialize() OVERRIDE; | 67 virtual void Initialize() OVERRIDE; |
| 54 virtual void GrabServer() OVERRIDE; | 68 virtual void GrabServer() OVERRIDE; |
| 55 virtual void UngrabServer() OVERRIDE; | 69 virtual void UngrabServer() OVERRIDE; |
| 56 virtual void SyncWithServer() OVERRIDE; | 70 virtual void SyncWithServer() OVERRIDE; |
| 57 virtual void SetBackgroundColor(uint32 color_argb) OVERRIDE; | 71 virtual void SetBackgroundColor(uint32 color_argb) OVERRIDE; |
| 58 virtual void ForceDPMSOn() OVERRIDE; | 72 virtual void ForceDPMSOn() OVERRIDE; |
| 59 virtual std::vector<OutputConfigurator::OutputSnapshot> GetOutputs() OVERRIDE; | 73 virtual std::vector<DisplaySnapshot*> GetOutputs() OVERRIDE; |
| 60 virtual void AddMode(const OutputConfigurator::OutputSnapshot& output, | 74 virtual void AddMode(const DisplaySnapshot& output, |
| 61 RRMode mode) OVERRIDE; | 75 const DisplayMode* mode) OVERRIDE; |
| 62 virtual bool Configure(const OutputConfigurator::OutputSnapshot& output, | 76 virtual bool Configure(const DisplaySnapshot& output, |
| 63 RRMode mode, | 77 const DisplayMode* mode, |
| 64 int x, | 78 const gfx::Point& origin) OVERRIDE; |
| 65 int y) OVERRIDE; | 79 virtual void CreateFrameBuffer(const gfx::Size& size) OVERRIDE; |
| 66 virtual void CreateFrameBuffer( | 80 virtual bool GetHDCPState(const DisplaySnapshot& output, |
| 67 int width, | 81 HDCPState* state) OVERRIDE; |
| 68 int height, | 82 virtual bool SetHDCPState(const DisplaySnapshot& output, |
| 69 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) OVERRIDE; | 83 HDCPState state) OVERRIDE; |
| 70 virtual bool GetHDCPState(const OutputConfigurator::OutputSnapshot& output, | |
| 71 ui::HDCPState* state) OVERRIDE; | |
| 72 virtual bool SetHDCPState(const OutputConfigurator::OutputSnapshot& output, | |
| 73 ui::HDCPState state) OVERRIDE; | |
| 74 | 84 |
| 75 virtual void AddObserver(NativeDisplayObserver* observer) OVERRIDE; | 85 virtual void AddObserver(NativeDisplayObserver* observer) OVERRIDE; |
| 76 virtual void RemoveObserver(NativeDisplayObserver* observer) OVERRIDE; | 86 virtual void RemoveObserver(NativeDisplayObserver* observer) OVERRIDE; |
| 77 | 87 |
| 78 private: | 88 private: |
| 79 class HelperDelegateX11; | 89 class HelperDelegateX11; |
| 80 class MessagePumpObserverX11; | 90 class MessagePumpObserverX11; |
| 81 | 91 |
| 82 // Initializes |mode_info| to contain details corresponding to |mode|. Returns | 92 // Parses all the modes made available by |screen_|. |
| 83 // true on success. | 93 void InitModes(); |
| 84 bool InitModeInfo(RRMode mode, OutputConfigurator::ModeInfo* mode_info); | |
| 85 | 94 |
| 86 // Helper method for GetOutputs() that returns an OutputSnapshot struct based | 95 // Helper method for GetOutputs() that returns an OutputSnapshot struct based |
| 87 // on the passed-in information. Further initialization is required (e.g. | 96 // on the passed-in information. |
| 88 // |selected_mode|, |mirror_mode|, and |touch_device_id|). | 97 DisplaySnapshotX11* InitDisplaySnapshot(RROutput id, |
| 89 OutputConfigurator::OutputSnapshot InitOutputSnapshot(RROutput id, | 98 XRROutputInfo* info, |
| 90 XRROutputInfo* info, | 99 RRCrtc* last_used_crtc, |
| 91 RRCrtc* last_used_crtc, | 100 int index); |
| 92 int index); | |
| 93 | 101 |
| 94 // Destroys unused CRTCs and parks used CRTCs in a way which allows a | 102 // Destroys unused CRTCs and parks used CRTCs in a way which allows a |
| 95 // framebuffer resize. This is faster than turning them off, resizing, | 103 // framebuffer resize. This is faster than turning them off, resizing, |
| 96 // then turning them back on. | 104 // then turning them back on. |
| 97 void DestroyUnusedCrtcs( | 105 void DestroyUnusedCrtcs(); |
| 98 const std::vector<OutputConfigurator::OutputSnapshot>& outputs); | |
| 99 | 106 |
| 100 bool ConfigureCrtc(RRCrtc crtc, RRMode mode, RROutput output, int x, int y); | 107 bool ConfigureCrtc(RRCrtc crtc, RRMode mode, RROutput output, int x, int y); |
| 101 | 108 |
| 102 // Returns whether |id| is configured to preserve aspect when scaling. | 109 // Returns whether |id| is configured to preserve aspect when scaling. |
| 103 bool IsOutputAspectPreservingScaling(RROutput id); | 110 bool IsOutputAspectPreservingScaling(RROutput id); |
| 104 | 111 |
| 105 Display* display_; | 112 Display* display_; |
| 106 Window window_; | 113 Window window_; |
| 107 | 114 |
| 108 // Initialized when the server is grabbed and freed when it's ungrabbed. | 115 // Initialized when the server is grabbed and freed when it's ungrabbed. |
| 109 XRRScreenResources* screen_; | 116 XRRScreenResources* screen_; |
| 110 | 117 |
| 118 std::map<RRMode, DisplayModeX11*> modes_; |
| 119 |
| 111 // Every time GetOutputs() is called we cache the updated list of outputs in | 120 // Every time GetOutputs() is called we cache the updated list of outputs in |
| 112 // |cached_outputs_| so that we can check for duplicate events rather than | 121 // |cached_outputs_| so that we can check for duplicate events rather than |
| 113 // propagate them. | 122 // propagate them. |
| 114 std::vector<OutputConfigurator::OutputSnapshot> cached_outputs_; | 123 ScopedVector<DisplaySnapshot> cached_outputs_; |
| 115 | 124 |
| 116 scoped_ptr<HelperDelegate> helper_delegate_; | 125 scoped_ptr<HelperDelegate> helper_delegate_; |
| 117 | 126 |
| 118 // Processes X11 display events associated with the root window and notifies | 127 // Processes X11 display events associated with the root window and notifies |
| 119 // |observers_| when a display change has occurred. | 128 // |observers_| when a display change has occurred. |
| 120 scoped_ptr<NativeDisplayEventDispatcherX11> message_pump_dispatcher_; | 129 scoped_ptr<NativeDisplayEventDispatcherX11> message_pump_dispatcher_; |
| 121 | 130 |
| 122 // Processes X11 display events that have no X11 window associated with it. | 131 // Processes X11 display events that have no X11 window associated with it. |
| 123 scoped_ptr<MessagePumpObserverX11> message_pump_observer_; | 132 scoped_ptr<MessagePumpObserverX11> message_pump_observer_; |
| 124 | 133 |
| 125 // List of observers waiting for display configuration change events. | 134 // List of observers waiting for display configuration change events. |
| 126 ObserverList<NativeDisplayObserver> observers_; | 135 ObserverList<NativeDisplayObserver> observers_; |
| 127 | 136 |
| 128 DISALLOW_COPY_AND_ASSIGN(NativeDisplayDelegateX11); | 137 DISALLOW_COPY_AND_ASSIGN(NativeDisplayDelegateX11); |
| 129 }; | 138 }; |
| 130 | 139 |
| 131 } // namespace ui | 140 } // namespace ui |
| 132 | 141 |
| 133 #endif // UI_DISPLAY_CHROMEOS_X11_NATIVE_DISPLAY_DELEGATE_X11_H_ | 142 #endif // UI_DISPLAY_CHROMEOS_X11_NATIVE_DISPLAY_DELEGATE_X11_H_ |
| OLD | NEW |