Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 
28 namespace mir
29 {
30 namespace graphics
31 {
32 class Buffer;
33 class GraphicBufferAllocator;
34 }
35 namespace compositor
36 {
37 
39 {
40 public:
41  SwitchingBundle(int nbuffers,
42  const std::shared_ptr<graphics::GraphicBufferAllocator> &,
44 
46 
47  std::shared_ptr<graphics::Buffer> client_acquire();
48  void client_release(std::shared_ptr<graphics::Buffer> const&);
49  std::shared_ptr<graphics::Buffer>
50  compositor_acquire(unsigned long frameno) override;
51  void compositor_release(std::shared_ptr<graphics::Buffer> const& released_buffer);
52  std::shared_ptr<graphics::Buffer> snapshot_acquire();
53  void snapshot_release(std::shared_ptr<graphics::Buffer> const& released_buffer);
55  void allow_framedropping(bool dropping_allowed);
56  bool framedropping_allowed() const;
57 
58 private:
59  graphics::BufferProperties bundle_properties;
60  std::shared_ptr<graphics::GraphicBufferAllocator> gralloc;
61 
62  int drop_frames(int max);
63  int nfree() const;
64  int first_free() const;
65  int next(int slot) const;
66  int prev(int slot) const;
67  int last_compositor() const;
68 
69  const std::shared_ptr<graphics::Buffer> &alloc_buffer(int slot);
70 
71  enum {MAX_NBUFFERS = 5};
72  struct SharedBuffer
73  {
74  std::shared_ptr<graphics::Buffer> buf;
75  int users = 0; // presently just a count of compositors sharing the buf
76  };
77  SharedBuffer ring[MAX_NBUFFERS];
78 
79  const int nbuffers;
80  int first_compositor;
81  int ncompositors;
82  int first_ready;
83  int nready;
84  int first_client;
85  int nclients;
86  int snapshot;
87  int nsnapshotters;
88 
89  std::mutex guard;
90  std::condition_variable cond;
91 
92  unsigned long last_consumed;
93 
94  bool overlapping_compositors;
95 
96  bool framedropping;
97  int force_drop;
98 };
99 
100 }
101 }
102 
103 #endif /* MIR_COMPOSITOR_SWITCHING_BUNDLE_H_ */

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Oct 15 00:23:28 UTC 2013