Merge lp:~kdub/mir/upgrade-anativewindow into lp:~mir-team/mir/trunk
- upgrade-anativewindow
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Kevin DuBois |
Approved revision: | no longer in the source branch. |
Merged at revision: | 491 |
Proposed branch: | lp:~kdub/mir/upgrade-anativewindow |
Merge into: | lp:~mir-team/mir/trunk |
Diff against target: |
1221 lines (+608/-377) 10 files modified
src/client/CMakeLists.txt (+1/-0) src/client/android/android_client_platform.cpp (+3/-1) src/client/android/android_driver_interpreter.h (+48/-0) src/client/android/client_surface_interpreter.cpp (+69/-0) src/client/android/client_surface_interpreter.h (+50/-0) src/client/android/mir_native_window.cpp (+52/-45) src/client/android/mir_native_window.h (+5/-4) tests/unit-tests/client/CMakeLists.txt (+1/-0) tests/unit-tests/client/test_android_native_window.cpp (+177/-327) tests/unit-tests/client/test_client_surface_interpreter.cpp (+202/-0) |
To merge this branch: | bzr merge lp:~kdub/mir/upgrade-anativewindow |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Alexandros Frantzis (community) | Approve | ||
Review via email: mp+152231@code.launchpad.net |
Commit message
Upgrade ANativeWindow to use the newer JB interface to ANativeWindow (largely adding one parameter to the end of 3 functions). This is necessary for the jb driver present on qcom/nexus4
Description of the change
Upgrade ANativeWindow to use the newer JB interface to ANativeWindow (largely adding one parameter to the end of 3 functions). This is necessary for the jb driver present on qcom/nexus4
Basically, what was done is to separate MirNativeWindow into a bit that does the 'basic book-keeping' (like hooking up the C function pointers properly, and figuring out what the C functions are trying to do), and the bit that does the core of what we're trying to do, provide the buffers and buffer info to the driver.
This has the nice effect that 1) we're decoupled from change to the the basic book-keeping bits and 2) we can write different implementations of the AndroidDriverIn
more nuts and bolts about the changes:
I separated the file, tests/unit-
PS Jenkins bot (ps-jenkins) wrote : | # |
Alexandros Frantzis (afrantzis) wrote : | # |
43 + * Copyright © 2012 Canonical Ltd.
...and at other points
Happy new year!
28 -std::shared_
29 +std::shared_
Either left or right.
71 +class AndroidDriverIn
Missing a virtual destructor.
Also, do we support the copy/assignment operations. If not, we should =delete them.
114 +mcla::
Although this is in line with how ClientPlatform:
For another MP: Also change ClientPlatform:
786 + EXPECT_NO_THROW({
I used to use EXPECT_NO_THROW, but I found that they are not helpful at all. When an exception is thrown, the test framework will say something like "expected: no to throw, actual: it throws", which is rather useless for debugging. Without the EXPECT_NO_THROW, slightly more detailed information is printed out, and, of course, the test still fails as expected.
Kevin DuBois (kdub) wrote : | # |
all good points, the updates should have addressed them all.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:497
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild:
http://
Alexandros Frantzis (afrantzis) wrote : | # |
The changes look good, some nitpicks left:
29 +std::shared_
The fate of '*' still hasn't been decided.
75 + virtual void driver_
136 +void mcla::ClientSur
206 + void driver_
Space before right parenthesis.
421 + explicit MirNativeWindow
shared_ptr const& ?
432 + std::shared_
shared_ptr const ?
1143 + EXPECT_
1171 + EXPECT_
Expected/Actual in reverse order.
Robert Carr (robertcarr) wrote : | # |
Looks good to me besides alf's points.
Alexandros Frantzis (afrantzis) wrote : | # |
Looks good.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:498
http://
Executed test runs:
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:498
http://
Executed test runs:
None: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'src/client/CMakeLists.txt' |
2 | --- src/client/CMakeLists.txt 2013-03-07 08:04:05 +0000 |
3 | +++ src/client/CMakeLists.txt 2013-03-12 15:51:13 +0000 |
4 | @@ -58,6 +58,7 @@ |
5 | android/android_registrar.cpp |
6 | android/android_client_platform.cpp |
7 | android/mir_native_window.cpp |
8 | + android/client_surface_interpreter.cpp |
9 | ${CLIENT_SOURCES} |
10 | ) |
11 | endif() |
12 | |
13 | === modified file 'src/client/android/android_client_platform.cpp' |
14 | --- src/client/android/android_client_platform.cpp 2013-03-07 08:04:05 +0000 |
15 | +++ src/client/android/android_client_platform.cpp 2013-03-12 15:51:13 +0000 |
16 | @@ -20,6 +20,7 @@ |
17 | #include "android_client_platform.h" |
18 | #include "android_registrar_gralloc.h" |
19 | #include "android_client_buffer_depository.h" |
20 | +#include "client_surface_interpreter.h" |
21 | #include "../mir_connection.h" |
22 | #include "../native_client_platform_factory.h" |
23 | |
24 | @@ -85,7 +86,8 @@ |
25 | |
26 | std::shared_ptr<EGLNativeWindowType> mcla::AndroidClientPlatform::create_egl_native_window(ClientSurface *surface) |
27 | { |
28 | - auto mir_native_window = new mcla::MirNativeWindow(surface); |
29 | + auto anativewindow_interpreter = std::make_shared<mcla::ClientSurfaceInterpreter>(*surface); |
30 | + auto mir_native_window = new mcla::MirNativeWindow(anativewindow_interpreter); |
31 | auto egl_native_window = new EGLNativeWindowType; |
32 | *egl_native_window = mir_native_window; |
33 | MirNativeWindowDeleter deleter = MirNativeWindowDeleter(mir_native_window); |
34 | |
35 | === added file 'src/client/android/android_driver_interpreter.h' |
36 | --- src/client/android/android_driver_interpreter.h 1970-01-01 00:00:00 +0000 |
37 | +++ src/client/android/android_driver_interpreter.h 2013-03-12 15:51:13 +0000 |
38 | @@ -0,0 +1,48 @@ |
39 | +/* |
40 | + * Copyright © 2013 Canonical Ltd. |
41 | + * |
42 | + * This program is free software: you can redistribute it and/or modify it |
43 | + * under the terms of the GNU Lesser General Public License version 3, |
44 | + * as published by the Free Software Foundation. |
45 | + * |
46 | + * This program is distributed in the hope that it will be useful, |
47 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
48 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
49 | + * GNU General Public License for more details. |
50 | + * |
51 | + * You should have received a copy of the GNU Lesser General Public License |
52 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
53 | + * |
54 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
55 | + */ |
56 | + |
57 | +#ifndef MIR_CLIENT_ANDROID_ANDROID_DRIVER_INTERPRETER_H_ |
58 | +#define MIR_CLIENT_ANDROID_ANDROID_DRIVER_INTERPRETER_H_ |
59 | + |
60 | +#include <system/window.h> |
61 | + |
62 | +namespace mir |
63 | +{ |
64 | +namespace client |
65 | +{ |
66 | +namespace android |
67 | +{ |
68 | +class AndroidDriverInterpreter |
69 | +{ |
70 | +public: |
71 | + virtual ANativeWindowBuffer* driver_requests_buffer() = 0; |
72 | + virtual void driver_returns_buffer(ANativeWindowBuffer*, int fence_fd) = 0; |
73 | + virtual void dispatch_driver_request_format(int format) = 0; |
74 | + virtual int driver_requests_info(int key) const = 0; |
75 | +protected: |
76 | + AndroidDriverInterpreter() {}; |
77 | + virtual ~AndroidDriverInterpreter() {}; |
78 | + AndroidDriverInterpreter(AndroidDriverInterpreter const&) = delete; |
79 | + AndroidDriverInterpreter& operator=(AndroidDriverInterpreter const&) = delete; |
80 | +}; |
81 | + |
82 | +} |
83 | +} |
84 | +} |
85 | + |
86 | +#endif /* MIR_CLIENT_ANDROID_ANDROID_DRIVER_INTERPRETER_H_ */ |
87 | |
88 | === added file 'src/client/android/client_surface_interpreter.cpp' |
89 | --- src/client/android/client_surface_interpreter.cpp 1970-01-01 00:00:00 +0000 |
90 | +++ src/client/android/client_surface_interpreter.cpp 2013-03-12 15:51:13 +0000 |
91 | @@ -0,0 +1,69 @@ |
92 | +/* |
93 | + * Copyright © 2013 Canonical Ltd. |
94 | + * |
95 | + * This program is free software: you can redistribute it and/or modify it |
96 | + * under the terms of the GNU Lesser General Public License version 3, |
97 | + * as published by the Free Software Foundation. |
98 | + * |
99 | + * This program is distributed in the hope that it will be useful, |
100 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
101 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
102 | + * GNU General Public License for more details. |
103 | + * |
104 | + * You should have received a copy of the GNU Lesser General Public License |
105 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
106 | + * |
107 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
108 | + */ |
109 | + |
110 | +#include "client_surface_interpreter.h" |
111 | +#include "../client_buffer.h" |
112 | +#include <stdexcept> |
113 | + |
114 | +namespace mcla=mir::client::android; |
115 | + |
116 | +mcla::ClientSurfaceInterpreter::ClientSurfaceInterpreter(ClientSurface& surface) |
117 | + : surface(surface), |
118 | + driver_pixel_format(-1) |
119 | +{ |
120 | +} |
121 | + |
122 | +ANativeWindowBuffer* mcla::ClientSurfaceInterpreter::driver_requests_buffer() |
123 | +{ |
124 | + auto buffer = surface.get_current_buffer(); |
125 | + auto buffer_to_driver = buffer->get_native_handle(); |
126 | + buffer_to_driver->format = driver_pixel_format; |
127 | + |
128 | + return buffer_to_driver; |
129 | +} |
130 | + |
131 | +static void empty(MirSurface * /*surface*/, void * /*client_context*/) |
132 | +{} |
133 | +void mcla::ClientSurfaceInterpreter::driver_returns_buffer(ANativeWindowBuffer*, int /*fence_fd*/) |
134 | +{ |
135 | + mir_wait_for(surface.next_buffer(empty, NULL)); |
136 | +} |
137 | + |
138 | +void mcla::ClientSurfaceInterpreter::dispatch_driver_request_format(int format) |
139 | +{ |
140 | + driver_pixel_format = format; |
141 | +} |
142 | + |
143 | +int mcla::ClientSurfaceInterpreter::driver_requests_info(int key) const |
144 | +{ |
145 | + switch (key) |
146 | + { |
147 | + case NATIVE_WINDOW_WIDTH: |
148 | + case NATIVE_WINDOW_DEFAULT_WIDTH: |
149 | + return surface.get_parameters().width; |
150 | + case NATIVE_WINDOW_HEIGHT: |
151 | + case NATIVE_WINDOW_DEFAULT_HEIGHT: |
152 | + return surface.get_parameters().height; |
153 | + case NATIVE_WINDOW_FORMAT: |
154 | + return driver_pixel_format; |
155 | + case NATIVE_WINDOW_TRANSFORM_HINT: |
156 | + return 0; |
157 | + default: |
158 | + throw std::runtime_error("driver requested unsupported query"); |
159 | + } |
160 | +} |
161 | |
162 | === added file 'src/client/android/client_surface_interpreter.h' |
163 | --- src/client/android/client_surface_interpreter.h 1970-01-01 00:00:00 +0000 |
164 | +++ src/client/android/client_surface_interpreter.h 2013-03-12 15:51:13 +0000 |
165 | @@ -0,0 +1,50 @@ |
166 | +/* |
167 | + * Copyright © 2013 Canonical Ltd. |
168 | + * |
169 | + * This program is free software: you can redistribute it and/or modify it |
170 | + * under the terms of the GNU Lesser General Public License version 3, |
171 | + * as published by the Free Software Foundation. |
172 | + * |
173 | + * This program is distributed in the hope that it will be useful, |
174 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
175 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
176 | + * GNU General Public License for more details. |
177 | + * |
178 | + * You should have received a copy of the GNU Lesser General Public License |
179 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
180 | + * |
181 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
182 | + */ |
183 | + |
184 | +#ifndef MIR_CLIENT_ANDROID_CLIENT_SURFACE_INTERPRETER_H_ |
185 | +#define MIR_CLIENT_ANDROID_CLIENT_SURFACE_INTERPRETER_H_ |
186 | + |
187 | +#include "android_driver_interpreter.h" |
188 | +#include "../mir_client_surface.h" |
189 | + |
190 | +namespace mir |
191 | +{ |
192 | +namespace client |
193 | +{ |
194 | +namespace android |
195 | +{ |
196 | + |
197 | +class ClientSurfaceInterpreter : public AndroidDriverInterpreter |
198 | +{ |
199 | +public: |
200 | + explicit ClientSurfaceInterpreter(ClientSurface& surface); |
201 | + |
202 | + ANativeWindowBuffer* driver_requests_buffer(); |
203 | + void driver_returns_buffer(ANativeWindowBuffer*, int fence_fd); |
204 | + void dispatch_driver_request_format(int format); |
205 | + int driver_requests_info(int key) const; |
206 | +private: |
207 | + ClientSurface& surface; |
208 | + int driver_pixel_format; |
209 | +}; |
210 | + |
211 | +} |
212 | +} |
213 | +} |
214 | + |
215 | +#endif /* MIR_CLIENT_ANDROID_CLIENT_SURFACE_INTERPRETER_H_ */ |
216 | |
217 | === modified file 'src/client/android/mir_native_window.cpp' |
218 | --- src/client/android/mir_native_window.cpp 2013-03-07 08:04:05 +0000 |
219 | +++ src/client/android/mir_native_window.cpp 2013-03-12 15:51:13 +0000 |
220 | @@ -17,7 +17,7 @@ |
221 | */ |
222 | |
223 | #include "mir_native_window.h" |
224 | -#include "../client_buffer.h" |
225 | +#include "android_driver_interpreter.h" |
226 | |
227 | namespace mcl=mir::client; |
228 | namespace mcla=mir::client::android; |
229 | @@ -27,13 +27,19 @@ |
230 | static int query_static(const ANativeWindow* anw, int key, int* value); |
231 | static int perform_static(ANativeWindow* anw, int key, ...); |
232 | static int setSwapInterval_static (struct ANativeWindow* window, int interval); |
233 | +static int dequeueBuffer_deprecated_static (struct ANativeWindow* window, |
234 | + struct ANativeWindowBuffer** buffer); |
235 | static int dequeueBuffer_static (struct ANativeWindow* window, |
236 | - struct ANativeWindowBuffer** buffer); |
237 | + struct ANativeWindowBuffer** buffer, int* fence_fd); |
238 | static int lockBuffer_static(struct ANativeWindow* window, |
239 | struct ANativeWindowBuffer* buffer); |
240 | +static int queueBuffer_deprecated_static(struct ANativeWindow* window, |
241 | + struct ANativeWindowBuffer* buffer); |
242 | static int queueBuffer_static(struct ANativeWindow* window, |
243 | - struct ANativeWindowBuffer* buffer); |
244 | + struct ANativeWindowBuffer* buffer, int fence_fd); |
245 | static int cancelBuffer_static(struct ANativeWindow* window, |
246 | + struct ANativeWindowBuffer* buffer, int fence_fd); |
247 | +static int cancelBuffer_deprecated_static(struct ANativeWindow* window, |
248 | struct ANativeWindowBuffer* buffer); |
249 | |
250 | static void incRef(android_native_base_t*) |
251 | @@ -57,18 +63,34 @@ |
252 | return ret; |
253 | } |
254 | |
255 | +int dequeueBuffer_deprecated_static (struct ANativeWindow* window, |
256 | + struct ANativeWindowBuffer** buffer) |
257 | +{ |
258 | + auto self = static_cast<mcla::MirNativeWindow*>(window); |
259 | + return self->dequeueBuffer(buffer); |
260 | +} |
261 | + |
262 | int dequeueBuffer_static (struct ANativeWindow* window, |
263 | - struct ANativeWindowBuffer** buffer) |
264 | + struct ANativeWindowBuffer** buffer, int* fence_fd) |
265 | { |
266 | + *fence_fd = -1; |
267 | auto self = static_cast<mcla::MirNativeWindow*>(window); |
268 | return self->dequeueBuffer(buffer); |
269 | } |
270 | |
271 | +int queueBuffer_deprecated_static(struct ANativeWindow* window, |
272 | + struct ANativeWindowBuffer* buffer) |
273 | +{ |
274 | + auto self = static_cast<mcla::MirNativeWindow*>(window); |
275 | + return self->queueBuffer(buffer, -1); |
276 | +} |
277 | + |
278 | int queueBuffer_static(struct ANativeWindow* window, |
279 | - struct ANativeWindowBuffer* buffer) |
280 | + struct ANativeWindowBuffer* buffer, int fence_fd) |
281 | { |
282 | auto self = static_cast<mcla::MirNativeWindow*>(window); |
283 | - return self->queueBuffer(buffer); |
284 | + return self->queueBuffer(buffer, fence_fd); |
285 | + |
286 | } |
287 | |
288 | /* setSwapInterval, lockBuffer, and cancelBuffer don't seem to being called by the driver. for now just return without calling into MirNativeWindow */ |
289 | @@ -83,25 +105,33 @@ |
290 | return 0; |
291 | } |
292 | |
293 | +int cancelBuffer_deprecated_static(struct ANativeWindow* /*window*/, |
294 | + struct ANativeWindowBuffer* /*buffer*/) |
295 | +{ |
296 | + return 0; |
297 | +} |
298 | + |
299 | int cancelBuffer_static(struct ANativeWindow* /*window*/, |
300 | - struct ANativeWindowBuffer* /*buffer*/) |
301 | + struct ANativeWindowBuffer* /*buffer*/, int /*fence_fd*/) |
302 | { |
303 | return 0; |
304 | } |
305 | |
306 | } |
307 | |
308 | -mcla::MirNativeWindow::MirNativeWindow(ClientSurface* client_surface) |
309 | - : surface(client_surface), |
310 | - driver_pixel_format(-1) |
311 | +mcla::MirNativeWindow::MirNativeWindow(std::shared_ptr<AndroidDriverInterpreter> const& interpreter) |
312 | + : driver_interpreter(interpreter) |
313 | { |
314 | ANativeWindow::query = &query_static; |
315 | ANativeWindow::perform = &perform_static; |
316 | ANativeWindow::setSwapInterval = &setSwapInterval_static; |
317 | - ANativeWindow::dequeueBuffer_DEPRECATED = &dequeueBuffer_static; |
318 | + ANativeWindow::dequeueBuffer_DEPRECATED = &dequeueBuffer_deprecated_static; |
319 | + ANativeWindow::dequeueBuffer = &dequeueBuffer_static; |
320 | ANativeWindow::lockBuffer_DEPRECATED = &lockBuffer_static; |
321 | - ANativeWindow::queueBuffer_DEPRECATED = &queueBuffer_static; |
322 | - ANativeWindow::cancelBuffer_DEPRECATED = &cancelBuffer_static; |
323 | + ANativeWindow::queueBuffer_DEPRECATED = &queueBuffer_deprecated_static; |
324 | + ANativeWindow::queueBuffer = &queueBuffer_static; |
325 | + ANativeWindow::cancelBuffer_DEPRECATED = &cancelBuffer_deprecated_static; |
326 | + ANativeWindow::cancelBuffer = &cancelBuffer_static; |
327 | |
328 | ANativeWindow::common.incRef = &incRef; |
329 | ANativeWindow::common.decRef = &incRef; |
330 | @@ -112,45 +142,20 @@ |
331 | |
332 | int mcla::MirNativeWindow::dequeueBuffer (struct ANativeWindowBuffer** buffer_to_driver) |
333 | { |
334 | - int ret = 0; |
335 | - auto buffer = surface->get_current_buffer(); |
336 | - *buffer_to_driver = buffer->get_native_handle(); |
337 | - (*buffer_to_driver)->format = driver_pixel_format; |
338 | - return ret; |
339 | + *buffer_to_driver = driver_interpreter->driver_requests_buffer(); |
340 | + return 0; |
341 | } |
342 | |
343 | -static void empty(MirSurface * /*surface*/, void * /*client_context*/) |
344 | -{} |
345 | -int mcla::MirNativeWindow::queueBuffer(struct ANativeWindowBuffer* /*buffer*/) |
346 | +int mcla::MirNativeWindow::queueBuffer(struct ANativeWindowBuffer* buffer, int fence_fd) |
347 | { |
348 | - mir_wait_for(surface->next_buffer(empty, NULL)); |
349 | + driver_interpreter->driver_returns_buffer(buffer, fence_fd); |
350 | return 0; |
351 | } |
352 | |
353 | int mcla::MirNativeWindow::query(int key, int* value ) const |
354 | { |
355 | - int ret = 0; |
356 | - switch (key) |
357 | - { |
358 | - case NATIVE_WINDOW_WIDTH: |
359 | - case NATIVE_WINDOW_DEFAULT_WIDTH: |
360 | - *value = surface->get_parameters().width; |
361 | - break; |
362 | - case NATIVE_WINDOW_HEIGHT: |
363 | - case NATIVE_WINDOW_DEFAULT_HEIGHT: |
364 | - *value = surface->get_parameters().height; |
365 | - break; |
366 | - case NATIVE_WINDOW_FORMAT: |
367 | - *value = driver_pixel_format; |
368 | - break; |
369 | - case NATIVE_WINDOW_TRANSFORM_HINT: |
370 | - *value = 0; /* transform hint is a bitmask. 0 means no transform */ |
371 | - break; |
372 | - default: |
373 | - ret = -1; |
374 | - break; |
375 | - } |
376 | - return ret; |
377 | + *value = driver_interpreter->driver_requests_info(key); |
378 | + return 0; |
379 | } |
380 | |
381 | int mcla::MirNativeWindow::perform(int key, va_list arg_list ) |
382 | @@ -159,10 +164,12 @@ |
383 | va_list args; |
384 | va_copy(args, arg_list); |
385 | |
386 | + int driver_format; |
387 | switch(key) |
388 | { |
389 | case NATIVE_WINDOW_SET_BUFFERS_FORMAT: |
390 | - driver_pixel_format = va_arg(args, int); |
391 | + driver_format = va_arg(args, int); |
392 | + driver_interpreter->dispatch_driver_request_format(driver_format); |
393 | break; |
394 | default: |
395 | break; |
396 | |
397 | === modified file 'src/client/android/mir_native_window.h' |
398 | --- src/client/android/mir_native_window.h 2013-03-07 08:04:05 +0000 |
399 | +++ src/client/android/mir_native_window.h 2013-03-12 15:51:13 +0000 |
400 | @@ -22,6 +22,7 @@ |
401 | #include "../mir_client_surface.h" |
402 | #include <system/window.h> |
403 | #include <cstdarg> |
404 | +#include <memory> |
405 | |
406 | namespace mir |
407 | { |
408 | @@ -29,20 +30,20 @@ |
409 | { |
410 | namespace android |
411 | { |
412 | +class AndroidDriverInterpreter; |
413 | |
414 | class MirNativeWindow : public ANativeWindow |
415 | { |
416 | public: |
417 | - explicit MirNativeWindow(ClientSurface* surface); |
418 | + explicit MirNativeWindow(std::shared_ptr<AndroidDriverInterpreter> const& interpreter); |
419 | |
420 | int query(int key, int* value) const; |
421 | int perform(int key, va_list args ); |
422 | int dequeueBuffer(struct ANativeWindowBuffer** buffer); |
423 | - int queueBuffer(struct ANativeWindowBuffer* buffer); |
424 | + int queueBuffer(struct ANativeWindowBuffer* buffer, int fence_fd); |
425 | private: |
426 | |
427 | - ClientSurface * surface; |
428 | - int driver_pixel_format; |
429 | + std::shared_ptr<AndroidDriverInterpreter> const driver_interpreter; |
430 | }; |
431 | |
432 | } |
433 | |
434 | === modified file 'tests/unit-tests/client/CMakeLists.txt' |
435 | --- tests/unit-tests/client/CMakeLists.txt 2013-03-08 07:20:43 +0000 |
436 | +++ tests/unit-tests/client/CMakeLists.txt 2013-03-12 15:51:13 +0000 |
437 | @@ -13,6 +13,7 @@ |
438 | ${CMAKE_CURRENT_SOURCE_DIR}/test_android_native_window.cpp |
439 | ${CMAKE_CURRENT_SOURCE_DIR}/test_android_client_depository.cpp |
440 | ${CMAKE_CURRENT_SOURCE_DIR}/test_android_client_platform.cpp |
441 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_client_surface_interpreter.cpp |
442 | ) |
443 | endif() |
444 | |
445 | |
446 | === modified file 'tests/unit-tests/client/test_android_native_window.cpp' |
447 | --- tests/unit-tests/client/test_android_native_window.cpp 2013-03-07 08:04:05 +0000 |
448 | +++ tests/unit-tests/client/test_android_native_window.cpp 2013-03-12 15:51:13 +0000 |
449 | @@ -18,54 +18,22 @@ |
450 | |
451 | #include "src/client/mir_client_surface.h" |
452 | #include "src/client/android/mir_native_window.h" |
453 | -#include "src/client/client_buffer.h" |
454 | +#include "src/client/android/android_driver_interpreter.h" |
455 | + |
456 | #include <gmock/gmock.h> |
457 | #include <gtest/gtest.h> |
458 | #include <memory> |
459 | -namespace mcl=mir::client; |
460 | namespace mcla=mir::client::android; |
461 | -namespace geom=mir::geometry; |
462 | |
463 | namespace |
464 | { |
465 | -struct MockClientBuffer : public mcl::ClientBuffer |
466 | -{ |
467 | - MockClientBuffer() |
468 | - { |
469 | - using namespace testing; |
470 | - ON_CALL(*this, get_native_handle()) |
471 | - .WillByDefault(Return(&buffer)); |
472 | - } |
473 | - MOCK_METHOD0(secure_for_cpu_write, std::shared_ptr<mcl::MemoryRegion>()); |
474 | - MOCK_CONST_METHOD0(size, geom::Size()); |
475 | - MOCK_CONST_METHOD0(stride, geom::Stride()); |
476 | - MOCK_CONST_METHOD0(pixel_format, geom::PixelFormat()); |
477 | - |
478 | - MOCK_CONST_METHOD0(get_buffer_package, std::shared_ptr<MirBufferPackage>()); |
479 | - MOCK_METHOD0(get_native_handle, ANativeWindowBuffer*()); |
480 | - |
481 | - ANativeWindowBuffer buffer; |
482 | - native_handle_t handle; |
483 | -}; |
484 | - |
485 | -struct MockMirSurface : public mcl::ClientSurface |
486 | -{ |
487 | - MockMirSurface(MirSurfaceParameters params) |
488 | - : params(params) |
489 | - { |
490 | - using namespace testing; |
491 | - ON_CALL(*this, get_parameters()) |
492 | - .WillByDefault(Return(params)); |
493 | - ON_CALL(*this, get_current_buffer()) |
494 | - .WillByDefault(Return( |
495 | - std::make_shared<NiceMock<MockClientBuffer>>())); |
496 | - } |
497 | - |
498 | - MOCK_CONST_METHOD0(get_parameters, MirSurfaceParameters()); |
499 | - MOCK_METHOD0(get_current_buffer, std::shared_ptr<mcl::ClientBuffer>()); |
500 | - MOCK_METHOD2(next_buffer, MirWaitHandle*(mir_surface_lifecycle_callback callback, void * context)); |
501 | - |
502 | - MirSurfaceParameters params; |
503 | +class MockAndroidDriverInterpreter : public mcla::AndroidDriverInterpreter |
504 | +{ |
505 | +public: |
506 | + MOCK_METHOD0(driver_requests_buffer, ANativeWindowBuffer*()); |
507 | + MOCK_METHOD2(driver_returns_buffer, void(ANativeWindowBuffer*, int)); |
508 | + MOCK_METHOD1(dispatch_driver_request_format, void(int)); |
509 | + MOCK_CONST_METHOD1(driver_requests_info, int(int)); |
510 | }; |
511 | } |
512 | |
513 | @@ -75,333 +43,215 @@ |
514 | virtual void SetUp() |
515 | { |
516 | using namespace testing; |
517 | - surf_params.width = 530; |
518 | - surf_params.height = 715; |
519 | - surf_params.pixel_format = mir_pixel_format_abgr_8888; |
520 | |
521 | - mock_surface = std::make_shared<NiceMock<MockMirSurface>>(surf_params); |
522 | - mock_client_buffer = |
523 | - std::make_shared<NiceMock<MockClientBuffer>>(); |
524 | + mock_driver_interpreter = std::make_shared<NiceMock<MockAndroidDriverInterpreter>>(); |
525 | } |
526 | |
527 | - MirSurfaceParameters surf_params; |
528 | - std::shared_ptr<MockMirSurface> mock_surface; |
529 | - std::shared_ptr<MockClientBuffer> mock_client_buffer; |
530 | + std::shared_ptr<MockAndroidDriverInterpreter> mock_driver_interpreter; |
531 | }; |
532 | |
533 | /* Query hook tests */ |
534 | -TEST_F(AndroidNativeWindowTest, native_window_query_hook_callable) |
535 | -{ |
536 | - ANativeWindow* anw; |
537 | - int value; |
538 | - |
539 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
540 | - |
541 | - ASSERT_NE(nullptr, anw->query); |
542 | - EXPECT_NO_THROW({ |
543 | - anw->query(anw, NATIVE_WINDOW_WIDTH ,&value); |
544 | - }); |
545 | - |
546 | - |
547 | - delete anw; |
548 | -} |
549 | - |
550 | -TEST_F(AndroidNativeWindowTest, native_window_width_query_hook) |
551 | -{ |
552 | - using namespace testing; |
553 | - ANativeWindow* anw; |
554 | - int value; |
555 | - |
556 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
557 | - |
558 | - EXPECT_CALL(*mock_surface, get_parameters()) |
559 | - .Times(1); |
560 | - |
561 | - auto rc = anw->query(anw, NATIVE_WINDOW_WIDTH ,&value); |
562 | - |
563 | - EXPECT_EQ(0, rc); |
564 | - EXPECT_EQ(surf_params.width, value); |
565 | - |
566 | - delete anw; |
567 | -} |
568 | - |
569 | -TEST_F(AndroidNativeWindowTest, native_window_height_query_hook) |
570 | -{ |
571 | - using namespace testing; |
572 | - ANativeWindow* anw; |
573 | - int value; |
574 | - |
575 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
576 | - EXPECT_CALL(*mock_surface, get_parameters()) |
577 | - .Times(1); |
578 | - |
579 | - auto rc = anw->query(anw, NATIVE_WINDOW_HEIGHT ,&value); |
580 | - |
581 | - EXPECT_EQ(0, rc); |
582 | - EXPECT_EQ(surf_params.height, value); |
583 | - |
584 | - delete anw; |
585 | -} |
586 | - |
587 | -TEST_F(AndroidNativeWindowTest, native_window_hint_query_hook) |
588 | -{ |
589 | - using namespace testing; |
590 | - ANativeWindow* anw; |
591 | - /* transform hint is a bitmask of a few options for rotation/flipping buffer. a value |
592 | - of zero is no transform */ |
593 | - int transform_hint_zero = 0; |
594 | - int value; |
595 | - |
596 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
597 | - |
598 | - auto rc = anw->query(anw, NATIVE_WINDOW_TRANSFORM_HINT ,&value); |
599 | - |
600 | - EXPECT_EQ(0, rc); |
601 | - EXPECT_EQ(transform_hint_zero, value); |
602 | - |
603 | - delete anw; |
604 | -} |
605 | - |
606 | -TEST_F(AndroidNativeWindowTest, native_window_default_width_query_hook) |
607 | -{ |
608 | - using namespace testing; |
609 | - ANativeWindow* anw; |
610 | - int value; |
611 | - |
612 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
613 | - |
614 | - auto rc = anw->query(anw, NATIVE_WINDOW_DEFAULT_WIDTH ,&value); |
615 | - |
616 | - EXPECT_EQ(0, rc); |
617 | - EXPECT_EQ(surf_params.width, value); |
618 | - |
619 | - delete anw; |
620 | -} |
621 | - |
622 | -TEST_F(AndroidNativeWindowTest, native_window_default_height_query_hook) |
623 | -{ |
624 | - using namespace testing; |
625 | - ANativeWindow* anw; |
626 | - int value; |
627 | - |
628 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
629 | - |
630 | - auto rc = anw->query(anw, NATIVE_WINDOW_DEFAULT_HEIGHT ,&value); |
631 | - |
632 | - EXPECT_EQ(0, rc); |
633 | - EXPECT_EQ(surf_params.height, value); |
634 | - |
635 | - delete anw; |
636 | +TEST_F(AndroidNativeWindowTest, native_window_query_hook) |
637 | +{ |
638 | + using namespace testing; |
639 | + |
640 | + int returned_width, width = 271828; |
641 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
642 | + |
643 | + ASSERT_NE(nullptr, window->query); |
644 | + EXPECT_CALL(*mock_driver_interpreter, driver_requests_info(NATIVE_WINDOW_WIDTH)) |
645 | + .Times(1) |
646 | + .WillOnce(Return(width)); |
647 | + |
648 | + window->query(window.get(), NATIVE_WINDOW_WIDTH ,&returned_width); |
649 | + |
650 | + EXPECT_EQ(width, returned_width); |
651 | } |
652 | |
653 | /* perform hook tests */ |
654 | TEST_F(AndroidNativeWindowTest, native_window_perform_hook_callable) |
655 | { |
656 | - ANativeWindow* anw; |
657 | - |
658 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
659 | - |
660 | - ASSERT_NE(nullptr, anw->perform); |
661 | - EXPECT_NO_THROW({ |
662 | - anw->perform(anw, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS , 40, 22); |
663 | - }); |
664 | - |
665 | - delete anw; |
666 | -} |
667 | - |
668 | -/* format is an int that is set by the driver. these are not the HAL_PIXEL_FORMATS in android */ |
669 | -TEST_F(AndroidNativeWindowTest, native_window_perform_remembers_format) |
670 | -{ |
671 | - ANativeWindow* anw; |
672 | - int format = 945; |
673 | - |
674 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
675 | - |
676 | - anw->perform(anw, NATIVE_WINDOW_SET_BUFFERS_FORMAT , format); |
677 | - |
678 | - int tmp_format = 0; |
679 | - anw->query(anw, NATIVE_WINDOW_FORMAT, &tmp_format); |
680 | - |
681 | - EXPECT_EQ(tmp_format, format); |
682 | - |
683 | - delete anw; |
684 | + int format = 4; |
685 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
686 | + |
687 | + EXPECT_CALL(*mock_driver_interpreter, dispatch_driver_request_format(format)) |
688 | + .Times(1); |
689 | + |
690 | + ASSERT_NE(nullptr, window->perform); |
691 | + window->perform(window.get(), NATIVE_WINDOW_SET_BUFFERS_FORMAT, format); |
692 | } |
693 | |
694 | /* setSwapInterval hook tests */ |
695 | TEST_F(AndroidNativeWindowTest, native_window_setswapinterval_hook_callable) |
696 | { |
697 | - ANativeWindow* anw; |
698 | - |
699 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
700 | - |
701 | - ASSERT_NE(nullptr, anw->setSwapInterval); |
702 | - EXPECT_NO_THROW({ |
703 | - anw->setSwapInterval(anw, 22); |
704 | - }); |
705 | - |
706 | - delete anw; |
707 | + int swap = 2; |
708 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
709 | + |
710 | + ASSERT_NE(nullptr, window->setSwapInterval); |
711 | + window->setSwapInterval(window.get(), swap); |
712 | } |
713 | |
714 | /* dequeue hook tests */ |
715 | TEST_F(AndroidNativeWindowTest, native_window_dequeue_hook_callable) |
716 | { |
717 | - ANativeWindow* anw; |
718 | - ANativeWindowBuffer* tmp; |
719 | - |
720 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
721 | - |
722 | - ASSERT_NE(nullptr, anw->dequeueBuffer_DEPRECATED); |
723 | - EXPECT_NO_THROW({ |
724 | - anw->dequeueBuffer_DEPRECATED(anw, &tmp); |
725 | - }); |
726 | - |
727 | - delete anw; |
728 | -} |
729 | - |
730 | -TEST_F(AndroidNativeWindowTest, native_window_dequeue_calls_surface_get_current) |
731 | -{ |
732 | - using namespace testing; |
733 | - ANativeWindow* anw; |
734 | - ANativeWindowBuffer* tmp; |
735 | - |
736 | - EXPECT_CALL(*mock_surface, get_current_buffer()) |
737 | - .Times(1) |
738 | - .WillOnce(Return(mock_client_buffer)); |
739 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
740 | - |
741 | - anw->dequeueBuffer_DEPRECATED(anw, &tmp); |
742 | - |
743 | - delete anw; |
744 | -} |
745 | - |
746 | -TEST_F(AndroidNativeWindowTest, native_window_dequeue_gets_native_handle_from_returned_buffer) |
747 | -{ |
748 | - using namespace testing; |
749 | - ANativeWindow* anw; |
750 | - native_handle_t handle; |
751 | - ANativeWindowBuffer buffer; |
752 | - buffer.handle = &handle; |
753 | - |
754 | - ANativeWindowBuffer* tmp; |
755 | - |
756 | - EXPECT_CALL(*mock_client_buffer, get_native_handle()) |
757 | - .Times(1) |
758 | - .WillOnce(Return(&buffer)); |
759 | - EXPECT_CALL(*mock_surface, get_current_buffer()) |
760 | - .Times(1) |
761 | - .WillOnce(Return(mock_client_buffer)); |
762 | - |
763 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
764 | - |
765 | - anw->dequeueBuffer_DEPRECATED(anw, &tmp); |
766 | - |
767 | - EXPECT_EQ(tmp, &buffer); |
768 | - delete anw; |
769 | -} |
770 | - |
771 | -TEST_F(AndroidNativeWindowTest, native_window_dequeue_has_proper_rc) |
772 | -{ |
773 | - using namespace testing; |
774 | - ANativeWindow* anw; |
775 | - |
776 | - ANativeWindowBuffer* tmp; |
777 | - |
778 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
779 | - |
780 | - auto ret = anw->dequeueBuffer_DEPRECATED(anw, &tmp); |
781 | - EXPECT_EQ(0, ret); |
782 | - |
783 | - delete anw; |
784 | + ANativeWindowBuffer* returned_buffer; |
785 | + int fence_fd; |
786 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
787 | + |
788 | + ASSERT_NE(nullptr, window->dequeueBuffer); |
789 | + window->dequeueBuffer(window.get(), &returned_buffer, &fence_fd); |
790 | +} |
791 | + |
792 | +TEST_F(AndroidNativeWindowTest, native_window_dequeue_returns_right_buffer) |
793 | +{ |
794 | + using namespace testing; |
795 | + |
796 | + ANativeWindowBuffer* returned_buffer; |
797 | + ANativeWindowBuffer fake_buffer; |
798 | + int fence_fd; |
799 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
800 | + |
801 | + EXPECT_CALL(*mock_driver_interpreter, driver_requests_buffer()) |
802 | + .Times(1) |
803 | + .WillOnce(Return(&fake_buffer)); |
804 | + |
805 | + window->dequeueBuffer(window.get(), &returned_buffer, &fence_fd); |
806 | + |
807 | + EXPECT_EQ(&fake_buffer, returned_buffer); |
808 | +} |
809 | + |
810 | + |
811 | +TEST_F(AndroidNativeWindowTest, native_window_dequeue_indicates_buffer_immediately_usable) |
812 | +{ |
813 | + ANativeWindowBuffer* returned_buffer; |
814 | + int fence_fd; |
815 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
816 | + |
817 | + window->dequeueBuffer(window.get(), &returned_buffer, &fence_fd); |
818 | + EXPECT_EQ(-1, fence_fd); |
819 | +} |
820 | + |
821 | +TEST_F(AndroidNativeWindowTest, native_window_dequeue_deprecated_hook_callable) |
822 | +{ |
823 | + ANativeWindowBuffer* tmp; |
824 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
825 | + |
826 | + ASSERT_NE(nullptr, window->dequeueBuffer_DEPRECATED); |
827 | + window->dequeueBuffer_DEPRECATED(window.get(), &tmp); |
828 | +} |
829 | + |
830 | +TEST_F(AndroidNativeWindowTest, native_window_dequeue_deprecated_returns_right_buffer) |
831 | +{ |
832 | + using namespace testing; |
833 | + |
834 | + ANativeWindowBuffer* returned_buffer; |
835 | + ANativeWindowBuffer fake_buffer; |
836 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
837 | + |
838 | + EXPECT_CALL(*mock_driver_interpreter, driver_requests_buffer()) |
839 | + .Times(1) |
840 | + .WillOnce(Return(&fake_buffer)); |
841 | + |
842 | + window->dequeueBuffer_DEPRECATED(window.get(), &returned_buffer); |
843 | + EXPECT_EQ(&fake_buffer, returned_buffer); |
844 | } |
845 | |
846 | /* queue hook tests */ |
847 | TEST_F(AndroidNativeWindowTest, native_window_queue_hook_callable) |
848 | { |
849 | - ANativeWindow* anw; |
850 | - ANativeWindowBuffer* tmp = 0x0; |
851 | - |
852 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
853 | - |
854 | - ASSERT_NE(nullptr, anw->queueBuffer_DEPRECATED); |
855 | - EXPECT_NO_THROW({ |
856 | - anw->queueBuffer_DEPRECATED(anw, tmp); |
857 | - }); |
858 | - |
859 | - delete anw; |
860 | -} |
861 | - |
862 | -TEST_F(AndroidNativeWindowTest, native_window_queue_advances_buffer) |
863 | -{ |
864 | - using namespace testing; |
865 | - ANativeWindow* anw; |
866 | - ANativeWindowBuffer* tmp = 0x0; |
867 | - |
868 | - EXPECT_CALL(*mock_surface, next_buffer(_,_)) |
869 | - .Times(1); |
870 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
871 | - |
872 | - anw->queueBuffer_DEPRECATED(anw, tmp); |
873 | - |
874 | - delete anw; |
875 | + ANativeWindowBuffer* tmp = nullptr; |
876 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
877 | + |
878 | + ASSERT_NE(nullptr, window->queueBuffer); |
879 | + window->queueBuffer(window.get(), tmp, -1); |
880 | +} |
881 | + |
882 | +TEST_F(AndroidNativeWindowTest, native_window_queue_passes_buffer_and_fence_back) |
883 | +{ |
884 | + ANativeWindowBuffer buffer; |
885 | + int fence_fd = 33; |
886 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
887 | + |
888 | + EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer, fence_fd)) |
889 | + .Times(1); |
890 | + |
891 | + window->queueBuffer(window.get(), &buffer, fence_fd); |
892 | +} |
893 | + |
894 | +TEST_F(AndroidNativeWindowTest, native_window_queue_deprecated_hook_callable) |
895 | +{ |
896 | + ANativeWindowBuffer* tmp = nullptr; |
897 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
898 | + |
899 | + ASSERT_NE(nullptr, window->queueBuffer_DEPRECATED); |
900 | + window->queueBuffer_DEPRECATED(window.get(), tmp); |
901 | +} |
902 | + |
903 | +TEST_F(AndroidNativeWindowTest, native_window_queue_deprecated_always_indicates_no_wait) |
904 | +{ |
905 | + ANativeWindowBuffer buffer; |
906 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
907 | + |
908 | + EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer, -1)) |
909 | + .Times(1); |
910 | + |
911 | + window->queueBuffer_DEPRECATED(window.get(), &buffer); |
912 | } |
913 | |
914 | /* cancel hook tests */ |
915 | -TEST_F(AndroidNativeWindowTest, native_window_cancel_hook_callable) |
916 | +TEST_F(AndroidNativeWindowTest, native_window_cancel_hooks_callable) |
917 | { |
918 | - ANativeWindow* anw; |
919 | - ANativeWindowBuffer* tmp = 0x0; |
920 | - |
921 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
922 | - |
923 | - ASSERT_NE(nullptr, anw->cancelBuffer_DEPRECATED); |
924 | - EXPECT_NO_THROW({ |
925 | - anw->cancelBuffer_DEPRECATED(anw, tmp); |
926 | - }); |
927 | - |
928 | - delete anw; |
929 | + ANativeWindowBuffer* tmp = nullptr; |
930 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
931 | + |
932 | + ASSERT_NE(nullptr, window->cancelBuffer_DEPRECATED); |
933 | + ASSERT_NE(nullptr, window->cancelBuffer); |
934 | + window->cancelBuffer_DEPRECATED(window.get(), tmp); |
935 | + window->cancelBuffer(window.get(), tmp, -1); |
936 | } |
937 | |
938 | /* lock hook tests */ |
939 | TEST_F(AndroidNativeWindowTest, native_window_lock_hook_callable) |
940 | { |
941 | - ANativeWindow* anw; |
942 | ANativeWindowBuffer* tmp = 0x0; |
943 | - |
944 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
945 | - |
946 | - ASSERT_NE(nullptr, anw->lockBuffer_DEPRECATED); |
947 | - EXPECT_NO_THROW({ |
948 | - anw->lockBuffer_DEPRECATED(anw, tmp); |
949 | - }); |
950 | - |
951 | - delete anw; |
952 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
953 | + |
954 | + ASSERT_NE(nullptr, window->lockBuffer_DEPRECATED); |
955 | + window->lockBuffer_DEPRECATED(window.get(), tmp); |
956 | } |
957 | -/* incRef is reffable */ |
958 | + |
959 | TEST_F(AndroidNativeWindowTest, native_window_incref_hook_callable) |
960 | { |
961 | - ANativeWindow* anw; |
962 | - |
963 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
964 | - |
965 | - ASSERT_NE(nullptr, anw->common.incRef); |
966 | - EXPECT_NO_THROW({ |
967 | - anw->common.incRef(NULL); |
968 | - }); |
969 | - |
970 | - delete anw; |
971 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
972 | + |
973 | + ASSERT_NE(nullptr, window->common.incRef); |
974 | + window->common.incRef(NULL); |
975 | } |
976 | |
977 | -/* decRef is reffable */ |
978 | TEST_F(AndroidNativeWindowTest, native_window_decref_hook_callable) |
979 | { |
980 | - ANativeWindow* anw; |
981 | - |
982 | - anw = new mcla::MirNativeWindow(mock_surface.get()); |
983 | - |
984 | - ASSERT_NE(nullptr, anw->common.decRef); |
985 | - EXPECT_NO_THROW({ |
986 | - anw->common.decRef(NULL); |
987 | - }); |
988 | - |
989 | - delete anw; |
990 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
991 | + |
992 | + ASSERT_NE(nullptr, window->common.decRef); |
993 | + window->common.decRef(NULL); |
994 | +} |
995 | + |
996 | +TEST_F(AndroidNativeWindowTest, native_window_dequeue_deprecated_has_proper_rc) |
997 | +{ |
998 | + ANativeWindowBuffer* tmp; |
999 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
1000 | + |
1001 | + auto ret = window->dequeueBuffer_DEPRECATED(window.get(), &tmp); |
1002 | + EXPECT_EQ(0, ret); |
1003 | +} |
1004 | + |
1005 | +TEST_F(AndroidNativeWindowTest, native_window_dequeue_has_proper_rc) |
1006 | +{ |
1007 | + ANativeWindowBuffer* tmp; |
1008 | + int fencefd; |
1009 | + |
1010 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mcla::MirNativeWindow>(mock_driver_interpreter); |
1011 | + |
1012 | + auto ret = window->dequeueBuffer(window.get(), &tmp, &fencefd); |
1013 | + EXPECT_EQ(0, ret); |
1014 | } |
1015 | |
1016 | === added file 'tests/unit-tests/client/test_client_surface_interpreter.cpp' |
1017 | --- tests/unit-tests/client/test_client_surface_interpreter.cpp 1970-01-01 00:00:00 +0000 |
1018 | +++ tests/unit-tests/client/test_client_surface_interpreter.cpp 2013-03-12 15:51:13 +0000 |
1019 | @@ -0,0 +1,202 @@ |
1020 | +/* |
1021 | + * Copyright © 2013 Canonical Ltd. |
1022 | + * |
1023 | + * This program is free software: you can redistribute it and/or modify |
1024 | + * it under the terms of the GNU General Public License version 3 as |
1025 | + * published by the Free Software Foundation. |
1026 | + * |
1027 | + * This program is distributed in the hope that it will be useful, |
1028 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1029 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1030 | + * GNU General Public License for more details. |
1031 | + * |
1032 | + * You should have received a copy of the GNU General Public License |
1033 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1034 | + * |
1035 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
1036 | + */ |
1037 | + |
1038 | +#include "src/client/mir_client_surface.h" |
1039 | +#include "src/client/client_buffer.h" |
1040 | +#include "src/client/android/client_surface_interpreter.h" |
1041 | +#include <system/window.h> |
1042 | +#include <gmock/gmock.h> |
1043 | +#include <gtest/gtest.h> |
1044 | + |
1045 | +namespace mcl=mir::client; |
1046 | +namespace mcla=mir::client::android; |
1047 | +namespace geom=mir::geometry; |
1048 | + |
1049 | +namespace |
1050 | +{ |
1051 | +struct MockClientBuffer : public mcl::ClientBuffer |
1052 | +{ |
1053 | + MockClientBuffer() |
1054 | + { |
1055 | + using namespace testing; |
1056 | + ON_CALL(*this, get_native_handle()) |
1057 | + .WillByDefault(Return(&buffer)); |
1058 | + } |
1059 | + MOCK_METHOD0(secure_for_cpu_write, std::shared_ptr<mcl::MemoryRegion>()); |
1060 | + MOCK_CONST_METHOD0(size, geom::Size()); |
1061 | + MOCK_CONST_METHOD0(stride, geom::Stride()); |
1062 | + MOCK_CONST_METHOD0(pixel_format, geom::PixelFormat()); |
1063 | + |
1064 | + MOCK_CONST_METHOD0(get_buffer_package, std::shared_ptr<MirBufferPackage>()); |
1065 | + MOCK_METHOD0(get_native_handle, ANativeWindowBuffer*()); |
1066 | + |
1067 | + ANativeWindowBuffer buffer; |
1068 | + native_handle_t handle; |
1069 | +}; |
1070 | + |
1071 | +struct MockMirSurface : public mcl::ClientSurface |
1072 | +{ |
1073 | + MockMirSurface(MirSurfaceParameters params) |
1074 | + : params(params) |
1075 | + { |
1076 | + using namespace testing; |
1077 | + ON_CALL(*this, get_parameters()) |
1078 | + .WillByDefault(Return(params)); |
1079 | + ON_CALL(*this, get_current_buffer()) |
1080 | + .WillByDefault(Return( |
1081 | + std::make_shared<NiceMock<MockClientBuffer>>())); |
1082 | + } |
1083 | + |
1084 | + MOCK_CONST_METHOD0(get_parameters, MirSurfaceParameters()); |
1085 | + MOCK_METHOD0(get_current_buffer, std::shared_ptr<mcl::ClientBuffer>()); |
1086 | + MOCK_METHOD2(next_buffer, MirWaitHandle*(mir_surface_lifecycle_callback callback, void * context)); |
1087 | + |
1088 | + MirSurfaceParameters params; |
1089 | +}; |
1090 | +} |
1091 | + |
1092 | +class AndroidInterpreterTest : public ::testing::Test |
1093 | +{ |
1094 | +protected: |
1095 | + virtual void SetUp() |
1096 | + { |
1097 | + using namespace testing; |
1098 | + surf_params.width = 530; |
1099 | + surf_params.height = 715; |
1100 | + surf_params.pixel_format = mir_pixel_format_abgr_8888; |
1101 | + |
1102 | + mock_client_buffer = std::make_shared<NiceMock<MockClientBuffer>>(); |
1103 | + } |
1104 | + |
1105 | + MirSurfaceParameters surf_params; |
1106 | + std::shared_ptr<MockClientBuffer> mock_client_buffer; |
1107 | +}; |
1108 | + |
1109 | +TEST_F(AndroidInterpreterTest, native_window_dequeue_calls_surface_get_current) |
1110 | +{ |
1111 | + using namespace testing; |
1112 | + MockMirSurface mock_surface{surf_params}; |
1113 | + mcla::ClientSurfaceInterpreter interpreter(mock_surface); |
1114 | + |
1115 | + EXPECT_CALL(mock_surface, get_current_buffer()) |
1116 | + .Times(1) |
1117 | + .WillOnce(Return(mock_client_buffer)); |
1118 | + |
1119 | + interpreter.driver_requests_buffer(); |
1120 | +} |
1121 | + |
1122 | +TEST_F(AndroidInterpreterTest, native_window_dequeue_gets_native_handle_from_returned_buffer) |
1123 | +{ |
1124 | + using namespace testing; |
1125 | + native_handle_t handle; |
1126 | + ANativeWindowBuffer buffer; |
1127 | + buffer.handle = &handle; |
1128 | + |
1129 | + MockMirSurface mock_surface{surf_params}; |
1130 | + mcla::ClientSurfaceInterpreter interpreter(mock_surface); |
1131 | + |
1132 | + EXPECT_CALL(*mock_client_buffer, get_native_handle()) |
1133 | + .Times(1) |
1134 | + .WillOnce(Return(&buffer)); |
1135 | + EXPECT_CALL(mock_surface, get_current_buffer()) |
1136 | + .Times(1) |
1137 | + .WillOnce(Return(mock_client_buffer)); |
1138 | + |
1139 | + auto returned_buffer = interpreter.driver_requests_buffer(); |
1140 | + EXPECT_EQ(&buffer, returned_buffer); |
1141 | +} |
1142 | + |
1143 | +TEST_F(AndroidInterpreterTest, native_window_queue_advances_buffer) |
1144 | +{ |
1145 | + using namespace testing; |
1146 | + ANativeWindowBuffer buffer; |
1147 | + int fence_fd = -1; |
1148 | + |
1149 | + MockMirSurface mock_surface{surf_params}; |
1150 | + mcla::ClientSurfaceInterpreter interpreter(mock_surface); |
1151 | + |
1152 | + EXPECT_CALL(mock_surface, next_buffer(_,_)) |
1153 | + .Times(1); |
1154 | + |
1155 | + interpreter.driver_returns_buffer(&buffer, fence_fd); |
1156 | +} |
1157 | + |
1158 | +/* format is an int that is set by the driver. these are not the HAL_PIXEL_FORMATS in android */ |
1159 | +TEST_F(AndroidInterpreterTest, native_window_perform_remembers_format) |
1160 | +{ |
1161 | + int format = 945; |
1162 | + MockMirSurface mock_surface{surf_params}; |
1163 | + mcla::ClientSurfaceInterpreter interpreter(mock_surface); |
1164 | + |
1165 | + interpreter.dispatch_driver_request_format(format); |
1166 | + auto tmp_format = interpreter.driver_requests_info(NATIVE_WINDOW_FORMAT); |
1167 | + |
1168 | + EXPECT_EQ(format, tmp_format); |
1169 | +} |
1170 | + |
1171 | +TEST_F(AndroidInterpreterTest, native_window_hint_query_hook) |
1172 | +{ |
1173 | + MockMirSurface mock_surface{surf_params}; |
1174 | + mcla::ClientSurfaceInterpreter interpreter(mock_surface); |
1175 | + /* transform hint is a bitmask of a few options for rotation/flipping buffer. a value |
1176 | + of zero is no transform */ |
1177 | + int transform_hint_zero = 0; |
1178 | + auto transform = interpreter.driver_requests_info(NATIVE_WINDOW_TRANSFORM_HINT); |
1179 | + |
1180 | + EXPECT_EQ(transform_hint_zero, transform); |
1181 | +} |
1182 | + |
1183 | +TEST_F(AndroidInterpreterTest, native_window_default_width_query_hook) |
1184 | +{ |
1185 | + MockMirSurface mock_surface{surf_params}; |
1186 | + mcla::ClientSurfaceInterpreter interpreter(mock_surface); |
1187 | + |
1188 | + auto default_width = interpreter.driver_requests_info(NATIVE_WINDOW_DEFAULT_WIDTH); |
1189 | + |
1190 | + EXPECT_EQ(surf_params.width, default_width); |
1191 | +} |
1192 | + |
1193 | +TEST_F(AndroidInterpreterTest, native_window_default_height_query_hook) |
1194 | +{ |
1195 | + MockMirSurface mock_surface{surf_params}; |
1196 | + mcla::ClientSurfaceInterpreter interpreter(mock_surface); |
1197 | + |
1198 | + auto default_height = interpreter.driver_requests_info(NATIVE_WINDOW_DEFAULT_HEIGHT); |
1199 | + |
1200 | + EXPECT_EQ(surf_params.height, default_height); |
1201 | +} |
1202 | + |
1203 | +TEST_F(AndroidInterpreterTest, native_window_width_query_hook) |
1204 | +{ |
1205 | + MockMirSurface mock_surface{surf_params}; |
1206 | + mcla::ClientSurfaceInterpreter interpreter(mock_surface); |
1207 | + |
1208 | + auto width = interpreter.driver_requests_info(NATIVE_WINDOW_WIDTH); |
1209 | + |
1210 | + EXPECT_EQ(surf_params.width, width); |
1211 | +} |
1212 | + |
1213 | +TEST_F(AndroidInterpreterTest, native_window_height_query_hook) |
1214 | +{ |
1215 | + MockMirSurface mock_surface{surf_params}; |
1216 | + mcla::ClientSurfaceInterpreter interpreter(mock_surface); |
1217 | + |
1218 | + auto height = interpreter.driver_requests_info(NATIVE_WINDOW_HEIGHT); |
1219 | + |
1220 | + EXPECT_EQ(surf_params.height, height); |
1221 | +} |
PASSED: Continuous integration, rev:493 jenkins. qa.ubuntu. com/job/ mir-ci/ 14/ jenkins. qa.ubuntu. com/job/ mir-quantal- amd64-ci/ 14//console
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild: jenkins. qa.ubuntu. com/job/ mir-ci/ 14//rebuild/?
http://