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 }
63 class ClientBuffer;
64 class ClientPlatform;
65 class PerfReport;
66 struct MemoryRegion;
67 
68 class ServerBufferSemantics;
70 {
71 public:
73  MirConnection* connection,
74  std::shared_ptr<MirWaitHandle> creation_wait_handle,
76  std::shared_ptr<ClientPlatform> const& native_window_factory,
77  mir::protobuf::BufferStream const& protobuf_bs,
78  std::shared_ptr<PerfReport> const& perf_report,
79  std::string const& surface_name,
80  geometry::Size ideal_size, size_t nbuffers);
81  // For surfaceless buffer streams
83  MirConnection* connection,
84  std::shared_ptr<MirWaitHandle> creation_wait_handle,
86  std::shared_ptr<ClientPlatform> const& native_window_factory,
87  mir::protobuf::BufferStreamParameters const& parameters,
88  std::shared_ptr<PerfReport> const& perf_report,
89  size_t nbuffers);
90 
91  virtual ~BufferStream();
92 
93  MirWaitHandle* next_buffer(std::function<void()> const& done) override;
94  std::shared_ptr<mir::client::ClientBuffer> get_current_buffer() override;
95  // Required by debug API
96  uint32_t get_current_buffer_id() override;
97 
98  int swap_interval() const override;
99  MirWaitHandle* set_swap_interval(int interval) override;
100  void set_buffer_cache_size(unsigned int) override;
101 
102  EGLNativeWindowType egl_native_window() override;
103  std::shared_ptr<MemoryRegion> secure_for_cpu_write() override;
104 
105  // mcl::EGLNativeSurface interface
106  MirSurfaceParameters get_parameters() const override;
107  void request_and_wait_for_next_buffer() override;
108 
109  void request_and_wait_for_configure(MirSurfaceAttrib attrib, int) override;
110 
111  MirNativeBuffer* get_current_buffer_package() override;
112 
113  MirPlatformType platform_type() override;
114 
115  frontend::BufferStreamId rpc_id() const override;
116  bool valid() const override;
117 
118  void buffer_available(mir::protobuf::Buffer const& buffer) override;
119  void buffer_unavailable() override;
120  void set_size(geometry::Size) override;
121  MirWaitHandle* set_scale(float scale) override;
122  char const* get_error_message() const override;
123  MirConnection* connection() const override;
124 
125 protected:
126  BufferStream(BufferStream const&) = delete;
127  BufferStream& operator=(BufferStream const&) = delete;
128 
129 private:
130  void process_buffer(protobuf::Buffer const& buffer);
131  void process_buffer(protobuf::Buffer const& buffer, std::unique_lock<std::mutex>&);
132  void on_swap_interval_set(int interval);
133  void on_scale_set(float scale);
134  void release_cpu_region();
135  MirWaitHandle* force_swap_interval(int interval);
136  void init_swap_interval();
137 
138  mutable std::mutex mutex; // Protects all members of *this
139 
140  MirConnection* connection_;
141  mir::client::rpc::DisplayServer& display_server;
142  std::shared_ptr<ClientPlatform> const client_platform;
143  std::unique_ptr<mir::protobuf::BufferStream> protobuf_bs;
144 
145  bool fixed_swap_interval;
146  int swap_interval_;
147  float scale_;
148 
149  std::shared_ptr<mir::client::PerfReport> const perf_report;
150  std::shared_ptr<void> egl_native_window_;
151 
152  MirWaitHandle interval_wait_handle;
153  std::unique_ptr<mir::protobuf::Void> protobuf_void;
154 
155  std::shared_ptr<MemoryRegion> secured_region;
156 
157  geometry::Size cached_buffer_size;
158 
159  std::unique_ptr<ServerBufferSemantics> buffer_depository;
160  geometry::Size ideal_buffer_size;
161  size_t const nbuffers;
162  std::string error_message;
163  std::shared_ptr<MirWaitHandle> creation_wait_handle;
164 };
165 
166 }
167 }
168 
169 #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:69
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:69
Interface to client-side platform specific support for graphics operations.
Definition: client_platform.h:41
Definition: mir_connection.h:96
Definition: client_buffer.h:55
Definition: buffer_stream.h:37
#define EGLNativeWindowType
Definition: client_buffer_stream.h:56
MirPlatformType
The native buffer type for the system the client is connected on.
Definition: client_types.h:197
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:166

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016