Mir
surface_stack.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012-2014 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: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIR_SCENE_SURFACE_STACK_H_
20 #define MIR_SCENE_SURFACE_STACK_H_
21 
22 #include "surface_stack_model.h"
23 
24 #include "mir/compositor/scene.h"
25 #include "mir/scene/depth_id.h"
26 #include "mir/scene/observer.h"
27 #include "mir/input/scene.h"
28 
29 #include "mir/basic_observers.h"
30 
31 #include <memory>
32 #include <vector>
33 #include <mutex>
34 #include <map>
35 #include <set>
36 
37 namespace mir
38 {
39 namespace graphics
40 {
41 class Renderable;
42 }
45 namespace scene
46 {
47 class InputRegistrar;
48 class BasicSurface;
49 class SceneReport;
50 class RenderingTracker;
51 
52 class Observers : public Observer, BasicObservers<Observer>
53 {
54 public:
55  // ms::Observer
56  void surface_added(Surface* surface) override;
57  void surface_removed(Surface* surface) override;
58  void surfaces_reordered() override;
59  void scene_changed() override;
60  void surface_exists(Surface* surface) override;
61  void end_observation() override;
62 
65 };
66 
68 {
69 public:
70  explicit SurfaceStack(
71  std::shared_ptr<SceneReport> const& report);
72  virtual ~SurfaceStack() noexcept(true) {}
73 
74  // From Scene
76  int frames_pending(compositor::CompositorID) const override;
79 
80  // From Scene
81  void for_each(std::function<void(std::shared_ptr<input::Surface> const&)> const& callback) override;
82 
83  virtual void remove_surface(std::weak_ptr<Surface> const& surface) override;
84 
85  virtual void raise(std::weak_ptr<Surface> const& surface) override;
86 
87  void raise(SurfaceSet const& surfaces) override;
88 
89  void add_surface(
90  std::shared_ptr<Surface> const& surface,
91  DepthId depth,
92  input::InputReceptionMode input_mode) override;
93 
94  auto surface_at(geometry::Point) const -> std::shared_ptr<Surface> override;
95 
96  void add_observer(std::shared_ptr<Observer> const& observer) override;
97  void remove_observer(std::weak_ptr<Observer> const& observer) override;
98 
99  // Intended for input overlays, as described in mir::input::Scene documentation.
100  void add_input_visualization(std::shared_ptr<graphics::Renderable> const& overlay) override;
101  void remove_input_visualization(std::weak_ptr<graphics::Renderable> const& overlay) override;
102 
103  void emit_scene_changed() override;
104 
105 private:
106  SurfaceStack(const SurfaceStack&) = delete;
107  SurfaceStack& operator=(const SurfaceStack&) = delete;
108  void create_rendering_tracker_for(std::shared_ptr<Surface> const&);
109  void update_rendering_tracker_compositors();
110 
111  std::mutex mutable guard;
112 
113  std::shared_ptr<InputRegistrar> const input_registrar;
114  std::shared_ptr<SceneReport> const report;
115 
116  typedef std::vector<std::shared_ptr<Surface>> Layer;
117  std::map<DepthId, Layer> layers_by_depth;
118  std::map<Surface*,std::shared_ptr<RenderingTracker>> rendering_trackers;
119  std::set<compositor::CompositorID> registered_compositors;
120 
121  std::vector<std::shared_ptr<graphics::Renderable>> overlays;
122 
123  Observers observers;
124  bool scene_changed = false;
125 };
126 
127 }
128 }
129 
130 #endif /* MIR_SCENE_SURFACE_STACK_H_ */
Definition: scene.h:42
All things Mir.
Definition: atomic_callback.h:25
Definition: surface_stack_model.h:37
void surface_added(Surface *surface) override
Definition: surface_stack.cpp:429
Definition: hwc_layers.h:45
Definition: surface_stack.h:67
Definition: scene_report.h:29
Definition: point.h:30
void surface_removed(Surface *surface) override
Definition: surface_stack.cpp:435
int frames_pending(compositor::CompositorID) const override
Return the number of additional frames that you need to render to get fully up to date with the lates...
Definition: surface_stack.cpp:159
An observer for top level notifications of scene changes. In order to receive more granular change no...
Definition: observer.h:33
STL namespace.
std::set< std::weak_ptr< Surface >, std::owner_less< std::weak_ptr< Surface >>> SurfaceSet
Definition: surface_stack_model.h:40
void for_each(std::function< void(std::shared_ptr< input::Surface > const &)> const &callback) override
Definition: surface_stack.cpp:321
void emit_scene_changed() override
Definition: surface_stack.cpp:231
void add_input_visualization(std::shared_ptr< graphics::Renderable > const &overlay) override
Definition: surface_stack.cpp:204
void add_observer(std::shared_ptr< Observer > const &observer) override
Definition: surface_stack.cpp:403
std::vector< std::shared_ptr< SceneElement >> SceneElementSequence
Definition: scene.h:38
Definition: scene.h:40
virtual void remove_surface(std::weak_ptr< Surface > const &surface) override
Definition: surface_stack.cpp:256
true
Definition: display_configuration.cpp:30
SurfaceStack(std::shared_ptr< SceneReport > const &report)
Definition: surface_stack.cpp:122
compositor::SceneElementSequence scene_elements_for(compositor::CompositorID id) override
Generate a valid sequence of scene elements based on the current state of the Scene.
Definition: surface_stack.cpp:128
void unregister_compositor(compositor::CompositorID id) override
Definition: surface_stack.cpp:195
Definition: surface_stack.h:52
virtual ~SurfaceStack() noexcept(true)
Definition: surface_stack.h:72
void remove_input_visualization(std::weak_ptr< graphics::Renderable > const &overlay) override
Definition: surface_stack.cpp:214
auto surface_at(geometry::Point) const -> std::shared_ptr< Surface > override
Definition: surface_stack.cpp:301
void remove_observer(std::weak_ptr< Observer > const &observer) override
Definition: surface_stack.cpp:418
void const * CompositorID
Definition: compositor_id.h:27
Definition: basic_observers.h:28
void end_observation() override
Definition: surface_stack.cpp:459
void surface_exists(Surface *surface) override
Definition: surface_stack.cpp:453
void surfaces_reordered() override
Definition: surface_stack.cpp:441
void add_surface(std::shared_ptr< Surface > const &surface, DepthId depth, input::InputReceptionMode input_mode) override
Definition: surface_stack.cpp:240
InputReceptionMode
Definition: input_reception_mode.h:27
void register_compositor(compositor::CompositorID id) override
Definition: surface_stack.cpp:186
Definition: surface.h:47
Definition: rendering_tracker.h:37
void scene_changed() override
Definition: surface_stack.cpp:447

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