| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #include "components/mus/ws/user_display_manager.h" | |
| 6 | |
| 7 #include "components/mus/ws/display.h" | |
| 8 #include "components/mus/ws/display_manager.h" | |
| 9 #include "components/mus/ws/display_manager_delegate.h" | |
| 10 | |
| 11 namespace mus { | |
| 12 namespace ws { | |
| 13 | |
| 14 UserDisplayManager::UserDisplayManager(ws::DisplayManager* display_manager, | |
| 15 DisplayManagerDelegate* delegate, | |
| 16 const UserId& user_id) | |
| 17 : display_manager_(display_manager), | |
| 18 delegate_(delegate), | |
| 19 user_id_(user_id), | |
| 20 got_valid_frame_decorations_( | |
| 21 delegate->GetFrameDecorationsForUser(user_id, nullptr)), | |
| 22 current_cursor_location_(0) {} | |
| 23 | |
| 24 UserDisplayManager::~UserDisplayManager() {} | |
| 25 | |
| 26 void UserDisplayManager::OnFrameDecorationValuesChanged() { | |
| 27 if (!got_valid_frame_decorations_) { | |
| 28 got_valid_frame_decorations_ = true; | |
| 29 display_manager_observers_.ForAllPtrs([this]( | |
| 30 mojom::DisplayManagerObserver* observer) { CallOnDisplays(observer); }); | |
| 31 if (test_observer_) | |
| 32 CallOnDisplays(test_observer_); | |
| 33 return; | |
| 34 } | |
| 35 | |
| 36 mojo::Array<mojom::DisplayPtr> displays = GetAllDisplays(); | |
| 37 display_manager_observers_.ForAllPtrs( | |
| 38 [this, &displays](mojom::DisplayManagerObserver* observer) { | |
| 39 observer->OnDisplaysChanged(displays.Clone()); | |
| 40 }); | |
| 41 if (test_observer_) | |
| 42 test_observer_->OnDisplaysChanged(displays.Clone()); | |
| 43 } | |
| 44 | |
| 45 void UserDisplayManager::AddDisplayManagerBinding( | |
| 46 mojo::InterfaceRequest<mojom::DisplayManager> request) { | |
| 47 display_manager_bindings_.AddBinding(this, std::move(request)); | |
| 48 } | |
| 49 | |
| 50 void UserDisplayManager::OnWillDestroyDisplay(Display* display) { | |
| 51 if (!got_valid_frame_decorations_) | |
| 52 return; | |
| 53 | |
| 54 display_manager_observers_.ForAllPtrs( | |
| 55 [this, &display](mojom::DisplayManagerObserver* observer) { | |
| 56 observer->OnDisplayRemoved(display->id()); | |
| 57 }); | |
| 58 if (test_observer_) | |
| 59 test_observer_->OnDisplayRemoved(display->id()); | |
| 60 } | |
| 61 | |
| 62 void UserDisplayManager::OnMouseCursorLocationChanged(const gfx::Point& point) { | |
| 63 current_cursor_location_ = | |
| 64 static_cast<base::subtle::Atomic32>( | |
| 65 (point.x() & 0xFFFF) << 16 | (point.y() & 0xFFFF)); | |
| 66 if (cursor_location_memory()) { | |
| 67 base::subtle::NoBarrier_Store(cursor_location_memory(), | |
| 68 current_cursor_location_); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 void UserDisplayManager::OnDisplayUpdate(Display* display) { | |
| 73 if (!got_valid_frame_decorations_) | |
| 74 return; | |
| 75 | |
| 76 mojo::Array<mojom::DisplayPtr> displays(1); | |
| 77 displays[0] = display->ToMojomDisplay(); | |
| 78 delegate_->GetFrameDecorationsForUser( | |
| 79 user_id_, &(displays[0]->frame_decoration_values)); | |
| 80 display_manager_observers_.ForAllPtrs( | |
| 81 [this, &displays](mojom::DisplayManagerObserver* observer) { | |
| 82 observer->OnDisplaysChanged(displays.Clone()); | |
| 83 }); | |
| 84 if (test_observer_) | |
| 85 test_observer_->OnDisplaysChanged(displays.Clone()); | |
| 86 } | |
| 87 | |
| 88 mojo::ScopedSharedBufferHandle UserDisplayManager::GetCursorLocationMemory() { | |
| 89 if (!cursor_location_handle_.is_valid()) { | |
| 90 // Create our shared memory segment to share the cursor state with our | |
| 91 // window clients. | |
| 92 cursor_location_handle_ = | |
| 93 mojo::SharedBufferHandle::Create(sizeof(base::subtle::Atomic32)); | |
| 94 | |
| 95 if (!cursor_location_handle_.is_valid()) | |
| 96 return mojo::ScopedSharedBufferHandle(); | |
| 97 | |
| 98 cursor_location_mapping_ = | |
| 99 cursor_location_handle_->Map(sizeof(base::subtle::Atomic32)); | |
| 100 if (!cursor_location_mapping_) | |
| 101 return mojo::ScopedSharedBufferHandle(); | |
| 102 base::subtle::NoBarrier_Store(cursor_location_memory(), | |
| 103 current_cursor_location_); | |
| 104 } | |
| 105 | |
| 106 return cursor_location_handle_->Clone( | |
| 107 mojo::SharedBufferHandle::AccessMode::READ_ONLY); | |
| 108 } | |
| 109 | |
| 110 | |
| 111 void UserDisplayManager::OnObserverAdded( | |
| 112 mojom::DisplayManagerObserver* observer) { | |
| 113 // Many clients key off the frame decorations to size widgets. Wait for frame | |
| 114 // decorations before notifying so that we don't have to worry about clients | |
| 115 // resizing appropriately. | |
| 116 if (!got_valid_frame_decorations_) | |
| 117 return; | |
| 118 | |
| 119 CallOnDisplays(observer); | |
| 120 } | |
| 121 | |
| 122 mojo::Array<mojom::DisplayPtr> UserDisplayManager::GetAllDisplays() { | |
| 123 const std::set<Display*>& displays = display_manager_->displays(); | |
| 124 mojo::Array<mojom::DisplayPtr> display_ptrs(displays.size()); | |
| 125 { | |
| 126 size_t i = 0; | |
| 127 // TODO(sky): need ordering! | |
| 128 for (Display* display : displays) { | |
| 129 display_ptrs[i] = display->ToMojomDisplay(); | |
| 130 delegate_->GetFrameDecorationsForUser( | |
| 131 user_id_, &(display_ptrs[i]->frame_decoration_values)); | |
| 132 ++i; | |
| 133 } | |
| 134 } | |
| 135 return display_ptrs; | |
| 136 } | |
| 137 | |
| 138 void UserDisplayManager::CallOnDisplays( | |
| 139 mojom::DisplayManagerObserver* observer) { | |
| 140 observer->OnDisplays(GetAllDisplays()); | |
| 141 } | |
| 142 | |
| 143 void UserDisplayManager::AddObserver( | |
| 144 mojom::DisplayManagerObserverPtr observer) { | |
| 145 mojom::DisplayManagerObserver* observer_impl = observer.get(); | |
| 146 display_manager_observers_.AddPtr(std::move(observer)); | |
| 147 OnObserverAdded(observer_impl); | |
| 148 } | |
| 149 | |
| 150 } // namespace ws | |
| 151 } // namespace mus | |
| OLD | NEW |