Mir

Merge lp:~raof/mir/buffer-age-misc-cleanups into lp:~mir-team/mir/trunk

Proposed by Chris Halse Rogers
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 536
Proposed branch: lp:~raof/mir/buffer-age-misc-cleanups
Merge into: lp:~mir-team/mir/trunk
Diff against target: 549 lines (+156/-58)
14 files modified
src/client/android/android_client_buffer_factory.cpp (+2/-2)
src/client/android/android_client_buffer_factory.h (+2/-2)
src/client/client_buffer_depository.cpp (+2/-2)
src/client/client_buffer_depository.h (+2/-2)
src/client/client_buffer_factory.h (+7/-1)
src/client/client_platform.h (+1/-1)
src/client/gbm/gbm_client_buffer_factory.cpp (+1/-1)
src/client/gbm/gbm_client_buffer_factory.h (+1/-1)
src/client/gbm/gbm_client_platform.h (+1/-1)
src/client/mir_connection.cpp (+1/-2)
src/client/mir_surface.cpp (+4/-4)
src/client/mir_surface.h (+3/-3)
tests/unit-tests/client/test_client_buffer_depository.cpp (+22/-15)
tests/unit-tests/client/test_client_mir_surface.cpp (+107/-21)
To merge this branch: bzr merge lp:~raof/mir/buffer-age-misc-cleanups
Reviewer Review Type Date Requested Status
Alexandros Frantzis (community) Approve
Alan Griffiths Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+155164@code.launchpad.net

Commit message

Miscellaneous cleanups left over from non-blocking merge reviews of
lp:~raof/mir/client-side-buffer-age.

Description of the change

Miscellaneous cleanups left over from non-blocking merge reviews of
lp:~raof/mir/client-side-buffer-age.

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
Alan Griffiths (alan-griffiths) wrote :

180 - buffer_depository(depository),
181 logger(logger)
182 {
183 + buffer_depository = std::make_shared<mcl::ClientBufferDepository>(factory, 3);
184 +

Use initializers where possible. Vis:

      buffer_depository(std::make_shared<mcl::ClientBufferDepository>(factory, 3)),

~~~~

in test_client_mir_surface.cpp

226 +#include <cstring>
227 +

Is anything from this header used?

~~~~

$ bin/unit-tests --gtest_filter=MirBufferDepositoryTest* | grep "GMOCK WARNING:" | wc -l
66

review: Needs Fixing
Revision history for this message
Robert Carr (robertcarr) wrote :

Looks good to me besides Alan's comments.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Chris Halse Rogers (raof) wrote :

> in test_client_mir_surface.cpp
>
>226 +#include <cstring>
>227 +
>
>Is anything from this header used?

Yes - memcmp, for the BufferPackageMatches matcher.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

LGTM

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

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/client/android/android_client_buffer_factory.cpp'
--- src/client/android/android_client_buffer_factory.cpp 2013-03-20 06:14:48 +0000
+++ src/client/android/android_client_buffer_factory.cpp 2013-03-26 09:39:22 +0000
@@ -24,12 +24,12 @@
24namespace mcla=mir::client::android;24namespace mcla=mir::client::android;
25namespace geom=mir::geometry;25namespace geom=mir::geometry;
2626
27mcla::AndroidClientBufferFactory::AndroidClientBufferFactory(std::shared_ptr<AndroidRegistrar> const &buffer_registrar)27mcla::AndroidClientBufferFactory::AndroidClientBufferFactory(std::shared_ptr<AndroidRegistrar> const& buffer_registrar)
28 : registrar(buffer_registrar)28 : registrar(buffer_registrar)
29{29{
30}30}
3131
32std::shared_ptr<mcl::ClientBuffer> mcla::AndroidClientBufferFactory::create_buffer(std::shared_ptr<mir_toolkit::MirBufferPackage> const & package, geom::Size size, geom::PixelFormat pf)32std::shared_ptr<mcl::ClientBuffer> mcla::AndroidClientBufferFactory::create_buffer(std::shared_ptr<mir_toolkit::MirBufferPackage> const& package, geom::Size size, geom::PixelFormat pf)
33{33{
34 return std::make_shared<mcla::AndroidClientBuffer>(registrar, package, size, pf);34 return std::make_shared<mcla::AndroidClientBuffer>(registrar, package, size, pf);
35}35}
3636
=== modified file 'src/client/android/android_client_buffer_factory.h'
--- src/client/android/android_client_buffer_factory.h 2013-03-20 06:14:48 +0000
+++ src/client/android/android_client_buffer_factory.h 2013-03-26 09:39:22 +0000
@@ -41,9 +41,9 @@
41class AndroidClientBufferFactory : public ClientBufferFactory41class AndroidClientBufferFactory : public ClientBufferFactory
42{42{
43public:43public:
44 explicit AndroidClientBufferFactory(std::shared_ptr<AndroidRegistrar> const &);44 explicit AndroidClientBufferFactory(std::shared_ptr<AndroidRegistrar> const&);
4545
46 virtual std::shared_ptr<ClientBuffer> create_buffer(std::shared_ptr<mir_toolkit::MirBufferPackage> const & package,46 virtual std::shared_ptr<ClientBuffer> create_buffer(std::shared_ptr<mir_toolkit::MirBufferPackage> const& package,
47 geometry::Size size, geometry::PixelFormat pf);47 geometry::Size size, geometry::PixelFormat pf);
48private:48private:
49 std::shared_ptr<AndroidRegistrar> registrar;49 std::shared_ptr<AndroidRegistrar> registrar;
5050
=== modified file 'src/client/client_buffer_depository.cpp'
--- src/client/client_buffer_depository.cpp 2013-03-18 05:58:51 +0000
+++ src/client/client_buffer_depository.cpp 2013-03-26 09:39:22 +0000
@@ -27,14 +27,14 @@
2727
28namespace mcl=mir::client;28namespace mcl=mir::client;
2929
30mcl::ClientBufferDepository::ClientBufferDepository(std::shared_ptr<ClientBufferFactory> const &factory, int max_buffers)30mcl::ClientBufferDepository::ClientBufferDepository(std::shared_ptr<ClientBufferFactory> const& factory, int max_buffers)
31 : factory(factory),31 : factory(factory),
32 current_buffer_iter(buffers.end()),32 current_buffer_iter(buffers.end()),
33 max_age(max_buffers - 1)33 max_age(max_buffers - 1)
34{34{
35}35}
3636
37void mcl::ClientBufferDepository::deposit_package(std::shared_ptr<mir_toolkit::MirBufferPackage> const & package, int id, geometry::Size size, geometry::PixelFormat pf)37void mcl::ClientBufferDepository::deposit_package(std::shared_ptr<mir_toolkit::MirBufferPackage> const& package, int id, geometry::Size size, geometry::PixelFormat pf)
38{38{
39 for (auto next = buffers.begin(); next != buffers.end();)39 for (auto next = buffers.begin(); next != buffers.end();)
40 {40 {
4141
=== modified file 'src/client/client_buffer_depository.h'
--- src/client/client_buffer_depository.h 2013-03-24 23:33:49 +0000
+++ src/client/client_buffer_depository.h 2013-03-26 09:39:22 +0000
@@ -47,13 +47,13 @@
47class ClientBufferDepository47class ClientBufferDepository
48{48{
49public:49public:
50 ClientBufferDepository(std::shared_ptr<ClientBufferFactory> const &factory, int max_buffers);50 ClientBufferDepository(std::shared_ptr<ClientBufferFactory> const& factory, int max_buffers);
5151
52 /// Construct a ClientBuffer from the IPC data, and use it as the current buffer.52 /// Construct a ClientBuffer from the IPC data, and use it as the current buffer.
5353
54 /// This also marks the previous current buffer (if any) as being submitted to the server.54 /// This also marks the previous current buffer (if any) as being submitted to the server.
55 /// \post current_buffer() will return a ClientBuffer constructed from this IPC data.55 /// \post current_buffer() will return a ClientBuffer constructed from this IPC data.
56 void deposit_package(std::shared_ptr<mir_toolkit::MirBufferPackage> const &, int id,56 void deposit_package(std::shared_ptr<mir_toolkit::MirBufferPackage> const&, int id,
57 geometry::Size, geometry::PixelFormat);57 geometry::Size, geometry::PixelFormat);
58 std::shared_ptr<ClientBuffer> current_buffer();58 std::shared_ptr<ClientBuffer> current_buffer();
5959
6060
=== modified file 'src/client/client_buffer_factory.h'
--- src/client/client_buffer_factory.h 2013-03-20 06:14:48 +0000
+++ src/client/client_buffer_factory.h 2013-03-26 09:39:22 +0000
@@ -35,8 +35,14 @@
35class ClientBufferFactory35class ClientBufferFactory
36{36{
37public:37public:
38 virtual std::shared_ptr<ClientBuffer> create_buffer(std::shared_ptr<mir_toolkit::MirBufferPackage> const & package,38 virtual std::shared_ptr<ClientBuffer> create_buffer(std::shared_ptr<mir_toolkit::MirBufferPackage> const& package,
39 geometry::Size size, geometry::PixelFormat pf) = 0;39 geometry::Size size, geometry::PixelFormat pf) = 0;
40
41protected:
42 ClientBufferFactory() = default;
43 ClientBufferFactory(ClientBufferFactory const &) = delete;
44 ClientBufferFactory &operator=(ClientBufferFactory const &) = delete;
45 virtual ~ClientBufferFactory() {}
40};46};
4147
42}48}
4349
=== modified file 'src/client/client_platform.h'
--- src/client/client_platform.h 2013-03-24 23:33:49 +0000
+++ src/client/client_platform.h 2013-03-26 09:39:22 +0000
@@ -36,7 +36,7 @@
36 ClientPlatform(const ClientPlatform& p) = delete;36 ClientPlatform(const ClientPlatform& p) = delete;
37 ClientPlatform& operator=(const ClientPlatform& p) = delete;37 ClientPlatform& operator=(const ClientPlatform& p) = delete;
3838
39 virtual std::shared_ptr<ClientBufferFactory> create_buffer_factory () = 0;39 virtual std::shared_ptr<ClientBufferFactory> create_buffer_factory() = 0;
40 virtual std::shared_ptr<EGLNativeWindowType> create_egl_native_window(ClientSurface *surface) = 0;40 virtual std::shared_ptr<EGLNativeWindowType> create_egl_native_window(ClientSurface *surface) = 0;
41 virtual std::shared_ptr<EGLNativeDisplayType> create_egl_native_display() = 0;41 virtual std::shared_ptr<EGLNativeDisplayType> create_egl_native_display() = 0;
42};42};
4343
=== modified file 'src/client/gbm/gbm_client_buffer_factory.cpp'
--- src/client/gbm/gbm_client_buffer_factory.cpp 2013-03-20 23:50:00 +0000
+++ src/client/gbm/gbm_client_buffer_factory.cpp 2013-03-26 09:39:22 +0000
@@ -29,7 +29,7 @@
29{29{
30}30}
3131
32std::shared_ptr<mcl::ClientBuffer> mclg::GBMClientBufferFactory::create_buffer(std::shared_ptr<mir_toolkit::MirBufferPackage> const & package, geometry::Size size, geometry::PixelFormat pf)32std::shared_ptr<mcl::ClientBuffer> mclg::GBMClientBufferFactory::create_buffer(std::shared_ptr<mir_toolkit::MirBufferPackage> const& package, geometry::Size size, geometry::PixelFormat pf)
33{33{
34 return std::make_shared<mclg::GBMClientBuffer>(drm_fd_handler, package, size, pf);34 return std::make_shared<mclg::GBMClientBuffer>(drm_fd_handler, package, size, pf);
35}35}
3636
=== modified file 'src/client/gbm/gbm_client_buffer_factory.h'
--- src/client/gbm/gbm_client_buffer_factory.h 2013-03-20 23:50:00 +0000
+++ src/client/gbm/gbm_client_buffer_factory.h 2013-03-26 09:39:22 +0000
@@ -39,7 +39,7 @@
39public:39public:
40 explicit GBMClientBufferFactory(std::shared_ptr<DRMFDHandler> const& drm_fd_handler);40 explicit GBMClientBufferFactory(std::shared_ptr<DRMFDHandler> const& drm_fd_handler);
4141
42 std::shared_ptr<ClientBuffer> create_buffer(std::shared_ptr<mir_toolkit::MirBufferPackage> const & package,42 std::shared_ptr<ClientBuffer> create_buffer(std::shared_ptr<mir_toolkit::MirBufferPackage> const& package,
43 geometry::Size size, geometry::PixelFormat pf);43 geometry::Size size, geometry::PixelFormat pf);
44private:44private:
45 std::shared_ptr<DRMFDHandler> drm_fd_handler;45 std::shared_ptr<DRMFDHandler> drm_fd_handler;
4646
=== modified file 'src/client/gbm/gbm_client_platform.h'
--- src/client/gbm/gbm_client_platform.h 2013-03-24 23:33:49 +0000
+++ src/client/gbm/gbm_client_platform.h 2013-03-26 09:39:22 +0000
@@ -39,7 +39,7 @@
39 std::shared_ptr<DRMFDHandler> const& drm_fd_handler,39 std::shared_ptr<DRMFDHandler> const& drm_fd_handler,
40 EGLNativeDisplayContainer& display_container);40 EGLNativeDisplayContainer& display_container);
4141
42 std::shared_ptr<ClientBufferFactory> create_buffer_factory ();42 std::shared_ptr<ClientBufferFactory> create_buffer_factory();
43 std::shared_ptr<EGLNativeWindowType> create_egl_native_window(ClientSurface *surface);43 std::shared_ptr<EGLNativeWindowType> create_egl_native_window(ClientSurface *surface);
44 std::shared_ptr<EGLNativeDisplayType> create_egl_native_display();44 std::shared_ptr<EGLNativeDisplayType> create_egl_native_display();
4545
4646
=== modified file 'src/client/mir_connection.cpp'
--- src/client/mir_connection.cpp 2013-03-24 23:33:49 +0000
+++ src/client/mir_connection.cpp 2013-03-26 09:39:22 +0000
@@ -66,9 +66,8 @@
66 mir_surface_lifecycle_callback callback,66 mir_surface_lifecycle_callback callback,
67 void * context)67 void * context)
68{68{
69 auto depository = std::make_shared<mir::client::ClientBufferDepository>(platform->create_buffer_factory(), 3);
70 auto null_log = std::make_shared<mir::client::NullLogger>();69 auto null_log = std::make_shared<mir::client::NullLogger>();
71 auto surface = new MirSurface(this, server, null_log, depository, params, callback, context);70 auto surface = new MirSurface(this, server, null_log, platform->create_buffer_factory(), params, callback, context);
72 return surface->get_create_wait_handle();71 return surface->get_create_wait_handle();
73}72}
7473
7574
=== modified file 'src/client/mir_surface.cpp'
--- src/client/mir_surface.cpp 2013-03-24 23:33:49 +0000
+++ src/client/mir_surface.cpp 2013-03-26 09:39:22 +0000
@@ -32,13 +32,13 @@
32mir_toolkit::MirSurface::MirSurface(32mir_toolkit::MirSurface::MirSurface(
33 MirConnection *allocating_connection,33 MirConnection *allocating_connection,
34 mp::DisplayServer::Stub & server,34 mp::DisplayServer::Stub & server,
35 const std::shared_ptr<mir::client::Logger>& logger,35 std::shared_ptr<mir::client::Logger> const& logger,
36 const std::shared_ptr<mcl::ClientBufferDepository>& depository,36 std::shared_ptr<mcl::ClientBufferFactory> const& factory,
37 MirSurfaceParameters const & params,37 MirSurfaceParameters const& params,
38 mir_surface_lifecycle_callback callback, void * context)38 mir_surface_lifecycle_callback callback, void * context)
39 : server(server),39 : server(server),
40 connection(allocating_connection),40 connection(allocating_connection),
41 buffer_depository(depository),41 buffer_depository(std::make_shared<mcl::ClientBufferDepository>(factory, 3)),
42 logger(logger)42 logger(logger)
43{43{
44 mir::protobuf::SurfaceParameters message;44 mir::protobuf::SurfaceParameters message;
4545
=== modified file 'src/client/mir_surface.h'
--- src/client/mir_surface.h 2013-03-24 23:33:49 +0000
+++ src/client/mir_surface.h 2013-03-26 09:39:22 +0000
@@ -49,9 +49,9 @@
49 MirSurface(49 MirSurface(
50 MirConnection *allocating_connection,50 MirConnection *allocating_connection,
51 mir::protobuf::DisplayServer::Stub & server,51 mir::protobuf::DisplayServer::Stub & server,
52 const std::shared_ptr<mir::client::Logger>& logger,52 std::shared_ptr<mir::client::Logger> const& logger,
53 const std::shared_ptr<mir::client::ClientBufferDepository>& depository,53 std::shared_ptr<mir::client::ClientBufferFactory> const& buffer_factory,
54 MirSurfaceParameters const & params,54 MirSurfaceParameters const& params,
55 mir_surface_lifecycle_callback callback, void * context);55 mir_surface_lifecycle_callback callback, void * context);
5656
57 ~MirSurface();57 ~MirSurface();
5858
=== modified file 'tests/unit-tests/client/test_client_buffer_depository.cpp'
--- tests/unit-tests/client/test_client_buffer_depository.cpp 2013-03-21 07:54:30 +0000
+++ tests/unit-tests/client/test_client_buffer_depository.cpp 2013-03-26 09:39:22 +0000
@@ -36,6 +36,9 @@
36 using namespace testing;36 using namespace testing;
37 ON_CALL(*this, mark_as_submitted())37 ON_CALL(*this, mark_as_submitted())
38 .WillByDefault(Invoke([this](){this->AgingBuffer::mark_as_submitted();}));38 .WillByDefault(Invoke([this](){this->AgingBuffer::mark_as_submitted();}));
39
40 // By default we expect all buffers to be destroyed.
41 EXPECT_CALL(*this, Destroy()).Times(1);
39 }42 }
4043
41 MOCK_METHOD0(Destroy, void());44 MOCK_METHOD0(Destroy, void());
@@ -67,7 +70,7 @@
67 }70 }
6871
69 MOCK_METHOD3(create_buffer,72 MOCK_METHOD3(create_buffer,
70 std::shared_ptr<mcl::ClientBuffer>(std::shared_ptr<MirBufferPackage> const &,73 std::shared_ptr<mcl::ClientBuffer>(std::shared_ptr<MirBufferPackage> const&,
71 geom::Size, geom::PixelFormat));74 geom::Size, geom::PixelFormat));
7275
73 std::shared_ptr<mcl::ClientBuffer> buffer;76 std::shared_ptr<mcl::ClientBuffer> buffer;
@@ -265,19 +268,23 @@
265 depository.deposit_package(packages[0], 1, size, pf);268 depository.deposit_package(packages[0], 1, size, pf);
266 // Raw pointer so we don't influence the buffer's life-cycle269 // Raw pointer so we don't influence the buffer's life-cycle
267 MockBuffer *first_buffer = static_cast<MockBuffer *>(depository.current_buffer().get());270 MockBuffer *first_buffer = static_cast<MockBuffer *>(depository.current_buffer().get());
271 // We expect this to not be destroyed before we deposit the fourth buffer.
272 bool buffer_destroyed = false;
273 ON_CALL(*first_buffer, Destroy()).WillByDefault(Invoke([&buffer_destroyed] () {buffer_destroyed = true;}));
274
268275
269 depository.deposit_package(packages[1], 2, size, pf);276 depository.deposit_package(packages[1], 2, size, pf);
270 depository.deposit_package(packages[2], 3, size, pf);277 depository.deposit_package(packages[2], 3, size, pf);
271278
272 // We've deposited three different buffers now; the fourth should trigger the destruction279 // We've deposited three different buffers now; the fourth should trigger the destruction
273 // of the first buffer.280 // of the first buffer.
274 EXPECT_CALL(*first_buffer, Destroy());281 ASSERT_FALSE(buffer_destroyed);
275282
276 depository.deposit_package(packages[3], 4, size, pf);283 depository.deposit_package(packages[3], 4, size, pf);
277284
278 // Explicitly verify that the buffer has been destroyed here, before the depository goes out of scope285 // Explicitly verify that the buffer has been destroyed here, before the depository goes out of scope
279 // and its destructor cleans everything up.286 // and its destructor cleans everything up.
280 Mock::VerifyAndClearExpectations(first_buffer);287 EXPECT_TRUE(buffer_destroyed);
281}288}
282289
283TEST_F(MirBufferDepositoryTest, depositing_packages_implicitly_submits_current_buffer)290TEST_F(MirBufferDepositoryTest, depositing_packages_implicitly_submits_current_buffer)
@@ -300,33 +307,33 @@
300 using namespace testing;307 using namespace testing;
301 std::shared_ptr<mcl::ClientBufferDepository> depository;308 std::shared_ptr<mcl::ClientBufferDepository> depository;
302 std::shared_ptr<MirBufferPackage> packages[10];309 std::shared_ptr<MirBufferPackage> packages[10];
303 MockBuffer *buffers[10];310 bool buffer_destroyed[10];
304311
305 for (int num_buffers = 2; num_buffers < 10; ++num_buffers)312 for (int num_buffers = 2; num_buffers < 10; ++num_buffers)
306 {313 {
307 depository = std::make_shared<mcl::ClientBufferDepository>(mock_factory, num_buffers);314 depository = std::make_shared<mcl::ClientBufferDepository>(mock_factory, num_buffers);
308 315
309 depository->deposit_package(packages[0], 1, size, pf);316 // Reset destroyed tracking; resetting the depository will have destroyed all the buffers
310 // Raw pointer so we don't influence the buffer's life-cycle317 for (bool& destroyed_flag : buffer_destroyed)
311 MockBuffer* first_buffer = static_cast<MockBuffer *>(depository->current_buffer().get());318 destroyed_flag = false;
312319
313 int i;320 int i;
314 for (i = 1; i < num_buffers ; ++i)321 for (i = 0; i < num_buffers ; ++i)
315 {322 {
323 MockBuffer *buffer;
316 depository->deposit_package(packages[i], i + 1, size, pf);324 depository->deposit_package(packages[i], i + 1, size, pf);
317 buffers[i] = static_cast<MockBuffer *>(depository->current_buffer().get());325 buffer = static_cast<MockBuffer *>(depository->current_buffer().get());
318 // None of these buffers should be destroyed326 ON_CALL(*buffer, Destroy()).WillByDefault(Invoke([&buffer_destroyed, i] () {buffer_destroyed[i] = true;}));
319 EXPECT_CALL(*buffers[i], Destroy()).Times(0);
320 }327 }
321328
322 // Next deposit should destroy first buffer329 // Next deposit should destroy first buffer
323 EXPECT_CALL(*first_buffer, Destroy()).Times(1);330 ASSERT_FALSE(buffer_destroyed[0]);
324 depository->deposit_package(packages[i], i+1, size, pf);331 depository->deposit_package(packages[i], i+1, size, pf);
325 EXPECT_TRUE(Mock::VerifyAndClearExpectations(first_buffer));332 EXPECT_TRUE(buffer_destroyed[0]);
326333
327 // Verify none of the other buffers have been destroyed334 // Verify none of the other buffers have been destroyed
328 for (i = 1; i < num_buffers; ++i)335 for (i = 1; i < num_buffers; ++i)
329 EXPECT_TRUE(Mock::VerifyAndClearExpectations(buffers[i]));336 EXPECT_FALSE(buffer_destroyed[i]);
330 }337 }
331}338}
332339
333340
=== modified file 'tests/unit-tests/client/test_client_mir_surface.cpp'
--- tests/unit-tests/client/test_client_mir_surface.cpp 2013-03-24 23:33:49 +0000
+++ tests/unit-tests/client/test_client_mir_surface.cpp 2013-03-26 09:39:22 +0000
@@ -33,6 +33,8 @@
33#include "mir_test/test_protobuf_client.h"33#include "mir_test/test_protobuf_client.h"
34#include "mir_test/gmock_fixes.h"34#include "mir_test/gmock_fixes.h"
3535
36#include <cstring>
37
36#include <gtest/gtest.h>38#include <gtest/gtest.h>
37#include <gmock/gmock.h>39#include <gmock/gmock.h>
3840
@@ -84,11 +86,11 @@
84 int num_fd = 2, num_data = 8;86 int num_fd = 2, num_data = 8;
85 for (auto i=0; i<num_fd; i++)87 for (auto i=0; i<num_fd; i++)
86 {88 {
87 server_package.fd[i] = i*3;89 server_package.fd[i] = global_buffer_id * i;
88 }90 }
89 for (auto i=0; i<num_data; i++)91 for (auto i=0; i<num_data; i++)
90 {92 {
91 server_package.data[i] = i*2;93 server_package.data[i] = (global_buffer_id + i) * 2;
92 }94 }
93 server_package.stride = 66;95 server_package.stride = 66;
94 }96 }
@@ -134,9 +136,14 @@
134136
135struct MockBuffer : public mcl::ClientBuffer137struct MockBuffer : public mcl::ClientBuffer
136{138{
137 MockBuffer()139 explicit MockBuffer(std::shared_ptr<MirBufferPackage> const& contents)
138 {140 {
141 using namespace testing;
139142
143 auto buffer_package = std::make_shared<MirBufferPackage>();
144 *buffer_package = *contents;
145 ON_CALL(*this, get_buffer_package())
146 .WillByDefault(Return(buffer_package));
140 }147 }
141148
142 MOCK_METHOD0(secure_for_cpu_write, std::shared_ptr<mcl::MemoryRegion>());149 MOCK_METHOD0(secure_for_cpu_write, std::shared_ptr<mcl::MemoryRegion>());
@@ -156,15 +163,20 @@
156 {163 {
157 using namespace testing;164 using namespace testing;
158165
159 emptybuffer=std::make_shared<NiceMock<MockBuffer>>();166 emptybuffer=std::make_shared<NiceMock<MockBuffer>>(std::make_shared<MirBufferPackage>());
167
160 ON_CALL(*this, create_buffer(_,_,_))168 ON_CALL(*this, create_buffer(_,_,_))
161 .WillByDefault(Return(emptybuffer));169 .WillByDefault(DoAll(SaveArg<0>(&current_package),
170 InvokeWithoutArgs([this] () {this->current_buffer = std::make_shared<NiceMock<MockBuffer>>(current_package);}),
171 ReturnPointee(&current_buffer)));
162 }172 }
163173
164 MOCK_METHOD3(create_buffer,174 MOCK_METHOD3(create_buffer,
165 std::shared_ptr<mcl::ClientBuffer>(std::shared_ptr<MirBufferPackage> const &,175 std::shared_ptr<mcl::ClientBuffer>(std::shared_ptr<MirBufferPackage> const&,
166 geom::Size, geom::PixelFormat));176 geom::Size, geom::PixelFormat));
167177
178 std::shared_ptr<MirBufferPackage> current_package;
179 std::shared_ptr<mcl::ClientBuffer> current_buffer;
168 std::shared_ptr<mcl::ClientBuffer> emptybuffer;180 std::shared_ptr<mcl::ClientBuffer> emptybuffer;
169};181};
170182
@@ -219,7 +231,6 @@
219 test_server->comm->start();231 test_server->comm->start();
220232
221 mock_buffer_factory = std::make_shared<mt::MockClientBufferFactory>();233 mock_buffer_factory = std::make_shared<mt::MockClientBufferFactory>();
222 depository = std::make_shared<mcl::ClientBufferDepository>(mock_buffer_factory, 3);
223234
224 params = MirSurfaceParameters{"test", 33, 45, mir_pixel_format_abgr_8888,235 params = MirSurfaceParameters{"test", 33, 45, mir_pixel_format_abgr_8888,
225 mir_buffer_usage_hardware};236 mir_buffer_usage_hardware};
@@ -250,7 +261,6 @@
250261
251 MirSurfaceParameters params;262 MirSurfaceParameters params;
252 std::shared_ptr<mt::MockClientBufferFactory> mock_buffer_factory;263 std::shared_ptr<mt::MockClientBufferFactory> mock_buffer_factory;
253 std::shared_ptr<mcl::ClientBufferDepository> depository;
254264
255 mir::protobuf::Connection response;265 mir::protobuf::Connection response;
256 mir::protobuf::ConnectParameters connect_parameters;266 mir::protobuf::ConnectParameters connect_parameters;
@@ -272,7 +282,13 @@
272 EXPECT_CALL(*mock_buffer_factory, create_buffer(_,_,_))282 EXPECT_CALL(*mock_buffer_factory, create_buffer(_,_,_))
273 .Times(1);283 .Times(1);
274284
275 auto surface = std::make_shared<MirSurface> (connection.get(), *client_comm_channel, logger, depository, params, &empty_callback, (void*) NULL);285 auto surface = std::make_shared<MirSurface> (connection.get(),
286 *client_comm_channel,
287 logger,
288 mock_buffer_factory,
289 params,
290 &empty_callback,
291 nullptr);
276292
277 auto wait_handle = surface->get_create_wait_handle();293 auto wait_handle = surface->get_create_wait_handle();
278 wait_handle->wait_for_result();294 wait_handle->wait_for_result();
@@ -290,7 +306,13 @@
290 EXPECT_CALL(*mock_buffer_factory, create_buffer(_,_,_))306 EXPECT_CALL(*mock_buffer_factory, create_buffer(_,_,_))
291 .Times(1);307 .Times(1);
292308
293 auto surface = std::make_shared<MirSurface> (connection.get(), *client_comm_channel, logger, depository, params, &empty_callback, (void*) NULL);309 auto surface = std::make_shared<MirSurface> (connection.get(),
310 *client_comm_channel,
311 logger,
312 mock_buffer_factory,
313 params,
314 &empty_callback,
315 nullptr);
294316
295 auto wait_handle = surface->get_create_wait_handle();317 auto wait_handle = surface->get_create_wait_handle();
296 wait_handle->wait_for_result();318 wait_handle->wait_for_result();
@@ -301,6 +323,22 @@
301 buffer_wait_handle->wait_for_result();323 buffer_wait_handle->wait_for_result();
302}324}
303325
326MATCHER_P(BufferPackageMatches, package, "")
327{
328 // Can't simply use memcmp() on the whole struct because age is not sent over the wire
329 if (package.data_items != arg.data_items)
330 return false;
331 if (package.fd_items != arg.fd_items)
332 return false;
333 if (memcmp(package.data, arg.data, sizeof(package.data[0]) * package.data_items))
334 return false;
335 if (memcmp(package.fd, arg.fd, sizeof(package.fd[0]) * package.fd_items))
336 return false;
337 if (package.stride != arg.stride)
338 return false;
339 return true;
340}
341
304TEST_F(MirClientSurfaceTest, client_buffer_uses_ipc_message_from_server_on_create)342TEST_F(MirClientSurfaceTest, client_buffer_uses_ipc_message_from_server_on_create)
305{343{
306 using namespace testing;344 using namespace testing;
@@ -311,16 +349,18 @@
311 .WillOnce(DoAll(SaveArg<0>(&submitted_package),349 .WillOnce(DoAll(SaveArg<0>(&submitted_package),
312 Return(mock_buffer_factory->emptybuffer)));350 Return(mock_buffer_factory->emptybuffer)));
313351
314 auto surface = std::make_shared<MirSurface> (connection.get(), *client_comm_channel, logger, depository, params, &empty_callback, (void*) NULL);352 auto surface = std::make_shared<MirSurface> (connection.get(),
353 *client_comm_channel,
354 logger,
355 mock_buffer_factory,
356 params,
357 &empty_callback,
358 nullptr);
315 auto wait_handle = surface->get_create_wait_handle();359 auto wait_handle = surface->get_create_wait_handle();
316 wait_handle->wait_for_result();360 wait_handle->wait_for_result();
317361
318 /* check for same contents */362 /* check for same contents */
319 ASSERT_EQ(submitted_package->data_items, mock_server_tool->server_package.data_items);363 EXPECT_THAT(*submitted_package, BufferPackageMatches(mock_server_tool->server_package));
320 ASSERT_EQ(submitted_package->fd_items, mock_server_tool->server_package.fd_items);
321 ASSERT_EQ(submitted_package->stride, mock_server_tool->server_package.stride);
322 for (auto i=0; i< submitted_package->data_items; i++)
323 EXPECT_EQ(submitted_package->data[i], mock_server_tool->server_package.data[i]);
324}364}
325365
326TEST_F(MirClientSurfaceTest, message_width_used_in_buffer_creation )366TEST_F(MirClientSurfaceTest, message_width_used_in_buffer_creation )
@@ -335,7 +375,13 @@
335 .WillOnce(DoAll(SaveArg<1>(&sz),375 .WillOnce(DoAll(SaveArg<1>(&sz),
336 Return(mock_buffer_factory->emptybuffer)));376 Return(mock_buffer_factory->emptybuffer)));
337377
338 auto surface = std::make_shared<MirSurface> (connection.get(), *client_comm_channel, logger, depository, params, &empty_callback, (void*) NULL);378 auto surface = std::make_shared<MirSurface> (connection.get(),
379 *client_comm_channel,
380 logger,
381 mock_buffer_factory,
382 params,
383 &empty_callback,
384 nullptr);
339 auto wait_handle = surface->get_create_wait_handle();385 auto wait_handle = surface->get_create_wait_handle();
340 wait_handle->wait_for_result();386 wait_handle->wait_for_result();
341387
@@ -354,7 +400,13 @@
354 .WillOnce(DoAll(SaveArg<1>(&sz),400 .WillOnce(DoAll(SaveArg<1>(&sz),
355 Return(mock_buffer_factory->emptybuffer)));401 Return(mock_buffer_factory->emptybuffer)));
356402
357 auto surface = std::make_shared<MirSurface> (connection.get(), *client_comm_channel, logger, depository, params, &empty_callback, (void*) NULL);403 auto surface = std::make_shared<MirSurface> (connection.get(),
404 *client_comm_channel,
405 logger,
406 mock_buffer_factory,
407 params,
408 &empty_callback,
409 nullptr);
358 auto wait_handle = surface->get_create_wait_handle();410 auto wait_handle = surface->get_create_wait_handle();
359 wait_handle->wait_for_result();411 wait_handle->wait_for_result();
360412
@@ -373,13 +425,47 @@
373 .WillOnce(DoAll(SaveArg<2>(&pf),425 .WillOnce(DoAll(SaveArg<2>(&pf),
374 Return(mock_buffer_factory->emptybuffer)));426 Return(mock_buffer_factory->emptybuffer)));
375427
376 auto surface = std::make_shared<MirSurface> (connection.get(), *client_comm_channel, logger, depository, params, &empty_callback, (void*) NULL);428 auto surface = std::make_shared<MirSurface> (connection.get(),
429 *client_comm_channel,
430 logger,
431 mock_buffer_factory,
432 params,
433 &empty_callback,
434 nullptr);
435
377 auto wait_handle = surface->get_create_wait_handle();436 auto wait_handle = surface->get_create_wait_handle();
378 wait_handle->wait_for_result();437 wait_handle->wait_for_result();
379438
380 EXPECT_EQ(pf, geom::PixelFormat::abgr_8888);439 EXPECT_EQ(pf, geom::PixelFormat::abgr_8888);
381}440}
382441
442TEST_F(MirClientSurfaceTest, get_buffer_returns_last_received_buffer_package)
443{
444 using namespace testing;
445
446 EXPECT_CALL(*mock_buffer_factory, create_buffer(_,_,_))
447 .Times(1);
448
449 auto surface = std::make_shared<MirSurface> (connection.get(),
450 *client_comm_channel,
451 logger,
452 mock_buffer_factory,
453 params,
454 &empty_callback,
455 nullptr);
456 auto wait_handle = surface->get_create_wait_handle();
457 wait_handle->wait_for_result();
458
459 EXPECT_THAT(*surface->get_current_buffer_package(), BufferPackageMatches(mock_server_tool->server_package));
460
461 EXPECT_CALL(*mock_buffer_factory, create_buffer(_,_,_))
462 .Times(1);
463 auto buffer_wait_handle = surface->next_buffer(&empty_surface_callback, nullptr);
464 buffer_wait_handle->wait_for_result();
465
466 EXPECT_THAT(*surface->get_current_buffer_package(), BufferPackageMatches(mock_server_tool->server_package));
467}
468
383TEST_F(MirClientSurfaceTest, default_surface_type)469TEST_F(MirClientSurfaceTest, default_surface_type)
384{470{
385 using namespace testing;471 using namespace testing;
@@ -391,10 +477,10 @@
391 auto surface = std::make_shared<MirSurface> (connection.get(),477 auto surface = std::make_shared<MirSurface> (connection.get(),
392 *client_comm_channel,478 *client_comm_channel,
393 logger,479 logger,
394 depository,480 mock_buffer_factory,
395 params,481 params,
396 &empty_callback,482 &empty_callback,
397 (void*) NULL);483 nullptr);
398 surface->get_create_wait_handle()->wait_for_result();484 surface->get_create_wait_handle()->wait_for_result();
399485
400 EXPECT_EQ(mir_surface_type_normal,486 EXPECT_EQ(mir_surface_type_normal,

Subscribers

People subscribed via source and target branches