Mir
buffer_stream.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 3 as
6  * 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: Robert Carr <robert.carr@canonical.com>
17  */
18 
19 #ifndef MIR_CLIENT_BUFFER_STREAM_H
20 #define MIR_CLIENT_BUFFER_STREAM_H
21 
22 #include "mir_wait_handle.h"
23 #include "mir/egl_native_surface.h"
24 #include "mir/client_buffer.h"
25 #include "client_buffer_stream.h"
27 #include "mir/geometry/size.h"
28 
30 
31 #include <EGL/eglplatform.h>
32 
33 #include <queue>
34 #include <memory>
35 #include <mutex>
36 
37 namespace google
38 {
39 namespace protobuf
40 {
41 class Closure;
42 }
43 }
44 namespace mir
45 {
46 namespace logging
47 {
48 class Logger;
49 }
50 namespace protobuf
51 {
52 class BufferStream;
53 class BufferStreamParameters;
54 class Void;
55 }
56 namespace client
57 {
58 namespace rpc
59 {
60 class DisplayServer;
61 }
62 class SurfaceMap;
63 class AsyncBufferFactory;
65 class ClientBuffer;
66 class ClientPlatform;
67 class PerfReport;
68 struct MemoryRegion;
69 class SurfaceMap;
70 class ServerBufferSemantics;
72 {
73 public:
75  MirConnection* connection,
76  std::shared_ptr<MirWaitHandle> creation_wait_handle,
78  std::shared_ptr<ClientPlatform> const& native_window_factory,
79  std::weak_ptr<SurfaceMap> const& map,
80  std::shared_ptr<AsyncBufferFactory> const& factory,
81  mir::protobuf::BufferStream const& protobuf_bs,
82  std::shared_ptr<PerfReport> const& perf_report,
83  std::string const& surface_name,
84  geometry::Size ideal_size, size_t nbuffers);
85  // For surfaceless buffer streams
87  MirConnection* connection,
88  std::shared_ptr<MirWaitHandle> creation_wait_handle,
90  std::shared_ptr<ClientPlatform> const& native_window_factory,
91  std::weak_ptr<SurfaceMap> const& map,
92  std::shared_ptr<AsyncBufferFactory> const& factory,
93  mir::protobuf::BufferStreamParameters const& parameters,
94  std::shared_ptr<PerfReport> const& perf_report,
95  size_t nbuffers);
96 
97  virtual ~BufferStream();
98 
99  MirWaitHandle* next_buffer(std::function<void()> const& done) override;
100  std::shared_ptr<mir::client::ClientBuffer> get_current_buffer() override;
101  // Required by debug API
102  uint32_t get_current_buffer_id() override;
103 
104  int swap_interval() const override;
105  MirWaitHandle* set_swap_interval(int interval) override;
106  void set_buffer_cache_size(unsigned int) override;
107 
108  EGLNativeWindowType egl_native_window() override;
109  std::shared_ptr<MemoryRegion> secure_for_cpu_write() override;
110 
111  // mcl::EGLNativeSurface interface
112  MirSurfaceParameters get_parameters() const override;
113  void request_and_wait_for_next_buffer() override;
114 
115  void request_and_wait_for_configure(MirSurfaceAttrib attrib, int) override;
116 
117  MirNativeBuffer* get_current_buffer_package() override;
118 
119  MirPlatformType platform_type() override;
120 
121  frontend::BufferStreamId rpc_id() const override;
122  bool valid() const override;
123 
124  void buffer_available(mir::protobuf::Buffer const& buffer) override;
125  void buffer_unavailable() override;
126  void set_size(geometry::Size) override;
127  MirWaitHandle* set_scale(float scale) override;
128  char const* get_error_message() const override;
129  MirConnection* connection() const override;
130 
131 protected:
132  BufferStream(BufferStream const&) = delete;
133  BufferStream& operator=(BufferStream const&) = delete;
134 
135 private:
136  void process_buffer(protobuf::Buffer const& buffer);
137  void process_buffer(protobuf::Buffer const& buffer, std::unique_lock<std::mutex>&);
138  void on_swap_interval_set(int interval);
139  void on_scale_set(float scale);
140  void release_cpu_region();
141  MirWaitHandle* force_swap_interval(int interval);
142  void init_swap_interval();
143 
144  mutable std::mutex mutex; // Protects all members of *this
145 
146  MirConnection* connection_;
147  mir::client::rpc::DisplayServer& display_server;
148  std::shared_ptr<ClientPlatform> const client_platform;
149  std::unique_ptr<mir::protobuf::BufferStream> protobuf_bs;
150 
151  bool fixed_swap_interval;
152  int swap_interval_;
153  float scale_;
154 
155  std::shared_ptr<mir::client::PerfReport> const perf_report;
156  std::shared_ptr<void> egl_native_window_;
157 
158  MirWaitHandle interval_wait_handle;
159  std::unique_ptr<mir::protobuf::Void> protobuf_void;
160 
161  std::shared_ptr<MemoryRegion> secured_region;
162 
163  std::unique_ptr<ServerBufferSemantics> buffer_depository;
164  geometry::Size ideal_buffer_size;
165  size_t const nbuffers;
166  std::string error_message;
167  std::shared_ptr<MirWaitHandle> creation_wait_handle;
168  std::weak_ptr<SurfaceMap> const map;
169  std::shared_ptr<AsyncBufferFactory> const factory;
170 };
171 
172 }
173 }
174 
175 #endif // MIR_CLIENT_BUFFER_STREAM_H
Definition: size.h:30
All things Mir.
Definition: atomic_callback.h:25
A factory for creating client-side representations of graphics buffers.
Definition: client_buffer_factory.h:38
Definition: mir_wait_handle.h:31
Definition: buffer_stream.h:71
Definition: surface_map.h:40
Definition: mir_native_buffer.h:30
Definition: logger.h:41
Definition: egl_native_surface.h:31
Definition: client_buffer.h:46
MirSurfaceAttrib
Attributes of a surface that the client and server/shell may wish to get or set over the wire...
Definition: common.h:34
Definition: perf_report.h:27
Definition: client_buffer_stream.h:68
Interface to client-side platform specific support for graphics operations.
Definition: client_platform.h:41
Definition: mir_connection.h:96
Definition: buffer_factory.h:33
Definition: client_buffer.h:55
Definition: buffer_stream.h:37
#define EGLNativeWindowType
Definition: client_buffer_stream.h:55
MirPlatformType
The native buffer type for the system the client is connected on.
Definition: client_types.h:200
Definition: mir_display_server.h:33
MirSurfaceParameters is the structure of minimum required information that you must provide to Mir in...
Definition: client_types.h:169

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