Merge lp:~kdub/mir/android-buffer-syncfence into lp:mir
- android-buffer-syncfence
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | kevin gunn |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1132 |
Proposed branch: | lp:~kdub/mir/android-buffer-syncfence |
Merge into: | lp:mir |
Diff against target: |
3871 lines (+1199/-549) 80 files modified
include/platform/mir/graphics/buffer.h (+2/-2) include/shared/mir/graphics/android/android_driver_interpreter.h (+3/-3) include/shared/mir/graphics/android/android_native_buffer.h (+72/-0) include/shared/mir/graphics/android/fence.h (+13/-8) include/shared/mir/graphics/android/mir_native_window.h (+2/-3) include/shared/mir/graphics/android/native_buffer.h (+21/-23) include/shared/mir/graphics/android/sync_fence.h (+33/-10) include/shared/mir/graphics/native_buffer.h (+41/-0) include/test/mir_test/draw/android_graphics.h (+1/-2) include/test/mir_test_doubles/mock_alloc_adaptor.h (+1/-1) include/test/mir_test_doubles/mock_android_native_buffer.h (+59/-0) include/test/mir_test_doubles/mock_buffer.h (+2/-2) include/test/mir_test_doubles/mock_fence.h (+44/-0) include/test/mir_test_doubles/mock_interpreter_resource_cache.h (+3/-1) include/test/mir_test_doubles/stub_buffer.h (+7/-3) src/client/android/android_client_buffer.cpp (+17/-11) src/client/android/android_client_buffer.h (+4/-3) src/client/android/android_client_platform.cpp (+6/-1) src/client/android/android_client_platform.h (+1/-0) src/client/android/client_surface_interpreter.cpp (+14/-5) src/client/android/client_surface_interpreter.h (+10/-2) src/client/client_buffer.h (+3/-2) src/client/client_platform.h (+3/-0) src/client/gbm/gbm_client_platform.cpp (+6/-0) src/client/gbm/gbm_client_platform.h (+1/-0) src/client/mir_client_library.cpp (+1/-2) src/client/mir_surface.cpp (+4/-2) src/client/mir_surface.h (+2/-2) src/server/compositor/temporary_buffers.cpp (+1/-1) src/server/compositor/temporary_buffers.h (+1/-1) src/server/graphics/android/android_alloc_adaptor.cpp (+16/-11) src/server/graphics/android/android_alloc_adaptor.h (+1/-1) src/server/graphics/android/android_buffer_allocator.cpp (+1/-0) src/server/graphics/android/android_platform.cpp (+4/-1) src/server/graphics/android/buffer.cpp (+38/-15) src/server/graphics/android/buffer.h (+10/-3) src/server/graphics/android/default_framebuffer_factory.cpp (+0/-1) src/server/graphics/android/fb_device.cpp (+6/-2) src/server/graphics/android/fb_swapper.h (+1/-1) src/server/graphics/android/graphic_alloc_adaptor.h (+3/-3) src/server/graphics/android/hwc11_device.cpp (+4/-3) src/server/graphics/android/hwc11_device.h (+2/-0) src/server/graphics/android/hwc_layerlist.cpp (+5/-2) src/server/graphics/android/internal_client_window.cpp (+10/-8) src/server/graphics/android/internal_client_window.h (+3/-2) src/server/graphics/android/interpreter_cache.cpp (+24/-3) src/server/graphics/android/interpreter_cache.h (+4/-1) src/server/graphics/android/interpreter_resource_cache.h (+4/-1) src/server/graphics/android/server_render_window.cpp (+11/-12) src/server/graphics/android/server_render_window.h (+2/-10) src/server/graphics/gbm/gbm_platform.cpp (+1/-0) src/shared/graphics/android/CMakeLists.txt (+2/-1) src/shared/graphics/android/android_native_buffer.cpp (+54/-0) src/shared/graphics/android/mir_native_window.cpp (+17/-15) src/shared/graphics/android/refcounted_buffer.cpp (+34/-38) src/shared/graphics/android/syncfence.cpp (+55/-12) tests/draw/android_graphics.cpp (+1/-1) tests/integration-tests/client/test_client_render.cpp (+17/-16) tests/integration-tests/graphics/android/test_buffer_integration.cpp (+2/-1) tests/mir_test_framework/testing_client_options.cpp (+6/-1) tests/mir_test_framework/testing_server_options.cpp (+3/-3) tests/unit-tests/client/android/test_android_native_window.cpp (+32/-32) tests/unit-tests/client/android/test_client_android_buffer.cpp (+17/-13) tests/unit-tests/client/android/test_client_surface_interpreter.cpp (+11/-31) tests/unit-tests/client/test_aging_buffer.cpp (+1/-1) tests/unit-tests/client/test_client_buffer_depository.cpp (+1/-1) tests/unit-tests/client/test_client_mir_surface.cpp (+9/-3) tests/unit-tests/client/test_mir_connection.cpp (+1/-0) tests/unit-tests/graphics/android/CMakeLists.txt (+1/-0) tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp (+30/-28) tests/unit-tests/graphics/android/test_android_platform.cpp (+14/-18) tests/unit-tests/graphics/android/test_buffer.cpp (+41/-16) tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp (+49/-33) tests/unit-tests/graphics/android/test_external_refcount.cpp (+35/-10) tests/unit-tests/graphics/android/test_fb_device.cpp (+6/-6) tests/unit-tests/graphics/android/test_hwc_layerlist.cpp (+15/-14) tests/unit-tests/graphics/android/test_internal_client_interpreter.cpp (+13/-21) tests/unit-tests/graphics/android/test_interpreter_buffer_cache.cpp (+40/-17) tests/unit-tests/graphics/android/test_server_interpreter.cpp (+23/-47) tests/unit-tests/graphics/android/test_sync_fence.cpp (+141/-0) |
To merge this branch: | bzr merge lp:~kdub/mir/android-buffer-syncfence |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexandros Frantzis (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Alan Griffiths | Approve | ||
Daniel van Vugt | Needs Fixing | ||
Review via email: mp+189717@code.launchpad.net |
Commit message
graphics: android: prepare buffers for passing around sync fences. Actual synchronization should not have changed, just making room in mga::Buffer
Description of the change
graphics: android: expand classes so android can pass around sync fences as part of its native type. buffer synchronization points remain the same for ipc clients and composition pass. internal clients (like unity) have had their waits shifted to just before the render pass.
android history lesson!
The tl;dr is that fences allow us to tighten up our synchronization, using buffers exactly as soon as they are ready. This MP expands the native buffer for android, as well as mga::Buffer to transfer fences between the different components easily.
Starting around jellybean (-ish), google introduced the use of the kernel sync driver (/dev/sw_sync) to protect the color buffers associated with each buffer. The sw sync driver distributes fd's that represent fences, and allows the kernel, the userspace, or another process to wait on a synchronization event created earlier. This allows for greater cpu/gpu parallelism. We know exactly when a driver is done using a buffer, and are notified from the kernel across process boundaries. It also lets us submit a bunch of fences to HWC at once, and the kernel atomically (from our perspective), waits for the fences we've submitted, posts the fb, and signals the fences for the buffers that were tied up in the last frame.
mir grew up around gingerbread drivers, so we were not passing sync fences around with buffers, (much like surfaceflinger circa gingerbread). We naively clear the fences whenever we see that there is one. Because google added fences to the driver api after designating ANativeWindowBu
The server native buffer type was still MirNativeBuffer, tying us to c89 compatibility (this type is part of the api). Internally, I redefined the native type returned by mg::Buffer's native_
again, this should not change how we're getting sync, or add any of the aforementioned improvements, most the churn is just re-designating the native type for android so that every buffer has a fence protecting its contents.
PS Jenkins bot (ps-jenkins) wrote : | # |
Kevin DuBois (kdub) wrote : | # |
will hold off until improvement window opens
Alexandros Frantzis (afrantzis) wrote : | # |
A first pass:
> the server native buffer type was still MirNativeBuffer, tying us to c89 compatibility
> (this type is part of the api). Internally, I redefined the native type returned by
> mg::Buffer's native_
This double typedef (server- and client-side) confuses me. Trying to think of another solution...
518 + auto ops = std::make_
641 + auto ops = std::make_
820 + auto ops = std::make_
881 + auto ops = std::make_
902 + auto ops = std::make_
Do we need to create the ops before each operation? We could create one
instance in the constructor of each class that needs it.
718 + //note: this is wrong to do here if we don't update the fence. however, we don't have the
719 + // infrastructure to pass the texture resource to the compositor yet. We are guaranteed
720 + // no tearing by the swapper algorithm
721 +}
What's wrong to do here?
732 + [this](
733 + {
...
739 + lk.release();
A note for the future: with C++14 we will be able to do: [this, lk = std::move(lk)](...)
1372 + struct sync_merge_data data { merge_fd, "mirfence", -1 };
int const dont_care{-1}; ?
423 +std::shared_
create_
1635 +std::shared_
Couldn't we reuse mtd::create_
2332 +#if 0
2333 +//consume_
2334 +//produce_
...
Not needed.
1547 + int fake_fd = 442;
2486 + int fake_fence = 4848;
2594 + int fence = 44;
Could be const.
Kevin DuBois (kdub) wrote : | # |
hey, who switched to 'needs review'? :) I have some further improvements for the NativeBuffer type for android that makes things more landable.... will push today
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1145
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Kevin DuBois (kdub) wrote : | # |
@alf,
got the android side to just a simple fwd decl. (eg, no mir_toolkit includes in android anymore)
The intention is for the server and the client to both us mg::NativeBuffer, and translate to MirNativeBuffer just at the point the api needs it. I think with a bit more work on the gbm side, we could get both gbm and android to use fwd decl of mg::NativeBuffer and eliminate include/
@sync ops, reduced the number of allocations needed, and moved to const members of the allocating classes in some cases, like suggested
@What's wrong to do here?
the comment was just cryptic. What I meant to say is hopefully better captured in the updated comment. It was more of a todo for when we start supporting certain egl fence extensions.
@lambda capture of unique_lock
i found this out when I tried to do something similar, glad it'll be in the next version of c++
@ magic -1 value
renamed type to better indicate this is an infinite timeout value
@create_stub_buffer
eliminated this function by making the mg::NativeBuffer for android more easily mockable
@if0
removed, a sneak preview of what i want to do to the framebuffer pass to have better use of the fences :)
@could be const
in the refactors, this became a non-const reference, so they have to be non const
Kevin DuBois (kdub) wrote : | # |
as I indicated https:/
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1166
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Daniel van Vugt (vanvugt) wrote : | # |
Hmm, using development-branch unit-tests all pass. Using this proposal however there's a regression:
[ FAILED ] 2 tests, listed below:
[ FAILED ] AndroidBufferBi
[ FAILED ] HWCLayerListTes
Daniel van Vugt (vanvugt) wrote : | # |
^ On Nexus 4 that is.
Daniel van Vugt (vanvugt) wrote : | # |
^ Umm, I mean on Nexus 7.
Daniel van Vugt (vanvugt) wrote : | # |
OK, so two issues so far:
1. unit-tests FAILED regression (see above).
2. SyncFileOps -- Why is this a class? Even the implementation has no members.
Daniel van Vugt (vanvugt) wrote : | # |
Confirmed the unit-tests regression on Nexus 4 as well as Nexus 7.
Alan Griffiths (alan-griffiths) wrote : | # |
> Hmm, using development-branch unit-tests all pass. Using this proposal however
> there's a regression:
>
> [ FAILED ] 2 tests, listed below:
> [ FAILED ] AndroidBufferBi
> [ FAILED ] HWCLayerListTes
I see the same regression.
Alan Griffiths (alan-griffiths) wrote : | # |
I definitely don't follow all of it, but apart from the test regressions there's nothing crying out to be addressed before landing.
Kevin DuBois (kdub) wrote : | # |
fixed
Alan Griffiths (alan-griffiths) wrote : | # |
I definitely don't follow all of it, but apart there's nothing crying out to be addressed before landing.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1168
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Alexandros Frantzis (afrantzis) wrote : | # |
Looks good.
Preview Diff
1 | === modified file 'include/platform/mir/graphics/buffer.h' |
2 | --- include/platform/mir/graphics/buffer.h 2013-08-28 03:41:48 +0000 |
3 | +++ include/platform/mir/graphics/buffer.h 2013-10-14 15:38:18 +0000 |
4 | @@ -19,7 +19,7 @@ |
5 | #ifndef MIR_COMPOSITOR_BUFFER_H_ |
6 | #define MIR_COMPOSITOR_BUFFER_H_ |
7 | |
8 | -#include "mir_toolkit/mir_native_buffer.h" |
9 | +#include "mir/graphics/native_buffer.h" |
10 | #include "mir/geometry/size.h" |
11 | #include "mir/geometry/pixel_format.h" |
12 | |
13 | @@ -36,7 +36,7 @@ |
14 | public: |
15 | virtual ~Buffer() {} |
16 | |
17 | - virtual std::shared_ptr<MirNativeBuffer> native_buffer_handle() const = 0; |
18 | + virtual std::shared_ptr<NativeBuffer> native_buffer_handle() const = 0; |
19 | virtual BufferID id() const = 0; |
20 | virtual geometry::Size size() const = 0; |
21 | virtual geometry::Stride stride() const = 0; |
22 | |
23 | === modified file 'include/shared/mir/graphics/android/android_driver_interpreter.h' |
24 | --- include/shared/mir/graphics/android/android_driver_interpreter.h 2013-05-16 20:19:12 +0000 |
25 | +++ include/shared/mir/graphics/android/android_driver_interpreter.h 2013-10-14 15:38:18 +0000 |
26 | @@ -19,8 +19,8 @@ |
27 | #ifndef MIR_GRAPHICS_ANDROID_DRIVER_INTERPRETER_H_ |
28 | #define MIR_GRAPHICS_ANDROID_DRIVER_INTERPRETER_H_ |
29 | |
30 | +#include "mir/graphics/android/native_buffer.h" |
31 | #include <system/window.h> |
32 | -#include "sync_object.h" |
33 | #include <memory> |
34 | |
35 | namespace mir |
36 | @@ -32,8 +32,8 @@ |
37 | class AndroidDriverInterpreter |
38 | { |
39 | public: |
40 | - virtual ANativeWindowBuffer* driver_requests_buffer() = 0; |
41 | - virtual void driver_returns_buffer(ANativeWindowBuffer*, std::shared_ptr<SyncObject> const&) = 0; |
42 | + virtual NativeBuffer* driver_requests_buffer() = 0; |
43 | + virtual void driver_returns_buffer(ANativeWindowBuffer*, int fence) = 0; |
44 | virtual void dispatch_driver_request_format(int format) = 0; |
45 | virtual int driver_requests_info(int key) const = 0; |
46 | virtual void sync_to_display(bool sync) = 0; |
47 | |
48 | === added file 'include/shared/mir/graphics/android/android_native_buffer.h' |
49 | --- include/shared/mir/graphics/android/android_native_buffer.h 1970-01-01 00:00:00 +0000 |
50 | +++ include/shared/mir/graphics/android/android_native_buffer.h 2013-10-14 15:38:18 +0000 |
51 | @@ -0,0 +1,72 @@ |
52 | +/* |
53 | + * Copyright © 2013 Canonical Ltd. |
54 | + * |
55 | + * This program is free software: you can redistribute it and/or modify it |
56 | + * under the terms of the GNU Lesser General Public License version 3, |
57 | + * as published by the Free Software Foundation. |
58 | + * |
59 | + * This program is distributed in the hope that it will be useful, |
60 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
61 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
62 | + * GNU Lesser General Public License for more details. |
63 | + * |
64 | + * You should have received a copy of the GNU Lesser General Public License |
65 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
66 | + * |
67 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
68 | + */ |
69 | + |
70 | +#ifndef MIR_GRAPHICS_ANDROID_ANDROID_NATIVE_BUFFER_H_ |
71 | +#define MIR_GRAPHICS_ANDROID_ANDROID_NATIVE_BUFFER_H_ |
72 | + |
73 | +#include "native_buffer.h" |
74 | +#include <memory> |
75 | +#include <mutex> |
76 | + |
77 | +namespace mir |
78 | +{ |
79 | +namespace graphics |
80 | +{ |
81 | +namespace android |
82 | +{ |
83 | +class Fence; |
84 | + |
85 | +struct AndroidNativeBuffer : public graphics::NativeBuffer |
86 | +{ |
87 | + AndroidNativeBuffer(std::shared_ptr<ANativeWindowBuffer> const& handle, |
88 | + std::shared_ptr<Fence> const& fence); |
89 | + |
90 | + ANativeWindowBuffer* anwb() const; |
91 | + buffer_handle_t handle() const; |
92 | + NativeFence copy_fence() const; |
93 | + |
94 | + void wait_for_content(); |
95 | + void update_fence(NativeFence& merge_fd); |
96 | + |
97 | +private: |
98 | + std::shared_ptr<Fence> fence; |
99 | + std::shared_ptr<ANativeWindowBuffer> native_window_buffer; |
100 | +}; |
101 | + |
102 | +struct RefCountedNativeBuffer : public ANativeWindowBuffer |
103 | +{ |
104 | + RefCountedNativeBuffer(std::shared_ptr<const native_handle_t> const& handle); |
105 | + |
106 | + void driver_reference(); |
107 | + void driver_dereference(); |
108 | + void mir_dereference(); |
109 | +private: |
110 | + ~RefCountedNativeBuffer() = default; |
111 | + |
112 | + std::shared_ptr<const native_handle_t> const handle_resource; |
113 | + |
114 | + std::mutex mutex; |
115 | + bool mir_reference; |
116 | + int driver_references; |
117 | +}; |
118 | + |
119 | +} |
120 | +} |
121 | +} |
122 | + |
123 | +#endif /* MIR_GRAPHICS_ANDROID_ANDROID_NATIVE_BUFFER_H_ */ |
124 | |
125 | === renamed file 'include/shared/mir/graphics/android/sync_object.h' => 'include/shared/mir/graphics/android/fence.h' |
126 | --- include/shared/mir/graphics/android/sync_object.h 2013-09-24 22:14:32 +0000 |
127 | +++ include/shared/mir/graphics/android/fence.h 2013-10-14 15:38:18 +0000 |
128 | @@ -16,8 +16,8 @@ |
129 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
130 | */ |
131 | |
132 | -#ifndef MIR_GRAPHICS_ANDROID_SYNC_OBJECT_H_ |
133 | -#define MIR_GRAPHICS_ANDROID_SYNC_OBJECT_H_ |
134 | +#ifndef MIR_GRAPHICS_ANDROID_FENCE_H_ |
135 | +#define MIR_GRAPHICS_ANDROID_FENCE_H_ |
136 | |
137 | namespace mir |
138 | { |
139 | @@ -26,16 +26,21 @@ |
140 | namespace android |
141 | { |
142 | |
143 | -class SyncObject |
144 | +typedef int NativeFence; |
145 | + |
146 | +class Fence |
147 | { |
148 | public: |
149 | - virtual ~SyncObject() = default; |
150 | + virtual ~Fence() = default; |
151 | + |
152 | virtual void wait() = 0; |
153 | + virtual void merge_with(NativeFence& merge_fd) = 0; |
154 | + virtual NativeFence copy_native_handle() const = 0; |
155 | |
156 | protected: |
157 | - SyncObject() = default; |
158 | - SyncObject(SyncObject const&) = delete; |
159 | - SyncObject& operator=(SyncObject const&) = delete; |
160 | + Fence() = default; |
161 | + Fence(Fence const&) = delete; |
162 | + Fence& operator=(Fence const&) = delete; |
163 | }; |
164 | |
165 | |
166 | @@ -43,4 +48,4 @@ |
167 | } |
168 | } |
169 | |
170 | -#endif /* MIR_GRAPHICS_ANDROID_SYNC_OBJECT_H_ */ |
171 | +#endif /* MIR_GRAPHICS_ANDROID_FENCE_H_ */ |
172 | |
173 | === modified file 'include/shared/mir/graphics/android/mir_native_window.h' |
174 | --- include/shared/mir/graphics/android/mir_native_window.h 2013-05-16 20:19:12 +0000 |
175 | +++ include/shared/mir/graphics/android/mir_native_window.h 2013-10-14 15:38:18 +0000 |
176 | @@ -29,7 +29,6 @@ |
177 | { |
178 | namespace android |
179 | { |
180 | -class SyncObject; |
181 | class AndroidDriverInterpreter; |
182 | |
183 | class MirNativeWindow : public ANativeWindow |
184 | @@ -39,8 +38,8 @@ |
185 | |
186 | int query(int key, int* value) const; |
187 | int perform(int key, va_list args ); |
188 | - int dequeueBuffer(struct ANativeWindowBuffer** buffer); |
189 | - int queueBuffer(struct ANativeWindowBuffer* buffer, std::shared_ptr<SyncObject> const& fence); |
190 | + int dequeueBuffer(struct ANativeWindowBuffer** buffer, int* fence); |
191 | + int queueBuffer(struct ANativeWindowBuffer* buffer, int fence); |
192 | int setSwapInterval(int interval); |
193 | private: |
194 | |
195 | |
196 | === renamed file 'include/shared/mir/graphics/android/mir_native_buffer.h' => 'include/shared/mir/graphics/android/native_buffer.h' |
197 | --- include/shared/mir/graphics/android/mir_native_buffer.h 2013-06-25 18:06:12 +0000 |
198 | +++ include/shared/mir/graphics/android/native_buffer.h 2013-10-14 15:38:18 +0000 |
199 | @@ -16,38 +16,36 @@ |
200 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
201 | */ |
202 | |
203 | -#ifndef MIR_GRAPHICS_ANDROID_MIR_NATIVE_BUFFER_H_ |
204 | -#define MIR_GRAPHICS_ANDROID_MIR_NATIVE_BUFFER_H_ |
205 | +#ifndef MIR_GRAPHICS_ANDROID_NATIVE_BUFFER_H_ |
206 | +#define MIR_GRAPHICS_ANDROID_NATIVE_BUFFER_H_ |
207 | |
208 | +#include "fence.h" |
209 | #include <system/window.h> |
210 | -#include <memory> |
211 | -#include <mutex> |
212 | |
213 | namespace mir |
214 | { |
215 | namespace graphics |
216 | { |
217 | -namespace android |
218 | -{ |
219 | - |
220 | -struct MirNativeBuffer : public ANativeWindowBuffer |
221 | -{ |
222 | - MirNativeBuffer(std::shared_ptr<const native_handle_t> const&); |
223 | - void driver_reference(); |
224 | - void driver_dereference(); |
225 | - void mir_dereference(); |
226 | - |
227 | -private: |
228 | - ~MirNativeBuffer(); |
229 | - |
230 | - std::shared_ptr<const native_handle_t> const handle_resource; |
231 | - std::mutex mutex; |
232 | - bool mir_reference; |
233 | - int driver_references; |
234 | + |
235 | +class NativeBuffer |
236 | +{ |
237 | +public: |
238 | + virtual ~NativeBuffer() = default; |
239 | + |
240 | + virtual ANativeWindowBuffer* anwb() const = 0; |
241 | + virtual buffer_handle_t handle() const = 0; |
242 | + virtual android::NativeFence copy_fence() const = 0; |
243 | + |
244 | + virtual void wait_for_content() = 0; |
245 | + virtual void update_fence(android::NativeFence& fence) = 0; |
246 | + |
247 | +protected: |
248 | + NativeBuffer() = default; |
249 | + NativeBuffer(NativeBuffer const&) = delete; |
250 | + NativeBuffer& operator=(NativeBuffer const&) = delete; |
251 | }; |
252 | |
253 | } |
254 | } |
255 | -} |
256 | |
257 | -#endif /* MIR_GRAPHICS_ANDROID_MIR_NATIVE_BUFFER_H_ */ |
258 | +#endif /* MIR_GRAPHICS_ANDROID_NATIVE_BUFFER_H_ */ |
259 | |
260 | === renamed file 'include/shared/mir/graphics/android/syncfence.h' => 'include/shared/mir/graphics/android/sync_fence.h' |
261 | --- include/shared/mir/graphics/android/syncfence.h 2013-09-24 18:48:23 +0000 |
262 | +++ include/shared/mir/graphics/android/sync_fence.h 2013-10-14 15:38:18 +0000 |
263 | @@ -15,10 +15,11 @@ |
264 | * |
265 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
266 | */ |
267 | -#ifndef MIR_GRAPHICS_ANDROID_SYNCFENCE_H_ |
268 | -#define MIR_GRAPHICS_ANDROID_SYNCFENCE_H_ |
269 | +#ifndef MIR_GRAPHICS_ANDROID_SYNC_FENCE_H_ |
270 | +#define MIR_GRAPHICS_ANDROID_SYNC_FENCE_H_ |
271 | |
272 | -#include "mir/graphics/android/sync_object.h" |
273 | +#include "mir/graphics/android/fence.h" |
274 | +#include <memory> |
275 | |
276 | namespace mir |
277 | { |
278 | @@ -27,22 +28,44 @@ |
279 | namespace android |
280 | { |
281 | |
282 | -class SyncFence : public SyncObject |
283 | -{ |
284 | -public: |
285 | - SyncFence(); |
286 | - SyncFence(int fd); |
287 | +class SyncFileOps |
288 | +{ |
289 | +public: |
290 | + virtual ~SyncFileOps() = default; |
291 | + virtual int ioctl(int, int, void*) = 0; |
292 | + virtual int dup(int) = 0; |
293 | + virtual int close(int) = 0; |
294 | +}; |
295 | + |
296 | +class RealSyncFileOps : public SyncFileOps |
297 | +{ |
298 | +public: |
299 | + int ioctl(int fd, int req, void* dat); |
300 | + int dup(int fd); |
301 | + int close(int fd); |
302 | +}; |
303 | + |
304 | +class SyncFence : public Fence |
305 | +{ |
306 | +public: |
307 | + SyncFence(std::shared_ptr<SyncFileOps> const&, int fd); |
308 | ~SyncFence() noexcept; |
309 | |
310 | void wait(); |
311 | + void merge_with(NativeFence& merge_fd); |
312 | + NativeFence copy_native_handle() const; |
313 | |
314 | private: |
315 | SyncFence(SyncFence const&) = delete; |
316 | SyncFence& operator=(SyncFence const&) = delete; |
317 | - int const fence_fd; |
318 | + |
319 | + int fence_fd; |
320 | + std::shared_ptr<SyncFileOps> const ops; |
321 | + |
322 | + int const infinite_timeout = -1; |
323 | }; |
324 | |
325 | } |
326 | } |
327 | } |
328 | -#endif /* MIR_GRAPHICS_ANDROID_SYNCFENCE_H_ */ |
329 | +#endif /* MIR_GRAPHICS_ANDROID_SYNC_FENCE_H_ */ |
330 | |
331 | === added file 'include/shared/mir/graphics/native_buffer.h' |
332 | --- include/shared/mir/graphics/native_buffer.h 1970-01-01 00:00:00 +0000 |
333 | +++ include/shared/mir/graphics/native_buffer.h 2013-10-14 15:38:18 +0000 |
334 | @@ -0,0 +1,41 @@ |
335 | +/* |
336 | + * Copyright © 2013 Canonical Ltd. |
337 | + * |
338 | + * This program is free software: you can redistribute it and/or modify it |
339 | + * under the terms of the GNU Lesser General Public License version 3, |
340 | + * as published by the Free Software Foundation. |
341 | + * |
342 | + * This program is distributed in the hope that it will be useful, |
343 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
344 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
345 | + * GNU Lesser General Public License for more details. |
346 | + * |
347 | + * You should have received a copy of the GNU Lesser General Public License |
348 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
349 | + * |
350 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
351 | + */ |
352 | + |
353 | +#ifndef MIR_GRAPHICS_NATIVE_BUFFER_H_ |
354 | +#define MIR_GRAPHICS_NATIVE_BUFFER_H_ |
355 | + |
356 | +#ifndef ANDROID |
357 | +#include <mir_toolkit/mir_native_buffer.h> |
358 | +#endif |
359 | + |
360 | +namespace mir |
361 | +{ |
362 | +namespace graphics |
363 | +{ |
364 | + |
365 | +#ifdef ANDROID |
366 | +//just a fwd dcl |
367 | +class NativeBuffer; |
368 | +#else |
369 | +typedef struct MirBufferPackage NativeBuffer; |
370 | +#endif |
371 | + |
372 | +} |
373 | +} |
374 | + |
375 | +#endif /* MIR_GRAPHICS_NATIVE_BUFFER_H_ */ |
376 | |
377 | === modified file 'include/test/mir_test/draw/android_graphics.h' |
378 | --- include/test/mir_test/draw/android_graphics.h 2013-06-12 15:36:31 +0000 |
379 | +++ include/test/mir_test/draw/android_graphics.h 2013-10-14 15:38:18 +0000 |
380 | @@ -42,8 +42,7 @@ |
381 | TestGrallocMapper(); |
382 | TestGrallocMapper(const hw_module_t *hw_module, alloc_device_t* alloc_dev); |
383 | ~TestGrallocMapper(); |
384 | - std::shared_ptr<MirGraphicsRegion> graphic_region_from_handle( |
385 | - std::shared_ptr<ANativeWindowBuffer> const& package); |
386 | + std::shared_ptr<MirGraphicsRegion> graphic_region_from_handle(ANativeWindowBuffer* package); |
387 | |
388 | private: |
389 | TestGrallocMapper(TestGrallocMapper const&) = delete; |
390 | |
391 | === modified file 'include/test/mir_test_doubles/mock_alloc_adaptor.h' |
392 | --- include/test/mir_test_doubles/mock_alloc_adaptor.h 2013-05-21 21:43:25 +0000 |
393 | +++ include/test/mir_test_doubles/mock_alloc_adaptor.h 2013-10-14 15:38:18 +0000 |
394 | @@ -35,7 +35,7 @@ |
395 | { |
396 | public: |
397 | MOCK_METHOD3(alloc_buffer, |
398 | - std::shared_ptr<ANativeWindowBuffer>(geometry::Size, geometry::PixelFormat, graphics::android::BufferUsage)); |
399 | + std::shared_ptr<graphics::NativeBuffer>(geometry::Size, geometry::PixelFormat, graphics::android::BufferUsage)); |
400 | }; |
401 | |
402 | } |
403 | |
404 | === added file 'include/test/mir_test_doubles/mock_android_native_buffer.h' |
405 | --- include/test/mir_test_doubles/mock_android_native_buffer.h 1970-01-01 00:00:00 +0000 |
406 | +++ include/test/mir_test_doubles/mock_android_native_buffer.h 2013-10-14 15:38:18 +0000 |
407 | @@ -0,0 +1,59 @@ |
408 | +/* |
409 | + * Copyright © 2012 Canonical Ltd. |
410 | + * |
411 | + * This program is free software: you can redistribute it and/or modify it |
412 | + * under the terms of the GNU General Public License version 3, |
413 | + * as published by the Free Software Foundation. |
414 | + * |
415 | + * This program is distributed in the hope that it will be useful, |
416 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
417 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
418 | + * GNU General Public License for more details. |
419 | + * |
420 | + * You should have received a copy of the GNU General Public License |
421 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
422 | + * |
423 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
424 | + */ |
425 | + |
426 | +#ifndef MIR_TEST_DOUBLES_MOCK_ANDROID_NATIVE_BUFFER_H_ |
427 | +#define MIR_TEST_DOUBLES_MOCK_ANDROID_NATIVE_BUFFER_H_ |
428 | + |
429 | +#include "mir/graphics/android/native_buffer.h" |
430 | +#include <gmock/gmock.h> |
431 | + |
432 | +namespace mir |
433 | +{ |
434 | +namespace test |
435 | +{ |
436 | +namespace doubles |
437 | +{ |
438 | + |
439 | +struct MockAndroidNativeBuffer : public graphics::NativeBuffer |
440 | +{ |
441 | + MockAndroidNativeBuffer() |
442 | + { |
443 | + using namespace testing; |
444 | + ON_CALL(*this, anwb()) |
445 | + .WillByDefault(Return(&stub_anwb)); |
446 | + ON_CALL(*this, handle()) |
447 | + .WillByDefault(Return(&native_handle)); |
448 | + } |
449 | + MOCK_CONST_METHOD0(anwb, ANativeWindowBuffer*()); |
450 | + MOCK_CONST_METHOD0(handle, buffer_handle_t()); |
451 | + MOCK_CONST_METHOD0(copy_fence, graphics::android::NativeFence()); |
452 | + |
453 | + MOCK_METHOD0(wait_for_content, void()); |
454 | + MOCK_METHOD1(update_fence, void(graphics::android::NativeFence&)); |
455 | + |
456 | + ANativeWindowBuffer stub_anwb; |
457 | + native_handle_t native_handle; |
458 | +}; |
459 | + |
460 | +typedef testing::NiceMock<MockAndroidNativeBuffer> StubAndroidNativeBuffer; |
461 | + |
462 | +} |
463 | +} |
464 | +} |
465 | + |
466 | +#endif /* MIR_TEST_DOUBLES_MOCK_ANDROID_NATIVE_BUFFER_H_ */ |
467 | |
468 | === modified file 'include/test/mir_test_doubles/mock_buffer.h' |
469 | --- include/test/mir_test_doubles/mock_buffer.h 2013-08-28 03:41:48 +0000 |
470 | +++ include/test/mir_test_doubles/mock_buffer.h 2013-10-14 15:38:18 +0000 |
471 | @@ -55,13 +55,13 @@ |
472 | ON_CALL(*this, id()) |
473 | .WillByDefault(Return(graphics::BufferID{4})); |
474 | ON_CALL(*this, native_buffer_handle()) |
475 | - .WillByDefault(Return(std::shared_ptr<MirNativeBuffer>())); |
476 | + .WillByDefault(Return(std::shared_ptr<graphics::NativeBuffer>())); |
477 | } |
478 | |
479 | MOCK_CONST_METHOD0(size, geometry::Size()); |
480 | MOCK_CONST_METHOD0(stride, geometry::Stride()); |
481 | MOCK_CONST_METHOD0(pixel_format, geometry::PixelFormat()); |
482 | - MOCK_CONST_METHOD0(native_buffer_handle, std::shared_ptr<MirNativeBuffer>()); |
483 | + MOCK_CONST_METHOD0(native_buffer_handle, std::shared_ptr<graphics::NativeBuffer>()); |
484 | |
485 | MOCK_METHOD0(bind_to_texture, void()); |
486 | MOCK_CONST_METHOD0(id, graphics::BufferID()); |
487 | |
488 | === added file 'include/test/mir_test_doubles/mock_fence.h' |
489 | --- include/test/mir_test_doubles/mock_fence.h 1970-01-01 00:00:00 +0000 |
490 | +++ include/test/mir_test_doubles/mock_fence.h 2013-10-14 15:38:18 +0000 |
491 | @@ -0,0 +1,44 @@ |
492 | +/* |
493 | + * Copyright © 2013 Canonical Ltd. |
494 | + * |
495 | + * This program is free software: you can redistribute it and/or modify it |
496 | + * under the terms of the GNU General Public License version 3, |
497 | + * as published by the Free Software Foundation. |
498 | + * |
499 | + * This program is distributed in the hope that it will be useful, |
500 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
501 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
502 | + * GNU General Public License for more details. |
503 | + * |
504 | + * You should have received a copy of the GNU General Public License |
505 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
506 | + * |
507 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
508 | + */ |
509 | + |
510 | +#ifndef MIR_TEST_DOUBLES_MOCK_FENCE_H_ |
511 | +#define MIR_TEST_DOUBLES_MOCK_FENCE_H_ |
512 | + |
513 | +#include "mir/graphics/android/fence.h" |
514 | + |
515 | +#include <gmock/gmock.h> |
516 | + |
517 | +namespace mir |
518 | +{ |
519 | +namespace test |
520 | +{ |
521 | +namespace doubles |
522 | +{ |
523 | + |
524 | +struct MockFence : public graphics::android::Fence |
525 | +{ |
526 | + MOCK_METHOD0(wait, void()); |
527 | + MOCK_METHOD1(merge_with, void(graphics::android::NativeFence&)); |
528 | + MOCK_CONST_METHOD0(copy_native_handle, graphics::android::NativeFence()); |
529 | +}; |
530 | + |
531 | +} |
532 | +} |
533 | +} |
534 | + |
535 | +#endif /* MIR_TEST_DOUBLES_MOCK_FENCE_H_ */ |
536 | |
537 | === modified file 'include/test/mir_test_doubles/mock_interpreter_resource_cache.h' |
538 | --- include/test/mir_test_doubles/mock_interpreter_resource_cache.h 2013-08-28 03:41:48 +0000 |
539 | +++ include/test/mir_test_doubles/mock_interpreter_resource_cache.h 2013-10-14 15:38:18 +0000 |
540 | @@ -28,8 +28,10 @@ |
541 | { |
542 | struct MockInterpreterResourceCache : public graphics::android::InterpreterResourceCache |
543 | { |
544 | - MOCK_METHOD2(store_buffer, void(std::shared_ptr<graphics::Buffer>const&, ANativeWindowBuffer*)); |
545 | + MOCK_METHOD2(store_buffer, void(std::shared_ptr<graphics::Buffer>const&, |
546 | + std::shared_ptr<graphics::NativeBuffer> const&)); |
547 | MOCK_METHOD1(retrieve_buffer, std::shared_ptr<graphics::Buffer>(ANativeWindowBuffer*)); |
548 | + MOCK_METHOD2(update_native_fence, void(ANativeWindowBuffer*, int)); |
549 | }; |
550 | } |
551 | } |
552 | |
553 | === modified file 'include/test/mir_test_doubles/stub_buffer.h' |
554 | --- include/test/mir_test_doubles/stub_buffer.h 2013-08-28 03:41:48 +0000 |
555 | +++ include/test/mir_test_doubles/stub_buffer.h 2013-10-14 15:38:18 +0000 |
556 | @@ -19,6 +19,10 @@ |
557 | #ifndef MIR_TEST_DOUBLES_STUB_BUFFER_H_ |
558 | #define MIR_TEST_DOUBLES_STUB_BUFFER_H_ |
559 | |
560 | +#ifdef ANDROID |
561 | +#include "mock_android_native_buffer.h" |
562 | +#endif |
563 | + |
564 | #include "mir/graphics/buffer_basic.h" |
565 | #include "mir/graphics/buffer_properties.h" |
566 | #include "mir/geometry/size.h" |
567 | @@ -52,12 +56,12 @@ |
568 | |
569 | virtual geometry::PixelFormat pixel_format() const { return buf_pixel_format; } |
570 | |
571 | - virtual std::shared_ptr<MirNativeBuffer> native_buffer_handle() const |
572 | + virtual std::shared_ptr<graphics::NativeBuffer> native_buffer_handle() const |
573 | { |
574 | #ifndef ANDROID |
575 | - return std::make_shared<MirNativeBuffer>(); |
576 | + return std::make_shared<graphics::NativeBuffer>(); |
577 | #else |
578 | - return std::shared_ptr<MirNativeBuffer>(); |
579 | + return std::make_shared<StubAndroidNativeBuffer>(); |
580 | #endif |
581 | } |
582 | virtual void bind_to_texture() {} |
583 | |
584 | === modified file 'src/client/android/android_client_buffer.cpp' |
585 | --- src/client/android/android_client_buffer.cpp 2013-08-28 03:41:48 +0000 |
586 | +++ src/client/android/android_client_buffer.cpp 2013-10-14 15:38:18 +0000 |
587 | @@ -16,7 +16,8 @@ |
588 | * Authored by: Kevin DuBois<kevin.dubois@canonical.com> |
589 | */ |
590 | |
591 | -#include "mir/graphics/android/mir_native_buffer.h" |
592 | +#include "mir/graphics/android/android_native_buffer.h" |
593 | +#include "mir/graphics/android/sync_fence.h" |
594 | #include "mir_toolkit/mir_client_library.h" |
595 | #include "android_client_buffer.h" |
596 | #include <hardware/gralloc.h> |
597 | @@ -31,20 +32,25 @@ |
598 | geom::Size size, geom::PixelFormat pf, geometry::Stride stride) |
599 | : buffer_registrar(registrar), |
600 | native_handle(handle), |
601 | - buffer_pf(pf), buffer_stride{stride} |
602 | + buffer_pf(pf), buffer_stride{stride}, buffer_size(size) |
603 | { |
604 | - auto tmp = new mga::MirNativeBuffer(handle); |
605 | - native_window_buffer = std::shared_ptr<mga::MirNativeBuffer>(tmp, [](mga::MirNativeBuffer* buffer) |
606 | + auto ops = std::make_shared<mga::RealSyncFileOps>(); |
607 | + auto fence = std::make_shared<mga::SyncFence>(ops, -1); |
608 | + auto anwb = std::shared_ptr<mga::RefCountedNativeBuffer>( |
609 | + new mga::RefCountedNativeBuffer(handle), |
610 | + [](mga::RefCountedNativeBuffer* buffer) |
611 | { |
612 | buffer->mir_dereference(); |
613 | }); |
614 | |
615 | - native_window_buffer->height = static_cast<int32_t>(size.height.as_uint32_t()); |
616 | - native_window_buffer->width = static_cast<int32_t>(size.width.as_uint32_t()); |
617 | - native_window_buffer->stride = stride.as_uint32_t() / |
618 | + anwb->height = static_cast<int32_t>(buffer_size.height.as_uint32_t()); |
619 | + anwb->width = static_cast<int32_t>(buffer_size.width.as_uint32_t()); |
620 | + anwb->stride = stride.as_uint32_t() / |
621 | geom::bytes_per_pixel(buffer_pf); |
622 | - native_window_buffer->usage = GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER; |
623 | - native_window_buffer->handle = native_handle.get(); |
624 | + anwb->usage = GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER; |
625 | + anwb->handle = native_handle.get(); |
626 | + |
627 | + native_window_buffer = std::make_shared<mga::AndroidNativeBuffer>(anwb, fence); |
628 | } |
629 | |
630 | mcla::AndroidClientBuffer::~AndroidClientBuffer() noexcept |
631 | @@ -66,7 +72,7 @@ |
632 | |
633 | geom::Size mcla::AndroidClientBuffer::size() const |
634 | { |
635 | - return {native_window_buffer->width, native_window_buffer->height}; |
636 | + return buffer_size; |
637 | } |
638 | |
639 | geom::Stride mcla::AndroidClientBuffer::stride() const |
640 | @@ -79,7 +85,7 @@ |
641 | return buffer_pf; |
642 | } |
643 | |
644 | -std::shared_ptr<ANativeWindowBuffer> mcla::AndroidClientBuffer::native_buffer_handle() const |
645 | +std::shared_ptr<mir::graphics::NativeBuffer> mcla::AndroidClientBuffer::native_buffer_handle() const |
646 | { |
647 | return native_window_buffer; |
648 | } |
649 | |
650 | === modified file 'src/client/android/android_client_buffer.h' |
651 | --- src/client/android/android_client_buffer.h 2013-06-21 23:24:37 +0000 |
652 | +++ src/client/android/android_client_buffer.h 2013-10-14 15:38:18 +0000 |
653 | @@ -20,7 +20,7 @@ |
654 | #ifndef MIR_CLIENT_ANDROID_ANDROID_CLIENT_BUFFER_H_ |
655 | #define MIR_CLIENT_ANDROID_ANDROID_CLIENT_BUFFER_H_ |
656 | |
657 | -#include "mir_toolkit/mir_client_library.h" |
658 | +#include "mir/graphics/android/android_native_buffer.h" |
659 | #include "../aging_buffer.h" |
660 | #include "android_registrar.h" |
661 | |
662 | @@ -46,7 +46,7 @@ |
663 | geometry::Size size() const; |
664 | geometry::Stride stride() const; |
665 | geometry::PixelFormat pixel_format() const; |
666 | - std::shared_ptr<ANativeWindowBuffer> native_buffer_handle() const; |
667 | + std::shared_ptr<mir::graphics::NativeBuffer> native_buffer_handle() const; |
668 | |
669 | AndroidClientBuffer(const AndroidClientBuffer&) = delete; |
670 | AndroidClientBuffer& operator=(const AndroidClientBuffer&) = delete; |
671 | @@ -54,10 +54,11 @@ |
672 | void pack_native_window_buffer(); |
673 | |
674 | std::shared_ptr<AndroidRegistrar> buffer_registrar; |
675 | - std::shared_ptr<ANativeWindowBuffer> native_window_buffer; |
676 | + std::shared_ptr<graphics::android::AndroidNativeBuffer> native_window_buffer; |
677 | std::shared_ptr<const native_handle_t> native_handle; |
678 | const geometry::PixelFormat buffer_pf; |
679 | geometry::Stride const buffer_stride; |
680 | + geometry::Size const buffer_size; |
681 | }; |
682 | |
683 | } |
684 | |
685 | === modified file 'src/client/android/android_client_platform.cpp' |
686 | --- src/client/android/android_client_platform.cpp 2013-06-19 09:57:32 +0000 |
687 | +++ src/client/android/android_client_platform.cpp 2013-10-14 15:38:18 +0000 |
688 | @@ -106,4 +106,9 @@ |
689 | MirPlatformType mcla::AndroidClientPlatform::platform_type() const |
690 | { |
691 | return mir_platform_type_android; |
692 | -} |
693 | +} |
694 | + |
695 | +MirNativeBuffer* mcla::AndroidClientPlatform::convert_native_buffer(graphics::NativeBuffer* buf) const |
696 | +{ |
697 | + return buf->anwb(); |
698 | +} |
699 | |
700 | === modified file 'src/client/android/android_client_platform.h' |
701 | --- src/client/android/android_client_platform.h 2013-05-27 09:39:39 +0000 |
702 | +++ src/client/android/android_client_platform.h 2013-10-14 15:38:18 +0000 |
703 | @@ -36,6 +36,7 @@ |
704 | std::shared_ptr<ClientBufferFactory> create_buffer_factory(); |
705 | std::shared_ptr<EGLNativeWindowType> create_egl_native_window(ClientSurface *surface); |
706 | std::shared_ptr<EGLNativeDisplayType> create_egl_native_display(); |
707 | + MirNativeBuffer* convert_native_buffer(graphics::NativeBuffer*) const; |
708 | }; |
709 | |
710 | } |
711 | |
712 | === modified file 'src/client/android/client_surface_interpreter.cpp' |
713 | --- src/client/android/client_surface_interpreter.cpp 2013-10-13 13:08:21 +0000 |
714 | +++ src/client/android/client_surface_interpreter.cpp 2013-10-14 15:38:18 +0000 |
715 | @@ -17,7 +17,9 @@ |
716 | */ |
717 | |
718 | #include "client_surface_interpreter.h" |
719 | +#include "mir/graphics/android/sync_fence.h" |
720 | #include "../client_buffer.h" |
721 | +#include <system/window.h> |
722 | #include <stdexcept> |
723 | |
724 | namespace mcla=mir::client::android; |
725 | @@ -25,24 +27,31 @@ |
726 | |
727 | mcla::ClientSurfaceInterpreter::ClientSurfaceInterpreter(ClientSurface& surface) |
728 | : surface(surface), |
729 | - driver_pixel_format(-1) |
730 | + driver_pixel_format(-1), |
731 | + sync_ops(std::make_shared<mga::RealSyncFileOps>()) |
732 | + |
733 | { |
734 | } |
735 | |
736 | -MirNativeBuffer* mcla::ClientSurfaceInterpreter::driver_requests_buffer() |
737 | +mir::graphics::NativeBuffer* mcla::ClientSurfaceInterpreter::driver_requests_buffer() |
738 | { |
739 | auto buffer = surface.get_current_buffer(); |
740 | auto buffer_to_driver = buffer->native_buffer_handle(); |
741 | - buffer_to_driver->format = driver_pixel_format; |
742 | |
743 | + ANativeWindowBuffer* anwb = buffer_to_driver->anwb(); |
744 | + anwb->format = driver_pixel_format; |
745 | return buffer_to_driver.get(); |
746 | } |
747 | |
748 | static void empty(MirSurface * /*surface*/, void * /*client_context*/) |
749 | {} |
750 | -void mcla::ClientSurfaceInterpreter::driver_returns_buffer(MirNativeBuffer*, std::shared_ptr<mga::SyncObject> const& sync_fence) |
751 | + |
752 | +void mcla::ClientSurfaceInterpreter::driver_returns_buffer(ANativeWindowBuffer*, int fence_fd) |
753 | { |
754 | - sync_fence->wait(); |
755 | + //TODO: pass fence to server instead of waiting here |
756 | + mga::SyncFence sync_fence(sync_ops, fence_fd); |
757 | + sync_fence.wait(); |
758 | + |
759 | mir_wait_for(surface.next_buffer(empty, NULL)); |
760 | } |
761 | |
762 | |
763 | === modified file 'src/client/android/client_surface_interpreter.h' |
764 | --- src/client/android/client_surface_interpreter.h 2013-05-16 20:19:12 +0000 |
765 | +++ src/client/android/client_surface_interpreter.h 2013-10-14 15:38:18 +0000 |
766 | @@ -24,6 +24,13 @@ |
767 | |
768 | namespace mir |
769 | { |
770 | +namespace graphics |
771 | +{ |
772 | +namespace android |
773 | +{ |
774 | +class SyncFileOps; |
775 | +} |
776 | +} |
777 | namespace client |
778 | { |
779 | namespace android |
780 | @@ -34,8 +41,8 @@ |
781 | public: |
782 | explicit ClientSurfaceInterpreter(ClientSurface& surface); |
783 | |
784 | - MirNativeBuffer* driver_requests_buffer(); |
785 | - void driver_returns_buffer(MirNativeBuffer*, std::shared_ptr<graphics::android::SyncObject> const&); |
786 | + graphics::NativeBuffer* driver_requests_buffer(); |
787 | + void driver_returns_buffer(ANativeWindowBuffer*, int fence_fd ); |
788 | void dispatch_driver_request_format(int format); |
789 | int driver_requests_info(int key) const; |
790 | void sync_to_display(bool); |
791 | @@ -43,6 +50,7 @@ |
792 | private: |
793 | ClientSurface& surface; |
794 | int driver_pixel_format; |
795 | + std::shared_ptr<graphics::android::SyncFileOps> const sync_ops; |
796 | }; |
797 | |
798 | } |
799 | |
800 | === modified file 'src/client/client_buffer.h' |
801 | --- src/client/client_buffer.h 2013-05-03 22:53:42 +0000 |
802 | +++ src/client/client_buffer.h 2013-10-14 15:38:18 +0000 |
803 | @@ -20,7 +20,7 @@ |
804 | #ifndef MIR_CLIENT_CLIENT_BUFFER_H_ |
805 | #define MIR_CLIENT_CLIENT_BUFFER_H_ |
806 | |
807 | -#include "mir_toolkit/mir_native_buffer.h" |
808 | +#include "mir/graphics/native_buffer.h" |
809 | #include "mir_toolkit/common.h" |
810 | #include "mir/geometry/pixel_format.h" |
811 | #include "mir/geometry/size.h" |
812 | @@ -36,6 +36,7 @@ |
813 | |
814 | namespace mir |
815 | { |
816 | + |
817 | namespace client |
818 | { |
819 | |
820 | @@ -60,7 +61,7 @@ |
821 | virtual uint32_t age() const = 0; |
822 | virtual void increment_age() = 0; |
823 | virtual void mark_as_submitted() = 0; |
824 | - virtual std::shared_ptr<MirNativeBuffer> native_buffer_handle() const = 0; |
825 | + virtual std::shared_ptr<graphics::NativeBuffer> native_buffer_handle() const = 0; |
826 | }; |
827 | |
828 | } |
829 | |
830 | === modified file 'src/client/client_platform.h' |
831 | --- src/client/client_platform.h 2013-06-19 09:57:32 +0000 |
832 | +++ src/client/client_platform.h 2013-10-14 15:38:18 +0000 |
833 | @@ -18,7 +18,9 @@ |
834 | #ifndef MIR_CLIENT_CLIENT_PLATFORM_H_ |
835 | #define MIR_CLIENT_CLIENT_PLATFORM_H_ |
836 | |
837 | +#include "mir/graphics/native_buffer.h" |
838 | #include "mir_toolkit/client_types.h" |
839 | +#include "mir_toolkit/mir_native_buffer.h" |
840 | |
841 | #include <EGL/eglplatform.h> |
842 | #include <memory> |
843 | @@ -48,6 +50,7 @@ |
844 | virtual std::shared_ptr<ClientBufferFactory> create_buffer_factory() = 0; |
845 | virtual std::shared_ptr<EGLNativeWindowType> create_egl_native_window(ClientSurface *surface) = 0; |
846 | virtual std::shared_ptr<EGLNativeDisplayType> create_egl_native_display() = 0; |
847 | + virtual MirNativeBuffer* convert_native_buffer(graphics::NativeBuffer*) const = 0; |
848 | }; |
849 | |
850 | } |
851 | |
852 | === modified file 'src/client/gbm/gbm_client_platform.cpp' |
853 | --- src/client/gbm/gbm_client_platform.cpp 2013-06-13 22:44:04 +0000 |
854 | +++ src/client/gbm/gbm_client_platform.cpp 2013-10-14 15:38:18 +0000 |
855 | @@ -171,3 +171,9 @@ |
856 | { |
857 | return mir_platform_type_gbm; |
858 | } |
859 | + |
860 | +MirNativeBuffer* mclg::GBMClientPlatform::convert_native_buffer(graphics::NativeBuffer* buf) const |
861 | +{ |
862 | + //MirNativeBuffer is type-compatible with the MirNativeBuffer |
863 | + return buf; |
864 | +} |
865 | |
866 | === modified file 'src/client/gbm/gbm_client_platform.h' |
867 | --- src/client/gbm/gbm_client_platform.h 2013-05-03 18:39:57 +0000 |
868 | +++ src/client/gbm/gbm_client_platform.h 2013-10-14 15:38:18 +0000 |
869 | @@ -43,6 +43,7 @@ |
870 | std::shared_ptr<ClientBufferFactory> create_buffer_factory(); |
871 | std::shared_ptr<EGLNativeWindowType> create_egl_native_window(ClientSurface *surface); |
872 | std::shared_ptr<EGLNativeDisplayType> create_egl_native_display(); |
873 | + MirNativeBuffer* convert_native_buffer(graphics::NativeBuffer*) const; |
874 | |
875 | private: |
876 | ClientContext* const context; |
877 | |
878 | === modified file 'src/client/mir_client_library.cpp' |
879 | --- src/client/mir_client_library.cpp 2013-10-11 05:32:53 +0000 |
880 | +++ src/client/mir_client_library.cpp 2013-10-14 15:38:18 +0000 |
881 | @@ -264,8 +264,7 @@ |
882 | |
883 | void mir_surface_get_current_buffer(MirSurface * surface, MirNativeBuffer ** buffer_package_out) |
884 | { |
885 | - auto package = surface->get_current_buffer_package(); |
886 | - *buffer_package_out = package.get(); |
887 | + *buffer_package_out = surface->get_current_buffer_package(); |
888 | } |
889 | |
890 | uint32_t mir_debug_surface_current_buffer_id(MirSurface * surface) |
891 | |
892 | === modified file 'src/client/mir_surface.cpp' |
893 | --- src/client/mir_surface.cpp 2013-09-11 05:21:22 +0000 |
894 | +++ src/client/mir_surface.cpp 2013-10-14 15:38:18 +0000 |
895 | @@ -226,10 +226,12 @@ |
896 | return connection->release_surface(this, callback, context); |
897 | } |
898 | |
899 | -std::shared_ptr<MirNativeBuffer> MirSurface::get_current_buffer_package() |
900 | +MirNativeBuffer* MirSurface::get_current_buffer_package() |
901 | { |
902 | + auto platform = connection->get_client_platform(); |
903 | auto buffer = get_current_buffer(); |
904 | - return buffer->native_buffer_handle(); |
905 | + auto handle = buffer->native_buffer_handle(); |
906 | + return platform->convert_native_buffer(handle.get()); |
907 | } |
908 | |
909 | std::shared_ptr<mcl::ClientBuffer> MirSurface::get_current_buffer() |
910 | |
911 | === modified file 'src/client/mir_surface.h' |
912 | --- src/client/mir_surface.h 2013-08-28 03:41:48 +0000 |
913 | +++ src/client/mir_surface.h 2013-10-14 15:38:18 +0000 |
914 | @@ -24,7 +24,7 @@ |
915 | #include "mir/geometry/dimensions.h" |
916 | #include "mir_toolkit/mir_client_library.h" |
917 | #include "mir_toolkit/common.h" |
918 | -#include "mir_toolkit/mir_native_buffer.h" |
919 | +#include "mir/graphics/native_buffer.h" |
920 | #include "client_buffer_depository.h" |
921 | #include "mir_wait_handle.h" |
922 | #include "mir_client_surface.h" |
923 | @@ -79,7 +79,7 @@ |
924 | MirWaitHandle* next_buffer(mir_surface_callback callback, void * context); |
925 | MirWaitHandle* get_create_wait_handle(); |
926 | |
927 | - std::shared_ptr<MirNativeBuffer> get_current_buffer_package(); |
928 | + MirNativeBuffer* get_current_buffer_package(); |
929 | MirPlatformType platform_type(); |
930 | std::shared_ptr<mir::client::ClientBuffer> get_current_buffer(); |
931 | uint32_t get_current_buffer_id() const; |
932 | |
933 | === modified file 'src/server/compositor/temporary_buffers.cpp' |
934 | --- src/server/compositor/temporary_buffers.cpp 2013-08-28 03:41:48 +0000 |
935 | +++ src/server/compositor/temporary_buffers.cpp 2013-10-14 15:38:18 +0000 |
936 | @@ -89,7 +89,7 @@ |
937 | buffer->bind_to_texture(); |
938 | } |
939 | |
940 | -std::shared_ptr<MirNativeBuffer> mc::TemporaryBuffer::native_buffer_handle() const |
941 | +std::shared_ptr<mg::NativeBuffer> mc::TemporaryBuffer::native_buffer_handle() const |
942 | { |
943 | return buffer->native_buffer_handle(); |
944 | } |
945 | |
946 | === modified file 'src/server/compositor/temporary_buffers.h' |
947 | --- src/server/compositor/temporary_buffers.h 2013-08-28 03:41:48 +0000 |
948 | +++ src/server/compositor/temporary_buffers.h 2013-10-14 15:38:18 +0000 |
949 | @@ -40,7 +40,7 @@ |
950 | geometry::PixelFormat pixel_format() const; |
951 | mg::BufferID id() const; |
952 | void bind_to_texture(); |
953 | - std::shared_ptr<MirNativeBuffer> native_buffer_handle() const; |
954 | + std::shared_ptr<mg::NativeBuffer> native_buffer_handle() const; |
955 | bool can_bypass() const override; |
956 | |
957 | protected: |
958 | |
959 | === modified file 'src/server/graphics/android/android_alloc_adaptor.cpp' |
960 | --- src/server/graphics/android/android_alloc_adaptor.cpp 2013-06-25 18:06:12 +0000 |
961 | +++ src/server/graphics/android/android_alloc_adaptor.cpp 2013-10-14 15:38:18 +0000 |
962 | @@ -17,7 +17,8 @@ |
963 | * Kevin DuBois <kevin.dubois@canonical.com> |
964 | */ |
965 | |
966 | -#include "mir/graphics/android/mir_native_buffer.h" |
967 | +#include "mir/graphics/android/android_native_buffer.h" |
968 | +#include "mir/graphics/android/sync_fence.h" |
969 | #include "android_alloc_adaptor.h" |
970 | #include "android_format_conversion-inl.h" |
971 | |
972 | @@ -50,7 +51,7 @@ |
973 | { |
974 | } |
975 | |
976 | -std::shared_ptr<ANativeWindowBuffer> mga::AndroidAllocAdaptor::alloc_buffer( |
977 | +std::shared_ptr<mg::NativeBuffer> mga::AndroidAllocAdaptor::alloc_buffer( |
978 | geometry::Size size, geometry::PixelFormat pf, BufferUsage usage) |
979 | { |
980 | buffer_handle_t buf_handle = NULL; |
981 | @@ -70,20 +71,24 @@ |
982 | AndroidBufferHandleDeleter del1(alloc_dev); |
983 | std::shared_ptr<native_handle_t> handle(buf_handle, del1); |
984 | |
985 | - auto tmp = new mga::MirNativeBuffer(handle); |
986 | - std::shared_ptr<mga::MirNativeBuffer> buffer(tmp, [](MirNativeBuffer* buffer) |
987 | + auto ops = std::make_shared<mga::RealSyncFileOps>(); |
988 | + auto fence = std::make_shared<mga::SyncFence>(ops, -1); |
989 | + |
990 | + auto anwb = std::shared_ptr<mga::RefCountedNativeBuffer>( |
991 | + new mga::RefCountedNativeBuffer(handle), |
992 | + [](mga::RefCountedNativeBuffer* buffer) |
993 | { |
994 | buffer->mir_dereference(); |
995 | }); |
996 | |
997 | - buffer->width = width; |
998 | - buffer->height = height; |
999 | - buffer->stride = stride; |
1000 | - buffer->handle = buf_handle; |
1001 | - buffer->format = format; |
1002 | - buffer->usage = usage_flag; |
1003 | + anwb->width = width; |
1004 | + anwb->height = height; |
1005 | + anwb->stride = stride; |
1006 | + anwb->handle = buf_handle; |
1007 | + anwb->format = format; |
1008 | + anwb->usage = usage_flag; |
1009 | |
1010 | - return buffer; |
1011 | + return std::make_shared<mga::AndroidNativeBuffer>(anwb, fence); |
1012 | } |
1013 | |
1014 | int mga::AndroidAllocAdaptor::convert_to_android_usage(BufferUsage usage) |
1015 | |
1016 | === modified file 'src/server/graphics/android/android_alloc_adaptor.h' |
1017 | --- src/server/graphics/android/android_alloc_adaptor.h 2013-05-21 21:43:25 +0000 |
1018 | +++ src/server/graphics/android/android_alloc_adaptor.h 2013-10-14 15:38:18 +0000 |
1019 | @@ -35,7 +35,7 @@ |
1020 | { |
1021 | public: |
1022 | explicit AndroidAllocAdaptor(const std::shared_ptr<struct alloc_device_t>& alloc_device); |
1023 | - std::shared_ptr<ANativeWindowBuffer> alloc_buffer(geometry::Size, |
1024 | + std::shared_ptr<NativeBuffer> alloc_buffer(geometry::Size, |
1025 | geometry::PixelFormat, BufferUsage usage); |
1026 | |
1027 | /* note: alloc_device_t has a third method (dump) that isn't needed by us. it can be used to check buffer contents */ |
1028 | |
1029 | === modified file 'src/server/graphics/android/android_buffer_allocator.cpp' |
1030 | --- src/server/graphics/android/android_buffer_allocator.cpp 2013-08-28 03:41:48 +0000 |
1031 | +++ src/server/graphics/android/android_buffer_allocator.cpp 2013-10-14 15:38:18 +0000 |
1032 | @@ -21,6 +21,7 @@ |
1033 | #include "mir/graphics/buffer_initializer.h" |
1034 | #include "mir/graphics/egl_extensions.h" |
1035 | #include "mir/graphics/buffer_properties.h" |
1036 | +#include "mir/graphics/android/sync_fence.h" |
1037 | #include "android_graphic_buffer_allocator.h" |
1038 | #include "android_alloc_adaptor.h" |
1039 | #include "buffer.h" |
1040 | |
1041 | === modified file 'src/server/graphics/android/android_platform.cpp' |
1042 | --- src/server/graphics/android/android_platform.cpp 2013-09-19 13:24:22 +0000 |
1043 | +++ src/server/graphics/android/android_platform.cpp 2013-10-14 15:38:18 +0000 |
1044 | @@ -17,6 +17,7 @@ |
1045 | * Alexandros Frantzis <alexandros.frantzis@canonical.com> |
1046 | */ |
1047 | |
1048 | +#include "mir/graphics/android/sync_fence.h" |
1049 | #include "android_platform.h" |
1050 | #include "android_graphic_buffer_allocator.h" |
1051 | #include "android_hwc_factory.h" |
1052 | @@ -25,6 +26,7 @@ |
1053 | #include "default_framebuffer_factory.h" |
1054 | #include "internal_client.h" |
1055 | #include "mir/graphics/platform_ipc_package.h" |
1056 | +#include "mir/graphics/android/native_buffer.h" |
1057 | #include "mir/graphics/buffer_initializer.h" |
1058 | #include "mir/graphics/buffer_id.h" |
1059 | #include "mir/graphics/buffer_ipc_packer.h" |
1060 | @@ -84,9 +86,10 @@ |
1061 | std::shared_ptr<mg::Buffer> const& buffer) const |
1062 | { |
1063 | auto native_buffer = buffer->native_buffer_handle(); |
1064 | - auto buffer_handle = native_buffer->handle; |
1065 | + auto buffer_handle = native_buffer->handle(); |
1066 | |
1067 | int offset = 0; |
1068 | + |
1069 | for(auto i=0; i<buffer_handle->numFds; i++) |
1070 | { |
1071 | packer->pack_fd(buffer_handle->data[offset++]); |
1072 | |
1073 | === modified file 'src/server/graphics/android/buffer.cpp' |
1074 | --- src/server/graphics/android/buffer.cpp 2013-08-28 03:41:48 +0000 |
1075 | +++ src/server/graphics/android/buffer.cpp 2013-10-14 15:38:18 +0000 |
1076 | @@ -18,6 +18,8 @@ |
1077 | */ |
1078 | |
1079 | #include "mir/graphics/egl_extensions.h" |
1080 | +#include "mir/graphics/android/native_buffer.h" |
1081 | +#include "mir/graphics/android/sync_fence.h" |
1082 | #include "android_format_conversion-inl.h" |
1083 | #include "buffer.h" |
1084 | |
1085 | @@ -31,7 +33,7 @@ |
1086 | namespace mga=mir::graphics::android; |
1087 | namespace geom=mir::geometry; |
1088 | |
1089 | -mga::Buffer::Buffer(std::shared_ptr<ANativeWindowBuffer> const& buffer_handle, |
1090 | +mga::Buffer::Buffer(std::shared_ptr<NativeBuffer> const& buffer_handle, |
1091 | std::shared_ptr<mg::EGLExtensions> const& extensions) |
1092 | : native_buffer(buffer_handle), |
1093 | egl_extensions(extensions) |
1094 | @@ -50,22 +52,33 @@ |
1095 | |
1096 | geom::Size mga::Buffer::size() const |
1097 | { |
1098 | - return {native_buffer->width, native_buffer->height}; |
1099 | + ANativeWindowBuffer *anwb = native_buffer->anwb(); |
1100 | + return {anwb->width, anwb->height}; |
1101 | } |
1102 | |
1103 | geom::Stride mga::Buffer::stride() const |
1104 | { |
1105 | - return geom::Stride{native_buffer->stride * |
1106 | + ANativeWindowBuffer *anwb = native_buffer->anwb(); |
1107 | + return geom::Stride{anwb->stride * |
1108 | geom::bytes_per_pixel(pixel_format())}; |
1109 | } |
1110 | |
1111 | geom::PixelFormat mga::Buffer::pixel_format() const |
1112 | { |
1113 | - return mga::to_mir_format(native_buffer->format); |
1114 | + ANativeWindowBuffer *anwb = native_buffer->anwb(); |
1115 | + return mga::to_mir_format(anwb->format); |
1116 | +} |
1117 | + |
1118 | +bool mga::Buffer::can_bypass() const |
1119 | +{ |
1120 | + return false; |
1121 | } |
1122 | |
1123 | void mga::Buffer::bind_to_texture() |
1124 | { |
1125 | + std::unique_lock<std::mutex> lk(content_lock); |
1126 | + native_buffer->wait_for_content(); |
1127 | + |
1128 | EGLDisplay disp = eglGetCurrentDisplay(); |
1129 | if (disp == EGL_NO_DISPLAY) { |
1130 | BOOST_THROW_EXCEPTION(std::runtime_error("cannot bind buffer to texture without EGL context\n")); |
1131 | @@ -80,7 +93,7 @@ |
1132 | if (it == egl_image_map.end()) |
1133 | { |
1134 | image = egl_extensions->eglCreateImageKHR(disp, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, |
1135 | - native_buffer.get(), image_attrs); |
1136 | + native_buffer->anwb(), image_attrs); |
1137 | if (image == EGL_NO_IMAGE_KHR) |
1138 | { |
1139 | BOOST_THROW_EXCEPTION(std::runtime_error("error binding buffer to texture\n")); |
1140 | @@ -93,14 +106,24 @@ |
1141 | } |
1142 | |
1143 | egl_extensions->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); |
1144 | -} |
1145 | - |
1146 | -bool mga::Buffer::can_bypass() const |
1147 | -{ |
1148 | - return false; |
1149 | -} |
1150 | - |
1151 | -std::shared_ptr<ANativeWindowBuffer> mga::Buffer::native_buffer_handle() const |
1152 | -{ |
1153 | - return native_buffer; |
1154 | + |
1155 | + //TODO: we should make use of the android egl fence extension here to update the fence. |
1156 | + // if the extension is not available, we should pass out a token that the user |
1157 | + // will have to keep until the completion of the gl draw |
1158 | +} |
1159 | + |
1160 | +std::shared_ptr<mg::NativeBuffer> mga::Buffer::native_buffer_handle() const |
1161 | +{ |
1162 | + std::unique_lock<std::mutex> lk(content_lock); |
1163 | + |
1164 | + auto native_resource = std::shared_ptr<mg::NativeBuffer>( |
1165 | + native_buffer.get(), |
1166 | + [this](NativeBuffer*) |
1167 | + { |
1168 | + content_lock.unlock(); |
1169 | + }); |
1170 | + |
1171 | + //lock remains in effect until the native handle is released |
1172 | + lk.release(); |
1173 | + return native_resource; |
1174 | } |
1175 | |
1176 | === modified file 'src/server/graphics/android/buffer.h' |
1177 | --- src/server/graphics/android/buffer.h 2013-08-28 03:41:48 +0000 |
1178 | +++ src/server/graphics/android/buffer.h 2013-10-14 15:38:18 +0000 |
1179 | @@ -23,6 +23,8 @@ |
1180 | #include "mir/graphics/buffer_basic.h" |
1181 | #include "buffer_usage.h" |
1182 | |
1183 | +#include <mutex> |
1184 | +#include <condition_variable> |
1185 | #include <map> |
1186 | |
1187 | #define GL_GLEXT_PROTOTYPES |
1188 | @@ -41,7 +43,7 @@ |
1189 | class Buffer: public BufferBasic |
1190 | { |
1191 | public: |
1192 | - Buffer(std::shared_ptr<ANativeWindowBuffer> const& buffer_handle, |
1193 | + Buffer(std::shared_ptr<NativeBuffer> const& buffer_handle, |
1194 | std::shared_ptr<EGLExtensions> const& extensions); |
1195 | ~Buffer(); |
1196 | |
1197 | @@ -50,12 +52,17 @@ |
1198 | geometry::PixelFormat pixel_format() const; |
1199 | void bind_to_texture(); |
1200 | bool can_bypass() const override; |
1201 | - std::shared_ptr<ANativeWindowBuffer> native_buffer_handle() const; |
1202 | + |
1203 | + //note, you will get the native representation of an android buffer, including |
1204 | + //the fences associated with the buffer. You must close these fences |
1205 | + std::shared_ptr<NativeBuffer> native_buffer_handle() const; |
1206 | |
1207 | private: |
1208 | + std::mutex mutable content_lock; |
1209 | + |
1210 | std::map<EGLDisplay,EGLImageKHR> egl_image_map; |
1211 | |
1212 | - std::shared_ptr<ANativeWindowBuffer> native_buffer; |
1213 | + std::shared_ptr<NativeBuffer> native_buffer; |
1214 | std::shared_ptr<EGLExtensions> egl_extensions; |
1215 | }; |
1216 | |
1217 | |
1218 | === modified file 'src/server/graphics/android/default_framebuffer_factory.cpp' |
1219 | --- src/server/graphics/android/default_framebuffer_factory.cpp 2013-08-28 03:41:48 +0000 |
1220 | +++ src/server/graphics/android/default_framebuffer_factory.cpp 2013-10-14 15:38:18 +0000 |
1221 | @@ -32,7 +32,6 @@ |
1222 | |
1223 | namespace mg = mir::graphics; |
1224 | namespace mga=mir::graphics::android; |
1225 | -namespace mc=mir::compositor; |
1226 | |
1227 | mga::DefaultFramebufferFactory::DefaultFramebufferFactory( |
1228 | std::shared_ptr<GraphicBufferAllocator> const& buffer_allocator) |
1229 | |
1230 | === modified file 'src/server/graphics/android/fb_device.cpp' |
1231 | --- src/server/graphics/android/fb_device.cpp 2013-10-03 03:44:08 +0000 |
1232 | +++ src/server/graphics/android/fb_device.cpp 2013-10-14 15:38:18 +0000 |
1233 | @@ -17,6 +17,8 @@ |
1234 | */ |
1235 | |
1236 | #include "mir/graphics/buffer.h" |
1237 | +#include "mir/graphics/android/sync_fence.h" |
1238 | +#include "mir/graphics/android/native_buffer.h" |
1239 | |
1240 | #include "fb_device.h" |
1241 | #include "buffer.h" |
1242 | @@ -41,8 +43,10 @@ |
1243 | |
1244 | void mga::FBDevice::set_next_frontbuffer(std::shared_ptr<mg::Buffer> const& buffer) |
1245 | { |
1246 | - auto handle = buffer->native_buffer_handle(); |
1247 | - if (fb_device->post(fb_device.get(), handle->handle) != 0) |
1248 | + auto native_buffer = buffer->native_buffer_handle(); |
1249 | + native_buffer->wait_for_content(); |
1250 | + |
1251 | + if (fb_device->post(fb_device.get(), native_buffer->handle()) != 0) |
1252 | { |
1253 | BOOST_THROW_EXCEPTION(std::runtime_error("error posting with fb device")); |
1254 | } |
1255 | |
1256 | === modified file 'src/server/graphics/android/fb_swapper.h' |
1257 | --- src/server/graphics/android/fb_swapper.h 2013-08-28 03:41:48 +0000 |
1258 | +++ src/server/graphics/android/fb_swapper.h 2013-10-14 15:38:18 +0000 |
1259 | @@ -30,7 +30,7 @@ |
1260 | |
1261 | namespace android |
1262 | { |
1263 | -//TODO: remove this interface. FBSimpleSwapper should inherit from mc::BufferSwapper |
1264 | + |
1265 | class FBSwapper{ |
1266 | public: |
1267 | virtual ~FBSwapper() = default; |
1268 | |
1269 | === modified file 'src/server/graphics/android/graphic_alloc_adaptor.h' |
1270 | --- src/server/graphics/android/graphic_alloc_adaptor.h 2013-05-21 21:43:25 +0000 |
1271 | +++ src/server/graphics/android/graphic_alloc_adaptor.h 2013-10-14 15:38:18 +0000 |
1272 | @@ -22,21 +22,21 @@ |
1273 | #include "mir/geometry/size.h" |
1274 | #include "mir/geometry/pixel_format.h" |
1275 | #include "buffer_usage.h" |
1276 | - |
1277 | -#include <system/window.h> |
1278 | #include <memory> |
1279 | |
1280 | namespace mir |
1281 | { |
1282 | namespace graphics |
1283 | { |
1284 | + |
1285 | +class NativeBuffer; |
1286 | namespace android |
1287 | { |
1288 | |
1289 | class GraphicAllocAdaptor |
1290 | { |
1291 | public: |
1292 | - virtual std::shared_ptr<ANativeWindowBuffer> alloc_buffer(geometry::Size size, |
1293 | + virtual std::shared_ptr<NativeBuffer> alloc_buffer(geometry::Size size, |
1294 | geometry::PixelFormat, BufferUsage usage) = 0; |
1295 | protected: |
1296 | GraphicAllocAdaptor() = default; |
1297 | |
1298 | === modified file 'src/server/graphics/android/hwc11_device.cpp' |
1299 | --- src/server/graphics/android/hwc11_device.cpp 2013-09-25 15:46:05 +0000 |
1300 | +++ src/server/graphics/android/hwc11_device.cpp 2013-10-14 15:38:18 +0000 |
1301 | @@ -20,7 +20,7 @@ |
1302 | #include "hwc11_device.h" |
1303 | #include "hwc_layerlist.h" |
1304 | #include "hwc_vsync_coordinator.h" |
1305 | -#include "mir/graphics/android/syncfence.h" |
1306 | +#include "mir/graphics/android/sync_fence.h" |
1307 | #include <boost/throw_exception.hpp> |
1308 | #include <stdexcept> |
1309 | |
1310 | @@ -34,7 +34,8 @@ |
1311 | std::shared_ptr<HWCVsyncCoordinator> const& coordinator) |
1312 | : HWCCommonDevice(hwc_device, coordinator), |
1313 | layer_list(layer_list), |
1314 | - fb_device(fbdev) |
1315 | + fb_device(fbdev), |
1316 | + sync_ops(std::make_shared<mga::RealSyncFileOps>()) |
1317 | { |
1318 | size_t num_configs = 1; |
1319 | auto rc = hwc_device->getDisplayConfigs(hwc_device.get(), HWC_DISPLAY_PRIMARY, &primary_display_config, &num_configs); |
1320 | @@ -103,7 +104,7 @@ |
1321 | BOOST_THROW_EXCEPTION(std::runtime_error("error during hwc set()")); |
1322 | } |
1323 | |
1324 | - mga::SyncFence fence(displays[HWC_DISPLAY_PRIMARY]->retireFenceFd); |
1325 | + mga::SyncFence fence(sync_ops, displays[HWC_DISPLAY_PRIMARY]->retireFenceFd); |
1326 | fence.wait(); |
1327 | } |
1328 | |
1329 | |
1330 | === modified file 'src/server/graphics/android/hwc11_device.h' |
1331 | --- src/server/graphics/android/hwc11_device.h 2013-09-25 15:46:05 +0000 |
1332 | +++ src/server/graphics/android/hwc11_device.h 2013-10-14 15:38:18 +0000 |
1333 | @@ -31,6 +31,7 @@ |
1334 | { |
1335 | class HWCLayerList; |
1336 | class HWCVsyncCoordinator; |
1337 | +class SyncFileOps; |
1338 | |
1339 | class HWC11Device : public HWCCommonDevice |
1340 | { |
1341 | @@ -52,6 +53,7 @@ |
1342 | private: |
1343 | std::shared_ptr<HWCLayerList> const layer_list; |
1344 | std::shared_ptr<DisplaySupportProvider> const fb_device; |
1345 | + std::shared_ptr<SyncFileOps> const sync_ops; |
1346 | unsigned int primary_display_config; |
1347 | }; |
1348 | |
1349 | |
1350 | === modified file 'src/server/graphics/android/hwc_layerlist.cpp' |
1351 | --- src/server/graphics/android/hwc_layerlist.cpp 2013-09-24 22:20:17 +0000 |
1352 | +++ src/server/graphics/android/hwc_layerlist.cpp 2013-10-14 15:38:18 +0000 |
1353 | @@ -16,6 +16,8 @@ |
1354 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
1355 | */ |
1356 | |
1357 | +#include "mir/graphics/android/sync_fence.h" |
1358 | +#include "mir/graphics/android/native_buffer.h" |
1359 | #include "hwc_layerlist.h" |
1360 | #include "buffer.h" |
1361 | |
1362 | @@ -101,13 +103,14 @@ |
1363 | |
1364 | void mga::LayerList::set_fb_target(std::shared_ptr<mg::Buffer> const& buffer) |
1365 | { |
1366 | - auto handle = buffer->native_buffer_handle(); |
1367 | + auto native_buffer = buffer->native_buffer_handle(); |
1368 | + native_buffer->wait_for_content(); |
1369 | |
1370 | geom::Point pt{0, 0}; |
1371 | geom::Rectangle rect{pt, buffer->size()}; |
1372 | HWCRect display_rect(rect); |
1373 | |
1374 | - auto fb_layer = std::make_shared<HWCFBLayer>(handle->handle, display_rect); |
1375 | + auto fb_layer = std::make_shared<HWCFBLayer>(native_buffer->handle(), display_rect); |
1376 | layer_list[fb_position] = fb_layer; |
1377 | |
1378 | update_list(); |
1379 | |
1380 | === modified file 'src/server/graphics/android/internal_client_window.cpp' |
1381 | --- src/server/graphics/android/internal_client_window.cpp 2013-10-13 13:08:21 +0000 |
1382 | +++ src/server/graphics/android/internal_client_window.cpp 2013-10-14 15:38:18 +0000 |
1383 | @@ -18,13 +18,16 @@ |
1384 | |
1385 | #include "internal_client_window.h" |
1386 | #include "mir/graphics/internal_surface.h" |
1387 | +#include "mir/graphics/android/sync_fence.h" |
1388 | #include "mir/graphics/buffer.h" |
1389 | #include "interpreter_resource_cache.h" |
1390 | #include "android_format_conversion-inl.h" |
1391 | |
1392 | #include <boost/throw_exception.hpp> |
1393 | #include <stdexcept> |
1394 | -namespace mga=mir::graphics::android; |
1395 | + |
1396 | +namespace mg=mir::graphics; |
1397 | +namespace mga=mg::android; |
1398 | namespace geom=mir::geometry; |
1399 | |
1400 | mga::InternalClientWindow::InternalClientWindow(std::shared_ptr<InternalSurface> const& surface, |
1401 | @@ -35,19 +38,18 @@ |
1402 | format = mga::to_android_format(geometry::PixelFormat(surface->pixel_format())); |
1403 | } |
1404 | |
1405 | -ANativeWindowBuffer* mga::InternalClientWindow::driver_requests_buffer() |
1406 | +mg::NativeBuffer* mga::InternalClientWindow::driver_requests_buffer() |
1407 | { |
1408 | auto buffer = surface->advance_client_buffer(); |
1409 | - auto handle = buffer->native_buffer_handle().get(); |
1410 | + auto handle = buffer->native_buffer_handle(); |
1411 | resource_cache->store_buffer(buffer, handle); |
1412 | - return handle; |
1413 | + return handle.get(); |
1414 | } |
1415 | |
1416 | -void mga::InternalClientWindow::driver_returns_buffer(ANativeWindowBuffer* handle, |
1417 | - std::shared_ptr<SyncObject> const& fence) |
1418 | +void mga::InternalClientWindow::driver_returns_buffer(ANativeWindowBuffer* buffer, int fence_fd) |
1419 | { |
1420 | - fence->wait(); |
1421 | - resource_cache->retrieve_buffer(handle); |
1422 | + resource_cache->update_native_fence(buffer, fence_fd); |
1423 | + resource_cache->retrieve_buffer(buffer); |
1424 | /* here, the mc::TemporaryBuffer will destruct, triggering buffer advance */ |
1425 | } |
1426 | |
1427 | |
1428 | === modified file 'src/server/graphics/android/internal_client_window.h' |
1429 | --- src/server/graphics/android/internal_client_window.h 2013-08-28 03:41:48 +0000 |
1430 | +++ src/server/graphics/android/internal_client_window.h 2013-10-14 15:38:18 +0000 |
1431 | @@ -22,6 +22,7 @@ |
1432 | #include "mir/graphics/android/android_driver_interpreter.h" |
1433 | #include "mir/geometry/size.h" |
1434 | #include "mir/geometry/pixel_format.h" |
1435 | +#include <memory> |
1436 | |
1437 | namespace mir |
1438 | { |
1439 | @@ -37,8 +38,8 @@ |
1440 | public: |
1441 | InternalClientWindow(std::shared_ptr<InternalSurface> const&, |
1442 | std::shared_ptr<InterpreterResourceCache> const&); |
1443 | - ANativeWindowBuffer* driver_requests_buffer(); |
1444 | - void driver_returns_buffer(ANativeWindowBuffer*, std::shared_ptr<SyncObject> const&); |
1445 | + graphics::NativeBuffer* driver_requests_buffer(); |
1446 | + void driver_returns_buffer(ANativeWindowBuffer*, int); |
1447 | void dispatch_driver_request_format(int); |
1448 | int driver_requests_info(int) const; |
1449 | void sync_to_display(bool sync); |
1450 | |
1451 | === modified file 'src/server/graphics/android/interpreter_cache.cpp' |
1452 | --- src/server/graphics/android/interpreter_cache.cpp 2013-08-28 03:41:48 +0000 |
1453 | +++ src/server/graphics/android/interpreter_cache.cpp 2013-10-14 15:38:18 +0000 |
1454 | @@ -16,6 +16,8 @@ |
1455 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
1456 | */ |
1457 | |
1458 | +#include "mir/graphics/android/sync_fence.h" |
1459 | +#include "mir/graphics/android/native_buffer.h" |
1460 | #include "interpreter_cache.h" |
1461 | #include <boost/throw_exception.hpp> |
1462 | #include <stdexcept> |
1463 | @@ -23,19 +25,38 @@ |
1464 | namespace mg = mir::graphics; |
1465 | namespace mga=mir::graphics::android; |
1466 | |
1467 | -void mga::InterpreterCache::store_buffer(std::shared_ptr<mg::Buffer>const& buffer, ANativeWindowBuffer* key) |
1468 | +void mga::InterpreterCache::store_buffer(std::shared_ptr<mg::Buffer>const& buffer, |
1469 | + std::shared_ptr<mg::NativeBuffer> const& key) |
1470 | { |
1471 | - buffers_in_driver[key] = buffer; |
1472 | + native_buffers[key->anwb()] = key; |
1473 | + buffers_in_driver[key->anwb()] = buffer; |
1474 | } |
1475 | |
1476 | std::shared_ptr<mg::Buffer> mga::InterpreterCache::retrieve_buffer(ANativeWindowBuffer* returned_handle) |
1477 | { |
1478 | auto buffer_it = buffers_in_driver.find(returned_handle); |
1479 | - if (buffer_it == buffers_in_driver.end()) |
1480 | + auto native_it = native_buffers.find(returned_handle); |
1481 | + |
1482 | + if ((buffer_it == buffers_in_driver.end()) || |
1483 | + (native_it == native_buffers.end())) |
1484 | { |
1485 | BOOST_THROW_EXCEPTION(std::runtime_error("driver is returning buffers it never was given!")); |
1486 | } |
1487 | + native_buffers.erase(native_it); |
1488 | + |
1489 | auto buffer_out = buffer_it->second; |
1490 | buffers_in_driver.erase(buffer_it); |
1491 | return buffer_out; |
1492 | } |
1493 | + |
1494 | +void mga::InterpreterCache::update_native_fence(ANativeWindowBuffer* key, int fence) |
1495 | +{ |
1496 | + auto native_it = native_buffers.find(key); |
1497 | + if (native_it == native_buffers.end()) |
1498 | + { |
1499 | + BOOST_THROW_EXCEPTION(std::runtime_error("driver is returning buffers it never was given!")); |
1500 | + } |
1501 | + |
1502 | + auto native_buffer = native_it->second; |
1503 | + native_buffer->update_fence(fence); |
1504 | +} |
1505 | |
1506 | === modified file 'src/server/graphics/android/interpreter_cache.h' |
1507 | --- src/server/graphics/android/interpreter_cache.h 2013-08-28 03:41:48 +0000 |
1508 | +++ src/server/graphics/android/interpreter_cache.h 2013-10-14 15:38:18 +0000 |
1509 | @@ -33,11 +33,14 @@ |
1510 | public: |
1511 | InterpreterCache() {} |
1512 | |
1513 | - void store_buffer(std::shared_ptr<graphics::Buffer>const& buffer, ANativeWindowBuffer* key); |
1514 | + void store_buffer(std::shared_ptr<graphics::Buffer>const& buffer, |
1515 | + std::shared_ptr<graphics::NativeBuffer> const& key); |
1516 | std::shared_ptr<graphics::Buffer> retrieve_buffer(ANativeWindowBuffer* key); |
1517 | + void update_native_fence(ANativeWindowBuffer* key, int fence); |
1518 | |
1519 | private: |
1520 | std::unordered_map<ANativeWindowBuffer*, std::shared_ptr<graphics::Buffer>> buffers_in_driver; |
1521 | + std::unordered_map<ANativeWindowBuffer*, std::shared_ptr<graphics::NativeBuffer>> native_buffers; |
1522 | }; |
1523 | } |
1524 | } |
1525 | |
1526 | === modified file 'src/server/graphics/android/interpreter_resource_cache.h' |
1527 | --- src/server/graphics/android/interpreter_resource_cache.h 2013-08-28 03:41:48 +0000 |
1528 | +++ src/server/graphics/android/interpreter_resource_cache.h 2013-10-14 15:38:18 +0000 |
1529 | @@ -26,6 +26,7 @@ |
1530 | namespace graphics |
1531 | { |
1532 | class Buffer; |
1533 | +class NativeBuffer; |
1534 | |
1535 | namespace android |
1536 | { |
1537 | @@ -34,8 +35,10 @@ |
1538 | public: |
1539 | InterpreterResourceCache() {} |
1540 | |
1541 | - virtual void store_buffer(std::shared_ptr<graphics::Buffer>const& buffer, ANativeWindowBuffer* key) = 0; |
1542 | + virtual void store_buffer(std::shared_ptr<graphics::Buffer>const& buffer, |
1543 | + std::shared_ptr<graphics::NativeBuffer> const& key) = 0; |
1544 | virtual std::shared_ptr<graphics::Buffer> retrieve_buffer(ANativeWindowBuffer* key) = 0; |
1545 | + virtual void update_native_fence(ANativeWindowBuffer* key, int fence) = 0; |
1546 | |
1547 | protected: |
1548 | virtual ~InterpreterResourceCache() {} |
1549 | |
1550 | === modified file 'src/server/graphics/android/server_render_window.cpp' |
1551 | --- src/server/graphics/android/server_render_window.cpp 2013-10-13 13:08:21 +0000 |
1552 | +++ src/server/graphics/android/server_render_window.cpp 2013-10-14 15:38:18 +0000 |
1553 | @@ -18,6 +18,7 @@ |
1554 | */ |
1555 | |
1556 | #include "mir/graphics/buffer.h" |
1557 | +#include "mir/graphics/android/sync_fence.h" |
1558 | #include "server_render_window.h" |
1559 | #include "display_support_provider.h" |
1560 | #include "fb_swapper.h" |
1561 | @@ -25,12 +26,11 @@ |
1562 | #include "android_format_conversion-inl.h" |
1563 | #include "interpreter_resource_cache.h" |
1564 | |
1565 | +#include <system/window.h> |
1566 | #include <boost/throw_exception.hpp> |
1567 | #include <stdexcept> |
1568 | |
1569 | -#include <thread> |
1570 | -#include <chrono> |
1571 | -namespace mc=mir::compositor; |
1572 | +namespace mg=mir::graphics; |
1573 | namespace mga=mir::graphics::android; |
1574 | namespace geom=mir::geometry; |
1575 | |
1576 | @@ -44,21 +44,20 @@ |
1577 | { |
1578 | } |
1579 | |
1580 | -ANativeWindowBuffer* mga::ServerRenderWindow::driver_requests_buffer() |
1581 | +mg::NativeBuffer* mga::ServerRenderWindow::driver_requests_buffer() |
1582 | { |
1583 | auto buffer = swapper->compositor_acquire(); |
1584 | - auto handle = buffer->native_buffer_handle().get(); |
1585 | + auto handle = buffer->native_buffer_handle(); |
1586 | resource_cache->store_buffer(buffer, handle); |
1587 | - return handle; |
1588 | + return handle.get(); |
1589 | } |
1590 | |
1591 | -//sync object could be passed to hwc. we don't need to that yet though |
1592 | -void mga::ServerRenderWindow::driver_returns_buffer(ANativeWindowBuffer* returned_handle, std::shared_ptr<SyncObject> const& fence) |
1593 | +void mga::ServerRenderWindow::driver_returns_buffer(ANativeWindowBuffer* buffer, int fence_fd) |
1594 | { |
1595 | - fence->wait(); |
1596 | - auto buffer = resource_cache->retrieve_buffer(returned_handle); |
1597 | - poster->set_next_frontbuffer(buffer); |
1598 | - swapper->compositor_release(buffer); |
1599 | + resource_cache->update_native_fence(buffer, fence_fd); |
1600 | + auto buffer_resource = resource_cache->retrieve_buffer(buffer); |
1601 | + poster->set_next_frontbuffer(buffer_resource); |
1602 | + swapper->compositor_release(buffer_resource); |
1603 | } |
1604 | |
1605 | void mga::ServerRenderWindow::dispatch_driver_request_format(int request_format) |
1606 | |
1607 | === modified file 'src/server/graphics/android/server_render_window.h' |
1608 | --- src/server/graphics/android/server_render_window.h 2013-05-16 20:04:58 +0000 |
1609 | +++ src/server/graphics/android/server_render_window.h 2013-10-14 15:38:18 +0000 |
1610 | @@ -23,18 +23,10 @@ |
1611 | #include "mir/graphics/android/android_driver_interpreter.h" |
1612 | #include "mir/geometry/pixel_format.h" |
1613 | |
1614 | -#include <hardware/fb.h> |
1615 | -#include <hardware/hwcomposer.h> |
1616 | - |
1617 | #include <memory> |
1618 | -#include <unordered_map> |
1619 | |
1620 | namespace mir |
1621 | { |
1622 | -namespace compositor |
1623 | -{ |
1624 | -class Buffer; |
1625 | -} |
1626 | namespace graphics |
1627 | { |
1628 | namespace android |
1629 | @@ -50,8 +42,8 @@ |
1630 | std::shared_ptr<DisplaySupportProvider> const& display_poster, |
1631 | std::shared_ptr<InterpreterResourceCache> const&); |
1632 | |
1633 | - ANativeWindowBuffer* driver_requests_buffer(); |
1634 | - void driver_returns_buffer(ANativeWindowBuffer*, std::shared_ptr<SyncObject> const&); |
1635 | + graphics::NativeBuffer* driver_requests_buffer(); |
1636 | + void driver_returns_buffer(ANativeWindowBuffer*, int fence_fd); |
1637 | void dispatch_driver_request_format(int format); |
1638 | int driver_requests_info(int key) const; |
1639 | void sync_to_display(bool sync); |
1640 | |
1641 | === modified file 'src/server/graphics/gbm/gbm_platform.cpp' |
1642 | --- src/server/graphics/gbm/gbm_platform.cpp 2013-09-11 05:21:22 +0000 |
1643 | +++ src/server/graphics/gbm/gbm_platform.cpp 2013-10-14 15:38:18 +0000 |
1644 | @@ -26,6 +26,7 @@ |
1645 | #include "mir/graphics/platform_ipc_package.h" |
1646 | #include "mir/graphics/buffer_ipc_packer.h" |
1647 | #include "mir/options/option.h" |
1648 | +#include "mir/graphics/native_buffer.h" |
1649 | |
1650 | #include "drm_close_threadsafe.h" |
1651 | |
1652 | |
1653 | === modified file 'src/shared/graphics/android/CMakeLists.txt' |
1654 | --- src/shared/graphics/android/CMakeLists.txt 2013-06-18 23:16:39 +0000 |
1655 | +++ src/shared/graphics/android/CMakeLists.txt 2013-10-14 15:38:18 +0000 |
1656 | @@ -2,7 +2,8 @@ |
1657 | mirsharedandroid STATIC |
1658 | |
1659 | mir_native_window.cpp |
1660 | - mir_native_buffer.cpp |
1661 | + refcounted_buffer.cpp |
1662 | + android_native_buffer.cpp |
1663 | syncfence.cpp |
1664 | ) |
1665 | |
1666 | |
1667 | === added file 'src/shared/graphics/android/android_native_buffer.cpp' |
1668 | --- src/shared/graphics/android/android_native_buffer.cpp 1970-01-01 00:00:00 +0000 |
1669 | +++ src/shared/graphics/android/android_native_buffer.cpp 2013-10-14 15:38:18 +0000 |
1670 | @@ -0,0 +1,54 @@ |
1671 | +/* |
1672 | + * Copyright © 2013 Canonical Ltd. |
1673 | + * |
1674 | + * This program is free software: you can redistribute it and/or modify it |
1675 | + * under the terms of the GNU Lesser General Public License version 3, |
1676 | + * as published by the Free Software Foundation. |
1677 | + * |
1678 | + * This program is distributed in the hope that it will be useful, |
1679 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1680 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1681 | + * GNU Lesser General Public License for more details. |
1682 | + * |
1683 | + * You should have received a copy of the GNU Lesser General Public License |
1684 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1685 | + * |
1686 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
1687 | + */ |
1688 | + |
1689 | +#include "mir/graphics/android/android_native_buffer.h" |
1690 | + |
1691 | +namespace mga=mir::graphics::android; |
1692 | + |
1693 | +mga::AndroidNativeBuffer::AndroidNativeBuffer( |
1694 | + std::shared_ptr<ANativeWindowBuffer> const& anwb, |
1695 | + std::shared_ptr<Fence> const& fence) |
1696 | + : fence(fence), |
1697 | + native_window_buffer(anwb) |
1698 | +{ |
1699 | +} |
1700 | + |
1701 | +void mga::AndroidNativeBuffer::wait_for_content() |
1702 | +{ |
1703 | + fence->wait(); |
1704 | +} |
1705 | + |
1706 | +void mga::AndroidNativeBuffer::update_fence(NativeFence& merge_fd) |
1707 | +{ |
1708 | + fence->merge_with(merge_fd); |
1709 | +} |
1710 | + |
1711 | +ANativeWindowBuffer* mga::AndroidNativeBuffer::anwb() const |
1712 | +{ |
1713 | + return native_window_buffer.get(); |
1714 | +} |
1715 | + |
1716 | +buffer_handle_t mga::AndroidNativeBuffer::handle() const |
1717 | +{ |
1718 | + return native_window_buffer->handle; |
1719 | +} |
1720 | + |
1721 | +mga::NativeFence mga::AndroidNativeBuffer::copy_fence() const |
1722 | +{ |
1723 | + return fence->copy_native_handle(); |
1724 | +} |
1725 | |
1726 | === modified file 'src/shared/graphics/android/mir_native_window.cpp' |
1727 | --- src/shared/graphics/android/mir_native_window.cpp 2013-09-24 18:48:23 +0000 |
1728 | +++ src/shared/graphics/android/mir_native_window.cpp 2013-10-14 15:38:18 +0000 |
1729 | @@ -18,9 +18,9 @@ |
1730 | |
1731 | #include "mir/graphics/android/mir_native_window.h" |
1732 | #include "mir/graphics/android/android_driver_interpreter.h" |
1733 | -#include "mir/graphics/android/syncfence.h" |
1734 | - |
1735 | - |
1736 | +#include "mir/graphics/android/sync_fence.h" |
1737 | + |
1738 | +namespace mg=mir::graphics; |
1739 | namespace mga=mir::graphics::android; |
1740 | |
1741 | namespace |
1742 | @@ -69,33 +69,31 @@ |
1743 | int dequeueBuffer_deprecated_static (struct ANativeWindow* window, |
1744 | struct ANativeWindowBuffer** buffer) |
1745 | { |
1746 | + int fence_fd = -1; |
1747 | auto self = static_cast<mga::MirNativeWindow*>(window); |
1748 | - return self->dequeueBuffer(buffer); |
1749 | + //todo: we have to close the fence |
1750 | + return self->dequeueBuffer(buffer, &fence_fd); |
1751 | } |
1752 | |
1753 | int dequeueBuffer_static (struct ANativeWindow* window, |
1754 | struct ANativeWindowBuffer** buffer, int* fence_fd) |
1755 | { |
1756 | - *fence_fd = -1; |
1757 | auto self = static_cast<mga::MirNativeWindow*>(window); |
1758 | - return self->dequeueBuffer(buffer); |
1759 | + return self->dequeueBuffer(buffer, fence_fd); |
1760 | } |
1761 | |
1762 | int queueBuffer_deprecated_static(struct ANativeWindow* window, |
1763 | struct ANativeWindowBuffer* buffer) |
1764 | { |
1765 | auto self = static_cast<mga::MirNativeWindow*>(window); |
1766 | - auto fence = std::make_shared<mga::SyncFence>(); |
1767 | - return self->queueBuffer(buffer, fence); |
1768 | + return self->queueBuffer(buffer, -1); |
1769 | } |
1770 | |
1771 | int queueBuffer_static(struct ANativeWindow* window, |
1772 | struct ANativeWindowBuffer* buffer, int fence_fd) |
1773 | { |
1774 | auto self = static_cast<mga::MirNativeWindow*>(window); |
1775 | - auto fence = std::make_shared<mga::SyncFence>(fence_fd); |
1776 | - return self->queueBuffer(buffer, fence); |
1777 | - |
1778 | + return self->queueBuffer(buffer, fence_fd); |
1779 | } |
1780 | |
1781 | int setSwapInterval_static (struct ANativeWindow* window, int interval) |
1782 | @@ -160,19 +158,23 @@ |
1783 | return 0; |
1784 | } |
1785 | |
1786 | -int mga::MirNativeWindow::dequeueBuffer (struct ANativeWindowBuffer** buffer_to_driver) |
1787 | +int mga::MirNativeWindow::dequeueBuffer(struct ANativeWindowBuffer** buffer_to_driver, int* fence_fd) |
1788 | { |
1789 | - *buffer_to_driver = driver_interpreter->driver_requests_buffer(); |
1790 | + auto buffer = driver_interpreter->driver_requests_buffer(); |
1791 | + |
1792 | + //driver is responsible for closing this native handle |
1793 | + *fence_fd = buffer->copy_fence(); |
1794 | + *buffer_to_driver = buffer->anwb(); |
1795 | return 0; |
1796 | } |
1797 | |
1798 | -int mga::MirNativeWindow::queueBuffer(struct ANativeWindowBuffer* buffer, std::shared_ptr<mga::SyncObject> const& fence) |
1799 | +int mga::MirNativeWindow::queueBuffer(struct ANativeWindowBuffer* buffer, int fence) |
1800 | { |
1801 | driver_interpreter->driver_returns_buffer(buffer, fence); |
1802 | return 0; |
1803 | } |
1804 | |
1805 | -int mga::MirNativeWindow::query(int key, int* value ) const |
1806 | +int mga::MirNativeWindow::query(int key, int* value) const |
1807 | { |
1808 | *value = driver_interpreter->driver_requests_info(key); |
1809 | return 0; |
1810 | |
1811 | === renamed file 'src/shared/graphics/android/mir_native_buffer.cpp' => 'src/shared/graphics/android/refcounted_buffer.cpp' |
1812 | --- src/shared/graphics/android/mir_native_buffer.cpp 2013-10-09 07:04:15 +0000 |
1813 | +++ src/shared/graphics/android/refcounted_buffer.cpp 2013-10-14 15:38:18 +0000 |
1814 | @@ -16,25 +16,54 @@ |
1815 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
1816 | */ |
1817 | |
1818 | -#include "mir/graphics/android/mir_native_buffer.h" |
1819 | +#include "mir/graphics/android/android_native_buffer.h" |
1820 | |
1821 | namespace mga=mir::graphics::android; |
1822 | |
1823 | namespace |
1824 | { |
1825 | -void incref_hook(struct android_native_base_t* base) |
1826 | +static void incref_hook(struct android_native_base_t* base) |
1827 | { |
1828 | - auto buffer = reinterpret_cast<mga::MirNativeBuffer*>(base); |
1829 | + auto buffer = reinterpret_cast<mga::RefCountedNativeBuffer*>(base); |
1830 | buffer->driver_reference(); |
1831 | } |
1832 | void decref_hook(struct android_native_base_t* base) |
1833 | { |
1834 | - auto buffer = reinterpret_cast<mga::MirNativeBuffer*>(base); |
1835 | + auto buffer = reinterpret_cast<mga::RefCountedNativeBuffer*>(base); |
1836 | buffer->driver_dereference(); |
1837 | } |
1838 | } |
1839 | |
1840 | -mga::MirNativeBuffer::MirNativeBuffer(std::shared_ptr<const native_handle_t> const& handle) |
1841 | +void mga::RefCountedNativeBuffer::driver_reference() |
1842 | +{ |
1843 | + std::unique_lock<std::mutex> lk(mutex); |
1844 | + driver_references++; |
1845 | +} |
1846 | + |
1847 | +void mga::RefCountedNativeBuffer::driver_dereference() |
1848 | +{ |
1849 | + std::unique_lock<std::mutex> lk(mutex); |
1850 | + driver_references--; |
1851 | + if ((!mir_reference) && (driver_references == 0)) |
1852 | + { |
1853 | + lk.unlock(); |
1854 | + delete this; |
1855 | + } |
1856 | +} |
1857 | + |
1858 | +void mga::RefCountedNativeBuffer::mir_dereference() |
1859 | +{ |
1860 | + std::unique_lock<std::mutex> lk(mutex); |
1861 | + mir_reference = false; |
1862 | + if (driver_references == 0) |
1863 | + { |
1864 | + lk.unlock(); |
1865 | + delete this; |
1866 | + } |
1867 | +} |
1868 | + |
1869 | +mga::RefCountedNativeBuffer::RefCountedNativeBuffer( |
1870 | + std::shared_ptr<const native_handle_t> const& handle) |
1871 | : handle_resource(handle), |
1872 | mir_reference(true), |
1873 | driver_references(0) |
1874 | @@ -42,36 +71,3 @@ |
1875 | common.incRef = incref_hook; |
1876 | common.decRef = decref_hook; |
1877 | } |
1878 | - |
1879 | - |
1880 | -void mga::MirNativeBuffer::driver_reference() |
1881 | -{ |
1882 | - std::unique_lock<std::mutex> lk(mutex); |
1883 | - driver_references++; |
1884 | -} |
1885 | - |
1886 | -void mga::MirNativeBuffer::driver_dereference() |
1887 | -{ |
1888 | - std::unique_lock<std::mutex> lk(mutex); |
1889 | - driver_references--; |
1890 | - if ((!mir_reference) && (driver_references == 0)) |
1891 | - { |
1892 | - lk.unlock(); |
1893 | - delete this; |
1894 | - } |
1895 | -} |
1896 | - |
1897 | -void mga::MirNativeBuffer::mir_dereference() |
1898 | -{ |
1899 | - std::unique_lock<std::mutex> lk(mutex); |
1900 | - mir_reference = false; |
1901 | - if (driver_references == 0) |
1902 | - { |
1903 | - lk.unlock(); |
1904 | - delete this; |
1905 | - } |
1906 | -} |
1907 | - |
1908 | -mga::MirNativeBuffer::~MirNativeBuffer() |
1909 | -{ |
1910 | -} |
1911 | |
1912 | === modified file 'src/shared/graphics/android/syncfence.cpp' |
1913 | --- src/shared/graphics/android/syncfence.cpp 2013-10-04 00:07:09 +0000 |
1914 | +++ src/shared/graphics/android/syncfence.cpp 2013-10-14 15:38:18 +0000 |
1915 | @@ -16,7 +16,7 @@ |
1916 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
1917 | */ |
1918 | |
1919 | -#include "mir/graphics/android/syncfence.h" |
1920 | +#include "mir/graphics/android/sync_fence.h" |
1921 | |
1922 | #include <unistd.h> |
1923 | #include <sys/ioctl.h> |
1924 | @@ -24,13 +24,9 @@ |
1925 | |
1926 | namespace mga = mir::graphics::android; |
1927 | |
1928 | -mga::SyncFence::SyncFence() |
1929 | - : fence_fd(-1) |
1930 | -{ |
1931 | -} |
1932 | - |
1933 | -mga::SyncFence::SyncFence(int fd) |
1934 | - : fence_fd(fd) |
1935 | +mga::SyncFence::SyncFence(std::shared_ptr<mga::SyncFileOps> const& ops, int fd) |
1936 | + : fence_fd(fd), |
1937 | + ops(ops) |
1938 | { |
1939 | } |
1940 | |
1941 | @@ -38,7 +34,7 @@ |
1942 | { |
1943 | if (fence_fd > 0) |
1944 | { |
1945 | - ::close(fence_fd); |
1946 | + ops->close(fence_fd); |
1947 | } |
1948 | } |
1949 | |
1950 | @@ -46,7 +42,54 @@ |
1951 | { |
1952 | if (fence_fd > 0) |
1953 | { |
1954 | - int timeout = -1; |
1955 | - ::ioctl(fence_fd, SYNC_IOC_WAIT, &timeout); |
1956 | - } |
1957 | + int timeout = infinite_timeout; |
1958 | + ops->ioctl(fence_fd, SYNC_IOC_WAIT, &timeout); |
1959 | + ops->close(fence_fd); |
1960 | + fence_fd = -1; |
1961 | + } |
1962 | +} |
1963 | + |
1964 | +void mga::SyncFence::merge_with(NativeFence& merge_fd) |
1965 | +{ |
1966 | + if (merge_fd < 0) |
1967 | + { |
1968 | + return; |
1969 | + } |
1970 | + |
1971 | + if (fence_fd < 0) |
1972 | + { |
1973 | + //our fence was invalid, adopt the other fence |
1974 | + fence_fd = merge_fd; |
1975 | + } |
1976 | + else |
1977 | + { |
1978 | + //both fences were valid, must merge |
1979 | + struct sync_merge_data data { merge_fd, "mirfence", infinite_timeout }; |
1980 | + ops->ioctl(fence_fd, SYNC_IOC_MERGE, &data); |
1981 | + ops->close(fence_fd); |
1982 | + ops->close(merge_fd); |
1983 | + fence_fd = data.fence; |
1984 | + } |
1985 | + |
1986 | + merge_fd = -1; |
1987 | +} |
1988 | + |
1989 | +mga::NativeFence mga::SyncFence::copy_native_handle() const |
1990 | +{ |
1991 | + return ops->dup(fence_fd); |
1992 | +} |
1993 | + |
1994 | +int mga::RealSyncFileOps::ioctl(int fd, int req, void* dat) |
1995 | +{ |
1996 | + return ::ioctl(fd, req, dat); |
1997 | +} |
1998 | + |
1999 | +int mga::RealSyncFileOps::dup(int fd) |
2000 | +{ |
2001 | + return ::dup(fd); |
2002 | +} |
2003 | + |
2004 | +int mga::RealSyncFileOps::close(int fd) |
2005 | +{ |
2006 | + return ::close(fd); |
2007 | } |
2008 | |
2009 | === modified file 'tests/draw/android_graphics.cpp' |
2010 | --- tests/draw/android_graphics.cpp 2013-05-14 21:39:52 +0000 |
2011 | +++ tests/draw/android_graphics.cpp 2013-10-14 15:38:18 +0000 |
2012 | @@ -96,7 +96,7 @@ |
2013 | } |
2014 | |
2015 | std::shared_ptr<MirGraphicsRegion> mtd::TestGrallocMapper::graphic_region_from_handle( |
2016 | - std::shared_ptr<ANativeWindowBuffer> const& package) |
2017 | + ANativeWindowBuffer* package) |
2018 | { |
2019 | int *vaddr; |
2020 | int usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN; |
2021 | |
2022 | === modified file 'tests/integration-tests/client/test_client_render.cpp' |
2023 | --- tests/integration-tests/client/test_client_render.cpp 2013-09-24 11:07:53 +0000 |
2024 | +++ tests/integration-tests/client/test_client_render.cpp 2013-10-14 15:38:18 +0000 |
2025 | @@ -20,6 +20,7 @@ |
2026 | |
2027 | #include "mir/graphics/buffer_properties.h" |
2028 | #include "mir/graphics/buffer_initializer.h" |
2029 | +#include "mir/graphics/android/native_buffer.h" |
2030 | #include "src/server/graphics/android/android_graphic_buffer_allocator.h" |
2031 | |
2032 | #include "mir_test/draw/android_graphics.h" |
2033 | @@ -311,7 +312,7 @@ |
2034 | /* server code */ |
2035 | struct StubServerGenerator : public mt::StubServerTool |
2036 | { |
2037 | - StubServerGenerator(std::shared_ptr<MirNativeBuffer> const& handle, int id) |
2038 | + StubServerGenerator(std::shared_ptr<mg::NativeBuffer> const& handle, int id) |
2039 | : handle(handle), |
2040 | next_received(false), |
2041 | next_allowed(false), |
2042 | @@ -330,10 +331,10 @@ |
2043 | response->set_height(test_height); |
2044 | response->set_pixel_format(request->pixel_format()); |
2045 | response->mutable_buffer()->set_buffer_id(handle_id); |
2046 | - response->mutable_buffer()->set_stride(handle->stride); |
2047 | + response->mutable_buffer()->set_stride(handle->anwb()->stride); |
2048 | |
2049 | response->mutable_buffer()->set_fds_on_side_channel(1); |
2050 | - native_handle_t const* native_handle = handle->handle; |
2051 | + native_handle_t const* native_handle = handle->handle(); |
2052 | for(auto i=0; i<native_handle->numFds; i++) |
2053 | response->mutable_buffer()->add_fd(native_handle->data[i]); |
2054 | for(auto i=0; i<native_handle->numInts; i++) |
2055 | @@ -366,8 +367,8 @@ |
2056 | response->set_buffer_id(handle_id); |
2057 | |
2058 | response->set_fds_on_side_channel(1); |
2059 | - native_handle_t const* native_handle = handle->handle; |
2060 | - response->set_stride(handle->stride); |
2061 | + native_handle_t const* native_handle = handle->handle(); |
2062 | + response->set_stride(handle->anwb()->stride); |
2063 | for(auto i=0; i<native_handle->numFds; i++) |
2064 | response->add_fd(native_handle->data[i]); |
2065 | for(auto i=0; i<native_handle->numInts; i++) |
2066 | @@ -392,14 +393,14 @@ |
2067 | lk.unlock(); |
2068 | } |
2069 | |
2070 | - void set_handle(std::shared_ptr<MirNativeBuffer> const& pack, int id) |
2071 | + void set_handle(std::shared_ptr<mg::NativeBuffer> const& pack, int id) |
2072 | { |
2073 | handle = pack; |
2074 | handle_id = id; |
2075 | } |
2076 | |
2077 | private: |
2078 | - std::shared_ptr<MirNativeBuffer> handle; |
2079 | + std::shared_ptr<mg::NativeBuffer> handle; |
2080 | |
2081 | std::mutex next_guard; |
2082 | std::condition_variable next_cv; |
2083 | @@ -485,8 +486,8 @@ |
2084 | std::shared_ptr<mtd::TestGrallocMapper> buffer_converter; |
2085 | std::shared_ptr<mtf::Process> client_process; |
2086 | |
2087 | - std::shared_ptr<MirNativeBuffer> handle; |
2088 | - std::shared_ptr<MirNativeBuffer> second_handle; |
2089 | + std::shared_ptr<mg::NativeBuffer> handle; |
2090 | + std::shared_ptr<mg::NativeBuffer> second_handle; |
2091 | |
2092 | std::shared_ptr<mg::Buffer> android_buffer; |
2093 | std::shared_ptr<mg::Buffer> second_android_buffer; |
2094 | @@ -514,7 +515,7 @@ |
2095 | EXPECT_TRUE(render_single_client_process->wait_for_termination().succeeded()); |
2096 | |
2097 | /* check content */ |
2098 | - auto region = buffer_converter->graphic_region_from_handle(handle); |
2099 | + auto region = buffer_converter->graphic_region_from_handle(handle->anwb()); |
2100 | EXPECT_TRUE(rendered_pattern.check(region)); |
2101 | } |
2102 | |
2103 | @@ -527,7 +528,7 @@ |
2104 | |
2105 | /* wait for next buffer */ |
2106 | mock_server->wait_on_next_buffer(); |
2107 | - auto region = buffer_converter->graphic_region_from_handle(handle); |
2108 | + auto region = buffer_converter->graphic_region_from_handle(handle->anwb()); |
2109 | EXPECT_TRUE(rendered_pattern0.check(region)); |
2110 | |
2111 | mock_server->set_handle(second_handle, 15); |
2112 | @@ -536,7 +537,7 @@ |
2113 | /* wait for client to finish */ |
2114 | EXPECT_TRUE(render_double_client_process->wait_for_termination().succeeded()); |
2115 | |
2116 | - auto second_region = buffer_converter->graphic_region_from_handle(second_handle); |
2117 | + auto second_region = buffer_converter->graphic_region_from_handle(second_handle->anwb()); |
2118 | EXPECT_TRUE(rendered_pattern1.check(second_region)); |
2119 | } |
2120 | |
2121 | @@ -554,7 +555,7 @@ |
2122 | EXPECT_TRUE(second_render_with_same_buffer_client_process->wait_for_termination().succeeded()); |
2123 | |
2124 | /* check content */ |
2125 | - auto region = buffer_converter->graphic_region_from_handle(handle); |
2126 | + auto region = buffer_converter->graphic_region_from_handle(handle->anwb()); |
2127 | EXPECT_TRUE(rendered_pattern.check(region)); |
2128 | } |
2129 | |
2130 | @@ -573,7 +574,7 @@ |
2131 | EXPECT_TRUE(render_accelerated_process->wait_for_termination().succeeded()); |
2132 | |
2133 | /* check content */ |
2134 | - auto region = buffer_converter->graphic_region_from_handle(handle); |
2135 | + auto region = buffer_converter->graphic_region_from_handle(handle->anwb()); |
2136 | EXPECT_TRUE(red_pattern.check(region)); |
2137 | } |
2138 | |
2139 | @@ -596,9 +597,9 @@ |
2140 | EXPECT_TRUE(render_accelerated_process_double->wait_for_termination().succeeded()); |
2141 | |
2142 | /* check content */ |
2143 | - auto region = buffer_converter->graphic_region_from_handle(handle); |
2144 | + auto region = buffer_converter->graphic_region_from_handle(handle->anwb()); |
2145 | EXPECT_TRUE(red_pattern.check(region)); |
2146 | |
2147 | - auto second_region = buffer_converter->graphic_region_from_handle(second_handle); |
2148 | + auto second_region = buffer_converter->graphic_region_from_handle(second_handle->anwb()); |
2149 | EXPECT_TRUE(green_pattern.check(second_region)); |
2150 | } |
2151 | |
2152 | === modified file 'tests/integration-tests/graphics/android/test_buffer_integration.cpp' |
2153 | --- tests/integration-tests/graphics/android/test_buffer_integration.cpp 2013-08-28 03:41:48 +0000 |
2154 | +++ tests/integration-tests/graphics/android/test_buffer_integration.cpp 2013-10-14 15:38:18 +0000 |
2155 | @@ -20,6 +20,7 @@ |
2156 | #include "src/server/compositor/switching_bundle.h" |
2157 | #include "mir/graphics/buffer_initializer.h" |
2158 | #include "mir/graphics/null_display_report.h" |
2159 | +#include "mir/graphics/android/native_buffer.h" |
2160 | #include "mir/graphics/buffer_properties.h" |
2161 | |
2162 | #include "mir_test/draw/android_graphics.h" |
2163 | @@ -65,7 +66,7 @@ |
2164 | mg::BufferProperties sw_properties{size, pf, mg::BufferUsage::software}; |
2165 | auto test_buffer = allocator->alloc_buffer(sw_properties); |
2166 | |
2167 | - auto region = sw_renderer.graphic_region_from_handle(test_buffer->native_buffer_handle()); |
2168 | + auto region = sw_renderer.graphic_region_from_handle(test_buffer->native_buffer_handle()->anwb()); |
2169 | mtd::DrawPatternSolid red_pattern(0xFF0000FF); |
2170 | red_pattern.draw(region); |
2171 | EXPECT_TRUE(red_pattern.check(region)); |
2172 | |
2173 | === modified file 'tests/mir_test_framework/testing_client_options.cpp' |
2174 | --- tests/mir_test_framework/testing_client_options.cpp 2013-09-25 17:45:08 +0000 |
2175 | +++ tests/mir_test_framework/testing_client_options.cpp 2013-10-14 15:38:18 +0000 |
2176 | @@ -65,7 +65,7 @@ |
2177 | void mark_as_submitted() |
2178 | { |
2179 | } |
2180 | - std::shared_ptr<MirNativeBuffer> native_buffer_handle() const |
2181 | + std::shared_ptr<mir::graphics::NativeBuffer> native_buffer_handle() const |
2182 | { |
2183 | return nullptr; |
2184 | } |
2185 | @@ -103,6 +103,11 @@ |
2186 | auto fake_display = reinterpret_cast<EGLNativeDisplayType>(0x12345678); |
2187 | return std::make_shared<EGLNativeDisplayType>(fake_display); |
2188 | } |
2189 | + |
2190 | + MirNativeBuffer* convert_native_buffer(mir::graphics::NativeBuffer*) const |
2191 | + { |
2192 | + return nullptr; |
2193 | + } |
2194 | }; |
2195 | |
2196 | struct StubClientPlatformFactory : public mcl::ClientPlatformFactory |
2197 | |
2198 | === modified file 'tests/mir_test_framework/testing_server_options.cpp' |
2199 | --- tests/mir_test_framework/testing_server_options.cpp 2013-09-24 10:25:41 +0000 |
2200 | +++ tests/mir_test_framework/testing_server_options.cpp 2013-10-14 15:38:18 +0000 |
2201 | @@ -75,10 +75,10 @@ |
2202 | std::runtime_error("Failed to open dummy fd")) << boost::errinfo_errno(errno)); |
2203 | } |
2204 | |
2205 | - std::shared_ptr<MirNativeBuffer> native_buffer_handle() const override |
2206 | + std::shared_ptr<mg::NativeBuffer> native_buffer_handle() const override |
2207 | { |
2208 | #ifndef ANDROID |
2209 | - auto native_buffer = std::make_shared<MirNativeBuffer>(); |
2210 | + auto native_buffer = std::make_shared<mg::NativeBuffer>(); |
2211 | native_buffer->data_items = 1; |
2212 | native_buffer->data[0] = 0xDEADBEEF; |
2213 | native_buffer->fd_items = 1; |
2214 | @@ -93,7 +93,7 @@ |
2215 | } |
2216 | return native_buffer; |
2217 | #else |
2218 | - return std::shared_ptr<MirNativeBuffer>(); |
2219 | + return std::shared_ptr<mg::NativeBuffer>(); |
2220 | #endif |
2221 | } |
2222 | |
2223 | |
2224 | === modified file 'tests/unit-tests/client/android/test_android_native_window.cpp' |
2225 | --- tests/unit-tests/client/android/test_android_native_window.cpp 2013-05-16 20:07:39 +0000 |
2226 | +++ tests/unit-tests/client/android/test_android_native_window.cpp 2013-10-14 15:38:18 +0000 |
2227 | @@ -18,31 +18,37 @@ |
2228 | |
2229 | #include "mir/graphics/android/mir_native_window.h" |
2230 | #include "mir/graphics/android/android_driver_interpreter.h" |
2231 | -#include "mir/graphics/android/sync_object.h" |
2232 | #include "src/client/mir_client_surface.h" |
2233 | +#include "mir_test_doubles/mock_android_native_buffer.h" |
2234 | +#include "mir_test_doubles/mock_fence.h" |
2235 | |
2236 | #include <gmock/gmock.h> |
2237 | #include <gtest/gtest.h> |
2238 | #include <memory> |
2239 | + |
2240 | namespace mga=mir::graphics::android; |
2241 | +namespace mtd=mir::test::doubles; |
2242 | |
2243 | namespace |
2244 | { |
2245 | |
2246 | -struct MockSyncFence : public mga::SyncObject |
2247 | -{ |
2248 | - ~MockSyncFence() noexcept {} |
2249 | - MOCK_METHOD0(wait, void()); |
2250 | -}; |
2251 | - |
2252 | class MockAndroidDriverInterpreter : public mga::AndroidDriverInterpreter |
2253 | { |
2254 | public: |
2255 | - MOCK_METHOD0(driver_requests_buffer, ANativeWindowBuffer*()); |
2256 | - MOCK_METHOD2(driver_returns_buffer, void(ANativeWindowBuffer*, std::shared_ptr<mga::SyncObject>const& )); |
2257 | + MockAndroidDriverInterpreter() |
2258 | + : buffer(std::make_shared<mtd::StubAndroidNativeBuffer>()) |
2259 | + { |
2260 | + using namespace testing; |
2261 | + ON_CALL(*this, driver_requests_buffer()) |
2262 | + .WillByDefault(Return(buffer.get())); |
2263 | + } |
2264 | + MOCK_METHOD0(driver_requests_buffer, mir::graphics::NativeBuffer*()); |
2265 | + MOCK_METHOD2(driver_returns_buffer, void(ANativeWindowBuffer*, int)); |
2266 | MOCK_METHOD1(dispatch_driver_request_format, void(int)); |
2267 | MOCK_CONST_METHOD1(driver_requests_info, int(int)); |
2268 | MOCK_METHOD1(sync_to_display, void(bool)); |
2269 | + |
2270 | + std::shared_ptr<mir::graphics::NativeBuffer> buffer; |
2271 | }; |
2272 | } |
2273 | |
2274 | @@ -137,29 +143,23 @@ |
2275 | { |
2276 | using namespace testing; |
2277 | |
2278 | - ANativeWindowBuffer* returned_buffer; |
2279 | - ANativeWindowBuffer fake_buffer; |
2280 | - int fence_fd; |
2281 | - std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter); |
2282 | - |
2283 | + int fake_fd = 4948; |
2284 | + auto mock_buffer = std::make_shared<mtd::MockAndroidNativeBuffer>(); |
2285 | + EXPECT_CALL(*mock_buffer, copy_fence()) |
2286 | + .Times(1) |
2287 | + .WillOnce(Return(fake_fd)); |
2288 | EXPECT_CALL(*mock_driver_interpreter, driver_requests_buffer()) |
2289 | .Times(1) |
2290 | - .WillOnce(Return(&fake_buffer)); |
2291 | - |
2292 | - window->dequeueBuffer(window.get(), &returned_buffer, &fence_fd); |
2293 | - |
2294 | - EXPECT_EQ(&fake_buffer, returned_buffer); |
2295 | -} |
2296 | - |
2297 | - |
2298 | -TEST_F(AndroidNativeWindowTest, native_window_dequeue_indicates_buffer_immediately_usable) |
2299 | -{ |
2300 | + .WillOnce(Return(mock_buffer.get())); |
2301 | + |
2302 | + std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter); |
2303 | + |
2304 | + int fence_fd; |
2305 | ANativeWindowBuffer* returned_buffer; |
2306 | - int fence_fd; |
2307 | - std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter); |
2308 | - |
2309 | window->dequeueBuffer(window.get(), &returned_buffer, &fence_fd); |
2310 | - EXPECT_EQ(-1, fence_fd); |
2311 | + |
2312 | + EXPECT_EQ(mock_buffer->anwb(), returned_buffer); |
2313 | + EXPECT_EQ(fake_fd, fence_fd); |
2314 | } |
2315 | |
2316 | TEST_F(AndroidNativeWindowTest, native_window_dequeue_deprecated_hook_callable) |
2317 | @@ -176,15 +176,15 @@ |
2318 | using namespace testing; |
2319 | |
2320 | ANativeWindowBuffer* returned_buffer; |
2321 | - ANativeWindowBuffer fake_buffer; |
2322 | + auto fake_buffer = std::make_shared<mtd::StubAndroidNativeBuffer>(); |
2323 | std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter); |
2324 | |
2325 | EXPECT_CALL(*mock_driver_interpreter, driver_requests_buffer()) |
2326 | .Times(1) |
2327 | - .WillOnce(Return(&fake_buffer)); |
2328 | + .WillOnce(Return(fake_buffer.get())); |
2329 | |
2330 | window->dequeueBuffer_DEPRECATED(window.get(), &returned_buffer); |
2331 | - EXPECT_EQ(&fake_buffer, returned_buffer); |
2332 | + EXPECT_EQ(fake_buffer->anwb(), returned_buffer); |
2333 | } |
2334 | |
2335 | /* queue hook tests */ |
2336 | @@ -204,7 +204,7 @@ |
2337 | int fence_fd = 33; |
2338 | std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter); |
2339 | |
2340 | - EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer, _)) |
2341 | + EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer, fence_fd)) |
2342 | .Times(1); |
2343 | |
2344 | window->queueBuffer(window.get(), &buffer, fence_fd); |
2345 | |
2346 | === modified file 'tests/unit-tests/client/android/test_client_android_buffer.cpp' |
2347 | --- tests/unit-tests/client/android/test_client_android_buffer.cpp 2013-08-28 03:41:48 +0000 |
2348 | +++ tests/unit-tests/client/android/test_client_android_buffer.cpp 2013-10-14 15:38:18 +0000 |
2349 | @@ -142,24 +142,28 @@ |
2350 | static_cast<int32_t>(stride.as_uint32_t() / geom::bytes_per_pixel(pf)); |
2351 | mcla::AndroidClientBuffer buffer(mock_android_registrar, package, size, pf, stride); |
2352 | auto native_handle = buffer.native_buffer_handle(); |
2353 | - |
2354 | ASSERT_NE(nullptr, native_handle); |
2355 | - EXPECT_EQ(package.get(), native_handle->handle); |
2356 | - EXPECT_EQ(width.as_uint32_t(), static_cast<uint32_t>(native_handle->width)); |
2357 | - EXPECT_EQ(height.as_uint32_t(), static_cast<uint32_t>(native_handle->height)); |
2358 | - EXPECT_EQ(correct_usage, native_handle->usage); |
2359 | - EXPECT_EQ(expected_stride_in_pixels, native_handle->stride); |
2360 | + |
2361 | + auto anwb = native_handle->anwb(); |
2362 | + ASSERT_NE(nullptr, anwb); |
2363 | + |
2364 | + EXPECT_EQ(package.get(), anwb->handle); |
2365 | + EXPECT_EQ(width.as_uint32_t(), static_cast<uint32_t>(anwb->width)); |
2366 | + EXPECT_EQ(height.as_uint32_t(), static_cast<uint32_t>(anwb->height)); |
2367 | + EXPECT_EQ(correct_usage, anwb->usage); |
2368 | + EXPECT_EQ(expected_stride_in_pixels, anwb->stride); |
2369 | } |
2370 | |
2371 | TEST_F(ClientAndroidBufferTest, buffer_packs_anativewindowbuffer_refcounters_set) |
2372 | { |
2373 | mcla::AndroidClientBuffer buffer(mock_android_registrar, package, size, pf, stride); |
2374 | auto native_handle = buffer.native_buffer_handle(); |
2375 | - |
2376 | - ASSERT_NE(nullptr, native_handle); |
2377 | - ASSERT_NE(nullptr, native_handle->common.incRef); |
2378 | - ASSERT_NE(nullptr, native_handle->common.decRef); |
2379 | - |
2380 | - native_handle->common.incRef(&native_handle->common); |
2381 | - native_handle->common.decRef(&native_handle->common); |
2382 | + auto anwb = native_handle->anwb(); |
2383 | + |
2384 | + ASSERT_NE(nullptr, anwb); |
2385 | + ASSERT_NE(nullptr, anwb->common.incRef); |
2386 | + ASSERT_NE(nullptr, anwb->common.decRef); |
2387 | + |
2388 | + anwb->common.incRef(&anwb->common); |
2389 | + anwb->common.decRef(&anwb->common); |
2390 | } |
2391 | |
2392 | === modified file 'tests/unit-tests/client/android/test_client_surface_interpreter.cpp' |
2393 | --- tests/unit-tests/client/android/test_client_surface_interpreter.cpp 2013-09-24 22:20:17 +0000 |
2394 | +++ tests/unit-tests/client/android/test_client_surface_interpreter.cpp 2013-10-14 15:38:18 +0000 |
2395 | @@ -16,9 +16,12 @@ |
2396 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
2397 | */ |
2398 | |
2399 | +#include "mir/graphics/android/native_buffer.h" |
2400 | #include "src/client/mir_client_surface.h" |
2401 | #include "src/client/client_buffer.h" |
2402 | #include "src/client/android/client_surface_interpreter.h" |
2403 | +#include "mir_test_doubles/mock_android_native_buffer.h" |
2404 | +#include "mir_test/fake_shared.h" |
2405 | #include <system/window.h> |
2406 | #include <gmock/gmock.h> |
2407 | #include <gtest/gtest.h> |
2408 | @@ -27,20 +30,16 @@ |
2409 | namespace mcla=mir::client::android; |
2410 | namespace mga=mir::graphics::android; |
2411 | namespace geom=mir::geometry; |
2412 | +namespace mt=mir::test; |
2413 | +namespace mtd=mir::test::doubles; |
2414 | |
2415 | -namespace |
2416 | -{ |
2417 | -struct MockSyncFence : public mga::SyncObject |
2418 | -{ |
2419 | - ~MockSyncFence() noexcept {} |
2420 | - MOCK_METHOD0(wait, void()); |
2421 | -}; |
2422 | struct MockClientBuffer : public mcl::ClientBuffer |
2423 | { |
2424 | MockClientBuffer() |
2425 | { |
2426 | using namespace testing; |
2427 | - buffer = std::make_shared<ANativeWindowBuffer>(); |
2428 | + buffer = std::make_shared<mtd::StubAndroidNativeBuffer>(); |
2429 | + |
2430 | ON_CALL(*this, native_buffer_handle()) |
2431 | .WillByDefault(Return(buffer)); |
2432 | } |
2433 | @@ -55,9 +54,9 @@ |
2434 | MOCK_METHOD0(mark_as_submitted, void()); |
2435 | MOCK_METHOD0(increment_age, void()); |
2436 | |
2437 | - MOCK_CONST_METHOD0(native_buffer_handle, std::shared_ptr<MirNativeBuffer>()); |
2438 | + MOCK_CONST_METHOD0(native_buffer_handle, std::shared_ptr<mir::graphics::NativeBuffer>()); |
2439 | |
2440 | - std::shared_ptr<ANativeWindowBuffer> buffer; |
2441 | + std::shared_ptr<mir::graphics::NativeBuffer> buffer; |
2442 | native_handle_t handle; |
2443 | }; |
2444 | |
2445 | @@ -80,7 +79,6 @@ |
2446 | MOCK_METHOD2(configure, MirWaitHandle*(MirSurfaceAttrib, int)); |
2447 | MirSurfaceParameters params; |
2448 | }; |
2449 | -} |
2450 | |
2451 | class AndroidInterpreterTest : public ::testing::Test |
2452 | { |
2453 | @@ -93,12 +91,10 @@ |
2454 | surf_params.pixel_format = mir_pixel_format_abgr_8888; |
2455 | |
2456 | mock_client_buffer = std::make_shared<NiceMock<MockClientBuffer>>(); |
2457 | - mock_sync = std::make_shared<NiceMock<MockSyncFence>>(); |
2458 | } |
2459 | |
2460 | MirSurfaceParameters surf_params; |
2461 | std::shared_ptr<MockClientBuffer> mock_client_buffer; |
2462 | - std::shared_ptr<MockSyncFence> mock_sync; |
2463 | }; |
2464 | |
2465 | TEST_F(AndroidInterpreterTest, native_window_dequeue_calls_surface_get_current) |
2466 | @@ -117,9 +113,7 @@ |
2467 | TEST_F(AndroidInterpreterTest, native_window_dequeue_gets_native_handle_from_returned_buffer) |
2468 | { |
2469 | using namespace testing; |
2470 | - native_handle_t handle; |
2471 | - auto buffer = std::make_shared<ANativeWindowBuffer>(); |
2472 | - buffer->handle = &handle; |
2473 | + auto buffer = std::make_shared<mtd::StubAndroidNativeBuffer>(); |
2474 | |
2475 | testing::NiceMock<MockMirSurface> mock_surface{surf_params}; |
2476 | mcla::ClientSurfaceInterpreter interpreter(mock_surface); |
2477 | @@ -146,21 +140,7 @@ |
2478 | EXPECT_CALL(mock_surface, next_buffer(_,_)) |
2479 | .Times(1); |
2480 | |
2481 | - interpreter.driver_returns_buffer(&buffer, mock_sync); |
2482 | -} |
2483 | - |
2484 | -TEST_F(AndroidInterpreterTest, native_window_queue_waits_on_fence) |
2485 | -{ |
2486 | - using namespace testing; |
2487 | - ANativeWindowBuffer buffer; |
2488 | - |
2489 | - testing::NiceMock<MockMirSurface> mock_surface{surf_params}; |
2490 | - mcla::ClientSurfaceInterpreter interpreter(mock_surface); |
2491 | - |
2492 | - EXPECT_CALL(*mock_sync, wait()) |
2493 | - .Times(1); |
2494 | - |
2495 | - interpreter.driver_returns_buffer(&buffer, mock_sync); |
2496 | + interpreter.driver_returns_buffer(&buffer, -1); |
2497 | } |
2498 | |
2499 | /* format is an int that is set by the driver. these are not the HAL_PIXEL_FORMATS in android */ |
2500 | |
2501 | === modified file 'tests/unit-tests/client/test_aging_buffer.cpp' |
2502 | --- tests/unit-tests/client/test_aging_buffer.cpp 2013-05-02 19:05:14 +0000 |
2503 | +++ tests/unit-tests/client/test_aging_buffer.cpp 2013-10-14 15:38:18 +0000 |
2504 | @@ -51,7 +51,7 @@ |
2505 | exit(1); |
2506 | } |
2507 | |
2508 | - std::shared_ptr<MirNativeBuffer> native_buffer_handle() const |
2509 | + std::shared_ptr<mir::graphics::NativeBuffer> native_buffer_handle() const |
2510 | { |
2511 | exit(1); |
2512 | } |
2513 | |
2514 | === modified file 'tests/unit-tests/client/test_client_buffer_depository.cpp' |
2515 | --- tests/unit-tests/client/test_client_buffer_depository.cpp 2013-05-03 18:39:57 +0000 |
2516 | +++ tests/unit-tests/client/test_client_buffer_depository.cpp 2013-10-14 15:38:18 +0000 |
2517 | @@ -52,7 +52,7 @@ |
2518 | MOCK_CONST_METHOD0(size, geom::Size()); |
2519 | MOCK_CONST_METHOD0(stride, geom::Stride()); |
2520 | MOCK_CONST_METHOD0(pixel_format, geom::PixelFormat()); |
2521 | - MOCK_CONST_METHOD0(native_buffer_handle, std::shared_ptr<MirNativeBuffer>()); |
2522 | + MOCK_CONST_METHOD0(native_buffer_handle, std::shared_ptr<mir::graphics::NativeBuffer>()); |
2523 | }; |
2524 | |
2525 | struct MockClientBufferFactory : public mcl::ClientBufferFactory |
2526 | |
2527 | === modified file 'tests/unit-tests/client/test_client_mir_surface.cpp' |
2528 | --- tests/unit-tests/client/test_client_mir_surface.cpp 2013-09-27 13:03:16 +0000 |
2529 | +++ tests/unit-tests/client/test_client_mir_surface.cpp 2013-10-14 15:38:18 +0000 |
2530 | @@ -50,6 +50,7 @@ |
2531 | namespace mcl = mir::client; |
2532 | namespace mircv = mir::input::receiver; |
2533 | namespace mp = mir::protobuf; |
2534 | +namespace mg = mir::graphics; |
2535 | namespace geom = mir::geometry; |
2536 | |
2537 | namespace mir |
2538 | @@ -179,7 +180,7 @@ |
2539 | MOCK_CONST_METHOD0(age, uint32_t()); |
2540 | MOCK_METHOD0(increment_age, void()); |
2541 | MOCK_METHOD0(mark_as_submitted, void()); |
2542 | - MOCK_CONST_METHOD0(native_buffer_handle, std::shared_ptr<MirNativeBuffer>()); |
2543 | + MOCK_CONST_METHOD0(native_buffer_handle, std::shared_ptr<mg::NativeBuffer>()); |
2544 | }; |
2545 | |
2546 | struct MockClientBufferFactory : public mcl::ClientBufferFactory |
2547 | @@ -225,6 +226,11 @@ |
2548 | { |
2549 | return std::shared_ptr<EGLNativeDisplayType>(); |
2550 | } |
2551 | + |
2552 | + MirNativeBuffer* convert_native_buffer(mir::graphics::NativeBuffer*) const |
2553 | + { |
2554 | + return nullptr; |
2555 | + } |
2556 | }; |
2557 | |
2558 | struct StubClientPlatformFactory : public mcl::ClientPlatformFactory |
2559 | @@ -607,9 +613,9 @@ |
2560 | void increment_age() {} |
2561 | void mark_as_submitted() {} |
2562 | |
2563 | - std::shared_ptr<MirNativeBuffer> native_buffer_handle() const |
2564 | + std::shared_ptr<mg::NativeBuffer> native_buffer_handle() const |
2565 | { |
2566 | - return std::shared_ptr<MirNativeBuffer>(); |
2567 | + return std::shared_ptr<mg::NativeBuffer>(); |
2568 | } |
2569 | |
2570 | geom::Size size_; |
2571 | |
2572 | === modified file 'tests/unit-tests/client/test_mir_connection.cpp' |
2573 | --- tests/unit-tests/client/test_mir_connection.cpp 2013-09-03 02:53:15 +0000 |
2574 | +++ tests/unit-tests/client/test_mir_connection.cpp 2013-10-14 15:38:18 +0000 |
2575 | @@ -102,6 +102,7 @@ |
2576 | .WillByDefault(Return(std::shared_ptr<EGLNativeWindowType>())); |
2577 | } |
2578 | |
2579 | + MOCK_CONST_METHOD1(convert_native_buffer, MirNativeBuffer*(mir::graphics::NativeBuffer*)); |
2580 | MOCK_CONST_METHOD0(platform_type, MirPlatformType()); |
2581 | MOCK_METHOD0(create_buffer_factory, std::shared_ptr<mcl::ClientBufferFactory>()); |
2582 | MOCK_METHOD1(create_egl_native_window, std::shared_ptr<EGLNativeWindowType>(mcl::ClientSurface*)); |
2583 | |
2584 | === modified file 'tests/unit-tests/graphics/android/CMakeLists.txt' |
2585 | --- tests/unit-tests/graphics/android/CMakeLists.txt 2013-06-18 18:37:32 +0000 |
2586 | +++ tests/unit-tests/graphics/android/CMakeLists.txt 2013-10-14 15:38:18 +0000 |
2587 | @@ -1,5 +1,6 @@ |
2588 | list(APPEND UNIT_TEST_SOURCES |
2589 | ${CMAKE_CURRENT_SOURCE_DIR}/test_buffer.cpp |
2590 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_sync_fence.cpp |
2591 | ${CMAKE_CURRENT_SOURCE_DIR}/test_android_buffer_allocator.cpp |
2592 | ${CMAKE_CURRENT_SOURCE_DIR}/test_buffer_tex_bind.cpp |
2593 | ${CMAKE_CURRENT_SOURCE_DIR}/test_android_fb.cpp |
2594 | |
2595 | === modified file 'tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp' |
2596 | --- tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp 2013-08-28 03:41:48 +0000 |
2597 | +++ tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp 2013-10-14 15:38:18 +0000 |
2598 | @@ -17,6 +17,7 @@ |
2599 | */ |
2600 | |
2601 | #include "src/server/graphics/android/android_alloc_adaptor.h" |
2602 | +#include "mir/graphics/android/native_buffer.h" |
2603 | |
2604 | #include "mir_test_doubles/mock_android_alloc_device.h" |
2605 | #include "mir_test_doubles/mock_alloc_adaptor.h" |
2606 | @@ -180,62 +181,63 @@ |
2607 | |
2608 | TEST_F(AdaptorICSTest, handle_size_is_correct) |
2609 | { |
2610 | - auto handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2611 | - |
2612 | - EXPECT_EQ(static_cast<int>(size.width.as_uint32_t()), handle->width); |
2613 | - EXPECT_EQ(static_cast<int>(size.height.as_uint32_t()), handle->height); |
2614 | -} |
2615 | - |
2616 | -TEST_F(AdaptorICSTest, handle_stride_is_correct) |
2617 | -{ |
2618 | - auto handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2619 | - |
2620 | - EXPECT_EQ(static_cast<int>(mock_alloc_device->fake_stride), handle->stride); |
2621 | + auto native_handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2622 | + auto anwb = native_handle->anwb(); |
2623 | + EXPECT_EQ(static_cast<int>(size.width.as_uint32_t()), anwb->width); |
2624 | + EXPECT_EQ(static_cast<int>(size.height.as_uint32_t()), anwb->height); |
2625 | + EXPECT_EQ(static_cast<int>(mock_alloc_device->fake_stride), anwb->stride); |
2626 | } |
2627 | |
2628 | TEST_F(AdaptorICSTest, handle_buffer_pf_is_converted_to_android_abgr_8888) |
2629 | { |
2630 | - auto handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2631 | - EXPECT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, handle->format); |
2632 | + auto native_handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2633 | + auto anwb = native_handle->anwb(); |
2634 | + EXPECT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, anwb->format); |
2635 | } |
2636 | |
2637 | TEST_F(AdaptorICSTest, handle_buffer_pf_is_converted_to_android_xbgr_8888) |
2638 | { |
2639 | - auto handle = alloc_adaptor->alloc_buffer(size, geom::PixelFormat::xbgr_8888, usage); |
2640 | - EXPECT_EQ(HAL_PIXEL_FORMAT_RGBX_8888, handle->format); |
2641 | + auto native_handle = alloc_adaptor->alloc_buffer(size, geom::PixelFormat::xbgr_8888, usage); |
2642 | + auto anwb = native_handle->anwb(); |
2643 | + EXPECT_EQ(HAL_PIXEL_FORMAT_RGBX_8888, anwb->format); |
2644 | } |
2645 | |
2646 | TEST_F(AdaptorICSTest, handle_buffer_usage_is_converted_to_android_use_hw) |
2647 | { |
2648 | - auto handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2649 | - EXPECT_EQ(hw_usage_flags, handle->usage); |
2650 | + auto native_handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2651 | + auto anwb = native_handle->anwb(); |
2652 | + EXPECT_EQ(hw_usage_flags, anwb->usage); |
2653 | } |
2654 | |
2655 | TEST_F(AdaptorICSTest, handle_buffer_usage_is_converted_to_android_use_fb) |
2656 | { |
2657 | - auto handle = alloc_adaptor->alloc_buffer(size, pf, mga::BufferUsage::use_framebuffer_gles); |
2658 | - EXPECT_EQ(fb_usage_flags, handle->usage); |
2659 | + auto native_handle = alloc_adaptor->alloc_buffer(size, pf, mga::BufferUsage::use_framebuffer_gles); |
2660 | + auto anwb = native_handle->anwb(); |
2661 | + EXPECT_EQ(fb_usage_flags, anwb->usage); |
2662 | } |
2663 | |
2664 | TEST_F(AdaptorICSTest, handle_has_strong_reference_for_c_drivers) |
2665 | { |
2666 | - auto handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2667 | - ASSERT_NE(nullptr, handle->common.incRef); |
2668 | - ASSERT_NE(nullptr, handle->common.decRef); |
2669 | - handle->common.incRef(&handle->common); |
2670 | - handle->common.decRef(&handle->common); |
2671 | + auto native_handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2672 | + auto anwb = native_handle->anwb(); |
2673 | + ASSERT_NE(nullptr, anwb->common.incRef); |
2674 | + ASSERT_NE(nullptr, anwb->common.decRef); |
2675 | + anwb->common.incRef(&anwb->common); |
2676 | + anwb->common.decRef(&anwb->common); |
2677 | } |
2678 | |
2679 | TEST_F(AdaptorICSTest, handle_has_right_magic) |
2680 | { |
2681 | int magic = ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r'); /* magic value shared by JB and ICS */ |
2682 | - auto handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2683 | - EXPECT_EQ(magic, handle->common.magic); |
2684 | + auto native_handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2685 | + auto anwb = native_handle->anwb(); |
2686 | + EXPECT_EQ(magic, anwb->common.magic); |
2687 | } |
2688 | |
2689 | TEST_F(AdaptorICSTest, handle_has_version) |
2690 | { |
2691 | int version = 96; /* version value shared by JB and ICS */ |
2692 | - auto handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2693 | - EXPECT_EQ(version, handle->common.version); |
2694 | + auto native_handle = alloc_adaptor->alloc_buffer(size, pf, usage); |
2695 | + auto anwb = native_handle->anwb(); |
2696 | + EXPECT_EQ(version, anwb->common.version); |
2697 | } |
2698 | |
2699 | === modified file 'tests/unit-tests/graphics/android/test_android_platform.cpp' |
2700 | --- tests/unit-tests/graphics/android/test_android_platform.cpp 2013-08-28 03:41:48 +0000 |
2701 | +++ tests/unit-tests/graphics/android/test_android_platform.cpp 2013-10-14 15:38:18 +0000 |
2702 | @@ -22,11 +22,14 @@ |
2703 | #include "mir/options/program_option.h" |
2704 | #include "mir_test_doubles/mock_buffer.h" |
2705 | #include "mir_test_doubles/mock_buffer_packer.h" |
2706 | +#include "mir_test/fake_shared.h" |
2707 | +#include "mir_test_doubles/mock_android_native_buffer.h" |
2708 | #include <system/window.h> |
2709 | #include <gtest/gtest.h> |
2710 | |
2711 | namespace mg=mir::graphics; |
2712 | namespace mga=mir::graphics::android; |
2713 | +namespace mt=mir::test; |
2714 | namespace mtd=mir::test::doubles; |
2715 | namespace geom=mir::geometry; |
2716 | namespace mo=mir::options; |
2717 | @@ -36,6 +39,8 @@ |
2718 | protected: |
2719 | virtual void SetUp() |
2720 | { |
2721 | + using namespace testing; |
2722 | + |
2723 | stub_display_report = std::make_shared<mg::NullDisplayReport>(); |
2724 | stride = geom::Stride(300*4); |
2725 | |
2726 | @@ -51,21 +56,20 @@ |
2727 | { |
2728 | native_buffer_handle->data[i] = i; |
2729 | } |
2730 | - |
2731 | - anwb = std::make_shared<ANativeWindowBuffer>(); |
2732 | - anwb->stride = (int) stride.as_uint32_t(); |
2733 | - anwb->handle = native_buffer_handle.get(); |
2734 | - |
2735 | - |
2736 | + |
2737 | + native_buffer = std::make_shared<mtd::StubAndroidNativeBuffer>(); |
2738 | mock_buffer = std::make_shared<mtd::MockBuffer>(); |
2739 | + |
2740 | + ON_CALL(*native_buffer, handle()) |
2741 | + .WillByDefault(Return(native_buffer_handle.get())); |
2742 | ON_CALL(*mock_buffer, native_buffer_handle()) |
2743 | - .WillByDefault(testing::Return(anwb)); |
2744 | + .WillByDefault(Return(native_buffer)); |
2745 | ON_CALL(*mock_buffer, stride()) |
2746 | - .WillByDefault(testing::Return(stride)); |
2747 | + .WillByDefault(Return(stride)); |
2748 | } |
2749 | |
2750 | + std::shared_ptr<mtd::MockAndroidNativeBuffer> native_buffer; |
2751 | std::shared_ptr<mtd::MockBuffer> mock_buffer; |
2752 | - std::shared_ptr<ANativeWindowBuffer> anwb; |
2753 | std::shared_ptr<native_handle_t> native_buffer_handle; |
2754 | std::shared_ptr<mg::DisplayReport> stub_display_report; |
2755 | geom::Stride stride; |
2756 | @@ -75,14 +79,6 @@ |
2757 | /* ipc packaging tests */ |
2758 | TEST_F(PlatformBufferIPCPackaging, test_ipc_data_packed_correctly) |
2759 | { |
2760 | - auto mock_buffer = std::make_shared<mtd::MockBuffer>(); |
2761 | - geom::Stride dummy_stride(4390); |
2762 | - |
2763 | - EXPECT_CALL(*mock_buffer, native_buffer_handle()) |
2764 | - .WillOnce(testing::Return(anwb)); |
2765 | - EXPECT_CALL(*mock_buffer, stride()) |
2766 | - .WillOnce(testing::Return(dummy_stride)); |
2767 | - |
2768 | auto platform = mg::create_platform(std::make_shared<mo::ProgramOption>(), stub_display_report); |
2769 | |
2770 | auto mock_packer = std::make_shared<mtd::MockPacker>(); |
2771 | @@ -97,7 +93,7 @@ |
2772 | EXPECT_CALL(*mock_packer, pack_data(native_buffer_handle->data[offset++])) |
2773 | .Times(1); |
2774 | } |
2775 | - EXPECT_CALL(*mock_packer, pack_stride(dummy_stride)) |
2776 | + EXPECT_CALL(*mock_packer, pack_stride(stride)) |
2777 | .Times(1); |
2778 | |
2779 | platform->fill_ipc_package(mock_packer, mock_buffer); |
2780 | |
2781 | === modified file 'tests/unit-tests/graphics/android/test_buffer.cpp' |
2782 | --- tests/unit-tests/graphics/android/test_buffer.cpp 2013-08-28 03:41:48 +0000 |
2783 | +++ tests/unit-tests/graphics/android/test_buffer.cpp 2013-10-14 15:38:18 +0000 |
2784 | @@ -18,7 +18,12 @@ |
2785 | |
2786 | #include "mir/graphics/egl_extensions.h" |
2787 | #include "src/server/graphics/android/buffer.h" |
2788 | +#include "mir/graphics/android/sync_fence.h" |
2789 | +#include "mir/graphics/android/native_buffer.h" |
2790 | #include "mir_test_doubles/mock_egl.h" |
2791 | +#include "mir_test_doubles/mock_fence.h" |
2792 | +#include "mir_test/fake_shared.h" |
2793 | +#include "mir_test_doubles/mock_android_native_buffer.h" |
2794 | |
2795 | #include <hardware/gralloc.h> |
2796 | #include <gtest/gtest.h> |
2797 | @@ -29,6 +34,7 @@ |
2798 | namespace mga = mir::graphics::android; |
2799 | namespace geom = mir::geometry; |
2800 | namespace mtd = mir::test::doubles; |
2801 | +namespace mt = mir::test; |
2802 | |
2803 | class AndroidGraphicBufferBasic : public ::testing::Test |
2804 | { |
2805 | @@ -36,11 +42,13 @@ |
2806 | virtual void SetUp() |
2807 | { |
2808 | using namespace testing; |
2809 | - mock_buffer_handle = std::make_shared<ANativeWindowBuffer>(); |
2810 | - mock_buffer_handle->width = 44; |
2811 | - mock_buffer_handle->height = 45; |
2812 | - mock_buffer_handle->stride = 46; |
2813 | - mock_buffer_handle->format = HAL_PIXEL_FORMAT_RGBA_8888; |
2814 | + mock_native_buffer = std::make_shared<mtd::MockAndroidNativeBuffer>(); |
2815 | + |
2816 | + anwb = mock_native_buffer->anwb(); |
2817 | + anwb->width = 44; |
2818 | + anwb->height = 45; |
2819 | + anwb->stride = 46; |
2820 | + anwb->format = HAL_PIXEL_FORMAT_RGBA_8888; |
2821 | |
2822 | default_use = mga::BufferUsage::use_hardware; |
2823 | pf = geom::PixelFormat::abgr_8888; |
2824 | @@ -48,8 +56,9 @@ |
2825 | extensions = std::make_shared<mg::EGLExtensions>(); |
2826 | } |
2827 | |
2828 | - mtd::MockEGL mock_egl; |
2829 | - std::shared_ptr<ANativeWindowBuffer> mock_buffer_handle; |
2830 | + ANativeWindowBuffer *anwb; |
2831 | + testing::NiceMock<mtd::MockEGL> mock_egl; |
2832 | + std::shared_ptr<mtd::MockAndroidNativeBuffer> mock_native_buffer; |
2833 | geom::PixelFormat pf; |
2834 | geom::Size size; |
2835 | mga::BufferUsage default_use; |
2836 | @@ -60,9 +69,9 @@ |
2837 | { |
2838 | using namespace testing; |
2839 | |
2840 | - mga::Buffer buffer(mock_buffer_handle, extensions); |
2841 | + mga::Buffer buffer(mock_native_buffer, extensions); |
2842 | |
2843 | - geom::Size expected_size{mock_buffer_handle->width, mock_buffer_handle->height}; |
2844 | + geom::Size expected_size{anwb->width, anwb->height}; |
2845 | EXPECT_EQ(expected_size, buffer.size()); |
2846 | } |
2847 | |
2848 | @@ -70,24 +79,40 @@ |
2849 | { |
2850 | using namespace testing; |
2851 | |
2852 | - mga::Buffer buffer(mock_buffer_handle, extensions); |
2853 | + mga::Buffer buffer(mock_native_buffer, extensions); |
2854 | EXPECT_EQ(geom::PixelFormat::abgr_8888, buffer.pixel_format()); |
2855 | } |
2856 | |
2857 | -TEST_F(AndroidGraphicBufferBasic, returns_native_buffer_when_asked) |
2858 | +TEST_F(AndroidGraphicBufferBasic, returns_native_buffer_times_two) |
2859 | { |
2860 | using namespace testing; |
2861 | - |
2862 | - mga::Buffer buffer(mock_buffer_handle, extensions); |
2863 | - EXPECT_EQ(mock_buffer_handle, buffer.native_buffer_handle()); |
2864 | + int acquire_fake_fence_fd1 = 948; |
2865 | + int acquire_fake_fence_fd2 = 954; |
2866 | + |
2867 | + EXPECT_CALL(*mock_native_buffer, update_fence(acquire_fake_fence_fd1)) |
2868 | + .Times(1); |
2869 | + EXPECT_CALL(*mock_native_buffer, update_fence(acquire_fake_fence_fd2)) |
2870 | + .Times(1); |
2871 | + |
2872 | + mga::Buffer buffer(mock_native_buffer, extensions); |
2873 | + { |
2874 | + auto native_resource = buffer.native_buffer_handle(); |
2875 | + EXPECT_EQ(mock_native_buffer, native_resource); |
2876 | + native_resource->update_fence(acquire_fake_fence_fd1); |
2877 | + } |
2878 | + { |
2879 | + auto native_resource = buffer.native_buffer_handle(); |
2880 | + EXPECT_EQ(mock_native_buffer, native_resource); |
2881 | + native_resource->update_fence(acquire_fake_fence_fd2); |
2882 | + } |
2883 | } |
2884 | |
2885 | TEST_F(AndroidGraphicBufferBasic, queries_native_window_for_stride) |
2886 | { |
2887 | using namespace testing; |
2888 | |
2889 | - geom::Stride expected_stride{mock_buffer_handle->stride * |
2890 | + geom::Stride expected_stride{anwb->stride * |
2891 | geom::bytes_per_pixel(pf)}; |
2892 | - mga::Buffer buffer(mock_buffer_handle, extensions); |
2893 | + mga::Buffer buffer(mock_native_buffer, extensions); |
2894 | EXPECT_EQ(expected_stride, buffer.stride()); |
2895 | } |
2896 | |
2897 | === modified file 'tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp' |
2898 | --- tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp 2013-08-28 03:41:48 +0000 |
2899 | +++ tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp 2013-10-14 15:38:18 +0000 |
2900 | @@ -17,8 +17,10 @@ |
2901 | */ |
2902 | |
2903 | #include "src/server/graphics/android/buffer.h" |
2904 | +#include "mir/graphics/egl_extensions.h" |
2905 | #include "mir_test_doubles/mock_egl.h" |
2906 | -#include "mir/graphics/egl_extensions.h" |
2907 | +#include "mir_test_doubles/mock_fence.h" |
2908 | +#include "mir_test_doubles/mock_android_native_buffer.h" |
2909 | |
2910 | #include <system/window.h> |
2911 | #include <stdexcept> |
2912 | @@ -36,7 +38,7 @@ |
2913 | { |
2914 | using namespace testing; |
2915 | |
2916 | - stub_buffer = std::make_shared<ANativeWindowBuffer>(); |
2917 | + mock_native_buffer = std::make_shared<mtd::MockAndroidNativeBuffer>(); |
2918 | size = geom::Size{300, 220}; |
2919 | pf = geom::PixelFormat::abgr_8888; |
2920 | extensions = std::make_shared<mg::EGLExtensions>(); |
2921 | @@ -54,7 +56,7 @@ |
2922 | mtd::MockEGL mock_egl; |
2923 | std::shared_ptr<mg::EGLExtensions> extensions; |
2924 | std::shared_ptr<mga::Buffer> buffer; |
2925 | - std::shared_ptr<ANativeWindowBuffer> stub_buffer; |
2926 | + std::shared_ptr<mtd::MockAndroidNativeBuffer> mock_native_buffer; |
2927 | }; |
2928 | |
2929 | TEST_F(AndroidBufferBinding, buffer_queries_for_display) |
2930 | @@ -63,7 +65,7 @@ |
2931 | EXPECT_CALL(mock_egl, eglGetCurrentDisplay()) |
2932 | .Times(Exactly(1)); |
2933 | |
2934 | - mga::Buffer buffer(stub_buffer, extensions); |
2935 | + mga::Buffer buffer(mock_native_buffer, extensions); |
2936 | buffer.bind_to_texture(); |
2937 | } |
2938 | |
2939 | @@ -73,7 +75,7 @@ |
2940 | EXPECT_CALL(mock_egl, eglCreateImageKHR(_,_,_,_,_)) |
2941 | .Times(Exactly(1)); |
2942 | |
2943 | - mga::Buffer buffer(stub_buffer, extensions); |
2944 | + mga::Buffer buffer(mock_native_buffer, extensions); |
2945 | buffer.bind_to_texture(); |
2946 | } |
2947 | |
2948 | @@ -83,9 +85,23 @@ |
2949 | EXPECT_CALL(mock_egl, eglCreateImageKHR(_,_,_,_,_)) |
2950 | .Times(Exactly(1)); |
2951 | |
2952 | - mga::Buffer buffer(stub_buffer, extensions); |
2953 | - buffer.bind_to_texture(); |
2954 | - buffer.bind_to_texture(); |
2955 | + mga::Buffer buffer(mock_native_buffer, extensions); |
2956 | + buffer.bind_to_texture(); |
2957 | + buffer.bind_to_texture(); |
2958 | + buffer.bind_to_texture(); |
2959 | +} |
2960 | + |
2961 | +TEST_F(AndroidBufferBinding, buffer_anwb_is_bound) |
2962 | +{ |
2963 | + using namespace testing; |
2964 | + ANativeWindowBuffer *stub_anwb = reinterpret_cast<ANativeWindowBuffer*>(0xdeed); |
2965 | + EXPECT_CALL(*mock_native_buffer, anwb()) |
2966 | + .Times(1) |
2967 | + .WillOnce(Return(stub_anwb)); |
2968 | + EXPECT_CALL(mock_egl, eglCreateImageKHR(_,_,_,stub_anwb,_)) |
2969 | + .Times(Exactly(1)); |
2970 | + |
2971 | + mga::Buffer buffer(mock_native_buffer, extensions); |
2972 | buffer.bind_to_texture(); |
2973 | } |
2974 | |
2975 | @@ -98,7 +114,7 @@ |
2976 | EXPECT_CALL(mock_egl, eglCreateImageKHR(_,_,_,_,_)) |
2977 | .Times(Exactly(2)); |
2978 | |
2979 | - mga::Buffer buffer(stub_buffer, extensions); |
2980 | + mga::Buffer buffer(mock_native_buffer, extensions); |
2981 | buffer.bind_to_texture(); |
2982 | |
2983 | /* return 2nd fake display */ |
2984 | @@ -117,7 +133,7 @@ |
2985 | EXPECT_CALL(mock_egl, eglDestroyImageKHR(_,_)) |
2986 | .Times(Exactly(2)); |
2987 | |
2988 | - mga::Buffer buffer(stub_buffer, extensions); |
2989 | + mga::Buffer buffer(mock_native_buffer, extensions); |
2990 | buffer.bind_to_texture(); |
2991 | |
2992 | EXPECT_CALL(mock_egl, eglGetCurrentDisplay()) |
2993 | @@ -150,7 +166,7 @@ |
2994 | .Times(Exactly(1)) |
2995 | .WillOnce(Return((first_fake_egl_image))); |
2996 | |
2997 | - mga::Buffer buffer(stub_buffer, extensions); |
2998 | + mga::Buffer buffer(mock_native_buffer, extensions); |
2999 | buffer.bind_to_texture(); |
3000 | |
3001 | /* manipulate mock to return 2nd set */ |
3002 | @@ -175,7 +191,7 @@ |
3003 | |
3004 | EXPECT_CALL(mock_egl, eglCreateImageKHR(fake_display,_,_,_,_)) |
3005 | .Times(Exactly(1)); |
3006 | - mga::Buffer buffer(stub_buffer, extensions); |
3007 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3008 | buffer.bind_to_texture(); |
3009 | } |
3010 | |
3011 | @@ -185,7 +201,7 @@ |
3012 | |
3013 | EXPECT_CALL(mock_egl, eglCreateImageKHR(_, EGL_NO_CONTEXT,_,_,_)) |
3014 | .Times(Exactly(1)); |
3015 | - mga::Buffer buffer(stub_buffer, extensions); |
3016 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3017 | buffer.bind_to_texture(); |
3018 | } |
3019 | |
3020 | @@ -195,17 +211,7 @@ |
3021 | |
3022 | EXPECT_CALL(mock_egl, eglCreateImageKHR(_,_,EGL_NATIVE_BUFFER_ANDROID,_,_)) |
3023 | .Times(Exactly(1)); |
3024 | - mga::Buffer buffer(stub_buffer, extensions); |
3025 | - buffer.bind_to_texture(); |
3026 | -} |
3027 | - |
3028 | -TEST_F(AndroidBufferBinding, buffer_sets_anw_buffer_to_provided_anw) |
3029 | -{ |
3030 | - using namespace testing; |
3031 | - |
3032 | - EXPECT_CALL(mock_egl, eglCreateImageKHR(_,_,_,stub_buffer.get(),_)) |
3033 | - .Times(Exactly(1)); |
3034 | - mga::Buffer buffer(stub_buffer, extensions); |
3035 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3036 | buffer.bind_to_texture(); |
3037 | } |
3038 | |
3039 | @@ -219,7 +225,7 @@ |
3040 | .Times(Exactly(1)) |
3041 | .WillOnce(DoAll(SaveArg<4>(&attrs), |
3042 | Return(mock_egl.fake_egl_image))); |
3043 | - mga::Buffer buffer(stub_buffer, extensions); |
3044 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3045 | buffer.bind_to_texture(); |
3046 | |
3047 | /* note: this should not segfault. if it does, the attributes were set wrong */ |
3048 | @@ -239,7 +245,7 @@ |
3049 | EXPECT_CALL(mock_egl, eglDestroyImageKHR(mock_egl.fake_egl_display, fake_egl_image)) |
3050 | .Times(Exactly(1)); |
3051 | |
3052 | - mga::Buffer buffer(stub_buffer, extensions); |
3053 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3054 | buffer.bind_to_texture(); |
3055 | } |
3056 | |
3057 | @@ -252,7 +258,7 @@ |
3058 | EXPECT_CALL(mock_egl, eglDestroyImageKHR(_,_)) |
3059 | .Times(Exactly(0)); |
3060 | |
3061 | - mga::Buffer buffer(stub_buffer, extensions); |
3062 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3063 | EXPECT_THROW( |
3064 | { |
3065 | buffer.bind_to_texture(); |
3066 | @@ -271,7 +277,7 @@ |
3067 | .Times(Exactly(1)) |
3068 | .WillRepeatedly(Return((EGL_NO_IMAGE_KHR))); |
3069 | |
3070 | - mga::Buffer buffer(stub_buffer, extensions); |
3071 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3072 | EXPECT_THROW( |
3073 | { |
3074 | buffer.bind_to_texture(); |
3075 | @@ -285,7 +291,7 @@ |
3076 | using namespace testing; |
3077 | EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, _)) |
3078 | .Times(Exactly(1)); |
3079 | - mga::Buffer buffer(stub_buffer, extensions); |
3080 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3081 | buffer.bind_to_texture(); |
3082 | } |
3083 | |
3084 | @@ -295,7 +301,7 @@ |
3085 | EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, _)) |
3086 | .Times(Exactly(3)); |
3087 | |
3088 | - mga::Buffer buffer(stub_buffer, extensions); |
3089 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3090 | buffer.bind_to_texture(); |
3091 | buffer.bind_to_texture(); |
3092 | buffer.bind_to_texture(); |
3093 | @@ -306,7 +312,7 @@ |
3094 | using namespace testing; |
3095 | EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, _)) |
3096 | .Times(Exactly(1)); |
3097 | - mga::Buffer buffer(stub_buffer, extensions); |
3098 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3099 | buffer.bind_to_texture(); |
3100 | } |
3101 | |
3102 | @@ -315,7 +321,7 @@ |
3103 | using namespace testing; |
3104 | EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, mock_egl.fake_egl_image)) |
3105 | .Times(Exactly(1)); |
3106 | - mga::Buffer buffer(stub_buffer, extensions); |
3107 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3108 | buffer.bind_to_texture(); |
3109 | } |
3110 | |
3111 | @@ -327,7 +333,7 @@ |
3112 | |
3113 | EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, _)) |
3114 | .Times(Exactly(1)); |
3115 | - mga::Buffer buffer(stub_buffer, extensions); |
3116 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3117 | buffer.bind_to_texture(); |
3118 | |
3119 | EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, second_fake_egl_image)) |
3120 | @@ -340,3 +346,13 @@ |
3121 | .WillOnce(Return((second_fake_egl_image))); |
3122 | buffer.bind_to_texture(); |
3123 | } |
3124 | + |
3125 | +TEST_F(AndroidBufferBinding, bind_to_texture_waits_on_fence) |
3126 | +{ |
3127 | + using namespace testing; |
3128 | + EXPECT_CALL(*mock_native_buffer, wait_for_content()) |
3129 | + .Times(1); |
3130 | + |
3131 | + mga::Buffer buffer(mock_native_buffer, extensions); |
3132 | + buffer.bind_to_texture(); |
3133 | +} |
3134 | |
3135 | === modified file 'tests/unit-tests/graphics/android/test_external_refcount.cpp' |
3136 | --- tests/unit-tests/graphics/android/test_external_refcount.cpp 2013-07-01 18:27:23 +0000 |
3137 | +++ tests/unit-tests/graphics/android/test_external_refcount.cpp 2013-10-14 15:38:18 +0000 |
3138 | @@ -16,25 +16,27 @@ |
3139 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
3140 | */ |
3141 | |
3142 | -#include "mir/graphics/android/mir_native_buffer.h" |
3143 | +#include "mir/graphics/android/android_native_buffer.h" |
3144 | +#include "mir_test_doubles/mock_fence.h" |
3145 | #include <memory> |
3146 | #include <gtest/gtest.h> |
3147 | |
3148 | +namespace mtd=mir::test::doubles; |
3149 | namespace mga=mir::graphics::android; |
3150 | |
3151 | TEST(AndroidRefcount, driver_hooks) |
3152 | { |
3153 | auto native_handle_resource = std::make_shared<native_handle_t>(); |
3154 | auto use_count_before = native_handle_resource.use_count(); |
3155 | - mga::MirNativeBuffer* driver_reference = nullptr; |
3156 | + ANativeWindowBuffer* driver_reference = nullptr; |
3157 | { |
3158 | - auto tmp = new mga::MirNativeBuffer(native_handle_resource); |
3159 | - std::shared_ptr<mga::MirNativeBuffer> buffer(tmp, [](mga::MirNativeBuffer* buffer) |
3160 | + auto tmp = new mga::RefCountedNativeBuffer(native_handle_resource); |
3161 | + std::shared_ptr<mga::RefCountedNativeBuffer> buffer(tmp, [](mga::RefCountedNativeBuffer* buffer) |
3162 | { |
3163 | buffer->mir_dereference(); |
3164 | }); |
3165 | |
3166 | - driver_reference = buffer.get(); |
3167 | + driver_reference = buffer.get(); |
3168 | driver_reference->common.incRef(&driver_reference->common); |
3169 | //Mir loses its reference, driver still has a ref |
3170 | } |
3171 | @@ -49,15 +51,15 @@ |
3172 | auto native_handle_resource = std::make_shared<native_handle_t>(); |
3173 | auto use_count_before = native_handle_resource.use_count(); |
3174 | { |
3175 | - std::shared_ptr<mga::MirNativeBuffer> mir_reference; |
3176 | - mga::MirNativeBuffer* driver_reference = nullptr; |
3177 | + std::shared_ptr<mga::RefCountedNativeBuffer> mir_reference; |
3178 | + ANativeWindowBuffer* driver_reference = nullptr; |
3179 | { |
3180 | - auto tmp = new mga::MirNativeBuffer(native_handle_resource); |
3181 | - mir_reference = std::shared_ptr<mga::MirNativeBuffer>(tmp, [](mga::MirNativeBuffer* buffer) |
3182 | + auto tmp = new mga::RefCountedNativeBuffer(native_handle_resource); |
3183 | + mir_reference = std::shared_ptr<mga::RefCountedNativeBuffer>(tmp, [](mga::RefCountedNativeBuffer* buffer) |
3184 | { |
3185 | buffer->mir_dereference(); |
3186 | }); |
3187 | - driver_reference = mir_reference.get(); |
3188 | + driver_reference = tmp; |
3189 | driver_reference->common.incRef(&driver_reference->common); |
3190 | } |
3191 | |
3192 | @@ -67,3 +69,26 @@ |
3193 | } |
3194 | EXPECT_EQ(use_count_before, native_handle_resource.use_count()); |
3195 | } |
3196 | + |
3197 | +TEST(AndroidAndroidNativeBuffer, wait_for_fence) |
3198 | +{ |
3199 | + auto fence = std::make_shared<mtd::MockFence>(); |
3200 | + EXPECT_CALL(*fence, wait()) |
3201 | + .Times(1); |
3202 | + |
3203 | + auto native_handle_resource = std::make_shared<ANativeWindowBuffer>(); |
3204 | + mga::AndroidNativeBuffer buffer(native_handle_resource, fence); |
3205 | + buffer.wait_for_content(); |
3206 | +} |
3207 | + |
3208 | +TEST(AndroidAndroidNativeBuffer, update_fence) |
3209 | +{ |
3210 | + int fake_fd = 48484; |
3211 | + auto fence = std::make_shared<mtd::MockFence>(); |
3212 | + EXPECT_CALL(*fence, merge_with(fake_fd)) |
3213 | + .Times(1); |
3214 | + |
3215 | + auto native_handle_resource = std::make_shared<ANativeWindowBuffer>(); |
3216 | + mga::AndroidNativeBuffer buffer(native_handle_resource, fence); |
3217 | + buffer.update_fence(fake_fd); |
3218 | +} |
3219 | |
3220 | === modified file 'tests/unit-tests/graphics/android/test_fb_device.cpp' |
3221 | --- tests/unit-tests/graphics/android/test_fb_device.cpp 2013-08-28 03:41:48 +0000 |
3222 | +++ tests/unit-tests/graphics/android/test_fb_device.cpp 2013-10-14 15:38:18 +0000 |
3223 | @@ -20,6 +20,7 @@ |
3224 | #include "mir_test_doubles/mock_buffer.h" |
3225 | #include "src/server/graphics/android/fb_device.h" |
3226 | #include "mir_test_doubles/mock_android_hw.h" |
3227 | +#include "mir_test_doubles/mock_android_native_buffer.h" |
3228 | |
3229 | #include <gtest/gtest.h> |
3230 | #include <stdexcept> |
3231 | @@ -43,16 +44,15 @@ |
3232 | fb_hal_mock = std::make_shared<mtd::MockFBHalDevice>(width, height, format, fbnum); |
3233 | mock_buffer = std::make_shared<NiceMock<mtd::MockBuffer>>(); |
3234 | |
3235 | - dummy_buffer = std::make_shared<ANativeWindowBuffer>(); |
3236 | - dummy_buffer->handle = (buffer_handle_t) 0x4893; |
3237 | + native_buffer = std::make_shared<mtd::StubAndroidNativeBuffer>(); |
3238 | ON_CALL(*mock_buffer, native_buffer_handle()) |
3239 | - .WillByDefault(Return(dummy_buffer)); |
3240 | + .WillByDefault(Return(native_buffer)); |
3241 | } |
3242 | |
3243 | unsigned int width, height, format, fbnum; |
3244 | std::shared_ptr<mtd::MockFBHalDevice> fb_hal_mock; |
3245 | std::shared_ptr<mtd::MockBuffer> mock_buffer; |
3246 | - std::shared_ptr<ANativeWindowBuffer> dummy_buffer; |
3247 | + std::shared_ptr<mir::graphics::NativeBuffer> native_buffer; |
3248 | mtd::HardwareAccessMock hw_access_mock; |
3249 | }; |
3250 | |
3251 | @@ -61,7 +61,7 @@ |
3252 | using namespace testing; |
3253 | mga::FBDevice fbdev(fb_hal_mock); |
3254 | |
3255 | - EXPECT_CALL(*fb_hal_mock, post_interface(fb_hal_mock.get(),dummy_buffer->handle)) |
3256 | + EXPECT_CALL(*fb_hal_mock, post_interface(fb_hal_mock.get(), native_buffer->handle())) |
3257 | .Times(1); |
3258 | |
3259 | fbdev.set_next_frontbuffer(mock_buffer); |
3260 | @@ -72,7 +72,7 @@ |
3261 | using namespace testing; |
3262 | mga::FBDevice fbdev(fb_hal_mock); |
3263 | |
3264 | - EXPECT_CALL(*fb_hal_mock, post_interface(fb_hal_mock.get(),dummy_buffer->handle)) |
3265 | + EXPECT_CALL(*fb_hal_mock, post_interface(fb_hal_mock.get(),native_buffer->handle())) |
3266 | .Times(1) |
3267 | .WillOnce(Return(-1)); |
3268 | |
3269 | |
3270 | === modified file 'tests/unit-tests/graphics/android/test_hwc_layerlist.cpp' |
3271 | --- tests/unit-tests/graphics/android/test_hwc_layerlist.cpp 2013-09-24 19:03:27 +0000 |
3272 | +++ tests/unit-tests/graphics/android/test_hwc_layerlist.cpp 2013-10-14 15:38:18 +0000 |
3273 | @@ -19,8 +19,10 @@ |
3274 | #include "src/server/graphics/android/hwc_layerlist.h" |
3275 | #include "mir_test_doubles/mock_buffer.h" |
3276 | #include "hwc_struct_helper-inl.h" |
3277 | +#include "mir_test_doubles/mock_android_native_buffer.h" |
3278 | #include <gtest/gtest.h> |
3279 | |
3280 | +namespace mg=mir::graphics; |
3281 | namespace mga=mir::graphics::android; |
3282 | namespace mtd=mir::test::doubles; |
3283 | namespace geom=mir::geometry; |
3284 | @@ -36,23 +38,22 @@ |
3285 | height = 876; |
3286 | default_size = geom::Size{width, height}; |
3287 | |
3288 | - stub_handle_1 = std::make_shared<ANativeWindowBuffer>(); |
3289 | - stub_handle_2 = std::make_shared<ANativeWindowBuffer>(); |
3290 | + native_handle_1 = std::make_shared<mtd::StubAndroidNativeBuffer>(); |
3291 | + native_handle_2 = std::make_shared<mtd::StubAndroidNativeBuffer>(); |
3292 | |
3293 | mock_buffer = std::make_shared<NiceMock<mtd::MockBuffer>>(); |
3294 | ON_CALL(*mock_buffer, native_buffer_handle()) |
3295 | - .WillByDefault(Return(stub_handle_1)); |
3296 | + .WillByDefault(Return(native_handle_1)); |
3297 | ON_CALL(*mock_buffer, size()) |
3298 | .WillByDefault(Return(default_size)); |
3299 | - |
3300 | } |
3301 | |
3302 | int width; |
3303 | int height; |
3304 | geom::Size default_size; |
3305 | |
3306 | - std::shared_ptr<ANativeWindowBuffer> stub_handle_1; |
3307 | - std::shared_ptr<ANativeWindowBuffer> stub_handle_2; |
3308 | + std::shared_ptr<mg::NativeBuffer> native_handle_1; |
3309 | + std::shared_ptr<mg::NativeBuffer> native_handle_2; |
3310 | std::shared_ptr<mtd::MockBuffer> mock_buffer; |
3311 | }; |
3312 | |
3313 | @@ -80,7 +81,7 @@ |
3314 | EXPECT_THAT(c, HWCRectMatchesRect(layer.visibleRegionScreen.rects[2],"")); |
3315 | } |
3316 | |
3317 | -TEST_F(HWCLayerListTest, set_fb_target_figures_out_buffer_size) |
3318 | +TEST_F(HWCLayerListTest, hwc_list_creation_loads_latest_fb_target) |
3319 | { |
3320 | using namespace testing; |
3321 | |
3322 | @@ -125,13 +126,13 @@ |
3323 | |
3324 | EXPECT_CALL(*mock_buffer, native_buffer_handle()) |
3325 | .Times(1) |
3326 | - .WillOnce(Return(stub_handle_1)); |
3327 | + .WillOnce(Return(native_handle_1)); |
3328 | |
3329 | layerlist.set_fb_target(mock_buffer); |
3330 | auto list = layerlist.native_list(); |
3331 | ASSERT_EQ(1u, list->numHwLayers); |
3332 | hwc_layer_1 target_layer = list->hwLayers[0]; |
3333 | - EXPECT_EQ(stub_handle_1->handle, target_layer.handle); |
3334 | + EXPECT_EQ(native_handle_1->handle(), target_layer.handle); |
3335 | } |
3336 | |
3337 | TEST_F(HWCLayerListTest, set_fb_target_2x) |
3338 | @@ -142,20 +143,20 @@ |
3339 | |
3340 | EXPECT_CALL(*mock_buffer, native_buffer_handle()) |
3341 | .Times(2) |
3342 | - .WillOnce(Return(stub_handle_1)) |
3343 | - .WillOnce(Return(stub_handle_2)); |
3344 | + .WillOnce(Return(native_handle_1)) |
3345 | + .WillOnce(Return(native_handle_2)); |
3346 | |
3347 | layerlist.set_fb_target(mock_buffer); |
3348 | auto list = layerlist.native_list(); |
3349 | ASSERT_EQ(1u, list->numHwLayers); |
3350 | hwc_layer_1 target_layer = list->hwLayers[0]; |
3351 | - EXPECT_EQ(stub_handle_1->handle, target_layer.handle); |
3352 | + EXPECT_EQ(native_handle_1->handle(), target_layer.handle); |
3353 | |
3354 | layerlist.set_fb_target(mock_buffer); |
3355 | auto list_second = layerlist.native_list(); |
3356 | ASSERT_EQ(1u, list_second->numHwLayers); |
3357 | target_layer = list_second->hwLayers[0]; |
3358 | - EXPECT_EQ(stub_handle_2->handle, target_layer.handle); |
3359 | + EXPECT_EQ(native_handle_2->handle(), target_layer.handle); |
3360 | } |
3361 | |
3362 | TEST_F(HWCLayerListTest, set_fb_target_programs_other_struct_members_correctly) |
3363 | @@ -173,7 +174,7 @@ |
3364 | expected_layer.compositionType = HWC_FRAMEBUFFER_TARGET; |
3365 | expected_layer.hints = 0; |
3366 | expected_layer.flags = 0; |
3367 | - expected_layer.handle = stub_handle_1->handle; |
3368 | + expected_layer.handle = native_handle_1->handle(); |
3369 | expected_layer.transform = 0; |
3370 | expected_layer.blending = HWC_BLENDING_NONE; |
3371 | expected_layer.sourceCrop = source_region; |
3372 | |
3373 | === modified file 'tests/unit-tests/graphics/android/test_internal_client_interpreter.cpp' |
3374 | --- tests/unit-tests/graphics/android/test_internal_client_interpreter.cpp 2013-09-24 19:03:27 +0000 |
3375 | +++ tests/unit-tests/graphics/android/test_internal_client_interpreter.cpp 2013-10-14 15:38:18 +0000 |
3376 | @@ -19,7 +19,9 @@ |
3377 | #include "src/server/graphics/android/internal_client_window.h" |
3378 | #include "mir_test_doubles/mock_buffer.h" |
3379 | #include "mir_test_doubles/mock_interpreter_resource_cache.h" |
3380 | +#include "mir_test_doubles/mock_fence.h" |
3381 | #include "mir/graphics/internal_surface.h" |
3382 | +#include "mir_test_doubles/mock_android_native_buffer.h" |
3383 | |
3384 | #include <gtest/gtest.h> |
3385 | #include <stdexcept> |
3386 | @@ -48,28 +50,23 @@ |
3387 | mock_cache = std::make_shared<mtd::MockInterpreterResourceCache>(); |
3388 | mock_surface = std::make_shared<MockInternalSurface>(); |
3389 | mock_buffer = std::make_shared<mtd::MockBuffer>(); |
3390 | - stub_anw = std::make_shared<ANativeWindowBuffer>(); |
3391 | + stub_native_buffer = std::make_shared<mtd::StubAndroidNativeBuffer>(); |
3392 | |
3393 | ON_CALL(*mock_surface, advance_client_buffer()) |
3394 | .WillByDefault(Return(mock_buffer)); |
3395 | ON_CALL(*mock_surface, pixel_format()) |
3396 | .WillByDefault(Return(mir_pixel_format_abgr_8888)); |
3397 | ON_CALL(*mock_buffer, native_buffer_handle()) |
3398 | - .WillByDefault(Return(stub_anw)); |
3399 | + .WillByDefault(Return(stub_native_buffer)); |
3400 | } |
3401 | |
3402 | - std::shared_ptr<ANativeWindowBuffer> stub_anw; |
3403 | + std::shared_ptr<mg::NativeBuffer> stub_native_buffer; |
3404 | std::shared_ptr<mtd::MockInterpreterResourceCache> mock_cache; |
3405 | std::shared_ptr<MockInternalSurface> mock_surface; |
3406 | std::shared_ptr<mtd::MockBuffer> mock_buffer; |
3407 | geom::Size sz; |
3408 | }; |
3409 | |
3410 | -struct MockSyncFence : public mga::SyncObject |
3411 | -{ |
3412 | - ~MockSyncFence() noexcept {} |
3413 | - MOCK_METHOD0(wait, void()); |
3414 | -}; |
3415 | } |
3416 | |
3417 | TEST_F(InternalClientWindow, driver_requests_buffer) |
3418 | @@ -80,29 +77,30 @@ |
3419 | EXPECT_CALL(*mock_buffer, native_buffer_handle()) |
3420 | .Times(1); |
3421 | std::shared_ptr<mg::Buffer> tmp = mock_buffer; |
3422 | - EXPECT_CALL(*mock_cache, store_buffer(tmp, stub_anw.get())) |
3423 | + EXPECT_CALL(*mock_cache, store_buffer(tmp, stub_native_buffer)) |
3424 | .Times(1); |
3425 | |
3426 | mga::InternalClientWindow interpreter(mock_surface, mock_cache); |
3427 | auto test_buffer = interpreter.driver_requests_buffer(); |
3428 | - EXPECT_EQ(stub_anw.get(), test_buffer); |
3429 | + ASSERT_NE(nullptr, test_buffer); |
3430 | + EXPECT_EQ(stub_native_buffer.get(), test_buffer); |
3431 | } |
3432 | |
3433 | TEST_F(InternalClientWindow, driver_returns_buffer) |
3434 | { |
3435 | using namespace testing; |
3436 | - auto mock_sync = std::make_shared<MockSyncFence>(); |
3437 | + int fake_fence = 4848; |
3438 | |
3439 | Sequence seq; |
3440 | - EXPECT_CALL(*mock_sync, wait()) |
3441 | - .InSequence(seq); |
3442 | - EXPECT_CALL(*mock_cache, retrieve_buffer(stub_anw.get())) |
3443 | + EXPECT_CALL(*mock_cache, update_native_fence(stub_native_buffer->anwb(), fake_fence)) |
3444 | + .Times(1); |
3445 | + EXPECT_CALL(*mock_cache, retrieve_buffer(stub_native_buffer->anwb())) |
3446 | .InSequence(seq) |
3447 | .WillOnce(Return(mock_buffer)); |
3448 | |
3449 | mga::InternalClientWindow interpreter(mock_surface, mock_cache); |
3450 | auto test_bufferptr = interpreter.driver_requests_buffer(); |
3451 | - interpreter.driver_returns_buffer(test_bufferptr, mock_sync); |
3452 | + interpreter.driver_returns_buffer(test_bufferptr->anwb(), fake_fence); |
3453 | } |
3454 | |
3455 | TEST_F(InternalClientWindow, size_test) |
3456 | @@ -145,9 +143,3 @@ |
3457 | auto rc_format = interpreter.driver_requests_info(NATIVE_WINDOW_FORMAT); |
3458 | EXPECT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, rc_format); |
3459 | } |
3460 | - |
3461 | -TEST_F(InternalClientWindow, window_holds_buffer_resource_for_driver) |
3462 | -{ |
3463 | - mga::InternalClientWindow interpreter(mock_surface, mock_cache); |
3464 | - |
3465 | -} |
3466 | |
3467 | === modified file 'tests/unit-tests/graphics/android/test_interpreter_buffer_cache.cpp' |
3468 | --- tests/unit-tests/graphics/android/test_interpreter_buffer_cache.cpp 2013-05-06 22:24:13 +0000 |
3469 | +++ tests/unit-tests/graphics/android/test_interpreter_buffer_cache.cpp 2013-10-14 15:38:18 +0000 |
3470 | @@ -18,10 +18,12 @@ |
3471 | |
3472 | #include "src/server/graphics/android/interpreter_cache.h" |
3473 | #include "mir_test_doubles/stub_buffer.h" |
3474 | +#include "mir_test_doubles/mock_android_native_buffer.h" |
3475 | |
3476 | #include <gtest/gtest.h> |
3477 | #include <stdexcept> |
3478 | |
3479 | +namespace mg=mir::graphics; |
3480 | namespace mga=mir::graphics::android; |
3481 | namespace mtd=mir::test::doubles; |
3482 | |
3483 | @@ -32,55 +34,76 @@ |
3484 | stub_buffer1 = std::make_shared<mtd::StubBuffer>(); |
3485 | stub_buffer2 = std::make_shared<mtd::StubBuffer>(); |
3486 | stub_buffer3 = std::make_shared<mtd::StubBuffer>(); |
3487 | - key1 = (ANativeWindowBuffer*)0x1; |
3488 | - key2 = (ANativeWindowBuffer*)0x2; |
3489 | - key3 = (ANativeWindowBuffer*)0x3; |
3490 | + native_buffer1 = std::make_shared<mtd::MockAndroidNativeBuffer>(); |
3491 | + native_buffer2 = std::make_shared<mtd::StubAndroidNativeBuffer>(); |
3492 | + native_buffer3 = std::make_shared<mtd::StubAndroidNativeBuffer>(); |
3493 | } |
3494 | |
3495 | std::shared_ptr<mtd::StubBuffer> stub_buffer1; |
3496 | std::shared_ptr<mtd::StubBuffer> stub_buffer2; |
3497 | std::shared_ptr<mtd::StubBuffer> stub_buffer3; |
3498 | - ANativeWindowBuffer *key1; |
3499 | - ANativeWindowBuffer *key2; |
3500 | - ANativeWindowBuffer *key3; |
3501 | + std::shared_ptr<mtd::MockAndroidNativeBuffer> native_buffer1; |
3502 | + std::shared_ptr<mg::NativeBuffer> native_buffer2; |
3503 | + std::shared_ptr<mg::NativeBuffer> native_buffer3; |
3504 | }; |
3505 | |
3506 | TEST_F(InterpreterResourceTest, deposit_buffer) |
3507 | { |
3508 | mga::InterpreterCache cache; |
3509 | - cache.store_buffer(stub_buffer1, key1); |
3510 | + cache.store_buffer(stub_buffer1, native_buffer1); |
3511 | |
3512 | - auto test_buffer = cache.retrieve_buffer(key1); |
3513 | + auto test_buffer = cache.retrieve_buffer(native_buffer1->anwb()); |
3514 | EXPECT_EQ(stub_buffer1, test_buffer); |
3515 | } |
3516 | |
3517 | TEST_F(InterpreterResourceTest, deposit_many_buffers) |
3518 | { |
3519 | mga::InterpreterCache cache; |
3520 | - cache.store_buffer(stub_buffer1, key1); |
3521 | - cache.store_buffer(stub_buffer2, key2); |
3522 | - cache.store_buffer(stub_buffer3, key3); |
3523 | + cache.store_buffer(stub_buffer1, native_buffer1); |
3524 | + cache.store_buffer(stub_buffer2, native_buffer2); |
3525 | + cache.store_buffer(stub_buffer3, native_buffer3); |
3526 | |
3527 | - EXPECT_EQ(stub_buffer3, cache.retrieve_buffer(key3)); |
3528 | - EXPECT_EQ(stub_buffer1, cache.retrieve_buffer(key1)); |
3529 | - EXPECT_EQ(stub_buffer2, cache.retrieve_buffer(key2)); |
3530 | + EXPECT_EQ(stub_buffer3, cache.retrieve_buffer(native_buffer3->anwb())); |
3531 | + EXPECT_EQ(stub_buffer1, cache.retrieve_buffer(native_buffer1->anwb())); |
3532 | + EXPECT_EQ(stub_buffer2, cache.retrieve_buffer(native_buffer2->anwb())); |
3533 | } |
3534 | |
3535 | TEST_F(InterpreterResourceTest, deposit_buffer_has_ownership) |
3536 | { |
3537 | mga::InterpreterCache cache; |
3538 | |
3539 | + auto native_use_count_before = native_buffer1.use_count(); |
3540 | auto use_count_before = stub_buffer1.use_count(); |
3541 | - cache.store_buffer(stub_buffer1, key1); |
3542 | + |
3543 | + cache.store_buffer(stub_buffer1, native_buffer1); |
3544 | + EXPECT_EQ(native_use_count_before+1, native_buffer1.use_count()); |
3545 | EXPECT_EQ(use_count_before+1, stub_buffer1.use_count()); |
3546 | - cache.retrieve_buffer(key1); |
3547 | + |
3548 | + cache.retrieve_buffer(native_buffer1->anwb()); |
3549 | + EXPECT_EQ(native_use_count_before, native_buffer1.use_count()); |
3550 | EXPECT_EQ(use_count_before, stub_buffer1.use_count()); |
3551 | } |
3552 | |
3553 | +TEST_F(InterpreterResourceTest, update_fence_for) |
3554 | +{ |
3555 | + int fence_fd = 44; |
3556 | + mga::InterpreterCache cache; |
3557 | + |
3558 | + EXPECT_CALL(*native_buffer1, update_fence(fence_fd)) |
3559 | + .Times(1); |
3560 | + |
3561 | + cache.store_buffer(stub_buffer1, native_buffer1); |
3562 | + cache.update_native_fence(native_buffer1->anwb(), fence_fd); |
3563 | + |
3564 | + EXPECT_THROW({ |
3565 | + cache.update_native_fence(nullptr, fence_fd); |
3566 | + }, std::runtime_error); |
3567 | +} |
3568 | + |
3569 | TEST_F(InterpreterResourceTest, retreive_buffer_with_bad_key_throws) |
3570 | { |
3571 | mga::InterpreterCache cache; |
3572 | EXPECT_THROW({ |
3573 | - cache.retrieve_buffer(key1); |
3574 | + cache.retrieve_buffer(native_buffer1->anwb()); |
3575 | }, std::runtime_error); |
3576 | } |
3577 | |
3578 | === modified file 'tests/unit-tests/graphics/android/test_server_interpreter.cpp' |
3579 | --- tests/unit-tests/graphics/android/test_server_interpreter.cpp 2013-09-24 19:03:27 +0000 |
3580 | +++ tests/unit-tests/graphics/android/test_server_interpreter.cpp 2013-10-14 15:38:18 +0000 |
3581 | @@ -21,27 +21,25 @@ |
3582 | |
3583 | #include "mir_test_doubles/mock_display_support_provider.h" |
3584 | #include "mir_test_doubles/mock_buffer.h" |
3585 | +#include "mir_test_doubles/mock_fence.h" |
3586 | #include "mir_test_doubles/mock_interpreter_resource_cache.h" |
3587 | +#include "mir_test/fake_shared.h" |
3588 | +#include "mir_test_doubles/mock_android_native_buffer.h" |
3589 | |
3590 | #include <gtest/gtest.h> |
3591 | #include <gmock/gmock.h> |
3592 | #include <stdexcept> |
3593 | |
3594 | + |
3595 | +namespace mt=mir::test; |
3596 | namespace mtd=mir::test::doubles; |
3597 | namespace geom=mir::geometry; |
3598 | namespace mg=mir::graphics; |
3599 | namespace mga=mir::graphics::android; |
3600 | -namespace mc=mir::compositor; |
3601 | |
3602 | namespace |
3603 | { |
3604 | |
3605 | -struct StubFence : public mga::SyncObject |
3606 | -{ |
3607 | - virtual ~StubFence() noexcept {} |
3608 | - MOCK_METHOD0(wait, void()); |
3609 | -}; |
3610 | - |
3611 | struct MockFBSwapper : public mga::FBSwapper |
3612 | { |
3613 | ~MockFBSwapper() noexcept {} |
3614 | @@ -62,7 +60,6 @@ |
3615 | mock_cache = std::make_shared<mtd::MockInterpreterResourceCache>(); |
3616 | ON_CALL(*mock_display_poster, display_format()) |
3617 | .WillByDefault(Return(geom::PixelFormat::abgr_8888)); |
3618 | - stub_sync = std::make_shared<StubFence>(); |
3619 | } |
3620 | |
3621 | std::shared_ptr<mtd::MockBuffer> mock_buffer1; |
3622 | @@ -71,39 +68,39 @@ |
3623 | std::shared_ptr<mtd::MockInterpreterResourceCache> mock_cache; |
3624 | std::shared_ptr<MockFBSwapper> mock_swapper; |
3625 | std::shared_ptr<mtd::MockDisplaySupportProvider> mock_display_poster; |
3626 | - std::shared_ptr<StubFence> stub_sync; |
3627 | }; |
3628 | } |
3629 | |
3630 | TEST_F(ServerRenderWindowTest, driver_wants_a_buffer) |
3631 | { |
3632 | using namespace testing; |
3633 | + |
3634 | mga::ServerRenderWindow render_window(mock_swapper, mock_display_poster, mock_cache); |
3635 | |
3636 | - auto stub_anw = std::make_shared<ANativeWindowBuffer>(); |
3637 | + auto stub_buffer = std::make_shared<mtd::StubAndroidNativeBuffer>(); |
3638 | |
3639 | EXPECT_CALL(*mock_swapper, compositor_acquire()) |
3640 | .Times(1) |
3641 | .WillOnce(Return(mock_buffer1)); |
3642 | EXPECT_CALL(*mock_buffer1, native_buffer_handle()) |
3643 | .Times(1) |
3644 | - .WillOnce(Return(stub_anw)); |
3645 | + .WillOnce(Return(stub_buffer)); |
3646 | |
3647 | std::shared_ptr<mg::Buffer> tmp = mock_buffer1; |
3648 | - EXPECT_CALL(*mock_cache, store_buffer(tmp, stub_anw.get())) |
3649 | + std::shared_ptr<mg::NativeBuffer> tmp2 = stub_buffer; |
3650 | + EXPECT_CALL(*mock_cache, store_buffer(tmp, tmp2)) |
3651 | .Times(1); |
3652 | |
3653 | auto rc_buffer = render_window.driver_requests_buffer(); |
3654 | - EXPECT_EQ(stub_anw.get(), rc_buffer); |
3655 | + EXPECT_EQ(stub_buffer.get(), rc_buffer); |
3656 | } |
3657 | |
3658 | TEST_F(ServerRenderWindowTest, driver_is_done_with_a_buffer_properly) |
3659 | { |
3660 | using namespace testing; |
3661 | - auto stub_anw = std::make_shared<ANativeWindowBuffer>(); |
3662 | - EXPECT_CALL(*mock_cache, retrieve_buffer(stub_anw.get())) |
3663 | - .Times(1) |
3664 | - .WillOnce(Return(mock_buffer1)); |
3665 | + int fake_fence = 488; |
3666 | + auto stub_buffer = std::make_shared<mtd::StubAndroidNativeBuffer>(); |
3667 | + |
3668 | mga::ServerRenderWindow render_window(mock_swapper, mock_display_poster, mock_cache); |
3669 | |
3670 | EXPECT_CALL(*mock_swapper, compositor_acquire()) |
3671 | @@ -111,45 +108,24 @@ |
3672 | .WillOnce(Return(mock_buffer1)); |
3673 | EXPECT_CALL(*mock_buffer1, native_buffer_handle()) |
3674 | .Times(1) |
3675 | - .WillOnce(Return(stub_anw)); |
3676 | + .WillOnce(Return(stub_buffer)); |
3677 | |
3678 | render_window.driver_requests_buffer(); |
3679 | testing::Mock::VerifyAndClearExpectations(mock_swapper.get()); |
3680 | |
3681 | std::shared_ptr<mg::Buffer> buf1 = mock_buffer1; |
3682 | + EXPECT_CALL(*mock_cache, update_native_fence(stub_buffer->anwb(), fake_fence)) |
3683 | + .Times(1); |
3684 | + EXPECT_CALL(*mock_cache, retrieve_buffer(stub_buffer->anwb())) |
3685 | + .Times(1) |
3686 | + .WillOnce(Return(mock_buffer1)); |
3687 | EXPECT_CALL(*mock_swapper, compositor_release(buf1)) |
3688 | - .Times(1); |
3689 | - EXPECT_CALL(*stub_sync, wait()) |
3690 | - .Times(1); |
3691 | - |
3692 | - render_window.driver_returns_buffer(stub_anw.get(), stub_sync); |
3693 | - testing::Mock::VerifyAndClearExpectations(mock_swapper.get()); |
3694 | -} |
3695 | - |
3696 | -TEST_F(ServerRenderWindowTest, driver_returns_buffer_posts_to_fb) |
3697 | -{ |
3698 | - using namespace testing; |
3699 | - auto stub_anw = std::make_shared<ANativeWindowBuffer>(); |
3700 | - EXPECT_CALL(*mock_cache, retrieve_buffer(_)) |
3701 | - .Times(1) |
3702 | - .WillOnce(Return(mock_buffer1)); |
3703 | - mga::ServerRenderWindow render_window(mock_swapper, mock_display_poster, mock_cache); |
3704 | - |
3705 | - mg::BufferID id{442}, returned_id; |
3706 | - EXPECT_CALL(*mock_swapper, compositor_acquire()) |
3707 | - .Times(1) |
3708 | - .WillOnce(Return(mock_buffer1)); |
3709 | - EXPECT_CALL(*mock_swapper, compositor_release(_)) |
3710 | - .Times(1); |
3711 | - std::shared_ptr<mg::Buffer> buf1 = mock_buffer1; |
3712 | - EXPECT_CALL(*mock_buffer1, native_buffer_handle()) |
3713 | - .Times(1) |
3714 | - .WillOnce(Return(stub_anw)); |
3715 | + .Times(1); |
3716 | EXPECT_CALL(*mock_display_poster, set_next_frontbuffer(buf1)) |
3717 | .Times(1); |
3718 | |
3719 | - auto handle1 = render_window.driver_requests_buffer(); |
3720 | - render_window.driver_returns_buffer(handle1, stub_sync); |
3721 | + render_window.driver_returns_buffer(stub_buffer->anwb(), fake_fence); |
3722 | + testing::Mock::VerifyAndClearExpectations(mock_swapper.get()); |
3723 | } |
3724 | |
3725 | TEST_F(ServerRenderWindowTest, driver_inquires_about_format) |
3726 | |
3727 | === added file 'tests/unit-tests/graphics/android/test_sync_fence.cpp' |
3728 | --- tests/unit-tests/graphics/android/test_sync_fence.cpp 1970-01-01 00:00:00 +0000 |
3729 | +++ tests/unit-tests/graphics/android/test_sync_fence.cpp 2013-10-14 15:38:18 +0000 |
3730 | @@ -0,0 +1,141 @@ |
3731 | +/* |
3732 | + * Copyright © 2013 Canonical Ltd. |
3733 | + * |
3734 | + * This program is free software: you can redistribute it and/or modify |
3735 | + * it under the terms of the GNU General Public License version 3 as |
3736 | + * published by the Free Software Foundation. |
3737 | + * |
3738 | + * This program is distributed in the hope that it will be useful, |
3739 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3740 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3741 | + * GNU General Public License for more details. |
3742 | + * |
3743 | + * You should have received a copy of the GNU General Public License |
3744 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3745 | + * |
3746 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
3747 | + */ |
3748 | + |
3749 | +#include "mir/graphics/android/sync_fence.h" |
3750 | +#include "mir_test_doubles/mock_fence.h" |
3751 | + |
3752 | +#include <android/linux/sync.h> |
3753 | +#include <sys/ioctl.h> |
3754 | +#include <gtest/gtest.h> |
3755 | +#include <gmock/gmock.h> |
3756 | +#include <memory> |
3757 | + |
3758 | +namespace mga = mir::graphics::android; |
3759 | +namespace mtd = mir::test::doubles; |
3760 | + |
3761 | +namespace |
3762 | +{ |
3763 | +struct MockFileOps : public mga::SyncFileOps |
3764 | +{ |
3765 | + MOCK_METHOD3(ioctl, int(int,int,void*)); |
3766 | + MOCK_METHOD1(dup, int(int)); |
3767 | + MOCK_METHOD1(close, int(int)); |
3768 | +}; |
3769 | +} |
3770 | + |
3771 | +class SyncSwTest : public ::testing::Test |
3772 | +{ |
3773 | +protected: |
3774 | + virtual void SetUp() |
3775 | + { |
3776 | + mock_fops = std::make_shared<MockFileOps>(); |
3777 | + } |
3778 | + |
3779 | + int dummy_fd = 3; |
3780 | + int invalid_fd = -1; |
3781 | + std::shared_ptr<MockFileOps> mock_fops; |
3782 | +}; |
3783 | + |
3784 | + |
3785 | +MATCHER_P(TimeoutMatches, value, |
3786 | + std::string("timeout should be: " + testing::PrintToString(value))) |
3787 | +{ |
3788 | + int* timeout = static_cast<int*>(arg); |
3789 | + if (!timeout) |
3790 | + return false; |
3791 | + return value == *timeout; |
3792 | +} |
3793 | + |
3794 | +MATCHER_P(MergeMatches, value, |
3795 | + std::string("merge should be: " + testing::PrintToString(value))) |
3796 | +{ |
3797 | + auto argument = static_cast<struct sync_merge_data*>(arg); |
3798 | + return argument->fd2 == value.fd2; |
3799 | +} |
3800 | + |
3801 | +TEST_F(SyncSwTest, sync_wait) |
3802 | +{ |
3803 | + EXPECT_CALL(*mock_fops, ioctl(dummy_fd, SYNC_IOC_WAIT, TimeoutMatches(-1))) |
3804 | + .Times(1); |
3805 | + mga::SyncFence fence1(mock_fops, dummy_fd); |
3806 | + fence1.wait(); |
3807 | + |
3808 | + //will not call ioctl |
3809 | + mga::SyncFence fence2(mock_fops, invalid_fd); |
3810 | + fence2.wait(); |
3811 | +} |
3812 | + |
3813 | + |
3814 | +namespace |
3815 | +{ |
3816 | +struct IoctlSetter |
3817 | +{ |
3818 | + IoctlSetter(int fd) |
3819 | + : fd(fd) |
3820 | + { |
3821 | + } |
3822 | + int merge_setter(int, int, void* data) |
3823 | + { |
3824 | + auto b = static_cast<struct sync_merge_data*>(data); |
3825 | + b->fence = fd; |
3826 | + return 0; |
3827 | + } |
3828 | + int fd; |
3829 | +}; |
3830 | +} |
3831 | +TEST_F(SyncSwTest, sync_merge_with_valid_fd) |
3832 | +{ |
3833 | + using namespace testing; |
3834 | + int dummy_fd2 = 44; |
3835 | + int out_fd = 88; |
3836 | + IoctlSetter setter(out_fd); |
3837 | + |
3838 | + struct sync_merge_data expected_data_in { dummy_fd2, "name", 0 }; |
3839 | + |
3840 | + EXPECT_CALL(*mock_fops, ioctl(dummy_fd, SYNC_IOC_MERGE, MergeMatches(expected_data_in))) |
3841 | + .Times(1) |
3842 | + .WillOnce(Invoke(&setter, &IoctlSetter::merge_setter)); |
3843 | + |
3844 | + mga::SyncFence fence1(mock_fops, dummy_fd); |
3845 | + |
3846 | + fence1.merge_with(dummy_fd2); |
3847 | +} |
3848 | + |
3849 | +TEST_F(SyncSwTest, sync_merge_with_invalid_fd) |
3850 | +{ |
3851 | + using namespace testing; |
3852 | + EXPECT_CALL(*mock_fops, ioctl(dummy_fd, SYNC_IOC_MERGE, _)) |
3853 | + .Times(0); |
3854 | + |
3855 | + mga::SyncFence fence1(mock_fops, invalid_fd); |
3856 | + |
3857 | + fence1.merge_with(dummy_fd); |
3858 | +} |
3859 | + |
3860 | +TEST_F(SyncSwTest, copy_dups_fd) |
3861 | +{ |
3862 | + using namespace testing; |
3863 | + int fd2 = dummy_fd + 1; |
3864 | + EXPECT_CALL(*mock_fops, dup(dummy_fd)) |
3865 | + .Times(1) |
3866 | + .WillOnce(Return(fd2));; |
3867 | + |
3868 | + mga::SyncFence fence(mock_fops, dummy_fd); |
3869 | + |
3870 | + EXPECT_EQ(fd2, fence.copy_native_handle()); |
3871 | +} |
FAILED: Continuous integration, rev:1128 /code.launchpad .net/~kdub/ mir/android- buffer- syncfence/ +merge/ 189717/ +edit-commit- message
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http:// jenkins. qa.ubuntu. com/job/ mir-team- mir-development -branch- ci/135/ jenkins. qa.ubuntu. com/job/ mir-android- saucy-i386- build/2290 jenkins. qa.ubuntu. com/job/ mir-clang- saucy-amd64- build/2175 jenkins. qa.ubuntu. com/job/ mir-team- mir-development -branch- saucy-amd64- ci/132 jenkins. qa.ubuntu. com/job/ mir-team- mir-development -branch- saucy-amd64- ci/132/ artifact/ work/output/ *zip*/output. zip
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild: 10.97.0. 26:8080/ job/mir- team-mir- development- branch- ci/135/ rebuild
http://