| 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 #include "ui/display/manager/chromeos/x11/native_display_event_dispatcher_x11.h" | 5 #include "ui/display/manager/chromeos/x11/native_display_event_dispatcher_x11.h" |
| 6 | 6 |
| 7 #include <X11/extensions/Xrandr.h> | 7 #include <X11/extensions/Xrandr.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/time/default_tick_clock.h" | 10 #include "base/time/default_tick_clock.h" |
| 11 #include "ui/display/manager/chromeos/x11/display_mode_x11.h" | 11 #include "ui/display/manager/chromeos/x11/display_mode_x11.h" |
| 12 #include "ui/display/manager/chromeos/x11/display_snapshot_x11.h" | 12 #include "ui/display/manager/chromeos/x11/display_snapshot_x11.h" |
| 13 #include "ui/events/platform/platform_event_source.h" | 13 #include "ui/events/platform/platform_event_source.h" |
| 14 | 14 |
| 15 namespace ui { | 15 namespace display { |
| 16 | 16 |
| 17 // static | 17 // static |
| 18 const int NativeDisplayEventDispatcherX11::kUseCacheAfterStartupMs = 7000; | 18 const int NativeDisplayEventDispatcherX11::kUseCacheAfterStartupMs = 7000; |
| 19 | 19 |
| 20 NativeDisplayEventDispatcherX11::NativeDisplayEventDispatcherX11( | 20 NativeDisplayEventDispatcherX11::NativeDisplayEventDispatcherX11( |
| 21 NativeDisplayDelegateX11::HelperDelegate* delegate, | 21 NativeDisplayDelegateX11::HelperDelegate* delegate, |
| 22 int xrandr_event_base) | 22 int xrandr_event_base) |
| 23 : delegate_(delegate), | 23 : delegate_(delegate), |
| 24 xrandr_event_base_(xrandr_event_base), | 24 xrandr_event_base_(xrandr_event_base), |
| 25 tick_clock_(new base::DefaultTickClock) { | 25 tick_clock_(new base::DefaultTickClock) { |
| 26 startup_time_ = tick_clock_->NowTicks(); | 26 startup_time_ = tick_clock_->NowTicks(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 NativeDisplayEventDispatcherX11::~NativeDisplayEventDispatcherX11() {} | 29 NativeDisplayEventDispatcherX11::~NativeDisplayEventDispatcherX11() {} |
| 30 | 30 |
| 31 bool NativeDisplayEventDispatcherX11::CanDispatchEvent( | 31 bool NativeDisplayEventDispatcherX11::CanDispatchEvent( |
| 32 const PlatformEvent& event) { | 32 const ui::PlatformEvent& event) { |
| 33 return (event->type - xrandr_event_base_ == RRScreenChangeNotify) || | 33 return (event->type - xrandr_event_base_ == RRScreenChangeNotify) || |
| 34 (event->type - xrandr_event_base_ == RRNotify); | 34 (event->type - xrandr_event_base_ == RRNotify); |
| 35 } | 35 } |
| 36 | 36 |
| 37 uint32_t NativeDisplayEventDispatcherX11::DispatchEvent( | 37 uint32_t NativeDisplayEventDispatcherX11::DispatchEvent( |
| 38 const PlatformEvent& event) { | 38 const ui::PlatformEvent& event) { |
| 39 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { | 39 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { |
| 40 VLOG(1) << "Received RRScreenChangeNotify event"; | 40 VLOG(1) << "Received RRScreenChangeNotify event"; |
| 41 delegate_->UpdateXRandRConfiguration(event); | 41 delegate_->UpdateXRandRConfiguration(event); |
| 42 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 42 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Bail out early for everything except RRNotify_OutputChange events | 45 // Bail out early for everything except RRNotify_OutputChange events |
| 46 // about an output getting connected or disconnected. | 46 // about an output getting connected or disconnected. |
| 47 if (event->type - xrandr_event_base_ != RRNotify) | 47 if (event->type - xrandr_event_base_ != RRNotify) |
| 48 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 48 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 75 ++it) { | 75 ++it) { |
| 76 const DisplaySnapshotX11* x11_output = | 76 const DisplaySnapshotX11* x11_output = |
| 77 static_cast<const DisplaySnapshotX11*>(*it); | 77 static_cast<const DisplaySnapshotX11*>(*it); |
| 78 const DisplayModeX11* x11_mode = | 78 const DisplayModeX11* x11_mode = |
| 79 static_cast<const DisplayModeX11*>(x11_output->current_mode()); | 79 static_cast<const DisplayModeX11*>(x11_output->current_mode()); |
| 80 RRMode mode_id = x11_mode ? x11_mode->mode_id() : None; | 80 RRMode mode_id = x11_mode ? x11_mode->mode_id() : None; |
| 81 | 81 |
| 82 // Update if we failed to fetch the external display's ID before. | 82 // Update if we failed to fetch the external display's ID before. |
| 83 // Internal display's EDID should always be available. | 83 // Internal display's EDID should always be available. |
| 84 bool display_id_needs_update = | 84 bool display_id_needs_update = |
| 85 x11_output->type() != ui::DISPLAY_CONNECTION_TYPE_INTERNAL && | 85 x11_output->type() != DISPLAY_CONNECTION_TYPE_INTERNAL && |
| 86 !x11_output->display_id(); | 86 !x11_output->display_id(); |
| 87 | 87 |
| 88 if (x11_output->output() == output_change_event->output) { | 88 if (x11_output->output() == output_change_event->output) { |
| 89 if (connected && x11_output->crtc() == output_change_event->crtc && | 89 if (connected && x11_output->crtc() == output_change_event->crtc && |
| 90 mode_id == output_change_event->mode && | 90 mode_id == output_change_event->mode && |
| 91 !display_id_needs_update) { | 91 !display_id_needs_update) { |
| 92 VLOG(1) << "Ignoring event describing already-cached state"; | 92 VLOG(1) << "Ignoring event describing already-cached state"; |
| 93 return POST_DISPATCH_PERFORM_DEFAULT; | 93 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 94 } | 94 } |
| 95 found_changed_output = true; | 95 found_changed_output = true; |
| 96 break; | 96 break; |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 if (!connected && !found_changed_output) { | 100 if (!connected && !found_changed_output) { |
| 101 VLOG(1) << "Ignoring event describing already-disconnected output"; | 101 VLOG(1) << "Ignoring event describing already-disconnected output"; |
| 102 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 102 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 delegate_->NotifyDisplayObservers(); | 106 delegate_->NotifyDisplayObservers(); |
| 107 | 107 |
| 108 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 108 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void NativeDisplayEventDispatcherX11::SetTickClockForTest( | 111 void NativeDisplayEventDispatcherX11::SetTickClockForTest( |
| 112 std::unique_ptr<base::TickClock> tick_clock) { | 112 std::unique_ptr<base::TickClock> tick_clock) { |
| 113 tick_clock_ = std::move(tick_clock); | 113 tick_clock_ = std::move(tick_clock); |
| 114 startup_time_ = tick_clock_->NowTicks(); | 114 startup_time_ = tick_clock_->NowTicks(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace ui | 117 } // namespace display |
| OLD | NEW |