Mir
cursor.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 
20 #ifndef MIR_GRAPHICS_MESA_CURSOR_H_
21 #define MIR_GRAPHICS_MESA_CURSOR_H_
22 
23 #include "mir/graphics/cursor.h"
24 #include "mir/geometry/point.h"
26 
27 #include "mir_toolkit/common.h"
28 
29 #include <gbm.h>
30 
31 #include <memory>
32 #include <mutex>
33 
34 namespace mir
35 {
36 namespace geometry
37 {
38 struct Rectangle;
39 }
40 namespace graphics
41 {
42 class CursorImage;
43 
44 namespace mesa
45 {
46 class KMSOutputContainer;
47 class KMSOutput;
48 class KMSDisplayConfiguration;
49 class GBMPlatform;
50 
52 {
53 public:
54  virtual ~CurrentConfiguration() = default;
55 
56  virtual void with_current_configuration_do(
57  std::function<void(KMSDisplayConfiguration const&)> const& exec) = 0;
58 
59 protected:
60  CurrentConfiguration() = default;
62  CurrentConfiguration& operator=(CurrentConfiguration const&) = delete;
63 };
64 
65 class Cursor : public graphics::Cursor
66 {
67 public:
68  Cursor(
69  gbm_device* device,
70  KMSOutputContainer& output_container,
71  std::shared_ptr<CurrentConfiguration> const& current_configuration,
72  std::shared_ptr<CursorImage> const& cursor_image);
73 
74  ~Cursor() noexcept;
75 
76  void show() override;
77  void show(CursorImage const& cursor_image) override;
78  void hide() override;
79 
80  void move_to(geometry::Point position) override;
81 
82  void suspend();
83  void resume();
84 
85 private:
86  enum ForceCursorState { UpdateState, ForceState };
87  void for_each_used_output(std::function<void(KMSOutput&, geometry::Rectangle const&, MirOrientation orientation)> const& f);
88  void place_cursor_at(geometry::Point position, ForceCursorState force_state);
89  void place_cursor_at_locked(std::lock_guard<std::mutex> const&, geometry::Point position, ForceCursorState force_state);
90  void write_buffer_data_locked(std::lock_guard<std::mutex> const&, void const* data, size_t count);
91  void pad_and_write_image_data_locked(std::lock_guard<std::mutex> const&, CursorImage const& image);
92 
93  std::mutex guard;
94 
95  KMSOutputContainer& output_container;
96  geometry::Point current_position;
97  geometry::Displacement hotspot;
98 
99  bool visible;
100 
101  struct GBMBOWrapper
102  {
103  GBMBOWrapper(gbm_device* gbm);
104  operator gbm_bo*();
105  ~GBMBOWrapper();
106  private:
107  gbm_bo* buffer;
108  GBMBOWrapper(GBMBOWrapper const&) = delete;
109  GBMBOWrapper& operator=(GBMBOWrapper const&) = delete;
110  } buffer;
111 
112  uint32_t buffer_width;
113  uint32_t buffer_height;
114 
115  std::shared_ptr<CurrentConfiguration> const current_configuration;
116 };
117 }
118 }
119 }
120 
121 
122 #endif /* MIR_GRAPHICS_MESA_CURSOR_H_ */
All things Mir.
Definition: atomic_callback.h:25
Definition: kms_output_container.h:34
Definition: point.h:30
Definition: kms_output.h:37
MirOrientation
Direction relative to the "natural" orientation of the display.
Definition: common.h:164
Definition: cursor_image.h:30
Definition: cursor.h:33
Definition: cursor.h:65
Definition: kms_display_configuration.h:33
Definition: displacement.h:32
Definition: rectangle.h:33

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Sep 8 14:50:19 UTC 2016