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_protobuf.pb.h"
23 
24 #include "mir_wait_handle.h"
25 #include "mir/egl_native_surface.h"
26 #include "mir/client_buffer.h"
27 #include "client_buffer_stream.h"
29 
31 
32 #include <EGL/eglplatform.h>
33 
34 #include <memory>
35 #include <mutex>
36 
37 namespace mir
38 {
39 namespace logging
40 {
41 class Logger;
42 }
43 namespace client
44 {
46 class ClientBuffer;
48 class PerfReport;
49 struct MemoryRegion;
50 
52 {
53 Producer, // As in surfaces
54 Consumer // As in screencasts
55 };
56 
58 {
59 public:
60  BufferStream(mir::protobuf::DisplayServer& server,
61  BufferStreamMode mode,
62  std::shared_ptr<ClientBufferFactory> const& buffer_factory,
63  std::shared_ptr<EGLNativeWindowFactory> const& native_window_factory,
64  protobuf::BufferStream const& protobuf_bs,
65  std::shared_ptr<logging::Logger> const& logger);
66  virtual ~BufferStream();
67 
68  MirWaitHandle* next_buffer(std::function<void()> const& done) override;
69  std::shared_ptr<mir::client::ClientBuffer> get_current_buffer() override;
70  // Required by debug API
71  uint32_t get_current_buffer_id() override;
72 
73  int swap_interval() const override;
74  void set_swap_interval(int interval) override;
75 
76  EGLNativeWindowType egl_native_window() override;
77  std::shared_ptr<MemoryRegion> secure_for_cpu_write() override;
78 
79  // mcl::EGLNativeSurface interface
80  MirSurfaceParameters get_parameters() const override;
81  void request_and_wait_for_next_buffer() override;
82  // TODO: In this context it seems like a wart that this is a "SurfaceAttribute"
83  void request_and_wait_for_configure(MirSurfaceAttrib attrib, int) override;
84 
85 protected:
86  BufferStream(BufferStream const&) = delete;
87  BufferStream& operator=(BufferStream const&) = delete;
88 
89 private:
90  void process_buffer(protobuf::Buffer const& buffer);
91  void next_buffer_received(
92  std::function<void()> done);
93  void on_configured();
94  void release_cpu_region();
95 
96  mutable std::mutex mutex; // Protects all members of *this
97 
98  mir::protobuf::DisplayServer& display_server;
99 
100  BufferStreamMode const mode;
101  std::shared_ptr<EGLNativeWindowFactory> const native_window_factory;
102 
103  mir::protobuf::BufferStream protobuf_bs;
104  mir::client::ClientBufferDepository buffer_depository;
105 
106  int swap_interval_;
107 
108  std::shared_ptr<mir::client::PerfReport> const perf_report;
109 
110  std::shared_ptr<EGLNativeWindowType> egl_native_window_;
111 
112  MirWaitHandle next_buffer_wait_handle;
113  MirWaitHandle configure_wait_handle;
114 
115  std::shared_ptr<MemoryRegion> secured_region;
116 
117  geometry::Size cached_buffer_size;
118 };
119 
120 }
121 }
122 
123 #endif // MIR_CLIENT_BUFFER_STREAM_H
BufferStream(mir::protobuf::DisplayServer &server, BufferStreamMode mode, std::shared_ptr< ClientBufferFactory > const &buffer_factory, std::shared_ptr< EGLNativeWindowFactory > const &native_window_factory, protobuf::BufferStream const &protobuf_bs, std::shared_ptr< logging::Logger > const &logger)
Definition: size.h:30
All things Mir.
Definition: buffer_stream.h:37
A factory for creating client-side representations of graphics buffers.
Definition: client_buffer_factory.h:38
BufferStreamMode
Definition: buffer_stream.h:51
EGLNativeWindowType egl_native_window() override
Definition: buffer_stream.cpp:216
Definition: mir_wait_handle.h:31
Definition: buffer_stream.h:54
virtual ~BufferStream()
Definition: buffer_stream.cpp:125
Definition: buffer_stream.h:57
std::shared_ptr< MemoryRegion > secure_for_cpu_write() override
Definition: buffer_stream.cpp:227
MirWaitHandle * next_buffer(std::function< void()> const &done) override
Definition: buffer_stream.cpp:160
void request_and_wait_for_configure(MirSurfaceAttrib attrib, int) override
Definition: buffer_stream.cpp:273
Responsible for taking the buffer data sent from the server and wrapping it in a ClientBuffer.
Definition: client_buffer_depository.h:46
Definition: logger.h:41
Definition: egl_native_surface.h:31
Definition: client_buffer.h:43
MirSurfaceAttrib
Attributes of a surface that the client and server/shell may wish to get or set over the wire...
Definition: common.h:36
Definition: perf_report.h:27
Definition: egl_native_window_factory.h:32
void request_and_wait_for_next_buffer() override
Definition: buffer_stream.cpp:258
Definition: client_buffer_stream.h:37
BufferStream & operator=(BufferStream const &)=delete
Definition: client_buffer.h:52
int swap_interval() const override
Definition: buffer_stream.cpp:308
std::shared_ptr< mir::client::ClientBuffer > get_current_buffer() override
Definition: buffer_stream.cpp:210
void set_swap_interval(int interval) override
Definition: buffer_stream.cpp:314
uint32_t get_current_buffer_id() override
Definition: buffer_stream.cpp:302
Definition: buffer_stream.h:53
MirSurfaceParameters get_parameters() const override
Definition: buffer_stream.cpp:246
MirSurfaceParameters is the structure of minimum required information that you must provide to Mir in...
Definition: client_types.h:138

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Mar 24 16:15:19 UTC 2015