Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mir_surface.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012 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: Kevin DuBois <kevin.dubois@canonical.com>
17  */
18 #ifndef MIR_CLIENT_MIR_SURFACE_H_
19 #define MIR_CLIENT_MIR_SURFACE_H_
20 
21 #include "mir_protobuf.pb.h"
22 
26 #include "mir_toolkit/common.h"
29 #include "mir_wait_handle.h"
30 #include "mir_client_surface.h"
31 #include "client_platform.h"
32 
33 #include <memory>
34 #include <functional>
35 #include <mutex>
36 
37 namespace mir
38 {
39 namespace input
40 {
41 namespace receiver
42 {
43 class InputPlatform;
44 class InputReceiverThread;
45 }
46 }
47 namespace client
48 {
49 class ClientBuffer;
50 
51 struct MemoryRegion;
52 }
53 }
54 
56 {
57 public:
58  MirSurface(MirSurface const &) = delete;
59  MirSurface& operator=(MirSurface const &) = delete;
60 
61  MirSurface(
62  MirConnection *allocating_connection,
63  mir::protobuf::DisplayServer::Stub & server,
64  std::shared_ptr<mir::client::ClientBufferFactory> const& buffer_factory,
65  std::shared_ptr<mir::input::receiver::InputPlatform> const& input_platform,
66  MirSurfaceParameters const& params,
67  mir_surface_callback callback, void * context);
68 
69  ~MirSurface();
70 
72  mir_surface_callback callback,
73  void *context);
74 
76  char const * get_error_message();
77  int id() const;
78  bool is_valid() const;
79  MirWaitHandle* next_buffer(mir_surface_callback callback, void * context);
81 
84  std::shared_ptr<mir::client::ClientBuffer> get_current_buffer();
85  uint32_t get_current_buffer_id() const;
86  void get_cpu_region(MirGraphicsRegion& region);
87  void release_cpu_region();
88  EGLNativeWindowType generate_native_window();
89 
91  int attrib(MirSurfaceAttrib a) const;
92 
93  void set_event_handler(MirEventDelegate const* delegate);
94  void handle_event(MirEvent const& e);
95 
96 private:
97  mutable std::recursive_mutex mutex; // Protects all members of *this
98 
99  void on_configured();
100  void process_incoming_buffer();
101  void populate(MirBufferPackage& buffer_package);
102  void created(mir_surface_callback callback, void * context);
103  void new_buffer(mir_surface_callback callback, void * context);
104  mir::geometry::PixelFormat convert_ipc_pf_to_geometry(google::protobuf::int32 pf);
105 
106  /* todo: race condition. protobuf does not guarantee that callbacks will be synchronized. potential
107  race in surface, last_buffer_id */
108  mir::protobuf::DisplayServer::Stub & server;
109  mir::protobuf::Surface surface;
110  std::string error_message;
111 
112  MirConnection *connection;
113  MirWaitHandle create_wait_handle;
114  MirWaitHandle next_buffer_wait_handle;
115  MirWaitHandle configure_wait_handle;
116 
117  std::shared_ptr<mir::client::MemoryRegion> secured_region;
118  std::shared_ptr<mir::client::ClientBufferDepository> buffer_depository;
119  std::shared_ptr<mir::input::receiver::InputPlatform> const input_platform;
120 
121  std::shared_ptr<EGLNativeWindowType> accelerated_window;
122 
123  mir::protobuf::SurfaceSetting configure_result;
124 
125  // Cache of latest SurfaceSettings returned from the server
126  int attrib_cache[mir_surface_attrib_enum_max_];
127 
128  std::function<void(MirEvent const*)> handle_event_callback;
129  std::shared_ptr<mir::input::receiver::InputReceiverThread> input_thread;
130 };
131 
132 #endif /* MIR_CLIENT_PRIVATE_MIR_WAIT_HANDLE_H_ */

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Oct 15 00:23:28 UTC 2013