Mir

Merge lp:~kdub/mir/mesa-reconstruct-buffer into lp:mir

Proposed by Kevin DuBois on 2015-04-09
Status: Merged
Approved by: Alexandros Frantzis on 2015-04-15
Approved revision: 2478
Merged at revision: 2487
Proposed branch: lp:~kdub/mir/mesa-reconstruct-buffer
Merge into: lp:mir
Diff against target: 164 lines (+105/-0)
5 files modified
src/platforms/mesa/server/buffer_allocator.cpp (+31/-0)
src/platforms/mesa/server/buffer_allocator.h (+2/-0)
tests/include/mir_test_doubles/mock_gbm.h (+1/-0)
tests/mir_test_doubles/mock_gbm.cpp (+5/-0)
tests/unit-tests/graphics/mesa/test_buffer_allocator.cpp (+66/-0)
To merge this branch: bzr merge lp:~kdub/mir/mesa-reconstruct-buffer
Reviewer Review Type Date Requested Status
Alexandros Frantzis (community) Approve on 2015-04-15
Alan Griffiths Approve on 2015-04-15
PS Jenkins bot continuous-integration Approve on 2015-04-14
Robert Carr (community) Approve on 2015-04-13
Chris Halse Rogers 2015-04-09 Approve on 2015-04-13
Review via email: mp+255722@code.launchpad.net

Commit Message

mesa: provide a way for a nested server to reconstruct a mgm::Buffer from a MirNativeBuffer.

Description of the Change

mesa: provide a way for a nested server to reconstruct a mgm::Buffer from a MirNativeBuffer.

The nested server gets access to the native buffer type from mir_buffer_stream_current_buffer(), and the type that is returned is platform-dependendent, so allow each platform to reconstruct the mg::Buffer.

To post a comment you must log in.
Chris Halse Rogers (raof) wrote :

27 + BOOST_THROW_EXCEPTION(std::runtime_error("Failed to import MirBufferPackage"));

This would more usefully be a std::system_error; gbm_bo_import will set errno in case of failure.

Otherwise looks good to me.

review: Needs Fixing
lp:~kdub/mir/mesa-reconstruct-buffer updated on 2015-04-10
2472. By Kevin DuBois on 2015-04-10

use system error instead of runtime_error

lp:~kdub/mir/mesa-reconstruct-buffer updated on 2015-04-10
2473. By Kevin DuBois on 2015-04-10

correct clang error

Chris Halse Rogers (raof) wrote :

LGTM

review: Approve
Alan Griffiths (alan-griffiths) wrote :

*nitpicking*

31+ std::shared_ptr<gbm_bo> bo(
32+ gbm_bo_import(device, GBM_BO_IMPORT_FD, &data, package->flags),
33+ [](gbm_bo* bo){ gbm_bo_destroy(bo); });
34+ if (!bo)
35+ BOOST_THROW_EXCEPTION(
36+ std::system_error(errno, std::system_category(), "Failed to import MirBufferPackage"));

Easier to read with a blank line before the if, and braces around the multi-line conditional.

review: Needs Fixing
lp:~kdub/mir/mesa-reconstruct-buffer updated on 2015-04-13
2474. By Kevin DuBois on 2015-04-13

braces and spaces

2475. By Kevin DuBois on 2015-04-13

merge mir

Robert Carr (robertcarr) wrote :

LGTM.

Nits:
l22
+ BOOST_THROW_EXCEPTION(std::runtime_error("Failed to create mgm::Buffer from MirBufferPackage"));

I think because the caller can verify this, we can say its a precondition violation and this is thus a logic_error.

review: Approve
Kevin DuBois (kdub) wrote :

@jenkins, I thought this was fixed?
 11: [ RUN ] SimpleDispatchThreadTest.keeps_dispatching_after_signal_interruption

lp:~kdub/mir/mesa-reconstruct-buffer updated on 2015-04-13
2476. By Kevin DuBois on 2015-04-13

use logic_error instead of runtime_error

Kevin DuBois (kdub) wrote :

@Robert, fair enough, changed to logic_error

Alexandros Frantzis (afrantzis) wrote :
Download full text (3.2 KiB)

> @jenkins, I thought this was fixed?
> 11: [ RUN ] SimpleDispatchThreadTest.keeps_dispatching_after_signal_interruption

Because this test forks a new process, it catches valgrind errors detected in previous tests. In this case the real issue is:

11: [ RUN ] MesaBufferAllocatorTest.reconstructs_from_native_type
11: ==32764== Conditional jump or move depends on uninitialised value(s)
11: ==32764== at 0x15CFAC8: Matches (gmock-spec-builders.h:1088)
11: ==32764== by 0x15CFAC8: ShouldHandleArguments (gmock-spec-builders.h:1101)
11: ==32764== by 0x15CFAC8: FindMatchingExpectationLocked (gmock-spec-builders.h:1667)
11: ==32764== by 0x15CFAC8: testing::internal::FunctionMockerBase<gbm_bo* (gbm_device*, unsigned int, void*, unsigned int)>::UntypedFindMatchingExpectation(void const*, void const**, bool*, std::ostream*, std::ostream*) (gmock-spec-builders.h:1631)
11: ==32764== by 0x161E937: testing::internal::UntypedFunctionMockerBase::UntypedInvokeWith(void const*) (in /tmp/buildd/mir-0.13.0bzr2476pkg0vivid1509/obj-x86_64-linux-gnu/bin/.mir_unit_tests-uninstalled)
11: ==32764== by 0x15B8142: InvokeWith (gmock-spec-builders.h:1529)
11: ==32764== by 0x15B8142: Invoke (gmock-generated-function-mockers.h:162)
11: ==32764== by 0x15B8142: gbm_bo_import (mock_gbm.h:79)
11: ==32764== by 0x15B8142: gbm_bo_import (mock_gbm.cpp:174)
11: ==32764== by 0x13BA657: mir::graphics::mesa::BufferAllocator::reconstruct_from(MirBufferPackage*, MirPixelFormat) (buffer_allocator.cpp:249)
11: ==32764== by 0x10A7CCF: MesaBufferAllocatorTest_reconstructs_from_native_type_Test::TestBody() (test_buffer_allocator.cpp:321)
11: ==32764== by 0x160FA49: void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /tmp/buildd/mir-0.13.0bzr2476pkg0vivid1509/obj-x86_64-linux-gnu/bin/.mir_unit_tests-uninstalled)
11: ==32764== by 0x160A71E: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /tmp/buildd/mir-0.13.0bzr2476pkg0vivid1509/obj-x86_64-linux-gnu/bin/.mir_unit_tests-uninstalled)
11: ==32764== by 0x15F038A: testing::Test::Run() (in /tmp/buildd/mir-0.13.0bzr2476pkg0vivid1509/obj-x86_64-linux-gnu/bin/.mir_unit_tests-uninstalled)
11: ==32764== by 0x15F0C28: testing::TestInfo::Run() (in /tmp/buildd/mir-0.13.0bzr2476pkg0vivid1509/obj-x86_64-linux-gnu/bin/.mir_unit_tests-uninstalled)
11: ==32764== by 0x15F1331: testing::TestCase::Run() (in /tmp/buildd/mir-0.13.0bzr2476pkg0vivid1509/obj-x86_64-linux-gnu/bin/.mir_unit_tests-uninstalled)
11: ==32764== by 0x15F8203: testing::internal::UnitTestImpl::RunAllTests() (in /tmp/buildd/mir-0.13.0bzr2476pkg0vivid1509/obj-x86_64-linux-gnu/bin/.mir_unit_tests-uninstalled)
11: ==32764== by 0x1611014: bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (in /tmp/buildd/mir-0.13.0bzr2476pkg0vivid1509/obj-x86_64-linux-gnu/bin/.mir_unit_tests-uninstalled)
11: ==32764==
11: [ OK ] Mesa...

Read more...

review: Needs Fixing
lp:~kdub/mir/mesa-reconstruct-buffer updated on 2015-04-14
2477. By Kevin DuBois on 2015-04-14

fix uninitialized test variable valgrind complaint

2478. By Kevin DuBois on 2015-04-14

merge mir

Kevin DuBois (kdub) wrote :

ah, thanks. should be corrected

Alan Griffiths (alan-griffiths) wrote :

OA

review: Approve
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
1=== modified file 'src/platforms/mesa/server/buffer_allocator.cpp'
2--- src/platforms/mesa/server/buffer_allocator.cpp 2015-04-13 14:07:18 +0000
3+++ src/platforms/mesa/server/buffer_allocator.cpp 2015-04-14 12:24:42 +0000
4@@ -33,6 +33,7 @@
5
6 #include <algorithm>
7 #include <stdexcept>
8+#include <system_error>
9 #include <gbm.h>
10 #include <cassert>
11
12@@ -227,3 +228,33 @@
13
14 return iter != formats.end();
15 }
16+
17+std::unique_ptr<mg::Buffer> mgm::BufferAllocator::reconstruct_from(
18+ MirBufferPackage* package,
19+ MirPixelFormat format)
20+{
21+ if (package->fd_items != 1)
22+ BOOST_THROW_EXCEPTION(std::logic_error("Failed to create mgm::Buffer from invalid MirBufferPackage"));
23+
24+ gbm_import_fd_data data;
25+ data.fd = package->fd[0];
26+ data.width = package->width;
27+ data.height = package->height;
28+ data.stride = package->stride;
29+ data.format = format;
30+
31+ std::shared_ptr<gbm_bo> bo(
32+ gbm_bo_import(device, GBM_BO_IMPORT_FD, &data, package->flags),
33+ [](gbm_bo* bo){ gbm_bo_destroy(bo); });
34+
35+ if (!bo)
36+ {
37+ BOOST_THROW_EXCEPTION(
38+ std::system_error(errno, std::system_category(), "Failed to import MirBufferPackage"));
39+ }
40+
41+ return std::make_unique<mgm::GBMBuffer>(
42+ bo,
43+ package->flags,
44+ std::make_unique<EGLImageBufferTextureBinder>(bo, egl_extensions));
45+}
46
47=== modified file 'src/platforms/mesa/server/buffer_allocator.h'
48--- src/platforms/mesa/server/buffer_allocator.h 2015-01-22 09:00:14 +0000
49+++ src/platforms/mesa/server/buffer_allocator.h 2015-04-14 12:24:42 +0000
50@@ -46,6 +46,8 @@
51 virtual std::shared_ptr<Buffer> alloc_buffer(
52 graphics::BufferProperties const& buffer_properties);
53
54+ std::unique_ptr<Buffer> reconstruct_from(MirBufferPackage* package, MirPixelFormat format);
55+
56 std::vector<MirPixelFormat> supported_pixel_formats();
57
58 private:
59
60=== modified file 'tests/include/mir_test_doubles/mock_gbm.h'
61--- tests/include/mir_test_doubles/mock_gbm.h 2013-08-28 03:41:48 +0000
62+++ tests/include/mir_test_doubles/mock_gbm.h 2015-04-14 12:24:42 +0000
63@@ -76,6 +76,7 @@
64 MOCK_METHOD1(gbm_bo_get_user_data, void*(struct gbm_bo *bo));
65 MOCK_METHOD3(gbm_bo_write, bool(struct gbm_bo *bo, const void *buf, size_t count));
66 MOCK_METHOD1(gbm_bo_destroy, void(struct gbm_bo *bo));
67+ MOCK_METHOD4(gbm_bo_import, struct gbm_bo*(struct gbm_device*, uint32_t, void*, uint32_t));
68
69 FakeGBMResources fake_gbm;
70
71
72=== modified file 'tests/mir_test_doubles/mock_gbm.cpp'
73--- tests/mir_test_doubles/mock_gbm.cpp 2013-08-28 03:41:48 +0000
74+++ tests/mir_test_doubles/mock_gbm.cpp 2015-04-14 12:24:42 +0000
75@@ -168,3 +168,8 @@
76 {
77 return global_mock->gbm_bo_destroy(bo);
78 }
79+
80+struct gbm_bo* gbm_bo_import(struct gbm_device* device, uint32_t type, void* data, uint32_t flags)
81+{
82+ return global_mock->gbm_bo_import(device, type, data, flags);
83+}
84
85=== modified file 'tests/unit-tests/graphics/mesa/test_buffer_allocator.cpp'
86--- tests/unit-tests/graphics/mesa/test_buffer_allocator.cpp 2015-03-31 02:35:42 +0000
87+++ tests/unit-tests/graphics/mesa/test_buffer_allocator.cpp 2015-04-14 12:24:42 +0000
88@@ -31,6 +31,7 @@
89 #include <cstdlib>
90 #include <memory>
91 #include <stdexcept>
92+#include <system_error>
93 #include <algorithm>
94 #include <gtest/gtest.h>
95 #include <gmock/gmock.h>
96@@ -281,3 +282,68 @@
97 allocator->alloc_buffer(mg::BufferProperties{size, mir_pixel_format_abgr_8888, usage});
98 }, std::runtime_error);
99 }
100+
101+MATCHER_P(GbmImportMatch, value, "import data matches")
102+{
103+ using namespace testing;
104+ auto data = reinterpret_cast<struct gbm_import_fd_data*>(arg);
105+ EXPECT_THAT(data->fd, Eq(value.fd));
106+ EXPECT_THAT(data->width, Eq(value.width));
107+ EXPECT_THAT(data->height, Eq(value.height));
108+ EXPECT_THAT(data->stride, Eq(value.stride));
109+ EXPECT_THAT(data->format, Eq(value.format));
110+ return !(::testing::Test::HasFailure());
111+}
112+
113+TEST_F(MesaBufferAllocatorTest, reconstructs_from_native_type)
114+{
115+ using namespace testing;
116+ MirNativeBuffer native_buffer;
117+ uint32_t stride {22};
118+ native_buffer.fd_items = 1;
119+ native_buffer.fd[0] = 33;
120+ native_buffer.width = size.width.as_uint32_t();
121+ native_buffer.height = size.height.as_uint32_t();
122+ native_buffer.stride = stride;
123+ native_buffer.flags = GBM_BO_USE_RENDERING;
124+
125+ struct gbm_import_fd_data expected_data {
126+ native_buffer.fd[0],
127+ size.width.as_uint32_t(),
128+ size.height.as_uint32_t(),
129+ stride,
130+ pf
131+ };
132+
133+ EXPECT_CALL(mock_gbm, gbm_bo_import(_, GBM_BO_IMPORT_FD, GbmImportMatch(expected_data), native_buffer.flags ))
134+ .WillOnce(Return(mock_gbm.fake_gbm.bo));
135+ EXPECT_CALL(mock_gbm, gbm_bo_destroy(mock_gbm.fake_gbm.bo));
136+
137+ auto buffer = allocator->reconstruct_from(&native_buffer, pf);
138+ ASSERT_THAT(buffer, Ne(nullptr));
139+}
140+
141+TEST_F(MesaBufferAllocatorTest, reconstruct_throws_with_invalid_native_type)
142+{
143+ MirNativeBuffer native_buffer;
144+ native_buffer.fd_items = 0;
145+ EXPECT_THROW({
146+ auto buffer = allocator->reconstruct_from(&native_buffer, pf);
147+ }, std::logic_error);
148+ native_buffer.fd_items = 2;
149+ EXPECT_THROW({
150+ auto buffer = allocator->reconstruct_from(&native_buffer, pf);
151+ }, std::logic_error);
152+}
153+
154+TEST_F(MesaBufferAllocatorTest, reconstruct_throws_if_gbm_cannot_import)
155+{
156+ using namespace testing;
157+ EXPECT_CALL(mock_gbm, gbm_bo_import(_, _, _, _))
158+ .WillOnce(Return(nullptr));
159+ MirNativeBuffer native_buffer;
160+ native_buffer.fd_items = 1;
161+ EXPECT_THROW({
162+ auto buffer = allocator->reconstruct_from(&native_buffer, pf);
163+ }, std::system_error);
164+}

Subscribers

People subscribed via source and target branches