Mir
buffer_queue.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014-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 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  */
17 
18 #ifndef MIR_BUFFER_QUEUE_H_
19 #define MIR_BUFFER_QUEUE_H_
20 
23 #include "buffer_bundle.h"
24 
25 #include <mutex>
26 #include <condition_variable>
27 #include <queue>
28 #include <vector>
29 
30 namespace mir
31 {
32 namespace graphics
33 {
34 class Buffer;
35 class GraphicBufferAllocator;
36 }
37 namespace compositor
38 {
39 
40 class BufferQueue : public BufferBundle
41 {
42 public:
43  typedef std::function<void(graphics::Buffer* buffer)> Callback;
44 
45  BufferQueue(int nbuffers,
46  std::shared_ptr<graphics::GraphicBufferAllocator> const& alloc,
47  graphics::BufferProperties const& props,
48  FrameDroppingPolicyFactory const& policy_provider);
49 
50  void client_acquire(Callback complete) override;
51  void client_release(graphics::Buffer* buffer) override;
52  std::shared_ptr<graphics::Buffer> compositor_acquire(void const* user_id) override;
53  void compositor_release(std::shared_ptr<graphics::Buffer> const& buffer) override;
54  std::shared_ptr<graphics::Buffer> snapshot_acquire() override;
55  void snapshot_release(std::shared_ptr<graphics::Buffer> const& buffer) override;
56 
57  graphics::BufferProperties properties() const override;
58  void allow_framedropping(bool dropping_allowed) override;
59  void force_requests_to_complete() override;
60  void resize(const geometry::Size &newsize) override;
61  int buffers_ready_for_compositor(void const* user_id) const override;
62  int buffers_free_for_client() const override;
63  bool framedropping_allowed() const;
64  bool is_a_current_buffer_user(void const* user_id) const;
65  void drop_old_buffers() override;
66  void drop_client_requests() override;
67 
74  void set_scaling_delay(int nframes);
75  int scaling_delay() const;
76 
77 private:
78  class LockableCallback;
79  enum SnapshotWait
80  {
81  wait_for_snapshot,
82  ignore_snapshot
83  };
84  void give_buffer_to_client(graphics::Buffer* buffer,
85  std::unique_lock<std::mutex>& lock);
86  void give_buffer_to_client(graphics::Buffer* buffer,
87  std::unique_lock<std::mutex>& lock, SnapshotWait wait_type);
88  void release(graphics::Buffer* buffer,
89  std::unique_lock<std::mutex> lock);
90  void drop_frame(std::unique_lock<std::mutex>& lock, SnapshotWait wait_type);
91 
92  mutable std::mutex guard;
93 
94  std::vector<std::shared_ptr<graphics::Buffer>> buffers;
95  std::deque<graphics::Buffer*> ready_to_composite_queue;
96  std::deque<graphics::Buffer*> buffers_owned_by_client;
97  std::vector<graphics::Buffer*> free_buffers;
98  std::vector<graphics::Buffer*> buffers_sent_to_compositor;
99  std::vector<graphics::Buffer*> pending_snapshots;
100 
101  std::vector<void const*> current_buffer_users;
102  graphics::Buffer* current_compositor_buffer;
103 
104  std::deque<Callback> pending_client_notifications;
105 
106  bool client_ahead_of_compositor() const;
107  graphics::Buffer* get_a_free_buffer();
108 
109  int nbuffers;
110  int frame_deadlines_threshold;
111  int frame_deadlines_met;
112  int scheduled_extra_frames;
113  bool frame_dropping_enabled;
114  bool current_compositor_buffer_valid;
115  graphics::BufferProperties the_properties;
116  bool force_new_compositor_buffer;
117  bool callbacks_allowed;
118  bool single_compositor;
119 
120  std::condition_variable snapshot_released;
121  std::shared_ptr<graphics::GraphicBufferAllocator> gralloc;
122 
123  // Ensure framedrop_policy gets destroyed first so the callback installed
124  // does not access dead objects.
125  std::unique_ptr<FrameDroppingPolicy> framedrop_policy;
126 };
127 
128 }
129 }
130 
131 #endif
Definition: size.h:30
All things Mir.
Definition: atomic_callback.h:25
Definition: buffer_bundle.h:60
Definition: buffer_queue.h:40
Buffer creation properties.
Definition: buffer_properties.h:48
Definition: buffer.h:44
Creator of FrameDroppingPolicies.
Definition: frame_dropping_policy_factory.h:40
std::function< void(graphics::Buffer *buffer)> Callback
Definition: buffer_queue.h:43

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