Mir
null_display_sync_group.h
Go to the documentation of this file.
1 /*
2  * Copyright © 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 2 or 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: Kevin DuBois <kevin.dubois@canonical.com>
17  */
18 
19 #ifndef MIR_TEST_DOUBLES_NULL_DISPLAY_SYNC_GROUP_H_
20 #define MIR_TEST_DOUBLES_NULL_DISPLAY_SYNC_GROUP_H_
21 
22 #include "mir/graphics/display.h"
23 #include "mir/geometry/size.h"
26 #include <thread>
27 
28 namespace mir
29 {
30 namespace test
31 {
32 namespace doubles
33 {
34 
35 struct StubDisplaySyncGroup : graphics::DisplaySyncGroup
36 {
37 public:
38  StubDisplaySyncGroup(std::vector<geometry::Rectangle> const& output_rects)
39  : output_rects{output_rects}
40  {
41  for (auto const& output_rect : output_rects)
42  display_buffers.emplace_back(output_rect);
43  }
45 
46  void for_each_display_buffer(std::function<void(graphics::DisplayBuffer&)> const& f) override
47  {
48  for (auto& db : display_buffers)
49  f(db);
50  }
51 
52  void post() override
53  {
54  /* yield() is needed to ensure reasonable runtime under valgrind for some tests */
55  std::this_thread::yield();
56  }
57 
58  std::chrono::milliseconds recommended_sleep() const override
59  {
60  return std::chrono::milliseconds::zero();
61  }
62 
63 private:
64  std::vector<geometry::Rectangle> const output_rects;
65  std::vector<StubDisplayBuffer> display_buffers;
66 };
67 
68 struct NullDisplaySyncGroup : graphics::DisplaySyncGroup
69 {
70  void for_each_display_buffer(std::function<void(graphics::DisplayBuffer&)> const& f) override
71  {
72  f(db);
73  }
74  virtual void post() override
75  {
76  /* yield() is needed to ensure reasonable runtime under valgrind for some tests */
77  std::this_thread::yield();
78  }
79 
80  std::chrono::milliseconds recommended_sleep() const override
81  {
82  return std::chrono::milliseconds::zero();
83  }
84 
86 };
87 
88 }
89 }
90 }
91 
92 #endif /* MIR_TEST_DOUBLES_NULL_DISPLAY_SYNC_GROUP_H_ */
Definition: null_display_sync_group.h:68
Definition: size.h:30
virtual void post() override
Definition: null_display_sync_group.h:74
AutoUnblockThread is a helper thread class that can gracefully shutdown at destruction time...
Definition: sw_splash.h:26
NullDisplayBuffer db
Definition: null_display_sync_group.h:85
Definition: null_display_buffer.h:31
Definition: null_display_sync_group.h:35
StubDisplaySyncGroup(std::vector< geometry::Rectangle > const &output_rects)
Definition: null_display_sync_group.h:38
std::chrono::milliseconds recommended_sleep() const override
Definition: null_display_sync_group.h:80
StubDisplaySyncGroup(geometry::Size sz)
Definition: null_display_sync_group.h:44
void for_each_display_buffer(std::function< void(graphics::DisplayBuffer &)> const &f) override
Definition: null_display_sync_group.h:46
void post() override
Definition: null_display_sync_group.h:52
std::chrono::milliseconds recommended_sleep() const override
Definition: null_display_sync_group.h:58
void for_each_display_buffer(std::function< void(graphics::DisplayBuffer &)> const &f) override
Definition: null_display_sync_group.h:70

Copyright © 2012-2017 Canonical Ltd.
Generated on Mon Oct 30 19:44:55 UTC 2017