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 {
35 class ClientBuffer;
37 {
38 public:
39  virtual void allocate_buffer(geometry::Size size, MirPixelFormat format, int usage) = 0;
40  virtual void free_buffer(int buffer_id) = 0;
41  virtual void submit_buffer(int buffer_id, ClientBuffer&) = 0;
42  virtual ~ServerBufferRequests() = default;
43 protected:
44  ServerBufferRequests() = default;
46  ServerBufferRequests& operator=(ServerBufferRequests const&) = delete;
47 };
48 
50 
51 struct BufferInfo
52 {
53  std::shared_ptr<ClientBuffer> buffer;
54  int id;
55 };
56 
58 {
59 public:
61  std::shared_ptr<ClientBufferFactory> const&,
62  std::shared_ptr<ServerBufferRequests> const&,
63  geometry::Size size, MirPixelFormat format, int usage,
64  unsigned int initial_nbuffers);
65  ~BufferVault();
66 
67  NoTLSFuture<BufferInfo> withdraw();
68  void deposit(std::shared_ptr<ClientBuffer> const& buffer);
69  void wire_transfer_inbound(protobuf::Buffer const&);
70  void wire_transfer_outbound(std::shared_ptr<ClientBuffer> const& buffer);
71  void set_size(geometry::Size);
72  void disconnected();
73  void set_scale(float scale);
74 
75 private:
76  std::shared_ptr<ClientBufferFactory> const factory;
77  std::shared_ptr<ServerBufferRequests> const server_requests;
78  MirPixelFormat const format;
79  int const usage;
80 
81  enum class Owner;
82  struct BufferEntry
83  {
84  std::shared_ptr<ClientBuffer> buffer;
85  Owner owner;
86  };
87 
88  std::mutex mutex;
89  std::map<int, BufferEntry> buffers;
90  std::deque<NoTLSPromise<BufferInfo>> promises;
92  bool disconnected_;
93 };
94 }
95 }
96 #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:51
Definition: buffer_vault.h:57
int id
Definition: buffer_vault.h:54
Owner
Definition: buffer_vault.cpp:32
std::shared_ptr< ClientBuffer > buffer
Definition: buffer_vault.h:53
MirPixelFormat
32-bit pixel formats (8888): The order of components in the enum matches the order of the components ...
Definition: common.h:134
Definition: buffer_vault.h:36
Definition: no_tls_future-inl.h:101
Definition: client_buffer.h:55
int const size
Definition: make_socket_rpc_channel.cpp:51

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