| 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 "components/mus/ws/user_display_manager.h" | 5 #include "components/mus/ws/user_display_manager.h" |
| 6 | 6 |
| 7 #include "components/mus/ws/display.h" | 7 #include "components/mus/ws/display.h" |
| 8 #include "components/mus/ws/display_manager.h" | 8 #include "components/mus/ws/display_manager.h" |
| 9 #include "components/mus/ws/window_manager_state.h" | 9 #include "components/mus/ws/window_manager_state.h" |
| 10 | 10 |
| 11 namespace mus { | 11 namespace mus { |
| 12 namespace ws { | 12 namespace ws { |
| 13 | 13 |
| 14 UserDisplayManager::UserDisplayManager(ws::DisplayManager* display_manager, | 14 UserDisplayManager::UserDisplayManager(ws::DisplayManager* display_manager, |
| 15 const UserId& user_id) | 15 const UserId& user_id) |
| 16 : display_manager_(display_manager), user_id_(user_id) { | 16 : display_manager_(display_manager), |
| 17 user_id_(user_id), |
| 18 current_cursor_location_(0), |
| 19 cursor_location_memory_(nullptr) { |
| 17 for (const WindowManagerState* wms : GetWindowManagerStatesForUser()) { | 20 for (const WindowManagerState* wms : GetWindowManagerStatesForUser()) { |
| 18 if (wms->got_frame_decoration_values()) { | 21 if (wms->got_frame_decoration_values()) { |
| 19 got_valid_frame_decorations_ = true; | 22 got_valid_frame_decorations_ = true; |
| 20 break; | 23 break; |
| 21 } | 24 } |
| 22 } | 25 } |
| 23 } | 26 } |
| 24 | 27 |
| 25 UserDisplayManager::~UserDisplayManager() {} | 28 UserDisplayManager::~UserDisplayManager() {} |
| 26 | 29 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 55 } | 58 } |
| 56 | 59 |
| 57 display_manager_observers_.ForAllPtrs( | 60 display_manager_observers_.ForAllPtrs( |
| 58 [this, &display](mojom::DisplayManagerObserver* observer) { | 61 [this, &display](mojom::DisplayManagerObserver* observer) { |
| 59 observer->OnDisplayRemoved(display->id()); | 62 observer->OnDisplayRemoved(display->id()); |
| 60 }); | 63 }); |
| 61 if (test_observer_) | 64 if (test_observer_) |
| 62 test_observer_->OnDisplayRemoved(display->id()); | 65 test_observer_->OnDisplayRemoved(display->id()); |
| 63 } | 66 } |
| 64 | 67 |
| 68 void UserDisplayManager::OnMouseCursorLocationChanged(const gfx::Point& point) { |
| 69 current_cursor_location_ = |
| 70 static_cast<base::subtle::Atomic32>( |
| 71 (point.x() & 0xFFFF) << 16 | (point.y() & 0xFFFF)); |
| 72 if (cursor_location_memory_) { |
| 73 base::subtle::NoBarrier_Store(cursor_location_memory_, |
| 74 current_cursor_location_); |
| 75 } |
| 76 } |
| 77 |
| 78 mojo::ScopedSharedBufferHandle UserDisplayManager::GetCursorLocationMemory() { |
| 79 if (!cursor_location_memory_) { |
| 80 // Create our shared memory segment to share the cursor state with our |
| 81 // window clients. |
| 82 MojoResult result = mojo::CreateSharedBuffer(nullptr, |
| 83 sizeof(base::subtle::Atomic32), |
| 84 &cursor_location_handle_); |
| 85 if (result != MOJO_RESULT_OK) |
| 86 return mojo::ScopedSharedBufferHandle(); |
| 87 DCHECK(cursor_location_handle_.is_valid()); |
| 88 |
| 89 result = mojo::MapBuffer(cursor_location_handle_.get(), 0, |
| 90 sizeof(base::subtle::Atomic32), |
| 91 reinterpret_cast<void**>(&cursor_location_memory_), |
| 92 MOJO_MAP_BUFFER_FLAG_NONE); |
| 93 if (result != MOJO_RESULT_OK) |
| 94 return mojo::ScopedSharedBufferHandle(); |
| 95 DCHECK(cursor_location_memory_); |
| 96 |
| 97 base::subtle::NoBarrier_Store(cursor_location_memory_, |
| 98 current_cursor_location_); |
| 99 } |
| 100 |
| 101 mojo::ScopedSharedBufferHandle duped; |
| 102 MojoDuplicateBufferHandleOptions options = { |
| 103 sizeof(MojoDuplicateBufferHandleOptions), |
| 104 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY |
| 105 }; |
| 106 MojoResult result = mojo::DuplicateBuffer(cursor_location_handle_.get(), |
| 107 &options, &duped); |
| 108 if (result != MOJO_RESULT_OK) |
| 109 return mojo::ScopedSharedBufferHandle(); |
| 110 DCHECK(duped.is_valid()); |
| 111 |
| 112 return duped; |
| 113 } |
| 114 |
| 115 |
| 65 std::set<const WindowManagerState*> | 116 std::set<const WindowManagerState*> |
| 66 UserDisplayManager::GetWindowManagerStatesForUser() const { | 117 UserDisplayManager::GetWindowManagerStatesForUser() const { |
| 67 std::set<const WindowManagerState*> result; | 118 std::set<const WindowManagerState*> result; |
| 68 for (const Display* display : display_manager_->displays()) { | 119 for (const Display* display : display_manager_->displays()) { |
| 69 const WindowManagerState* wms = | 120 const WindowManagerState* wms = |
| 70 display->GetWindowManagerStateForUser(user_id_); | 121 display->GetWindowManagerStateForUser(user_id_); |
| 71 if (wms && wms->got_frame_decoration_values()) | 122 if (wms && wms->got_frame_decoration_values()) |
| 72 result.insert(wms); | 123 result.insert(wms); |
| 73 } | 124 } |
| 74 return result; | 125 return result; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 166 |
| 116 void UserDisplayManager::AddObserver( | 167 void UserDisplayManager::AddObserver( |
| 117 mojom::DisplayManagerObserverPtr observer) { | 168 mojom::DisplayManagerObserverPtr observer) { |
| 118 mojom::DisplayManagerObserver* observer_impl = observer.get(); | 169 mojom::DisplayManagerObserver* observer_impl = observer.get(); |
| 119 display_manager_observers_.AddPtr(std::move(observer)); | 170 display_manager_observers_.AddPtr(std::move(observer)); |
| 120 OnObserverAdded(observer_impl); | 171 OnObserverAdded(observer_impl); |
| 121 } | 172 } |
| 122 | 173 |
| 123 } // namespace ws | 174 } // namespace ws |
| 124 } // namespace mus | 175 } // namespace mus |
| OLD | NEW |