Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
switching_bundle.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU 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 General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by:
17  * Kevin DuBois <kevin.dubois@canonical.com>
18  */
19 
20 #ifndef MIR_COMPOSITOR_SWITCHING_BUNDLE_H_
21 #define MIR_COMPOSITOR_SWITCHING_BUNDLE_H_
22 
23 #include "buffer_bundle.h"
24 #include <condition_variable>
25 #include <mutex>
26 #include <memory>
27 #include <iosfwd>
28 #include <unordered_set>
29 
30 namespace mir
31 {
32 namespace graphics
33 {
34 class Buffer;
35 class GraphicBufferAllocator;
36 }
37 namespace compositor
38 {
39 
41 {
42 public:
43  enum {min_buffers = 1, max_buffers = 5};
44 
45  SwitchingBundle(int nbuffers,
46  const std::shared_ptr<graphics::GraphicBufferAllocator> &,
48 
49  ~SwitchingBundle() noexcept;
50 
51  graphics::BufferProperties properties() const;
52 
53  void client_acquire(std::function<void(graphics::Buffer* buffer)> complete) override;
54  void client_release(graphics::Buffer* buffer);
55  std::shared_ptr<graphics::Buffer>
56  compositor_acquire(void const* user_id) override;
57  void compositor_release(std::shared_ptr<graphics::Buffer> const& released_buffer);
58  std::shared_ptr<graphics::Buffer> snapshot_acquire();
59  void snapshot_release(std::shared_ptr<graphics::Buffer> const& released_buffer);
61  void allow_framedropping(bool dropping_allowed);
62  bool framedropping_allowed() const;
63 
70  void resize(const geometry::Size &newsize) override;
71  int buffers_ready_for_compositor() const override;
72 
73 private:
74  graphics::BufferProperties bundle_properties;
75  std::shared_ptr<graphics::GraphicBufferAllocator> gralloc;
76 
77  int drop_frames(int max);
78  int nfree() const;
79  int first_free() const;
80  int next(int slot) const;
81  int prev(int slot) const;
82  int last_compositor() const;
83 
84  const std::shared_ptr<graphics::Buffer> &alloc_buffer(int slot);
85  void complete_client_acquire(std::unique_lock<std::mutex> lock);
86  bool client_buffers_available(std::unique_lock<std::mutex> const& lock);
87  struct SharedBuffer
88  {
89  std::shared_ptr<graphics::Buffer> buf;
90  int users = 0; // presently just a count of compositors sharing the buf
91  };
92  SharedBuffer ring[max_buffers];
93 
94  const int nbuffers;
95  int first_compositor;
96  int ncompositors;
97  int first_ready;
98  int nready;
99  int first_client;
100  int nclients;
101  int snapshot;
102  int nsnapshotters;
103 
104  mutable std::mutex guard;
105  std::condition_variable cond;
106 
107  std::unordered_set<void const*> users;
108 
109  bool overlapping_compositors;
110 
111  bool framedropping;
112  int force_drop;
113 
114  std::function<void(graphics::Buffer* buffer)> client_acquire_todo;
115 
116  friend std::ostream& operator<<(std::ostream& os, const SwitchingBundle& bundle);
117 };
118 
119 // for use when debugging. e.g "std::cout << *this << std::endl;"
120 std::ostream& operator<<(std::ostream& os, const SwitchingBundle& bundle);
121 
122 }
123 }
124 
125 #endif /* MIR_COMPOSITOR_SWITCHING_BUNDLE_H_ */
Definition: buffer_bundle.h:33
SwitchingBundle(int nbuffers, const std::shared_ptr< graphics::GraphicBufferAllocator > &, const graphics::BufferProperties &)
Definition: switching_bundle.cpp:69
int buffers_ready_for_compositor() const override
Definition: switching_bundle.cpp:460
void client_release(graphics::Buffer *buffer)
Definition: switching_bundle.cpp:281
std::shared_ptr< graphics::Buffer > compositor_acquire(void const *user_id) override
Acquire the next buffer that's ready to display/composite.
Definition: switching_bundle.cpp:297
Definition: switching_bundle.h:43
void allow_framedropping(bool dropping_allowed)
Definition: switching_bundle.cpp:436
bool framedropping_allowed() const
Definition: switching_bundle.cpp:442
graphics::BufferProperties properties() const
Definition: switching_bundle.cpp:448
std::shared_ptr< graphics::Buffer > snapshot_acquire()
Definition: switching_bundle.cpp:379
Definition: switching_bundle.h:43
friend std::ostream & operator<<(std::ostream &os, const SwitchingBundle &bundle)
void client_acquire(std::function< void(graphics::Buffer *buffer)> complete) override
Definition: switching_bundle.cpp:208
void force_requests_to_complete()
Definition: switching_bundle.cpp:425
std::ostream & operator<<(std::ostream &os, const SwitchingBundle &bundle)
Definition: switching_bundle.cpp:466
void snapshot_release(std::shared_ptr< graphics::Buffer > const &released_buffer)
Definition: switching_bundle.cpp:407
void compositor_release(std::shared_ptr< graphics::Buffer > const &released_buffer)
Definition: switching_bundle.cpp:345
Buffer creation properties.
Definition: buffer_properties.h:48
void resize(const geometry::Size &newsize) override
Change the dimensions of the buffers contained in the bundle.
Definition: switching_bundle.cpp:454
~SwitchingBundle() noexcept
Definition: switching_bundle.cpp:93
Definition: switching_bundle.h:40

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Apr 11 21:14:53 UTC 2014