Mir

Merge lp:~raof/mir/gbm-cleanup-extra into lp:~mir-team/mir/trunk

Proposed by Chris Halse Rogers
Status: Merged
Approved by: Chris Halse Rogers
Approved revision: no longer in the source branch.
Merged at revision: 749
Proposed branch: lp:~raof/mir/gbm-cleanup-extra
Merge into: lp:~mir-team/mir/trunk
Diff against target: 1186 lines (+635/-227)
24 files modified
CMakeLists.txt (+1/-1)
debian/changelog (+6/-0)
debian/control (+2/-2)
include/shared/mir_toolkit/mesa/native_display.h (+14/-18)
src/client/CMakeLists.txt (+2/-1)
src/client/gbm/gbm_client_platform.cpp (+25/-3)
src/client/gbm/gbm_native_surface.cpp (+78/-0)
src/client/gbm/gbm_native_surface.h (+42/-0)
src/client/gbm/mesa_native_display_container.cpp (+4/-39)
src/server/graphics/gbm/CMakeLists.txt (+1/-0)
src/server/graphics/gbm/internal_client.cpp (+6/-1)
src/server/graphics/gbm/internal_client.h (+2/-0)
src/server/graphics/gbm/internal_native_display.cpp (+4/-36)
src/server/graphics/gbm/internal_native_display.h (+2/-10)
src/server/graphics/gbm/internal_native_surface.cpp (+77/-0)
src/server/graphics/gbm/internal_native_surface.h (+62/-0)
tests/unit-tests/client/gbm/CMakeLists.txt (+1/-0)
tests/unit-tests/client/gbm/test_gbm_client_platform.cpp (+0/-11)
tests/unit-tests/client/gbm/test_native_surface.cpp (+114/-0)
tests/unit-tests/graphics/android/test_internal_client_interpreter.cpp (+6/-0)
tests/unit-tests/graphics/gbm/CMakeLists.txt (+1/-0)
tests/unit-tests/graphics/gbm/test_internal_client.cpp (+15/-5)
tests/unit-tests/graphics/gbm/test_internal_native_display.cpp (+0/-100)
tests/unit-tests/graphics/gbm/test_internal_native_surface.cpp (+170/-0)
To merge this branch: bzr merge lp:~raof/mir/gbm-cleanup-extra
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Robert Ancell Approve
Review via email: mp+169972@code.launchpad.net

Commit message

Add hooks for eglSwapInterval in the gbm platform.

Split the mesa EGLMesaNativeDisplay into an EGLMesaNativeDisplay and an EGLMesaNativeSurface

Description of the change

Just a trivial extra commit on top of Kevin's MP:

we need some hooks in the driver to get eglSwapInterval(dpy,0); to work on the gbm platform (android already has these hooks). Since its disruptive to bump the driver, I did a cleanup of the interface that mesa uses to get buffers from us; we now have both an EGLNativeDisplayType and an EGLNativeSurface type, and the upstream version of the drivers we maintain is now (probably) upstreamable.

the patch for mesa has landed to (https://github.com/RAOF/mesa.git), we should bump the package in the archives to the latest version at about the same time this lands. I'll coordinate with RAOF to minimize disruption.

To post a comment you must log in.
Revision history for this message
Robert Ancell (robert-ancell) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2013-05-16 16:53:01 +0000
3+++ CMakeLists.txt 2013-06-18 03:30:36 +0000
4@@ -28,7 +28,7 @@
5
6 set(MIR_VERSION_MAJOR 0)
7 set(MIR_VERSION_MINOR 0)
8-set(MIR_VERSION_PATCH 3)
9+set(MIR_VERSION_PATCH 4)
10
11 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
12
13
14=== modified file 'debian/changelog'
15--- debian/changelog 2013-05-15 00:37:34 +0000
16+++ debian/changelog 2013-06-18 03:30:36 +0000
17@@ -1,3 +1,9 @@
18+mir (0.0.4-0ubuntu1) raring; urgency=low
19+
20+ * change mesa header to clean up the file and add swapinterval 0 hook
21+
22+ -- Kevin DuBois <kevin.dubois@canonical.com> Mon, 17 Jun 2013 18:02:32 -0700
23+
24 mir (0.0.3-0ubuntu1) raring; urgency=low
25
26 [ Bryce Harrington ]
27
28=== modified file 'debian/control'
29--- debian/control 2013-06-06 16:38:10 +0000
30+++ debian/control 2013-06-18 03:30:36 +0000
31@@ -89,7 +89,7 @@
32 .
33 Contains header files required to build Mir servers.
34
35-Package: libmirclient0
36+Package: libmirclient1
37 Section: libs
38 Architecture: any
39 Depends: ${misc:Depends},
40@@ -103,7 +103,7 @@
41 Package: libmirclient-dev
42 Section: libdevel
43 Architecture: any
44-Depends: libmirclient0 (= ${binary:Version}),
45+Depends: libmirclient1 (= ${binary:Version}),
46 libmirprotobuf-dev (= ${source:Version}),
47 mircommon-dev (= ${source:Version}),
48 ${misc:Depends},
49
50=== renamed file 'debian/libmirclient0.install' => 'debian/libmirclient1.install'
51=== modified file 'include/shared/mir_toolkit/mesa/native_display.h'
52--- include/shared/mir_toolkit/mesa/native_display.h 2013-05-08 18:57:03 +0000
53+++ include/shared/mir_toolkit/mesa/native_display.h 2013-06-18 03:30:36 +0000
54@@ -21,6 +21,9 @@
55 #include "mir_toolkit/mir_native_buffer.h"
56 #include "mir_toolkit/client_types.h"
57
58+#define MIR_MESA_TRUE 1
59+#define MIR_MESA_FALSE 0
60+
61 #ifdef __cplusplus
62 /**
63 * \addtogroup mir_toolkit
64@@ -31,31 +34,24 @@
65 #endif
66
67 typedef struct MirMesaEGLNativeDisplay MirMesaEGLNativeDisplay;
68+typedef struct MirMesaEGLNativeSurface MirMesaEGLNativeSurface;
69
70 struct MirMesaEGLNativeDisplay
71 {
72- void (*display_get_platform)(MirMesaEGLNativeDisplay* display,
73+ int (*display_get_platform)(MirMesaEGLNativeDisplay* display,
74 MirPlatformPackage* package);
75- void (*surface_get_current_buffer)(MirMesaEGLNativeDisplay* display,
76- MirEGLNativeWindowType surface,
77- MirBufferPackage* buffer_package);
78- void (*surface_get_parameters)(MirMesaEGLNativeDisplay* display,
79- MirEGLNativeWindowType surface,
80+ void *context;
81+};
82+
83+struct MirMesaEGLNativeSurface
84+{
85+ int (*surface_set_swapinterval)(MirMesaEGLNativeSurface* surface, int interval);
86+ int (*surface_advance_buffer)(MirMesaEGLNativeSurface* surface,
87+ MirBufferPackage* buffer_package);
88+ int (*surface_get_parameters)(MirMesaEGLNativeSurface* surface,
89 MirSurfaceParameters* surface_parameters);
90- void (*surface_advance_buffer)(MirMesaEGLNativeDisplay* display,
91- MirEGLNativeWindowType surface);
92-
93- void *context;
94 };
95
96-typedef enum mir_display_type
97-{
98- MIR_DISPLAY_TYPE_CLIENT,
99- MIR_DISPLAY_TYPE_SERVER_INTERNAL
100-} mir_display_type;
101-
102-mir_display_type mir_get_display_type(MirMesaEGLNativeDisplay* display);
103-
104 int mir_egl_mesa_display_is_valid(MirMesaEGLNativeDisplay* display);
105 int mir_server_internal_display_is_valid(MirMesaEGLNativeDisplay* display);
106
107
108=== modified file 'src/client/CMakeLists.txt'
109--- src/client/CMakeLists.txt 2013-06-03 12:15:45 +0000
110+++ src/client/CMakeLists.txt 2013-06-18 03:30:36 +0000
111@@ -54,6 +54,7 @@
112 gbm/gbm_client_buffer_factory.cpp
113 gbm/gbm_client_buffer.cpp
114 gbm/mesa_native_display_container.cpp
115+ gbm/gbm_native_surface.cpp
116 ${CLIENT_SOURCES}
117 )
118 endif()
119@@ -69,7 +70,7 @@
120
121 PROPERTIES
122 VERSION ${MIR_VERSION_MAJOR}.${MIR_VERSION_MINOR}.${MIR_VERSION_PATCH}
123- SOVERSION ${MIR_VERSION_MAJOR}
124+ SOVERSION 1
125 )
126
127 set(
128
129=== modified file 'src/client/gbm/gbm_client_platform.cpp'
130--- src/client/gbm/gbm_client_platform.cpp 2013-05-03 21:59:56 +0000
131+++ src/client/gbm/gbm_client_platform.cpp 2013-06-18 03:30:36 +0000
132@@ -21,6 +21,7 @@
133 #include "gbm_client_buffer_factory.h"
134 #include "mesa_native_display_container.h"
135 #include "drm_fd_handler.h"
136+#include "gbm_native_surface.h"
137 #include "../mir_connection.h"
138 #include "../client_buffer_factory.h"
139 #include "../native_client_platform_factory.h"
140@@ -129,11 +130,32 @@
141 return std::make_shared<mclg::GBMClientBufferFactory>(drm_fd_handler);
142 }
143
144+namespace
145+{
146+struct NativeWindowDeleter
147+{
148+ NativeWindowDeleter(mclg::GBMNativeSurface* window)
149+ : window(window) {}
150+
151+ void operator()(EGLNativeWindowType* type)
152+ {
153+ delete type;
154+ delete window;
155+ }
156+
157+private:
158+ mclg::GBMNativeSurface* window;
159+};
160+}
161+
162 std::shared_ptr<EGLNativeWindowType> mclg::GBMClientPlatform::create_egl_native_window(ClientSurface* client_surface)
163 {
164- auto window_type = std::make_shared<EGLNativeWindowType>();
165- *window_type = reinterpret_cast<EGLNativeWindowType>(client_surface);
166- return window_type;
167+ //TODO: this is awkward on both android and gbm...
168+ auto gbm_window = new GBMNativeSurface(*client_surface);
169+ auto egl_native_window = new EGLNativeWindowType;
170+ *egl_native_window = gbm_window;
171+ NativeWindowDeleter deleter(gbm_window);
172+ return std::shared_ptr<EGLNativeWindowType>(egl_native_window, deleter);
173 }
174
175 std::shared_ptr<EGLNativeDisplayType> mclg::GBMClientPlatform::create_egl_native_display()
176
177=== added file 'src/client/gbm/gbm_native_surface.cpp'
178--- src/client/gbm/gbm_native_surface.cpp 1970-01-01 00:00:00 +0000
179+++ src/client/gbm/gbm_native_surface.cpp 2013-06-18 03:30:36 +0000
180@@ -0,0 +1,78 @@
181+/*
182+ * Copyright © 2013 Canonical Ltd.
183+ *
184+ * This program is free software: you can redistribute it and/or modify it
185+ * under the terms of the GNU Lesser General Public License version 3,
186+ * as published by the Free Software Foundation.
187+ *
188+ * This program is distributed in the hope that it will be useful,
189+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
190+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
191+ * GNU Lesser General Public License for more details.
192+ *
193+ * You should have received a copy of the GNU Lesser General Public License
194+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
195+ *
196+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
197+ */
198+
199+#include <cstring>
200+#include "../client_buffer.h"
201+#include "gbm_native_surface.h"
202+
203+namespace mclg=mir::client::gbm;
204+
205+namespace
206+{
207+static int advance_buffer_static(MirMesaEGLNativeSurface* surface,
208+ MirBufferPackage* buffer_package)
209+{
210+ auto s = static_cast<mclg::GBMNativeSurface*>(surface);
211+ return s->advance_buffer(buffer_package);
212+}
213+
214+static int get_parameters_static(MirMesaEGLNativeSurface* surface,
215+ MirSurfaceParameters* surface_parameters)
216+{
217+ auto s = static_cast<mclg::GBMNativeSurface*>(surface);
218+ return s->get_parameters(surface_parameters);
219+}
220+
221+static int set_swapinterval_static(MirMesaEGLNativeSurface* surface, int interval)
222+{
223+ //TODO
224+ (void) surface;
225+ (void) interval;
226+ return MIR_MESA_TRUE;
227+}
228+
229+static void buffer_advanced_callback(MirSurface* /* surface */,
230+ void* /* context */)
231+{
232+}
233+}
234+
235+mclg::GBMNativeSurface::GBMNativeSurface(ClientSurface& surface)
236+ : surface(surface)
237+{
238+ surface_advance_buffer = advance_buffer_static;
239+ surface_get_parameters = get_parameters_static;
240+ surface_set_swapinterval = set_swapinterval_static;
241+}
242+
243+int mclg::GBMNativeSurface::advance_buffer(MirBufferPackage* buffer_package)
244+{
245+ mir_wait_for(surface.next_buffer(buffer_advanced_callback, NULL));
246+ auto buffer = surface.get_current_buffer();
247+
248+ auto buffer_to_driver = buffer->native_buffer_handle();
249+ memcpy(buffer_package, buffer_to_driver.get(), sizeof(MirBufferPackage));
250+ return MIR_MESA_TRUE;
251+}
252+
253+int mclg::GBMNativeSurface::get_parameters(MirSurfaceParameters* surface_parameters)
254+{
255+ auto params = surface.get_parameters();
256+ memcpy(surface_parameters, &params, sizeof(MirSurfaceParameters));
257+ return MIR_MESA_TRUE;
258+}
259
260=== added file 'src/client/gbm/gbm_native_surface.h'
261--- src/client/gbm/gbm_native_surface.h 1970-01-01 00:00:00 +0000
262+++ src/client/gbm/gbm_native_surface.h 2013-06-18 03:30:36 +0000
263@@ -0,0 +1,42 @@
264+/*
265+ * Copyright © 2013 Canonical Ltd.
266+ *
267+ * This program is free software: you can redistribute it and/or modify it
268+ * under the terms of the GNU Lesser General Public License version 3,
269+ * as published by the Free Software Foundation.
270+ *
271+ * This program is distributed in the hope that it will be useful,
272+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
273+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
274+ * GNU Lesser General Public License for more details.
275+ *
276+ * You should have received a copy of the GNU Lesser General Public License
277+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
278+ *
279+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
280+ */
281+
282+#include "mir_toolkit/mesa/native_display.h"
283+#include "../mir_client_surface.h"
284+
285+namespace mir
286+{
287+namespace client
288+{
289+namespace gbm
290+{
291+
292+class GBMNativeSurface : public MirMesaEGLNativeSurface
293+{
294+public:
295+ explicit GBMNativeSurface(ClientSurface&);
296+
297+ int advance_buffer(MirBufferPackage* buffer_package);
298+ int get_parameters(MirSurfaceParameters* surface_parameters);
299+private:
300+ ClientSurface& surface;
301+};
302+
303+}
304+}
305+}
306
307=== modified file 'src/client/gbm/mesa_native_display_container.cpp'
308--- src/client/gbm/mesa_native_display_container.cpp 2013-06-06 08:36:17 +0000
309+++ src/client/gbm/mesa_native_display_container.cpp 2013-06-18 03:30:36 +0000
310@@ -33,42 +33,12 @@
311 extern "C"
312 {
313
314-static void gbm_egl_display_get_platform(MirMesaEGLNativeDisplay* display,
315+static int gbm_egl_display_get_platform(MirMesaEGLNativeDisplay* display,
316 MirPlatformPackage* package)
317 {
318 auto connection = static_cast<MirConnection*>(display->context);
319-
320 mir_connection_get_platform(connection, package);
321-}
322-
323-static void gbm_egl_surface_get_current_buffer(MirMesaEGLNativeDisplay* /* display */,
324- MirEGLNativeWindowType surface,
325- MirBufferPackage* buffer_package)
326-{
327- MirSurface* ms = static_cast<MirSurface*>(surface);
328- MirBufferPackage * current_package;
329- mir_surface_get_current_buffer(ms, &current_package);
330- memcpy(buffer_package, current_package, sizeof(MirBufferPackage));
331-}
332-
333-static void buffer_advanced_callback(MirSurface* /* surface */,
334- void* /* context */)
335-{
336-}
337-
338-static void gbm_egl_surface_advance_buffer(MirMesaEGLNativeDisplay* /* display */,
339- MirEGLNativeWindowType surface)
340-{
341- MirSurface* ms = static_cast<MirSurface*>(surface);
342- mir_wait_for(mir_surface_swap_buffers(ms, buffer_advanced_callback, nullptr));
343-}
344-
345-static void gbm_egl_surface_get_parameters(MirMesaEGLNativeDisplay* /* display */,
346- MirEGLNativeWindowType surface,
347- MirSurfaceParameters* surface_parameters)
348-{
349- MirSurface* ms = static_cast<MirSurface*>(surface);
350- mir_surface_get_parameters(ms, surface_parameters);
351+ return MIR_MESA_TRUE;
352 }
353
354 int mir_egl_mesa_display_is_valid(MirMesaEGLNativeDisplay* display)
355@@ -99,8 +69,7 @@
356 }
357 }
358
359-bool
360-mclg::MesaNativeDisplayContainer::validate(MirEGLNativeDisplayType display) const
361+bool mclg::MesaNativeDisplayContainer::validate(MirEGLNativeDisplayType display) const
362 {
363 std::lock_guard<std::mutex> lg(guard);
364 return (valid_displays.find(display) != valid_displays.end());
365@@ -111,9 +80,6 @@
366 {
367 MirMesaEGLNativeDisplay* display = new MirMesaEGLNativeDisplay();
368 display->display_get_platform = gbm_egl_display_get_platform;
369- display->surface_get_current_buffer = gbm_egl_surface_get_current_buffer;
370- display->surface_advance_buffer = gbm_egl_surface_advance_buffer;
371- display->surface_get_parameters = gbm_egl_surface_get_parameters;
372 display->context = connection;
373
374 std::lock_guard<std::mutex> lg(guard);
375@@ -123,8 +89,7 @@
376 return egl_display;
377 }
378
379-void
380-mclg::MesaNativeDisplayContainer::release(MirEGLNativeDisplayType display)
381+void mclg::MesaNativeDisplayContainer::release(MirEGLNativeDisplayType display)
382 {
383 std::lock_guard<std::mutex> lg(guard);
384
385
386=== modified file 'src/server/graphics/gbm/CMakeLists.txt'
387--- src/server/graphics/gbm/CMakeLists.txt 2013-05-23 13:01:05 +0000
388+++ src/server/graphics/gbm/CMakeLists.txt 2013-06-18 03:30:36 +0000
389@@ -27,6 +27,7 @@
390 kms_page_flipper.cpp
391 linux_virtual_terminal.cpp
392 internal_native_display.cpp
393+ internal_native_surface.cpp
394 internal_client.cpp
395 drm_close_threadsafe.cpp
396 )
397
398=== modified file 'src/server/graphics/gbm/internal_client.cpp'
399--- src/server/graphics/gbm/internal_client.cpp 2013-05-14 16:45:25 +0000
400+++ src/server/graphics/gbm/internal_client.cpp 2013-06-18 03:30:36 +0000
401@@ -34,5 +34,10 @@
402
403 EGLNativeWindowType mgg::InternalClient::egl_native_window(std::shared_ptr<mf::Surface> const& surface)
404 {
405- return reinterpret_cast<EGLNativeWindowType>(surface.get());
406+ if (!client_window)
407+ {
408+ client_window = std::make_shared<mgg::InternalNativeSurface>(surface);
409+ }
410+
411+ return client_window.get();
412 }
413
414=== modified file 'src/server/graphics/gbm/internal_client.h'
415--- src/server/graphics/gbm/internal_client.h 2013-05-14 16:45:25 +0000
416+++ src/server/graphics/gbm/internal_client.h 2013-06-18 03:30:36 +0000
417@@ -21,6 +21,7 @@
418
419 #include "mir/graphics/internal_client.h"
420 #include "internal_native_display.h"
421+#include "internal_native_surface.h"
422 #include <memory>
423
424 namespace mir
425@@ -44,6 +45,7 @@
426
427 private:
428 std::shared_ptr<MirMesaEGLNativeDisplay> const native_display;
429+ std::shared_ptr<MirMesaEGLNativeSurface> client_window;
430 };
431
432 }
433
434=== modified file 'src/server/graphics/gbm/internal_native_display.cpp'
435--- src/server/graphics/gbm/internal_native_display.cpp 2013-05-14 22:14:13 +0000
436+++ src/server/graphics/gbm/internal_native_display.cpp 2013-06-18 03:30:36 +0000
437@@ -38,23 +38,9 @@
438 {
439 context = this;
440 this->display_get_platform = &InternalNativeDisplay::native_display_get_platform;
441- this->surface_get_current_buffer = &InternalNativeDisplay::native_display_surface_get_current_buffer;
442- this->surface_get_parameters = &InternalNativeDisplay::native_display_surface_get_parameters;
443- this->surface_advance_buffer = &InternalNativeDisplay::native_display_surface_advance_buffer;
444-}
445-
446-void mgg::InternalNativeDisplay::native_display_surface_get_current_buffer(MirMesaEGLNativeDisplay*,
447- MirEGLNativeWindowType surface,
448- MirBufferPackage* package)
449-{
450- auto mir_surface = static_cast<mf::Surface*>(surface);
451-
452- auto buffer = mir_surface->client_buffer();
453- auto buffer_package = buffer->native_buffer_handle();
454- memcpy(package, buffer_package.get(), sizeof(MirBufferPackage));
455-}
456-
457-void mgg::InternalNativeDisplay::native_display_get_platform(MirMesaEGLNativeDisplay* display, MirPlatformPackage* package)
458+}
459+
460+int mgg::InternalNativeDisplay::native_display_get_platform(MirMesaEGLNativeDisplay* display, MirPlatformPackage* package)
461 {
462 auto native_disp = static_cast<InternalNativeDisplay*>(display);
463 package->data_items = native_disp->platform_package->ipc_data.size();
464@@ -68,23 +54,5 @@
465 package->fd[i] = native_disp->platform_package->ipc_fds[i];
466 }
467
468-}
469-
470-void mgg::InternalNativeDisplay::native_display_surface_get_parameters(MirMesaEGLNativeDisplay*,
471- MirEGLNativeWindowType surface,
472- MirSurfaceParameters* parameters)
473-{
474- auto mir_surface = static_cast<mf::Surface*>(surface);
475-
476- parameters->width = mir_surface->size().width.as_uint32_t();
477- parameters->height = mir_surface->size().height.as_uint32_t();
478- parameters->pixel_format = static_cast<MirPixelFormat>(mir_surface->pixel_format());
479- parameters->buffer_usage = mir_buffer_usage_hardware;
480-}
481-
482-void mgg::InternalNativeDisplay::native_display_surface_advance_buffer(MirMesaEGLNativeDisplay*,
483- MirEGLNativeWindowType surface)
484-{
485- auto mir_surface = static_cast<mf::Surface*>(surface);
486- mir_surface->advance_client_buffer();
487+ return MIR_MESA_TRUE;
488 }
489
490=== modified file 'src/server/graphics/gbm/internal_native_display.h'
491--- src/server/graphics/gbm/internal_native_display.h 2013-05-09 20:58:30 +0000
492+++ src/server/graphics/gbm/internal_native_display.h 2013-06-18 03:30:36 +0000
493@@ -1,4 +1,3 @@
494-
495 /*
496 * Copyright © 2013 Canonical Ltd.
497 *
498@@ -37,16 +36,9 @@
499 public:
500 InternalNativeDisplay(std::shared_ptr<PlatformIPCPackage> const& platform_package);
501
502- static void native_display_get_platform(MirMesaEGLNativeDisplay* display, MirPlatformPackage* package);
503- static void native_display_surface_get_current_buffer(MirMesaEGLNativeDisplay* /* display */,
504- MirEGLNativeWindowType surface,
505- MirBufferPackage* package);
506- static void native_display_surface_get_parameters(MirMesaEGLNativeDisplay* /* display */,
507- MirEGLNativeWindowType surface,
508- MirSurfaceParameters* parameters);
509- static void native_display_surface_advance_buffer(MirMesaEGLNativeDisplay* /* display */,
510- MirEGLNativeWindowType surface);
511 private:
512+ static int native_display_get_platform(MirMesaEGLNativeDisplay* display, MirPlatformPackage* package);
513+
514 std::shared_ptr<PlatformIPCPackage> platform_package;
515 };
516
517
518=== added file 'src/server/graphics/gbm/internal_native_surface.cpp'
519--- src/server/graphics/gbm/internal_native_surface.cpp 1970-01-01 00:00:00 +0000
520+++ src/server/graphics/gbm/internal_native_surface.cpp 2013-06-18 03:30:36 +0000
521@@ -0,0 +1,77 @@
522+/*
523+ * Copyright © 2013 Canonical Ltd.
524+ *
525+ * This program is free software: you can redistribute it and/or modify it
526+ * under the terms of the GNU General Public License version 3,
527+ * as published by the Free Software Foundation.
528+ *
529+ * This program is distributed in the hope that it will be useful,
530+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
531+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
532+ * GNU General Public License for more details.
533+ *
534+ * You should have received a copy of the GNU General Public License
535+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
536+ *
537+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
538+ */
539+
540+#include "mir/frontend/surface.h"
541+#include "mir/compositor/buffer.h"
542+#include "internal_native_surface.h"
543+#include <cstring>
544+namespace mgg = mir::graphics::gbm;
545+
546+mgg::InternalNativeSurface::InternalNativeSurface(std::shared_ptr<frontend::Surface> const& surface)
547+ : surface(surface)
548+{
549+ surface_advance_buffer = advance_buffer_static;
550+ surface_get_parameters = get_parameters_static;
551+ surface_set_swapinterval = set_swapinterval_static;
552+}
553+
554+int mgg::InternalNativeSurface::advance_buffer_static(
555+ MirMesaEGLNativeSurface* surface, MirBufferPackage* package)
556+{
557+ auto native_surface = static_cast<mgg::InternalNativeSurface*>(surface);
558+ return native_surface->advance_buffer(package);
559+}
560+
561+int mgg::InternalNativeSurface::advance_buffer(MirBufferPackage* package)
562+{
563+ /* TODO: kdub has a cleanup branch for the surface interface that will make this less ugly */
564+ current_buffer.reset();
565+ surface->advance_client_buffer();
566+ current_buffer = surface->client_buffer();
567+
568+ auto buffer_package = current_buffer->native_buffer_handle();
569+ memcpy(package, buffer_package.get(), sizeof(MirBufferPackage));
570+
571+ return MIR_MESA_TRUE;
572+}
573+
574+int mgg::InternalNativeSurface::get_parameters_static(
575+ MirMesaEGLNativeSurface* surface, MirSurfaceParameters* parameters)
576+{
577+ auto native_surface = static_cast<mgg::InternalNativeSurface*>(surface);
578+ return native_surface->get_parameters(parameters);
579+}
580+
581+int mgg::InternalNativeSurface::get_parameters(MirSurfaceParameters* parameters)
582+{
583+ auto size = surface->size();
584+ parameters->width = size.width.as_uint32_t();
585+ parameters->height = size.height.as_uint32_t();
586+ parameters->pixel_format = static_cast<MirPixelFormat>(surface->pixel_format());
587+ parameters->buffer_usage = mir_buffer_usage_hardware;
588+
589+ return MIR_MESA_TRUE;
590+}
591+
592+int mgg::InternalNativeSurface::set_swapinterval_static(MirMesaEGLNativeSurface* surface, int interval)
593+{
594+ //TODO:
595+ (void) surface;
596+ (void) interval;
597+ return MIR_MESA_TRUE;
598+}
599
600=== added file 'src/server/graphics/gbm/internal_native_surface.h'
601--- src/server/graphics/gbm/internal_native_surface.h 1970-01-01 00:00:00 +0000
602+++ src/server/graphics/gbm/internal_native_surface.h 2013-06-18 03:30:36 +0000
603@@ -0,0 +1,62 @@
604+/*
605+ * Copyright © 2013 Canonical Ltd.
606+ *
607+ * This program is free software: you can redistribute it and/or modify it
608+ * under the terms of the GNU General Public License version 3,
609+ * as published by the Free Software Foundation.
610+ *
611+ * This program is distributed in the hope that it will be useful,
612+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
613+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
614+ * GNU General Public License for more details.
615+ *
616+ * You should have received a copy of the GNU General Public License
617+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
618+ *
619+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
620+ */
621+
622+#ifndef MIR_GRAPHICS_GBM_INTERNAL_NATIVE_SURFACE_H_
623+#define MIR_GRAPHICS_GBM_INTERNAL_NATIVE_SURFACE_H_
624+
625+#include "mir_toolkit/mesa/native_display.h"
626+#include <memory>
627+
628+namespace mir
629+{
630+namespace frontend
631+{
632+class Surface;
633+}
634+namespace compositor
635+{
636+class Buffer;
637+}
638+namespace graphics
639+{
640+namespace gbm
641+{
642+
643+class InternalNativeSurface : public MirMesaEGLNativeSurface
644+{
645+public:
646+ InternalNativeSurface(std::shared_ptr<frontend::Surface> const& surface);
647+
648+ int advance_buffer(MirBufferPackage* package);
649+ int get_parameters(MirSurfaceParameters* parameters);
650+
651+private:
652+ static int set_swapinterval_static(MirMesaEGLNativeSurface* surface, int interval);
653+ static int advance_buffer_static(MirMesaEGLNativeSurface* surface,
654+ MirBufferPackage* package);
655+ static int get_parameters_static(MirMesaEGLNativeSurface* surface,
656+ MirSurfaceParameters* parameters);
657+
658+ std::shared_ptr<frontend::Surface> surface;
659+ std::shared_ptr<compositor::Buffer> current_buffer;
660+};
661+
662+}
663+}
664+}
665+#endif /* MIR_GRAPHICS_GBM_INTERNAL_NATIVE_DISPLAY_H_ */
666
667=== modified file 'tests/unit-tests/client/gbm/CMakeLists.txt'
668--- tests/unit-tests/client/gbm/CMakeLists.txt 2013-03-24 23:33:49 +0000
669+++ tests/unit-tests/client/gbm/CMakeLists.txt 2013-06-18 03:30:36 +0000
670@@ -19,6 +19,7 @@
671 ${CMAKE_CURRENT_SOURCE_DIR}/test_gbm_client_buffer.cpp
672 ${CMAKE_CURRENT_SOURCE_DIR}/test_gbm_client_platform.cpp
673 ${CMAKE_CURRENT_SOURCE_DIR}/test_mesa_native_display_container.cpp
674+ ${CMAKE_CURRENT_SOURCE_DIR}/test_native_surface.cpp
675 )
676
677 set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} PARENT_SCOPE)
678
679=== modified file 'tests/unit-tests/client/gbm/test_gbm_client_platform.cpp'
680--- tests/unit-tests/client/gbm/test_gbm_client_platform.cpp 2013-05-08 17:52:49 +0000
681+++ tests/unit-tests/client/gbm/test_gbm_client_platform.cpp 2013-06-18 03:30:36 +0000
682@@ -29,17 +29,6 @@
683 namespace mt = mir::test;
684 namespace mtd = mir::test::doubles;
685
686-TEST(GBMClientPlatformTest, egl_native_window_is_client_surface)
687-{
688- mtd::MockClientContext context;
689- mcl::NativeClientPlatformFactory factory;
690- mtd::MockClientSurface surface;
691- auto platform = factory.create_client_platform(&context);
692- auto mock_client_surface = std::make_shared<mtd::MockClientSurface>();
693- auto native_window = platform->create_egl_native_window(&surface);
694- EXPECT_EQ(reinterpret_cast<EGLNativeWindowType>(&surface), *native_window);
695-}
696-
697 /* TODO: mir_egl_mesa_display_is_valid is a bit fragile because libmirserver and libmirclient both have very
698 * different implementations and both have symbols for it. If the linking order of the test changes,
699 * specifically, if mir_egl_mesa_display_is_valid resolves into libmirserver, then this test will break.
700
701=== added file 'tests/unit-tests/client/gbm/test_native_surface.cpp'
702--- tests/unit-tests/client/gbm/test_native_surface.cpp 1970-01-01 00:00:00 +0000
703+++ tests/unit-tests/client/gbm/test_native_surface.cpp 2013-06-18 03:30:36 +0000
704@@ -0,0 +1,114 @@
705+/*
706+ * Copyright © 2013 Canonical Ltd.
707+ *
708+ * This program is free software: you can redistribute it and/or modify
709+ * it under the terms of the GNU General Public License version 3 as
710+ * published by the Free Software Foundation.
711+ *
712+ * This program is distributed in the hope that it will be useful,
713+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
714+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
715+ * GNU General Public License for more details.
716+ *
717+ * You should have received a copy of the GNU General Public License
718+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
719+ *
720+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
721+ */
722+
723+#include "src/client/gbm/gbm_native_surface.h"
724+#include "src/client/client_buffer.h"
725+#include <gmock/gmock.h>
726+#include <gtest/gtest.h>
727+
728+namespace mcl=mir::client;
729+namespace mcl=mir::client;
730+namespace mclg=mir::client::gbm;
731+namespace geom=mir::geometry;
732+
733+namespace
734+{
735+
736+struct MockClientBuffer : public mcl::ClientBuffer
737+{
738+ MockClientBuffer()
739+ {
740+ ON_CALL(*this, native_buffer_handle())
741+ .WillByDefault(testing::Return(std::make_shared<MirBufferPackage>()));
742+ }
743+ ~MockClientBuffer() noexcept {}
744+
745+ MOCK_METHOD0(secure_for_cpu_write, std::shared_ptr<mcl::MemoryRegion>());
746+ MOCK_CONST_METHOD0(size, geom::Size());
747+ MOCK_CONST_METHOD0(stride, geom::Stride());
748+ MOCK_CONST_METHOD0(pixel_format, geom::PixelFormat());
749+
750+ MOCK_CONST_METHOD0(age, uint32_t());
751+ MOCK_METHOD0(mark_as_submitted, void());
752+ MOCK_METHOD0(increment_age, void());
753+
754+ MOCK_CONST_METHOD0(native_buffer_handle, std::shared_ptr<MirNativeBuffer>());
755+};
756+
757+struct MockMirSurface : public mcl::ClientSurface
758+{
759+ MockMirSurface(MirSurfaceParameters params)
760+ : params(params)
761+ {
762+ using namespace testing;
763+ ON_CALL(*this, get_parameters())
764+ .WillByDefault(Return(params));
765+ ON_CALL(*this, get_current_buffer())
766+ .WillByDefault(Return(
767+ std::make_shared<NiceMock<MockClientBuffer>>()));
768+ }
769+
770+ MOCK_CONST_METHOD0(get_parameters, MirSurfaceParameters());
771+ MOCK_METHOD0(get_current_buffer, std::shared_ptr<mcl::ClientBuffer>());
772+ MOCK_METHOD2(next_buffer, MirWaitHandle*(mir_surface_lifecycle_callback callback, void * context));
773+
774+ MirSurfaceParameters params;
775+};
776+}
777+
778+class GBMInterpreterTest : public ::testing::Test
779+{
780+public:
781+ virtual void SetUp()
782+ {
783+ using namespace testing;
784+ surf_params.width = 530;
785+ surf_params.height = 715;
786+ surf_params.pixel_format = mir_pixel_format_abgr_8888;
787+
788+ buffer = std::make_shared<MirBufferPackage>();
789+ }
790+
791+ std::shared_ptr<MirBufferPackage> buffer;
792+ MirSurfaceParameters surf_params;
793+};
794+
795+TEST_F(GBMInterpreterTest, basic_parameters)
796+{
797+ testing::NiceMock<MockMirSurface> mock_surface{surf_params};
798+ mclg::GBMNativeSurface interpreter(mock_surface);
799+
800+ MirSurfaceParameters params;
801+ interpreter.surface_get_parameters(&interpreter, &params);
802+}
803+
804+TEST_F(GBMInterpreterTest, basic_advance)
805+{
806+ using namespace testing;
807+ testing::NiceMock<MockMirSurface> mock_surface{surf_params};
808+
809+ mclg::GBMNativeSurface interpreter(mock_surface);
810+
811+ EXPECT_CALL(mock_surface, next_buffer(_,_))
812+ .Times(1);
813+ EXPECT_CALL(mock_surface, get_current_buffer())
814+ .Times(1);
815+
816+ MirBufferPackage buffer_package;
817+ interpreter.surface_advance_buffer(&interpreter, &buffer_package);
818+}
819
820=== modified file 'tests/unit-tests/graphics/android/test_internal_client_interpreter.cpp'
821--- tests/unit-tests/graphics/android/test_internal_client_interpreter.cpp 2013-05-09 18:26:45 +0000
822+++ tests/unit-tests/graphics/android/test_internal_client_interpreter.cpp 2013-06-18 03:30:36 +0000
823@@ -147,3 +147,9 @@
824 auto rc_format = interpreter.driver_requests_info(NATIVE_WINDOW_FORMAT);
825 EXPECT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, rc_format);
826 }
827+
828+TEST_F(InternalClientWindow, window_holds_buffer_resource_for_driver)
829+{
830+ mga::InternalClientWindow interpreter(mock_surface, mock_cache);
831+
832+}
833
834=== modified file 'tests/unit-tests/graphics/gbm/CMakeLists.txt'
835--- tests/unit-tests/graphics/gbm/CMakeLists.txt 2013-05-08 17:26:17 +0000
836+++ tests/unit-tests/graphics/gbm/CMakeLists.txt 2013-06-18 03:30:36 +0000
837@@ -10,6 +10,7 @@
838 ${CMAKE_CURRENT_SOURCE_DIR}/test_kms_page_flipper.cpp
839 ${CMAKE_CURRENT_SOURCE_DIR}/test_linux_virtual_terminal.cpp
840 ${CMAKE_CURRENT_SOURCE_DIR}/test_internal_native_display.cpp
841+ ${CMAKE_CURRENT_SOURCE_DIR}/test_internal_native_surface.cpp
842 )
843
844 set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} PARENT_SCOPE)
845
846=== modified file 'tests/unit-tests/graphics/gbm/test_internal_client.cpp'
847--- tests/unit-tests/graphics/gbm/test_internal_client.cpp 2013-05-14 16:45:25 +0000
848+++ tests/unit-tests/graphics/gbm/test_internal_client.cpp 2013-06-18 03:30:36 +0000
849@@ -19,6 +19,7 @@
850 #include "mir/frontend/surface.h"
851 #include "mir_toolkit/mesa/native_display.h"
852 #include "src/server/graphics/gbm/internal_client.h"
853+#include "src/server/graphics/gbm/internal_native_surface.h"
854 #include "mir_test_doubles/stub_platform.h"
855 #include "mir_test_doubles/stub_surface.h"
856
857@@ -29,15 +30,24 @@
858 namespace mgg=mir::graphics::gbm;
859 namespace mtd=mir::test::doubles;
860
861-TEST(InternalClient, native_display)
862+TEST(InternalClient, native_display_sanity)
863 {
864- auto stub_window = std::make_shared<mtd::StubSurface>();
865 auto stub_display = std::make_shared<MirMesaEGLNativeDisplay>();
866 mgg::InternalClient client(stub_display);
867
868 auto native_display = client.egl_native_display();
869- auto native_window = client.egl_native_window(stub_window);
870-
871 EXPECT_EQ(reinterpret_cast<EGLNativeDisplayType>(stub_display.get()), native_display);
872- EXPECT_EQ(reinterpret_cast<EGLNativeWindowType>(stub_window.get()), native_window);
873+}
874+
875+TEST(InternalClient, native_surface_sanity)
876+{
877+ auto stub_display = std::make_shared<MirMesaEGLNativeDisplay>();
878+ mgg::InternalClient client(stub_display);
879+
880+ auto stub_window = std::make_shared<mtd::StubSurface>();
881+ auto native_window = static_cast<mgg::InternalNativeSurface*>(client.egl_native_window(stub_window));
882+
883+ ASSERT_NE(nullptr, native_window->surface_advance_buffer);
884+ ASSERT_NE(nullptr, native_window->surface_get_parameters);
885+ ASSERT_NE(nullptr, native_window->surface_set_swapinterval);
886 }
887
888=== modified file 'tests/unit-tests/graphics/gbm/test_internal_native_display.cpp'
889--- tests/unit-tests/graphics/gbm/test_internal_native_display.cpp 2013-05-14 22:27:33 +0000
890+++ tests/unit-tests/graphics/gbm/test_internal_native_display.cpp 2013-06-18 03:30:36 +0000
891@@ -43,10 +43,6 @@
892
893 struct InternalNativeDisplay : public testing::Test
894 {
895- InternalNativeDisplay()
896- {
897- }
898-
899 void SetUp()
900 {
901 using namespace ::testing;
902@@ -75,24 +71,6 @@
903 }
904 return true;
905 }
906-
907-MATCHER_P(StrideMatches, package, "")
908-{
909- if (arg.stride != package->stride)
910- {
911- return false;
912- }
913- return true;
914-}
915-
916-MATCHER_P(ParametersHaveSize, size, "")
917-{
918- if (static_cast<uint32_t>(arg.width) != size.width.as_uint32_t())
919- return false;
920- if (static_cast<uint32_t>(arg.height) != size.height.as_uint32_t())
921- return false;
922- return true;
923-}
924 }
925
926 TEST_F(InternalNativeDisplay, display_get_platform_matches_construction_platform)
927@@ -107,84 +85,6 @@
928 EXPECT_THAT(test_package, PackageMatches(platform_package));
929 }
930
931-TEST_F(InternalNativeDisplay, surface_get_current_buffer)
932-{
933- using namespace ::testing;
934-
935- mtd::MockSurface surface(std::make_shared<mtd::StubSurfaceBuilder>());
936- auto buffer = std::make_shared<mtd::MockBuffer>(geom::Size(), geom::Stride(), geom::PixelFormat());
937-
938- auto test_buffer_package = std::make_shared<MirBufferPackage>();
939-
940- test_buffer_package->data_items = 2;
941- test_buffer_package->data[0] = 1;
942- test_buffer_package->data[1] = 2;
943- test_buffer_package->fd_items = 2;
944- test_buffer_package->fd[0] = 3;
945- test_buffer_package->fd[1] = 4;
946- test_buffer_package->stride = 77;
947-
948- mgg::InternalNativeDisplay native_display(platform_package);
949-
950- EXPECT_CALL(*buffer, native_buffer_handle())
951- .WillOnce(Return(test_buffer_package));
952- EXPECT_CALL(surface, client_buffer()).Times(1)
953- .WillOnce(Return(buffer));
954-
955- MirBufferPackage buffer_package;
956- memset(&buffer_package, 0, sizeof(MirBufferPackage));
957- native_display.surface_get_current_buffer(
958- &native_display, static_cast<MirEGLNativeWindowType>(&surface), &buffer_package);
959-
960- EXPECT_EQ(test_buffer_package->data_items, buffer_package.data_items);
961- EXPECT_EQ(test_buffer_package->data[0], buffer_package.data[0]);
962- EXPECT_EQ(test_buffer_package->data[1], buffer_package.data[1]);
963- EXPECT_EQ(test_buffer_package->fd_items, buffer_package.fd_items);
964- EXPECT_EQ(test_buffer_package->fd[0], buffer_package.fd[0]);
965- EXPECT_EQ(test_buffer_package->fd[1], buffer_package.fd[1]);
966- EXPECT_EQ(test_buffer_package->stride, buffer_package.stride);
967-}
968-
969-TEST_F(InternalNativeDisplay, surface_advance_buffer)
970-{
971- using namespace ::testing;
972-
973- mtd::MockSurface surface(std::make_shared<mtd::StubSurfaceBuilder>());
974-
975- mgg::InternalNativeDisplay native_display(platform_package);
976-
977- EXPECT_CALL(surface, advance_client_buffer()).Times(1);
978-
979- native_display.surface_advance_buffer(
980- &native_display, static_cast<MirEGLNativeWindowType>(&surface));
981-}
982-
983-TEST_F(InternalNativeDisplay, surface_get_parameters)
984-{
985- using namespace ::testing;
986-
987- geom::Size const test_surface_size = geom::Size{geom::Width{17},
988- geom::Height{29}};
989- geom::PixelFormat const test_pixel_format = geom::PixelFormat::xrgb_8888;
990-
991- mgg::InternalNativeDisplay native_display(platform_package);
992-
993- mtd::MockSurface surface(std::make_shared<mtd::StubSurfaceBuilder>());
994- EXPECT_CALL(surface, size()).Times(AtLeast(1)).WillRepeatedly(Return(test_surface_size));
995- EXPECT_CALL(surface, pixel_format()).Times(AtLeast(1)).WillRepeatedly(Return(test_pixel_format));
996-
997- MirSurfaceParameters parameters;
998- memset(&parameters, 0, sizeof(MirSurfaceParameters));
999- native_display.surface_get_parameters(
1000- &native_display, static_cast<MirEGLNativeWindowType>(&surface), &parameters);
1001-
1002- EXPECT_THAT(parameters, ParametersHaveSize(test_surface_size));
1003- EXPECT_EQ(parameters.pixel_format, static_cast<MirPixelFormat>(geom::PixelFormat::xrgb_8888));
1004-
1005- // TODO: What to do about buffer usage besides hardware? ~racarr
1006- EXPECT_EQ(parameters.buffer_usage, mir_buffer_usage_hardware);
1007-}
1008-
1009 TEST(MirServerMesaEGLNativeDisplayInvariants, pixel_format_formats_are_castable)
1010 {
1011 EXPECT_EQ(static_cast<MirPixelFormat>(geom::PixelFormat::invalid), mir_pixel_format_invalid);
1012
1013=== added file 'tests/unit-tests/graphics/gbm/test_internal_native_surface.cpp'
1014--- tests/unit-tests/graphics/gbm/test_internal_native_surface.cpp 1970-01-01 00:00:00 +0000
1015+++ tests/unit-tests/graphics/gbm/test_internal_native_surface.cpp 2013-06-18 03:30:36 +0000
1016@@ -0,0 +1,170 @@
1017+/*
1018+ * Copyright © 2013 Canonical Ltd.
1019+ *
1020+ * This program is free software: you can redistribute it and/or modify
1021+ * it under the terms of the GNU General Public License version 3 as
1022+ * published by the Free Software Foundation.
1023+ *
1024+ * This program is distributed in the hope that it will be useful,
1025+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1026+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1027+ * GNU General Public License for more details.
1028+ *
1029+ * You should have received a copy of the GNU General Public License
1030+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1031+ *
1032+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
1033+ */
1034+
1035+#include "src/server/graphics/gbm/internal_native_surface.h"
1036+#include "mir/graphics/platform.h"
1037+#include "mir/graphics/platform_ipc_package.h"
1038+#include "mir/frontend/surface.h"
1039+
1040+#include "mir_toolkit/mesa/native_display.h"
1041+
1042+#include "mir_test/fake_shared.h"
1043+#include "mir_test_doubles/stub_surface_builder.h"
1044+#include "mir_test_doubles/mock_surface.h"
1045+#include "mir_test_doubles/mock_buffer.h"
1046+
1047+#include <gtest/gtest.h>
1048+#include <gmock/gmock.h>
1049+
1050+namespace mg = mir::graphics;
1051+namespace mgg = mir::graphics::gbm;
1052+namespace mc = mir::compositor;
1053+namespace msh = mir::shell;
1054+namespace geom = mir::geometry;
1055+namespace mt = mir::test;
1056+namespace mtd = mt::doubles;
1057+
1058+namespace
1059+{
1060+
1061+
1062+class MockFrontendSurface : public mir::frontend::Surface
1063+{
1064+public:
1065+ MOCK_METHOD0(destroy, void());
1066+ MOCK_METHOD0(force_requests_to_complete, void());
1067+ MOCK_CONST_METHOD0(size, geom::Size());
1068+ MOCK_CONST_METHOD0(pixel_format, geom::PixelFormat());
1069+ MOCK_CONST_METHOD0(client_buffer, std::shared_ptr<mc::Buffer>());
1070+ MOCK_METHOD0(advance_client_buffer, void());
1071+ MOCK_CONST_METHOD0(supports_input, bool());
1072+ MOCK_CONST_METHOD0(client_input_fd, int());
1073+ MOCK_METHOD2(configure, int(MirSurfaceAttrib, int));
1074+};
1075+
1076+struct InternalNativeSurface : public testing::Test
1077+{
1078+ void SetUp()
1079+ {
1080+ using namespace ::testing;
1081+ mock_surface = std::make_shared<MockFrontendSurface>();
1082+ }
1083+
1084+ std::shared_ptr<MockFrontendSurface> mock_surface;
1085+};
1086+
1087+MATCHER_P(ParametersHaveSize, size, "")
1088+{
1089+ if (static_cast<uint32_t>(arg.width) != size.width.as_uint32_t())
1090+ return false;
1091+ if (static_cast<uint32_t>(arg.height) != size.height.as_uint32_t())
1092+ return false;
1093+ return true;
1094+}
1095+}
1096+
1097+TEST_F(InternalNativeSurface, surface_advance_buffer_packaging)
1098+{
1099+ using namespace ::testing;
1100+
1101+ auto buffer = std::make_shared<mtd::MockBuffer>();
1102+
1103+ auto test_buffer_package = std::make_shared<MirBufferPackage>();
1104+ test_buffer_package->data_items = 2;
1105+ test_buffer_package->data[0] = 1;
1106+ test_buffer_package->data[1] = 2;
1107+ test_buffer_package->fd_items = 2;
1108+ test_buffer_package->fd[0] = 3;
1109+ test_buffer_package->fd[1] = 4;
1110+ test_buffer_package->stride = 77;
1111+
1112+ mgg::InternalNativeSurface native_surface(mock_surface);
1113+
1114+ EXPECT_CALL(*buffer, native_buffer_handle())
1115+ .WillOnce(Return(test_buffer_package));
1116+ EXPECT_CALL(*mock_surface, client_buffer())
1117+ .Times(1)
1118+ .WillOnce(Return(buffer));
1119+
1120+ MirBufferPackage buffer_package;
1121+ memset(&buffer_package, 0, sizeof(MirBufferPackage));
1122+ native_surface.surface_advance_buffer(&native_surface, &buffer_package);
1123+
1124+ EXPECT_EQ(test_buffer_package->data_items, buffer_package.data_items);
1125+ EXPECT_EQ(test_buffer_package->data[0], buffer_package.data[0]);
1126+ EXPECT_EQ(test_buffer_package->data[1], buffer_package.data[1]);
1127+ EXPECT_EQ(test_buffer_package->fd_items, buffer_package.fd_items);
1128+ EXPECT_EQ(test_buffer_package->fd[0], buffer_package.fd[0]);
1129+ EXPECT_EQ(test_buffer_package->fd[1], buffer_package.fd[1]);
1130+ EXPECT_EQ(test_buffer_package->stride, buffer_package.stride);
1131+}
1132+
1133+TEST_F(InternalNativeSurface, surface_advance_buffer_secures_resource)
1134+{
1135+ using namespace ::testing;
1136+ mgg::InternalNativeSurface native_surface(mock_surface);
1137+ auto stub_buffer1 = std::make_shared<mtd::MockBuffer>();
1138+ auto stub_buffer2 = std::make_shared<mtd::MockBuffer>();
1139+
1140+ auto test_buffer_package = std::make_shared<MirBufferPackage>();
1141+ EXPECT_CALL(*stub_buffer1, native_buffer_handle())
1142+ .WillOnce(Return(test_buffer_package));
1143+ EXPECT_CALL(*stub_buffer2, native_buffer_handle())
1144+ .WillOnce(Return(test_buffer_package));
1145+ EXPECT_CALL(*mock_surface, client_buffer())
1146+ .Times(2)
1147+ .WillOnce(Return(stub_buffer1))
1148+ .WillOnce(Return(stub_buffer2));
1149+
1150+ auto use_count_1 = stub_buffer1.use_count();
1151+ auto use_count_2 = stub_buffer2.use_count();
1152+
1153+ MirBufferPackage buffer_package;
1154+ native_surface.surface_advance_buffer(&native_surface, &buffer_package);
1155+ EXPECT_EQ(use_count_1 + 1, stub_buffer1.use_count());
1156+
1157+ native_surface.surface_advance_buffer(&native_surface, &buffer_package);
1158+ EXPECT_EQ(use_count_1, stub_buffer1.use_count());
1159+ EXPECT_EQ(use_count_2 + 1, stub_buffer2.use_count());
1160+}
1161+
1162+TEST_F(InternalNativeSurface, surface_get_parameters)
1163+{
1164+ using namespace ::testing;
1165+
1166+ geom::Size const test_surface_size = geom::Size{geom::Width{17},
1167+ geom::Height{29}};
1168+ geom::PixelFormat const test_pixel_format = geom::PixelFormat::xrgb_8888;
1169+ EXPECT_CALL(*mock_surface, size())
1170+ .Times(1)
1171+ .WillOnce(Return(test_surface_size));
1172+ EXPECT_CALL(*mock_surface, pixel_format())
1173+ .Times(1)
1174+ .WillOnce(Return(test_pixel_format));
1175+
1176+ mgg::InternalNativeSurface native_surface(mock_surface);
1177+
1178+ MirSurfaceParameters parameters;
1179+ memset(&parameters, 0, sizeof(MirSurfaceParameters));
1180+ native_surface.surface_get_parameters(&native_surface, &parameters);
1181+
1182+ EXPECT_THAT(parameters, ParametersHaveSize(test_surface_size));
1183+ EXPECT_EQ(parameters.pixel_format, static_cast<MirPixelFormat>(geom::PixelFormat::xrgb_8888));
1184+ // TODO: What to do about buffer usage besides hardware? ~racarr
1185+ EXPECT_EQ(parameters.buffer_usage, mir_buffer_usage_hardware);
1186+}

Subscribers

People subscribed via source and target branches