Mir

Merge lp:~kdub/mir/resettable-buffer-cb into lp:mir

Proposed by Kevin DuBois
Status: Merged
Approved by: Chris Halse Rogers
Approved revision: no longer in the source branch.
Merged at revision: 3574
Proposed branch: lp:~kdub/mir/resettable-buffer-cb
Merge into: lp:mir
Diff against target: 272 lines (+106/-7)
12 files modified
src/client/atomic_callback.h (+5/-0)
src/client/buffer.cpp (+9/-4)
src/client/buffer.h (+6/-3)
src/client/error_buffer.cpp (+1/-0)
src/client/error_buffer.h (+1/-0)
src/client/mir_buffer.h (+1/-0)
src/client/mir_buffer_api.cpp (+13/-0)
src/client/symbols.map (+1/-0)
src/include/client/mir_toolkit/mir_buffer.h (+12/-0)
tests/acceptance-tests/throwback/test_presentation_chain.cpp (+38/-0)
tests/include/mir/test/doubles/mock_mir_buffer.h (+1/-0)
tests/unit-tests/client/test_mir_buffer.cpp (+18/-0)
To merge this branch: bzr merge lp:~kdub/mir/resettable-buffer-cb
Reviewer Review Type Date Requested Status
Chris Halse Rogers Approve
Mir CI Bot continuous-integration Approve
Alan Griffiths Approve
Cemil Azizoglu (community) Approve
Review via email: mp+295068@code.launchpad.net

Commit message

client: add a function to the MirBuffer set of functions that allows a user to set the callback and context of a MirBuffer. Callback and context were provided in the construction; allow changing these via the new client api function.

Description of the change

client: add a function to the MirBuffer set of functions that allows a user to set the callback and context of a MirBuffer. Callback and context were provided in the construction; allow changing these via the new client api function.

To post a comment you must log in.
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

LGTM.

Nit : Line #110 (extraneous space) and line #116 (split at the comma) could use better formatting.
        +/** Reassign the callback that the MirBuffer will call when the buffer is
107 + * available for use again
108 + * \param [in] buffer The buffer
109 + * \param [in] available_callback The callback called when the buffer
110 + * is available
111 + * \param [in] available_context The context for the available_callback
112 + **/
113 +
114 +void mir_buffer_set_callback(
115 + MirBuffer* buffer,
116 + mir_buffer_callback available_callback, void* available_context);

review: Approve
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:3509
https://mir-jenkins.ubuntu.com/job/mir-ci/990/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/1072/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/1119
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1111
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/1111
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1083/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1083
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1083/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/1083
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1083/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/1083
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1083/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1083
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1083/artifact/output/*zip*/output.zip

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

I'm not entirely convinced that a recursive lock allows useful behaviour, but OK.

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

This *seems* like the sort of thing mcl::AtomicCallback is for? It doesn't currently handle changing the callback from an active callback, but that'd be a simple matter of copy-then-unlock.

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

 Ah yes, that class would make the code better, will use it.

Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3512
https://mir-jenkins.ubuntu.com/job/mir-ci/1092/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/1209
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/1259
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1250
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/1250
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1219
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1219/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1219
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1219/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/1219
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1219/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/1219
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1219/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1219
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1219/artifact/output/*zip*/output.zip

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

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

FAILED: Continuous integration, rev:3513
https://mir-jenkins.ubuntu.com/job/mir-ci/1194/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/1354/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/1405
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1396
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/1396
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1368
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1368/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1368
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1368/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1368/console
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1368/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/1368
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1368/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1368
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1368/artifact/output/*zip*/output.zip

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

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

krillin image 515 fails to come up, retriggering.

Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3513
https://mir-jenkins.ubuntu.com/job/mir-ci/1198/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/1365
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/1416
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1407
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/1407
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1379
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1379/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1379
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1379/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/1379
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1379/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/1379
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1379/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1379
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1379/artifact/output/*zip*/output.zip

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

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

+ cb.set_callback([&, callback, context]{ (*callback)(reinterpret_cast<::MirBuffer*>(this), context); });

The ‘&’ is rather strange there - you only really want to capture /this/ by value.

But that's a stylistic nit.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/client/atomic_callback.h'
--- src/client/atomic_callback.h 2016-01-29 08:18:22 +0000
+++ src/client/atomic_callback.h 2016-06-24 11:42:58 +0000
@@ -35,6 +35,11 @@
35 {35 {
36 }36 }
3737
38 AtomicCallback(std::function<void(Args...)> const& fn)
39 : callback(fn)
40 {
41 }
42
38 ~AtomicCallback() = default;43 ~AtomicCallback() = default;
3944
40 void set_callback(std::function<void(Args...)> const& fn)45 void set_callback(std::function<void(Args...)> const& fn)
4146
=== modified file 'src/client/buffer.cpp'
--- src/client/buffer.cpp 2016-06-06 11:51:31 +0000
+++ src/client/buffer.cpp 2016-06-24 11:42:58 +0000
@@ -28,10 +28,9 @@
28 std::shared_ptr<ClientBuffer> const& buffer,28 std::shared_ptr<ClientBuffer> const& buffer,
29 MirConnection* connection,29 MirConnection* connection,
30 MirBufferUsage usage) :30 MirBufferUsage usage) :
31 cb(cb),
32 cb_context(context),
33 buffer_id(buffer_id),31 buffer_id(buffer_id),
34 buffer(buffer),32 buffer(buffer),
33 cb([this, cb, context]{ (*cb)(reinterpret_cast<::MirBuffer*>(this), context); }),
35 owned(false),34 owned(false),
36 connection(connection),35 connection(connection),
37 usage(usage)36 usage(usage)
@@ -60,8 +59,8 @@
60 if (!owned)59 if (!owned)
61 owned = true;60 owned = true;
62 }61 }
63 cb(reinterpret_cast<::MirBuffer*>(static_cast<mcl::MirBuffer*>(this)), cb_context);
6462
63 cb();
65}64}
6665
67void mcl::Buffer::received(MirBufferPackage const& update_package)66void mcl::Buffer::received(MirBufferPackage const& update_package)
@@ -74,7 +73,8 @@
74 buffer->update_from(update_package);73 buffer->update_from(update_package);
75 }74 }
76 }75 }
77 cb(reinterpret_cast<::MirBuffer*>(static_cast<mcl::MirBuffer*>(this)), cb_context);76
77 cb();
78}78}
79 79
80MirGraphicsRegion mcl::Buffer::map_region()80MirGraphicsRegion mcl::Buffer::map_region()
@@ -138,3 +138,8 @@
138{138{
139 buffer->increment_age();139 buffer->increment_age();
140}140}
141
142void mcl::Buffer::set_callback(mir_buffer_callback callback, void* context)
143{
144 cb.set_callback([&, callback, context]{ (*callback)(reinterpret_cast<::MirBuffer*>(this), context); });
145}
141146
=== modified file 'src/client/buffer.h'
--- src/client/buffer.h 2016-06-06 11:51:31 +0000
+++ src/client/buffer.h 2016-06-24 11:42:58 +0000
@@ -21,6 +21,7 @@
2121
22#include "mir_toolkit/mir_buffer.h"22#include "mir_toolkit/mir_buffer.h"
23#include "mir/geometry/size.h"23#include "mir/geometry/size.h"
24#include "atomic_callback.h"
24#include "mir_buffer.h"25#include "mir_buffer.h"
25#include <memory>26#include <memory>
26#include <chrono>27#include <chrono>
@@ -41,6 +42,7 @@
41 std::shared_ptr<ClientBuffer> const& buffer,42 std::shared_ptr<ClientBuffer> const& buffer,
42 MirConnection* connection,43 MirConnection* connection,
43 MirBufferUsage usage);44 MirBufferUsage usage);
45
44 int rpc_id() const override;46 int rpc_id() const override;
4547
46 void submitted() override;48 void submitted() override;
@@ -62,11 +64,12 @@
62 MirConnection* allocating_connection() const override;64 MirConnection* allocating_connection() const override;
6365
64 void increment_age() override;66 void increment_age() override;
67 void set_callback(mir_buffer_callback callback, void* context) override;
65private:68private:
66 mir_buffer_callback cb;
67 void* cb_context;
68 int const buffer_id;69 int const buffer_id;
69 std::shared_ptr<ClientBuffer> buffer;70 std::shared_ptr<ClientBuffer> const buffer;
71
72 AtomicCallback<> cb;
7073
71 std::mutex mutex;74 std::mutex mutex;
72 bool owned;75 bool owned;
7376
=== modified file 'src/client/error_buffer.cpp'
--- src/client/error_buffer.cpp 2016-05-19 13:22:43 +0000
+++ src/client/error_buffer.cpp 2016-06-24 11:42:58 +0000
@@ -68,3 +68,4 @@
68geom::Size mcl::ErrorBuffer::size() const THROW_EXCEPTION68geom::Size mcl::ErrorBuffer::size() const THROW_EXCEPTION
69MirConnection* mcl::ErrorBuffer::allocating_connection() const THROW_EXCEPTION69MirConnection* mcl::ErrorBuffer::allocating_connection() const THROW_EXCEPTION
70void mcl::ErrorBuffer::increment_age() THROW_EXCEPTION70void mcl::ErrorBuffer::increment_age() THROW_EXCEPTION
71void mcl::ErrorBuffer::set_callback(mir_buffer_callback, void*) THROW_EXCEPTION
7172
=== modified file 'src/client/error_buffer.h'
--- src/client/error_buffer.h 2016-05-19 13:22:43 +0000
+++ src/client/error_buffer.h 2016-06-24 11:42:58 +0000
@@ -47,6 +47,7 @@
47 geometry::Size size() const override;47 geometry::Size size() const override;
48 MirConnection* allocating_connection() const override;48 MirConnection* allocating_connection() const override;
49 void increment_age() override;49 void increment_age() override;
50 void set_callback(mir_buffer_callback callback, void* context) override;
5051
51 bool valid() const;52 bool valid() const;
52 char const* error_message() const;53 char const* error_message() const;
5354
=== modified file 'src/client/mir_buffer.h'
--- src/client/mir_buffer.h 2016-05-16 14:45:02 +0000
+++ src/client/mir_buffer.h 2016-06-24 11:42:58 +0000
@@ -52,6 +52,7 @@
52 virtual geometry::Size size() const = 0;52 virtual geometry::Size size() const = 0;
53 virtual MirConnection* allocating_connection() const = 0;53 virtual MirConnection* allocating_connection() const = 0;
54 virtual void increment_age() = 0;54 virtual void increment_age() = 0;
55 virtual void set_callback(mir_buffer_callback callback, void* context) = 0;
55protected:56protected:
56 MirBuffer() = default;57 MirBuffer() = default;
57 MirBuffer(MirBuffer const&) = delete;58 MirBuffer(MirBuffer const&) = delete;
5859
=== modified file 'src/client/mir_buffer_api.cpp'
--- src/client/mir_buffer_api.cpp 2016-06-06 11:51:31 +0000
+++ src/client/mir_buffer_api.cpp 2016-06-24 11:42:58 +0000
@@ -174,3 +174,16 @@
174 MIR_LOG_UNCAUGHT_EXCEPTION(ex);174 MIR_LOG_UNCAUGHT_EXCEPTION(ex);
175 return mir_buffer_usage_hardware;175 return mir_buffer_usage_hardware;
176}176}
177
178void mir_buffer_set_callback(
179 MirBuffer* b, mir_buffer_callback available_callback, void* available_context)
180try
181{
182 mir::require(b);
183 auto buffer = reinterpret_cast<mcl::Buffer*>(b);
184 buffer->set_callback(available_callback, available_context);
185}
186catch (std::exception const& ex)
187{
188 MIR_LOG_UNCAUGHT_EXCEPTION(ex);
189}
177190
=== modified file 'src/client/symbols.map'
--- src/client/symbols.map 2016-06-09 17:42:21 +0000
+++ src/client/symbols.map 2016-06-24 11:42:58 +0000
@@ -366,6 +366,7 @@
366 mir_buffer_wait_fence;366 mir_buffer_wait_fence;
367 mir_buffer_get_native_buffer;367 mir_buffer_get_native_buffer;
368 mir_buffer_get_graphics_region;368 mir_buffer_get_graphics_region;
369 mir_buffer_set_callback;
369 mir_buffer_release;370 mir_buffer_release;
370 mir_connection_create_presentation_chain_sync;371 mir_connection_create_presentation_chain_sync;
371 mir_presentation_chain_is_valid;372 mir_presentation_chain_is_valid;
372373
=== modified file 'src/include/client/mir_toolkit/mir_buffer.h'
--- src/include/client/mir_toolkit/mir_buffer.h 2016-06-06 11:51:31 +0000
+++ src/include/client/mir_toolkit/mir_buffer.h 2016-06-24 11:42:58 +0000
@@ -50,6 +50,18 @@
50 MirBufferUsage buffer_usage,50 MirBufferUsage buffer_usage,
51 mir_buffer_callback available_callback, void* available_context);51 mir_buffer_callback available_callback, void* available_context);
5252
53/** Reassign the callback that the MirBuffer will call when the buffer is
54 * available for use again
55 * \param [in] buffer The buffer
56 * \param [in] available_callback The callback called when the buffer
57 * is available
58 * \param [in] available_context The context for the available_callback
59 **/
60
61void mir_buffer_set_callback(
62 MirBuffer* buffer,
63 mir_buffer_callback available_callback, void* available_context);
64
53/** @name Fenced Buffer content access functions.65/** @name Fenced Buffer content access functions.
54 *66 *
55 * These functions will wait until it is safe to access the buffer for the given purpose.67 * These functions will wait until it is safe to access the buffer for the given purpose.
5668
=== modified file 'tests/acceptance-tests/throwback/test_presentation_chain.cpp'
--- tests/acceptance-tests/throwback/test_presentation_chain.cpp 2016-06-06 11:51:31 +0000
+++ tests/acceptance-tests/throwback/test_presentation_chain.cpp 2016-06-24 11:42:58 +0000
@@ -355,3 +355,41 @@
355 EXPECT_THAT(mir_buffer_get_buffer_usage(buffer), Eq(usage));355 EXPECT_THAT(mir_buffer_get_buffer_usage(buffer), Eq(usage));
356 EXPECT_THAT(mir_buffer_get_pixel_format(buffer), Eq(format));356 EXPECT_THAT(mir_buffer_get_pixel_format(buffer), Eq(format));
357}357}
358
359namespace
360{
361void another_buffer_callback(MirBuffer* buffer, void* context)
362{
363 buffer_callback(buffer, context);
364}
365}
366TEST_F(PresentationChain, buffers_callback_can_be_reassigned)
367{
368 SurfaceWithChainFromStart surface(connection, size, pf);
369
370 MirBufferSync second_buffer_context;
371 MirBufferSync context;
372 MirBufferSync another_context;
373 mir_connection_allocate_buffer(
374 connection,
375 size.width.as_int(), size.height.as_int(), pf, usage,
376 buffer_callback, &context);
377 mir_connection_allocate_buffer(
378 connection,
379 size.width.as_int(), size.height.as_int(), pf, usage,
380 buffer_callback, &second_buffer_context);
381
382 ASSERT_TRUE(context.wait_for_buffer(10s));
383 ASSERT_THAT(context.buffer(), Ne(nullptr));
384 ASSERT_TRUE(second_buffer_context.wait_for_buffer(10s));
385 ASSERT_THAT(second_buffer_context.buffer(), Ne(nullptr));
386
387 mir_buffer_set_callback(context.buffer(), another_buffer_callback, &another_context);
388
389 mir_presentation_chain_submit_buffer(surface.chain(), context.buffer());
390 //flush the 1st buffer out
391 mir_presentation_chain_submit_buffer(surface.chain(), second_buffer_context.buffer());
392
393 ASSERT_TRUE(another_context.wait_for_buffer(10s));
394 ASSERT_THAT(another_context.buffer(), Ne(nullptr));
395}
358396
=== modified file 'tests/include/mir/test/doubles/mock_mir_buffer.h'
--- tests/include/mir/test/doubles/mock_mir_buffer.h 2016-05-13 18:55:24 +0000
+++ tests/include/mir/test/doubles/mock_mir_buffer.h 2016-06-24 11:42:58 +0000
@@ -55,6 +55,7 @@
55 MOCK_CONST_METHOD0(size, geometry::Size());55 MOCK_CONST_METHOD0(size, geometry::Size());
56 MOCK_CONST_METHOD0(allocating_connection, MirConnection*());56 MOCK_CONST_METHOD0(allocating_connection, MirConnection*());
57 MOCK_METHOD0(increment_age, void());57 MOCK_METHOD0(increment_age, void());
58 MOCK_METHOD2(set_callback, void(mir_buffer_callback callback, void* context));
58};59};
5960
60using StubMirBuffer = testing::NiceMock<MockMirBuffer>; 61using StubMirBuffer = testing::NiceMock<MockMirBuffer>;
6162
=== modified file 'tests/unit-tests/client/test_mir_buffer.cpp'
--- tests/unit-tests/client/test_mir_buffer.cpp 2016-06-06 11:51:31 +0000
+++ tests/unit-tests/client/test_mir_buffer.cpp 2016-06-24 11:42:58 +0000
@@ -177,6 +177,24 @@
177 EXPECT_THAT(call_count, Eq(1));177 EXPECT_THAT(call_count, Eq(1));
178}178}
179179
180TEST_F(MirBufferTest, callback_called_after_change_when_available_from_creation)
181{
182 int call_count = 0;
183 mcl::Buffer buffer(cb, nullptr, buffer_id, mock_client_buffer, nullptr, usage);
184 buffer.set_callback(cb, &call_count);
185 buffer.received();
186 EXPECT_THAT(call_count, Eq(1));
187}
188
189TEST_F(MirBufferTest, callback_called_after_change_when_available_from_server_return)
190{
191 int call_count = 0;
192 mcl::Buffer buffer(cb, nullptr, buffer_id, mock_client_buffer, nullptr, usage);
193 buffer.set_callback(cb, &call_count);
194 buffer.received(update_message);
195 EXPECT_THAT(call_count, Eq(1));
196}
197
180TEST_F(MirBufferTest, updates_package_when_server_returns)198TEST_F(MirBufferTest, updates_package_when_server_returns)
181{199{
182 EXPECT_CALL(*mock_client_buffer, update_from(Ref(update_message)));200 EXPECT_CALL(*mock_client_buffer, update_from(Ref(update_message)));

Subscribers

People subscribed via source and target branches