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 graphics
35 {
36 class Display;
37 }
38 namespace scene
39 {
40 class Observer;
41 }
42 
43 namespace compositor
44 {
45 
46 class DisplayBufferCompositorFactory;
47 class DisplayListener;
48 class CompositingFunctor;
49 class Scene;
50 class CompositorReport;
51 
52 enum class CompositorState
53 {
54  started,
55  stopped,
56  starting,
57  stopping
58 };
59 
61 {
62 public:
64  std::shared_ptr<graphics::Display> const& display,
65  std::shared_ptr<Scene> const& scene,
66  std::shared_ptr<DisplayBufferCompositorFactory> const& db_compositor_factory,
67  std::shared_ptr<DisplayListener> const& display_listener,
68  std::shared_ptr<CompositorReport> const& compositor_report,
69  std::chrono::milliseconds fixed_composite_delay, // -1 = automatic
70  bool compose_on_start);
72 
73  void start();
74  void stop();
75 
76 private:
77  void create_compositing_threads();
78  void destroy_compositing_threads();
79 
80  std::shared_ptr<graphics::Display> const display;
81  std::shared_ptr<Scene> const scene;
82  std::shared_ptr<DisplayBufferCompositorFactory> const display_buffer_compositor_factory;
83  std::shared_ptr<DisplayListener> const display_listener;
84  std::shared_ptr<CompositorReport> const report;
85 
86  std::vector<std::unique_ptr<CompositingFunctor>> thread_functors;
87  std::vector<std::future<void>> futures;
88 
89  std::atomic<CompositorState> state;
90  std::chrono::milliseconds fixed_composite_delay;
91  bool compose_on_start;
92 
93  void schedule_compositing(int number_composites);
94 
95  std::shared_ptr<mir::scene::Observer> observer;
96  mir::thread::BasicThreadPool thread_pool;
97 };
98 
99 }
100 }
101 
102 #endif /* MIR_COMPOSITOR_MULTI_THREADED_COMPOSITOR_H_ */
All things Mir.
Definition: atomic_callback.h:25
CompositorState
Definition: multi_threaded_compositor.h:52
~MultiThreadedCompositor()
Definition: multi_threaded_compositor.cpp:256
void stop()
Definition: multi_threaded_compositor.cpp:291
Definition: multi_threaded_compositor.h:60
Definition: basic_thread_pool.h:34
MultiThreadedCompositor(std::shared_ptr< graphics::Display > const &display, std::shared_ptr< Scene > const &scene, std::shared_ptr< DisplayBufferCompositorFactory > const &db_compositor_factory, std::shared_ptr< DisplayListener > const &display_listener, std::shared_ptr< CompositorReport > const &compositor_report, std::chrono::milliseconds fixed_composite_delay, bool compose_on_start)
Definition: multi_threaded_compositor.cpp:227
void start()
Definition: multi_threaded_compositor.cpp:268
Definition: compositor.h:27

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015