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 set_mode(MultiMonitorMode mode) override;
60  void force_requests_to_complete() override;
61  void resize(const geometry::Size &newsize) override;
62  int buffers_ready_for_compositor(void const* user_id) const override;
63  int buffers_free_for_client() const override;
64  bool framedropping_allowed() const;
65  bool is_a_current_buffer_user(void const* user_id) const;
66  void drop_old_buffers() override;
67  void drop_client_requests() override;
68 
75  void set_scaling_delay(int nframes);
76  int scaling_delay() const;
77 
78 private:
79  class LockableCallback;
80  enum SnapshotWait
81  {
82  wait_for_snapshot,
83  ignore_snapshot
84  };
85  void give_buffer_to_client(graphics::Buffer* buffer,
86  std::unique_lock<std::mutex>& lock);
87  void give_buffer_to_client(graphics::Buffer* buffer,
88  std::unique_lock<std::mutex>& lock, SnapshotWait wait_type);
89  void release(graphics::Buffer* buffer,
90  std::unique_lock<std::mutex> lock);
91  void drop_frame(std::unique_lock<std::mutex>& lock, SnapshotWait wait_type);
92 
93  mutable std::mutex guard;
94 
95  std::vector<std::shared_ptr<graphics::Buffer>> buffers;
96  std::deque<graphics::Buffer*> ready_to_composite_queue;
97  std::deque<graphics::Buffer*> buffers_owned_by_client;
98  std::vector<graphics::Buffer*> free_buffers;
99  std::vector<graphics::Buffer*> buffers_sent_to_compositor;
100  std::vector<graphics::Buffer*> pending_snapshots;
101 
102  std::vector<void const*> current_buffer_users;
103  graphics::Buffer* current_compositor_buffer;
104 
105  std::deque<Callback> pending_client_notifications;
106 
107  bool client_ahead_of_compositor() const;
108  graphics::Buffer* get_a_free_buffer();
109 
110  int nbuffers;
111  int frame_deadlines_threshold;
112  int frame_deadlines_met;
113  int scheduled_extra_frames;
114  MultiMonitorMode mm_mode;
115  bool frame_dropping_enabled;
116  bool current_compositor_buffer_valid;
117  graphics::BufferProperties the_properties;
118  bool force_new_compositor_buffer;
119  bool single_compositor;
120 
121  std::condition_variable snapshot_released;
122  std::shared_ptr<graphics::GraphicBufferAllocator> gralloc;
123 
124  mutable std::mutex callbacks_guard;
125  bool callbacks_allowed;
126 
127  // Ensure framedrop_policy gets destroyed first so the callback installed
128  // does not access dead objects.
129  std::unique_ptr<FrameDroppingPolicy> framedrop_policy;
130 };
131 
132 }
133 }
134 
135 #endif
Definition: size.h:30
All things Mir.
Definition: atomic_callback.h:25
Definition: buffer_bundle.h:67
MultiMonitorMode
Definition: buffer_bundle.h:33
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 Thu Sep 8 14:50:19 UTC 2016