OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 SERVICES_UI_WS_CURSOR_LOCATION_MANAGER_H_ |
| 6 #define SERVICES_UI_WS_CURSOR_LOCATION_MANAGER_H_ |
| 7 |
| 8 #include "base/atomicops.h" |
| 9 #include "base/macros.h" |
| 10 #include "mojo/public/cpp/system/buffer.h" |
| 11 |
| 12 namespace gfx { |
| 13 class Point; |
| 14 } |
| 15 |
| 16 namespace ui { |
| 17 namespace ws { |
| 18 |
| 19 // Manages a shared memory buffer that stores the cursor location. |
| 20 class CursorLocationManager { |
| 21 public: |
| 22 CursorLocationManager(); |
| 23 ~CursorLocationManager(); |
| 24 |
| 25 // Sets the current cursor location to |point|. Atomically writes the location |
| 26 // to shared memory. |
| 27 void OnMouseCursorLocationChanged(const gfx::Point& point); |
| 28 |
| 29 // Returns a read-only handle to the shared memory which contains the global |
| 30 // mouse cursor position. Each call returns a new handle. |
| 31 mojo::ScopedSharedBufferHandle GetCursorLocationMemory(); |
| 32 |
| 33 private: |
| 34 base::subtle::Atomic32* cursor_location_memory() { |
| 35 return reinterpret_cast<base::subtle::Atomic32*>( |
| 36 cursor_location_mapping_.get()); |
| 37 } |
| 38 |
| 39 // The current location of the cursor. This is always kept up to date so we |
| 40 // can atomically write this to |cursor_location_memory()| once it is created. |
| 41 base::subtle::Atomic32 current_cursor_location_ = 0; |
| 42 |
| 43 // A handle to a shared memory buffer that is one 32 bit integer long. We |
| 44 // share this with any client as the same user. This buffer is lazily |
| 45 // created on the first access. |
| 46 mojo::ScopedSharedBufferHandle cursor_location_handle_; |
| 47 |
| 48 // The one int32 in |cursor_location_handle_|. When we write to this |
| 49 // location, we must always write to it atomically. (On the other side of the |
| 50 // mojo connection, this data must be read atomically.) |
| 51 mojo::ScopedSharedBufferMapping cursor_location_mapping_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(CursorLocationManager); |
| 54 }; |
| 55 |
| 56 } // namespace ws |
| 57 } // namespace ui |
| 58 |
| 59 #endif // SERVICES_UI_WS_CURSOR_LOCATION_MANAGER_H_ |
OLD | NEW |