Mir

Merge lp:~kdub/mir/passthrough-ipc-plumbing into lp:mir

Proposed by Kevin DuBois on 2016-09-14
Status: Merged
Approved by: Daniel van Vugt on 2016-09-28
Approved revision: 3718
Merged at revision: 3725
Proposed branch: lp:~kdub/mir/passthrough-ipc-plumbing
Merge into: lp:mir
Prerequisite: lp:~kdub/mir/nested-native-buffer
Diff against target: 1083 lines (+479/-47)
33 files modified
include/common/mir_toolkit/mir_native_buffer.h (+2/-1)
src/client/mir_buffer_api.cpp (+14/-0)
src/client/symbols.map (+1/-0)
src/include/client/mir/client_buffer.h (+1/-0)
src/include/client/mir_toolkit/mir_buffer.h (+8/-0)
src/include/platform/mir/graphics/buffer_ipc_message.h (+1/-1)
src/platforms/android/client/buffer.cpp (+14/-7)
src/platforms/android/client/buffer.h (+2/-0)
src/platforms/android/client/gralloc_registrar.cpp (+4/-4)
src/platforms/android/include/native_buffer.h (+0/-5)
src/platforms/android/server/ipc_operations.cpp (+3/-2)
src/platforms/eglstream-kms/client/client_buffer.cpp (+5/-0)
src/platforms/eglstream-kms/client/client_buffer.h (+1/-0)
src/platforms/mesa/client/client_buffer.cpp (+5/-0)
src/platforms/mesa/client/client_buffer.h (+1/-0)
src/server/frontend/protobuf_buffer_packer.cpp (+5/-0)
src/server/frontend/protobuf_buffer_packer.h (+1/-0)
src/server/graphics/nested/CMakeLists.txt (+1/-0)
src/server/graphics/nested/ipc_operations.cpp (+92/-0)
src/server/graphics/nested/ipc_operations.h (+48/-0)
src/server/graphics/nested/native_buffer.h (+4/-0)
tests/acceptance-tests/throwback/test_presentation_chain.cpp (+22/-0)
tests/include/mir/test/doubles/mock_buffer_ipc_message.h (+1/-0)
tests/include/mir/test/doubles/mock_client_buffer.h (+1/-0)
tests/include/mir/test/doubles/null_client_buffer.h (+2/-0)
tests/include/mir/test/doubles/stub_client_buffer.h (+9/-5)
tests/unit-tests/client/test_aging_buffer.cpp (+5/-0)
tests/unit-tests/platforms/android/client/test_buffer.cpp (+8/-8)
tests/unit-tests/platforms/android/client/test_gralloc_registrar.cpp (+8/-8)
tests/unit-tests/platforms/android/server/test_platform.cpp (+6/-5)
tests/unit-tests/platforms/nested/CMakeLists.txt (+1/-0)
tests/unit-tests/platforms/nested/test_buffer.cpp (+4/-1)
tests/unit-tests/platforms/nested/test_ipc_operations.cpp (+199/-0)
To merge this branch: bzr merge lp:~kdub/mir/passthrough-ipc-plumbing
Reviewer Review Type Date Requested Status
Mir CI Bot continuous-integration Approve on 2016-09-27
Brandon Schaefer (community) Approve on 2016-09-26
Cemil Azizoglu (community) 2016-09-14 Approve on 2016-09-14
Review via email: mp+305698@code.launchpad.net

Commit Message

ipc: add the ability to pass MirBuffers in the nested server to the nested clients.

This needed some rework of android's fence-passing mechanism to be a bit more generic, so the nested platform can forward fences along properly.

Description of the Change

ipc: add the ability to pass MirBuffers in the nested server to the nested clients.

This needed some rework of android's fence-passing mechanism to be a bit more generic, so the nested platform can forward fences along properly.

To post a comment you must log in.
Cemil Azizoglu (cemil-azizoglu) wrote :

Mildly prefer to have the nested platform in place before adding to it.

review: Approve
Kevin DuBois (kdub) wrote :

Hmm, not sure what having the nested platform in place means. Its currently organized as a mg::Platform and the code lives in the libmirserver.so library.

Splitting out the code into its own .so is in-progress, but the nested passthrough work doesn't depend on the nested code being in its own platform library.

Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:3716
https://mir-jenkins.ubuntu.com/job/mir-ci/1807/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/2257/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2320
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2311
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2311
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2311
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2285
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2285/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2285/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2285
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2285/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2285/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2285
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2285/artifact/output/*zip*/output.zip

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

review: Needs Fixing (continuous-integration)
Daniel van Vugt (vanvugt) wrote :

^^^
Bug 1523621 and also Android vivid+overlay says:

19:26:42 ../../../../../tests/unit-tests/platforms/nested/test_ipc_operations.cpp:85:64: error: missing initializer for member ���mir::graphics::PlatformOperationMessage::data��� [-Werror=missing-field-initializers]
19:26:42 .WillByDefault(Return(mg::PlatformOperationMessage{}));
19:26:42 ^
19:26:42 ../../../../../tests/unit-tests/platforms/nested/test_ipc_operations.cpp:85:64: error: missing initializer for member ���mir::graphics::PlatformOperationMessage::fds��� [-Werror=missing-field-initializers]
19:26:42 ../../../../../tests/unit-tests/platforms/nested/test_ipc_operations.cpp: In member function ���virtual void NestedIPCOperations_uses_guest_platform_for_platform_ops_Test::TestBody()���:
19:26:42 ../../../../../tests/unit-tests/platforms/nested/test_ipc_operations.cpp:194:67: error: missing initializer for member ���mir::graphics::PlatformOperationMessage::data��� [-Werror=missing-field-initializers]
19:26:42 operations.platform_operation(0, mg::PlatformOperationMessage{});
19:26:42 ^
19:26:42 ../../../../../tests/unit-tests/platforms/nested/test_ipc_operations.cpp:194:67: error: missing initializer for member ���mir::graphics::PlatformOperationMessage::fds��� [-Werror=missing-field-initializers]
19:26:42 cc1plus: all warnings being treated as errors

Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3717
https://mir-jenkins.ubuntu.com/job/mir-ci/1817/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/2270
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2333
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2324
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2324
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2324
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2298
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2298/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/2298
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2298/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2298
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2298/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/2298
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2298/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/2298
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2298/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Brandon Schaefer (brandontschaefer) wrote :

lgtm

review: Approve
Daniel van Vugt (vanvugt) wrote :

08:07:21 Text conflict in src/client/mir_buffer_api.cpp
08:07:21 Text conflict in src/client/symbols.map
08:07:21 Text conflict in src/platforms/eglstream-kms/client/client_buffer.cpp
08:07:21 Text conflict in src/platforms/eglstream-kms/client/client_buffer.h
08:07:21 Text conflict in src/platforms/mesa/client/client_buffer.cpp
08:07:21 Text conflict in src/server/graphics/nested/native_buffer.h
08:07:21 Text conflict in tests/include/mir/test/doubles/mock_client_buffer.h
08:07:21 Text conflict in tests/unit-tests/client/test_aging_buffer.cpp
08:07:21 Text conflict in tests/unit-tests/platforms/nested/test_buffer.cpp
08:07:21 9 conflicts encountered.

3718. By Kevin DuBois on 2016-09-27

merge mir, fix 9 conflicts

Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3718
https://mir-jenkins.ubuntu.com/job/mir-ci/1830/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/2302
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2365
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2356
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2356
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2356
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2330
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2330/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/2330
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2330/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2330
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2330/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/2330
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2330/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/2330
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2330/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/common/mir_toolkit/mir_native_buffer.h'
2--- include/common/mir_toolkit/mir_native_buffer.h 2016-05-03 06:55:25 +0000
3+++ include/common/mir_toolkit/mir_native_buffer.h 2016-09-27 19:07:08 +0000
4@@ -24,7 +24,8 @@
5
6 typedef enum
7 {
8- mir_buffer_flag_can_scanout = 1
9+ mir_buffer_flag_can_scanout = 1,
10+ mir_buffer_flag_fenced = 1 << 1
11 } MirBufferFlag;
12
13 typedef struct MirBufferPackage
14
15=== modified file 'src/client/mir_buffer_api.cpp'
16--- src/client/mir_buffer_api.cpp 2016-09-15 17:46:10 +0000
17+++ src/client/mir_buffer_api.cpp 2016-09-27 19:07:08 +0000
18@@ -22,6 +22,7 @@
19 #include "presentation_chain.h"
20 #include "mir_connection.h"
21 #include "buffer.h"
22+#include "mir/client_buffer.h"
23 #include "mir/require.h"
24 #include "mir/uncaught.h"
25 #include "mir/require.h"
26@@ -220,6 +221,19 @@
27 MIR_LOG_UNCAUGHT_EXCEPTION(ex);
28 }
29
30+MirBufferPackage* mir_buffer_get_buffer_package(MirBuffer* b)
31+try
32+{
33+ mir::require(b);
34+ auto buffer = reinterpret_cast<mcl::Buffer*>(b);
35+ return buffer->client_buffer()->package();
36+}
37+catch (std::exception const& ex)
38+{
39+ MIR_LOG_UNCAUGHT_EXCEPTION(ex);
40+ return nullptr;
41+}
42+
43 void mir_buffer_egl_image_parameters(
44 MirBuffer* b, EGLenum* type, EGLClientBuffer* client_buffer, EGLint** attr)
45 try
46
47=== modified file 'src/client/symbols.map'
48--- src/client/symbols.map 2016-09-22 18:17:43 +0000
49+++ src/client/symbols.map 2016-09-27 19:07:08 +0000
50@@ -384,6 +384,7 @@
51 mir_buffer_get_buffer_usage;
52 mir_buffer_is_valid;
53 mir_buffer_get_error_message;
54+ mir_buffer_get_buffer_package;
55 mir_buffer_egl_image_parameters;
56 local:
57 *;
58
59=== modified file 'src/include/client/mir/client_buffer.h'
60--- src/include/client/mir/client_buffer.h 2016-09-15 16:42:54 +0000
61+++ src/include/client/mir/client_buffer.h 2016-09-27 19:07:08 +0000
62@@ -69,6 +69,7 @@
63 virtual std::shared_ptr<graphics::NativeBuffer> native_buffer_handle() const = 0;
64 virtual void update_from(MirBufferPackage const& update_package) = 0;
65 virtual void fill_update_msg(MirBufferPackage& message) = 0;
66+ virtual MirBufferPackage* package() const = 0;
67
68 virtual MirNativeBuffer* as_mir_native_buffer() const = 0;
69 virtual void set_fence(MirNativeFence, MirBufferAccess) = 0;
70
71=== modified file 'src/include/client/mir_toolkit/mir_buffer.h'
72--- src/include/client/mir_toolkit/mir_buffer.h 2016-09-15 16:42:54 +0000
73+++ src/include/client/mir_toolkit/mir_buffer.h 2016-09-27 19:07:08 +0000
74@@ -101,6 +101,14 @@
75 **/
76 MirNativeBuffer* mir_buffer_get_native_buffer(MirBuffer*, MirBufferAccess access);
77
78+/**
79+ * Access the MirBufferPackage
80+ *
81+ * \param [in] buffer The buffer
82+ * \return The MirBufferPackage representing buffer
83+ */
84+MirBufferPackage* mir_buffer_get_buffer_package(MirBuffer* buffer);
85+
86 /** Access a CPU-mapped region associated with a given buffer for the given purpose.
87 * This will synchronize the buffer for the given purpose.
88 *
89
90=== modified file 'src/include/platform/mir/graphics/buffer_ipc_message.h'
91--- src/include/platform/mir/graphics/buffer_ipc_message.h 2015-02-22 07:46:25 +0000
92+++ src/include/platform/mir/graphics/buffer_ipc_message.h 2016-09-27 19:07:08 +0000
93@@ -41,7 +41,7 @@
94
95 virtual std::vector<Fd> fds() = 0;
96 virtual std::vector<int> data() = 0;
97-
98+ virtual unsigned int flags() = 0;
99 protected:
100 BufferIpcMessage() = default;
101 BufferIpcMessage(BufferIpcMessage const&) = delete;
102
103=== modified file 'src/platforms/android/client/buffer.cpp'
104--- src/platforms/android/client/buffer.cpp 2016-09-15 16:42:54 +0000
105+++ src/platforms/android/client/buffer.cpp 2016-09-27 19:07:08 +0000
106@@ -16,6 +16,7 @@
107 * Authored by: Kevin DuBois<kevin.dubois@canonical.com>
108 */
109
110+#include "mir/graphics/platform_ipc_operations.h"
111 #include "android_native_buffer.h"
112 #include "sync_fence.h"
113 #include "mir_toolkit/mir_client_library.h"
114@@ -27,6 +28,7 @@
115 namespace mcl=mir::client;
116 namespace mcla=mir::client::android;
117 namespace geom=mir::geometry;
118+namespace mg=mir::graphics;
119 namespace mga=mir::graphics::android;
120
121 mcla::Buffer::Buffer(
122@@ -37,7 +39,8 @@
123 native_buffer{registrar->register_buffer(package, pf)},
124 buffer_pf(pf),
125 buffer_stride{package.stride},
126- buffer_size{package.width, package.height}
127+ buffer_size{package.width, package.height},
128+ creation_package(package)
129 {
130 }
131
132@@ -76,9 +79,8 @@
133
134 void mcla::Buffer::update_from(MirBufferPackage const& update_package)
135 {
136- if ((update_package.data_items != 0) &&
137- (update_package.fd_items != 0) &&
138- (update_package.data[0] == static_cast<int>(mga::BufferFlag::fenced)))
139+ if ((update_package.flags & mir_buffer_flag_fenced) &&
140+ (update_package.fd_items != 0))
141 {
142 auto fence_fd = update_package.fd[0];
143 native_buffer->update_usage(fence_fd, mga::BufferAccess::read);
144@@ -87,17 +89,17 @@
145
146 void mcla::Buffer::fill_update_msg(MirBufferPackage& message)
147 {
148- message.data_items = 1;
149+ message.data_items = 0;
150 auto fence = native_buffer->copy_fence();
151 if (fence > 0)
152 {
153- message.data[0] = static_cast<int>(mga::BufferFlag::fenced);
154+ message.flags = mir_buffer_flag_fenced;
155 message.fd[0] = fence;
156 message.fd_items = 1;
157 }
158 else
159 {
160- message.data[0] = static_cast<int>(mga::BufferFlag::unfenced);
161+ message.flags = 0;
162 message.fd_items = 0;
163 }
164 }
165@@ -153,3 +155,8 @@
166
167 BOOST_THROW_EXCEPTION(std::invalid_argument("invalid MirBufferAccess"));
168 }
169+
170+MirBufferPackage* mcla::Buffer::package() const
171+{
172+ return const_cast<MirBufferPackage*>(&creation_package);
173+}
174
175=== modified file 'src/platforms/android/client/buffer.h'
176--- src/platforms/android/client/buffer.h 2016-09-22 18:17:43 +0000
177+++ src/platforms/android/client/buffer.h 2016-09-27 19:07:08 +0000
178@@ -50,6 +50,7 @@
179 std::shared_ptr<graphics::NativeBuffer> native_buffer_handle() const override;
180 void update_from(MirBufferPackage const& update_package) override;
181 void fill_update_msg(MirBufferPackage& message) override;
182+ MirBufferPackage* package() const override;
183 MirNativeBuffer* as_mir_native_buffer() const override;
184 void set_fence(MirNativeFence, MirBufferAccess) override;
185 MirNativeFence get_fence() const override;
186@@ -69,6 +70,7 @@
187 MirPixelFormat const buffer_pf;
188 geometry::Stride const buffer_stride;
189 geometry::Size const buffer_size;
190+ MirBufferPackage const creation_package;
191 };
192
193 }
194
195=== modified file 'src/platforms/android/client/gralloc_registrar.cpp'
196--- src/platforms/android/client/gralloc_registrar.cpp 2016-09-19 04:16:15 +0000
197+++ src/platforms/android/client/gralloc_registrar.cpp 2016-09-27 19:07:08 +0000
198@@ -16,6 +16,7 @@
199 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
200 */
201
202+#include "mir/graphics/platform_ipc_operations.h"
203 #include "egl_sync_fence.h"
204 #include "android_native_buffer.h"
205 #include "sync_fence.h"
206@@ -91,8 +92,7 @@
207 MirBufferPackage const& package,
208 MirPixelFormat pf) const
209 {
210- bool const fence_present{package.data[0] == static_cast<int>(mga::BufferFlag::fenced)};
211- int const mir_flag_offset{1};
212+ auto fence_present = package.flags & mir_buffer_flag_fenced;
213
214 int native_handle_header_size = sizeof(native_handle_t);
215 int total_size = sizeof(int) *
216@@ -118,9 +118,9 @@
217 handle->data[i] = package.fd[i];
218 }
219
220- handle->numInts = package.data_items - mir_flag_offset;
221+ handle->numInts = package.data_items;
222 for (auto i = 0; i < handle->numInts; i++)
223- handle->data[handle->numFds+i] = package.data[i + mir_flag_offset];
224+ handle->data[handle->numFds+i] = package.data[i];
225
226 if (gralloc_module->registerBuffer(gralloc_module.get(), handle))
227 {
228
229=== modified file 'src/platforms/android/include/native_buffer.h'
230--- src/platforms/android/include/native_buffer.h 2016-09-19 04:16:15 +0000
231+++ src/platforms/android/include/native_buffer.h 2016-09-27 19:07:08 +0000
232@@ -31,11 +31,6 @@
233
234 namespace android
235 {
236-enum class BufferFlag
237-{
238- unfenced = 0,
239- fenced
240-};
241 enum class BufferAccess
242 {
243 read,
244
245=== modified file 'src/platforms/android/server/ipc_operations.cpp'
246--- src/platforms/android/server/ipc_operations.cpp 2016-09-19 04:16:15 +0000
247+++ src/platforms/android/server/ipc_operations.cpp 2016-09-27 19:07:08 +0000
248@@ -22,6 +22,7 @@
249 #include "mir/graphics/buffer_ipc_message.h"
250 #include "mir/graphics/platform_operation_message.h"
251 #include "mir/libname.h"
252+#include "mir_toolkit/mir_native_buffer.h"
253 #include "android_native_buffer.h"
254 #include "ipc_operations.h"
255
256@@ -40,12 +41,12 @@
257 mir::Fd fence_fd(native_buffer->copy_fence());
258 if (fence_fd != mir::Fd::invalid)
259 {
260- msg.pack_data(static_cast<int>(mga::BufferFlag::fenced));
261+ msg.pack_flags(mir_buffer_flag_fenced);
262 msg.pack_fd(fence_fd);
263 }
264 else
265 {
266- msg.pack_data(static_cast<int>(mga::BufferFlag::unfenced));
267+ msg.pack_flags(0);
268 }
269
270 if (msg_type == mg::BufferIpcMsgType::full_msg)
271
272=== modified file 'src/platforms/eglstream-kms/client/client_buffer.cpp'
273--- src/platforms/eglstream-kms/client/client_buffer.cpp 2016-09-22 18:17:43 +0000
274+++ src/platforms/eglstream-kms/client/client_buffer.cpp 2016-09-27 19:07:08 +0000
275@@ -166,6 +166,11 @@
276 return true;
277 }
278
279+MirBufferPackage* mcle::ClientBuffer::package() const
280+{
281+ return creation_package.get();
282+}
283+
284 void mcle::ClientBuffer::egl_image_creation_parameters(EGLenum*, EGLClientBuffer*, EGLint**)
285 {
286 BOOST_THROW_EXCEPTION(std::invalid_argument("not implemented yet"));
287
288=== modified file 'src/platforms/eglstream-kms/client/client_buffer.h'
289--- src/platforms/eglstream-kms/client/client_buffer.h 2016-09-22 18:17:43 +0000
290+++ src/platforms/eglstream-kms/client/client_buffer.h 2016-09-27 19:07:08 +0000
291@@ -55,6 +55,7 @@
292 void set_fence(MirNativeFence, MirBufferAccess);
293 MirNativeFence get_fence() const;
294 bool wait_fence(MirBufferAccess, std::chrono::nanoseconds timeout);
295+ MirBufferPackage* package() const;
296 void egl_image_creation_parameters(EGLenum*, EGLClientBuffer*, EGLint**);
297
298 private:
299
300=== modified file 'src/platforms/mesa/client/client_buffer.cpp'
301--- src/platforms/mesa/client/client_buffer.cpp 2016-09-22 18:17:43 +0000
302+++ src/platforms/mesa/client/client_buffer.cpp 2016-09-27 19:07:08 +0000
303@@ -170,6 +170,11 @@
304 return true;
305 }
306
307+MirBufferPackage* mclm::ClientBuffer::package() const
308+{
309+ return as_mir_native_buffer();
310+}
311+
312 void mclm::ClientBuffer::egl_image_creation_parameters(EGLenum*, EGLClientBuffer*, EGLint**)
313 {
314 BOOST_THROW_EXCEPTION(std::invalid_argument("not implemented yet"));
315
316=== modified file 'src/platforms/mesa/client/client_buffer.h'
317--- src/platforms/mesa/client/client_buffer.h 2016-09-22 18:17:43 +0000
318+++ src/platforms/mesa/client/client_buffer.h 2016-09-27 19:07:08 +0000
319@@ -53,6 +53,7 @@
320 std::shared_ptr<graphics::NativeBuffer> native_buffer_handle() const;
321 void update_from(MirBufferPackage const&);
322 void fill_update_msg(MirBufferPackage&);
323+ MirBufferPackage* package() const;
324 MirNativeBuffer* as_mir_native_buffer() const;
325 void set_fence(MirNativeFence, MirBufferAccess);
326 MirNativeFence get_fence() const;
327
328=== modified file 'src/server/frontend/protobuf_buffer_packer.cpp'
329--- src/server/frontend/protobuf_buffer_packer.cpp 2016-09-19 04:16:15 +0000
330+++ src/server/frontend/protobuf_buffer_packer.cpp 2016-09-27 19:07:08 +0000
331@@ -141,3 +141,8 @@
332 {
333 return {buffer_response->data().begin(), buffer_response->data().end()};
334 }
335+
336+unsigned int mfd::ProtobufBufferPacker::flags()
337+{
338+ return buffer_response->flags();
339+}
340
341=== modified file 'src/server/frontend/protobuf_buffer_packer.h'
342--- src/server/frontend/protobuf_buffer_packer.h 2015-06-17 05:20:42 +0000
343+++ src/server/frontend/protobuf_buffer_packer.h 2016-09-27 19:07:08 +0000
344@@ -55,6 +55,7 @@
345
346 std::vector<Fd> fds();
347 std::vector<int> data();
348+ unsigned int flags();
349 private:
350 std::vector<mir::Fd> fds_;
351 protobuf::Buffer* buffer_response;
352
353=== modified file 'src/server/graphics/nested/CMakeLists.txt'
354--- src/server/graphics/nested/CMakeLists.txt 2016-08-15 13:28:21 +0000
355+++ src/server/graphics/nested/CMakeLists.txt 2016-09-27 19:07:08 +0000
356@@ -13,4 +13,5 @@
357 cursor.cpp
358 platform.cpp
359 buffer.cpp
360+ ipc_operations.cpp
361 )
362
363=== added file 'src/server/graphics/nested/ipc_operations.cpp'
364--- src/server/graphics/nested/ipc_operations.cpp 1970-01-01 00:00:00 +0000
365+++ src/server/graphics/nested/ipc_operations.cpp 2016-09-27 19:07:08 +0000
366@@ -0,0 +1,92 @@
367+/*
368+ * Copyright © 2016 Canonical Ltd.
369+ *
370+ * This program is free software: you can redistribute it and/or modify it
371+ * under the terms of the GNU General Public License version 3,
372+ * as published by the Free Software Foundation.
373+ *
374+ * This program is distributed in the hope that it will be useful,
375+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
376+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
377+ * GNU General Public License for more details.
378+ *
379+ * You should have received a copy of the GNU General Public License
380+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
381+ *
382+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
383+ */
384+
385+#include "native_buffer.h"
386+#include "ipc_operations.h"
387+#include "mir_toolkit/mir_native_buffer.h"
388+#include "mir/graphics/platform_operation_message.h"
389+#include "mir/graphics/buffer.h"
390+#include "mir/graphics/buffer_ipc_message.h"
391+
392+namespace mg = mir::graphics;
393+namespace mgn = mir::graphics::nested;
394+namespace geom = mir::geometry;
395+
396+mgn::IpcOperations::IpcOperations(
397+ std::shared_ptr<mg::PlatformIpcOperations> const& host_operations) :
398+ ipc_operations(host_operations)
399+{
400+}
401+
402+void mgn::IpcOperations::pack_buffer(
403+ mg::BufferIpcMessage& message, mg::Buffer const& buffer, mg::BufferIpcMsgType msg_type) const
404+{
405+ if (auto native = std::dynamic_pointer_cast<mgn::NativeBuffer>(buffer.native_buffer_handle()))
406+ {
407+ auto package = native->package();
408+ auto fence = native->fence();
409+ if (fence > mir::Fd::invalid)
410+ {
411+ message.pack_flags(mir_buffer_flag_fenced | package->flags);
412+ message.pack_fd(fence);
413+ }
414+ else
415+ {
416+ message.pack_flags(~mir_buffer_flag_fenced & package->flags);
417+ }
418+
419+ if (msg_type == mg::BufferIpcMsgType::full_msg)
420+ {
421+ for (auto i = 0; i < package->data_items; i++)
422+ message.pack_data(package->data[i]);
423+ for (auto i = 0; i < package->fd_items; i++)
424+ message.pack_fd(mir::Fd(IntOwnedFd{package->fd[i]}));
425+ message.pack_stride(geom::Stride{package->stride});
426+ message.pack_size(geom::Size{package->width, package->height});
427+ }
428+ }
429+ else
430+ {
431+ ipc_operations->pack_buffer(message, buffer, msg_type);
432+ }
433+}
434+
435+void mgn::IpcOperations::unpack_buffer(mg::BufferIpcMessage& message, mg::Buffer const& buffer) const
436+{
437+ if (auto native = std::dynamic_pointer_cast<mgn::NativeBuffer>(buffer.native_buffer_handle()))
438+ {
439+ auto fds = message.fds();
440+ if ( (message.flags() & mir_buffer_flag_fenced) && !fds.empty())
441+ native->set_fence(fds.front());
442+ }
443+ else
444+ {
445+ ipc_operations->unpack_buffer(message, buffer);
446+ }
447+}
448+
449+std::shared_ptr<mg::PlatformIPCPackage> mgn::IpcOperations::connection_ipc_package()
450+{
451+ return ipc_operations->connection_ipc_package();
452+}
453+
454+mg::PlatformOperationMessage mgn::IpcOperations::platform_operation(
455+ unsigned int const opcode, mg::PlatformOperationMessage const& message)
456+{
457+ return ipc_operations->platform_operation(opcode, message);
458+}
459
460=== added file 'src/server/graphics/nested/ipc_operations.h'
461--- src/server/graphics/nested/ipc_operations.h 1970-01-01 00:00:00 +0000
462+++ src/server/graphics/nested/ipc_operations.h 2016-09-27 19:07:08 +0000
463@@ -0,0 +1,48 @@
464+/*
465+ * Copyright © 2016 Canonical Ltd.
466+ *
467+ * This program is free software: you can redistribute it and/or modify it
468+ * under the terms of the GNU General Public License version 3,
469+ * as published by the Free Software Foundation.
470+ *
471+ * This program is distributed in the hope that it will be useful,
472+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
473+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
474+ * GNU General Public License for more details.
475+ *
476+ * You should have received a copy of the GNU General Public License
477+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
478+ *
479+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
480+ */
481+
482+#ifndef MIR_GRAPHICS_NESTED_IPC_OPERATIONS_H_
483+#define MIR_GRAPHICS_NESTED_IPC_OPERATIONS_H_
484+
485+#include "mir/graphics/platform_ipc_operations.h"
486+#include <memory>
487+
488+namespace mir
489+{
490+namespace graphics
491+{
492+namespace nested
493+{
494+class IpcOperations : public PlatformIpcOperations
495+{
496+public:
497+ IpcOperations(std::shared_ptr<graphics::PlatformIpcOperations> const& host_operations);
498+
499+ void pack_buffer(BufferIpcMessage& message, Buffer const& buffer, BufferIpcMsgType msg_type) const override;
500+ void unpack_buffer(BufferIpcMessage& message, Buffer const& buffer) const override;
501+ std::shared_ptr<PlatformIPCPackage> connection_ipc_package() override;
502+ PlatformOperationMessage platform_operation(
503+ unsigned int const opcode, PlatformOperationMessage const& message) override;
504+
505+private:
506+ std::shared_ptr<graphics::PlatformIpcOperations> const ipc_operations;
507+};
508+}
509+}
510+}
511+#endif /* MIR_GRAPHICS_NESTED_IPC_OPERATIONS_H_ */
512
513=== modified file 'src/server/graphics/nested/native_buffer.h'
514--- src/server/graphics/nested/native_buffer.h 2016-09-15 16:20:24 +0000
515+++ src/server/graphics/nested/native_buffer.h 2016-09-27 19:07:08 +0000
516@@ -21,6 +21,7 @@
517
518 #include "mir/geometry/size.h"
519 #include "mir/graphics/native_buffer.h"
520+#include "mir/fd.h"
521 #include "mir_toolkit/client_types_nbs.h"
522 #include "mir_toolkit/client_types.h"
523 #include "mir_toolkit/mir_native_buffer.h"
524@@ -45,6 +46,9 @@
525 virtual MirGraphicsRegion get_graphics_region() = 0;
526 virtual geometry::Size size() const = 0;
527 virtual MirPixelFormat format() const = 0;
528+ virtual MirBufferPackage* package() const = 0;
529+ virtual Fd fence() const = 0;
530+ virtual void set_fence(Fd) = 0;
531 virtual std::tuple<EGLenum, EGLClientBuffer, EGLint*> egl_image_creation_hints() const = 0;
532 protected:
533 NativeBuffer() = default;
534
535=== modified file 'tests/acceptance-tests/throwback/test_presentation_chain.cpp'
536--- tests/acceptance-tests/throwback/test_presentation_chain.cpp 2016-09-27 15:07:45 +0000
537+++ tests/acceptance-tests/throwback/test_presentation_chain.cpp 2016-09-27 19:07:08 +0000
538@@ -226,6 +226,28 @@
539 EXPECT_THAT(mir_buffer_get_native_buffer(buffer, mir_none), Eq(nullptr));
540 }
541
542+TEST_F(PresentationChain, can_access_platform_message_representing_buffer)
543+{
544+ SurfaceWithChainFromStart surface(connection, size, pf);
545+
546+ MirBufferSync context;
547+ mir_connection_allocate_buffer(
548+ connection,
549+ size.width.as_int(), size.height.as_int(), pf, usage,
550+ buffer_callback, &context);
551+
552+ EXPECT_TRUE(context.wait_for_buffer(10s));
553+ auto buffer = context.buffer();
554+ EXPECT_THAT(context.buffer(), Ne(nullptr));
555+
556+ auto message = mir_buffer_get_buffer_package(buffer);
557+ ASSERT_THAT(message, Ne(nullptr));
558+ EXPECT_THAT(message->data_items, Ge(1));
559+ EXPECT_THAT(message->fd_items, Ge(1));
560+ EXPECT_THAT(message->width, Eq(size.width.as_int()));
561+ EXPECT_THAT(message->height, Eq(size.height.as_int()));
562+}
563+
564 TEST_F(PresentationChain, has_native_fence)
565 {
566 SurfaceWithChainFromStart surface(connection, size, pf);
567
568=== modified file 'tests/include/mir/test/doubles/mock_buffer_ipc_message.h'
569--- tests/include/mir/test/doubles/mock_buffer_ipc_message.h 2016-08-24 02:09:08 +0000
570+++ tests/include/mir/test/doubles/mock_buffer_ipc_message.h 2016-09-27 19:07:08 +0000
571@@ -40,6 +40,7 @@
572 MOCK_METHOD1(pack_size, void(geometry::Size const&));
573 MOCK_METHOD0(fds, std::vector<mir::Fd>());
574 MOCK_METHOD0(data, std::vector<int>());
575+ MOCK_METHOD0(flags, unsigned int());
576 };
577
578 }
579
580=== modified file 'tests/include/mir/test/doubles/mock_client_buffer.h'
581--- tests/include/mir/test/doubles/mock_client_buffer.h 2016-09-15 16:42:54 +0000
582+++ tests/include/mir/test/doubles/mock_client_buffer.h 2016-09-27 19:07:08 +0000
583@@ -47,6 +47,7 @@
584 MOCK_METHOD2(set_fence, void(MirNativeFence, MirBufferAccess));
585 MOCK_CONST_METHOD0(get_fence, MirNativeFence());
586 MOCK_METHOD2(wait_fence, bool(MirBufferAccess, std::chrono::nanoseconds));
587+ MOCK_CONST_METHOD0(package, MirBufferPackage*());
588 MOCK_METHOD3(egl_image_creation_parameters, void(EGLenum*, EGLClientBuffer*, EGLint**));
589 int age_{0};
590 };
591
592=== modified file 'tests/include/mir/test/doubles/null_client_buffer.h'
593--- tests/include/mir/test/doubles/null_client_buffer.h 2016-09-15 16:42:54 +0000
594+++ tests/include/mir/test/doubles/null_client_buffer.h 2016-09-27 19:07:08 +0000
595@@ -51,6 +51,8 @@
596 {
597 return nullptr;
598 }
599+ MirBufferPackage* package() const { return nullptr; }
600+
601 geometry::Size sz;
602
603 MirNativeBuffer* as_mir_native_buffer() const { return nullptr; }
604
605=== modified file 'tests/include/mir/test/doubles/stub_client_buffer.h'
606--- tests/include/mir/test/doubles/stub_client_buffer.h 2016-09-15 16:42:54 +0000
607+++ tests/include/mir/test/doubles/stub_client_buffer.h 2016-09-27 19:07:08 +0000
608@@ -35,7 +35,7 @@
609 std::shared_ptr<MirBufferPackage> const& package,
610 geometry::Size size, MirPixelFormat pf,
611 std::shared_ptr<graphics::NativeBuffer> const& buffer) :
612- package{package}, size_{size}, pf_{pf}, buffer{buffer}
613+ package_{package}, size_{size}, pf_{pf}, buffer{buffer}
614 {
615 }
616
617@@ -48,8 +48,8 @@
618
619 ~StubClientBuffer()
620 {
621- for (int i = 0; i < package->fd_items; i++)
622- ::close(package->fd[i]);
623+ for (int i = 0; i < package_->fd_items; i++)
624+ ::close(package_->fd[i]);
625 }
626
627 std::shared_ptr<client::MemoryRegion> secure_for_cpu_write() override
628@@ -65,7 +65,7 @@
629 }
630
631 geometry::Size size() const override { return size_; }
632- geometry::Stride stride() const override { return geometry::Stride{package->stride}; }
633+ geometry::Stride stride() const override { return geometry::Stride{package_->stride}; }
634 MirPixelFormat pixel_format() const override { return pf_; }
635 uint32_t age() const override { return 0; }
636 void increment_age() override {}
637@@ -75,6 +75,10 @@
638 {
639 return buffer;
640 }
641+ MirBufferPackage* package() const
642+ {
643+ return package_.get();
644+ }
645 void update_from(MirBufferPackage const&) override {}
646 void fill_update_msg(MirBufferPackage&) override{}
647
648@@ -84,7 +88,7 @@
649 bool wait_fence(MirBufferAccess, std::chrono::nanoseconds) override { return true; }
650 void egl_image_creation_parameters(EGLenum*, EGLClientBuffer*, EGLint**) {}
651
652- std::shared_ptr<MirBufferPackage> const package;
653+ std::shared_ptr<MirBufferPackage> const package_;
654 geometry::Size size_;
655 MirPixelFormat pf_;
656 std::shared_ptr<graphics::NativeBuffer> buffer;
657
658=== modified file 'tests/unit-tests/client/test_aging_buffer.cpp'
659--- tests/unit-tests/client/test_aging_buffer.cpp 2016-09-15 16:42:54 +0000
660+++ tests/unit-tests/client/test_aging_buffer.cpp 2016-09-27 19:07:08 +0000
661@@ -84,6 +84,11 @@
662 exit(1);
663 }
664
665+ MirBufferPackage* package() const override
666+ {
667+ exit(1);
668+ }
669+
670 void egl_image_creation_parameters(EGLenum*, EGLClientBuffer*, EGLint**) override
671 {
672 exit(1);
673
674=== modified file 'tests/unit-tests/platforms/android/client/test_buffer.cpp'
675--- tests/unit-tests/platforms/android/client/test_buffer.cpp 2016-08-01 07:24:32 +0000
676+++ tests/unit-tests/platforms/android/client/test_buffer.cpp 2016-09-27 19:07:08 +0000
677@@ -18,6 +18,7 @@
678
679 #include "mir/test/doubles/mock_buffer_registrar.h"
680 #include "mir/test/doubles/mock_android_native_buffer.h"
681+#include "mir/graphics/platform_ipc_operations.h"
682 #include "src/platforms/android/client/buffer.h"
683 #include "mir_toolkit/mir_client_library.h"
684
685@@ -95,20 +96,19 @@
686 .Times(1);
687 mcla::Buffer buffer(mock_registrar, package, pf);
688
689- package.data_items = 1;
690+ package.data_items = 0;
691 package.fd_items = 1;
692- package.data[0] = static_cast<int>(mga::BufferFlag::fenced);
693+ package.flags = mir_buffer_flag_fenced;
694 package.fd[0] = fake_fence;
695 buffer.update_from(package);
696
697- package.data[0] = static_cast<int>(mga::BufferFlag::unfenced);
698+ package.flags = 0;
699 buffer.update_from(package);
700 }
701
702 TEST_F(AndroidClientBuffer, fills_update_msg)
703 {
704 using namespace testing;
705- using mir::graphics::android::BufferFlag;
706 int stub_fence{44};
707 int invalid_fence{-1};
708
709@@ -122,15 +122,15 @@
710
711 buffer.fill_update_msg(msg);
712
713- EXPECT_THAT(msg.data_items, Eq(1));
714- EXPECT_THAT(msg.data[0], Eq(static_cast<int>(BufferFlag::fenced)));
715+ EXPECT_THAT(msg.data_items, Eq(0));
716+ EXPECT_THAT(msg.flags, Eq(mir_buffer_flag_fenced));
717 EXPECT_THAT(msg.fd_items, Eq(1));
718 EXPECT_THAT(msg.fd[0], Eq(stub_fence));
719
720 buffer.fill_update_msg(msg);
721
722- EXPECT_THAT(msg.data_items, Eq(1));
723- EXPECT_THAT(msg.data[0], Eq(static_cast<int>(BufferFlag::unfenced)));
724+ EXPECT_THAT(msg.data_items, Eq(0));
725+ EXPECT_THAT(msg.flags, Eq(0));
726 EXPECT_THAT(msg.fd_items, Eq(0));
727 }
728
729
730=== modified file 'tests/unit-tests/platforms/android/client/test_gralloc_registrar.cpp'
731--- tests/unit-tests/platforms/android/client/test_gralloc_registrar.cpp 2016-01-29 08:18:22 +0000
732+++ tests/unit-tests/platforms/android/client/test_gralloc_registrar.cpp 2016-09-27 19:07:08 +0000
733@@ -17,6 +17,7 @@
734 */
735
736 #include "native_buffer.h"
737+#include "mir/graphics/platform_ipc_operations.h"
738 #include "src/platforms/android/client/gralloc_registrar.h"
739 #include "mir/test/doubles/mock_android_native_buffer.h"
740 #include <stdexcept>
741@@ -93,8 +94,8 @@
742 stub_package.data_items = 21;
743 for (auto i = 0; i < stub_package.fd_items; i++)
744 stub_package.fd[i] = (i*4);
745- stub_package.data[0] = static_cast<int>(mir::graphics::android::BufferFlag::unfenced);
746- for (auto i = 1; i < stub_package.data_items; i++)
747+ stub_package.flags = 0;
748+ for (auto i = 0; i < stub_package.data_items; i++)
749 stub_package.data[i] = (i*3);
750 }
751
752@@ -113,18 +114,17 @@
753
754 TEST_F(GrallocRegistrar, client_buffer_converts_stub_package)
755 {
756- int const flag_offset{1};
757 mcla::GrallocRegistrar registrar(mock_module);
758 auto buffer = registrar.register_buffer(stub_package, pf);
759
760 auto handle = buffer->handle();
761 ASSERT_NE(nullptr, handle);
762 ASSERT_EQ(stub_package.fd_items, handle->numFds);
763- ASSERT_EQ(stub_package.data_items - 1, handle->numInts);
764+ ASSERT_EQ(stub_package.data_items, handle->numInts);
765 for (auto i = 0; i < stub_package.fd_items; i++)
766 EXPECT_EQ(stub_package.fd[i], handle->data[i]);
767- for (auto i = 0; i < stub_package.data_items - 1; i++)
768- EXPECT_EQ(stub_package.data[i + flag_offset], handle->data[i + stub_package.fd_items]);
769+ for (auto i = 0; i < stub_package.data_items; i++)
770+ EXPECT_EQ(stub_package.data[i], handle->data[i + stub_package.fd_items]);
771 }
772
773 TEST_F(GrallocRegistrar, client_sets_correct_version)
774@@ -160,8 +160,8 @@
775 using namespace testing;
776 MirBufferPackage stub_package;
777 memset(&stub_package, 0, sizeof(MirBufferPackage));
778- stub_package.data_items = 1;
779- stub_package.data[0] = static_cast<int>(mir::graphics::android::BufferFlag::unfenced);
780+ stub_package.data_items = 0;
781+ stub_package.flags = 0;
782 stub_package.fd_items = 2;
783 EXPECT_EQ(0, pipe(static_cast<int*>(stub_package.fd)));
784
785
786=== modified file 'tests/unit-tests/platforms/android/server/test_platform.cpp'
787--- tests/unit-tests/platforms/android/server/test_platform.cpp 2016-09-01 12:16:41 +0000
788+++ tests/unit-tests/platforms/android/server/test_platform.cpp 2016-09-27 19:07:08 +0000
789@@ -33,6 +33,7 @@
790 #include "mir/test/doubles/null_gl_context.h"
791 #include "mir_test_framework/executable_path.h"
792 #include "mir/shared_library.h"
793+#include "mir_toolkit/mir_native_buffer.h"
794 #include "native_window_report.h"
795 #include <system/window.h>
796 #include <gtest/gtest.h>
797@@ -120,7 +121,7 @@
798
799 mtd::MockBufferIpcMessage mock_ipc_msg;
800 int offset = 0;
801- EXPECT_CALL(mock_ipc_msg, pack_data(static_cast<int>(mga::BufferFlag::fenced)));
802+ EXPECT_CALL(mock_ipc_msg, pack_flags(mir_buffer_flag_fenced));
803 EXPECT_CALL(mock_ipc_msg, pack_fd(mtd::RawFdMatcher(fake_fence)));
804 for (auto i = 0u; i < num_fds; i++)
805 EXPECT_CALL(mock_ipc_msg, pack_fd(mtd::RawFdMatcher(native_buffer_handle->data[offset++])));
806@@ -155,7 +156,7 @@
807
808 mtd::MockBufferIpcMessage mock_ipc_msg;
809 int offset = 0;
810- EXPECT_CALL(mock_ipc_msg, pack_data(static_cast<int>(mga::BufferFlag::unfenced)));
811+ EXPECT_CALL(mock_ipc_msg, pack_flags(0));
812 EXPECT_CALL(mock_ipc_msg, pack_fd(mtd::RawFdMatcher(-1)))
813 .Times(0);
814
815@@ -203,7 +204,7 @@
816 EXPECT_CALL(mock_ipc_msg, pack_fd(mtd::RawFdMatcher(native_buffer_handle->data[offset++])))
817 .Times(1);
818 }
819- EXPECT_CALL(mock_ipc_msg, pack_data(static_cast<int>(mga::BufferFlag::unfenced)));
820+ EXPECT_CALL(mock_ipc_msg, pack_flags(0));
821 for (auto i = 0u; i < num_ints; i++)
822 {
823 EXPECT_CALL(mock_ipc_msg, pack_data(native_buffer_handle->data[offset++]))
824@@ -238,11 +239,11 @@
825 mtd::MockBufferIpcMessage mock_ipc_msg;
826
827 Sequence seq;
828- EXPECT_CALL(mock_ipc_msg, pack_data(static_cast<int>(mga::BufferFlag::fenced)))
829+ EXPECT_CALL(mock_ipc_msg, pack_flags(mir_buffer_flag_fenced))
830 .InSequence(seq);
831 EXPECT_CALL(mock_ipc_msg, pack_fd(mtd::RawFdMatcher(fake_fence)))
832 .InSequence(seq);
833- EXPECT_CALL(mock_ipc_msg, pack_data(static_cast<int>(mga::BufferFlag::unfenced)))
834+ EXPECT_CALL(mock_ipc_msg, pack_flags(0))
835 .InSequence(seq);
836
837 EXPECT_CALL(*native_buffer, copy_fence())
838
839=== modified file 'tests/unit-tests/platforms/nested/CMakeLists.txt'
840--- tests/unit-tests/platforms/nested/CMakeLists.txt 2016-08-29 11:15:35 +0000
841+++ tests/unit-tests/platforms/nested/CMakeLists.txt 2016-09-27 19:07:08 +0000
842@@ -5,6 +5,7 @@
843 ${CMAKE_CURRENT_SOURCE_DIR}/test_nested_cursor.cpp
844 ${CMAKE_CURRENT_SOURCE_DIR}/test_buffer.cpp
845 ${CMAKE_CURRENT_SOURCE_DIR}/test_nested_display_buffer.cpp
846+ ${CMAKE_CURRENT_SOURCE_DIR}/test_ipc_operations.cpp
847 $<TARGET_OBJECTS:mir-test-doubles-udev>
848 ${MIR_PLATFORM_OBJECTS}
849 ${MIR_SERVER_OBJECTS}
850
851=== modified file 'tests/unit-tests/platforms/nested/test_buffer.cpp'
852--- tests/unit-tests/platforms/nested/test_buffer.cpp 2016-09-22 18:17:43 +0000
853+++ tests/unit-tests/platforms/nested/test_buffer.cpp 2016-09-27 19:07:08 +0000
854@@ -44,6 +44,7 @@
855 using namespace testing;
856 namespace
857 {
858+
859 struct MockNativeBuffer : mgn::NativeBuffer
860 {
861 MOCK_CONST_METHOD0(client_handle, MirBuffer*());
862@@ -52,6 +53,9 @@
863 MOCK_CONST_METHOD0(size, geom::Size());
864 MOCK_CONST_METHOD0(format, MirPixelFormat());
865 MOCK_METHOD2(sync, void(MirBufferAccess, std::chrono::nanoseconds));
866+ MOCK_CONST_METHOD0(package, MirBufferPackage*());
867+ MOCK_CONST_METHOD0(fence, mir::Fd());
868+ MOCK_METHOD1(set_fence, void(mir::Fd));
869 MOCK_CONST_METHOD0(egl_image_creation_hints, std::tuple<EGLenum, EGLClientBuffer, EGLint*>());
870 };
871
872@@ -203,7 +207,6 @@
873
874 EXPECT_CALL(mock_egl, eglGetCurrentDisplay());
875 EXPECT_CALL(mock_egl, eglGetCurrentContext());
876- EXPECT_CALL(mock_egl, eglCreateImageKHR(_,_,_,_,_));
877 EXPECT_CALL(*client_buffer, sync(mir_read, _));
878 EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, _));
879
880
881=== added file 'tests/unit-tests/platforms/nested/test_ipc_operations.cpp'
882--- tests/unit-tests/platforms/nested/test_ipc_operations.cpp 1970-01-01 00:00:00 +0000
883+++ tests/unit-tests/platforms/nested/test_ipc_operations.cpp 2016-09-27 19:07:08 +0000
884@@ -0,0 +1,199 @@
885+/*
886+ * Copyright © 2016 Canonical Ltd.
887+ *
888+ * This program is free software: you can redistribute it and/or modify
889+ * it under the terms of the GNU General Public License version 3 as
890+ * published by the Free Software Foundation.
891+ *
892+ * This program is distributed in the hope that it will be useful,
893+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
894+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
895+ * GNU General Public License for more details.
896+ *
897+ * You should have received a copy of the GNU General Public License
898+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
899+ *
900+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
901+ */
902+
903+#include "src/server/graphics/nested/ipc_operations.h"
904+#include "src/server/graphics/nested/native_buffer.h"
905+#include "mir/test/doubles/stub_buffer.h"
906+#include "mir/test/doubles/mock_buffer_ipc_message.h"
907+#include "mir/test/fake_shared.h"
908+#include "mir/graphics/platform_ipc_operations.h"
909+#include "mir/graphics/platform_operation_message.h"
910+#include "mir/graphics/buffer_ipc_message.h"
911+#include "mir/geometry/size.h"
912+#include <gtest/gtest.h>
913+#include <gmock/gmock.h>
914+
915+using namespace testing;
916+
917+namespace geom = mir::geometry;
918+namespace mg = mir::graphics;
919+namespace mgn = mir::graphics::nested;
920+namespace mt = mir::test;
921+namespace mtd = mir::test::doubles;
922+
923+namespace
924+{
925+struct ForeignBuffer : mg::NativeBuffer
926+{
927+};
928+
929+struct StubNestedBuffer : mgn::NativeBuffer
930+{
931+public:
932+ void sync(MirBufferAccess, std::chrono::nanoseconds) override {}
933+ MirBuffer* client_handle() const override { return nullptr; }
934+ MirNativeBuffer* get_native_handle() override { return nullptr; }
935+ MirGraphicsRegion get_graphics_region() override
936+ {
937+ return MirGraphicsRegion { 0, 0, 0, mir_pixel_format_invalid, nullptr };
938+ }
939+ geom::Size size() const override { return {}; }
940+ MirPixelFormat format() const override { return mir_pixel_format_invalid; }
941+ MirBufferPackage* package() const override { return nullptr; }
942+ mir::Fd fence() const override { return mir::Fd(); }
943+ void set_fence(mir::Fd) override {}
944+ std::tuple<EGLenum, EGLClientBuffer, EGLint*> egl_image_creation_hints() const override
945+ {
946+ return {};
947+ }
948+};
949+
950+struct MockNestedBuffer : StubNestedBuffer
951+{
952+ MOCK_CONST_METHOD0(package, MirBufferPackage*());
953+ MOCK_CONST_METHOD0(fence, mir::Fd());
954+ MOCK_METHOD1(set_fence, void(mir::Fd));
955+};
956+
957+struct MockIpcOperations : mg::PlatformIpcOperations
958+{
959+ MOCK_CONST_METHOD3(pack_buffer, void(mg::BufferIpcMessage&, mg::Buffer const&, mg::BufferIpcMsgType));
960+ MOCK_CONST_METHOD2(unpack_buffer, void(mg::BufferIpcMessage&, mg::Buffer const&));
961+ MOCK_METHOD0(connection_ipc_package, std::shared_ptr<mg::PlatformIPCPackage>());
962+ MOCK_METHOD2(platform_operation,
963+ mg::PlatformOperationMessage(unsigned int const, mg::PlatformOperationMessage const&));
964+};
965+
966+struct NestedIPCOperations : testing::Test
967+{
968+ NestedIPCOperations()
969+ {
970+ ON_CALL(mock_ops, connection_ipc_package())
971+ .WillByDefault(Return(nullptr));
972+ ON_CALL(mock_ops, platform_operation(_,_))
973+ .WillByDefault(Return(mg::PlatformOperationMessage{ {}, {} }));
974+ }
975+ mtd::StubBuffer foreign_buffer{std::make_shared<ForeignBuffer>()};
976+ mtd::StubBuffer nested_buffer{std::make_shared<MockNestedBuffer>()};
977+ MockIpcOperations mock_ops;
978+};
979+}
980+
981+TEST_F(NestedIPCOperations, uses_guest_platform_on_guest_buffers)
982+{
983+ mtd::MockBufferIpcMessage msg;
984+ EXPECT_CALL(mock_ops, pack_buffer(Ref(msg), Ref(foreign_buffer), _));
985+ mgn::IpcOperations operations(mt::fake_shared(mock_ops));
986+ operations.pack_buffer(msg, foreign_buffer, mg::BufferIpcMsgType::full_msg);
987+}
988+
989+TEST_F(NestedIPCOperations, packs_unfenced_buffer_itself_when_native)
990+{
991+ EXPECT_CALL(mock_ops, pack_buffer(_, _, _))
992+ .Times(0);
993+
994+ auto nested = std::make_shared<MockNestedBuffer>();
995+ mtd::StubBuffer nested_buffer{nested};
996+ mtd::MockBufferIpcMessage msg;
997+ mgn::IpcOperations operations(mt::fake_shared(mock_ops));
998+
999+ MirBufferPackage package;
1000+ package.data_items = 1;
1001+ package.data[0] = 11;
1002+ package.fd_items = 1;
1003+ package.fd[0] = 11222;
1004+ package.stride = 33;
1005+ package.width = 10;
1006+ package.height = 100;
1007+ package.flags = 0;
1008+
1009+ EXPECT_CALL(*nested, package())
1010+ .WillOnce(Return(&package));
1011+ EXPECT_CALL(*nested, fence())
1012+ .WillOnce(Return(mir::Fd(-1)));
1013+
1014+ EXPECT_CALL(msg, pack_data(package.data[0]));
1015+ EXPECT_CALL(msg, pack_fd(mir::Fd(mir::IntOwnedFd{package.fd[0]})));
1016+ EXPECT_CALL(msg, pack_flags(0));
1017+#ifndef __clang__
1018+ //(LP: #1609612)
1019+ EXPECT_CALL(msg, pack_stride(geom::Stride{package.stride}));
1020+#endif
1021+ operations.pack_buffer(msg, nested_buffer, mg::BufferIpcMsgType::full_msg);
1022+}
1023+
1024+TEST_F(NestedIPCOperations, packs_fenced_buffer_itself_when_native)
1025+{
1026+ EXPECT_CALL(mock_ops, pack_buffer(_, _, _))
1027+ .Times(0);
1028+
1029+ auto nested = std::make_shared<MockNestedBuffer>();
1030+ mtd::StubBuffer nested_buffer{nested};
1031+ mtd::MockBufferIpcMessage msg;
1032+ mgn::IpcOperations operations(mt::fake_shared(mock_ops));
1033+
1034+ MirBufferPackage package;
1035+ package.data_items = 0;
1036+ package.fd_items = 0;
1037+ package.flags = 0;
1038+
1039+ EXPECT_CALL(*nested, package())
1040+ .WillOnce(Return(&package));
1041+ EXPECT_CALL(*nested, fence())
1042+ .WillOnce(Return(mir::Fd(mir::IntOwnedFd{111})));
1043+ EXPECT_CALL(msg, pack_fd(mir::Fd(mir::IntOwnedFd{111})));
1044+ EXPECT_CALL(msg, pack_flags(mir_buffer_flag_fenced));
1045+ operations.pack_buffer(msg, nested_buffer, mg::BufferIpcMsgType::update_msg);
1046+}
1047+
1048+TEST_F(NestedIPCOperations, unpacks_fenced_buffer_itself_when_foreign)
1049+{
1050+ mtd::MockBufferIpcMessage msg;
1051+ EXPECT_CALL(mock_ops, unpack_buffer(Ref(msg), Ref(foreign_buffer)));
1052+ mgn::IpcOperations operations(mt::fake_shared(mock_ops));
1053+ operations.unpack_buffer(msg, foreign_buffer);
1054+}
1055+
1056+TEST_F(NestedIPCOperations, unpacks_fenced_buffer_itself_when_native)
1057+{
1058+ auto nested = std::make_shared<MockNestedBuffer>();
1059+ mtd::StubBuffer nested_buffer{nested};
1060+ mir::Fd fake(mir::IntOwnedFd{1111});
1061+ mtd::MockBufferIpcMessage msg;
1062+ EXPECT_CALL(msg, flags())
1063+ .WillOnce(Return(mir_buffer_flag_fenced));
1064+ EXPECT_CALL(msg, fds())
1065+ .WillOnce(Return( std::vector<mir::Fd>{fake} ));
1066+ EXPECT_CALL(*nested, set_fence(_));
1067+ mgn::IpcOperations operations(mt::fake_shared(mock_ops));
1068+ operations.unpack_buffer(msg, nested_buffer);
1069+}
1070+
1071+TEST_F(NestedIPCOperations, uses_guest_platform_for_connection_package)
1072+{
1073+ EXPECT_CALL(mock_ops, connection_ipc_package());
1074+ mgn::IpcOperations operations(mt::fake_shared(mock_ops));
1075+ operations.connection_ipc_package();
1076+}
1077+
1078+TEST_F(NestedIPCOperations, uses_guest_platform_for_platform_ops)
1079+{
1080+ EXPECT_CALL(mock_ops, platform_operation(_,_));
1081+ mgn::IpcOperations operations(mt::fake_shared(mock_ops));
1082+ operations.platform_operation(0, mg::PlatformOperationMessage{ {}, {} });
1083+}

Subscribers

People subscribed via source and target branches