Mir

Merge lp:~vanvugt/mir/resize-BufferBundle into lp:mir

Proposed by Daniel van Vugt
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 1184
Proposed branch: lp:~vanvugt/mir/resize-BufferBundle
Merge into: lp:mir
Prerequisite: lp:~vanvugt/mir/StubBuffer-remembers-properties
Diff against target: 197 lines (+113/-1)
6 files modified
include/test/mir_test_doubles/mock_buffer_bundle.h (+1/-0)
src/server/compositor/buffer_bundle.h (+1/-0)
src/server/compositor/switching_bundle.cpp (+15/-0)
src/server/compositor/switching_bundle.h (+9/-1)
tests/unit-tests/compositor/test_switching_bundle.cpp (+86/-0)
tests/unit-tests/surfaces/test_surface_stack.cpp (+1/-0)
To merge this branch: bzr merge lp:~vanvugt/mir/resize-BufferBundle
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alexandros Frantzis (community) Approve
Kevin DuBois (community) Approve
Review via email: mp+193203@code.launchpad.net

Commit message

Add resize() support to BufferBundle. This is the first step and lowest level
of surface resize support.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

46 +void mc::SwitchingBundle::resize(const geometry::Size &newsize)
47 +{
48 + bundle_properties.size = newsize;
49 +}

We should guard this with a lock, since bundle_properties is not immutable any more.
The same applies to mc::SwitchingBundle::properties(), and also for allow_framedropping(),
framedropping_allowed() (existing problem).

review: Needs Fixing
Revision history for this message
Kevin DuBois (kdub) wrote :

apart from the locking, looks good to me. will 'pre-approve'

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Thanks for catching that. Locking added.

There is an argument that simple setting and getting of bools is "atomic enough" and that they don't need to be locked. But I think we should lock them, if for no other reason than to keep the helgrind warnings down.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Ignore the clang failure. That's bug 1246590.

Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/test/mir_test_doubles/mock_buffer_bundle.h'
2--- include/test/mir_test_doubles/mock_buffer_bundle.h 2013-08-28 03:41:48 +0000
3+++ include/test/mir_test_doubles/mock_buffer_bundle.h 2013-10-31 03:22:31 +0000
4@@ -47,6 +47,7 @@
5 MOCK_CONST_METHOD0(properties, graphics::BufferProperties());
6 MOCK_METHOD0(force_client_abort, void());
7 MOCK_METHOD0(force_requests_to_complete, void());
8+ MOCK_METHOD1(resize, void(const geometry::Size &));
9 };
10
11 }
12
13=== modified file 'src/server/compositor/buffer_bundle.h'
14--- src/server/compositor/buffer_bundle.h 2013-08-28 03:41:48 +0000
15+++ src/server/compositor/buffer_bundle.h 2013-10-31 03:22:31 +0000
16@@ -45,6 +45,7 @@
17 virtual graphics::BufferProperties properties() const = 0;
18 virtual void allow_framedropping(bool dropping_allowed) = 0;
19 virtual void force_requests_to_complete() = 0;
20+ virtual void resize(const geometry::Size &newsize) = 0;
21 protected:
22 BufferBundle() = default;
23 BufferBundle(BufferBundle const&) = delete;
24
25=== modified file 'src/server/compositor/switching_bundle.cpp'
26--- src/server/compositor/switching_bundle.cpp 2013-10-18 09:54:49 +0000
27+++ src/server/compositor/switching_bundle.cpp 2013-10-31 03:22:31 +0000
28@@ -239,6 +239,12 @@
29 }
30 }
31
32+ if (ret->size() != bundle_properties.size)
33+ {
34+ ret = gralloc->alloc_buffer(bundle_properties);
35+ ring[client].buf = ret;
36+ }
37+
38 return ret;
39 }
40
41@@ -391,15 +397,24 @@
42
43 void mc::SwitchingBundle::allow_framedropping(bool allow_dropping)
44 {
45+ std::unique_lock<std::mutex> lock(guard);
46 framedropping = allow_dropping;
47 }
48
49 bool mc::SwitchingBundle::framedropping_allowed() const
50 {
51+ std::unique_lock<std::mutex> lock(guard);
52 return framedropping;
53 }
54
55 mg::BufferProperties mc::SwitchingBundle::properties() const
56 {
57+ std::unique_lock<std::mutex> lock(guard);
58 return bundle_properties;
59 }
60+
61+void mc::SwitchingBundle::resize(const geometry::Size &newsize)
62+{
63+ std::unique_lock<std::mutex> lock(guard);
64+ bundle_properties.size = newsize;
65+}
66
67=== modified file 'src/server/compositor/switching_bundle.h'
68--- src/server/compositor/switching_bundle.h 2013-08-28 03:41:48 +0000
69+++ src/server/compositor/switching_bundle.h 2013-10-31 03:22:31 +0000
70@@ -55,6 +55,14 @@
71 void allow_framedropping(bool dropping_allowed);
72 bool framedropping_allowed() const;
73
74+ /**
75+ * Change the dimensions of the buffers contained in the bundle. For
76+ * client_acquire, the change is guaranteed to be immediate. For
77+ * compositors and snapshotters however, the change may be delayed by
78+ * nbuffers frames while old frames of the old size are consumed.
79+ */
80+ void resize(const geometry::Size &newsize) override;
81+
82 private:
83 graphics::BufferProperties bundle_properties;
84 std::shared_ptr<graphics::GraphicBufferAllocator> gralloc;
85@@ -86,7 +94,7 @@
86 int snapshot;
87 int nsnapshotters;
88
89- std::mutex guard;
90+ mutable std::mutex guard;
91 std::condition_variable cond;
92
93 unsigned long last_consumed;
94
95=== modified file 'tests/unit-tests/compositor/test_switching_bundle.cpp'
96--- tests/unit-tests/compositor/test_switching_bundle.cpp 2013-10-18 09:54:49 +0000
97+++ tests/unit-tests/compositor/test_switching_bundle.cpp 2013-10-31 03:22:31 +0000
98@@ -754,3 +754,89 @@
99 }
100 }
101
102+TEST_F(SwitchingBundleTest, resize_affects_client_acquires_immediately)
103+{
104+ for (int nbuffers = 1; nbuffers <= 5; ++nbuffers)
105+ {
106+ mc::SwitchingBundle bundle(nbuffers, allocator, basic_properties);
107+ unsigned long frameno = 1;
108+
109+ for (int width = 1; width < 100; ++width)
110+ {
111+ const geom::Size expect_size{width, width * 2};
112+
113+ for (int subframe = 0; subframe < 3; ++subframe)
114+ {
115+ bundle.resize(expect_size);
116+ auto client = bundle.client_acquire();
117+ ASSERT_EQ(expect_size, client->size());
118+ bundle.client_release(client);
119+
120+ auto compositor = bundle.compositor_acquire(frameno++);
121+ ASSERT_EQ(expect_size, compositor->size());
122+ bundle.compositor_release(compositor);
123+ }
124+ }
125+ }
126+}
127+
128+TEST_F(SwitchingBundleTest, compositor_acquires_resized_frames)
129+{
130+ for (int nbuffers = 1; nbuffers <= 5; ++nbuffers)
131+ {
132+ mc::SwitchingBundle bundle(nbuffers, allocator, basic_properties);
133+ mg::BufferID history[5];
134+ unsigned long frameno = 1;
135+
136+ const int width0 = 123;
137+ const int height0 = 456;
138+ const int dx = 2;
139+ const int dy = -3;
140+ int width = width0;
141+ int height = height0;
142+
143+ for (int produce = 0; produce < nbuffers; ++produce)
144+ {
145+ geom::Size new_size{width, height};
146+ width += dx;
147+ height += dy;
148+
149+ bundle.resize(new_size);
150+ auto client = bundle.client_acquire();
151+ history[produce] = client->id();
152+ ASSERT_EQ(new_size, client->size());
153+ bundle.client_release(client);
154+ }
155+
156+ width = width0;
157+ height = height0;
158+
159+ for (int consume = 0; consume < nbuffers; ++consume)
160+ {
161+ geom::Size expect_size{width, height};
162+ width += dx;
163+ height += dy;
164+
165+ auto compositor = bundle.compositor_acquire(frameno++);
166+
167+ // Verify the compositor gets resized buffers, eventually
168+ ASSERT_EQ(expect_size, compositor->size());
169+
170+ // Verify the compositor gets buffers with *contents*, ie. that
171+ // they have not been resized prematurely and are empty.
172+ ASSERT_EQ(history[consume], compositor->id());
173+
174+ bundle.compositor_release(compositor);
175+ }
176+
177+ // Verify the final buffer size sticks
178+ const geom::Size final_size{width - dx, height - dy};
179+ for (int unchanging = 0; unchanging < 100; ++unchanging)
180+ {
181+ auto compositor = bundle.compositor_acquire(frameno++);
182+ ASSERT_EQ(final_size, compositor->size());
183+ bundle.compositor_release(compositor);
184+ }
185+ }
186+}
187+
188
189=== modified file 'tests/unit-tests/surfaces/test_surface_stack.cpp'
190--- tests/unit-tests/surfaces/test_surface_stack.cpp 2013-10-25 09:01:53 +0000
191+++ tests/unit-tests/surfaces/test_surface_stack.cpp 2013-10-31 03:22:31 +0000
192@@ -78,6 +78,7 @@
193 void force_requests_to_complete() {}
194 virtual void allow_framedropping(bool) {}
195 virtual mg::BufferProperties properties() const { return mg::BufferProperties{}; };
196+ void resize(const geom::Size &) override {}
197 };
198
199

Subscribers

People subscribed via source and target branches