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