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 "mir_wait_handle.h"
26 #include <memory>
27 #include "no_tls_future-inl.h"
28 #include <deque>
29 #include <map>
30 
31 namespace mir
32 {
33 namespace protobuf { class Buffer; }
34 namespace client
35 {
36 class ClientBuffer;
37 class MirBuffer;
38 class AsyncBufferFactory;
39 class SurfaceMap;
40 
42 {
43 public:
44  virtual void allocate_buffer(geometry::Size size, MirPixelFormat format, int usage) = 0;
45  virtual void free_buffer(int buffer_id) = 0;
46  virtual void submit_buffer(MirBuffer&) = 0;
47  virtual ~ServerBufferRequests() = default;
48 protected:
49  ServerBufferRequests() = default;
51  ServerBufferRequests& operator=(ServerBufferRequests const&) = delete;
52 };
53 
55 
57 {
58 public:
60  std::shared_ptr<ClientBufferFactory> const&,
61  std::shared_ptr<AsyncBufferFactory> const&,
62  std::shared_ptr<ServerBufferRequests> const&,
63  std::weak_ptr<SurfaceMap> const&,
64  geometry::Size size, MirPixelFormat format, int usage,
65  unsigned int initial_nbuffers);
66  ~BufferVault();
67 
69  void deposit(std::shared_ptr<MirBuffer> const& buffer);
70  void wire_transfer_inbound(int buffer_id);
71  MirWaitHandle* wire_transfer_outbound(
72  std::shared_ptr<MirBuffer> const& buffer, std::function<void()> const&);
73  void set_size(geometry::Size);
74  void disconnected();
75  void set_scale(float scale);
76  void increase_buffer_count();
77  void decrease_buffer_count();
78 
79 private:
80  enum class Owner;
81  typedef std::map<int, Owner> BufferMap;
82  BufferMap::iterator available_buffer();
83  void trigger_callback(std::unique_lock<std::mutex> lk);
84 
85  void alloc_buffer(geometry::Size size, MirPixelFormat format, int usage);
86  void free_buffer(int free_id);
87  void realloc_buffer(int free_id, geometry::Size size, MirPixelFormat format, int usage);
88  std::shared_ptr<MirBuffer> checked_buffer_from_map(int id);
89  void set_size(std::unique_lock<std::mutex> const& lk, geometry::Size new_size);
90 
91 
92  std::shared_ptr<ClientBufferFactory> const platform_factory;
93  std::shared_ptr<AsyncBufferFactory> const buffer_factory;
94  std::shared_ptr<ServerBufferRequests> const server_requests;
95  std::weak_ptr<SurfaceMap> const surface_map;
96  MirPixelFormat const format;
97  int const usage;
98 
99  std::mutex mutex;
100  BufferMap buffers;
101  std::deque<NoTLSPromise<std::shared_ptr<MirBuffer>>> promises;
103  bool disconnected_;
104  size_t current_buffer_count;
105  size_t needed_buffer_count;
106  size_t const initial_buffer_count;
107  int last_received_id = 0;
108  MirWaitHandle next_buffer_wait_handle;
109  std::function<void()> deferred_cb;
110 };
111 }
112 }
113 #endif /* MIR_CLIENT_BUFFER_VAULT_H_ */
Definition: size.h:30
Definition: mir_buffer.h:34
All things Mir.
Definition: atomic_callback.h:25
A factory for creating client-side representations of graphics buffers.
Definition: client_buffer_factory.h:38
struct MirBuffer MirBuffer
Definition: client_types_nbs.h:33
Definition: mir_wait_handle.h:31
Definition: buffer_vault.h:56
Owner
Definition: buffer_vault.cpp:38
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:41
Definition: no_tls_future-inl.h:101
int const size
Definition: make_socket_rpc_channel.cpp:51

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