Mir

Merge lp:~kdub/mir/rw-fences into lp:mir

Proposed by Kevin DuBois
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 1713
Proposed branch: lp:~kdub/mir/rw-fences
Merge into: lp:mir
Prerequisite: lp:~kdub/mir/arrange-fences-on-buffer-send
Diff against target: 525 lines (+127/-63)
24 files modified
include/shared/mir/graphics/android/android_native_buffer.h (+7/-4)
include/shared/mir/graphics/android/native_buffer.h (+11/-2)
include/test/mir_test_doubles/mock_android_native_buffer.h (+2/-2)
src/client/android/android_client_buffer.cpp (+1/-1)
src/platform/graphics/android/android_alloc_adaptor.cpp (+1/-1)
src/platform/graphics/android/android_platform.cpp (+1/-1)
src/platform/graphics/android/buffer.cpp (+1/-1)
src/platform/graphics/android/fb_device.cpp (+1/-1)
src/platform/graphics/android/hwc_fb_device.cpp (+1/-1)
src/platform/graphics/android/hwc_layers.cpp (+1/-1)
src/platform/graphics/android/internal_client_window.cpp (+1/-1)
src/platform/graphics/android/interpreter_cache.cpp (+1/-1)
src/shared/graphics/android/android_native_buffer.cpp (+9/-3)
src/shared/graphics/android/mir_native_window.cpp (+1/-1)
src/shared/testdraw/android_graphics_region_factory.cpp (+2/-1)
tests/unit-tests/client/android/test_android_native_window.cpp (+1/-1)
tests/unit-tests/graphics/android/CMakeLists.txt (+1/-1)
tests/unit-tests/graphics/android/test_android_platform.cpp (+2/-2)
tests/unit-tests/graphics/android/test_buffer.cpp (+4/-4)
tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp (+1/-1)
tests/unit-tests/graphics/android/test_hwc_device.cpp (+6/-6)
tests/unit-tests/graphics/android/test_hwc_layers.cpp (+1/-1)
tests/unit-tests/graphics/android/test_interpreter_buffer_cache.cpp (+2/-2)
tests/unit-tests/graphics/android/test_native_buffer.cpp (+68/-23)
To merge this branch: bzr merge lp:~kdub/mir/rw-fences
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alexandros Frantzis (community) Approve
Alan Griffiths Needs Fixing
Alberto Aguirre (community) Approve
Review via email: mp+223479@code.launchpad.net

Commit message

android: designate the buffer usage when attempting to access or update the fence associated with the native buffer. This lets us skip waiting if the buffer is being reserved for reading and a second read is needed.

Specifically, if HWC has a buffer onscreen, and then needs to use that same buffer in the composition of the next frame, it needs to be able to read from the onscreen-buffer to assemble the next frame. We account for this if the buffer was an overlay in frame 1 and and overlay in frame 2, but if its overlay in frame 1, and then gl fallback in frame 2, then we need read-only access for the texture upload.

fixes: lp: #1329868

Description of the change

android: designate the buffer usage when attempting to access or update the fence associated with the native buffer. This lets us skip waiting if the buffer is being reserved for reading and a second read is needed.

Specifically, if HWC has a buffer onscreen, and then needs to use that same buffer in the composition of the next frame, it needs to be able to read from the onscreen-buffer to assemble the next frame. We account for this if the buffer was an overlay in frame 1 and and overlay in frame 2, but if its overlay in frame 1, and then gl fallback in frame 2, then we need read-only access for the texture upload.

checked for tears with full unity stack on:
mx3, nex4, nex10

fixes: lp: #1329868

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

Makes sense.

I can't think of any scenario where both read and write access is needed.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

bzr: ERROR: Invalid http response for https://xmlrpc.launchpad.net/bazaar/: Unable to handle http code 502: Bad Gateway

doesnt look related

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Warning: criss-cross merge encountered. See bzr help criss-cross.
...
Text conflict in src/platform/graphics/android/android_platform.cpp
1 conflicts encountered.

review: Needs Fixing
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

> Makes sense.
>
> I can't think of any scenario where both read and write access is needed.

Indeed, gralloc "spec" prohibits it.

Revision history for this message
Kevin DuBois (kdub) wrote :

conflict addressed.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> conflict addressed.

Ack. No time to review today - abstaining to unblock

review: Abstain
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Not a thorough review, but one thing that caught my eye:

TEST_F(NativeBuffer, access_for_read_while_being_read)
TEST_F(NativeBuffer, access_for_read_while_being_written)
...etc

The names describe what the arrangement and actions of the test are (while being read, try to read), but not what the expected behavior should be (does not wait). Therefore the names are not as informative as they could be. Perhaps something like:

TEST_F(NativeBuffer, does_not_wait_for_read_access_while_being_read)

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> Not a thorough review, but one thing that caught my eye:
>
> TEST_F(NativeBuffer, access_for_read_while_being_read)
> TEST_F(NativeBuffer, access_for_read_while_being_written)
> ...etc
>
> The names describe what the arrangement and actions of the test are (while
> being read, try to read), but not what the expected behavior should be (does
> not wait). Therefore the names are not as informative as they could be.
> Perhaps something like:
>
> TEST_F(NativeBuffer, does_not_wait_for_read_access_while_being_read)

Agreed, arguably a "nit" better test names would aid understanding.

review: Needs Fixing
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Other than the test name improvements (covered by Alan's needs fixing), looks good.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

concerns addressed + approvals, so top-approving

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/shared/mir/graphics/android/android_native_buffer.h'
2--- include/shared/mir/graphics/android/android_native_buffer.h 2013-10-11 22:03:04 +0000
3+++ include/shared/mir/graphics/android/android_native_buffer.h 2014-06-20 15:19:36 +0000
4@@ -33,18 +33,21 @@
5
6 struct AndroidNativeBuffer : public graphics::NativeBuffer
7 {
8- AndroidNativeBuffer(std::shared_ptr<ANativeWindowBuffer> const& handle,
9- std::shared_ptr<Fence> const& fence);
10+ AndroidNativeBuffer(
11+ std::shared_ptr<ANativeWindowBuffer> const& handle,
12+ std::shared_ptr<Fence> const& fence,
13+ BufferAccess fence_access);
14
15 ANativeWindowBuffer* anwb() const;
16 buffer_handle_t handle() const;
17 NativeFence copy_fence() const;
18
19- void wait_for_content();
20- void update_fence(NativeFence& merge_fd);
21+ void ensure_available_for(BufferAccess);
22+ void update_usage(NativeFence& merge_fd, BufferAccess);
23
24 private:
25 std::shared_ptr<Fence> fence;
26+ BufferAccess access;
27 std::shared_ptr<ANativeWindowBuffer> native_window_buffer;
28 };
29
30
31=== modified file 'include/shared/mir/graphics/android/native_buffer.h'
32--- include/shared/mir/graphics/android/native_buffer.h 2014-03-06 06:05:17 +0000
33+++ include/shared/mir/graphics/android/native_buffer.h 2014-06-20 15:19:36 +0000
34@@ -27,6 +27,15 @@
35 namespace graphics
36 {
37
38+namespace android
39+{
40+enum class BufferAccess
41+{
42+ read,
43+ write
44+};
45+}
46+
47 class NativeBuffer
48 {
49 public:
50@@ -36,8 +45,8 @@
51 virtual buffer_handle_t handle() const = 0;
52 virtual android::NativeFence copy_fence() const = 0;
53
54- virtual void wait_for_content() = 0;
55- virtual void update_fence(android::NativeFence& fence) = 0;
56+ virtual void ensure_available_for(android::BufferAccess intent) = 0;
57+ virtual void update_usage(android::NativeFence& fence, android::BufferAccess current_usage) = 0;
58
59 protected:
60 NativeBuffer() = default;
61
62=== modified file 'include/test/mir_test_doubles/mock_android_native_buffer.h'
63--- include/test/mir_test_doubles/mock_android_native_buffer.h 2014-03-11 13:44:57 +0000
64+++ include/test/mir_test_doubles/mock_android_native_buffer.h 2014-06-20 15:19:36 +0000
65@@ -54,8 +54,8 @@
66 MOCK_CONST_METHOD0(handle, buffer_handle_t());
67 MOCK_CONST_METHOD0(copy_fence, graphics::android::NativeFence());
68
69- MOCK_METHOD0(wait_for_content, void());
70- MOCK_METHOD1(update_fence, void(graphics::android::NativeFence&));
71+ MOCK_METHOD1(ensure_available_for, void(graphics::android::BufferAccess));
72+ MOCK_METHOD2(update_usage, void(graphics::android::NativeFence&, graphics::android::BufferAccess));
73
74 ANativeWindowBuffer stub_anwb;
75 native_handle_t native_handle;
76
77=== modified file 'src/client/android/android_client_buffer.cpp'
78--- src/client/android/android_client_buffer.cpp 2014-03-06 06:05:17 +0000
79+++ src/client/android/android_client_buffer.cpp 2014-06-20 15:19:36 +0000
80@@ -52,7 +52,7 @@
81 anwb->usage = GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER;
82 anwb->handle = native_handle.get();
83
84- native_window_buffer = std::make_shared<mga::AndroidNativeBuffer>(anwb, fence);
85+ native_window_buffer = std::make_shared<mga::AndroidNativeBuffer>(anwb, fence, mga::BufferAccess::read);
86 }
87
88 mcla::AndroidClientBuffer::~AndroidClientBuffer() noexcept
89
90=== modified file 'src/platform/graphics/android/android_alloc_adaptor.cpp'
91--- src/platform/graphics/android/android_alloc_adaptor.cpp 2014-03-06 06:05:17 +0000
92+++ src/platform/graphics/android/android_alloc_adaptor.cpp 2014-06-20 15:19:36 +0000
93@@ -88,7 +88,7 @@
94 anwb->format = format;
95 anwb->usage = usage_flag;
96
97- return std::make_shared<mga::AndroidNativeBuffer>(anwb, fence);
98+ return std::make_shared<mga::AndroidNativeBuffer>(anwb, fence, mga::BufferAccess::read);
99 }
100
101 int mga::AndroidAllocAdaptor::convert_to_android_usage(BufferUsage usage)
102
103=== modified file 'src/platform/graphics/android/android_platform.cpp'
104--- src/platform/graphics/android/android_platform.cpp 2014-06-18 22:04:55 +0000
105+++ src/platform/graphics/android/android_platform.cpp 2014-06-20 15:19:36 +0000
106@@ -118,7 +118,7 @@
107 auto native_buffer = buffer->native_buffer_handle();
108
109 /* TODO: instead of waiting, pack the fence fd in the message to the client */
110- native_buffer->wait_for_content();
111+ native_buffer->ensure_available_for(mga::BufferAccess::write);
112 if (msg_type == mg::BufferIpcMsgType::full_msg)
113 {
114 auto buffer_handle = native_buffer->handle();
115
116=== modified file 'src/platform/graphics/android/buffer.cpp'
117--- src/platform/graphics/android/buffer.cpp 2014-05-01 08:11:50 +0000
118+++ src/platform/graphics/android/buffer.cpp 2014-06-20 15:19:36 +0000
119@@ -76,7 +76,7 @@
120 void mga::Buffer::gl_bind_to_texture()
121 {
122 std::unique_lock<std::mutex> lk(content_lock);
123- native_buffer->wait_for_content();
124+ native_buffer->ensure_available_for(mga::BufferAccess::read);
125
126 DispContextPair current
127 {
128
129=== modified file 'src/platform/graphics/android/fb_device.cpp'
130--- src/platform/graphics/android/fb_device.cpp 2014-06-16 14:47:14 +0000
131+++ src/platform/graphics/android/fb_device.cpp 2014-06-20 15:19:36 +0000
132@@ -49,7 +49,7 @@
133 context.swap_buffers();
134 auto const& buffer = context.last_rendered_buffer();
135 auto native_buffer = buffer->native_buffer_handle();
136- native_buffer->wait_for_content();
137+ native_buffer->ensure_available_for(mga::BufferAccess::read);
138 if (fb_device->post(fb_device.get(), native_buffer->handle()) != 0)
139 {
140 BOOST_THROW_EXCEPTION(std::runtime_error("error posting with fb device"));
141
142=== modified file 'src/platform/graphics/android/hwc_fb_device.cpp'
143--- src/platform/graphics/android/hwc_fb_device.cpp 2014-06-16 14:47:14 +0000
144+++ src/platform/graphics/android/hwc_fb_device.cpp 2014-06-20 15:19:36 +0000
145@@ -70,7 +70,7 @@
146
147 auto const& buffer = context.last_rendered_buffer();
148 auto native_buffer = buffer->native_buffer_handle();
149- native_buffer->wait_for_content();
150+ native_buffer->ensure_available_for(mga::BufferAccess::read);
151 if (fb_device->post(fb_device.get(), native_buffer->handle()) != 0)
152 {
153 BOOST_THROW_EXCEPTION(std::runtime_error("error posting with fb device"));
154
155=== modified file 'src/platform/graphics/android/hwc_layers.cpp'
156--- src/platform/graphics/android/hwc_layers.cpp 2014-06-18 17:12:18 +0000
157+++ src/platform/graphics/android/hwc_layers.cpp 2014-06-20 15:19:36 +0000
158@@ -93,7 +93,7 @@
159 {
160 if (hwc_layer->compositionType != HWC_FRAMEBUFFER)
161 {
162- associated_buffer->update_fence(hwc_layer->releaseFenceFd);
163+ associated_buffer->update_usage(hwc_layer->releaseFenceFd, mga::BufferAccess::read);
164 hwc_layer->releaseFenceFd = -1;
165 hwc_layer->acquireFenceFd = -1;
166 associated_buffer.reset();
167
168=== modified file 'src/platform/graphics/android/internal_client_window.cpp'
169--- src/platform/graphics/android/internal_client_window.cpp 2014-04-15 05:31:19 +0000
170+++ src/platform/graphics/android/internal_client_window.cpp 2014-06-20 15:19:36 +0000
171@@ -65,7 +65,7 @@
172 buffer = it->second.buffer;
173 lookup.erase(it);
174
175- handle->update_fence(fence_fd);
176+ handle->update_usage(fence_fd, mga::BufferAccess::write);
177 surface->swap_buffers(buffer);
178 }
179
180
181=== modified file 'src/platform/graphics/android/interpreter_cache.cpp'
182--- src/platform/graphics/android/interpreter_cache.cpp 2014-03-06 06:05:17 +0000
183+++ src/platform/graphics/android/interpreter_cache.cpp 2014-06-20 15:19:36 +0000
184@@ -58,5 +58,5 @@
185 }
186
187 auto native_buffer = native_it->second;
188- native_buffer->update_fence(fence);
189+ native_buffer->update_usage(fence, mga::BufferAccess::write);
190 }
191
192=== modified file 'src/shared/graphics/android/android_native_buffer.cpp'
193--- src/shared/graphics/android/android_native_buffer.cpp 2013-10-11 23:46:05 +0000
194+++ src/shared/graphics/android/android_native_buffer.cpp 2014-06-20 15:19:36 +0000
195@@ -22,20 +22,26 @@
196
197 mga::AndroidNativeBuffer::AndroidNativeBuffer(
198 std::shared_ptr<ANativeWindowBuffer> const& anwb,
199- std::shared_ptr<Fence> const& fence)
200+ std::shared_ptr<Fence> const& fence,
201+ BufferAccess access)
202 : fence(fence),
203+ access(access),
204 native_window_buffer(anwb)
205 {
206 }
207
208-void mga::AndroidNativeBuffer::wait_for_content()
209+void mga::AndroidNativeBuffer::ensure_available_for(BufferAccess intent)
210 {
211+ if ((access == mga::BufferAccess::read) && (intent == mga::BufferAccess::read))
212+ return;
213+
214 fence->wait();
215 }
216
217-void mga::AndroidNativeBuffer::update_fence(NativeFence& merge_fd)
218+void mga::AndroidNativeBuffer::update_usage(NativeFence& merge_fd, BufferAccess updated_access)
219 {
220 fence->merge_with(merge_fd);
221+ access = updated_access;
222 }
223
224 ANativeWindowBuffer* mga::AndroidNativeBuffer::anwb() const
225
226=== modified file 'src/shared/graphics/android/mir_native_window.cpp'
227--- src/shared/graphics/android/mir_native_window.cpp 2014-03-06 06:05:17 +0000
228+++ src/shared/graphics/android/mir_native_window.cpp 2014-06-20 15:19:36 +0000
229@@ -171,7 +171,7 @@
230 {
231 auto buffer = driver_interpreter->driver_requests_buffer();
232 *buffer_to_driver = buffer->anwb();
233- buffer->wait_for_content();
234+ buffer->ensure_available_for(mga::BufferAccess::write);
235 return 0;
236 }
237
238
239=== modified file 'src/shared/testdraw/android_graphics_region_factory.cpp'
240--- src/shared/testdraw/android_graphics_region_factory.cpp 2014-03-26 05:48:59 +0000
241+++ src/shared/testdraw/android_graphics_region_factory.cpp 2014-06-20 15:19:36 +0000
242@@ -25,6 +25,7 @@
243 #include <stdexcept>
244
245 namespace mtd=mir::test::draw;
246+namespace mga=mir::graphics::android;
247
248 namespace
249 {
250@@ -66,7 +67,7 @@
251 std::shared_ptr<MirGraphicsRegion> graphic_region_from_handle(
252 mir::graphics::NativeBuffer& native_buffer)
253 {
254- native_buffer.wait_for_content();
255+ native_buffer.ensure_available_for(mga::BufferAccess::write);
256 auto anwb = native_buffer.anwb();
257 int *vaddr;
258 int usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
259
260=== modified file 'tests/unit-tests/client/android/test_android_native_window.cpp'
261--- tests/unit-tests/client/android/test_android_native_window.cpp 2014-03-06 06:05:17 +0000
262+++ tests/unit-tests/client/android/test_android_native_window.cpp 2014-06-20 15:19:36 +0000
263@@ -182,7 +182,7 @@
264 EXPECT_CALL(*mock_driver_interpreter, driver_requests_buffer())
265 .Times(1)
266 .WillOnce(Return(mock_buffer.get()));
267- EXPECT_CALL(*mock_buffer, wait_for_content())
268+ EXPECT_CALL(*mock_buffer, ensure_available_for(mga::BufferAccess::write))
269 .Times(1);
270 EXPECT_CALL(*mock_buffer, copy_fence())
271 .Times(0);
272
273=== modified file 'tests/unit-tests/graphics/android/CMakeLists.txt'
274--- tests/unit-tests/graphics/android/CMakeLists.txt 2014-06-02 17:07:02 +0000
275+++ tests/unit-tests/graphics/android/CMakeLists.txt 2014-06-20 15:19:36 +0000
276@@ -23,7 +23,7 @@
277 ${CMAKE_CURRENT_SOURCE_DIR}/test_pixel_format.cpp
278 ${CMAKE_CURRENT_SOURCE_DIR}/test_android_platform.cpp
279 ${CMAKE_CURRENT_SOURCE_DIR}/test_interpreter_buffer_cache.cpp
280- ${CMAKE_CURRENT_SOURCE_DIR}/test_external_refcount.cpp
281+ ${CMAKE_CURRENT_SOURCE_DIR}/test_native_buffer.cpp
282 ${CMAKE_CURRENT_SOURCE_DIR}/test_output_builder.cpp
283 ${CMAKE_CURRENT_SOURCE_DIR}/test_device_detection.cpp
284 ${CMAKE_CURRENT_SOURCE_DIR}/test_hwc_wrapper.cpp
285
286=== modified file 'tests/unit-tests/graphics/android/test_android_platform.cpp'
287--- tests/unit-tests/graphics/android/test_android_platform.cpp 2014-06-16 23:37:57 +0000
288+++ tests/unit-tests/graphics/android/test_android_platform.cpp 2014-06-20 15:19:36 +0000
289@@ -113,7 +113,7 @@
290 EXPECT_CALL(mock_packer, pack_size(_))
291 .Times(1);
292
293- EXPECT_CALL(*native_buffer, wait_for_content())
294+ EXPECT_CALL(*native_buffer, ensure_available_for(mga::BufferAccess::write))
295 .Times(1);
296
297 platform.fill_buffer_package(
298@@ -137,7 +137,7 @@
299 .Times(0);
300
301 /* TODO: instead of waiting, pass the fd along */
302- EXPECT_CALL(*native_buffer, wait_for_content())
303+ EXPECT_CALL(*native_buffer, ensure_available_for(mga::BufferAccess::write))
304 .Times(1);
305
306 platform.fill_buffer_package(
307
308=== modified file 'tests/unit-tests/graphics/android/test_buffer.cpp'
309--- tests/unit-tests/graphics/android/test_buffer.cpp 2014-03-06 06:05:17 +0000
310+++ tests/unit-tests/graphics/android/test_buffer.cpp 2014-06-20 15:19:36 +0000
311@@ -89,21 +89,21 @@
312 int acquire_fake_fence_fd1 = 948;
313 int acquire_fake_fence_fd2 = 954;
314
315- EXPECT_CALL(*mock_native_buffer, update_fence(acquire_fake_fence_fd1))
316+ EXPECT_CALL(*mock_native_buffer, update_usage(acquire_fake_fence_fd1, mga::BufferAccess::write))
317 .Times(1);
318- EXPECT_CALL(*mock_native_buffer, update_fence(acquire_fake_fence_fd2))
319+ EXPECT_CALL(*mock_native_buffer, update_usage(acquire_fake_fence_fd2, mga::BufferAccess::read))
320 .Times(1);
321
322 mga::Buffer buffer(mock_native_buffer, extensions);
323 {
324 auto native_resource = buffer.native_buffer_handle();
325 EXPECT_EQ(mock_native_buffer, native_resource);
326- native_resource->update_fence(acquire_fake_fence_fd1);
327+ native_resource->update_usage(acquire_fake_fence_fd1, mga::BufferAccess::write);
328 }
329 {
330 auto native_resource = buffer.native_buffer_handle();
331 EXPECT_EQ(mock_native_buffer, native_resource);
332- native_resource->update_fence(acquire_fake_fence_fd2);
333+ native_resource->update_usage(acquire_fake_fence_fd2, mga::BufferAccess::read);
334 }
335 }
336
337
338=== modified file 'tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp'
339--- tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp 2014-05-01 08:07:56 +0000
340+++ tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp 2014-06-20 15:19:36 +0000
341@@ -350,7 +350,7 @@
342 TEST_F(AndroidBufferBinding, gl_bind_to_texture_waits_on_fence)
343 {
344 using namespace testing;
345- EXPECT_CALL(*mock_native_buffer, wait_for_content())
346+ EXPECT_CALL(*mock_native_buffer, ensure_available_for(mga::BufferAccess::read))
347 .Times(1);
348
349 mga::Buffer buffer(mock_native_buffer, extensions);
350
351=== modified file 'tests/unit-tests/graphics/android/test_hwc_device.cpp'
352--- tests/unit-tests/graphics/android/test_hwc_device.cpp 2014-06-18 15:58:27 +0000
353+++ tests/unit-tests/graphics/android/test_hwc_device.cpp 2014-06-20 15:19:36 +0000
354@@ -302,7 +302,7 @@
355 EXPECT_CALL(*mock_hwc_device_wrapper, set(MatchesList(expected_list)))
356 .InSequence(seq)
357 .WillOnce(Invoke(set_fences_fn));
358- EXPECT_CALL(*mock_native_buffer, update_fence(fb_release_fence))
359+ EXPECT_CALL(*mock_native_buffer, update_usage(fb_release_fence, mga::BufferAccess::read))
360 .InSequence(seq);
361 EXPECT_CALL(*mock_file_ops, close(hwc_retire_fence))
362 .InSequence(seq);
363@@ -416,11 +416,11 @@
364 EXPECT_CALL(*mock_hwc_device_wrapper, set(MatchesList(expected_list)))
365 .InSequence(seq)
366 .WillOnce(Invoke(set_fences_fn));
367- EXPECT_CALL(*native_handle_1, update_fence(release_fence1))
368- .InSequence(seq);
369- EXPECT_CALL(*native_handle_2, update_fence(release_fence2))
370- .InSequence(seq);
371- EXPECT_CALL(*native_handle_3, update_fence(release_fence3))
372+ EXPECT_CALL(*native_handle_1, update_usage(release_fence1, mga::BufferAccess::read))
373+ .InSequence(seq);
374+ EXPECT_CALL(*native_handle_2, update_usage(release_fence2, mga::BufferAccess::read))
375+ .InSequence(seq);
376+ EXPECT_CALL(*native_handle_3, update_usage(release_fence3, mga::BufferAccess::read))
377 .InSequence(seq);
378
379 EXPECT_TRUE(device.post_overlays(mock_context, updated_list, stub_compositor));
380
381=== modified file 'tests/unit-tests/graphics/android/test_hwc_layers.cpp'
382--- tests/unit-tests/graphics/android/test_hwc_layers.cpp 2014-06-18 15:58:27 +0000
383+++ tests/unit-tests/graphics/android/test_hwc_layers.cpp 2014-06-20 15:19:36 +0000
384@@ -234,7 +234,7 @@
385 TEST_F(HWCLayersTest, buffer_fence_updates)
386 {
387 int fake_fence = 552;
388- EXPECT_CALL(*native_handle_1, update_fence(fake_fence))
389+ EXPECT_CALL(*native_handle_1, update_usage(fake_fence, mga::BufferAccess::read))
390 .Times(1);
391 type = mga::LayerType::framebuffer_target;
392 mga::HWCLayer layer(type, screen_position, alpha_enabled, list, list_index);
393
394=== modified file 'tests/unit-tests/graphics/android/test_interpreter_buffer_cache.cpp'
395--- tests/unit-tests/graphics/android/test_interpreter_buffer_cache.cpp 2014-03-06 06:05:17 +0000
396+++ tests/unit-tests/graphics/android/test_interpreter_buffer_cache.cpp 2014-06-20 15:19:36 +0000
397@@ -84,12 +84,12 @@
398 EXPECT_EQ(use_count_before, stub_buffer1.use_count());
399 }
400
401-TEST_F(InterpreterResourceTest, update_fence_for)
402+TEST_F(InterpreterResourceTest, update_usage_for)
403 {
404 int fence_fd = 44;
405 mga::InterpreterCache cache;
406
407- EXPECT_CALL(*native_buffer1, update_fence(fence_fd))
408+ EXPECT_CALL(*native_buffer1, update_usage(fence_fd, mga::BufferAccess::write))
409 .Times(1);
410
411 cache.store_buffer(stub_buffer1, native_buffer1);
412
413=== renamed file 'tests/unit-tests/graphics/android/test_external_refcount.cpp' => 'tests/unit-tests/graphics/android/test_native_buffer.cpp'
414--- tests/unit-tests/graphics/android/test_external_refcount.cpp 2014-03-06 06:05:17 +0000
415+++ tests/unit-tests/graphics/android/test_native_buffer.cpp 2014-06-20 15:19:36 +0000
416@@ -24,7 +24,21 @@
417 namespace mtd=mir::test::doubles;
418 namespace mga=mir::graphics::android;
419
420-TEST(AndroidRefcount, driver_hooks)
421+struct NativeBuffer : public testing::Test
422+{
423+ NativeBuffer() :
424+ a_native_window_buffer(std::make_shared<ANativeWindowBuffer>()),
425+ mock_fence(std::make_shared<testing::NiceMock<mtd::MockFence>>()),
426+ fake_fd{48484}
427+ {
428+ }
429+
430+ std::shared_ptr<ANativeWindowBuffer> a_native_window_buffer;
431+ std::shared_ptr<mtd::MockFence> mock_fence;
432+ int fake_fd;
433+};
434+
435+TEST_F(NativeBuffer, extends_lifetime_when_driver_calls_external_refcount_hooks)
436 {
437 auto native_handle_resource = std::make_shared<native_handle_t>();
438 auto use_count_before = native_handle_resource.use_count();
439@@ -46,7 +60,7 @@
440 EXPECT_EQ(use_count_before, native_handle_resource.use_count());
441 }
442
443-TEST(AndroidRefcount, driver_hooks_mir_ref)
444+TEST_F(NativeBuffer, is_not_destroyed_if_driver_loses_reference_while_mir_still_has_reference)
445 {
446 auto native_handle_resource = std::make_shared<native_handle_t>();
447 auto use_count_before = native_handle_resource.use_count();
448@@ -70,25 +84,56 @@
449 EXPECT_EQ(use_count_before, native_handle_resource.use_count());
450 }
451
452-TEST(AndroidAndroidNativeBuffer, wait_for_fence)
453-{
454- auto fence = std::make_shared<mtd::MockFence>();
455- EXPECT_CALL(*fence, wait())
456- .Times(1);
457-
458- auto native_handle_resource = std::make_shared<ANativeWindowBuffer>();
459- mga::AndroidNativeBuffer buffer(native_handle_resource, fence);
460- buffer.wait_for_content();
461-}
462-
463-TEST(AndroidAndroidNativeBuffer, update_fence)
464-{
465- int fake_fd = 48484;
466- auto fence = std::make_shared<mtd::MockFence>();
467- EXPECT_CALL(*fence, merge_with(fake_fd))
468- .Times(1);
469-
470- auto native_handle_resource = std::make_shared<ANativeWindowBuffer>();
471- mga::AndroidNativeBuffer buffer(native_handle_resource, fence);
472- buffer.update_fence(fake_fd);
473+TEST_F(NativeBuffer, does_not_wait_for_read_access_while_being_read)
474+{
475+ EXPECT_CALL(*mock_fence, wait())
476+ .Times(0);
477+ mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::read);
478+ buffer.ensure_available_for(mga::BufferAccess::read);
479+}
480+
481+TEST_F(NativeBuffer, waits_for_read_access_while_being_written)
482+{
483+ EXPECT_CALL(*mock_fence, wait())
484+ .Times(1);
485+ mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::write);
486+ buffer.ensure_available_for(mga::BufferAccess::read);
487+}
488+
489+TEST_F(NativeBuffer, waits_for_write_access_while_being_read)
490+{
491+ EXPECT_CALL(*mock_fence, wait())
492+ .Times(1);
493+ mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::read);
494+ buffer.ensure_available_for(mga::BufferAccess::write);
495+}
496+
497+TEST_F(NativeBuffer, waits_for_write_access_while_being_written)
498+{
499+ EXPECT_CALL(*mock_fence, wait())
500+ .Times(1);
501+ mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::write);
502+ buffer.ensure_available_for(mga::BufferAccess::write);
503+}
504+
505+TEST_F(NativeBuffer, merges_existing_fence_with_updated_fence)
506+{
507+ EXPECT_CALL(*mock_fence, merge_with(fake_fd))
508+ .Times(1);
509+ mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::read);
510+ buffer.update_usage(fake_fd, mga::BufferAccess::write);
511+}
512+
513+TEST_F(NativeBuffer, waits_depending_on_last_fence_update)
514+{
515+ EXPECT_CALL(*mock_fence, wait())
516+ .Times(3);
517+
518+ mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::read);
519+ buffer.ensure_available_for(mga::BufferAccess::write);
520+ buffer.ensure_available_for(mga::BufferAccess::read);
521+
522+ buffer.update_usage(fake_fd, mga::BufferAccess::write);
523+ buffer.ensure_available_for(mga::BufferAccess::write);
524+ buffer.ensure_available_for(mga::BufferAccess::read);
525 }

Subscribers

People subscribed via source and target branches