| 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 #ifndef COMPONENTS_MUS_WS_USER_DISPLAY_MANAGER_H_ | |
| 6 #define COMPONENTS_MUS_WS_USER_DISPLAY_MANAGER_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 | |
| 10 #include "base/atomicops.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "components/mus/public/interfaces/display.mojom.h" | |
| 13 #include "components/mus/ws/user_id.h" | |
| 14 #include "mojo/public/cpp/bindings/binding_set.h" | |
| 15 #include "mojo/public/cpp/bindings/interface_ptr_set.h" | |
| 16 | |
| 17 namespace gfx { | |
| 18 class Point; | |
| 19 } | |
| 20 | |
| 21 namespace mus { | |
| 22 namespace ws { | |
| 23 | |
| 24 class Display; | |
| 25 class DisplayManager; | |
| 26 class DisplayManagerDelegate; | |
| 27 | |
| 28 namespace test { | |
| 29 class UserDisplayManagerTestApi; | |
| 30 } | |
| 31 | |
| 32 // Provides per user display state. | |
| 33 class UserDisplayManager : public mojom::DisplayManager { | |
| 34 public: | |
| 35 UserDisplayManager(ws::DisplayManager* display_manager, | |
| 36 DisplayManagerDelegate* delegate, | |
| 37 const UserId& user_id); | |
| 38 ~UserDisplayManager() override; | |
| 39 | |
| 40 // Called when the frame decorations for this user change. | |
| 41 void OnFrameDecorationValuesChanged(); | |
| 42 | |
| 43 void AddDisplayManagerBinding( | |
| 44 mojo::InterfaceRequest<mojom::DisplayManager> request); | |
| 45 | |
| 46 // Called by Display prior to |display| being removed and destroyed. | |
| 47 void OnWillDestroyDisplay(Display* display); | |
| 48 | |
| 49 // Called from WindowManagerState when its EventDispatcher receives a mouse | |
| 50 // event. | |
| 51 void OnMouseCursorLocationChanged(const gfx::Point& point); | |
| 52 | |
| 53 // Called when something about the display (e.g. pixel-ratio, size) changes. | |
| 54 void OnDisplayUpdate(Display* display); | |
| 55 | |
| 56 // Returns a read-only handle to the shared memory which contains the global | |
| 57 // mouse cursor position. Each call returns a new handle. | |
| 58 mojo::ScopedSharedBufferHandle GetCursorLocationMemory(); | |
| 59 | |
| 60 private: | |
| 61 friend class test::UserDisplayManagerTestApi; | |
| 62 | |
| 63 // Called when a new observer is added. If frame decorations are available | |
| 64 // notifies the observer immediately. | |
| 65 void OnObserverAdded(mojom::DisplayManagerObserver* observer); | |
| 66 | |
| 67 mojo::Array<mojom::DisplayPtr> GetAllDisplays(); | |
| 68 | |
| 69 // Calls OnDisplays() on |observer|. | |
| 70 void CallOnDisplays(mojom::DisplayManagerObserver* observer); | |
| 71 | |
| 72 // Overriden from mojom::DisplayManager: | |
| 73 void AddObserver(mojom::DisplayManagerObserverPtr observer) override; | |
| 74 | |
| 75 base::subtle::Atomic32* cursor_location_memory() { | |
| 76 return reinterpret_cast<base::subtle::Atomic32*>( | |
| 77 cursor_location_mapping_.get()); | |
| 78 } | |
| 79 | |
| 80 ws::DisplayManager* display_manager_; | |
| 81 | |
| 82 DisplayManagerDelegate* delegate_; | |
| 83 | |
| 84 const UserId user_id_; | |
| 85 | |
| 86 // Set to true the first time at least one Display has valid frame values. | |
| 87 bool got_valid_frame_decorations_; | |
| 88 | |
| 89 mojo::BindingSet<mojom::DisplayManager> display_manager_bindings_; | |
| 90 | |
| 91 // WARNING: only use these once |got_valid_frame_decorations_| is true. | |
| 92 mojo::InterfacePtrSet<mojom::DisplayManagerObserver> | |
| 93 display_manager_observers_; | |
| 94 | |
| 95 // Observer used for tests. | |
| 96 mojom::DisplayManagerObserver* test_observer_ = nullptr; | |
| 97 | |
| 98 // The current location of the cursor. This is always kept up to date so we | |
| 99 // can atomically write this to |cursor_location_memory()| once it is created. | |
| 100 base::subtle::Atomic32 current_cursor_location_; | |
| 101 | |
| 102 // A handle to a shared memory buffer that is one 64 bit integer long. We | |
| 103 // share this with any client as the same user. This buffer is lazily | |
| 104 // created on the first access. | |
| 105 mojo::ScopedSharedBufferHandle cursor_location_handle_; | |
| 106 | |
| 107 // The one int32 in |cursor_location_handle_|. When we write to this | |
| 108 // location, we must always write to it atomically. (On the other side of the | |
| 109 // mojo connection, this data must be read atomically.) | |
| 110 mojo::ScopedSharedBufferMapping cursor_location_mapping_; | |
| 111 | |
| 112 DISALLOW_COPY_AND_ASSIGN(UserDisplayManager); | |
| 113 }; | |
| 114 | |
| 115 } // namespace ws | |
| 116 } // namespace mus | |
| 117 | |
| 118 #endif // COMPONENTS_MUS_WS_USER_DISPLAY_MANAGER_H_ | |
| OLD | NEW |