Mir

Merge lp:~cemil-azizoglu/mir/use_egl_native_window into lp:mir

Proposed by Cemil Azizoglu
Status: Superseded
Proposed branch: lp:~cemil-azizoglu/mir/use_egl_native_window
Merge into: lp:mir
Diff against target: 649 lines (+210/-37)
24 files modified
.bzrignore (+1/-0)
src/include/client/mir/client_platform.h (+2/-1)
src/platforms/android/client/android_client_platform.cpp (+15/-4)
src/platforms/android/client/android_client_platform.h (+2/-1)
src/platforms/android/client/egl_native_surface_interpreter.h (+17/-0)
src/platforms/android/common/mir_native_window.cpp (+6/-0)
src/platforms/android/include/mir_native_window.h (+2/-1)
src/platforms/eglstream-kms/client/client_platform.cpp (+5/-1)
src/platforms/eglstream-kms/client/client_platform.h (+1/-0)
src/platforms/mesa/client/client_platform.cpp (+7/-1)
src/platforms/mesa/client/client_platform.h (+2/-1)
src/platforms/mesa/client/native_surface.cpp (+19/-5)
src/platforms/mesa/client/native_surface.h (+3/-2)
src/platforms/mesa/include/native_buffer.h (+2/-0)
tests/acceptance-tests/throwback/test_client_library_errors.cpp (+4/-0)
tests/include/mir_test_framework/stub_client_platform_factory.h (+1/-0)
tests/mir_test_framework/stub_client_platform_factory.cpp (+4/-0)
tests/unit-tests/client/test_client_buffer_stream.cpp (+3/-0)
tests/unit-tests/client/test_mir_connection.cpp (+1/-0)
tests/unit-tests/platforms/android/CMakeLists.txt (+5/-0)
tests/unit-tests/platforms/android/client/test_android_client_platform.cpp (+15/-0)
tests/unit-tests/platforms/android/client/test_android_native_window.cpp (+16/-0)
tests/unit-tests/platforms/mesa/client/test_client_platform.cpp (+14/-0)
tests/unit-tests/platforms/mesa/client/test_native_surface.cpp (+63/-20)
To merge this branch: bzr merge lp:~cemil-azizoglu/mir/use_egl_native_window
Reviewer Review Type Date Requested Status
Mir development team Pending
Review via email: mp+304291@code.launchpad.net

This proposal has been superseded by a proposal from 2016-09-02.

Description of the change

Introduce use_egl_native_window()

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2016-08-26 19:50:25 +0000
3+++ .bzrignore 2016-09-01 23:11:16 +0000
4@@ -1,3 +1,4 @@
5 .idea
6 .project
7 include/server/mir/version.h
8+build-*
9
10=== modified file 'src/include/client/mir/client_platform.h'
11--- src/include/client/mir/client_platform.h 2016-05-03 06:55:25 +0000
12+++ src/include/client/mir/client_platform.h 2016-09-01 23:11:16 +0000
13@@ -63,7 +63,8 @@
14 virtual std::shared_ptr<ClientBufferFactory> create_buffer_factory() = 0;
15 // EGLNativeWindowType differs between platforms, so can't reasonably be used in the
16 // platform-independent interface.
17- virtual std::shared_ptr<void> create_egl_native_window(EGLNativeSurface *surface) = 0;
18+ virtual std::shared_ptr<void> create_egl_native_window(EGLNativeSurface* surface) = 0;
19+ virtual void use_egl_native_window(std::shared_ptr<void> native_window, EGLNativeSurface* surface) = 0;
20 virtual std::shared_ptr<EGLNativeDisplayType> create_egl_native_display() = 0;
21 virtual MirNativeBuffer* convert_native_buffer(graphics::NativeBuffer*) const = 0;
22 virtual MirPixelFormat get_egl_pixel_format(EGLDisplay, EGLConfig) const = 0;
23
24=== modified file 'src/platforms/android/client/android_client_platform.cpp'
25--- src/platforms/android/client/android_client_platform.cpp 2016-07-20 04:54:07 +0000
26+++ src/platforms/android/client/android_client_platform.cpp 2016-09-01 23:11:16 +0000
27@@ -57,7 +57,13 @@
28 return std::make_shared<mcla::AndroidClientBufferFactory>(registrar);
29 }
30
31-std::shared_ptr<void> mcla::AndroidClientPlatform::create_egl_native_window(EGLNativeSurface *surface)
32+void mcla::AndroidClientPlatform::use_egl_native_window(std::shared_ptr<void> native_window, EGLNativeSurface* surface)
33+{
34+ auto anw = std::static_pointer_cast<mga::MirNativeWindow>(native_window);
35+ anw->use_native_surface(std::make_shared<mcla::EGLNativeSurfaceInterpreter>(*surface));
36+}
37+
38+std::shared_ptr<void> mcla::AndroidClientPlatform::create_egl_native_window(EGLNativeSurface* surface)
39 {
40 auto log = getenv("MIR_CLIENT_ANDROID_WINDOW_REPORT");
41 std::shared_ptr<mga::NativeWindowReport> report;
42@@ -67,9 +73,14 @@
43 std::make_shared<mir::logging::DumbConsoleLogger>());
44 else
45 report = std::make_shared<mga::NullNativeWindowReport>();
46-
47- return std::make_shared<mga::MirNativeWindow>(
48- std::make_shared<mcla::EGLNativeSurfaceInterpreter>(*surface), report);
49+
50+ std::shared_ptr<mga::AndroidDriverInterpreter> surface_interpreter;
51+ if (surface)
52+ surface_interpreter = std::make_shared<mcla::EGLNativeSurfaceInterpreter>(*surface);
53+ else
54+ surface_interpreter = std::make_shared<mcla::ErrorDriverInterpreter>();
55+
56+ return std::make_shared<mga::MirNativeWindow>(surface_interpreter, report);
57 }
58
59 std::shared_ptr<EGLNativeDisplayType>
60
61=== modified file 'src/platforms/android/client/android_client_platform.h'
62--- src/platforms/android/client/android_client_platform.h 2016-05-03 06:55:25 +0000
63+++ src/platforms/android/client/android_client_platform.h 2016-09-01 23:11:16 +0000
64@@ -37,7 +37,8 @@
65 void populate(MirPlatformPackage& package) const override;
66 MirPlatformMessage* platform_operation(MirPlatformMessage const* request) override;
67 std::shared_ptr<ClientBufferFactory> create_buffer_factory() override;
68- std::shared_ptr<void> create_egl_native_window(EGLNativeSurface *surface) override;
69+ std::shared_ptr<void> create_egl_native_window(EGLNativeSurface* surface) override;
70+ void use_egl_native_window(std::shared_ptr<void> native_window, EGLNativeSurface* surface) override;
71 std::shared_ptr<EGLNativeDisplayType> create_egl_native_display() override;
72 MirNativeBuffer* convert_native_buffer(graphics::NativeBuffer*) const override;
73 MirPixelFormat get_egl_pixel_format(EGLDisplay, EGLConfig) const override;
74
75=== modified file 'src/platforms/android/client/egl_native_surface_interpreter.h'
76--- src/platforms/android/client/egl_native_surface_interpreter.h 2016-01-29 08:18:22 +0000
77+++ src/platforms/android/client/egl_native_surface_interpreter.h 2016-09-01 23:11:16 +0000
78@@ -21,6 +21,7 @@
79
80 #include "android_driver_interpreter.h"
81 #include "mir/egl_native_surface.h"
82+#include <boost/throw_exception.hpp>
83
84 namespace mir
85 {
86@@ -36,6 +37,22 @@
87 namespace android
88 {
89
90+class ErrorDriverInterpreter : public graphics::android::AndroidDriverInterpreter
91+{
92+public:
93+#define THROW_EXCEPTION \
94+{ \
95+ BOOST_THROW_EXCEPTION(std::logic_error("error: use_egl_native_window(...) has not yet been called"));\
96+}
97+ graphics::NativeBuffer* driver_requests_buffer() override THROW_EXCEPTION
98+ void driver_returns_buffer(ANativeWindowBuffer*, int) override THROW_EXCEPTION
99+ void dispatch_driver_request_format(int) override THROW_EXCEPTION
100+ void dispatch_driver_request_buffer_count(unsigned int) override THROW_EXCEPTION
101+ int driver_requests_info(int) const override THROW_EXCEPTION
102+ void sync_to_display(bool) override THROW_EXCEPTION
103+#undef THROW_EXCEPTION
104+};
105+
106 class EGLNativeSurfaceInterpreter : public graphics::android::AndroidDriverInterpreter
107 {
108 public:
109
110=== modified file 'src/platforms/android/common/mir_native_window.cpp'
111--- src/platforms/android/common/mir_native_window.cpp 2016-07-20 04:54:07 +0000
112+++ src/platforms/android/common/mir_native_window.cpp 2016-09-01 23:11:16 +0000
113@@ -322,3 +322,9 @@
114 MIR_LOG_DRIVER_BOUNDARY_EXCEPTION(e);
115 return -1;
116 }
117+
118+void mga::MirNativeWindow::use_native_surface(
119+ std::shared_ptr<AndroidDriverInterpreter> const& interpreter)
120+{
121+ driver_interpreter = interpreter;
122+}
123
124=== modified file 'src/platforms/android/include/mir_native_window.h'
125--- src/platforms/android/include/mir_native_window.h 2016-07-20 04:54:07 +0000
126+++ src/platforms/android/include/mir_native_window.h 2016-09-01 23:11:16 +0000
127@@ -50,8 +50,9 @@
128 int cancelBuffer(struct ANativeWindowBuffer* buffer, int fence);
129 int cancelBufferDeprecated(struct ANativeWindowBuffer* buffer);
130 int setSwapInterval(int interval);
131+ void use_native_surface(std::shared_ptr<AndroidDriverInterpreter> const& interpreter);
132 private:
133- std::shared_ptr<AndroidDriverInterpreter> const driver_interpreter;
134+ std::shared_ptr<AndroidDriverInterpreter> driver_interpreter;
135 std::shared_ptr<NativeWindowReport> const report;
136 std::shared_ptr<SyncFileOps> const sync_ops;
137 std::vector<struct ANativeWindowBuffer*> cancelled_buffers;
138
139=== modified file 'src/platforms/eglstream-kms/client/client_platform.cpp'
140--- src/platforms/eglstream-kms/client/client_platform.cpp 2016-08-03 12:27:57 +0000
141+++ src/platforms/eglstream-kms/client/client_platform.cpp 2016-09-01 23:11:16 +0000
142@@ -39,7 +39,11 @@
143 return std::make_shared<mcle::ClientBufferFactory>();
144 }
145
146-std::shared_ptr<void> mcle::ClientPlatform::create_egl_native_window(EGLNativeSurface* /*client_surface*/)
147+void mcle::ClientPlatform::use_egl_native_window(std::shared_ptr<void> /*native_window*/, EGLNativeSurface* /*surface*/)
148+{
149+}
150+
151+std::shared_ptr<void> mcle::ClientPlatform::create_egl_native_window(EGLNativeSurface* /*surface*/)
152 {
153 return nullptr;
154 }
155
156=== modified file 'src/platforms/eglstream-kms/client/client_platform.h'
157--- src/platforms/eglstream-kms/client/client_platform.h 2016-08-03 06:48:47 +0000
158+++ src/platforms/eglstream-kms/client/client_platform.h 2016-09-01 23:11:16 +0000
159@@ -37,6 +37,7 @@
160 MirPlatformMessage* platform_operation(MirPlatformMessage const* request) override;
161 std::shared_ptr<ClientBufferFactory> create_buffer_factory() override;
162 std::shared_ptr<void> create_egl_native_window(EGLNativeSurface *surface) override;
163+ void use_egl_native_window(std::shared_ptr<void> native_window, EGLNativeSurface* surface) override;
164 std::shared_ptr<EGLNativeDisplayType> create_egl_native_display() override;
165 MirNativeBuffer* convert_native_buffer(graphics::NativeBuffer*) const override;
166 MirPixelFormat get_egl_pixel_format(EGLDisplay, EGLConfig) const override;
167
168=== modified file 'src/platforms/mesa/client/client_platform.cpp'
169--- src/platforms/mesa/client/client_platform.cpp 2016-08-26 19:50:25 +0000
170+++ src/platforms/mesa/client/client_platform.cpp 2016-09-01 23:11:16 +0000
171@@ -74,9 +74,15 @@
172 return std::make_shared<mclm::ClientBufferFactory>(buffer_file_ops);
173 }
174
175+void mclm::ClientPlatform::use_egl_native_window(std::shared_ptr<void> native_window, EGLNativeSurface* surface)
176+{
177+ auto mnw = std::static_pointer_cast<NativeSurface>(native_window);
178+ mnw->use_native_surface(surface);
179+}
180+
181 std::shared_ptr<void> mclm::ClientPlatform::create_egl_native_window(EGLNativeSurface* client_surface)
182 {
183- return std::make_shared<NativeSurface>(*client_surface);
184+ return std::make_shared<NativeSurface>(client_surface);
185 }
186
187 std::shared_ptr<EGLNativeDisplayType> mclm::ClientPlatform::create_egl_native_display()
188
189=== modified file 'src/platforms/mesa/client/client_platform.h'
190--- src/platforms/mesa/client/client_platform.h 2016-05-03 06:55:25 +0000
191+++ src/platforms/mesa/client/client_platform.h 2016-09-01 23:11:16 +0000
192@@ -45,7 +45,8 @@
193 void populate(MirPlatformPackage& package) const override;
194 MirPlatformMessage* platform_operation(MirPlatformMessage const* request) override;
195 std::shared_ptr<ClientBufferFactory> create_buffer_factory() override;
196- std::shared_ptr<void> create_egl_native_window(EGLNativeSurface *surface) override;
197+ std::shared_ptr<void> create_egl_native_window(EGLNativeSurface* surface) override;
198+ void use_egl_native_window(std::shared_ptr<void> native_window, EGLNativeSurface* surface) override;
199 std::shared_ptr<EGLNativeDisplayType> create_egl_native_display() override;
200 MirNativeBuffer* convert_native_buffer(graphics::NativeBuffer*) const override;
201 MirPixelFormat get_egl_pixel_format(EGLDisplay, EGLConfig) const override;
202
203=== modified file 'src/platforms/mesa/client/native_surface.cpp'
204--- src/platforms/mesa/client/native_surface.cpp 2015-04-28 07:54:10 +0000
205+++ src/platforms/mesa/client/native_surface.cpp 2016-09-01 23:11:16 +0000
206@@ -27,6 +27,10 @@
207
208 namespace mclm=mir::client::mesa;
209
210+#define THROW_IF_NULL(s) \
211+ if (!(s)) \
212+ throw std::logic_error("error: use_egl_native_window(...) has not yet been called");
213+
214 namespace
215 {
216 static int advance_buffer_static(MirMesaEGLNativeSurface* surface,
217@@ -50,7 +54,7 @@
218 }
219 }
220
221-mclm::NativeSurface::NativeSurface(EGLNativeSurface& surface)
222+mclm::NativeSurface::NativeSurface(EGLNativeSurface* surface)
223 : starting(true), surface(surface)
224 {
225 surface_advance_buffer = advance_buffer_static;
226@@ -61,6 +65,8 @@
227 int mclm::NativeSurface::advance_buffer(MirBufferPackage* buffer_package)
228 try
229 {
230+ THROW_IF_NULL(surface);
231+
232 /*
233 * At present dri2_create_mir_window_surface will trigger
234 * mir_advance_colour_buffer which will land here. Since we're still
235@@ -70,9 +76,9 @@
236 if (starting)
237 starting = false;
238 else
239- surface.request_and_wait_for_next_buffer();
240+ surface->request_and_wait_for_next_buffer();
241
242- auto buffer = surface.get_current_buffer();
243+ auto buffer = surface->get_current_buffer();
244
245 auto buffer_to_driver = buffer->native_buffer_handle();
246 memcpy(buffer_package, buffer_to_driver.get(), sizeof(MirBufferPackage));
247@@ -87,7 +93,8 @@
248 int mclm::NativeSurface::get_parameters(MirSurfaceParameters* surface_parameters)
249 try
250 {
251- auto params = surface.get_parameters();
252+ THROW_IF_NULL(surface);
253+ auto params = surface->get_parameters();
254 memcpy(surface_parameters, &params, sizeof(MirSurfaceParameters));
255 return MIR_MESA_TRUE;
256 }
257@@ -100,10 +107,12 @@
258 int mclm::NativeSurface::set_swapinterval(int interval)
259 try
260 {
261+ THROW_IF_NULL(surface);
262+
263 if ((interval < 0) || (interval > 1))
264 return MIR_MESA_FALSE;
265
266- surface.request_and_wait_for_configure(mir_surface_attrib_swapinterval, interval);
267+ surface->request_and_wait_for_configure(mir_surface_attrib_swapinterval, interval);
268 return MIR_MESA_TRUE;
269 }
270 catch (std::exception const& e)
271@@ -111,3 +120,8 @@
272 MIR_LOG_DRIVER_BOUNDARY_EXCEPTION(e);
273 return MIR_MESA_FALSE;
274 }
275+
276+void mclm::NativeSurface::use_native_surface(EGLNativeSurface* native_surface)
277+{
278+ surface = native_surface;
279+}
280
281=== modified file 'src/platforms/mesa/client/native_surface.h'
282--- src/platforms/mesa/client/native_surface.h 2015-04-28 07:54:10 +0000
283+++ src/platforms/mesa/client/native_surface.h 2016-09-01 23:11:16 +0000
284@@ -32,15 +32,16 @@
285 class NativeSurface : public MirMesaEGLNativeSurface
286 {
287 public:
288- explicit NativeSurface(EGLNativeSurface&);
289+ explicit NativeSurface(EGLNativeSurface*);
290
291 int advance_buffer(MirBufferPackage* buffer_package);
292 int get_parameters(MirSurfaceParameters* surface_parameters);
293 int set_swapinterval(int interval);
294+ void use_native_surface(EGLNativeSurface* native_surface);
295
296 private:
297 bool starting;
298- EGLNativeSurface& surface;
299+ EGLNativeSurface* surface;
300 };
301
302 }
303
304=== modified file 'src/platforms/mesa/include/native_buffer.h'
305--- src/platforms/mesa/include/native_buffer.h 2016-08-03 18:07:27 +0000
306+++ src/platforms/mesa/include/native_buffer.h 2016-09-01 23:11:16 +0000
307@@ -20,6 +20,8 @@
308 #define MIR_GRAPHICS_MESA_NATIVE_BUFFER_H_
309
310 #include <mir_toolkit/mir_native_buffer.h>
311+
312+#include <stdlib.h>
313 #include <gbm.h>
314
315 namespace mir
316
317=== modified file 'tests/acceptance-tests/throwback/test_client_library_errors.cpp'
318--- tests/acceptance-tests/throwback/test_client_library_errors.cpp 2016-08-25 01:11:51 +0000
319+++ tests/acceptance-tests/throwback/test_client_library_errors.cpp 2016-09-01 23:11:16 +0000
320@@ -78,6 +78,10 @@
321 dummy_client_module.load_function<mcl::CreateClientPlatform>("create_client_platform")(context);
322 }
323
324+ void use_egl_native_window(std::shared_ptr<void> /*native_window*/, mir::client::EGLNativeSurface* /*surface*/) override
325+ {
326+ }
327+
328 std::shared_ptr<void> create_egl_native_window(mir::client::EGLNativeSurface *surface) override
329 {
330 if (should_fail<Method::create_egl_native_window, failure_set>())
331
332=== modified file 'tests/include/mir_test_framework/stub_client_platform_factory.h'
333--- tests/include/mir_test_framework/stub_client_platform_factory.h 2016-08-12 18:41:22 +0000
334+++ tests/include/mir_test_framework/stub_client_platform_factory.h 2016-09-01 23:11:16 +0000
335@@ -33,6 +33,7 @@
336 void populate(MirPlatformPackage& package) const override;
337 MirPlatformMessage* platform_operation(MirPlatformMessage const*) override;
338 std::shared_ptr<mir::client::ClientBufferFactory> create_buffer_factory() override;
339+ void use_egl_native_window(std::shared_ptr<void> native_window, mir::client::EGLNativeSurface* surface) override;
340 std::shared_ptr<void> create_egl_native_window(mir::client::EGLNativeSurface* surface) override;
341 std::shared_ptr<EGLNativeDisplayType> create_egl_native_display() override;
342 MirNativeBuffer* convert_native_buffer(mir::graphics::NativeBuffer* buf) const override;
343
344=== modified file 'tests/mir_test_framework/stub_client_platform_factory.cpp'
345--- tests/mir_test_framework/stub_client_platform_factory.cpp 2016-08-09 13:40:44 +0000
346+++ tests/mir_test_framework/stub_client_platform_factory.cpp 2016-09-01 23:11:16 +0000
347@@ -71,6 +71,10 @@
348 return std::make_shared<StubPlatformBufferFactory>();
349 }
350
351+void mtf::StubClientPlatform::use_egl_native_window(std::shared_ptr<void> /*native_window*/, mir::client::EGLNativeSurface* /*surface*/)
352+{
353+}
354+
355 std::shared_ptr<void> mtf::StubClientPlatform::create_egl_native_window(mir::client::EGLNativeSurface* surface)
356 {
357 return std::shared_ptr<void>{surface, [](void*){}};
358
359=== modified file 'tests/unit-tests/client/test_client_buffer_stream.cpp'
360--- tests/unit-tests/client/test_client_buffer_stream.cpp 2016-08-10 10:43:39 +0000
361+++ tests/unit-tests/client/test_client_buffer_stream.cpp 2016-09-01 23:11:16 +0000
362@@ -71,6 +71,9 @@
363 void populate(MirPlatformPackage& /* package */) const override
364 {
365 }
366+ void use_egl_native_window(std::shared_ptr<void> /*native_window*/, mcl::EGLNativeSurface* /*surface*/) override
367+ {
368+ }
369 std::shared_ptr<void> create_egl_native_window(mcl::EGLNativeSurface * /* surface */) override
370 {
371 return mt::fake_shared(egl_native_window);
372
373=== modified file 'tests/unit-tests/client/test_mir_connection.cpp'
374--- tests/unit-tests/client/test_mir_connection.cpp 2016-06-28 12:18:18 +0000
375+++ tests/unit-tests/client/test_mir_connection.cpp 2016-09-01 23:11:16 +0000
376@@ -206,6 +206,7 @@
377 MOCK_CONST_METHOD0(platform_type, MirPlatformType());
378 MOCK_METHOD1(platform_operation, MirPlatformMessage*(MirPlatformMessage const*));
379 MOCK_METHOD0(create_buffer_factory, std::shared_ptr<mcl::ClientBufferFactory>());
380+ MOCK_METHOD2(use_egl_native_window, void(std::shared_ptr<void>, mcl::EGLNativeSurface*));
381 MOCK_METHOD1(create_egl_native_window, std::shared_ptr<void>(mcl::EGLNativeSurface*));
382 MOCK_METHOD0(create_egl_native_display, std::shared_ptr<EGLNativeDisplayType>());
383 MOCK_CONST_METHOD2(get_egl_pixel_format,
384
385=== modified file 'tests/unit-tests/platforms/android/CMakeLists.txt'
386--- tests/unit-tests/platforms/android/CMakeLists.txt 2016-08-05 15:32:58 +0000
387+++ tests/unit-tests/platforms/android/CMakeLists.txt 2016-09-01 23:11:16 +0000
388@@ -4,6 +4,11 @@
389 ${ANDROID_HEADERS_INCLUDE_DIRS}
390 ${PROJECT_SOURCE_DIR}/src/platforms/android/include
391 )
392+
393+set(
394+ ANDROID_UNIT_TEST_SOURCES
395+)
396+
397 add_subdirectory("server")
398 add_subdirectory("client")
399
400
401=== modified file 'tests/unit-tests/platforms/android/client/test_android_client_platform.cpp'
402--- tests/unit-tests/platforms/android/client/test_android_client_platform.cpp 2016-01-29 08:18:22 +0000
403+++ tests/unit-tests/platforms/android/client/test_android_client_platform.cpp 2016-09-01 23:11:16 +0000
404@@ -16,6 +16,7 @@
405 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
406 */
407
408+#include "mir_native_window.h"
409 #include "mir/client_platform.h"
410 #include "mir/test/doubles/mock_client_context.h"
411 #include "mir/test/doubles/mock_egl_native_surface.h"
412@@ -59,6 +60,20 @@
413 EXPECT_NE(nullptr, egl_native_window);
414 }
415
416+TEST_F(AndroidClientPlatformTest, egl_native_window_can_be_set_with_null_native_surface)
417+{
418+ auto egl_native_window = platform->create_egl_native_window(nullptr);
419+ EXPECT_NE(nullptr, egl_native_window);
420+}
421+
422+TEST_F(AndroidClientPlatformTest, error_interpreter_used_with_null_native_surface)
423+{
424+ auto egl_native_window = platform->create_egl_native_window(nullptr);
425+ auto native_window = reinterpret_cast<mir::graphics::android::MirNativeWindow*>(egl_native_window.get());
426+ ANativeWindow& window = *native_window;
427+ EXPECT_EQ(window.setSwapInterval(&window, 1), -1);
428+}
429+
430 TEST_F(AndroidClientPlatformTest, egl_pixel_format_asks_the_driver)
431 {
432 auto const d = reinterpret_cast<EGLDisplay>(0x1234);
433
434=== modified file 'tests/unit-tests/platforms/android/client/test_android_native_window.cpp'
435--- tests/unit-tests/platforms/android/client/test_android_native_window.cpp 2016-08-24 02:09:08 +0000
436+++ tests/unit-tests/platforms/android/client/test_android_native_window.cpp 2016-09-01 23:11:16 +0000
437@@ -73,6 +73,22 @@
438
439 }
440
441+TEST_F(AndroidNativeWindowTest, use_native_surface_call_replaces_existing_interpreter)
442+{
443+ std::shared_ptr<MockAndroidDriverInterpreter> const new_driver_interpreter =
444+ std::make_shared<NiceMock<MockAndroidDriverInterpreter>>();
445+
446+ // Test that the call goes to the new interpreter instead of the old one
447+ EXPECT_CALL(*mock_driver_interpreter, sync_to_display(true))
448+ .Times(0);
449+
450+ EXPECT_CALL(*new_driver_interpreter, sync_to_display(true))
451+ .Times(1);
452+
453+ mir_native_window.use_native_surface(new_driver_interpreter);
454+ window.setSwapInterval(&window, 1);
455+}
456+
457 TEST_F(AndroidNativeWindowTest, native_window_swapinterval)
458 {
459 ASSERT_NE(nullptr, window.setSwapInterval);
460
461=== modified file 'tests/unit-tests/platforms/mesa/client/test_client_platform.cpp'
462--- tests/unit-tests/platforms/mesa/client/test_client_platform.cpp 2016-05-26 03:59:12 +0000
463+++ tests/unit-tests/platforms/mesa/client/test_client_platform.cpp 2016-09-01 23:11:16 +0000
464@@ -22,6 +22,7 @@
465 #include "src/platforms/mesa/client/mesa_native_display_container.h"
466 #include "mir_test_framework/client_platform_factory.h"
467 #include "mir/test/doubles/mock_egl.h"
468+#include "mir/test/doubles/mock_egl_native_surface.h"
469
470 #include "mir_toolkit/mir_client_library.h"
471 #include "mir_toolkit/mesa/native_display.h"
472@@ -155,3 +156,16 @@
473 EXPECT_EQ(mir_pixel_format_xrgb_8888, platform->get_egl_pixel_format(d, c));
474 EXPECT_EQ(mir_pixel_format_invalid, platform->get_egl_pixel_format(d, c));
475 }
476+
477+TEST_F(MesaClientPlatformTest, egl_native_window_is_set)
478+{
479+ testing::NiceMock<mtd::MockEGLNativeSurface> mock_surface;
480+ auto egl_native_window = platform->create_egl_native_window(&mock_surface);
481+ EXPECT_NE(nullptr, egl_native_window);
482+}
483+
484+TEST_F(MesaClientPlatformTest, egl_native_window_can_be_set_with_null_native_surface)
485+{
486+ auto egl_native_window = platform->create_egl_native_window(nullptr);
487+ EXPECT_NE(nullptr, egl_native_window);
488+}
489
490=== modified file 'tests/unit-tests/platforms/mesa/client/test_native_surface.cpp'
491--- tests/unit-tests/platforms/mesa/client/test_native_surface.cpp 2016-05-03 06:55:25 +0000
492+++ tests/unit-tests/platforms/mesa/client/test_native_surface.cpp 2016-09-01 23:11:16 +0000
493@@ -16,18 +16,20 @@
494 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
495 */
496
497+#include "src/platforms/mesa/include/native_buffer.h"
498 #include "src/platforms/mesa/client/native_surface.h"
499 #include "mir/client_buffer.h"
500 #include "mir/test/doubles/mock_egl_native_surface.h"
501 #include "mir/test/doubles/mock_client_buffer.h"
502-
503+#include "mir/test/fake_shared.h"
504 #include <gmock/gmock.h>
505 #include <gtest/gtest.h>
506
507-namespace mtd=mir::test::doubles;
508-namespace mcl=mir::client;
509-namespace mcl=mir::client;
510-namespace mclg=mir::client::mesa;
511+namespace mt=mir::test;
512+namespace mtd=mt::doubles;
513+namespace mcl=mir::client;
514+namespace mg=mir::graphics;
515+namespace mclg=mcl::mesa;
516 namespace geom=mir::geometry;
517
518 class MesaClientNativeSurfaceTest : public ::testing::Test
519@@ -44,18 +46,24 @@
520 .WillByDefault(Return(surf_params));
521 ON_CALL(mock_surface, get_current_buffer())
522 .WillByDefault(Return(
523- std::make_shared<NiceMock<mtd::MockClientBuffer>>()));
524+ mt::fake_shared(mock_buffer)));
525+ ON_CALL(mock_buffer, native_buffer_handle())
526+ .WillByDefault(Return(
527+ mt::fake_shared(native_buffer)));
528 }
529
530 MirSurfaceParameters surf_params;
531+ const char* error_msg = "thrown as part of test";
532+ mg::NativeBuffer native_buffer;
533+ testing::NiceMock<mtd::MockClientBuffer> mock_buffer;
534 testing::NiceMock<mtd::MockEGLNativeSurface> mock_surface;
535- mclg::NativeSurface native_surface{mock_surface};
536+ mclg::NativeSurface native_surface{&mock_surface};
537 };
538
539 TEST_F(MesaClientNativeSurfaceTest, basic_parameters)
540 {
541 MirSurfaceParameters params;
542- native_surface.surface_get_parameters(&native_surface, &params);
543+ EXPECT_EQ(MIR_MESA_TRUE, native_surface.surface_get_parameters(&native_surface, &params));
544 EXPECT_EQ(surf_params.width, params.width);
545 EXPECT_EQ(surf_params.height, params.height);
546 EXPECT_EQ(surf_params.pixel_format, params.pixel_format);
547@@ -72,7 +80,7 @@
548 EXPECT_CALL(mock_surface, get_current_buffer())
549 .Times(1);
550
551- native_surface.surface_advance_buffer(&native_surface, &buffer_package);
552+ EXPECT_EQ(MIR_MESA_TRUE, native_surface.surface_advance_buffer(&native_surface, &buffer_package));
553 }
554
555 TEST_F(MesaClientNativeSurfaceTest, basic_advance)
556@@ -88,8 +96,8 @@
557 EXPECT_CALL(mock_surface, get_current_buffer())
558 .Times(1);
559
560- native_surface.surface_advance_buffer(&native_surface, &buffer_package);
561- native_surface.surface_advance_buffer(&native_surface, &buffer_package);
562+ EXPECT_EQ(MIR_MESA_TRUE, native_surface.surface_advance_buffer(&native_surface, &buffer_package));
563+ EXPECT_EQ(MIR_MESA_TRUE, native_surface.surface_advance_buffer(&native_surface, &buffer_package));
564 }
565
566 TEST_F(MesaClientNativeSurfaceTest, swapinterval_request)
567@@ -102,8 +110,8 @@
568 EXPECT_CALL(mock_surface, request_and_wait_for_configure(mir_surface_attrib_swapinterval,1))
569 .InSequence(seq);
570
571- native_surface.set_swapinterval(0);
572- native_surface.set_swapinterval(1);
573+ EXPECT_EQ(MIR_MESA_TRUE, native_surface.set_swapinterval(0));
574+ EXPECT_EQ(MIR_MESA_TRUE, native_surface.set_swapinterval(1));
575 }
576
577 TEST_F(MesaClientNativeSurfaceTest, swapinterval_unsupported_request)
578@@ -119,10 +127,10 @@
579 using namespace testing;
580
581 EXPECT_CALL(mock_surface, get_current_buffer())
582- .WillOnce(Throw(std::runtime_error("")));
583+ .WillOnce(Throw(std::runtime_error(error_msg)));
584
585 MirBufferPackage buffer_package;
586- EXPECT_THAT(native_surface.advance_buffer(&buffer_package), Eq(MIR_MESA_FALSE));
587+ EXPECT_EQ(MIR_MESA_FALSE, native_surface.advance_buffer(&buffer_package));
588 }
589
590 TEST_F(MesaClientNativeSurfaceTest, returns_error_on_get_parameters_failure)
591@@ -130,10 +138,10 @@
592 using namespace testing;
593
594 EXPECT_CALL(mock_surface, get_parameters())
595- .WillOnce(Throw(std::runtime_error("")));
596+ .WillOnce(Throw(std::runtime_error(error_msg)));
597
598 MirSurfaceParameters surface_params;
599- EXPECT_THAT(native_surface.get_parameters(&surface_params), Eq(MIR_MESA_FALSE));
600+ EXPECT_EQ(MIR_MESA_FALSE, native_surface.get_parameters(&surface_params));
601 }
602
603 TEST_F(MesaClientNativeSurfaceTest, returns_error_on_set_swap_interval_failure)
604@@ -141,7 +149,42 @@
605 using namespace testing;
606
607 EXPECT_CALL(mock_surface, request_and_wait_for_configure(_,_))
608- .WillOnce(Throw(std::runtime_error("")));
609-
610- EXPECT_THAT(native_surface.set_swapinterval(0), Eq(MIR_MESA_FALSE));
611+ .WillOnce(Throw(std::runtime_error(error_msg)));
612+
613+ EXPECT_EQ(MIR_MESA_FALSE, native_surface.set_swapinterval(0));
614+}
615+
616+TEST_F(MesaClientNativeSurfaceTest, null_native_surface_returns_error)
617+{
618+ using namespace testing;
619+
620+ MirSurfaceParameters params;
621+ MirBufferPackage buffer_package;
622+
623+ mclg::NativeSurface null_native_surface{nullptr};
624+
625+ EXPECT_EQ(MIR_MESA_FALSE,
626+ null_native_surface.surface_get_parameters(&null_native_surface, &params));
627+ EXPECT_EQ(MIR_MESA_FALSE,
628+ null_native_surface.surface_advance_buffer(&null_native_surface, &buffer_package));
629+ EXPECT_EQ(MIR_MESA_FALSE,
630+ null_native_surface.surface_set_swapinterval(&null_native_surface, 1));
631+}
632+
633+TEST_F(MesaClientNativeSurfaceTest, native_surface_after_null_returns_success)
634+{
635+ using namespace testing;
636+
637+ MirSurfaceParameters params;
638+ MirBufferPackage buffer_package;
639+
640+ mclg::NativeSurface native_surface{nullptr};
641+
642+ native_surface.use_native_surface(&mock_surface);
643+ EXPECT_EQ(MIR_MESA_TRUE,
644+ native_surface.surface_get_parameters(&native_surface, &params));
645+ EXPECT_EQ(MIR_MESA_TRUE,
646+ native_surface.surface_advance_buffer(&native_surface, &buffer_package));
647+ EXPECT_EQ(MIR_MESA_TRUE,
648+ native_surface.surface_set_swapinterval(&native_surface, 1));
649 }

Subscribers

People subscribed via source and target branches