blob: 3222bfd78a49b8662e9b70f1c3fc7cf14e94e26b [file] [log] [blame]
Scott Violet4490a052018-04-24 18:12:051// 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 UI_AURA_MOUSE_LOCATION_MANAGER_H_
6#define UI_AURA_MOUSE_LOCATION_MANAGER_H_
7
8#include "base/atomicops.h"
9#include "base/macros.h"
10#include "mojo/public/cpp/system/buffer.h"
11
12namespace gfx {
13class Point;
14}
15
16namespace aura {
17
18// Manages a shared memory buffer that stores the mouse location. It is
19// expected Env calls SetMouseLocation() any time the location of the mouse
20// changes.
21class MouseLocationManager {
22 public:
23 MouseLocationManager();
24 ~MouseLocationManager();
25
26 // Sets the current mouse location to |point|. Atomically writes the location
27 // to shared memory. |point| should be in screen-coord and DIP.
28 void SetMouseLocation(const gfx::Point& point_in_dip);
29
30 // Returns a read-only handle to the shared memory which contains the global
31 // mouse position. Each call returns a new handle.
32 mojo::ScopedSharedBufferHandle GetMouseLocationMemory();
33
34 private:
35 base::subtle::Atomic32* mouse_location_memory() {
36 return reinterpret_cast<base::subtle::Atomic32*>(
37 mouse_location_mapping_.get());
38 }
39
40 // The current location of the mouse. This is always kept up to date so we
41 // can atomically write this to |mouse_location_memory()| once it is created.
42 base::subtle::Atomic32 current_mouse_location_ = 0;
43
44 // A handle to a shared memory buffer that is one 32 bit integer long. We
45 // share this with any client as the same user. This buffer is lazily
46 // created on the first access.
47 mojo::ScopedSharedBufferHandle mouse_location_handle_;
48
49 // The one int32 in |mouse_location_handle_|. When we write to this
50 // location, we must always write to it atomically. (On the other side of the
51 // mojo connection, this data must be read atomically.)
52 mojo::ScopedSharedBufferMapping mouse_location_mapping_;
53
54 DISALLOW_COPY_AND_ASSIGN(MouseLocationManager);
55};
56
57} // namespace aura
58
59#endif // UI_AURA_MOUSE_LOCATION_MANAGER_H_