Mir

Merge lp:~kdub/mir/submission-associated-buffer-cb into lp:mir

Proposed by Kevin DuBois
Status: Merged
Approved by: Cemil Azizoglu
Approved revision: no longer in the source branch.
Merged at revision: 3974
Proposed branch: lp:~kdub/mir/submission-associated-buffer-cb
Merge into: lp:mir
Diff against target: 517 lines (+116/-159)
13 files modified
playground/mir_demo_client_chain_jumping_buffers.c (+2/-1)
playground/mir_demo_client_prerendered_frames.c (+1/-1)
src/client/mir_buffer_api.cpp (+36/-13)
src/client/mir_presentation_chain_api.cpp (+5/-1)
src/client/symbols.map (+1/-1)
src/include/client/mir_toolkit/mir_buffer.h (+15/-15)
src/include/client/mir_toolkit/mir_presentation_chain.h (+10/-6)
src/server/graphics/nested/mir_client_host_connection.cpp (+9/-2)
src/server/graphics/nested/native_buffer.h (+1/-0)
tests/acceptance-tests/test_presentation_chain.cpp (+33/-119)
tests/unit-tests/platforms/nested/test_buffer.cpp (+1/-0)
tests/unit-tests/platforms/nested/test_ipc_operations.cpp (+1/-0)
tests/unit-tests/platforms/nested/test_nested_display_buffer.cpp (+1/-0)
To merge this branch: bzr merge lp:~kdub/mir/submission-associated-buffer-cb
Reviewer Review Type Date Requested Status
Cemil Azizoglu (community) Approve
Chris Halse Rogers Approve
Alan Griffiths Approve
Alexandros Frantzis (community) Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+315214@code.launchpad.net

Commit message

MirBuffer api: When a MirBuffer is submitted, the client api user will get a callback from the server once the MirBuffer is available again. Previously this callback was something given at buffer creation time, and could be set to something else later. This proposes changing the callback to be given at each time of submission.

This lets the api user:
1) have a handy mir_connection_buffer_allocate_sync() function, as waiting on the initial creation is not dangerous. (waiting forever immediately on a mir_presentation_chain_submit callback is a bit dangerous, because we make no guarantees about how long the server will own the buffer)
2) Puts callback designation closer to submission, which might make more sense, as the user is managing the effect of submitting at the same place they're submitting the buffer to the server.

This is for the 0.27 series (when MirSurface/MirBuffer/MirPresentationChain gets published).

Description of the change

MirBuffer api: When a MirBuffer is submitted, the client api user will get a callback from the server once the MirBuffer is available again. Previously this callback was something given at buffer creation time, and could be set to something else later. This proposes changing the callback to be given at each time of submission.

This lets the api user:
1) have a handy mir_connection_buffer_allocate_sync() function, as waiting on the initial creation is not dangerous. (waiting forever immediately on a mir_presentation_chain_submit callback is a bit dangerous, because we make no guarantees about how long the server will own the buffer)
2) Puts callback designation closer to submission, which might make more sense, as the user is managing the effect of submitting at the same place they're submitting the buffer to the server.

This is for the 0.27 series (when MirSurface/MirBuffer/MirPresentationChain gets published).

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:3964
https://mir-jenkins.ubuntu.com/job/mir-ci/2795/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/3663/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/3742
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/3732
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/3732
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/3732
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/3690/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3690
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3690/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/3690
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/3690/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3690
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3690/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3690
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3690/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3690
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3690/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/2795/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3965
https://mir-jenkins.ubuntu.com/job/mir-ci/2802/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/3673
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/3752
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/3742
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/3742
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/3742
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/3700
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/3700/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3700
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3700/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/3700
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/3700/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3700
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3700/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3700
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3700/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3700
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3700/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/2802/rebuild

review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

OK by me.

review: Approve
Revision history for this message
Chris Halse Rogers (raof) wrote :

LGTM.

review: Approve
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

Ok

Nit: indentation

236 + mir_presentation_chain_submit_buffer(chain, buffer.client_handle(),
237 + buffer_available, &buffer);

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'playground/mir_demo_client_chain_jumping_buffers.c'
2--- playground/mir_demo_client_chain_jumping_buffers.c 2017-01-18 02:29:37 +0000
3+++ playground/mir_demo_client_chain_jumping_buffers.c 2017-01-20 15:28:19 +0000
4@@ -250,7 +250,8 @@
5 b = buffer_available[spare_buffer].buffer;
6 pthread_mutex_unlock(&buffer_available[spare_buffer].lock);
7
8- mir_presentation_chain_submit_buffer(chain[i], b);
9+ mir_presentation_chain_submit_buffer(
10+ chain[i], b, available_callback, &buffer_available[spare_buffer]);
11
12 //just looks like a blur if we don't slow things down
13 ualarm(500000, 0);
14
15=== modified file 'playground/mir_demo_client_prerendered_frames.c'
16--- playground/mir_demo_client_prerendered_frames.c 2017-01-18 02:29:37 +0000
17+++ playground/mir_demo_client_prerendered_frames.c 2017-01-20 15:28:19 +0000
18@@ -224,7 +224,7 @@
19 b = buffer_available[i].buffer;
20 pthread_mutex_unlock(&buffer_available[i].lock);
21
22- mir_presentation_chain_submit_buffer(chain, b);
23+ mir_presentation_chain_submit_buffer(chain, b, available_callback, &buffer_available[i]);
24
25 if ((i == num_prerendered_frames - 1) || (i == 0))
26 inc *= -1;
27
28=== modified file 'src/client/mir_buffer_api.cpp'
29--- src/client/mir_buffer_api.cpp 2017-01-18 02:29:37 +0000
30+++ src/client/mir_buffer_api.cpp 2017-01-20 15:28:19 +0000
31@@ -49,6 +49,42 @@
32 MIR_LOG_UNCAUGHT_EXCEPTION(ex);
33 }
34
35+MirBuffer* mir_connection_allocate_buffer_sync(
36+ MirConnection* connection,
37+ int width, int height,
38+ MirPixelFormat format,
39+ MirBufferUsage usage)
40+try
41+{
42+ mir::require(connection);
43+
44+ struct BufferInfo
45+ {
46+ MirBuffer* buffer = nullptr;
47+ std::mutex mutex;
48+ std::condition_variable cv;
49+ } info;
50+ connection->allocate_buffer(mir::geometry::Size{width, height}, format, usage,
51+ [](MirBuffer* buffer, void* c)
52+ {
53+ mir::require(buffer);
54+ mir::require(c);
55+ auto context = reinterpret_cast<BufferInfo*>(c);
56+ std::unique_lock<decltype(context->mutex)> lk(context->mutex);
57+ context->buffer = buffer;
58+ context->cv.notify_all();
59+ }, &info);
60+
61+ std::unique_lock<decltype(info.mutex)> lk(info.mutex);
62+ info.cv.wait(lk, [&]{ return info.buffer; });
63+ return info.buffer;
64+}
65+catch (std::exception const& ex)
66+{
67+ MIR_LOG_UNCAUGHT_EXCEPTION(ex);
68+ return nullptr;
69+}
70+
71 void ignore(MirBuffer*, void*){}
72 void mir_buffer_release(MirBuffer* b)
73 try
74@@ -171,19 +207,6 @@
75 return "MirBuffer: unknown error";
76 }
77
78-void mir_buffer_set_callback(
79- MirBuffer* b, mir_buffer_callback available_callback, void* available_context)
80-try
81-{
82- mir::require(b);
83- auto buffer = reinterpret_cast<mcl::Buffer*>(b);
84- buffer->set_callback(available_callback, available_context);
85-}
86-catch (std::exception const& ex)
87-{
88- MIR_LOG_UNCAUGHT_EXCEPTION(ex);
89-}
90-
91 MirBufferPackage* mir_buffer_get_buffer_package(MirBuffer* b)
92 try
93 {
94
95=== modified file 'src/client/mir_presentation_chain_api.cpp'
96--- src/client/mir_presentation_chain_api.cpp 2017-01-18 02:29:37 +0000
97+++ src/client/mir_presentation_chain_api.cpp 2017-01-20 15:28:19 +0000
98@@ -59,11 +59,15 @@
99 }
100 }
101 //private NBS api under development
102-void mir_presentation_chain_submit_buffer(MirPresentationChain* chain, MirBuffer* b)
103+void mir_presentation_chain_submit_buffer(
104+ MirPresentationChain* chain,
105+ MirBuffer* b,
106+ mir_buffer_callback available_callback, void* available_context)
107 try
108 {
109 auto buffer = reinterpret_cast<mcl::MirBuffer*>(b);
110 mir::require(chain && buffer && mir_presentation_chain_is_valid(chain));
111+ buffer->set_callback(available_callback, available_context);
112 chain->submit_buffer(buffer);
113 }
114 catch (std::exception const& ex)
115
116=== modified file 'src/client/symbols.map'
117--- src/client/symbols.map 2017-01-18 16:25:59 +0000
118+++ src/client/symbols.map 2017-01-20 15:28:19 +0000
119@@ -364,13 +364,13 @@
120 global:
121 mir_buffer_map;
122 mir_buffer_unmap;
123- mir_buffer_set_callback;
124 mir_buffer_release;
125 mir_connection_create_presentation_chain_sync;
126 mir_presentation_chain_is_valid;
127 mir_presentation_chain_get_error_message;
128 mir_connection_create_presentation_chain;
129 mir_connection_allocate_buffer;
130+ mir_connection_allocate_buffer_sync;
131 mir_presentation_chain_submit_buffer;
132 mir_presentation_chain_release;
133 mir_surface_spec_add_presentation_chain;
134
135=== modified file 'src/include/client/mir_toolkit/mir_buffer.h'
136--- src/include/client/mir_toolkit/mir_buffer.h 2017-01-18 02:29:37 +0000
137+++ src/include/client/mir_toolkit/mir_buffer.h 2017-01-20 15:28:19 +0000
138@@ -31,10 +31,7 @@
139 #endif
140
141 /** Allocate a MirBuffer and do not wait for the server to return it.
142- *
143- * The callback will be called when the buffer is available for use.
144- * It will be called once when created, and once per every
145- * mir_presentation_chain_submit_buffer.
146+ * The callback will be called when the buffer is created.
147 *
148 * \param [in] connection The connection
149 * \param [in] width Requested buffer width
150@@ -51,6 +48,20 @@
151 MirBufferUsage buffer_usage,
152 mir_buffer_callback available_callback, void* available_context);
153
154+/** Allocate a MirBuffer and wait for the server to return it.
155+ *
156+ * \param [in] connection The connection
157+ * \param [in] width Requested buffer width
158+ * \param [in] height Requested buffer height
159+ * \param [in] buffer_usage Requested buffer usage
160+ * \return The buffer
161+ **/
162+MirBuffer* mir_connection_allocate_buffer_sync(
163+ MirConnection* connection,
164+ int width, int height,
165+ MirPixelFormat format,
166+ MirBufferUsage buffer_usage);
167+
168 /** Test for a valid buffer
169 * \param [in] buffer The buffer
170 * \return True if the buffer is valid, or false otherwise.
171@@ -67,17 +78,6 @@
172 **/
173 char const *mir_buffer_get_error_message(MirBuffer* buffer);
174
175-/** Reassign the callback that the MirBuffer will call when the buffer is
176- * available for use again
177- * \param [in] buffer The buffer
178- * \param [in] available_callback The callback called when the buffer
179- * is available
180- * \param [in] available_context The context for the available_callback
181- */
182-void mir_buffer_set_callback(
183- MirBuffer* buffer,
184- mir_buffer_callback available_callback, void* available_context);
185-
186 /**
187 * Access the MirBufferPackage
188 *
189
190=== modified file 'src/include/client/mir_toolkit/mir_presentation_chain.h'
191--- src/include/client/mir_toolkit/mir_presentation_chain.h 2017-01-18 04:43:15 +0000
192+++ src/include/client/mir_toolkit/mir_presentation_chain.h 2017-01-20 15:28:19 +0000
193@@ -87,15 +87,19 @@
194 * The server will notify the client when the buffer is available again via
195 * the callback registered during buffer creation.
196 *
197- * \warning: Once submitted, the buffer cannot be modified until the server
198- * has returned it. There's no guarantee about how long a server
199- * may hold the submitted buffer.
200+ * \warning: Once submitted, the buffer cannot be modified or resubmitted
201+ * until the server has returned it. There's no guarantee about
202+ * how long a server may hold the submitted buffer.
203 *
204- * \param [in] presentation_chain The presentation chain
205- * \param [in] buffer The buffer to be submitted
206+ * \param [in] presentation_chain The presentation chain
207+ * \param [in] buffer The buffer to be submitted
208+ * \param [in] available_callback The callback called when the buffer
209+ * is available
210+ * \param [in] available_context The context for the available_callback
211 **/
212 void mir_presentation_chain_submit_buffer(
213- MirPresentationChain* presentation_chain, MirBuffer* buffer);
214+ MirPresentationChain* presentation_chain, MirBuffer* buffer,
215+ mir_buffer_callback available_callback, void* available_context);
216
217 /**
218 * Set the MirSurfaceContent to display a MirPresentationChain.
219
220=== modified file 'src/server/graphics/nested/mir_client_host_connection.cpp'
221--- src/server/graphics/nested/mir_client_host_connection.cpp 2017-01-18 19:57:47 +0000
222+++ src/server/graphics/nested/mir_client_host_connection.cpp 2017-01-20 15:28:19 +0000
223@@ -514,9 +514,16 @@
224 mir_presentation_chain_release(chain);
225 }
226
227+ static void buffer_available(MirBuffer* buffer, void* context)
228+ {
229+ auto host_buffer = static_cast<mgn::NativeBuffer*>(context);
230+ host_buffer->available(buffer);
231+ }
232+
233 void submit_buffer(mgn::NativeBuffer& buffer) override
234 {
235- mir_presentation_chain_submit_buffer(chain, buffer.client_handle());
236+ mir_presentation_chain_submit_buffer(chain, buffer.client_handle(),
237+ buffer_available, &buffer);
238 }
239
240 void set_submission_mode(mgn::SubmissionMode mode) override
241@@ -682,7 +689,7 @@
242 host_buffer->available(buffer);
243 }
244
245- void available(MirBuffer* buffer)
246+ void available(MirBuffer* buffer) override
247 {
248 std::unique_lock<std::mutex> lk(mut);
249 if (!handle)
250
251=== modified file 'src/server/graphics/nested/native_buffer.h'
252--- src/server/graphics/nested/native_buffer.h 2017-01-18 02:29:37 +0000
253+++ src/server/graphics/nested/native_buffer.h 2017-01-20 15:28:19 +0000
254@@ -62,6 +62,7 @@
255 virtual Fd fence() const = 0;
256 virtual void set_fence(Fd) = 0;
257 virtual std::tuple<EGLenum, EGLClientBuffer, EGLint*> egl_image_creation_hints() const = 0;
258+ virtual void available(MirBuffer* buffer) = 0;
259 protected:
260 NativeBuffer() = default;
261 NativeBuffer(NativeBuffer const&) = delete;
262
263=== modified file 'tests/acceptance-tests/test_presentation_chain.cpp'
264--- tests/acceptance-tests/test_presentation_chain.cpp 2017-01-18 04:43:15 +0000
265+++ tests/acceptance-tests/test_presentation_chain.cpp 2017-01-20 15:28:19 +0000
266@@ -154,6 +154,12 @@
267
268 struct MirBufferSync
269 {
270+ MirBufferSync() {}
271+ MirBufferSync(MirBuffer* buffer) :
272+ buffer_(buffer)
273+ {
274+ }
275+
276 void buffer_available(MirBuffer* b)
277 {
278 std::unique_lock<std::mutex> lk(mutex);
279@@ -302,74 +308,36 @@
280
281 for(auto i = 0u; i < num_iterations; i++)
282 {
283- mir_presentation_chain_submit_buffer(window.chain(), contexts[i % num_buffers].buffer());
284- contexts[i % num_buffers].unavailable();
285- if (i != 0)
286- ASSERT_TRUE(contexts[(i-1) % num_buffers].wait_for_buffer(10s)) << "iteration " << i;
287- }
288-
289- for (auto& context : contexts)
290- mir_buffer_set_callback(context.buffer(), ignore_callback, nullptr);
291-}
292-
293-TEST_F(PresentationChain, submission_will_eventually_call_callback_reassociated)
294-{
295- SurfaceWithChainFromReassociation window(connection, size, pf);
296-
297- auto const num_buffers = 2u;
298- std::array<MirBufferSync, num_buffers> contexts;
299- auto num_iterations = 50u;
300- for(auto& context : contexts)
301- {
302- mir_connection_allocate_buffer(
303- connection,
304- size.width.as_int(), size.height.as_int(), pf, usage,
305- buffer_callback, &context);
306- ASSERT_TRUE(context.wait_for_buffer(10s));
307- ASSERT_THAT(context.buffer(), Ne(nullptr));
308- }
309-
310- for(auto i = 0u; i < num_iterations; i++)
311- {
312- mir_presentation_chain_submit_buffer(window.chain(), contexts[i % num_buffers].buffer());
313- contexts[i % num_buffers].unavailable();
314- if (i != 0)
315- ASSERT_TRUE(contexts[(i-1) % num_buffers].wait_for_buffer(10s)) << "iteration " << i;
316- }
317- for (auto& context : contexts)
318- mir_buffer_set_callback(context.buffer(), ignore_callback, nullptr);
319+ mir_presentation_chain_submit_buffer(
320+ window.chain(), contexts[i % num_buffers].buffer(),
321+ buffer_callback, &contexts[i % num_buffers]);
322+ contexts[i % num_buffers].unavailable();
323+ if (i != 0)
324+ ASSERT_TRUE(contexts[(i-1) % num_buffers].wait_for_buffer(10s)) << "iteration " << i;
325+ }
326+
327+ for (auto& context : contexts)
328+ mir_buffer_release(context.buffer());
329 }
330
331 TEST_F(PresentationChain, buffers_can_be_destroyed_before_theyre_returned)
332 {
333 SurfaceWithChainFromStart window(connection, size, pf);
334
335- MirBufferSync context;
336- mir_connection_allocate_buffer(
337- connection,
338- size.width.as_int(), size.height.as_int(), pf, usage,
339- buffer_callback, &context);
340+ auto buffer = mir_connection_allocate_buffer_sync(
341+ connection, size.width.as_int(), size.height.as_int(), pf, usage);
342
343- ASSERT_TRUE(context.wait_for_buffer(10s));
344- ASSERT_THAT(context.buffer(), Ne(nullptr));
345- mir_presentation_chain_submit_buffer(window.chain(), context.buffer());
346- mir_buffer_release(context.buffer());
347+ mir_presentation_chain_submit_buffer(window.chain(), buffer, ignore_callback, nullptr);
348+ mir_buffer_release(buffer);
349 }
350
351 TEST_F(PresentationChain, buffers_can_be_flushed)
352 {
353 SurfaceWithChainFromStart window(connection, size, pf);
354
355- MirBufferSync context;
356- mir_connection_allocate_buffer(
357- connection,
358- size.width.as_int(), size.height.as_int(), pf, usage,
359- buffer_callback, &context);
360-
361- ASSERT_TRUE(context.wait_for_buffer(10s));
362- ASSERT_THAT(context.buffer(), Ne(nullptr));
363-
364- mir_buffer_unmap(context.buffer());
365+ auto buffer = mir_connection_allocate_buffer_sync(
366+ connection, size.width.as_int(), size.height.as_int(), pf, usage);
367+ mir_buffer_unmap(buffer);
368 }
369
370 TEST_F(PresentationChain, destroying_a_chain_will_return_buffers_associated_with_chain)
371@@ -390,14 +358,12 @@
372 mir_window_apply_spec(window, spec);
373 mir_window_spec_release(spec);
374
375- MirBufferSync context;
376- mir_connection_allocate_buffer(
377- connection,
378- size.width.as_int(), size.height.as_int(), pf, usage,
379- buffer_callback, &context);
380- ASSERT_TRUE(context.wait_for_buffer(10s));
381+ auto buffer = mir_connection_allocate_buffer_sync(
382+ connection, size.width.as_int(), size.height.as_int(), pf, usage);
383+
384+ MirBufferSync context(buffer);
385 context.unavailable();
386- mir_presentation_chain_submit_buffer(chain, context.buffer());
387+ mir_presentation_chain_submit_buffer(chain, context.buffer(), buffer_callback, &context);
388
389 spec = mir_create_window_spec(connection);
390 mir_surface_spec_add_buffer_stream(spec, 0, 0, size.width.as_int(), size.height.as_int(), stream);
391@@ -414,18 +380,14 @@
392
393 TEST_F(PresentationChain, can_access_basic_buffer_properties)
394 {
395- MirBufferSync context;
396 geom::Width width { 32 };
397 geom::Height height { 33 };
398 auto format = mir_pixel_format_abgr_8888;
399 auto usage = mir_buffer_usage_software;
400
401 SurfaceWithChainFromStart window(connection, size, pf);
402- mir_connection_allocate_buffer(
403- connection, width.as_int(), height.as_int(), format, usage,
404- buffer_callback, &context);
405- ASSERT_TRUE(context.wait_for_buffer(10s));
406- auto buffer = context.buffer();
407+ auto buffer = mir_connection_allocate_buffer_sync(
408+ connection, width.as_int(), height.as_int(), format, usage);
409 EXPECT_THAT(mir_buffer_get_width(buffer), Eq(width.as_uint32_t()));
410 EXPECT_THAT(mir_buffer_get_height(buffer), Eq(height.as_uint32_t()));
411 EXPECT_THAT(mir_buffer_get_buffer_usage(buffer), Eq(usage));
412@@ -434,12 +396,8 @@
413
414 TEST_F(PresentationChain, can_check_valid_buffers)
415 {
416- MirBufferSync context;
417- mir_connection_allocate_buffer(
418- connection, size.width.as_int(), size.height.as_int(), pf, usage,
419- buffer_callback, &context);
420- ASSERT_TRUE(context.wait_for_buffer(10s));
421- auto buffer = context.buffer();
422+ auto buffer = mir_connection_allocate_buffer_sync(
423+ connection, size.width.as_int(), size.height.as_int(), pf, usage);
424 ASSERT_THAT(buffer, Ne(nullptr));
425 EXPECT_TRUE(mir_buffer_is_valid(buffer));
426 EXPECT_THAT(mir_buffer_get_error_message(buffer), StrEq(""));
427@@ -447,53 +405,9 @@
428
429 TEST_F(PresentationChain, can_check_invalid_buffers)
430 {
431- MirBufferSync context;
432- mir_connection_allocate_buffer(connection, 0, 0, pf, usage, buffer_callback, &context);
433- ASSERT_TRUE(context.wait_for_buffer(10s));
434- auto buffer = context.buffer();
435+ auto buffer = mir_connection_allocate_buffer_sync(connection, 0, 0, pf, usage);
436 ASSERT_THAT(buffer, Ne(nullptr));
437 EXPECT_FALSE(mir_buffer_is_valid(buffer));
438 EXPECT_THAT(mir_buffer_get_error_message(buffer), Not(StrEq("")));
439 mir_buffer_release(buffer);
440 }
441-
442-namespace
443-{
444-void another_buffer_callback(MirBuffer* buffer, void* context)
445-{
446- buffer_callback(buffer, context);
447-}
448-}
449-TEST_F(PresentationChain, buffers_callback_can_be_reassigned)
450-{
451- SurfaceWithChainFromStart window(connection, size, pf);
452-
453- MirBufferSync second_buffer_context;
454- MirBufferSync context;
455- MirBufferSync another_context;
456- mir_connection_allocate_buffer(
457- connection,
458- size.width.as_int(), size.height.as_int(), pf, usage,
459- buffer_callback, &context);
460- mir_connection_allocate_buffer(
461- connection,
462- size.width.as_int(), size.height.as_int(), pf, usage,
463- buffer_callback, &second_buffer_context);
464-
465- ASSERT_TRUE(context.wait_for_buffer(10s));
466- ASSERT_THAT(context.buffer(), Ne(nullptr));
467- ASSERT_TRUE(second_buffer_context.wait_for_buffer(10s));
468- ASSERT_THAT(second_buffer_context.buffer(), Ne(nullptr));
469-
470- mir_buffer_set_callback(context.buffer(), another_buffer_callback, &another_context);
471-
472- mir_presentation_chain_submit_buffer(window.chain(), context.buffer());
473- //flush the 1st buffer out
474- mir_presentation_chain_submit_buffer(window.chain(), second_buffer_context.buffer());
475-
476- ASSERT_TRUE(another_context.wait_for_buffer(10s));
477- ASSERT_THAT(another_context.buffer(), Ne(nullptr));
478-
479- mir_buffer_set_callback(context.buffer(), ignore_callback, nullptr);
480- mir_buffer_set_callback(second_buffer_context.buffer(), ignore_callback, nullptr);
481-}
482
483=== modified file 'tests/unit-tests/platforms/nested/test_buffer.cpp'
484--- tests/unit-tests/platforms/nested/test_buffer.cpp 2017-01-18 02:29:37 +0000
485+++ tests/unit-tests/platforms/nested/test_buffer.cpp 2017-01-20 15:28:19 +0000
486@@ -58,6 +58,7 @@
487 MOCK_CONST_METHOD0(fence, mir::Fd());
488 MOCK_METHOD1(set_fence, void(mir::Fd));
489 MOCK_CONST_METHOD0(egl_image_creation_hints, std::tuple<EGLenum, EGLClientBuffer, EGLint*>());
490+ MOCK_METHOD1(available, void(MirBuffer*));
491 };
492
493 struct MockHostConnection : mtd::StubHostConnection
494
495=== modified file 'tests/unit-tests/platforms/nested/test_ipc_operations.cpp'
496--- tests/unit-tests/platforms/nested/test_ipc_operations.cpp 2017-01-18 02:29:37 +0000
497+++ tests/unit-tests/platforms/nested/test_ipc_operations.cpp 2017-01-20 15:28:19 +0000
498@@ -54,6 +54,7 @@
499 mir::Fd fence() const override { return mir::Fd(); }
500 void set_fence(mir::Fd) override {}
501 void on_ownership_notification(std::function<void()> const&) override {}
502+ void available(MirBuffer*) override {}
503 std::tuple<EGLenum, EGLClientBuffer, EGLint*> egl_image_creation_hints() const override
504 {
505 return {};
506
507=== modified file 'tests/unit-tests/platforms/nested/test_nested_display_buffer.cpp'
508--- tests/unit-tests/platforms/nested/test_nested_display_buffer.cpp 2017-01-18 05:00:05 +0000
509+++ tests/unit-tests/platforms/nested/test_nested_display_buffer.cpp 2017-01-20 15:28:19 +0000
510@@ -123,6 +123,7 @@
511 MirBufferPackage* package() const override { return nullptr; }
512 mir::Fd fence() const override { return mir::Fd{mir::Fd::invalid}; }
513 void set_fence(mir::Fd) override {}
514+ void available(MirBuffer*) override {}
515 std::tuple<EGLenum, EGLClientBuffer, EGLint*> egl_image_creation_hints() const override
516 {
517 return std::tuple<EGLenum, EGLClientBuffer, EGLint*>{};

Subscribers

People subscribed via source and target branches