Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Unified Diff: services/ui/ws/cursor_location_manager.h

Issue 2696963003: Split cursor location from UserDisplayManager. (Closed)
Patch Set: Fixes. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: services/ui/ws/cursor_location_manager.h
diff --git a/services/ui/ws/cursor_location_manager.h b/services/ui/ws/cursor_location_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..69cf29b8cac5868d11bd7862c3402f9238460b68
--- /dev/null
+++ b/services/ui/ws/cursor_location_manager.h
@@ -0,0 +1,56 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SERVICES_UI_WS_CURSOR_LOCATION_MANAGER_H_
+#define SERVICES_UI_WS_CURSOR_LOCATION_MANAGER_H_
+
+#include "base/atomicops.h"
+#include "base/macros.h"
+#include "mojo/public/cpp/system/buffer.h"
+#include "ui/gfx/geometry/point.h"
msw 2017/02/16 21:19:49 nit: use a fwd decl instead
kylechar 2017/02/16 22:06:56 Done.
+
+namespace ui {
+namespace ws {
+
+// Manages a shared memory buffer that stores the cursor location.
+class CursorLocationManager {
+ public:
+ CursorLocationManager();
+ ~CursorLocationManager();
+
+ // Sets the current cursor location to |point|. Atomically writes the location
+ // to shared memory.
+ void OnMouseCursorLocationChanged(const gfx::Point& point);
+
+ // Returns a read-only handle to the shared memory which contains the global
+ // mouse cursor position. Each call returns a new handle.
+ mojo::ScopedSharedBufferHandle GetCursorLocationMemory();
+
+ private:
+ base::subtle::Atomic32* cursor_location_memory() {
+ return reinterpret_cast<base::subtle::Atomic32*>(
+ cursor_location_mapping_.get());
+ }
+
+ // The current location of the cursor. This is always kept up to date so we
+ // can atomically write this to |cursor_location_memory()| once it is created.
+ base::subtle::Atomic32 current_cursor_location_ = 0;
+
+ // A handle to a shared memory buffer that is one 32 bit integer long. We
+ // share this with any client as the same user. This buffer is lazily
+ // created on the first access.
+ mojo::ScopedSharedBufferHandle cursor_location_handle_;
+
+ // The one int32 in |cursor_location_handle_|. When we write to this
+ // location, we must always write to it atomically. (On the other side of the
+ // mojo connection, this data must be read atomically.)
+ mojo::ScopedSharedBufferMapping cursor_location_mapping_;
+
+ DISALLOW_COPY_AND_ASSIGN(CursorLocationManager);
+};
+
+} // namespace ws
+} // namespace ui
+
+#endif // SERVICES_UI_WS_CURSOR_LOCATION_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698