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 
30 namespace mir
31 {
32 namespace graphics
33 {
34 class Display;
35 }
36 namespace scene
37 {
38 class Observer;
39 }
40 
41 namespace compositor
42 {
43 
44 class DisplayBufferCompositorFactory;
45 class CompositingFunctor;
46 class Scene;
47 class CompositorReport;
48 
49 enum class CompositorState
50 {
51  started,
52  stopped,
53  starting,
54  stopping
55 };
56 
58 {
59 public:
60  MultiThreadedCompositor(std::shared_ptr<graphics::Display> const& display,
61  std::shared_ptr<Scene> const& scene,
62  std::shared_ptr<DisplayBufferCompositorFactory> const& db_compositor_factory,
63  std::shared_ptr<CompositorReport> const& compositor_report,
64  bool compose_on_start);
66 
67  void start();
68  void stop();
69 
70 private:
71  void create_compositing_threads();
72  void destroy_compositing_threads(std::unique_lock<std::mutex>& lock);
73 
74  std::shared_ptr<graphics::Display> const display;
75  std::shared_ptr<Scene> const scene;
76  std::shared_ptr<DisplayBufferCompositorFactory> const display_buffer_compositor_factory;
77  std::shared_ptr<CompositorReport> const report;
78 
79  std::vector<std::unique_ptr<CompositingFunctor>> thread_functors;
80  std::vector<std::future<void>> futures;
81 
82  std::mutex state_guard;
83  CompositorState state;
84  bool compose_on_start;
85 
86  void schedule_compositing(int number_composites);
87 
88  std::shared_ptr<mir::scene::Observer> observer;
89  mir::thread::BasicThreadPool thread_pool;
90 };
91 
92 }
93 }
94 
95 #endif /* MIR_COMPOSITOR_MULTI_THREADED_COMPOSITOR_H_ */
All things Mir.
Definition: buffer_stream.h:37
CompositorState
Definition: multi_threaded_compositor.h:49
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< CompositorReport > const &compositor_report, bool compose_on_start)
Definition: multi_threaded_compositor.cpp:207
~MultiThreadedCompositor()
Definition: multi_threaded_compositor.cpp:232
void stop()
Definition: multi_threaded_compositor.cpp:277
Definition: multi_threaded_compositor.h:57
Definition: basic_thread_pool.h:34
void start()
Definition: multi_threaded_compositor.cpp:246
Definition: compositor.h:27

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Mar 24 16:15:19 UTC 2015