Merge lp:~kdub/mir/egl-sync-fences into lp:mir
- egl-sync-fences
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | Kevin DuBois |
Approved revision: | no longer in the source branch. |
Merged at revision: | 3169 |
Proposed branch: | lp:~kdub/mir/egl-sync-fences |
Merge into: | lp:mir |
Prerequisite: | lp:~kdub/mir/android-shift-swapbuffers |
Diff against target: |
1322 lines (+420/-48) 44 files modified
include/renderers/gl/mir/renderer/gl/texture_source.h (+10/-0) src/common/graphics/android/CMakeLists.txt (+1/-0) src/common/graphics/android/android_native_buffer.cpp (+15/-1) src/gl/recently_used_cache.cpp (+8/-7) src/include/common/mir/graphics/android/android_native_buffer.h (+6/-0) src/include/common/mir/graphics/android/native_buffer.h (+3/-0) src/platform/symbols.map (+14/-0) src/platforms/android/client/CMakeLists.txt (+2/-0) src/platforms/android/client/gralloc_registrar.cpp (+3/-1) src/platforms/android/server/CMakeLists.txt (+1/-0) src/platforms/android/server/android_alloc_adaptor.cpp (+12/-5) src/platforms/android/server/android_alloc_adaptor.h (+6/-2) src/platforms/android/server/android_buffer_allocator.cpp (+10/-4) src/platforms/android/server/android_graphic_buffer_allocator.h (+5/-1) src/platforms/android/server/buffer.cpp (+23/-4) src/platforms/android/server/buffer.h (+6/-0) src/platforms/android/server/cmdstream_sync_factory.h (+48/-0) src/platforms/android/server/display_component_factory.h (+2/-0) src/platforms/android/server/egl_sync_factory.cpp (+34/-0) src/platforms/android/server/hal_component_factory.cpp (+15/-0) src/platforms/android/server/hal_component_factory.h (+3/-1) src/platforms/android/server/ipc_operations.cpp (+1/-0) src/platforms/android/server/platform.cpp (+10/-4) src/platforms/android/server/platform.h (+3/-0) src/platforms/mesa/server/common/gbm_buffer.cpp (+9/-0) src/platforms/mesa/server/common/gbm_buffer.h (+2/-0) src/platforms/mesa/server/common/shm_buffer.cpp (+9/-0) src/platforms/mesa/server/common/shm_buffer.h (+2/-0) tests/include/mir/test/doubles/mock_android_native_buffer.h (+2/-0) tests/include/mir/test/doubles/mock_buffer.h (+1/-0) tests/include/mir/test/doubles/mock_gl_buffer.h (+2/-0) tests/include/mir/test/doubles/stub_android_native_buffer.h (+3/-0) tests/include/mir/test/doubles/stub_cmdstream_sync_factory.h (+41/-0) tests/include/mir/test/doubles/stub_display_builder.h (+5/-0) tests/include/mir/test/doubles/stub_gl_buffer.h (+2/-0) tests/integration-tests/graphics/mesa/test_buffer_integration.cpp (+3/-0) tests/unit-tests/gl/test_gl_texture_cache.cpp (+3/-1) tests/unit-tests/gl/test_program_factory.cpp (+1/-1) tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp (+5/-2) tests/unit-tests/graphics/android/test_android_buffer_allocator.cpp (+6/-2) tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp (+13/-1) tests/unit-tests/graphics/android/test_display_hotplug.cpp (+5/-0) tests/unit-tests/graphics/android/test_native_buffer.cpp (+50/-7) tests/unit-tests/graphics/android/test_platform.cpp (+15/-4) |
To merge this branch: | bzr merge lp:~kdub/mir/egl-sync-fences |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Alan Griffiths | Approve | ||
Cemil Azizoglu (community) | Approve | ||
Andreas Pokorny (community) | Approve | ||
Review via email: mp+278181@code.launchpad.net |
Commit message
android: use the EGL_fence_sync extensions to synchronize client software buffers.
fixes: lp: #1517205
Description of the change
android: use the EGL_fence_sync extensions to synchronize client software buffers.
fixes: lp: #1517205
tested on n7, krillin, mx4. (krillin and mx4 had additional problem that will be fixed later. This MP did not make their situation worse)
Summary of Changes:
1) When the texture is used in the GLContext, raise the egl sync fence.
2) When the buffer is sent back to the client, make sure to clear the sync fence before sending it across IPC.
3) Make sure that we actually eglSwapBuffers in mir::renderer:
Helpful Details:
Why do we have to shift swapbuffers?
-- If we wait on the EGL sync fences before swapbuffers, then the wait will timeout, as the commands haven't been flushed, and the sync points won't signal. Android currently has the problem that the swapbuffers is delayed until mg::DisplayGrou
Why was swapbuffers in post?
-- HWC 1.0 has the unfortunate design that we're not allowed to call swapbuffers. HWC 1.1 and later, as well as the legacy FB module, can all call swapbuffers. We tried to bury this bad design choice, but this particular problem forces us to take different actions here. The problem we're seeing here is really why the HWC 1.1 api designers gave swapbuffers back to the server.
What was the problem?
glEGLTargetText
What's still wrong with krillin/mx4?
https:/
note: this should land at the same time as the stacked on branch:
https:/
I split the MP up for the benefit of reviewing (esp as we have to shift swapping behavior a bit)
PS Jenkins bot (ps-jenkins) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:3128
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:3130
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
None: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
FAILURE: http://
None: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:3134
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
FAILURE: http://
SUCCESS: http://
deb: http://
None: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Alan Griffiths (alan-griffiths) wrote : | # |
+ //must be called if using this buffer after initial texture upload
+ virtual void used_as_texture() = 0;
The comment suggests this is an easy-to-use-wrongly API and the name suggest a query, not a property setter.
I'm not very familiar with this code, but could gl_bind_
Alternatively, as the underlying action ("native_
~~~~
+ void used_by_gpu();
+ void ensure_
Again, this naming isn't great. Maybe "lock_for_
Andreas Pokorny (andreas-pokorny) wrote : | # |
I agree with Alans comments, better naming is needed.
Under the premise of those being resolved - the solution looks good and solves the bug even on n10
Cemil Azizoglu (cemil-azizoglu) wrote : | # |
I got a failure on PD silo (which merges this branch) and fixed it using the following patch :
=== modified file 'tests/
--- tests/unit-
+++ tests/unit-
@@ -18,11 +18,14 @@
#include "src/platforms/
#include "src/platforms/
+#include "src/platforms/
#include "mir/graphics/
#include "mir/test/
#include "mir/test/
+#include "mir/test/
+
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <stdexcept>
@@ -47,6 +50,7 @@
using namespace testing;
+ auto sync_factory = std::make_
auto quirks = std::make_
@@ -57,6 +61,7 @@
std:
std:
+ ::testing:
MirPixelFormat pf;
geom::Size size;
Cemil Azizoglu (cemil-azizoglu) wrote : | # |
Just realized the patch above was taken w.r.t. the trunk not this branch, so it will not apply cleanly. So just stick the added lines to your branch instead.
Kevin DuBois (kdub) wrote : | # |
Will try to improve the naming, although something that is nicer to use might take more invasive structural changes.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:3137
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Kevin DuBois (kdub) wrote : | # |
> I'm not very familiar with this code, but could gl_bind_
> in both branches (which might then be merged into one)?
gl_bind_to_texture possibly uploads the texture, so calling it twice when not needed will waste texture uploads. We need the second function that adds the sync point without uploading, mostly for texture cache usage.
Ideally, I'd change it to:
//uploads
gl_bind_
//adds sync points
secure_for_render()
but this doesn't fix the bugs for downstreams.
I think I'll go with:
//deprecated/
gl_bind_
//uploads
bind()
//adds sync points
secure_for_render()
Alan Griffiths (alan-griffiths) wrote : | # |
> > I'm not very familiar with this code, but could gl_bind_
> made idempotent and called
> > in both branches (which might then be merged into one)?
>
> gl_bind_to_texture possibly uploads the texture, so calling it twice when not
> needed will waste texture uploads. We need the second function that adds the
> sync point without uploading, mostly for texture cache usage.
I was wondering if gl_bind_
>
> Ideally, I'd change it to:
> //uploads
> gl_bind_
> //adds sync points
> secure_for_render()
>
> but this doesn't fix the bugs for downstreams.
Its also an easy to misuse API as it requires a specific order of calls. It is almost as though secure_for_render() should return an object (a future?) whose destructor does the wait for the gpu release.
> I think I'll go with:
> //deprecated/
> gl_bind_
> //uploads
> bind()
> //adds sync points
> secure_for_render()
OK, I don't have strong feelings against this, it is better than the current proposal.
Cemil Azizoglu (cemil-azizoglu) wrote : | # |
LGTM ...and works.
Alan Griffiths (alan-griffiths) wrote : | # |
This naming isn't actively misleading, and I'll accept the remaining ugliness as largely preexisting.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:3141
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Kevin DuBois (kdub) wrote : | # |
hmm, not in the autolanding queue after 1 day. will retoggle
Preview Diff
1 | === renamed file 'src/include/platform/mir/graphics/egl_extensions.h' => 'include/platform/mir/graphics/egl_extensions.h' |
2 | === renamed file 'src/include/platform/mir/graphics/egl_sync_fence.h' => 'include/platform/mir/graphics/egl_sync_fence.h' |
3 | === modified file 'include/renderers/gl/mir/renderer/gl/texture_source.h' |
4 | --- include/renderers/gl/mir/renderer/gl/texture_source.h 2015-09-15 17:13:45 +0000 |
5 | +++ include/renderers/gl/mir/renderer/gl/texture_source.h 2015-12-02 16:15:28 +0000 |
6 | @@ -26,12 +26,22 @@ |
7 | namespace gl |
8 | { |
9 | |
10 | +//FIXME: (kdub) we're not hiding the differences in texture upload approaches between our platforms |
11 | +// very well with this interface. |
12 | class TextureSource |
13 | { |
14 | public: |
15 | virtual ~TextureSource() = default; |
16 | |
17 | + // \warning deprecated, provided for convenience and legacy transition. |
18 | + //will call bind() and then secure_for_render() |
19 | virtual void gl_bind_to_texture() = 0; |
20 | + //Uploads texture. |
21 | + virtual void bind() = 0; |
22 | + //add synchronization points to the command stream to ensure resources |
23 | + //are present during the draw. Will not upload texture. |
24 | + //should be called if an already uploaded texture is reused. |
25 | + virtual void secure_for_render() = 0; |
26 | |
27 | protected: |
28 | TextureSource() = default; |
29 | |
30 | === modified file 'src/common/graphics/android/CMakeLists.txt' |
31 | --- src/common/graphics/android/CMakeLists.txt 2015-09-24 04:18:40 +0000 |
32 | +++ src/common/graphics/android/CMakeLists.txt 2015-12-02 16:15:28 +0000 |
33 | @@ -1,5 +1,6 @@ |
34 | include_directories(SYSTEM ${LIBHARDWARE_INCLUDE_DIRS}) |
35 | include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/3rd_party/android-deps) |
36 | +include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/include/platform) |
37 | |
38 | add_definitions( -DANDROID ) |
39 | |
40 | |
41 | === modified file 'src/common/graphics/android/android_native_buffer.cpp' |
42 | --- src/common/graphics/android/android_native_buffer.cpp 2015-06-17 05:20:42 +0000 |
43 | +++ src/common/graphics/android/android_native_buffer.cpp 2015-12-02 16:15:28 +0000 |
44 | @@ -17,14 +17,17 @@ |
45 | */ |
46 | |
47 | #include "mir/graphics/android/android_native_buffer.h" |
48 | +#include "mir/graphics/egl_sync_fence.h" |
49 | |
50 | namespace mga=mir::graphics::android; |
51 | |
52 | mga::AndroidNativeBuffer::AndroidNativeBuffer( |
53 | std::shared_ptr<ANativeWindowBuffer> const& anwb, |
54 | + std::shared_ptr<CommandStreamSync> const& cmdstream_sync, |
55 | std::shared_ptr<Fence> const& fence, |
56 | BufferAccess access) |
57 | - : fence(fence), |
58 | + : cmdstream_sync(cmdstream_sync), |
59 | + fence(fence), |
60 | access(access), |
61 | native_window_buffer(anwb) |
62 | { |
63 | @@ -58,3 +61,14 @@ |
64 | { |
65 | return fence->copy_native_handle(); |
66 | } |
67 | + |
68 | +void mga::AndroidNativeBuffer::lock_for_gpu() |
69 | +{ |
70 | + cmdstream_sync->raise(); |
71 | +} |
72 | + |
73 | +void mga::AndroidNativeBuffer::wait_for_unlock_by_gpu() |
74 | +{ |
75 | + using namespace std::chrono; |
76 | + cmdstream_sync->wait_for(duration_cast<nanoseconds>(seconds(2))); |
77 | +} |
78 | |
79 | === modified file 'src/gl/recently_used_cache.cpp' |
80 | --- src/gl/recently_used_cache.cpp 2015-10-06 02:30:52 +0000 |
81 | +++ src/gl/recently_used_cache.cpp 2015-12-02 16:15:28 +0000 |
82 | @@ -27,6 +27,7 @@ |
83 | namespace mg = mir::graphics; |
84 | namespace mgl = mir::gl; |
85 | namespace geom = mir::geometry; |
86 | +namespace mrgl = mir::renderer::gl; |
87 | |
88 | std::shared_ptr<mgl::Texture> mgl::RecentlyUsedCache::load(mg::Renderable const& renderable) |
89 | { |
90 | @@ -35,18 +36,18 @@ |
91 | auto& texture = textures[renderable.id()]; |
92 | texture.texture->bind(); |
93 | |
94 | + auto const texture_source = dynamic_cast<mrgl::TextureSource*>(buffer->native_buffer_base()); |
95 | + if (!texture_source) |
96 | + BOOST_THROW_EXCEPTION(std::logic_error("Buffer does not support GL rendering")); |
97 | + |
98 | if ((texture.last_bound_buffer != buffer_id) || (!texture.valid_binding)) |
99 | { |
100 | - auto const texture_source = |
101 | - dynamic_cast<mir::renderer::gl::TextureSource*>( |
102 | - buffer->native_buffer_base()); |
103 | - if (!texture_source) |
104 | - BOOST_THROW_EXCEPTION(std::logic_error("Buffer does not support GL rendering")); |
105 | - |
106 | - texture_source->gl_bind_to_texture(); |
107 | + texture_source->bind(); |
108 | texture.resource = buffer; |
109 | texture.last_bound_buffer = buffer_id; |
110 | } |
111 | + texture_source->secure_for_render(); |
112 | + |
113 | texture.valid_binding = true; |
114 | texture.used = true; |
115 | |
116 | |
117 | === modified file 'src/include/common/mir/graphics/android/android_native_buffer.h' |
118 | --- src/include/common/mir/graphics/android/android_native_buffer.h 2015-06-17 05:20:42 +0000 |
119 | +++ src/include/common/mir/graphics/android/android_native_buffer.h 2015-12-02 16:15:28 +0000 |
120 | @@ -27,6 +27,7 @@ |
121 | { |
122 | namespace graphics |
123 | { |
124 | +class CommandStreamSync; |
125 | namespace android |
126 | { |
127 | class Fence; |
128 | @@ -35,6 +36,7 @@ |
129 | { |
130 | AndroidNativeBuffer( |
131 | std::shared_ptr<ANativeWindowBuffer> const& handle, |
132 | + std::shared_ptr<CommandStreamSync> const& cmdstream_sync, |
133 | std::shared_ptr<Fence> const& fence, |
134 | BufferAccess fence_access); |
135 | |
136 | @@ -45,7 +47,11 @@ |
137 | void ensure_available_for(BufferAccess); |
138 | void update_usage(NativeFence& merge_fd, BufferAccess); |
139 | |
140 | + void lock_for_gpu(); |
141 | + void wait_for_unlock_by_gpu(); |
142 | + |
143 | private: |
144 | + std::shared_ptr<CommandStreamSync> cmdstream_sync; |
145 | std::shared_ptr<Fence> fence; |
146 | BufferAccess access; |
147 | std::shared_ptr<ANativeWindowBuffer> native_window_buffer; |
148 | |
149 | === modified file 'src/include/common/mir/graphics/android/native_buffer.h' |
150 | --- src/include/common/mir/graphics/android/native_buffer.h 2015-06-17 05:20:42 +0000 |
151 | +++ src/include/common/mir/graphics/android/native_buffer.h 2015-12-02 16:15:28 +0000 |
152 | @@ -53,6 +53,9 @@ |
153 | virtual void ensure_available_for(android::BufferAccess intent) = 0; |
154 | virtual void update_usage(android::NativeFence& fence, android::BufferAccess current_usage) = 0; |
155 | |
156 | + virtual void lock_for_gpu() = 0; |
157 | + virtual void wait_for_unlock_by_gpu() = 0; |
158 | + |
159 | protected: |
160 | NativeBuffer() = default; |
161 | NativeBuffer(NativeBuffer const&) = delete; |
162 | |
163 | === modified file 'src/platform/symbols.map' |
164 | --- src/platform/symbols.map 2015-11-04 14:22:48 +0000 |
165 | +++ src/platform/symbols.map 2015-12-02 16:15:28 +0000 |
166 | @@ -219,6 +219,7 @@ |
167 | vtable?for?mir::graphics::EventHandlerRegister; |
168 | vtable?for?mir::graphics::GLConfig; |
169 | vtable?for?mir::graphics::GLContext; |
170 | + vtable?for?mir::graphics::NullCommandSync; |
171 | vtable?for?mir::graphics::GraphicBufferAllocator; |
172 | vtable?for?mir::graphics::Platform; |
173 | vtable?for?mir::graphics::PlatformIpcOperations; |
174 | @@ -237,6 +238,19 @@ |
175 | mir::graphics::blue_channel_depth*; |
176 | mir::graphics::contains_alpha*; |
177 | mir::graphics::EGLExtensions::EGLExtensions*; |
178 | + mir::graphics::EGLSyncExtensions::EGLSyncExtensions*; |
179 | + mir::graphics::CommandStreamSync::?CommandStreamSync*; |
180 | + mir::graphics::CommandStreamSync::CommandStreamSync*; |
181 | + mir::graphics::CommandStreamSync::CommandStreamSync*; |
182 | + mir::graphics::CommandStreamSync::operator*; |
183 | + mir::graphics::NullCommandSync::?NullCommandSync*; |
184 | + mir::graphics::NullCommandSync::NullCommandSync*; |
185 | + mir::graphics::NullCommandSync::NullCommandSync*; |
186 | + mir::graphics::NullCommandSync::operator*; |
187 | + mir::graphics::EGLSyncFence::?EGLSyncFence*; |
188 | + mir::graphics::EGLSyncFence::EGLSyncFence*; |
189 | + mir::graphics::EGLSyncFence::EGLSyncFence*; |
190 | + mir::graphics::EGLSyncFence::operator*; |
191 | mir::graphics::EGLContextStore::?EGLContextStore*; |
192 | mir::graphics::EGLContextStore::EGLContextStore*; |
193 | mir::graphics::EGLContextStore::EGLContextStore*; |
194 | |
195 | === modified file 'src/platforms/android/client/CMakeLists.txt' |
196 | --- src/platforms/android/client/CMakeLists.txt 2015-11-04 07:43:28 +0000 |
197 | +++ src/platforms/android/client/CMakeLists.txt 2015-12-02 16:15:28 +0000 |
198 | @@ -1,6 +1,7 @@ |
199 | include_directories(${client_common_include_dirs}) |
200 | include_directories(SYSTEM ${LIBHARDWARE_INCLUDE_DIRS}) |
201 | include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/3rd_party/android-deps) |
202 | +include_directories(${CMAKE_SOURCE_DIR}/include/platform) |
203 | |
204 | add_definitions(-DANDROID) |
205 | |
206 | @@ -35,6 +36,7 @@ |
207 | mirclient |
208 | client_platform_common |
209 | mirsharedandroid-static |
210 | + mirplatform |
211 | ${LIBHARDWARE_LIBRARIES} |
212 | ) |
213 | |
214 | |
215 | === modified file 'src/platforms/android/client/gralloc_registrar.cpp' |
216 | --- src/platforms/android/client/gralloc_registrar.cpp 2015-06-18 14:33:10 +0000 |
217 | +++ src/platforms/android/client/gralloc_registrar.cpp 2015-12-02 16:15:28 +0000 |
218 | @@ -18,6 +18,7 @@ |
219 | |
220 | #include "mir/graphics/android/android_native_buffer.h" |
221 | #include "mir/graphics/android/sync_fence.h" |
222 | +#include "mir/graphics/egl_sync_fence.h" |
223 | #include "gralloc_registrar.h" |
224 | #include "mir/client_buffer.h" |
225 | |
226 | @@ -82,7 +83,8 @@ |
227 | anwb->usage = GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER; |
228 | anwb->handle = handle.get(); |
229 | |
230 | - return std::make_shared<mga::AndroidNativeBuffer>(anwb, fence, mga::BufferAccess::read); |
231 | + auto sync = std::make_shared<mg::NullCommandSync>(); //no need for eglsync client side |
232 | + return std::make_shared<mga::AndroidNativeBuffer>(anwb, sync, fence, mga::BufferAccess::read); |
233 | } |
234 | } |
235 | std::shared_ptr<mg::NativeBuffer> mcla::GrallocRegistrar::register_buffer( |
236 | |
237 | === modified file 'src/platforms/android/server/CMakeLists.txt' |
238 | --- src/platforms/android/server/CMakeLists.txt 2015-11-04 07:43:28 +0000 |
239 | +++ src/platforms/android/server/CMakeLists.txt 2015-12-02 16:15:28 +0000 |
240 | @@ -43,6 +43,7 @@ |
241 | hwc_fallback_gl_renderer.cpp |
242 | ipc_operations.cpp |
243 | hwc_blanking_control.cpp |
244 | + egl_sync_factory.cpp |
245 | ) |
246 | |
247 | add_library(mirplatformgraphicsandroid SHARED |
248 | |
249 | === modified file 'src/platforms/android/server/android_alloc_adaptor.cpp' |
250 | --- src/platforms/android/server/android_alloc_adaptor.cpp 2015-08-07 15:55:22 +0000 |
251 | +++ src/platforms/android/server/android_alloc_adaptor.cpp 2015-12-02 16:15:28 +0000 |
252 | @@ -20,7 +20,9 @@ |
253 | #include "mir/graphics/android/android_native_buffer.h" |
254 | #include "mir/graphics/android/sync_fence.h" |
255 | #include "mir/graphics/android/android_format_conversion-inl.h" |
256 | +#include "mir/graphics/egl_sync_fence.h" |
257 | #include "android_alloc_adaptor.h" |
258 | +#include "cmdstream_sync_factory.h" |
259 | #include "device_quirks.h" |
260 | |
261 | #include <boost/throw_exception.hpp> |
262 | @@ -48,10 +50,13 @@ |
263 | }; |
264 | } |
265 | |
266 | -mga::AndroidAllocAdaptor::AndroidAllocAdaptor(std::shared_ptr<struct alloc_device_t> const& alloc_device, |
267 | - std::shared_ptr<DeviceQuirks> const& quirks) |
268 | - : alloc_dev(alloc_device), |
269 | - quirks(quirks) |
270 | +mga::AndroidAllocAdaptor::AndroidAllocAdaptor( |
271 | + std::shared_ptr<struct alloc_device_t> const& alloc_device, |
272 | + std::shared_ptr<CommandStreamSyncFactory> const& sync_factory, |
273 | + std::shared_ptr<DeviceQuirks> const& quirks) : |
274 | + alloc_dev(alloc_device), |
275 | + sync_factory(sync_factory), |
276 | + quirks(quirks) |
277 | { |
278 | } |
279 | |
280 | @@ -94,7 +99,9 @@ |
281 | anwb->format = format; |
282 | anwb->usage = usage_flag; |
283 | |
284 | - return std::make_shared<mga::AndroidNativeBuffer>(anwb, fence, mga::BufferAccess::read); |
285 | + return std::make_shared<mga::AndroidNativeBuffer>(anwb, |
286 | + sync_factory->create_command_stream_sync(), |
287 | + fence, mga::BufferAccess::read); |
288 | } |
289 | |
290 | int mga::AndroidAllocAdaptor::convert_to_android_usage(BufferUsage usage) |
291 | |
292 | === modified file 'src/platforms/android/server/android_alloc_adaptor.h' |
293 | --- src/platforms/android/server/android_alloc_adaptor.h 2015-06-24 11:33:02 +0000 |
294 | +++ src/platforms/android/server/android_alloc_adaptor.h 2015-12-02 16:15:28 +0000 |
295 | @@ -31,12 +31,15 @@ |
296 | namespace android |
297 | { |
298 | class DeviceQuirks; |
299 | +class CommandStreamSyncFactory; |
300 | |
301 | class AndroidAllocAdaptor : public GraphicAllocAdaptor |
302 | { |
303 | public: |
304 | - explicit AndroidAllocAdaptor(std::shared_ptr<struct alloc_device_t> const& alloc_device, |
305 | - std::shared_ptr<DeviceQuirks> const& quirks); |
306 | + explicit AndroidAllocAdaptor( |
307 | + std::shared_ptr<struct alloc_device_t> const& alloc_device, |
308 | + std::shared_ptr<CommandStreamSyncFactory> const& cmdstream_sync_factory, |
309 | + std::shared_ptr<DeviceQuirks> const& quirks); |
310 | std::shared_ptr<NativeBuffer> alloc_buffer(geometry::Size, |
311 | MirPixelFormat, BufferUsage usage); |
312 | |
313 | @@ -44,6 +47,7 @@ |
314 | |
315 | private: |
316 | std::shared_ptr<struct alloc_device_t> alloc_dev; |
317 | + std::shared_ptr<CommandStreamSyncFactory> const sync_factory; |
318 | std::shared_ptr<DeviceQuirks> const quirks; |
319 | int convert_to_android_usage(BufferUsage usage); |
320 | }; |
321 | |
322 | === modified file 'src/platforms/android/server/android_buffer_allocator.cpp' |
323 | --- src/platforms/android/server/android_buffer_allocator.cpp 2015-11-25 12:59:13 +0000 |
324 | +++ src/platforms/android/server/android_buffer_allocator.cpp 2015-12-02 16:15:28 +0000 |
325 | @@ -19,12 +19,14 @@ |
326 | |
327 | #include "mir/graphics/platform.h" |
328 | #include "mir/graphics/egl_extensions.h" |
329 | +#include "mir/graphics/egl_sync_fence.h" |
330 | #include "mir/graphics/buffer_properties.h" |
331 | #include "mir/graphics/android/sync_fence.h" |
332 | #include "mir/graphics/android/android_native_buffer.h" |
333 | #include "android_graphic_buffer_allocator.h" |
334 | #include "android_alloc_adaptor.h" |
335 | #include "buffer.h" |
336 | +#include "cmdstream_sync_factory.h" |
337 | #include "device_quirks.h" |
338 | |
339 | #include <boost/throw_exception.hpp> |
340 | @@ -50,8 +52,11 @@ |
341 | |
342 | } |
343 | |
344 | -mga::AndroidGraphicBufferAllocator::AndroidGraphicBufferAllocator(std::shared_ptr<DeviceQuirks> const& quirks) |
345 | - : egl_extensions(std::make_shared<mg::EGLExtensions>()) |
346 | +mga::AndroidGraphicBufferAllocator::AndroidGraphicBufferAllocator( |
347 | + std::shared_ptr<CommandStreamSyncFactory> const& cmdstream_sync_factory, |
348 | + std::shared_ptr<DeviceQuirks> const& quirks) |
349 | + : egl_extensions(std::make_shared<mg::EGLExtensions>()), |
350 | + cmdstream_sync_factory(cmdstream_sync_factory) |
351 | { |
352 | int err; |
353 | |
354 | @@ -70,7 +75,7 @@ |
355 | std::shared_ptr<struct alloc_device_t> alloc_dev_ptr( |
356 | alloc_dev, |
357 | quirks->gralloc_cannot_be_closed_safely() ? null_alloc_dev_deleter : alloc_dev_deleter); |
358 | - alloc_device = std::shared_ptr<mga::GraphicAllocAdaptor>(new AndroidAllocAdaptor(alloc_dev_ptr, quirks)); |
359 | + alloc_device = std::shared_ptr<mga::GraphicAllocAdaptor>(new AndroidAllocAdaptor(alloc_dev_ptr, cmdstream_sync_factory, quirks)); |
360 | } |
361 | |
362 | std::shared_ptr<mg::Buffer> mga::AndroidGraphicBufferAllocator::alloc_buffer( |
363 | @@ -89,9 +94,10 @@ |
364 | [](ANativeWindowBuffer* buffer){ buffer->common.decRef(&buffer->common); }); |
365 | anwb->common.incRef(&anwb->common); |
366 | |
367 | + //TODO: we should have an android platform function for accessing the fence. |
368 | auto native_handle = std::make_shared<mga::AndroidNativeBuffer>( |
369 | native_window_buffer, |
370 | - //TODO: we should have an android platform function for accessing the fence. |
371 | + cmdstream_sync_factory->create_command_stream_sync(), |
372 | std::make_shared<mga::SyncFence>(std::make_shared<mga::RealSyncFileOps>(), mir::Fd()), |
373 | mga::BufferAccess::read); |
374 | return std::make_unique<Buffer>( |
375 | |
376 | === modified file 'src/platforms/android/server/android_graphic_buffer_allocator.h' |
377 | --- src/platforms/android/server/android_graphic_buffer_allocator.h 2015-06-24 11:33:02 +0000 |
378 | +++ src/platforms/android/server/android_graphic_buffer_allocator.h 2015-12-02 16:15:28 +0000 |
379 | @@ -39,11 +39,14 @@ |
380 | |
381 | class GraphicAllocAdaptor; |
382 | class DeviceQuirks; |
383 | +class CommandStreamSyncFactory; |
384 | |
385 | class AndroidGraphicBufferAllocator: public GraphicBufferAllocator, public graphics::GraphicBufferAllocator |
386 | { |
387 | public: |
388 | - AndroidGraphicBufferAllocator(std::shared_ptr<DeviceQuirks> const& quirks); |
389 | + AndroidGraphicBufferAllocator( |
390 | + std::shared_ptr<CommandStreamSyncFactory> const& cmdstream_sync_factory, |
391 | + std::shared_ptr<DeviceQuirks> const& quirks); |
392 | |
393 | std::shared_ptr<graphics::Buffer> alloc_buffer( |
394 | graphics::BufferProperties const& buffer_properties) override; |
395 | @@ -61,6 +64,7 @@ |
396 | const hw_module_t *hw_module; |
397 | std::shared_ptr<GraphicAllocAdaptor> alloc_device; |
398 | std::shared_ptr<EGLExtensions> const egl_extensions; |
399 | + std::shared_ptr<CommandStreamSyncFactory> const cmdstream_sync_factory; |
400 | }; |
401 | |
402 | } |
403 | |
404 | === modified file 'src/platforms/android/server/buffer.cpp' |
405 | --- src/platforms/android/server/buffer.cpp 2015-08-27 13:41:02 +0000 |
406 | +++ src/platforms/android/server/buffer.cpp 2015-12-02 16:15:28 +0000 |
407 | @@ -74,6 +74,18 @@ |
408 | void mga::Buffer::gl_bind_to_texture() |
409 | { |
410 | std::unique_lock<std::mutex> lk(content_lock); |
411 | + bind(lk); |
412 | + secure_for_render(lk); |
413 | +} |
414 | + |
415 | +void mga::Buffer::bind() |
416 | +{ |
417 | + std::unique_lock<std::mutex> lk(content_lock); |
418 | + bind(lk); |
419 | +} |
420 | + |
421 | +void mga::Buffer::bind(std::unique_lock<std::mutex> const&) |
422 | +{ |
423 | native_buffer->ensure_available_for(mga::BufferAccess::read); |
424 | |
425 | DispContextPair current |
426 | @@ -113,10 +125,6 @@ |
427 | } |
428 | |
429 | egl_extensions->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); |
430 | - |
431 | - //TODO: we should make use of the android egl fence extension here to update the fence. |
432 | - // if the extension is not available, we should pass out a token that the user |
433 | - // will have to keep until the completion of the gl draw |
434 | } |
435 | |
436 | std::shared_ptr<mg::NativeBuffer> mga::Buffer::native_buffer_handle() const |
437 | @@ -196,3 +204,14 @@ |
438 | { |
439 | return this; |
440 | } |
441 | + |
442 | +void mga::Buffer::secure_for_render() |
443 | +{ |
444 | + std::unique_lock<std::mutex> lk(content_lock); |
445 | + secure_for_render(lk); |
446 | +} |
447 | + |
448 | +void mga::Buffer::secure_for_render(std::unique_lock<std::mutex> const&) |
449 | +{ |
450 | + native_buffer->lock_for_gpu(); |
451 | +} |
452 | |
453 | === modified file 'src/platforms/android/server/buffer.h' |
454 | --- src/platforms/android/server/buffer.h 2015-09-04 06:46:36 +0000 |
455 | +++ src/platforms/android/server/buffer.h 2015-12-02 16:15:28 +0000 |
456 | @@ -56,6 +56,10 @@ |
457 | geometry::Stride stride() const override; |
458 | MirPixelFormat pixel_format() const override; |
459 | void gl_bind_to_texture() override; |
460 | + void bind() override; |
461 | + void secure_for_render() override; |
462 | + |
463 | + |
464 | //note, you will get the native representation of an android buffer, including |
465 | //the fences associated with the buffer. You must close these fences |
466 | std::shared_ptr<NativeBuffer> native_buffer_handle() const override; |
467 | @@ -66,6 +70,8 @@ |
468 | NativeBufferBase* native_buffer_base() override; |
469 | |
470 | private: |
471 | + void bind(std::unique_lock<std::mutex> const&); |
472 | + void secure_for_render(std::unique_lock<std::mutex> const&); |
473 | gralloc_module_t const* hw_module; |
474 | |
475 | typedef std::pair<EGLDisplay, EGLContext> DispContextPair; |
476 | |
477 | === added file 'src/platforms/android/server/cmdstream_sync_factory.h' |
478 | --- src/platforms/android/server/cmdstream_sync_factory.h 1970-01-01 00:00:00 +0000 |
479 | +++ src/platforms/android/server/cmdstream_sync_factory.h 2015-12-02 16:15:28 +0000 |
480 | @@ -0,0 +1,48 @@ |
481 | +/* |
482 | + * Copyright © 2015 Canonical Ltd. |
483 | + * |
484 | + * This program is free software: you can redistribute it and/or modify it |
485 | + * under the terms of the GNU Lesser General Public License version 3, |
486 | + * as published by the Free Software Foundation. |
487 | + * |
488 | + * This program is distributed in the hope that it will be useful, |
489 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
490 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
491 | + * GNU Lesser General Public License for more details. |
492 | + * |
493 | + * You should have received a copy of the GNU Lesser General Public License |
494 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
495 | + * |
496 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
497 | + */ |
498 | + |
499 | +#ifndef MIR_GRAPHICS_ANDROID_CMDSTREAM_SYNC_FACTORY_H_ |
500 | +#define MIR_GRAPHICS_ANDROID_CMDSTREAM_SYNC_FACTORY_H_ |
501 | + |
502 | +#include <memory> |
503 | +namespace mir |
504 | +{ |
505 | +namespace graphics |
506 | +{ |
507 | +class CommandStreamSync; |
508 | +namespace android |
509 | +{ |
510 | +class CommandStreamSyncFactory |
511 | +{ |
512 | +public: |
513 | + virtual ~CommandStreamSyncFactory() = default; |
514 | + virtual std::unique_ptr<CommandStreamSync> create_command_stream_sync() = 0; |
515 | +protected: |
516 | + CommandStreamSyncFactory() = default; |
517 | + CommandStreamSyncFactory(CommandStreamSyncFactory const&) = delete; |
518 | + CommandStreamSyncFactory& operator=(CommandStreamSyncFactory const&) = delete; |
519 | +}; |
520 | + |
521 | +class EGLSyncFactory : public CommandStreamSyncFactory |
522 | +{ |
523 | + std::unique_ptr<CommandStreamSync> create_command_stream_sync() override; |
524 | +}; |
525 | +} |
526 | +} |
527 | +} |
528 | +#endif /* MIR_GRAPHICS_ANDROID_CMDSTREAM_SYNC_FACTORY_H_ */ |
529 | |
530 | === modified file 'src/platforms/android/server/display_component_factory.h' |
531 | --- src/platforms/android/server/display_component_factory.h 2015-06-17 05:20:42 +0000 |
532 | +++ src/platforms/android/server/display_component_factory.h 2015-12-02 16:15:28 +0000 |
533 | @@ -19,6 +19,7 @@ |
534 | #ifndef MIR_GRAPHICS_ANDROID_DISPLAY_COMPONENT_FACTORY_H_ |
535 | #define MIR_GRAPHICS_ANDROID_DISPLAY_COMPONENT_FACTORY_H_ |
536 | |
537 | +#include "mir/graphics/egl_sync_fence.h" |
538 | #include "display_device.h" |
539 | #include "framebuffer_bundle.h" |
540 | #include <memory> |
541 | @@ -28,6 +29,7 @@ |
542 | namespace graphics |
543 | { |
544 | class DisplayConfigurationOutput; |
545 | +class CommandStreamSync; |
546 | namespace android |
547 | { |
548 | class HwcConfiguration; |
549 | |
550 | === added file 'src/platforms/android/server/egl_sync_factory.cpp' |
551 | --- src/platforms/android/server/egl_sync_factory.cpp 1970-01-01 00:00:00 +0000 |
552 | +++ src/platforms/android/server/egl_sync_factory.cpp 2015-12-02 16:15:28 +0000 |
553 | @@ -0,0 +1,34 @@ |
554 | +/* |
555 | + * Copyright © 2015 Canonical Ltd. |
556 | + * |
557 | + * This program is free software: you can redistribute it and/or modify it |
558 | + * under the terms of the GNU Lesser General Public License version 3, |
559 | + * as published by the Free Software Foundation. |
560 | + * |
561 | + * This program is distributed in the hope that it will be useful, |
562 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
563 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
564 | + * GNU Lesser General Public License for more details. |
565 | + * |
566 | + * You should have received a copy of the GNU Lesser General Public License |
567 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
568 | + * |
569 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
570 | + */ |
571 | + |
572 | +#include "cmdstream_sync_factory.h" |
573 | +#include "mir/graphics/egl_sync_fence.h" |
574 | +namespace mg = mir::graphics; |
575 | +namespace mga = mir::graphics::android; |
576 | + |
577 | +std::unique_ptr<mg::CommandStreamSync> mga::EGLSyncFactory::create_command_stream_sync() |
578 | +{ |
579 | + try |
580 | + { |
581 | + return std::make_unique<EGLSyncFence>(std::make_shared<mg::EGLSyncExtensions>()); |
582 | + } |
583 | + catch (std::runtime_error&) |
584 | + { |
585 | + return std::make_unique<NullCommandSync>(); |
586 | + } |
587 | +} |
588 | |
589 | === modified file 'src/platforms/android/server/hal_component_factory.cpp' |
590 | --- src/platforms/android/server/hal_component_factory.cpp 2015-06-24 11:33:02 +0000 |
591 | +++ src/platforms/android/server/hal_component_factory.cpp 2015-12-02 16:15:28 +0000 |
592 | @@ -65,6 +65,21 @@ |
593 | } |
594 | } |
595 | |
596 | +std::unique_ptr<mg::CommandStreamSync> mga::HalComponentFactory::create_command_stream_sync() |
597 | +{ |
598 | + if (hwc_version == mga::HwcVersion::hwc10) |
599 | + return std::make_unique<NullCommandSync>(); |
600 | + |
601 | + try |
602 | + { |
603 | + return std::make_unique<EGLSyncFence>(std::make_shared<mg::EGLSyncExtensions>()); |
604 | + } |
605 | + catch (std::runtime_error&) |
606 | + { |
607 | + return std::make_unique<NullCommandSync>(); |
608 | + } |
609 | +} |
610 | + |
611 | std::unique_ptr<mga::FramebufferBundle> mga::HalComponentFactory::create_framebuffers(mg::DisplayConfigurationOutput const& config) |
612 | { |
613 | return std::unique_ptr<mga::FramebufferBundle>(new mga::Framebuffers( |
614 | |
615 | === modified file 'src/platforms/android/server/hal_component_factory.h' |
616 | --- src/platforms/android/server/hal_component_factory.h 2015-06-24 11:33:02 +0000 |
617 | +++ src/platforms/android/server/hal_component_factory.h 2015-12-02 16:15:28 +0000 |
618 | @@ -19,6 +19,7 @@ |
619 | #ifndef MIR_GRAPHICS_ANDROID_HAL_COMPONENT_FACTORY_H_ |
620 | #define MIR_GRAPHICS_ANDROID_HAL_COMPONENT_FACTORY_H_ |
621 | |
622 | +#include "cmdstream_sync_factory.h" |
623 | #include "display_component_factory.h" |
624 | #include "display_resource_factory.h" |
625 | |
626 | @@ -39,7 +40,7 @@ |
627 | |
628 | //NOTE: this should be the only class that inspects the HWC version and assembles |
629 | //the components accordingly |
630 | -class HalComponentFactory : public DisplayComponentFactory |
631 | +class HalComponentFactory : public DisplayComponentFactory, public CommandStreamSyncFactory |
632 | { |
633 | public: |
634 | HalComponentFactory( |
635 | @@ -48,6 +49,7 @@ |
636 | std::shared_ptr<HwcReport> const& hwc_report, |
637 | std::shared_ptr<DeviceQuirks> const& quirks); |
638 | |
639 | + std::unique_ptr<CommandStreamSync> create_command_stream_sync() override; |
640 | std::unique_ptr<FramebufferBundle> create_framebuffers(DisplayConfigurationOutput const&) override; |
641 | std::unique_ptr<DisplayDevice> create_display_device() override; |
642 | std::unique_ptr<HwcConfiguration> create_hwc_configuration() override; |
643 | |
644 | === modified file 'src/platforms/android/server/ipc_operations.cpp' |
645 | --- src/platforms/android/server/ipc_operations.cpp 2015-06-18 14:33:10 +0000 |
646 | +++ src/platforms/android/server/ipc_operations.cpp 2015-12-02 16:15:28 +0000 |
647 | @@ -32,6 +32,7 @@ |
648 | { |
649 | auto native_buffer = buffer.native_buffer_handle(); |
650 | |
651 | + native_buffer->wait_for_unlock_by_gpu(); |
652 | mir::Fd fence_fd(native_buffer->copy_fence()); |
653 | if (fence_fd != mir::Fd::invalid) |
654 | { |
655 | |
656 | === modified file 'src/platforms/android/server/platform.cpp' |
657 | --- src/platforms/android/server/platform.cpp 2015-11-24 12:00:40 +0000 |
658 | +++ src/platforms/android/server/platform.cpp 2015-12-02 16:15:28 +0000 |
659 | @@ -85,11 +85,13 @@ |
660 | mga::Platform::Platform( |
661 | std::shared_ptr<graphics::GraphicBufferAllocator> const& buffer_allocator, |
662 | std::shared_ptr<mga::DisplayComponentFactory> const& display_buffer_builder, |
663 | + std::shared_ptr<CommandStreamSyncFactory> const& sync_factory, |
664 | std::shared_ptr<mg::DisplayReport> const& display_report, |
665 | mga::OverlayOptimization overlay_option, |
666 | std::shared_ptr<mga::DeviceQuirks> const& quirks) : |
667 | buffer_allocator(buffer_allocator), |
668 | display_buffer_builder(display_buffer_builder), |
669 | + sync_factory(sync_factory), |
670 | display_report(display_report), |
671 | quirks(quirks), |
672 | overlay_option(overlay_option) |
673 | @@ -153,10 +155,13 @@ |
674 | auto overlay_option = should_use_overlay_optimization(*options); |
675 | hwc_report->report_overlay_optimization(overlay_option); |
676 | auto display_resource_factory = std::make_shared<mga::ResourceFactory>(); |
677 | - auto buffer_allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(quirks); |
678 | + auto sync_factory = std::make_shared<mga::EGLSyncFactory>(); |
679 | + auto buffer_allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(sync_factory, quirks); |
680 | auto component_factory = std::make_shared<mga::HalComponentFactory>( |
681 | buffer_allocator, display_resource_factory, hwc_report, quirks); |
682 | - return mir::make_module_ptr<mga::Platform>(buffer_allocator, component_factory, display_report, overlay_option, quirks); |
683 | + |
684 | + return mir::make_module_ptr<mga::Platform>( |
685 | + buffer_allocator, component_factory, component_factory, display_report, overlay_option, quirks); |
686 | } |
687 | |
688 | mir::UniqueModulePtr<mg::Platform> create_guest_platform( |
689 | @@ -166,10 +171,11 @@ |
690 | mir::assert_entry_point_signature<mg::CreateGuestPlatform>(&create_guest_platform); |
691 | //TODO: actually allow disabling quirks for guest platform |
692 | auto quirks = std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{}); |
693 | + auto sync_factory = std::make_shared<mga::EGLSyncFactory>(); |
694 | //TODO: remove nullptr parameter once platform classes are sorted. |
695 | // mg::NativePlatform cannot create a display anyways, so it doesnt need a display builder |
696 | - auto const buffer_allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(quirks); |
697 | - return mir::make_module_ptr<mga::Platform>(buffer_allocator, nullptr, display_report, mga::OverlayOptimization::disabled, quirks); |
698 | + auto const buffer_allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(sync_factory, quirks); |
699 | + return mir::make_module_ptr<mga::Platform>(buffer_allocator, nullptr, sync_factory, display_report, mga::OverlayOptimization::disabled, quirks); |
700 | } |
701 | |
702 | void add_graphics_platform_options( |
703 | |
704 | === modified file 'src/platforms/android/server/platform.h' |
705 | --- src/platforms/android/server/platform.h 2015-11-24 12:00:40 +0000 |
706 | +++ src/platforms/android/server/platform.h 2015-12-02 16:15:28 +0000 |
707 | @@ -33,6 +33,7 @@ |
708 | class GraphicBufferAllocator; |
709 | class FramebufferFactory; |
710 | class DisplayComponentFactory; |
711 | +class CommandStreamSyncFactory; |
712 | |
713 | class Platform : public graphics::Platform |
714 | { |
715 | @@ -40,6 +41,7 @@ |
716 | Platform( |
717 | std::shared_ptr<graphics::GraphicBufferAllocator> const& buffer_allocator, |
718 | std::shared_ptr<DisplayComponentFactory> const& display_buffer_builder, |
719 | + std::shared_ptr<CommandStreamSyncFactory> const& sync_factory, |
720 | std::shared_ptr<DisplayReport> const& display_report, |
721 | OverlayOptimization overlay_option, |
722 | std::shared_ptr<DeviceQuirks> const& quirks); |
723 | @@ -55,6 +57,7 @@ |
724 | private: |
725 | std::shared_ptr<graphics::GraphicBufferAllocator> const buffer_allocator; |
726 | std::shared_ptr<DisplayComponentFactory> const display_buffer_builder; |
727 | + std::shared_ptr<CommandStreamSyncFactory> const sync_factory; |
728 | std::shared_ptr<DisplayReport> const display_report; |
729 | std::shared_ptr<PlatformIpcOperations> const ipc_operations; |
730 | std::shared_ptr<DeviceQuirks> const quirks; |
731 | |
732 | === modified file 'src/platforms/mesa/server/common/gbm_buffer.cpp' |
733 | --- src/platforms/mesa/server/common/gbm_buffer.cpp 2015-09-22 09:13:59 +0000 |
734 | +++ src/platforms/mesa/server/common/gbm_buffer.cpp 2015-12-02 16:15:28 +0000 |
735 | @@ -197,3 +197,12 @@ |
736 | { |
737 | return this; |
738 | } |
739 | + |
740 | +void mgm::GBMBuffer::secure_for_render() |
741 | +{ |
742 | +} |
743 | + |
744 | +void mgm::GBMBuffer::bind() |
745 | +{ |
746 | + gl_bind_to_texture(); |
747 | +} |
748 | |
749 | === modified file 'src/platforms/mesa/server/common/gbm_buffer.h' |
750 | --- src/platforms/mesa/server/common/gbm_buffer.h 2015-09-04 06:46:36 +0000 |
751 | +++ src/platforms/mesa/server/common/gbm_buffer.h 2015-12-02 16:15:28 +0000 |
752 | @@ -67,6 +67,8 @@ |
753 | virtual std::shared_ptr<MirNativeBuffer> native_buffer_handle() const override; |
754 | |
755 | virtual void gl_bind_to_texture() override; |
756 | + virtual void bind() override; |
757 | + virtual void secure_for_render() override; |
758 | |
759 | void write(unsigned char const* pixels, size_t size) override; |
760 | void read(std::function<void(unsigned char const*)> const& do_with_pixels) override; |
761 | |
762 | === modified file 'src/platforms/mesa/server/common/shm_buffer.cpp' |
763 | --- src/platforms/mesa/server/common/shm_buffer.cpp 2015-08-27 13:41:02 +0000 |
764 | +++ src/platforms/mesa/server/common/shm_buffer.cpp 2015-12-02 16:15:28 +0000 |
765 | @@ -176,3 +176,12 @@ |
766 | { |
767 | return this; |
768 | } |
769 | + |
770 | +void mgm::ShmBuffer::bind() |
771 | +{ |
772 | + gl_bind_to_texture(); |
773 | +} |
774 | + |
775 | +void mgm::ShmBuffer::secure_for_render() |
776 | +{ |
777 | +} |
778 | |
779 | === modified file 'src/platforms/mesa/server/common/shm_buffer.h' |
780 | --- src/platforms/mesa/server/common/shm_buffer.h 2015-09-04 06:46:36 +0000 |
781 | +++ src/platforms/mesa/server/common/shm_buffer.h 2015-12-02 16:15:28 +0000 |
782 | @@ -51,6 +51,8 @@ |
783 | MirPixelFormat pixel_format() const override; |
784 | std::shared_ptr<MirNativeBuffer> native_buffer_handle() const override; |
785 | void gl_bind_to_texture() override; |
786 | + void bind() override; |
787 | + void secure_for_render() override; |
788 | void write(unsigned char const* data, size_t size) override; |
789 | void read(std::function<void(unsigned char const*)> const& do_with_pixels) override; |
790 | NativeBufferBase* native_buffer_base() override; |
791 | |
792 | === modified file 'tests/include/mir/test/doubles/mock_android_native_buffer.h' |
793 | --- tests/include/mir/test/doubles/mock_android_native_buffer.h 2015-06-17 05:20:42 +0000 |
794 | +++ tests/include/mir/test/doubles/mock_android_native_buffer.h 2015-12-02 16:15:28 +0000 |
795 | @@ -57,6 +57,8 @@ |
796 | MOCK_METHOD1(ensure_available_for, void(graphics::android::BufferAccess)); |
797 | MOCK_METHOD2(update_usage, void(graphics::android::NativeFence&, graphics::android::BufferAccess)); |
798 | |
799 | + MOCK_METHOD0(lock_for_gpu, void()); |
800 | + MOCK_METHOD0(wait_for_unlock_by_gpu, void()); |
801 | ANativeWindowBuffer stub_anwb; |
802 | native_handle_t native_handle; |
803 | }; |
804 | |
805 | === modified file 'tests/include/mir/test/doubles/mock_buffer.h' |
806 | --- tests/include/mir/test/doubles/mock_buffer.h 2015-09-01 10:49:48 +0000 |
807 | +++ tests/include/mir/test/doubles/mock_buffer.h 2015-12-02 16:15:28 +0000 |
808 | @@ -72,6 +72,7 @@ |
809 | MOCK_METHOD2(write, void(unsigned char const*, size_t)); |
810 | MOCK_METHOD1(read, void(std::function<void(unsigned char const*)> const&)); |
811 | MOCK_METHOD0(native_buffer_base, graphics::NativeBufferBase*()); |
812 | + MOCK_METHOD0(used_as_texture, void()); |
813 | }; |
814 | |
815 | } |
816 | |
817 | === modified file 'tests/include/mir/test/doubles/mock_gl_buffer.h' |
818 | --- tests/include/mir/test/doubles/mock_gl_buffer.h 2015-09-04 06:46:36 +0000 |
819 | +++ tests/include/mir/test/doubles/mock_gl_buffer.h 2015-12-02 16:15:28 +0000 |
820 | @@ -36,6 +36,8 @@ |
821 | using MockBuffer::MockBuffer; |
822 | |
823 | MOCK_METHOD0(gl_bind_to_texture, void()); |
824 | + MOCK_METHOD0(secure_for_render, void()); |
825 | + MOCK_METHOD0(bind, void()); |
826 | }; |
827 | |
828 | } |
829 | |
830 | === modified file 'tests/include/mir/test/doubles/stub_android_native_buffer.h' |
831 | --- tests/include/mir/test/doubles/stub_android_native_buffer.h 2015-05-29 17:53:49 +0000 |
832 | +++ tests/include/mir/test/doubles/stub_android_native_buffer.h 2015-12-02 16:15:28 +0000 |
833 | @@ -47,6 +47,9 @@ |
834 | void ensure_available_for(graphics::android::BufferAccess) {} |
835 | void update_usage(graphics::android::NativeFence&, graphics::android::BufferAccess) {} |
836 | |
837 | + void lock_for_gpu() {}; |
838 | + void wait_for_unlock_by_gpu() {}; |
839 | + |
840 | ANativeWindowBuffer stub_anwb; |
841 | native_handle_t native_handle; |
842 | }; |
843 | |
844 | === added file 'tests/include/mir/test/doubles/stub_cmdstream_sync_factory.h' |
845 | --- tests/include/mir/test/doubles/stub_cmdstream_sync_factory.h 1970-01-01 00:00:00 +0000 |
846 | +++ tests/include/mir/test/doubles/stub_cmdstream_sync_factory.h 2015-12-02 16:15:28 +0000 |
847 | @@ -0,0 +1,41 @@ |
848 | +/* |
849 | + * Copyright © 2015 Canonical Ltd. |
850 | + * |
851 | + * This program is free software: you can redistribute it and/or modify it |
852 | + * under the terms of the GNU General Public License version 3, |
853 | + * as published by the Free Software Foundation. |
854 | + * |
855 | + * This program is distributed in the hope that it will be useful, |
856 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
857 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
858 | + * GNU General Public License for more details. |
859 | + * |
860 | + * You should have received a copy of the GNU General Public License |
861 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
862 | + * |
863 | + * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
864 | + */ |
865 | + |
866 | +#ifndef MIR_TEST_DOUBLES_STUB_CMDSTREAM_SYNC_FACTORY_H_ |
867 | +#define MIR_TEST_DOUBLES_STUB_CMDSTREAM_SYNC_FACTORY_H_ |
868 | + |
869 | +#include "src/platforms/android/server/cmdstream_sync_factory.h" |
870 | + |
871 | +namespace mir |
872 | +{ |
873 | +namespace test |
874 | +{ |
875 | +namespace doubles |
876 | +{ |
877 | +struct StubCmdStreamSyncFactory : graphics::android::CommandStreamSyncFactory |
878 | +{ |
879 | + std::unique_ptr<graphics::CommandStreamSync> create_command_stream_sync() override |
880 | + { |
881 | + return std::make_unique<graphics::NullCommandSync>(); |
882 | + } |
883 | +}; |
884 | +} |
885 | +} |
886 | +} |
887 | + |
888 | +#endif /* MIR_TEST_DOUBLES_STUB_CMDSTREAM_SYNC_FACTORY_H_ */ |
889 | |
890 | === modified file 'tests/include/mir/test/doubles/stub_display_builder.h' |
891 | --- tests/include/mir/test/doubles/stub_display_builder.h 2015-11-18 15:03:00 +0000 |
892 | +++ tests/include/mir/test/doubles/stub_display_builder.h 2015-12-02 16:15:28 +0000 |
893 | @@ -126,6 +126,11 @@ |
894 | config = std::move(mock_config); |
895 | } |
896 | |
897 | + std::unique_ptr<graphics::CommandStreamSync> create_command_stream_sync() |
898 | + { |
899 | + return std::make_unique<graphics::NullCommandSync>(); |
900 | + } |
901 | + |
902 | geometry::Size sz; |
903 | std::unique_ptr<graphics::android::HwcConfiguration> config; |
904 | }; |
905 | |
906 | === modified file 'tests/include/mir/test/doubles/stub_gl_buffer.h' |
907 | --- tests/include/mir/test/doubles/stub_gl_buffer.h 2015-09-04 06:46:36 +0000 |
908 | +++ tests/include/mir/test/doubles/stub_gl_buffer.h 2015-12-02 16:15:28 +0000 |
909 | @@ -36,6 +36,8 @@ |
910 | using StubBuffer::StubBuffer; |
911 | |
912 | void gl_bind_to_texture() {} |
913 | + void bind() {} |
914 | + void secure_for_render() {} |
915 | }; |
916 | |
917 | } |
918 | |
919 | === modified file 'tests/integration-tests/graphics/mesa/test_buffer_integration.cpp' |
920 | --- tests/integration-tests/graphics/mesa/test_buffer_integration.cpp 2015-11-02 21:56:56 +0000 |
921 | +++ tests/integration-tests/graphics/mesa/test_buffer_integration.cpp 2015-12-02 16:15:28 +0000 |
922 | @@ -77,6 +77,9 @@ |
923 | } |
924 | } |
925 | |
926 | + void bind() override { gl_bind_to_texture(); } |
927 | + void secure_for_render() override {} |
928 | + |
929 | private: |
930 | std::thread::id creation_thread_id; |
931 | }; |
932 | |
933 | === modified file 'tests/unit-tests/gl/test_gl_texture_cache.cpp' |
934 | --- tests/unit-tests/gl/test_gl_texture_cache.cpp 2015-10-06 02:30:52 +0000 |
935 | +++ tests/unit-tests/gl/test_gl_texture_cache.cpp 2015-12-02 16:15:28 +0000 |
936 | @@ -17,7 +17,7 @@ |
937 | * Originally by: Daniel van Vugt <daniel.van.vugt@canonical.com> |
938 | */ |
939 | |
940 | -#include "mir/gl/recently_used_cache.h" |
941 | +#include "src/gl/recently_used_cache.h" |
942 | #include "mir/test/doubles/mock_gl_buffer.h" |
943 | #include "mir/test/doubles/mock_renderable.h" |
944 | #include "mir/test/doubles/mock_gl.h" |
945 | @@ -75,6 +75,7 @@ |
946 | EXPECT_CALL(mock_gl, glBindTexture(GL_TEXTURE_2D, stub_texture)); |
947 | EXPECT_CALL(*mock_buffer,gl_bind_to_texture()) |
948 | .Times(0); |
949 | + EXPECT_CALL(*mock_buffer, used_as_texture()); |
950 | |
951 | // Frame 3: Texture found in cache but refreshed with new buffer |
952 | EXPECT_CALL(*mock_buffer, id()) |
953 | @@ -92,6 +93,7 @@ |
954 | EXPECT_CALL(*mock_buffer, id()) |
955 | .WillOnce(Return(mg::BufferID(456))); |
956 | EXPECT_CALL(mock_gl, glBindTexture(GL_TEXTURE_2D, stub_texture)); |
957 | + EXPECT_CALL(*mock_buffer, used_as_texture()); |
958 | |
959 | EXPECT_CALL(mock_gl, glDeleteTextures(1, Pointee(stub_texture))); |
960 | |
961 | |
962 | === modified file 'tests/unit-tests/gl/test_program_factory.cpp' |
963 | --- tests/unit-tests/gl/test_program_factory.cpp 2015-10-06 02:30:52 +0000 |
964 | +++ tests/unit-tests/gl/test_program_factory.cpp 2015-12-02 16:15:28 +0000 |
965 | @@ -24,7 +24,7 @@ |
966 | #include <gtest/gtest.h> |
967 | #include <gmock/gmock.h> |
968 | #include <mir/geometry/rectangle.h> |
969 | -#include "src/gl/default_program_factory.h" |
970 | +#include "mir/gl/default_program_factory.h" |
971 | #include <mir/test/fake_shared.h> |
972 | #include <mir/test/doubles/mock_buffer.h> |
973 | #include <mir/test/doubles/mock_renderable.h> |
974 | |
975 | === modified file 'tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp' |
976 | --- tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp 2015-08-07 15:55:22 +0000 |
977 | +++ tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp 2015-12-02 16:15:28 +0000 |
978 | @@ -17,11 +17,13 @@ |
979 | */ |
980 | |
981 | #include "src/platforms/android/server/android_alloc_adaptor.h" |
982 | +#include "src/platforms/android/server/cmdstream_sync_factory.h" |
983 | #include "src/platforms/android/server/device_quirks.h" |
984 | #include "mir/graphics/android/native_buffer.h" |
985 | |
986 | #include "mir/test/doubles/mock_android_alloc_device.h" |
987 | #include "mir/test/doubles/mock_alloc_adaptor.h" |
988 | +#include "mir/test/doubles/mock_egl.h" |
989 | |
990 | #include <gtest/gtest.h> |
991 | #include <gmock/gmock.h> |
992 | @@ -32,7 +34,6 @@ |
993 | namespace geom = mir::geometry; |
994 | namespace mtd = mir::test::doubles; |
995 | |
996 | - |
997 | class AdaptorICSTest : public ::testing::Test |
998 | { |
999 | public: |
1000 | @@ -48,13 +49,15 @@ |
1001 | mock_alloc_device = std::make_shared<NiceMock<mtd::MockAllocDevice>>(); |
1002 | |
1003 | auto quirks = std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{}); |
1004 | - alloc_adaptor = std::make_shared<mga::AndroidAllocAdaptor>(mock_alloc_device, quirks); |
1005 | + alloc_adaptor = std::make_shared<mga::AndroidAllocAdaptor>(mock_alloc_device, sync_factory, quirks); |
1006 | |
1007 | pf = mir_pixel_format_abgr_8888; |
1008 | size = geom::Size{300, 200}; |
1009 | usage = mga::BufferUsage::use_hardware; |
1010 | } |
1011 | |
1012 | + mtd::MockEGL mock_egl; |
1013 | + std::shared_ptr<mga::CommandStreamSyncFactory> sync_factory{std::make_shared<mga::EGLSyncFactory>()}; |
1014 | std::shared_ptr<mtd::MockAllocDevice> mock_alloc_device; |
1015 | std::shared_ptr<mga::AndroidAllocAdaptor> alloc_adaptor; |
1016 | |
1017 | |
1018 | === modified file 'tests/unit-tests/graphics/android/test_android_buffer_allocator.cpp' |
1019 | --- tests/unit-tests/graphics/android/test_android_buffer_allocator.cpp 2015-08-07 15:55:22 +0000 |
1020 | +++ tests/unit-tests/graphics/android/test_android_buffer_allocator.cpp 2015-12-02 16:15:28 +0000 |
1021 | @@ -23,6 +23,8 @@ |
1022 | #include "mir/graphics/buffer.h" |
1023 | #include "mir/graphics/android/native_buffer.h" |
1024 | |
1025 | +#include "mir/test/doubles/stub_display_builder.h" |
1026 | +#include "mir/test/doubles/stub_cmdstream_sync_factory.h" |
1027 | #include "mir/test/doubles/mock_egl.h" |
1028 | |
1029 | #include <hardware/gralloc.h> |
1030 | @@ -43,7 +45,9 @@ |
1031 | |
1032 | testing::NiceMock<mtd::HardwareAccessMock> hw_access_mock; |
1033 | testing::NiceMock<mtd::MockEGL> mock_egl; |
1034 | - mga::AndroidGraphicBufferAllocator allocator{std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{})}; |
1035 | + mga::AndroidGraphicBufferAllocator allocator{ |
1036 | + std::make_shared<mtd::StubCmdStreamSyncFactory>(), |
1037 | + std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{})}; |
1038 | }; |
1039 | |
1040 | TEST_F(AndroidGraphicBufferAllocatorTest, allocator_accesses_gralloc_module) |
1041 | @@ -54,7 +58,7 @@ |
1042 | .Times(1); |
1043 | |
1044 | auto quirks = std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{}); |
1045 | - mga::AndroidGraphicBufferAllocator allocator{quirks}; |
1046 | + mga::AndroidGraphicBufferAllocator allocator{std::make_shared<mtd::StubCmdStreamSyncFactory>(), quirks}; |
1047 | } |
1048 | |
1049 | TEST_F(AndroidGraphicBufferAllocatorTest, supported_pixel_formats_contain_common_formats) |
1050 | |
1051 | === modified file 'tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp' |
1052 | --- tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp 2015-06-25 03:00:08 +0000 |
1053 | +++ tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp 2015-12-02 16:15:28 +0000 |
1054 | @@ -289,7 +289,7 @@ |
1055 | |
1056 | |
1057 | /* binding tests */ |
1058 | -TEST_F(AndroidBufferBinding, buffer_calls_binding_extension) |
1059 | +TEST_F(AndroidBufferBinding, buffer_calls_binding_extension_and_notes_gpu_usage) |
1060 | { |
1061 | using namespace testing; |
1062 | EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, _)) |
1063 | @@ -298,11 +298,23 @@ |
1064 | buffer.gl_bind_to_texture(); |
1065 | } |
1066 | |
1067 | +TEST_F(AndroidBufferBinding, notes_gpu_usage_when_explicity_told) |
1068 | +{ |
1069 | + using namespace testing; |
1070 | + EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, _)) |
1071 | + .Times(0); |
1072 | + EXPECT_CALL(*mock_native_buffer, lock_for_gpu()); |
1073 | + mga::Buffer buffer(gralloc, mock_native_buffer, extensions); |
1074 | + buffer.secure_for_render(); |
1075 | +} |
1076 | + |
1077 | TEST_F(AndroidBufferBinding, buffer_calls_binding_extension_every_time) |
1078 | { |
1079 | using namespace testing; |
1080 | EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, _)) |
1081 | .Times(Exactly(3)); |
1082 | + EXPECT_CALL(*mock_native_buffer, lock_for_gpu()) |
1083 | + .Times(Exactly(3)); |
1084 | |
1085 | mga::Buffer buffer(gralloc, mock_native_buffer, extensions); |
1086 | buffer.gl_bind_to_texture(); |
1087 | |
1088 | === modified file 'tests/unit-tests/graphics/android/test_display_hotplug.cpp' |
1089 | --- tests/unit-tests/graphics/android/test_display_hotplug.cpp 2015-10-06 02:30:52 +0000 |
1090 | +++ tests/unit-tests/graphics/android/test_display_hotplug.cpp 2015-12-02 16:15:28 +0000 |
1091 | @@ -103,6 +103,11 @@ |
1092 | new mga::LayerList(std::make_shared<mga::IntegerSourceCrop>(), {}, geom::Displacement{})); |
1093 | } |
1094 | |
1095 | + std::unique_ptr<mg::CommandStreamSync> create_command_stream_sync() |
1096 | + { |
1097 | + return nullptr; |
1098 | + } |
1099 | + |
1100 | StubHwcConfig stub_config; |
1101 | }; |
1102 | |
1103 | |
1104 | === modified file 'tests/unit-tests/graphics/android/test_native_buffer.cpp' |
1105 | --- tests/unit-tests/graphics/android/test_native_buffer.cpp 2015-06-25 03:00:08 +0000 |
1106 | +++ tests/unit-tests/graphics/android/test_native_buffer.cpp 2015-12-02 16:15:28 +0000 |
1107 | @@ -17,25 +17,41 @@ |
1108 | */ |
1109 | |
1110 | #include "mir/graphics/android/android_native_buffer.h" |
1111 | +#include "mir/graphics/egl_sync_fence.h" |
1112 | #include "mir/test/doubles/mock_fence.h" |
1113 | #include <memory> |
1114 | #include <gtest/gtest.h> |
1115 | |
1116 | namespace mtd=mir::test::doubles; |
1117 | namespace mga=mir::graphics::android; |
1118 | +using namespace testing; |
1119 | + |
1120 | +namespace |
1121 | +{ |
1122 | +struct MockCommandStreamSync : public mir::graphics::CommandStreamSync |
1123 | +{ |
1124 | + MOCK_METHOD0(raise, void()); |
1125 | + MOCK_METHOD0(reset, void()); |
1126 | + MOCK_METHOD1(wait_for, bool(std::chrono::nanoseconds)); |
1127 | +}; |
1128 | +} |
1129 | |
1130 | struct NativeBuffer : public testing::Test |
1131 | { |
1132 | NativeBuffer() : |
1133 | a_native_window_buffer(std::make_shared<ANativeWindowBuffer>()), |
1134 | mock_fence(std::make_shared<testing::NiceMock<mtd::MockFence>>()), |
1135 | - fake_fd{48484} |
1136 | + fake_fd{48484}, |
1137 | + timeout{std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::seconds(2))}, |
1138 | + mock_cmdstream_sync{std::make_shared<MockCommandStreamSync>()} |
1139 | { |
1140 | } |
1141 | |
1142 | std::shared_ptr<ANativeWindowBuffer> a_native_window_buffer; |
1143 | std::shared_ptr<mtd::MockFence> mock_fence; |
1144 | int fake_fd; |
1145 | + std::chrono::nanoseconds timeout; |
1146 | + std::shared_ptr<MockCommandStreamSync> mock_cmdstream_sync; |
1147 | }; |
1148 | |
1149 | TEST_F(NativeBuffer, extends_lifetime_when_driver_calls_external_refcount_hooks) |
1150 | @@ -88,7 +104,7 @@ |
1151 | { |
1152 | EXPECT_CALL(*mock_fence, wait()) |
1153 | .Times(0); |
1154 | - mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::read); |
1155 | + mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read); |
1156 | buffer.ensure_available_for(mga::BufferAccess::read); |
1157 | } |
1158 | |
1159 | @@ -96,7 +112,7 @@ |
1160 | { |
1161 | EXPECT_CALL(*mock_fence, wait()) |
1162 | .Times(1); |
1163 | - mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::write); |
1164 | + mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::write); |
1165 | buffer.ensure_available_for(mga::BufferAccess::read); |
1166 | } |
1167 | |
1168 | @@ -104,7 +120,7 @@ |
1169 | { |
1170 | EXPECT_CALL(*mock_fence, wait()) |
1171 | .Times(1); |
1172 | - mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::read); |
1173 | + mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read); |
1174 | buffer.ensure_available_for(mga::BufferAccess::write); |
1175 | } |
1176 | |
1177 | @@ -112,7 +128,7 @@ |
1178 | { |
1179 | EXPECT_CALL(*mock_fence, wait()) |
1180 | .Times(1); |
1181 | - mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::write); |
1182 | + mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::write); |
1183 | buffer.ensure_available_for(mga::BufferAccess::write); |
1184 | } |
1185 | |
1186 | @@ -120,7 +136,7 @@ |
1187 | { |
1188 | EXPECT_CALL(*mock_fence, merge_with(fake_fd)) |
1189 | .Times(1); |
1190 | - mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::read); |
1191 | + mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read); |
1192 | buffer.update_usage(fake_fd, mga::BufferAccess::write); |
1193 | } |
1194 | |
1195 | @@ -129,7 +145,7 @@ |
1196 | EXPECT_CALL(*mock_fence, wait()) |
1197 | .Times(3); |
1198 | |
1199 | - mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::read); |
1200 | + mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read); |
1201 | buffer.ensure_available_for(mga::BufferAccess::write); |
1202 | buffer.ensure_available_for(mga::BufferAccess::read); |
1203 | |
1204 | @@ -137,3 +153,30 @@ |
1205 | buffer.ensure_available_for(mga::BufferAccess::write); |
1206 | buffer.ensure_available_for(mga::BufferAccess::read); |
1207 | } |
1208 | + |
1209 | +TEST_F(NativeBuffer, raises_egl_fence) |
1210 | +{ |
1211 | + mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read); |
1212 | + |
1213 | + EXPECT_CALL(*mock_cmdstream_sync, raise()); |
1214 | + buffer.lock_for_gpu(); |
1215 | +} |
1216 | + |
1217 | +TEST_F(NativeBuffer, clears_egl_fence_successfully) |
1218 | +{ |
1219 | + mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read); |
1220 | + EXPECT_CALL(*mock_cmdstream_sync, wait_for(timeout)) |
1221 | + .Times(1) |
1222 | + .WillOnce(Return(true)); |
1223 | + buffer.wait_for_unlock_by_gpu(); |
1224 | +} |
1225 | + |
1226 | +//not really helpful to throw if the timeout fails |
1227 | +TEST_F(NativeBuffer, ignores_clears_egl_fence_failure) |
1228 | +{ |
1229 | + mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read); |
1230 | + EXPECT_CALL(*mock_cmdstream_sync, wait_for(timeout)) |
1231 | + .Times(1) |
1232 | + .WillOnce(Return(false)); |
1233 | + buffer.wait_for_unlock_by_gpu(); |
1234 | +} |
1235 | |
1236 | === modified file 'tests/unit-tests/graphics/android/test_platform.cpp' |
1237 | --- tests/unit-tests/graphics/android/test_platform.cpp 2015-11-24 12:00:40 +0000 |
1238 | +++ tests/unit-tests/graphics/android/test_platform.cpp 2015-12-02 16:15:28 +0000 |
1239 | @@ -26,6 +26,7 @@ |
1240 | #include "mir/test/doubles/mock_display_report.h" |
1241 | #include "mir/test/doubles/mock_egl.h" |
1242 | #include "mir/test/doubles/stub_display_builder.h" |
1243 | +#include "mir/test/doubles/stub_cmdstream_sync_factory.h" |
1244 | #include "mir/test/doubles/fd_matcher.h" |
1245 | #include "mir/test/fake_shared.h" |
1246 | #include "mir/test/doubles/mock_android_native_buffer.h" |
1247 | @@ -54,6 +55,7 @@ |
1248 | using namespace testing; |
1249 | |
1250 | stub_display_builder = std::make_shared<mtd::StubDisplayBuilder>(); |
1251 | + stub_sync_factory = std::make_shared<mtd::StubCmdStreamSyncFactory>(); |
1252 | stub_display_report = mr::null_display_report(); |
1253 | stride = geom::Stride(300*4); |
1254 | |
1255 | @@ -86,6 +88,7 @@ |
1256 | std::shared_ptr<mtd::MockAndroidNativeBuffer> native_buffer; |
1257 | std::shared_ptr<mtd::StubBufferAllocator> stub_buffer_allocator; |
1258 | std::shared_ptr<mtd::StubDisplayBuilder> stub_display_builder; |
1259 | + std::shared_ptr<mtd::StubCmdStreamSyncFactory> stub_sync_factory; |
1260 | std::shared_ptr<mtd::MockBuffer> mock_buffer; |
1261 | std::shared_ptr<native_handle_t> native_buffer_handle; |
1262 | std::shared_ptr<mg::DisplayReport> stub_display_report; |
1263 | @@ -99,10 +102,12 @@ |
1264 | { |
1265 | using namespace ::testing; |
1266 | int fake_fence{333}; |
1267 | + EXPECT_CALL(*native_buffer, wait_for_unlock_by_gpu()); |
1268 | EXPECT_CALL(*native_buffer, copy_fence()) |
1269 | .WillOnce(Return(fake_fence)); |
1270 | |
1271 | - mga::Platform platform(stub_buffer_allocator, stub_display_builder, stub_display_report, mga::OverlayOptimization::enabled, quirks); |
1272 | + mga::Platform platform(stub_buffer_allocator, stub_display_builder, |
1273 | + stub_sync_factory, stub_display_report, mga::OverlayOptimization::enabled, quirks); |
1274 | |
1275 | mtd::MockBufferIpcMessage mock_ipc_msg; |
1276 | int offset = 0; |
1277 | @@ -130,10 +135,12 @@ |
1278 | TEST_F(PlatformBufferIPCPackaging, test_ipc_data_packed_correctly_for_full_ipc_without_fence) |
1279 | { |
1280 | using namespace ::testing; |
1281 | + EXPECT_CALL(*native_buffer, wait_for_unlock_by_gpu()); |
1282 | EXPECT_CALL(*native_buffer, copy_fence()) |
1283 | .WillOnce(Return(-1)); |
1284 | |
1285 | - mga::Platform platform(stub_buffer_allocator, stub_display_builder, stub_display_report, mga::OverlayOptimization::enabled, quirks); |
1286 | + mga::Platform platform(stub_buffer_allocator, stub_display_builder, |
1287 | + stub_sync_factory, stub_display_report, mga::OverlayOptimization::enabled, quirks); |
1288 | |
1289 | mtd::MockBufferIpcMessage mock_ipc_msg; |
1290 | int offset = 0; |
1291 | @@ -169,10 +176,12 @@ |
1292 | TEST_F(PlatformBufferIPCPackaging, test_ipc_data_packed_correctly_for_nested) |
1293 | { |
1294 | using namespace ::testing; |
1295 | + EXPECT_CALL(*native_buffer, wait_for_unlock_by_gpu()); |
1296 | EXPECT_CALL(*native_buffer, copy_fence()) |
1297 | .WillOnce(Return(-1)); |
1298 | |
1299 | - mga::Platform platform(stub_buffer_allocator, stub_display_builder, stub_display_report, mga::OverlayOptimization::enabled, quirks); |
1300 | + mga::Platform platform(stub_buffer_allocator, stub_display_builder, |
1301 | + stub_sync_factory, stub_display_report, mga::OverlayOptimization::enabled, quirks); |
1302 | |
1303 | mtd::MockBufferIpcMessage mock_ipc_msg; |
1304 | int offset = 0; |
1305 | @@ -207,7 +216,8 @@ |
1306 | using namespace ::testing; |
1307 | |
1308 | int fake_fence{33}; |
1309 | - mga::Platform platform(stub_buffer_allocator, stub_display_builder, stub_display_report, mga::OverlayOptimization::enabled, quirks); |
1310 | + mga::Platform platform(stub_buffer_allocator, stub_display_builder, |
1311 | + stub_sync_factory, stub_display_report, mga::OverlayOptimization::enabled, quirks); |
1312 | auto ipc_ops = platform.make_ipc_operations(); |
1313 | |
1314 | mtd::MockBufferIpcMessage mock_ipc_msg; |
1315 | @@ -234,6 +244,7 @@ |
1316 | mga::Platform platform( |
1317 | std::make_shared<mtd::StubBufferAllocator>(), |
1318 | std::make_shared<mtd::StubDisplayBuilder>(), |
1319 | + std::make_shared<mtd::StubCmdStreamSyncFactory>(), |
1320 | mr::null_display_report(), |
1321 | mga::OverlayOptimization::enabled, |
1322 | std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{})); |
FAILED: Continuous integration, rev:3127 jenkins. qa.ubuntu. com/job/ mir-ci/ 5612/ jenkins. qa.ubuntu. com/job/ mir-android- vivid-i386- build/4961/ console jenkins. qa.ubuntu. com/job/ mir-clang- vivid-amd64- build/3867 jenkins. qa.ubuntu. com/job/ mir-mediumtests -vivid- touch/4907/ console jenkins. qa.ubuntu. com/job/ mir-mediumtests -wily-touch/ 863/console jenkins. qa.ubuntu. com/job/ mir-wily- amd64-ci/ 1765 jenkins. qa.ubuntu. com/job/ mir-wily- amd64-ci/ 1765/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ mir-wily- i386-ci/ 861 jenkins. qa.ubuntu. com/job/ mir-wily- i386-ci/ 861/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ mir-mediumtests -builder- vivid-armhf/ 4907/console jenkins. qa.ubuntu. com/job/ mir-mediumtests -builder- wily-armhf/ 864/console
http://
Executed test runs:
FAILURE: http://
SUCCESS: http://
FAILURE: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/mir- ci/5612/ rebuild
http://