| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "services/ui/ws/user_display_manager.h" | 5 #include "services/ui/ws/user_display_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "services/ui/display/platform_screen.h" |
| 9 #include "services/ui/ws/display.h" | 10 #include "services/ui/ws/display.h" |
| 10 #include "services/ui/ws/display_manager.h" | 11 #include "services/ui/ws/display_manager.h" |
| 11 #include "services/ui/ws/user_display_manager_delegate.h" | 12 #include "services/ui/ws/user_display_manager_delegate.h" |
| 12 | 13 |
| 13 namespace ui { | 14 namespace ui { |
| 14 namespace ws { | 15 namespace ws { |
| 15 | 16 |
| 16 UserDisplayManager::UserDisplayManager(ws::DisplayManager* display_manager, | 17 UserDisplayManager::UserDisplayManager(ws::DisplayManager* display_manager, |
| 17 UserDisplayManagerDelegate* delegate, | 18 UserDisplayManagerDelegate* delegate, |
| 18 const UserId& user_id) | 19 const UserId& user_id) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 42 }); | 43 }); |
| 43 if (test_observer_) | 44 if (test_observer_) |
| 44 test_observer_->OnDisplaysChanged(displays.Clone()); | 45 test_observer_->OnDisplaysChanged(displays.Clone()); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void UserDisplayManager::AddDisplayManagerBinding( | 48 void UserDisplayManager::AddDisplayManagerBinding( |
| 48 mojo::InterfaceRequest<mojom::DisplayManager> request) { | 49 mojo::InterfaceRequest<mojom::DisplayManager> request) { |
| 49 display_manager_bindings_.AddBinding(this, std::move(request)); | 50 display_manager_bindings_.AddBinding(this, std::move(request)); |
| 50 } | 51 } |
| 51 | 52 |
| 53 void UserDisplayManager::OnDisplayUpdate(Display* display) { |
| 54 if (!got_valid_frame_decorations_) |
| 55 return; |
| 56 |
| 57 mojo::Array<mojom::WsDisplayPtr> displays(1); |
| 58 displays[0] = GetWsDisplayPtr(*display); |
| 59 |
| 60 display_manager_observers_.ForAllPtrs( |
| 61 [&displays](mojom::DisplayManagerObserver* observer) { |
| 62 observer->OnDisplaysChanged(displays.Clone()); |
| 63 }); |
| 64 if (test_observer_) |
| 65 test_observer_->OnDisplaysChanged(displays.Clone()); |
| 66 } |
| 67 |
| 52 void UserDisplayManager::OnWillDestroyDisplay(Display* display) { | 68 void UserDisplayManager::OnWillDestroyDisplay(Display* display) { |
| 53 if (!got_valid_frame_decorations_) | 69 if (!got_valid_frame_decorations_) |
| 54 return; | 70 return; |
| 55 | 71 |
| 56 display_manager_observers_.ForAllPtrs( | 72 display_manager_observers_.ForAllPtrs( |
| 57 [this, &display](mojom::DisplayManagerObserver* observer) { | 73 [&display](mojom::DisplayManagerObserver* observer) { |
| 58 observer->OnDisplayRemoved(display->GetId()); | 74 observer->OnDisplayRemoved(display->GetId()); |
| 59 }); | 75 }); |
| 60 if (test_observer_) | 76 if (test_observer_) |
| 61 test_observer_->OnDisplayRemoved(display->GetId()); | 77 test_observer_->OnDisplayRemoved(display->GetId()); |
| 62 } | 78 } |
| 63 | 79 |
| 80 void UserDisplayManager::OnPrimaryDisplayChanged(int64_t primary_display_id) { |
| 81 if (!got_valid_frame_decorations_) |
| 82 return; |
| 83 |
| 84 display_manager_observers_.ForAllPtrs( |
| 85 [primary_display_id](mojom::DisplayManagerObserver* observer) { |
| 86 observer->OnPrimaryDisplayChanged(primary_display_id); |
| 87 }); |
| 88 if (test_observer_) |
| 89 test_observer_->OnPrimaryDisplayChanged(primary_display_id); |
| 90 } |
| 91 |
| 64 void UserDisplayManager::OnMouseCursorLocationChanged(const gfx::Point& point) { | 92 void UserDisplayManager::OnMouseCursorLocationChanged(const gfx::Point& point) { |
| 65 current_cursor_location_ = | 93 current_cursor_location_ = |
| 66 static_cast<base::subtle::Atomic32>( | 94 static_cast<base::subtle::Atomic32>( |
| 67 (point.x() & 0xFFFF) << 16 | (point.y() & 0xFFFF)); | 95 (point.x() & 0xFFFF) << 16 | (point.y() & 0xFFFF)); |
| 68 if (cursor_location_memory()) { | 96 if (cursor_location_memory()) { |
| 69 base::subtle::NoBarrier_Store(cursor_location_memory(), | 97 base::subtle::NoBarrier_Store(cursor_location_memory(), |
| 70 current_cursor_location_); | 98 current_cursor_location_); |
| 71 } | 99 } |
| 72 } | 100 } |
| 73 | 101 |
| 74 void UserDisplayManager::OnDisplayUpdate(Display* display) { | |
| 75 if (!got_valid_frame_decorations_) | |
| 76 return; | |
| 77 | |
| 78 mojo::Array<mojom::WsDisplayPtr> displays(1); | |
| 79 displays[0] = display->ToWsDisplay(); | |
| 80 delegate_->GetFrameDecorationsForUser( | |
| 81 user_id_, &(displays[0]->frame_decoration_values)); | |
| 82 display_manager_observers_.ForAllPtrs( | |
| 83 [this, &displays](mojom::DisplayManagerObserver* observer) { | |
| 84 observer->OnDisplaysChanged(displays.Clone()); | |
| 85 }); | |
| 86 if (test_observer_) | |
| 87 test_observer_->OnDisplaysChanged(displays.Clone()); | |
| 88 } | |
| 89 | |
| 90 mojo::ScopedSharedBufferHandle UserDisplayManager::GetCursorLocationMemory() { | 102 mojo::ScopedSharedBufferHandle UserDisplayManager::GetCursorLocationMemory() { |
| 91 if (!cursor_location_handle_.is_valid()) { | 103 if (!cursor_location_handle_.is_valid()) { |
| 92 // Create our shared memory segment to share the cursor state with our | 104 // Create our shared memory segment to share the cursor state with our |
| 93 // window clients. | 105 // window clients. |
| 94 cursor_location_handle_ = | 106 cursor_location_handle_ = |
| 95 mojo::SharedBufferHandle::Create(sizeof(base::subtle::Atomic32)); | 107 mojo::SharedBufferHandle::Create(sizeof(base::subtle::Atomic32)); |
| 96 | 108 |
| 97 if (!cursor_location_handle_.is_valid()) | 109 if (!cursor_location_handle_.is_valid()) |
| 98 return mojo::ScopedSharedBufferHandle(); | 110 return mojo::ScopedSharedBufferHandle(); |
| 99 | 111 |
| 100 cursor_location_mapping_ = | 112 cursor_location_mapping_ = |
| 101 cursor_location_handle_->Map(sizeof(base::subtle::Atomic32)); | 113 cursor_location_handle_->Map(sizeof(base::subtle::Atomic32)); |
| 102 if (!cursor_location_mapping_) | 114 if (!cursor_location_mapping_) |
| 103 return mojo::ScopedSharedBufferHandle(); | 115 return mojo::ScopedSharedBufferHandle(); |
| 104 base::subtle::NoBarrier_Store(cursor_location_memory(), | 116 base::subtle::NoBarrier_Store(cursor_location_memory(), |
| 105 current_cursor_location_); | 117 current_cursor_location_); |
| 106 } | 118 } |
| 107 | 119 |
| 108 return cursor_location_handle_->Clone( | 120 return cursor_location_handle_->Clone( |
| 109 mojo::SharedBufferHandle::AccessMode::READ_ONLY); | 121 mojo::SharedBufferHandle::AccessMode::READ_ONLY); |
| 110 } | 122 } |
| 111 | 123 |
| 112 | |
| 113 void UserDisplayManager::OnObserverAdded( | 124 void UserDisplayManager::OnObserverAdded( |
| 114 mojom::DisplayManagerObserver* observer) { | 125 mojom::DisplayManagerObserver* observer) { |
| 115 // Many clients key off the frame decorations to size widgets. Wait for frame | 126 // Many clients key off the frame decorations to size widgets. Wait for frame |
| 116 // decorations before notifying so that we don't have to worry about clients | 127 // decorations before notifying so that we don't have to worry about clients |
| 117 // resizing appropriately. | 128 // resizing appropriately. |
| 118 if (!got_valid_frame_decorations_) | 129 if (!got_valid_frame_decorations_) |
| 119 return; | 130 return; |
| 120 | 131 |
| 121 CallOnDisplays(observer); | 132 CallOnDisplays(observer); |
| 122 } | 133 } |
| 123 | 134 |
| 135 mojom::WsDisplayPtr UserDisplayManager::GetWsDisplayPtr( |
| 136 const Display& display) { |
| 137 mojom::WsDisplayPtr ws_display = mojom::WsDisplay::New(); |
| 138 ws_display->display = display.ToDisplay(); |
| 139 delegate_->GetFrameDecorationsForUser(user_id_, |
| 140 &ws_display->frame_decoration_values); |
| 141 return ws_display; |
| 142 } |
| 143 |
| 124 mojo::Array<mojom::WsDisplayPtr> UserDisplayManager::GetAllDisplays() { | 144 mojo::Array<mojom::WsDisplayPtr> UserDisplayManager::GetAllDisplays() { |
| 125 const std::set<Display*>& displays = display_manager_->displays(); | 145 const auto& displays = display_manager_->displays(); |
| 126 mojo::Array<mojom::WsDisplayPtr> display_ptrs(displays.size()); | 146 mojo::Array<mojom::WsDisplayPtr> display_ptrs(displays.size()); |
| 127 { | 147 |
| 128 size_t i = 0; | 148 size_t i = 0; |
| 129 // TODO(sky): need ordering! | 149 // TODO(sky): need ordering! |
| 130 for (Display* display : displays) { | 150 for (Display* display : displays) { |
| 131 display_ptrs[i] = display->ToWsDisplay(); | 151 display_ptrs[i] = GetWsDisplayPtr(*display); |
| 132 delegate_->GetFrameDecorationsForUser( | 152 ++i; |
| 133 user_id_, &(display_ptrs[i]->frame_decoration_values)); | |
| 134 ++i; | |
| 135 } | |
| 136 } | 153 } |
| 154 |
| 137 return display_ptrs; | 155 return display_ptrs; |
| 138 } | 156 } |
| 139 | 157 |
| 140 void UserDisplayManager::CallOnDisplays( | 158 void UserDisplayManager::CallOnDisplays( |
| 141 mojom::DisplayManagerObserver* observer) { | 159 mojom::DisplayManagerObserver* observer) { |
| 142 observer->OnDisplays(GetAllDisplays()); | 160 // TODO(kylechar): Pass internal display id to clients here. |
| 161 observer->OnDisplays( |
| 162 GetAllDisplays(), |
| 163 display::PlatformScreen::GetInstance()->GetPrimaryDisplayId(), |
| 164 display::Display::kInvalidDisplayID); |
| 143 } | 165 } |
| 144 | 166 |
| 145 void UserDisplayManager::AddObserver( | 167 void UserDisplayManager::AddObserver( |
| 146 mojom::DisplayManagerObserverPtr observer) { | 168 mojom::DisplayManagerObserverPtr observer) { |
| 147 mojom::DisplayManagerObserver* observer_impl = observer.get(); | 169 mojom::DisplayManagerObserver* observer_impl = observer.get(); |
| 148 display_manager_observers_.AddPtr(std::move(observer)); | 170 display_manager_observers_.AddPtr(std::move(observer)); |
| 149 OnObserverAdded(observer_impl); | 171 OnObserverAdded(observer_impl); |
| 150 } | 172 } |
| 151 | 173 |
| 152 } // namespace ws | 174 } // namespace ws |
| 153 } // namespace ui | 175 } // namespace ui |
| OLD | NEW |