Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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;
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(CursorImage const& cursor_image) override;
77  void hide() override;
78 
79  void move_to(geometry::Point position);
80 
81  void suspend();
82  void resume();
83 
84 private:
85  enum ForceCursorState { UpdateState, ForceState };
86  void for_each_used_output(std::function<void(KMSOutput&, geometry::Rectangle const&, MirOrientation orientation)> const& f);
87  void place_cursor_at(geometry::Point position, ForceCursorState force_state);
88  void place_cursor_at_locked(std::lock_guard<std::mutex> const&, geometry::Point position, ForceCursorState force_state);
89  void write_buffer_data_locked(std::lock_guard<std::mutex> const&, void const* data, size_t count);
90  void pad_and_write_image_data_locked(std::lock_guard<std::mutex> const&, CursorImage const& image);
91 
92  std::mutex guard;
93 
94  KMSOutputContainer& output_container;
95  geometry::Point current_position;
96  geometry::Displacement hotspot;
97 
98  bool visible;
99 
100  struct GBMBOWrapper
101  {
102  GBMBOWrapper(gbm_device* gbm);
103  operator gbm_bo*();
104  ~GBMBOWrapper();
105  private:
106  gbm_bo* buffer;
107  GBMBOWrapper(GBMBOWrapper const&) = delete;
108  GBMBOWrapper& operator=(GBMBOWrapper const&) = delete;
109  } buffer;
110 
111  std::shared_ptr<CurrentConfiguration> const current_configuration;
112 };
113 }
114 }
115 }
116 
117 
118 #endif /* MIR_GRAPHICS_MESA_CURSOR_H_ */
All things Mir.
Definition: aging_buffer.h:24
Definition: kms_output_container.h:34
void move_to(geometry::Point position)
Definition: cursor.cpp:154
Definition: point.h:30
void hide() override
Definition: cursor.cpp:172
void show(CursorImage const &cursor_image) override
Definition: cursor.cpp:128
Definition: kms_output.h:37
MirOrientation
Direction relative to the "natural" orientation of the display.
Definition: common.h:134
CurrentConfiguration & operator=(CurrentConfiguration const &)=delete
Definition: cursor_image.h:30
Definition: cursor.h:33
virtual void with_current_configuration_do(std::function< void(KMSDisplayConfiguration const &)> const &exec)=0
Cursor & operator=(Cursor const &)=delete
Definition: cursor.h:65
Definition: kms_display_configuration.h:33
Definition: displacement.h:32
Definition: rectangle.h:33
~Cursor() noexcept
Definition: cursor.cpp:87
void resume()
Definition: cursor.cpp:167
void suspend()
Definition: cursor.cpp:159

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Oct 10 14:07:14 UTC 2014