Mir
buffer_vault.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 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 
19 #ifndef MIR_CLIENT_BUFFER_VAULT_H_
20 #define MIR_CLIENT_BUFFER_VAULT_H_
21 
22 #include "mir/geometry/size.h"
23 #include "mir_toolkit/common.h"
25 #include <memory>
26 #include "no_tls_future-inl.h"
27 #include <deque>
28 #include <map>
29 
30 namespace mir
31 {
32 namespace protobuf { class Buffer; }
33 namespace client
34 {
36 {
37 public:
38  virtual void allocate_buffer(geometry::Size size, MirPixelFormat format, int usage) = 0;
39  virtual void free_buffer(int buffer_id) = 0;
40  virtual void submit_buffer(int buffer_id, ClientBuffer&) = 0;
41  virtual ~ServerBufferRequests() = default;
42 protected:
43  ServerBufferRequests() = default;
46 };
47 
49 class ClientBuffer;
51 {
52 public:
54  std::shared_ptr<ClientBufferFactory> const&,
55  std::shared_ptr<ServerBufferRequests> const&,
56  geometry::Size size, MirPixelFormat format, int usage,
57  unsigned int initial_nbuffers);
58  ~BufferVault();
59 
61  void deposit(std::shared_ptr<ClientBuffer> const& buffer);
62  void wire_transfer_inbound(protobuf::Buffer const&);
63  void wire_transfer_outbound(std::shared_ptr<ClientBuffer> const& buffer);
65 
66 private:
67  std::shared_ptr<ClientBufferFactory> const factory;
68  std::shared_ptr<ServerBufferRequests> const server_requests;
69  MirPixelFormat const format;
70  int const usage;
71 
72  enum class Owner;
73  struct BufferEntry
74  {
75  std::shared_ptr<ClientBuffer> buffer;
76  Owner owner;
77  };
78 
79  std::mutex mutex;
80  std::map<int, BufferEntry> buffers;
81  std::deque<NoTLSPromise<std::shared_ptr<ClientBuffer>>> promises;
82  geometry::Size size;
83 };
84 }
85 }
86 #endif /* MIR_CLIENT_BUFFER_VAULT_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: buffer_vault.h:50
NoTLSFuture< std::shared_ptr< ClientBuffer > > withdraw()
Definition: buffer_vault.cpp:58
virtual ~ServerBufferRequests()=default
~BufferVault()
Definition: buffer_vault.cpp:52
Owner
Definition: buffer_vault.cpp:31
virtual void submit_buffer(int buffer_id, ClientBuffer &)=0
void wire_transfer_inbound(protobuf::Buffer const &)
Definition: buffer_vault.cpp:109
void deposit(std::shared_ptr< ClientBuffer > const &buffer)
Definition: buffer_vault.cpp:79
MirPixelFormat
32-bit pixel formats (8888): The order of components in the enum matches the order of the components ...
Definition: common.h:134
virtual void free_buffer(int buffer_id)=0
Definition: buffer_vault.h:35
Definition: no_tls_future-inl.h:97
Definition: client_buffer.h:52
virtual void allocate_buffer(geometry::Size size, MirPixelFormat format, int usage)=0
void wire_transfer_outbound(std::shared_ptr< ClientBuffer > const &buffer)
Definition: buffer_vault.cpp:91
void set_size(geometry::Size)
Definition: buffer_vault.cpp:156
ServerBufferRequests & operator=(ServerBufferRequests const &)=delete
int const size
Definition: make_socket_rpc_channel.cpp:51
BufferVault(std::shared_ptr< ClientBufferFactory > const &, std::shared_ptr< ServerBufferRequests > const &, geometry::Size size, MirPixelFormat format, int usage, unsigned int initial_nbuffers)
Definition: buffer_vault.cpp:38

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015