| 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/chromeos/x11/native_display_delegate_x11.h" | 5 #include "ui/display/chromeos/x11/native_display_delegate_x11.h" |
| 6 | 6 |
| 7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 #include <X11/extensions/dpms.h> | 9 #include <X11/extensions/dpms.h> |
| 10 #include <X11/extensions/Xrandr.h> | 10 #include <X11/extensions/Xrandr.h> |
| 11 #include <X11/extensions/XInput2.h> | 11 #include <X11/extensions/XInput2.h> |
| 12 | 12 |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/message_loop/message_pump_x11.h" | 17 #include "base/message_loop/message_pump_x11.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "ui/display/chromeos/native_display_observer.h" | 19 #include "ui/display/chromeos/native_display_observer.h" |
| 20 #include "ui/display/chromeos/x11/display_mode_x11.h" | 20 #include "ui/display/chromeos/x11/display_mode_x11.h" |
| 21 #include "ui/display/chromeos/x11/display_snapshot_x11.h" | 21 #include "ui/display/chromeos/x11/display_snapshot_x11.h" |
| 22 #include "ui/display/chromeos/x11/display_util_x11.h" | 22 #include "ui/display/chromeos/x11/display_util_x11.h" |
| 23 #include "ui/display/chromeos/x11/native_display_event_dispatcher_x11.h" | 23 #include "ui/display/chromeos/x11/native_display_event_dispatcher_x11.h" |
| 24 #include "ui/display/x11/edid_parser_x11.h" | 24 #include "ui/display/x11/edid_parser_x11.h" |
| 25 #include "ui/events/platform/platform_event_source.h" |
| 25 #include "ui/gfx/x/x11_error_tracker.h" | 26 #include "ui/gfx/x/x11_error_tracker.h" |
| 26 | 27 |
| 27 namespace ui { | 28 namespace ui { |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 // DPI measurements. | 32 // DPI measurements. |
| 32 const float kMmInInch = 25.4; | 33 const float kMmInInch = 25.4; |
| 33 const float kDpi96 = 96.0; | 34 const float kDpi96 = 96.0; |
| 34 const float kPixelsToMmScale = kMmInInch / kDpi96; | 35 const float kPixelsToMmScale = kMmInInch / kDpi96; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 148 |
| 148 //////////////////////////////////////////////////////////////////////////////// | 149 //////////////////////////////////////////////////////////////////////////////// |
| 149 // NativeDisplayDelegateX11 implementation: | 150 // NativeDisplayDelegateX11 implementation: |
| 150 | 151 |
| 151 NativeDisplayDelegateX11::NativeDisplayDelegateX11() | 152 NativeDisplayDelegateX11::NativeDisplayDelegateX11() |
| 152 : display_(base::MessagePumpX11::GetDefaultXDisplay()), | 153 : display_(base::MessagePumpX11::GetDefaultXDisplay()), |
| 153 window_(DefaultRootWindow(display_)), | 154 window_(DefaultRootWindow(display_)), |
| 154 screen_(NULL) {} | 155 screen_(NULL) {} |
| 155 | 156 |
| 156 NativeDisplayDelegateX11::~NativeDisplayDelegateX11() { | 157 NativeDisplayDelegateX11::~NativeDisplayDelegateX11() { |
| 157 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow( | 158 if (ui::PlatformEventSource::GetInstance()) { |
| 158 message_pump_dispatcher_.get()); | 159 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher( |
| 160 platform_event_dispatcher_.get()); |
| 161 } |
| 159 base::MessagePumpX11::Current()->RemoveObserver(message_pump_observer_.get()); | 162 base::MessagePumpX11::Current()->RemoveObserver(message_pump_observer_.get()); |
| 160 | 163 |
| 161 STLDeleteContainerPairSecondPointers(modes_.begin(), modes_.end()); | 164 STLDeleteContainerPairSecondPointers(modes_.begin(), modes_.end()); |
| 162 } | 165 } |
| 163 | 166 |
| 164 void NativeDisplayDelegateX11::Initialize() { | 167 void NativeDisplayDelegateX11::Initialize() { |
| 165 int error_base_ignored = 0; | 168 int error_base_ignored = 0; |
| 166 int xrandr_event_base = 0; | 169 int xrandr_event_base = 0; |
| 167 XRRQueryExtension(display_, &xrandr_event_base, &error_base_ignored); | 170 XRRQueryExtension(display_, &xrandr_event_base, &error_base_ignored); |
| 168 | 171 |
| 169 helper_delegate_.reset(new HelperDelegateX11(this)); | 172 helper_delegate_.reset(new HelperDelegateX11(this)); |
| 170 message_pump_dispatcher_.reset(new NativeDisplayEventDispatcherX11( | 173 platform_event_dispatcher_.reset(new NativeDisplayEventDispatcherX11( |
| 171 helper_delegate_.get(), xrandr_event_base)); | 174 helper_delegate_.get(), xrandr_event_base)); |
| 172 message_pump_observer_.reset( | 175 message_pump_observer_.reset( |
| 173 new MessagePumpObserverX11(helper_delegate_.get())); | 176 new MessagePumpObserverX11(helper_delegate_.get())); |
| 174 | 177 |
| 175 base::MessagePumpX11::Current()->AddDispatcherForRootWindow( | 178 if (ui::PlatformEventSource::GetInstance()) { |
| 176 message_pump_dispatcher_.get()); | 179 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher( |
| 180 platform_event_dispatcher_.get()); |
| 181 } |
| 177 // We can't do this with a root window listener because XI_HierarchyChanged | 182 // We can't do this with a root window listener because XI_HierarchyChanged |
| 178 // messages don't have a target window. | 183 // messages don't have a target window. |
| 179 base::MessagePumpX11::Current()->AddObserver(message_pump_observer_.get()); | 184 base::MessagePumpX11::Current()->AddObserver(message_pump_observer_.get()); |
| 180 } | 185 } |
| 181 | 186 |
| 182 void NativeDisplayDelegateX11::GrabServer() { | 187 void NativeDisplayDelegateX11::GrabServer() { |
| 183 CHECK(!screen_) << "Server already grabbed"; | 188 CHECK(!screen_) << "Server already grabbed"; |
| 184 XGrabServer(display_); | 189 XGrabServer(display_); |
| 185 screen_ = XRRGetScreenResources(display_, window_); | 190 screen_ = XRRGetScreenResources(display_, window_); |
| 186 CHECK(screen_); | 191 CHECK(screen_); |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 | 648 |
| 644 void NativeDisplayDelegateX11::AddObserver(NativeDisplayObserver* observer) { | 649 void NativeDisplayDelegateX11::AddObserver(NativeDisplayObserver* observer) { |
| 645 observers_.AddObserver(observer); | 650 observers_.AddObserver(observer); |
| 646 } | 651 } |
| 647 | 652 |
| 648 void NativeDisplayDelegateX11::RemoveObserver(NativeDisplayObserver* observer) { | 653 void NativeDisplayDelegateX11::RemoveObserver(NativeDisplayObserver* observer) { |
| 649 observers_.RemoveObserver(observer); | 654 observers_.RemoveObserver(observer); |
| 650 } | 655 } |
| 651 | 656 |
| 652 } // namespace ui | 657 } // namespace ui |
| OLD | NEW |