Mir
multi_threaded_compositor.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: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17  */
18 
19 #ifndef MIR_COMPOSITOR_MULTI_THREADED_COMPOSITOR_H_
20 #define MIR_COMPOSITOR_MULTI_THREADED_COMPOSITOR_H_
21 
24 
25 #include <mutex>
26 #include <memory>
27 #include <vector>
28 #include <future>
29 #include <chrono>
30 #include <atomic>
31 
32 namespace mir
33 {
34 namespace geometry { class Rectangle; }
35 namespace graphics
36 {
37 class Display;
38 }
39 namespace scene
40 {
41 class Observer;
42 }
43 
44 namespace compositor
45 {
46 
47 class DisplayBufferCompositorFactory;
48 class DisplayListener;
49 class CompositingFunctor;
50 class Scene;
51 class CompositorReport;
52 
53 enum class CompositorState
54 {
55  started,
56  stopped,
57  starting,
58  stopping
59 };
60 
62 {
63 public:
65  std::shared_ptr<graphics::Display> const& display,
66  std::shared_ptr<Scene> const& scene,
67  std::shared_ptr<DisplayBufferCompositorFactory> const& db_compositor_factory,
68  std::shared_ptr<DisplayListener> const& display_listener,
69  std::shared_ptr<CompositorReport> const& compositor_report,
70  std::chrono::milliseconds fixed_composite_delay, // -1 = automatic
71  bool compose_on_start);
73 
74  void start();
75  void stop();
76 
77 private:
78  void create_compositing_threads();
79  void destroy_compositing_threads();
80 
81  std::shared_ptr<graphics::Display> const display;
82  std::shared_ptr<Scene> const scene;
83  std::shared_ptr<DisplayBufferCompositorFactory> const display_buffer_compositor_factory;
84  std::shared_ptr<DisplayListener> const display_listener;
85  std::shared_ptr<CompositorReport> const report;
86 
87  std::vector<std::unique_ptr<CompositingFunctor>> thread_functors;
88  std::vector<std::future<void>> futures;
89 
90  std::atomic<CompositorState> state;
91  std::chrono::milliseconds fixed_composite_delay;
92  bool compose_on_start;
93 
94  void schedule_compositing(int number_composites);
95  void schedule_compositing(int number_composites, geometry::Rectangle const& damage) const;
96 
97  std::shared_ptr<mir::scene::Observer> observer;
98  mir::thread::BasicThreadPool thread_pool;
99 };
100 
101 }
102 }
103 
104 #endif /* MIR_COMPOSITOR_MULTI_THREADED_COMPOSITOR_H_ */
All things Mir.
Definition: atomic_callback.h:25
CompositorState
Definition: multi_threaded_compositor.h:53
Definition: multi_threaded_compositor.h:61
Definition: basic_thread_pool.h:34
std::promise< bool > stop
Definition: in.cpp:28
Definition: rectangle.h:33
Definition: compositor.h:27

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