Mir

Merge lp:~kdub/mir/egl-sync-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: 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
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::gl::RenderTarget::swap_buffers()

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::DisplayGroup::post. We shift swapbuffers so it is actually called before any waits on the sync fences can happen.

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?
glEGLTargetTexture2DOES will add the command to load the texture into the gpu command stream, but leaves it to us to hold the buffer until its done being used. eglSwapBuffers doesn't guarantee that we can release the buffer yet (as the gpu might need additional time to process after eglSwapBuffers returns); we have to synchronize using this fence extension.

What's still wrong with krillin/mx4?
https://bugs.launchpad.net/mir/+bug/1270245 (Which i'll hopefully track down and fix in a subsequent MP). The corruption caused by this bug looks visually the same as the corruption fixed by this MP.

note: this should land at the same time as the stacked on branch:
https://code.launchpad.net/~kdub/mir/android-shift-swapbuffers/+merge/278176
I split the MP up for the benefit of reviewing (esp as we have to shift swapping behavior a bit)

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
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
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 :

+ //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_to_texture() be made idempotent and called in both branches (which might then be merged into one)?

Alternatively, as the underlying action ("native_buffer->used_by_gpu()") is a side-effect of gl_bind_to_texture() in one branch shouldn't the above function be called "gl_reuse_texture()".

~~~~

+ void used_by_gpu();
+ void ensure_not_used_by_gpu();

Again, this naming isn't great. Maybe "lock_for_gpu()"/"wait_for_unlock_by_gpu()"?

review: Needs Information
Revision history for this message
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

review: Approve
Revision history for this message
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/unit-tests/graphics/android/test_android_alloc_adaptor.cpp'
--- tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp 2015-08-07 15:55:22 +0000
+++ tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp 2015-12-01 03:51:15 +0000
@@ -18,11 +18,14 @@

 #include "src/platforms/android/server/android_alloc_adaptor.h"
 #include "src/platforms/android/server/device_quirks.h"
+#include "src/platforms/android/server/cmdstream_sync_factory.h"
 #include "mir/graphics/android/native_buffer.h"

 #include "mir/test/doubles/mock_android_alloc_device.h"
 #include "mir/test/doubles/mock_alloc_adaptor.h"

+#include "mir/test/doubles/mock_egl.h"
+
 #include <gtest/gtest.h>
 #include <gmock/gmock.h>
 #include <stdexcept>
@@ -47,6 +50,7 @@
         using namespace testing;
         mock_alloc_device = std::make_shared<NiceMock<mtd::MockAllocDevice>>();

+ auto sync_factory = std::make_shared<mga::EGLSyncFactory>();
         auto quirks = std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{});
         alloc_adaptor = std::make_shared<mga::AndroidAllocAdaptor>(mock_alloc_device, quirks);

@@ -57,6 +61,7 @@

     std::shared_ptr<mtd::MockAllocDevice> mock_alloc_device;
     std::shared_ptr<mga::AndroidAllocAdaptor> alloc_adaptor;
+ ::testing::NiceMock<mtd::MockEGL> mock_egl;

     MirPixelFormat pf;
     geom::Size size;

review: Needs Fixing
Revision history for this message
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.

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

Will try to improve the naming, although something that is nicer to use might take more invasive structural changes.

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

> I'm not very familiar with this code, but could gl_bind_to_texture() be 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.

Ideally, I'd change it to:
//uploads
gl_bind_to_texture()
//adds sync points
secure_for_render()

but this doesn't fix the bugs for downstreams.

I think I'll go with:
//deprecated/legacy, calls bind(), then secure_for_render()
gl_bind_to_texture()
//uploads
bind()
//adds sync points
secure_for_render()

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

> > I'm not very familiar with this code, but could gl_bind_to_texture() be
> 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_to_texture() had enough context to "know" of the upload was unnecessary.

>
> Ideally, I'd change it to:
> //uploads
> gl_bind_to_texture()
> //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/legacy, calls bind(), then secure_for_render()
> gl_bind_to_texture()
> //uploads
> bind()
> //adds sync points
> secure_for_render()

OK, I don't have strong feelings against this, it is better than the current proposal.

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

LGTM ...and works.

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

This naming isn't actively misleading, and I'll accept the remaining ugliness as largely preexisting.

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 :

hmm, not in the autolanding queue after 1 day. will retoggle

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== renamed file 'src/include/platform/mir/graphics/egl_extensions.h' => 'include/platform/mir/graphics/egl_extensions.h'
=== renamed file 'src/include/platform/mir/graphics/egl_sync_fence.h' => 'include/platform/mir/graphics/egl_sync_fence.h'
=== modified file 'include/renderers/gl/mir/renderer/gl/texture_source.h'
--- include/renderers/gl/mir/renderer/gl/texture_source.h 2015-09-15 17:13:45 +0000
+++ include/renderers/gl/mir/renderer/gl/texture_source.h 2015-12-02 16:15:28 +0000
@@ -26,12 +26,22 @@
26namespace gl26namespace gl
27{27{
2828
29//FIXME: (kdub) we're not hiding the differences in texture upload approaches between our platforms
30// very well with this interface.
29class TextureSource31class TextureSource
30{32{
31public:33public:
32 virtual ~TextureSource() = default;34 virtual ~TextureSource() = default;
3335
36 // \warning deprecated, provided for convenience and legacy transition.
37 //will call bind() and then secure_for_render()
34 virtual void gl_bind_to_texture() = 0;38 virtual void gl_bind_to_texture() = 0;
39 //Uploads texture.
40 virtual void bind() = 0;
41 //add synchronization points to the command stream to ensure resources
42 //are present during the draw. Will not upload texture.
43 //should be called if an already uploaded texture is reused.
44 virtual void secure_for_render() = 0;
3545
36protected:46protected:
37 TextureSource() = default;47 TextureSource() = default;
3848
=== modified file 'src/common/graphics/android/CMakeLists.txt'
--- src/common/graphics/android/CMakeLists.txt 2015-09-24 04:18:40 +0000
+++ src/common/graphics/android/CMakeLists.txt 2015-12-02 16:15:28 +0000
@@ -1,5 +1,6 @@
1include_directories(SYSTEM ${LIBHARDWARE_INCLUDE_DIRS})1include_directories(SYSTEM ${LIBHARDWARE_INCLUDE_DIRS})
2include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/3rd_party/android-deps)2include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/3rd_party/android-deps)
3include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/include/platform)
34
4add_definitions( -DANDROID )5add_definitions( -DANDROID )
56
67
=== modified file 'src/common/graphics/android/android_native_buffer.cpp'
--- src/common/graphics/android/android_native_buffer.cpp 2015-06-17 05:20:42 +0000
+++ src/common/graphics/android/android_native_buffer.cpp 2015-12-02 16:15:28 +0000
@@ -17,14 +17,17 @@
17 */17 */
1818
19#include "mir/graphics/android/android_native_buffer.h"19#include "mir/graphics/android/android_native_buffer.h"
20#include "mir/graphics/egl_sync_fence.h"
2021
21namespace mga=mir::graphics::android;22namespace mga=mir::graphics::android;
2223
23mga::AndroidNativeBuffer::AndroidNativeBuffer(24mga::AndroidNativeBuffer::AndroidNativeBuffer(
24 std::shared_ptr<ANativeWindowBuffer> const& anwb,25 std::shared_ptr<ANativeWindowBuffer> const& anwb,
26 std::shared_ptr<CommandStreamSync> const& cmdstream_sync,
25 std::shared_ptr<Fence> const& fence,27 std::shared_ptr<Fence> const& fence,
26 BufferAccess access)28 BufferAccess access)
27 : fence(fence),29 : cmdstream_sync(cmdstream_sync),
30 fence(fence),
28 access(access),31 access(access),
29 native_window_buffer(anwb)32 native_window_buffer(anwb)
30{33{
@@ -58,3 +61,14 @@
58{61{
59 return fence->copy_native_handle();62 return fence->copy_native_handle();
60}63}
64
65void mga::AndroidNativeBuffer::lock_for_gpu()
66{
67 cmdstream_sync->raise();
68}
69
70void mga::AndroidNativeBuffer::wait_for_unlock_by_gpu()
71{
72 using namespace std::chrono;
73 cmdstream_sync->wait_for(duration_cast<nanoseconds>(seconds(2)));
74}
6175
=== modified file 'src/gl/recently_used_cache.cpp'
--- src/gl/recently_used_cache.cpp 2015-10-06 02:30:52 +0000
+++ src/gl/recently_used_cache.cpp 2015-12-02 16:15:28 +0000
@@ -27,6 +27,7 @@
27namespace mg = mir::graphics;27namespace mg = mir::graphics;
28namespace mgl = mir::gl;28namespace mgl = mir::gl;
29namespace geom = mir::geometry;29namespace geom = mir::geometry;
30namespace mrgl = mir::renderer::gl;
3031
31std::shared_ptr<mgl::Texture> mgl::RecentlyUsedCache::load(mg::Renderable const& renderable)32std::shared_ptr<mgl::Texture> mgl::RecentlyUsedCache::load(mg::Renderable const& renderable)
32{33{
@@ -35,18 +36,18 @@
35 auto& texture = textures[renderable.id()];36 auto& texture = textures[renderable.id()];
36 texture.texture->bind();37 texture.texture->bind();
3738
39 auto const texture_source = dynamic_cast<mrgl::TextureSource*>(buffer->native_buffer_base());
40 if (!texture_source)
41 BOOST_THROW_EXCEPTION(std::logic_error("Buffer does not support GL rendering"));
42
38 if ((texture.last_bound_buffer != buffer_id) || (!texture.valid_binding))43 if ((texture.last_bound_buffer != buffer_id) || (!texture.valid_binding))
39 {44 {
40 auto const texture_source =45 texture_source->bind();
41 dynamic_cast<mir::renderer::gl::TextureSource*>(
42 buffer->native_buffer_base());
43 if (!texture_source)
44 BOOST_THROW_EXCEPTION(std::logic_error("Buffer does not support GL rendering"));
45
46 texture_source->gl_bind_to_texture();
47 texture.resource = buffer;46 texture.resource = buffer;
48 texture.last_bound_buffer = buffer_id;47 texture.last_bound_buffer = buffer_id;
49 }48 }
49 texture_source->secure_for_render();
50
50 texture.valid_binding = true;51 texture.valid_binding = true;
51 texture.used = true;52 texture.used = true;
5253
5354
=== modified file 'src/include/common/mir/graphics/android/android_native_buffer.h'
--- src/include/common/mir/graphics/android/android_native_buffer.h 2015-06-17 05:20:42 +0000
+++ src/include/common/mir/graphics/android/android_native_buffer.h 2015-12-02 16:15:28 +0000
@@ -27,6 +27,7 @@
27{27{
28namespace graphics28namespace graphics
29{29{
30class CommandStreamSync;
30namespace android31namespace android
31{32{
32class Fence;33class Fence;
@@ -35,6 +36,7 @@
35{36{
36 AndroidNativeBuffer(37 AndroidNativeBuffer(
37 std::shared_ptr<ANativeWindowBuffer> const& handle,38 std::shared_ptr<ANativeWindowBuffer> const& handle,
39 std::shared_ptr<CommandStreamSync> const& cmdstream_sync,
38 std::shared_ptr<Fence> const& fence,40 std::shared_ptr<Fence> const& fence,
39 BufferAccess fence_access);41 BufferAccess fence_access);
4042
@@ -45,7 +47,11 @@
45 void ensure_available_for(BufferAccess);47 void ensure_available_for(BufferAccess);
46 void update_usage(NativeFence& merge_fd, BufferAccess);48 void update_usage(NativeFence& merge_fd, BufferAccess);
4749
50 void lock_for_gpu();
51 void wait_for_unlock_by_gpu();
52
48private:53private:
54 std::shared_ptr<CommandStreamSync> cmdstream_sync;
49 std::shared_ptr<Fence> fence;55 std::shared_ptr<Fence> fence;
50 BufferAccess access;56 BufferAccess access;
51 std::shared_ptr<ANativeWindowBuffer> native_window_buffer;57 std::shared_ptr<ANativeWindowBuffer> native_window_buffer;
5258
=== modified file 'src/include/common/mir/graphics/android/native_buffer.h'
--- src/include/common/mir/graphics/android/native_buffer.h 2015-06-17 05:20:42 +0000
+++ src/include/common/mir/graphics/android/native_buffer.h 2015-12-02 16:15:28 +0000
@@ -53,6 +53,9 @@
53 virtual void ensure_available_for(android::BufferAccess intent) = 0;53 virtual void ensure_available_for(android::BufferAccess intent) = 0;
54 virtual void update_usage(android::NativeFence& fence, android::BufferAccess current_usage) = 0;54 virtual void update_usage(android::NativeFence& fence, android::BufferAccess current_usage) = 0;
5555
56 virtual void lock_for_gpu() = 0;
57 virtual void wait_for_unlock_by_gpu() = 0;
58
56protected:59protected:
57 NativeBuffer() = default;60 NativeBuffer() = default;
58 NativeBuffer(NativeBuffer const&) = delete;61 NativeBuffer(NativeBuffer const&) = delete;
5962
=== modified file 'src/platform/symbols.map'
--- src/platform/symbols.map 2015-11-04 14:22:48 +0000
+++ src/platform/symbols.map 2015-12-02 16:15:28 +0000
@@ -219,6 +219,7 @@
219 vtable?for?mir::graphics::EventHandlerRegister;219 vtable?for?mir::graphics::EventHandlerRegister;
220 vtable?for?mir::graphics::GLConfig;220 vtable?for?mir::graphics::GLConfig;
221 vtable?for?mir::graphics::GLContext;221 vtable?for?mir::graphics::GLContext;
222 vtable?for?mir::graphics::NullCommandSync;
222 vtable?for?mir::graphics::GraphicBufferAllocator;223 vtable?for?mir::graphics::GraphicBufferAllocator;
223 vtable?for?mir::graphics::Platform;224 vtable?for?mir::graphics::Platform;
224 vtable?for?mir::graphics::PlatformIpcOperations;225 vtable?for?mir::graphics::PlatformIpcOperations;
@@ -237,6 +238,19 @@
237 mir::graphics::blue_channel_depth*;238 mir::graphics::blue_channel_depth*;
238 mir::graphics::contains_alpha*;239 mir::graphics::contains_alpha*;
239 mir::graphics::EGLExtensions::EGLExtensions*;240 mir::graphics::EGLExtensions::EGLExtensions*;
241 mir::graphics::EGLSyncExtensions::EGLSyncExtensions*;
242 mir::graphics::CommandStreamSync::?CommandStreamSync*;
243 mir::graphics::CommandStreamSync::CommandStreamSync*;
244 mir::graphics::CommandStreamSync::CommandStreamSync*;
245 mir::graphics::CommandStreamSync::operator*;
246 mir::graphics::NullCommandSync::?NullCommandSync*;
247 mir::graphics::NullCommandSync::NullCommandSync*;
248 mir::graphics::NullCommandSync::NullCommandSync*;
249 mir::graphics::NullCommandSync::operator*;
250 mir::graphics::EGLSyncFence::?EGLSyncFence*;
251 mir::graphics::EGLSyncFence::EGLSyncFence*;
252 mir::graphics::EGLSyncFence::EGLSyncFence*;
253 mir::graphics::EGLSyncFence::operator*;
240 mir::graphics::EGLContextStore::?EGLContextStore*;254 mir::graphics::EGLContextStore::?EGLContextStore*;
241 mir::graphics::EGLContextStore::EGLContextStore*;255 mir::graphics::EGLContextStore::EGLContextStore*;
242 mir::graphics::EGLContextStore::EGLContextStore*;256 mir::graphics::EGLContextStore::EGLContextStore*;
243257
=== modified file 'src/platforms/android/client/CMakeLists.txt'
--- src/platforms/android/client/CMakeLists.txt 2015-11-04 07:43:28 +0000
+++ src/platforms/android/client/CMakeLists.txt 2015-12-02 16:15:28 +0000
@@ -1,6 +1,7 @@
1include_directories(${client_common_include_dirs})1include_directories(${client_common_include_dirs})
2include_directories(SYSTEM ${LIBHARDWARE_INCLUDE_DIRS})2include_directories(SYSTEM ${LIBHARDWARE_INCLUDE_DIRS})
3include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/3rd_party/android-deps)3include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/3rd_party/android-deps)
4include_directories(${CMAKE_SOURCE_DIR}/include/platform)
45
5add_definitions(-DANDROID)6add_definitions(-DANDROID)
67
@@ -35,6 +36,7 @@
35 mirclient36 mirclient
36 client_platform_common37 client_platform_common
37 mirsharedandroid-static38 mirsharedandroid-static
39 mirplatform
38 ${LIBHARDWARE_LIBRARIES}40 ${LIBHARDWARE_LIBRARIES}
39)41)
4042
4143
=== modified file 'src/platforms/android/client/gralloc_registrar.cpp'
--- src/platforms/android/client/gralloc_registrar.cpp 2015-06-18 14:33:10 +0000
+++ src/platforms/android/client/gralloc_registrar.cpp 2015-12-02 16:15:28 +0000
@@ -18,6 +18,7 @@
1818
19#include "mir/graphics/android/android_native_buffer.h"19#include "mir/graphics/android/android_native_buffer.h"
20#include "mir/graphics/android/sync_fence.h"20#include "mir/graphics/android/sync_fence.h"
21#include "mir/graphics/egl_sync_fence.h"
21#include "gralloc_registrar.h"22#include "gralloc_registrar.h"
22#include "mir/client_buffer.h"23#include "mir/client_buffer.h"
2324
@@ -82,7 +83,8 @@
82 anwb->usage = GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER;83 anwb->usage = GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER;
83 anwb->handle = handle.get();84 anwb->handle = handle.get();
8485
85 return std::make_shared<mga::AndroidNativeBuffer>(anwb, fence, mga::BufferAccess::read);86 auto sync = std::make_shared<mg::NullCommandSync>(); //no need for eglsync client side
87 return std::make_shared<mga::AndroidNativeBuffer>(anwb, sync, fence, mga::BufferAccess::read);
86}88}
87}89}
88std::shared_ptr<mg::NativeBuffer> mcla::GrallocRegistrar::register_buffer(90std::shared_ptr<mg::NativeBuffer> mcla::GrallocRegistrar::register_buffer(
8991
=== modified file 'src/platforms/android/server/CMakeLists.txt'
--- src/platforms/android/server/CMakeLists.txt 2015-11-04 07:43:28 +0000
+++ src/platforms/android/server/CMakeLists.txt 2015-12-02 16:15:28 +0000
@@ -43,6 +43,7 @@
43 hwc_fallback_gl_renderer.cpp43 hwc_fallback_gl_renderer.cpp
44 ipc_operations.cpp44 ipc_operations.cpp
45 hwc_blanking_control.cpp45 hwc_blanking_control.cpp
46 egl_sync_factory.cpp
46)47)
4748
48add_library(mirplatformgraphicsandroid SHARED49add_library(mirplatformgraphicsandroid SHARED
4950
=== modified file 'src/platforms/android/server/android_alloc_adaptor.cpp'
--- src/platforms/android/server/android_alloc_adaptor.cpp 2015-08-07 15:55:22 +0000
+++ src/platforms/android/server/android_alloc_adaptor.cpp 2015-12-02 16:15:28 +0000
@@ -20,7 +20,9 @@
20#include "mir/graphics/android/android_native_buffer.h"20#include "mir/graphics/android/android_native_buffer.h"
21#include "mir/graphics/android/sync_fence.h"21#include "mir/graphics/android/sync_fence.h"
22#include "mir/graphics/android/android_format_conversion-inl.h"22#include "mir/graphics/android/android_format_conversion-inl.h"
23#include "mir/graphics/egl_sync_fence.h"
23#include "android_alloc_adaptor.h"24#include "android_alloc_adaptor.h"
25#include "cmdstream_sync_factory.h"
24#include "device_quirks.h"26#include "device_quirks.h"
2527
26#include <boost/throw_exception.hpp>28#include <boost/throw_exception.hpp>
@@ -48,10 +50,13 @@
48};50};
49}51}
5052
51mga::AndroidAllocAdaptor::AndroidAllocAdaptor(std::shared_ptr<struct alloc_device_t> const& alloc_device,53mga::AndroidAllocAdaptor::AndroidAllocAdaptor(
52 std::shared_ptr<DeviceQuirks> const& quirks)54 std::shared_ptr<struct alloc_device_t> const& alloc_device,
53 : alloc_dev(alloc_device),55 std::shared_ptr<CommandStreamSyncFactory> const& sync_factory,
54 quirks(quirks)56 std::shared_ptr<DeviceQuirks> const& quirks) :
57 alloc_dev(alloc_device),
58 sync_factory(sync_factory),
59 quirks(quirks)
55{60{
56}61}
5762
@@ -94,7 +99,9 @@
94 anwb->format = format;99 anwb->format = format;
95 anwb->usage = usage_flag;100 anwb->usage = usage_flag;
96101
97 return std::make_shared<mga::AndroidNativeBuffer>(anwb, fence, mga::BufferAccess::read);102 return std::make_shared<mga::AndroidNativeBuffer>(anwb,
103 sync_factory->create_command_stream_sync(),
104 fence, mga::BufferAccess::read);
98}105}
99106
100int mga::AndroidAllocAdaptor::convert_to_android_usage(BufferUsage usage)107int mga::AndroidAllocAdaptor::convert_to_android_usage(BufferUsage usage)
101108
=== modified file 'src/platforms/android/server/android_alloc_adaptor.h'
--- src/platforms/android/server/android_alloc_adaptor.h 2015-06-24 11:33:02 +0000
+++ src/platforms/android/server/android_alloc_adaptor.h 2015-12-02 16:15:28 +0000
@@ -31,12 +31,15 @@
31namespace android31namespace android
32{32{
33class DeviceQuirks;33class DeviceQuirks;
34class CommandStreamSyncFactory;
3435
35class AndroidAllocAdaptor : public GraphicAllocAdaptor36class AndroidAllocAdaptor : public GraphicAllocAdaptor
36{37{
37public:38public:
38 explicit AndroidAllocAdaptor(std::shared_ptr<struct alloc_device_t> const& alloc_device,39 explicit AndroidAllocAdaptor(
39 std::shared_ptr<DeviceQuirks> const& quirks);40 std::shared_ptr<struct alloc_device_t> const& alloc_device,
41 std::shared_ptr<CommandStreamSyncFactory> const& cmdstream_sync_factory,
42 std::shared_ptr<DeviceQuirks> const& quirks);
40 std::shared_ptr<NativeBuffer> alloc_buffer(geometry::Size,43 std::shared_ptr<NativeBuffer> alloc_buffer(geometry::Size,
41 MirPixelFormat, BufferUsage usage);44 MirPixelFormat, BufferUsage usage);
4245
@@ -44,6 +47,7 @@
4447
45private:48private:
46 std::shared_ptr<struct alloc_device_t> alloc_dev;49 std::shared_ptr<struct alloc_device_t> alloc_dev;
50 std::shared_ptr<CommandStreamSyncFactory> const sync_factory;
47 std::shared_ptr<DeviceQuirks> const quirks;51 std::shared_ptr<DeviceQuirks> const quirks;
48 int convert_to_android_usage(BufferUsage usage);52 int convert_to_android_usage(BufferUsage usage);
49};53};
5054
=== modified file 'src/platforms/android/server/android_buffer_allocator.cpp'
--- src/platforms/android/server/android_buffer_allocator.cpp 2015-11-25 12:59:13 +0000
+++ src/platforms/android/server/android_buffer_allocator.cpp 2015-12-02 16:15:28 +0000
@@ -19,12 +19,14 @@
1919
20#include "mir/graphics/platform.h"20#include "mir/graphics/platform.h"
21#include "mir/graphics/egl_extensions.h"21#include "mir/graphics/egl_extensions.h"
22#include "mir/graphics/egl_sync_fence.h"
22#include "mir/graphics/buffer_properties.h"23#include "mir/graphics/buffer_properties.h"
23#include "mir/graphics/android/sync_fence.h"24#include "mir/graphics/android/sync_fence.h"
24#include "mir/graphics/android/android_native_buffer.h"25#include "mir/graphics/android/android_native_buffer.h"
25#include "android_graphic_buffer_allocator.h"26#include "android_graphic_buffer_allocator.h"
26#include "android_alloc_adaptor.h"27#include "android_alloc_adaptor.h"
27#include "buffer.h"28#include "buffer.h"
29#include "cmdstream_sync_factory.h"
28#include "device_quirks.h"30#include "device_quirks.h"
2931
30#include <boost/throw_exception.hpp>32#include <boost/throw_exception.hpp>
@@ -50,8 +52,11 @@
5052
51}53}
5254
53mga::AndroidGraphicBufferAllocator::AndroidGraphicBufferAllocator(std::shared_ptr<DeviceQuirks> const& quirks)55mga::AndroidGraphicBufferAllocator::AndroidGraphicBufferAllocator(
54 : egl_extensions(std::make_shared<mg::EGLExtensions>())56 std::shared_ptr<CommandStreamSyncFactory> const& cmdstream_sync_factory,
57 std::shared_ptr<DeviceQuirks> const& quirks)
58 : egl_extensions(std::make_shared<mg::EGLExtensions>()),
59 cmdstream_sync_factory(cmdstream_sync_factory)
55{60{
56 int err;61 int err;
5762
@@ -70,7 +75,7 @@
70 std::shared_ptr<struct alloc_device_t> alloc_dev_ptr(75 std::shared_ptr<struct alloc_device_t> alloc_dev_ptr(
71 alloc_dev,76 alloc_dev,
72 quirks->gralloc_cannot_be_closed_safely() ? null_alloc_dev_deleter : alloc_dev_deleter);77 quirks->gralloc_cannot_be_closed_safely() ? null_alloc_dev_deleter : alloc_dev_deleter);
73 alloc_device = std::shared_ptr<mga::GraphicAllocAdaptor>(new AndroidAllocAdaptor(alloc_dev_ptr, quirks));78 alloc_device = std::shared_ptr<mga::GraphicAllocAdaptor>(new AndroidAllocAdaptor(alloc_dev_ptr, cmdstream_sync_factory, quirks));
74}79}
7580
76std::shared_ptr<mg::Buffer> mga::AndroidGraphicBufferAllocator::alloc_buffer(81std::shared_ptr<mg::Buffer> mga::AndroidGraphicBufferAllocator::alloc_buffer(
@@ -89,9 +94,10 @@
89 [](ANativeWindowBuffer* buffer){ buffer->common.decRef(&buffer->common); });94 [](ANativeWindowBuffer* buffer){ buffer->common.decRef(&buffer->common); });
90 anwb->common.incRef(&anwb->common);95 anwb->common.incRef(&anwb->common);
9196
97 //TODO: we should have an android platform function for accessing the fence.
92 auto native_handle = std::make_shared<mga::AndroidNativeBuffer>(98 auto native_handle = std::make_shared<mga::AndroidNativeBuffer>(
93 native_window_buffer,99 native_window_buffer,
94 //TODO: we should have an android platform function for accessing the fence.100 cmdstream_sync_factory->create_command_stream_sync(),
95 std::make_shared<mga::SyncFence>(std::make_shared<mga::RealSyncFileOps>(), mir::Fd()),101 std::make_shared<mga::SyncFence>(std::make_shared<mga::RealSyncFileOps>(), mir::Fd()),
96 mga::BufferAccess::read);102 mga::BufferAccess::read);
97 return std::make_unique<Buffer>(103 return std::make_unique<Buffer>(
98104
=== modified file 'src/platforms/android/server/android_graphic_buffer_allocator.h'
--- src/platforms/android/server/android_graphic_buffer_allocator.h 2015-06-24 11:33:02 +0000
+++ src/platforms/android/server/android_graphic_buffer_allocator.h 2015-12-02 16:15:28 +0000
@@ -39,11 +39,14 @@
3939
40class GraphicAllocAdaptor;40class GraphicAllocAdaptor;
41class DeviceQuirks;41class DeviceQuirks;
42class CommandStreamSyncFactory;
4243
43class AndroidGraphicBufferAllocator: public GraphicBufferAllocator, public graphics::GraphicBufferAllocator44class AndroidGraphicBufferAllocator: public GraphicBufferAllocator, public graphics::GraphicBufferAllocator
44{45{
45public:46public:
46 AndroidGraphicBufferAllocator(std::shared_ptr<DeviceQuirks> const& quirks);47 AndroidGraphicBufferAllocator(
48 std::shared_ptr<CommandStreamSyncFactory> const& cmdstream_sync_factory,
49 std::shared_ptr<DeviceQuirks> const& quirks);
4750
48 std::shared_ptr<graphics::Buffer> alloc_buffer(51 std::shared_ptr<graphics::Buffer> alloc_buffer(
49 graphics::BufferProperties const& buffer_properties) override;52 graphics::BufferProperties const& buffer_properties) override;
@@ -61,6 +64,7 @@
61 const hw_module_t *hw_module;64 const hw_module_t *hw_module;
62 std::shared_ptr<GraphicAllocAdaptor> alloc_device;65 std::shared_ptr<GraphicAllocAdaptor> alloc_device;
63 std::shared_ptr<EGLExtensions> const egl_extensions;66 std::shared_ptr<EGLExtensions> const egl_extensions;
67 std::shared_ptr<CommandStreamSyncFactory> const cmdstream_sync_factory;
64};68};
6569
66}70}
6771
=== modified file 'src/platforms/android/server/buffer.cpp'
--- src/platforms/android/server/buffer.cpp 2015-08-27 13:41:02 +0000
+++ src/platforms/android/server/buffer.cpp 2015-12-02 16:15:28 +0000
@@ -74,6 +74,18 @@
74void mga::Buffer::gl_bind_to_texture()74void mga::Buffer::gl_bind_to_texture()
75{75{
76 std::unique_lock<std::mutex> lk(content_lock);76 std::unique_lock<std::mutex> lk(content_lock);
77 bind(lk);
78 secure_for_render(lk);
79}
80
81void mga::Buffer::bind()
82{
83 std::unique_lock<std::mutex> lk(content_lock);
84 bind(lk);
85}
86
87void mga::Buffer::bind(std::unique_lock<std::mutex> const&)
88{
77 native_buffer->ensure_available_for(mga::BufferAccess::read);89 native_buffer->ensure_available_for(mga::BufferAccess::read);
7890
79 DispContextPair current91 DispContextPair current
@@ -113,10 +125,6 @@
113 }125 }
114126
115 egl_extensions->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);127 egl_extensions->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
116
117 //TODO: we should make use of the android egl fence extension here to update the fence.
118 // if the extension is not available, we should pass out a token that the user
119 // will have to keep until the completion of the gl draw
120}128}
121129
122std::shared_ptr<mg::NativeBuffer> mga::Buffer::native_buffer_handle() const130std::shared_ptr<mg::NativeBuffer> mga::Buffer::native_buffer_handle() const
@@ -196,3 +204,14 @@
196{204{
197 return this;205 return this;
198}206}
207
208void mga::Buffer::secure_for_render()
209{
210 std::unique_lock<std::mutex> lk(content_lock);
211 secure_for_render(lk);
212}
213
214void mga::Buffer::secure_for_render(std::unique_lock<std::mutex> const&)
215{
216 native_buffer->lock_for_gpu();
217}
199218
=== modified file 'src/platforms/android/server/buffer.h'
--- src/platforms/android/server/buffer.h 2015-09-04 06:46:36 +0000
+++ src/platforms/android/server/buffer.h 2015-12-02 16:15:28 +0000
@@ -56,6 +56,10 @@
56 geometry::Stride stride() const override;56 geometry::Stride stride() const override;
57 MirPixelFormat pixel_format() const override;57 MirPixelFormat pixel_format() const override;
58 void gl_bind_to_texture() override;58 void gl_bind_to_texture() override;
59 void bind() override;
60 void secure_for_render() override;
61
62
59 //note, you will get the native representation of an android buffer, including63 //note, you will get the native representation of an android buffer, including
60 //the fences associated with the buffer. You must close these fences64 //the fences associated with the buffer. You must close these fences
61 std::shared_ptr<NativeBuffer> native_buffer_handle() const override;65 std::shared_ptr<NativeBuffer> native_buffer_handle() const override;
@@ -66,6 +70,8 @@
66 NativeBufferBase* native_buffer_base() override;70 NativeBufferBase* native_buffer_base() override;
6771
68private:72private:
73 void bind(std::unique_lock<std::mutex> const&);
74 void secure_for_render(std::unique_lock<std::mutex> const&);
69 gralloc_module_t const* hw_module;75 gralloc_module_t const* hw_module;
7076
71 typedef std::pair<EGLDisplay, EGLContext> DispContextPair;77 typedef std::pair<EGLDisplay, EGLContext> DispContextPair;
7278
=== added file 'src/platforms/android/server/cmdstream_sync_factory.h'
--- src/platforms/android/server/cmdstream_sync_factory.h 1970-01-01 00:00:00 +0000
+++ src/platforms/android/server/cmdstream_sync_factory.h 2015-12-02 16:15:28 +0000
@@ -0,0 +1,48 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17 */
18
19#ifndef MIR_GRAPHICS_ANDROID_CMDSTREAM_SYNC_FACTORY_H_
20#define MIR_GRAPHICS_ANDROID_CMDSTREAM_SYNC_FACTORY_H_
21
22#include <memory>
23namespace mir
24{
25namespace graphics
26{
27class CommandStreamSync;
28namespace android
29{
30class CommandStreamSyncFactory
31{
32public:
33 virtual ~CommandStreamSyncFactory() = default;
34 virtual std::unique_ptr<CommandStreamSync> create_command_stream_sync() = 0;
35protected:
36 CommandStreamSyncFactory() = default;
37 CommandStreamSyncFactory(CommandStreamSyncFactory const&) = delete;
38 CommandStreamSyncFactory& operator=(CommandStreamSyncFactory const&) = delete;
39};
40
41class EGLSyncFactory : public CommandStreamSyncFactory
42{
43 std::unique_ptr<CommandStreamSync> create_command_stream_sync() override;
44};
45}
46}
47}
48#endif /* MIR_GRAPHICS_ANDROID_CMDSTREAM_SYNC_FACTORY_H_ */
049
=== modified file 'src/platforms/android/server/display_component_factory.h'
--- src/platforms/android/server/display_component_factory.h 2015-06-17 05:20:42 +0000
+++ src/platforms/android/server/display_component_factory.h 2015-12-02 16:15:28 +0000
@@ -19,6 +19,7 @@
19#ifndef MIR_GRAPHICS_ANDROID_DISPLAY_COMPONENT_FACTORY_H_19#ifndef MIR_GRAPHICS_ANDROID_DISPLAY_COMPONENT_FACTORY_H_
20#define MIR_GRAPHICS_ANDROID_DISPLAY_COMPONENT_FACTORY_H_20#define MIR_GRAPHICS_ANDROID_DISPLAY_COMPONENT_FACTORY_H_
2121
22#include "mir/graphics/egl_sync_fence.h"
22#include "display_device.h"23#include "display_device.h"
23#include "framebuffer_bundle.h"24#include "framebuffer_bundle.h"
24#include <memory>25#include <memory>
@@ -28,6 +29,7 @@
28namespace graphics29namespace graphics
29{30{
30class DisplayConfigurationOutput;31class DisplayConfigurationOutput;
32class CommandStreamSync;
31namespace android33namespace android
32{34{
33class HwcConfiguration;35class HwcConfiguration;
3436
=== added file 'src/platforms/android/server/egl_sync_factory.cpp'
--- src/platforms/android/server/egl_sync_factory.cpp 1970-01-01 00:00:00 +0000
+++ src/platforms/android/server/egl_sync_factory.cpp 2015-12-02 16:15:28 +0000
@@ -0,0 +1,34 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17 */
18
19#include "cmdstream_sync_factory.h"
20#include "mir/graphics/egl_sync_fence.h"
21namespace mg = mir::graphics;
22namespace mga = mir::graphics::android;
23
24std::unique_ptr<mg::CommandStreamSync> mga::EGLSyncFactory::create_command_stream_sync()
25{
26 try
27 {
28 return std::make_unique<EGLSyncFence>(std::make_shared<mg::EGLSyncExtensions>());
29 }
30 catch (std::runtime_error&)
31 {
32 return std::make_unique<NullCommandSync>();
33 }
34}
035
=== modified file 'src/platforms/android/server/hal_component_factory.cpp'
--- src/platforms/android/server/hal_component_factory.cpp 2015-06-24 11:33:02 +0000
+++ src/platforms/android/server/hal_component_factory.cpp 2015-12-02 16:15:28 +0000
@@ -65,6 +65,21 @@
65 }65 }
66}66}
6767
68std::unique_ptr<mg::CommandStreamSync> mga::HalComponentFactory::create_command_stream_sync()
69{
70 if (hwc_version == mga::HwcVersion::hwc10)
71 return std::make_unique<NullCommandSync>();
72
73 try
74 {
75 return std::make_unique<EGLSyncFence>(std::make_shared<mg::EGLSyncExtensions>());
76 }
77 catch (std::runtime_error&)
78 {
79 return std::make_unique<NullCommandSync>();
80 }
81}
82
68std::unique_ptr<mga::FramebufferBundle> mga::HalComponentFactory::create_framebuffers(mg::DisplayConfigurationOutput const& config)83std::unique_ptr<mga::FramebufferBundle> mga::HalComponentFactory::create_framebuffers(mg::DisplayConfigurationOutput const& config)
69{84{
70 return std::unique_ptr<mga::FramebufferBundle>(new mga::Framebuffers(85 return std::unique_ptr<mga::FramebufferBundle>(new mga::Framebuffers(
7186
=== modified file 'src/platforms/android/server/hal_component_factory.h'
--- src/platforms/android/server/hal_component_factory.h 2015-06-24 11:33:02 +0000
+++ src/platforms/android/server/hal_component_factory.h 2015-12-02 16:15:28 +0000
@@ -19,6 +19,7 @@
19#ifndef MIR_GRAPHICS_ANDROID_HAL_COMPONENT_FACTORY_H_19#ifndef MIR_GRAPHICS_ANDROID_HAL_COMPONENT_FACTORY_H_
20#define MIR_GRAPHICS_ANDROID_HAL_COMPONENT_FACTORY_H_20#define MIR_GRAPHICS_ANDROID_HAL_COMPONENT_FACTORY_H_
2121
22#include "cmdstream_sync_factory.h"
22#include "display_component_factory.h"23#include "display_component_factory.h"
23#include "display_resource_factory.h"24#include "display_resource_factory.h"
2425
@@ -39,7 +40,7 @@
3940
40//NOTE: this should be the only class that inspects the HWC version and assembles41//NOTE: this should be the only class that inspects the HWC version and assembles
41//the components accordingly42//the components accordingly
42class HalComponentFactory : public DisplayComponentFactory43class HalComponentFactory : public DisplayComponentFactory, public CommandStreamSyncFactory
43{44{
44public:45public:
45 HalComponentFactory(46 HalComponentFactory(
@@ -48,6 +49,7 @@
48 std::shared_ptr<HwcReport> const& hwc_report,49 std::shared_ptr<HwcReport> const& hwc_report,
49 std::shared_ptr<DeviceQuirks> const& quirks);50 std::shared_ptr<DeviceQuirks> const& quirks);
5051
52 std::unique_ptr<CommandStreamSync> create_command_stream_sync() override;
51 std::unique_ptr<FramebufferBundle> create_framebuffers(DisplayConfigurationOutput const&) override;53 std::unique_ptr<FramebufferBundle> create_framebuffers(DisplayConfigurationOutput const&) override;
52 std::unique_ptr<DisplayDevice> create_display_device() override;54 std::unique_ptr<DisplayDevice> create_display_device() override;
53 std::unique_ptr<HwcConfiguration> create_hwc_configuration() override;55 std::unique_ptr<HwcConfiguration> create_hwc_configuration() override;
5456
=== modified file 'src/platforms/android/server/ipc_operations.cpp'
--- src/platforms/android/server/ipc_operations.cpp 2015-06-18 14:33:10 +0000
+++ src/platforms/android/server/ipc_operations.cpp 2015-12-02 16:15:28 +0000
@@ -32,6 +32,7 @@
32{32{
33 auto native_buffer = buffer.native_buffer_handle();33 auto native_buffer = buffer.native_buffer_handle();
3434
35 native_buffer->wait_for_unlock_by_gpu();
35 mir::Fd fence_fd(native_buffer->copy_fence());36 mir::Fd fence_fd(native_buffer->copy_fence());
36 if (fence_fd != mir::Fd::invalid)37 if (fence_fd != mir::Fd::invalid)
37 {38 {
3839
=== modified file 'src/platforms/android/server/platform.cpp'
--- src/platforms/android/server/platform.cpp 2015-11-24 12:00:40 +0000
+++ src/platforms/android/server/platform.cpp 2015-12-02 16:15:28 +0000
@@ -85,11 +85,13 @@
85mga::Platform::Platform(85mga::Platform::Platform(
86 std::shared_ptr<graphics::GraphicBufferAllocator> const& buffer_allocator,86 std::shared_ptr<graphics::GraphicBufferAllocator> const& buffer_allocator,
87 std::shared_ptr<mga::DisplayComponentFactory> const& display_buffer_builder,87 std::shared_ptr<mga::DisplayComponentFactory> const& display_buffer_builder,
88 std::shared_ptr<CommandStreamSyncFactory> const& sync_factory,
88 std::shared_ptr<mg::DisplayReport> const& display_report,89 std::shared_ptr<mg::DisplayReport> const& display_report,
89 mga::OverlayOptimization overlay_option,90 mga::OverlayOptimization overlay_option,
90 std::shared_ptr<mga::DeviceQuirks> const& quirks) :91 std::shared_ptr<mga::DeviceQuirks> const& quirks) :
91 buffer_allocator(buffer_allocator),92 buffer_allocator(buffer_allocator),
92 display_buffer_builder(display_buffer_builder),93 display_buffer_builder(display_buffer_builder),
94 sync_factory(sync_factory),
93 display_report(display_report),95 display_report(display_report),
94 quirks(quirks),96 quirks(quirks),
95 overlay_option(overlay_option)97 overlay_option(overlay_option)
@@ -153,10 +155,13 @@
153 auto overlay_option = should_use_overlay_optimization(*options);155 auto overlay_option = should_use_overlay_optimization(*options);
154 hwc_report->report_overlay_optimization(overlay_option);156 hwc_report->report_overlay_optimization(overlay_option);
155 auto display_resource_factory = std::make_shared<mga::ResourceFactory>();157 auto display_resource_factory = std::make_shared<mga::ResourceFactory>();
156 auto buffer_allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(quirks);158 auto sync_factory = std::make_shared<mga::EGLSyncFactory>();
159 auto buffer_allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(sync_factory, quirks);
157 auto component_factory = std::make_shared<mga::HalComponentFactory>(160 auto component_factory = std::make_shared<mga::HalComponentFactory>(
158 buffer_allocator, display_resource_factory, hwc_report, quirks);161 buffer_allocator, display_resource_factory, hwc_report, quirks);
159 return mir::make_module_ptr<mga::Platform>(buffer_allocator, component_factory, display_report, overlay_option, quirks);162
163 return mir::make_module_ptr<mga::Platform>(
164 buffer_allocator, component_factory, component_factory, display_report, overlay_option, quirks);
160}165}
161166
162mir::UniqueModulePtr<mg::Platform> create_guest_platform(167mir::UniqueModulePtr<mg::Platform> create_guest_platform(
@@ -166,10 +171,11 @@
166 mir::assert_entry_point_signature<mg::CreateGuestPlatform>(&create_guest_platform);171 mir::assert_entry_point_signature<mg::CreateGuestPlatform>(&create_guest_platform);
167 //TODO: actually allow disabling quirks for guest platform172 //TODO: actually allow disabling quirks for guest platform
168 auto quirks = std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{});173 auto quirks = std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{});
174 auto sync_factory = std::make_shared<mga::EGLSyncFactory>();
169 //TODO: remove nullptr parameter once platform classes are sorted.175 //TODO: remove nullptr parameter once platform classes are sorted.
170 // mg::NativePlatform cannot create a display anyways, so it doesnt need a display builder176 // mg::NativePlatform cannot create a display anyways, so it doesnt need a display builder
171 auto const buffer_allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(quirks);177 auto const buffer_allocator = std::make_shared<mga::AndroidGraphicBufferAllocator>(sync_factory, quirks);
172 return mir::make_module_ptr<mga::Platform>(buffer_allocator, nullptr, display_report, mga::OverlayOptimization::disabled, quirks);178 return mir::make_module_ptr<mga::Platform>(buffer_allocator, nullptr, sync_factory, display_report, mga::OverlayOptimization::disabled, quirks);
173}179}
174180
175void add_graphics_platform_options(181void add_graphics_platform_options(
176182
=== modified file 'src/platforms/android/server/platform.h'
--- src/platforms/android/server/platform.h 2015-11-24 12:00:40 +0000
+++ src/platforms/android/server/platform.h 2015-12-02 16:15:28 +0000
@@ -33,6 +33,7 @@
33class GraphicBufferAllocator;33class GraphicBufferAllocator;
34class FramebufferFactory;34class FramebufferFactory;
35class DisplayComponentFactory;35class DisplayComponentFactory;
36class CommandStreamSyncFactory;
3637
37class Platform : public graphics::Platform38class Platform : public graphics::Platform
38{39{
@@ -40,6 +41,7 @@
40 Platform(41 Platform(
41 std::shared_ptr<graphics::GraphicBufferAllocator> const& buffer_allocator,42 std::shared_ptr<graphics::GraphicBufferAllocator> const& buffer_allocator,
42 std::shared_ptr<DisplayComponentFactory> const& display_buffer_builder,43 std::shared_ptr<DisplayComponentFactory> const& display_buffer_builder,
44 std::shared_ptr<CommandStreamSyncFactory> const& sync_factory,
43 std::shared_ptr<DisplayReport> const& display_report,45 std::shared_ptr<DisplayReport> const& display_report,
44 OverlayOptimization overlay_option,46 OverlayOptimization overlay_option,
45 std::shared_ptr<DeviceQuirks> const& quirks);47 std::shared_ptr<DeviceQuirks> const& quirks);
@@ -55,6 +57,7 @@
55private:57private:
56 std::shared_ptr<graphics::GraphicBufferAllocator> const buffer_allocator;58 std::shared_ptr<graphics::GraphicBufferAllocator> const buffer_allocator;
57 std::shared_ptr<DisplayComponentFactory> const display_buffer_builder;59 std::shared_ptr<DisplayComponentFactory> const display_buffer_builder;
60 std::shared_ptr<CommandStreamSyncFactory> const sync_factory;
58 std::shared_ptr<DisplayReport> const display_report;61 std::shared_ptr<DisplayReport> const display_report;
59 std::shared_ptr<PlatformIpcOperations> const ipc_operations;62 std::shared_ptr<PlatformIpcOperations> const ipc_operations;
60 std::shared_ptr<DeviceQuirks> const quirks;63 std::shared_ptr<DeviceQuirks> const quirks;
6164
=== modified file 'src/platforms/mesa/server/common/gbm_buffer.cpp'
--- src/platforms/mesa/server/common/gbm_buffer.cpp 2015-09-22 09:13:59 +0000
+++ src/platforms/mesa/server/common/gbm_buffer.cpp 2015-12-02 16:15:28 +0000
@@ -197,3 +197,12 @@
197{197{
198 return this;198 return this;
199}199}
200
201void mgm::GBMBuffer::secure_for_render()
202{
203}
204
205void mgm::GBMBuffer::bind()
206{
207 gl_bind_to_texture();
208}
200209
=== modified file 'src/platforms/mesa/server/common/gbm_buffer.h'
--- src/platforms/mesa/server/common/gbm_buffer.h 2015-09-04 06:46:36 +0000
+++ src/platforms/mesa/server/common/gbm_buffer.h 2015-12-02 16:15:28 +0000
@@ -67,6 +67,8 @@
67 virtual std::shared_ptr<MirNativeBuffer> native_buffer_handle() const override;67 virtual std::shared_ptr<MirNativeBuffer> native_buffer_handle() const override;
6868
69 virtual void gl_bind_to_texture() override;69 virtual void gl_bind_to_texture() override;
70 virtual void bind() override;
71 virtual void secure_for_render() override;
7072
71 void write(unsigned char const* pixels, size_t size) override;73 void write(unsigned char const* pixels, size_t size) override;
72 void read(std::function<void(unsigned char const*)> const& do_with_pixels) override;74 void read(std::function<void(unsigned char const*)> const& do_with_pixels) override;
7375
=== modified file 'src/platforms/mesa/server/common/shm_buffer.cpp'
--- src/platforms/mesa/server/common/shm_buffer.cpp 2015-08-27 13:41:02 +0000
+++ src/platforms/mesa/server/common/shm_buffer.cpp 2015-12-02 16:15:28 +0000
@@ -176,3 +176,12 @@
176{176{
177 return this;177 return this;
178}178}
179
180void mgm::ShmBuffer::bind()
181{
182 gl_bind_to_texture();
183}
184
185void mgm::ShmBuffer::secure_for_render()
186{
187}
179188
=== modified file 'src/platforms/mesa/server/common/shm_buffer.h'
--- src/platforms/mesa/server/common/shm_buffer.h 2015-09-04 06:46:36 +0000
+++ src/platforms/mesa/server/common/shm_buffer.h 2015-12-02 16:15:28 +0000
@@ -51,6 +51,8 @@
51 MirPixelFormat pixel_format() const override;51 MirPixelFormat pixel_format() const override;
52 std::shared_ptr<MirNativeBuffer> native_buffer_handle() const override;52 std::shared_ptr<MirNativeBuffer> native_buffer_handle() const override;
53 void gl_bind_to_texture() override;53 void gl_bind_to_texture() override;
54 void bind() override;
55 void secure_for_render() override;
54 void write(unsigned char const* data, size_t size) override;56 void write(unsigned char const* data, size_t size) override;
55 void read(std::function<void(unsigned char const*)> const& do_with_pixels) override;57 void read(std::function<void(unsigned char const*)> const& do_with_pixels) override;
56 NativeBufferBase* native_buffer_base() override;58 NativeBufferBase* native_buffer_base() override;
5759
=== modified file 'tests/include/mir/test/doubles/mock_android_native_buffer.h'
--- tests/include/mir/test/doubles/mock_android_native_buffer.h 2015-06-17 05:20:42 +0000
+++ tests/include/mir/test/doubles/mock_android_native_buffer.h 2015-12-02 16:15:28 +0000
@@ -57,6 +57,8 @@
57 MOCK_METHOD1(ensure_available_for, void(graphics::android::BufferAccess));57 MOCK_METHOD1(ensure_available_for, void(graphics::android::BufferAccess));
58 MOCK_METHOD2(update_usage, void(graphics::android::NativeFence&, graphics::android::BufferAccess));58 MOCK_METHOD2(update_usage, void(graphics::android::NativeFence&, graphics::android::BufferAccess));
5959
60 MOCK_METHOD0(lock_for_gpu, void());
61 MOCK_METHOD0(wait_for_unlock_by_gpu, void());
60 ANativeWindowBuffer stub_anwb;62 ANativeWindowBuffer stub_anwb;
61 native_handle_t native_handle;63 native_handle_t native_handle;
62};64};
6365
=== modified file 'tests/include/mir/test/doubles/mock_buffer.h'
--- tests/include/mir/test/doubles/mock_buffer.h 2015-09-01 10:49:48 +0000
+++ tests/include/mir/test/doubles/mock_buffer.h 2015-12-02 16:15:28 +0000
@@ -72,6 +72,7 @@
72 MOCK_METHOD2(write, void(unsigned char const*, size_t));72 MOCK_METHOD2(write, void(unsigned char const*, size_t));
73 MOCK_METHOD1(read, void(std::function<void(unsigned char const*)> const&));73 MOCK_METHOD1(read, void(std::function<void(unsigned char const*)> const&));
74 MOCK_METHOD0(native_buffer_base, graphics::NativeBufferBase*());74 MOCK_METHOD0(native_buffer_base, graphics::NativeBufferBase*());
75 MOCK_METHOD0(used_as_texture, void());
75};76};
7677
77}78}
7879
=== modified file 'tests/include/mir/test/doubles/mock_gl_buffer.h'
--- tests/include/mir/test/doubles/mock_gl_buffer.h 2015-09-04 06:46:36 +0000
+++ tests/include/mir/test/doubles/mock_gl_buffer.h 2015-12-02 16:15:28 +0000
@@ -36,6 +36,8 @@
36 using MockBuffer::MockBuffer;36 using MockBuffer::MockBuffer;
3737
38 MOCK_METHOD0(gl_bind_to_texture, void());38 MOCK_METHOD0(gl_bind_to_texture, void());
39 MOCK_METHOD0(secure_for_render, void());
40 MOCK_METHOD0(bind, void());
39};41};
4042
41}43}
4244
=== modified file 'tests/include/mir/test/doubles/stub_android_native_buffer.h'
--- tests/include/mir/test/doubles/stub_android_native_buffer.h 2015-05-29 17:53:49 +0000
+++ tests/include/mir/test/doubles/stub_android_native_buffer.h 2015-12-02 16:15:28 +0000
@@ -47,6 +47,9 @@
47 void ensure_available_for(graphics::android::BufferAccess) {}47 void ensure_available_for(graphics::android::BufferAccess) {}
48 void update_usage(graphics::android::NativeFence&, graphics::android::BufferAccess) {}48 void update_usage(graphics::android::NativeFence&, graphics::android::BufferAccess) {}
4949
50 void lock_for_gpu() {};
51 void wait_for_unlock_by_gpu() {};
52
50 ANativeWindowBuffer stub_anwb;53 ANativeWindowBuffer stub_anwb;
51 native_handle_t native_handle;54 native_handle_t native_handle;
52};55};
5356
=== added file 'tests/include/mir/test/doubles/stub_cmdstream_sync_factory.h'
--- tests/include/mir/test/doubles/stub_cmdstream_sync_factory.h 1970-01-01 00:00:00 +0000
+++ tests/include/mir/test/doubles/stub_cmdstream_sync_factory.h 2015-12-02 16:15:28 +0000
@@ -0,0 +1,41 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17 */
18
19#ifndef MIR_TEST_DOUBLES_STUB_CMDSTREAM_SYNC_FACTORY_H_
20#define MIR_TEST_DOUBLES_STUB_CMDSTREAM_SYNC_FACTORY_H_
21
22#include "src/platforms/android/server/cmdstream_sync_factory.h"
23
24namespace mir
25{
26namespace test
27{
28namespace doubles
29{
30struct StubCmdStreamSyncFactory : graphics::android::CommandStreamSyncFactory
31{
32 std::unique_ptr<graphics::CommandStreamSync> create_command_stream_sync() override
33 {
34 return std::make_unique<graphics::NullCommandSync>();
35 }
36};
37}
38}
39}
40
41#endif /* MIR_TEST_DOUBLES_STUB_CMDSTREAM_SYNC_FACTORY_H_ */
042
=== modified file 'tests/include/mir/test/doubles/stub_display_builder.h'
--- tests/include/mir/test/doubles/stub_display_builder.h 2015-11-18 15:03:00 +0000
+++ tests/include/mir/test/doubles/stub_display_builder.h 2015-12-02 16:15:28 +0000
@@ -126,6 +126,11 @@
126 config = std::move(mock_config); 126 config = std::move(mock_config);
127 }127 }
128128
129 std::unique_ptr<graphics::CommandStreamSync> create_command_stream_sync()
130 {
131 return std::make_unique<graphics::NullCommandSync>();
132 }
133
129 geometry::Size sz;134 geometry::Size sz;
130 std::unique_ptr<graphics::android::HwcConfiguration> config;135 std::unique_ptr<graphics::android::HwcConfiguration> config;
131};136};
132137
=== modified file 'tests/include/mir/test/doubles/stub_gl_buffer.h'
--- tests/include/mir/test/doubles/stub_gl_buffer.h 2015-09-04 06:46:36 +0000
+++ tests/include/mir/test/doubles/stub_gl_buffer.h 2015-12-02 16:15:28 +0000
@@ -36,6 +36,8 @@
36 using StubBuffer::StubBuffer;36 using StubBuffer::StubBuffer;
3737
38 void gl_bind_to_texture() {}38 void gl_bind_to_texture() {}
39 void bind() {}
40 void secure_for_render() {}
39};41};
4042
41}43}
4244
=== modified file 'tests/integration-tests/graphics/mesa/test_buffer_integration.cpp'
--- tests/integration-tests/graphics/mesa/test_buffer_integration.cpp 2015-11-02 21:56:56 +0000
+++ tests/integration-tests/graphics/mesa/test_buffer_integration.cpp 2015-12-02 16:15:28 +0000
@@ -77,6 +77,9 @@
77 }77 }
78 }78 }
7979
80 void bind() override { gl_bind_to_texture(); }
81 void secure_for_render() override {}
82
80private:83private:
81 std::thread::id creation_thread_id;84 std::thread::id creation_thread_id;
82};85};
8386
=== modified file 'tests/unit-tests/gl/test_gl_texture_cache.cpp'
--- tests/unit-tests/gl/test_gl_texture_cache.cpp 2015-10-06 02:30:52 +0000
+++ tests/unit-tests/gl/test_gl_texture_cache.cpp 2015-12-02 16:15:28 +0000
@@ -17,7 +17,7 @@
17 * Originally by: Daniel van Vugt <daniel.van.vugt@canonical.com>17 * Originally by: Daniel van Vugt <daniel.van.vugt@canonical.com>
18 */18 */
1919
20#include "mir/gl/recently_used_cache.h"20#include "src/gl/recently_used_cache.h"
21#include "mir/test/doubles/mock_gl_buffer.h"21#include "mir/test/doubles/mock_gl_buffer.h"
22#include "mir/test/doubles/mock_renderable.h"22#include "mir/test/doubles/mock_renderable.h"
23#include "mir/test/doubles/mock_gl.h"23#include "mir/test/doubles/mock_gl.h"
@@ -75,6 +75,7 @@
75 EXPECT_CALL(mock_gl, glBindTexture(GL_TEXTURE_2D, stub_texture));75 EXPECT_CALL(mock_gl, glBindTexture(GL_TEXTURE_2D, stub_texture));
76 EXPECT_CALL(*mock_buffer,gl_bind_to_texture())76 EXPECT_CALL(*mock_buffer,gl_bind_to_texture())
77 .Times(0);77 .Times(0);
78 EXPECT_CALL(*mock_buffer, used_as_texture());
7879
79 // Frame 3: Texture found in cache but refreshed with new buffer80 // Frame 3: Texture found in cache but refreshed with new buffer
80 EXPECT_CALL(*mock_buffer, id())81 EXPECT_CALL(*mock_buffer, id())
@@ -92,6 +93,7 @@
92 EXPECT_CALL(*mock_buffer, id())93 EXPECT_CALL(*mock_buffer, id())
93 .WillOnce(Return(mg::BufferID(456)));94 .WillOnce(Return(mg::BufferID(456)));
94 EXPECT_CALL(mock_gl, glBindTexture(GL_TEXTURE_2D, stub_texture));95 EXPECT_CALL(mock_gl, glBindTexture(GL_TEXTURE_2D, stub_texture));
96 EXPECT_CALL(*mock_buffer, used_as_texture());
9597
96 EXPECT_CALL(mock_gl, glDeleteTextures(1, Pointee(stub_texture)));98 EXPECT_CALL(mock_gl, glDeleteTextures(1, Pointee(stub_texture)));
9799
98100
=== modified file 'tests/unit-tests/gl/test_program_factory.cpp'
--- tests/unit-tests/gl/test_program_factory.cpp 2015-10-06 02:30:52 +0000
+++ tests/unit-tests/gl/test_program_factory.cpp 2015-12-02 16:15:28 +0000
@@ -24,7 +24,7 @@
24#include <gtest/gtest.h>24#include <gtest/gtest.h>
25#include <gmock/gmock.h>25#include <gmock/gmock.h>
26#include <mir/geometry/rectangle.h>26#include <mir/geometry/rectangle.h>
27#include "src/gl/default_program_factory.h"27#include "mir/gl/default_program_factory.h"
28#include <mir/test/fake_shared.h>28#include <mir/test/fake_shared.h>
29#include <mir/test/doubles/mock_buffer.h>29#include <mir/test/doubles/mock_buffer.h>
30#include <mir/test/doubles/mock_renderable.h>30#include <mir/test/doubles/mock_renderable.h>
3131
=== modified file 'tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp'
--- tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp 2015-08-07 15:55:22 +0000
+++ tests/unit-tests/graphics/android/test_android_alloc_adaptor.cpp 2015-12-02 16:15:28 +0000
@@ -17,11 +17,13 @@
17 */17 */
1818
19#include "src/platforms/android/server/android_alloc_adaptor.h"19#include "src/platforms/android/server/android_alloc_adaptor.h"
20#include "src/platforms/android/server/cmdstream_sync_factory.h"
20#include "src/platforms/android/server/device_quirks.h"21#include "src/platforms/android/server/device_quirks.h"
21#include "mir/graphics/android/native_buffer.h"22#include "mir/graphics/android/native_buffer.h"
2223
23#include "mir/test/doubles/mock_android_alloc_device.h"24#include "mir/test/doubles/mock_android_alloc_device.h"
24#include "mir/test/doubles/mock_alloc_adaptor.h"25#include "mir/test/doubles/mock_alloc_adaptor.h"
26#include "mir/test/doubles/mock_egl.h"
2527
26#include <gtest/gtest.h>28#include <gtest/gtest.h>
27#include <gmock/gmock.h>29#include <gmock/gmock.h>
@@ -32,7 +34,6 @@
32namespace geom = mir::geometry;34namespace geom = mir::geometry;
33namespace mtd = mir::test::doubles;35namespace mtd = mir::test::doubles;
3436
35
36class AdaptorICSTest : public ::testing::Test37class AdaptorICSTest : public ::testing::Test
37{38{
38public:39public:
@@ -48,13 +49,15 @@
48 mock_alloc_device = std::make_shared<NiceMock<mtd::MockAllocDevice>>();49 mock_alloc_device = std::make_shared<NiceMock<mtd::MockAllocDevice>>();
4950
50 auto quirks = std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{});51 auto quirks = std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{});
51 alloc_adaptor = std::make_shared<mga::AndroidAllocAdaptor>(mock_alloc_device, quirks);52 alloc_adaptor = std::make_shared<mga::AndroidAllocAdaptor>(mock_alloc_device, sync_factory, quirks);
5253
53 pf = mir_pixel_format_abgr_8888;54 pf = mir_pixel_format_abgr_8888;
54 size = geom::Size{300, 200};55 size = geom::Size{300, 200};
55 usage = mga::BufferUsage::use_hardware;56 usage = mga::BufferUsage::use_hardware;
56 }57 }
5758
59 mtd::MockEGL mock_egl;
60 std::shared_ptr<mga::CommandStreamSyncFactory> sync_factory{std::make_shared<mga::EGLSyncFactory>()};
58 std::shared_ptr<mtd::MockAllocDevice> mock_alloc_device;61 std::shared_ptr<mtd::MockAllocDevice> mock_alloc_device;
59 std::shared_ptr<mga::AndroidAllocAdaptor> alloc_adaptor;62 std::shared_ptr<mga::AndroidAllocAdaptor> alloc_adaptor;
6063
6164
=== modified file 'tests/unit-tests/graphics/android/test_android_buffer_allocator.cpp'
--- tests/unit-tests/graphics/android/test_android_buffer_allocator.cpp 2015-08-07 15:55:22 +0000
+++ tests/unit-tests/graphics/android/test_android_buffer_allocator.cpp 2015-12-02 16:15:28 +0000
@@ -23,6 +23,8 @@
23#include "mir/graphics/buffer.h"23#include "mir/graphics/buffer.h"
24#include "mir/graphics/android/native_buffer.h"24#include "mir/graphics/android/native_buffer.h"
2525
26#include "mir/test/doubles/stub_display_builder.h"
27#include "mir/test/doubles/stub_cmdstream_sync_factory.h"
26#include "mir/test/doubles/mock_egl.h"28#include "mir/test/doubles/mock_egl.h"
2729
28#include <hardware/gralloc.h>30#include <hardware/gralloc.h>
@@ -43,7 +45,9 @@
4345
44 testing::NiceMock<mtd::HardwareAccessMock> hw_access_mock;46 testing::NiceMock<mtd::HardwareAccessMock> hw_access_mock;
45 testing::NiceMock<mtd::MockEGL> mock_egl;47 testing::NiceMock<mtd::MockEGL> mock_egl;
46 mga::AndroidGraphicBufferAllocator allocator{std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{})};48 mga::AndroidGraphicBufferAllocator allocator{
49 std::make_shared<mtd::StubCmdStreamSyncFactory>(),
50 std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{})};
47};51};
4852
49TEST_F(AndroidGraphicBufferAllocatorTest, allocator_accesses_gralloc_module)53TEST_F(AndroidGraphicBufferAllocatorTest, allocator_accesses_gralloc_module)
@@ -54,7 +58,7 @@
54 .Times(1);58 .Times(1);
5559
56 auto quirks = std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{});60 auto quirks = std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{});
57 mga::AndroidGraphicBufferAllocator allocator{quirks};61 mga::AndroidGraphicBufferAllocator allocator{std::make_shared<mtd::StubCmdStreamSyncFactory>(), quirks};
58}62}
5963
60TEST_F(AndroidGraphicBufferAllocatorTest, supported_pixel_formats_contain_common_formats)64TEST_F(AndroidGraphicBufferAllocatorTest, supported_pixel_formats_contain_common_formats)
6165
=== modified file 'tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp'
--- tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp 2015-06-25 03:00:08 +0000
+++ tests/unit-tests/graphics/android/test_buffer_tex_bind.cpp 2015-12-02 16:15:28 +0000
@@ -289,7 +289,7 @@
289289
290290
291/* binding tests */291/* binding tests */
292TEST_F(AndroidBufferBinding, buffer_calls_binding_extension)292TEST_F(AndroidBufferBinding, buffer_calls_binding_extension_and_notes_gpu_usage)
293{293{
294 using namespace testing;294 using namespace testing;
295 EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, _))295 EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, _))
@@ -298,11 +298,23 @@
298 buffer.gl_bind_to_texture();298 buffer.gl_bind_to_texture();
299}299}
300300
301TEST_F(AndroidBufferBinding, notes_gpu_usage_when_explicity_told)
302{
303 using namespace testing;
304 EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, _))
305 .Times(0);
306 EXPECT_CALL(*mock_native_buffer, lock_for_gpu());
307 mga::Buffer buffer(gralloc, mock_native_buffer, extensions);
308 buffer.secure_for_render();
309}
310
301TEST_F(AndroidBufferBinding, buffer_calls_binding_extension_every_time)311TEST_F(AndroidBufferBinding, buffer_calls_binding_extension_every_time)
302{312{
303 using namespace testing;313 using namespace testing;
304 EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, _))314 EXPECT_CALL(mock_egl, glEGLImageTargetTexture2DOES(_, _))
305 .Times(Exactly(3));315 .Times(Exactly(3));
316 EXPECT_CALL(*mock_native_buffer, lock_for_gpu())
317 .Times(Exactly(3));
306318
307 mga::Buffer buffer(gralloc, mock_native_buffer, extensions);319 mga::Buffer buffer(gralloc, mock_native_buffer, extensions);
308 buffer.gl_bind_to_texture();320 buffer.gl_bind_to_texture();
309321
=== modified file 'tests/unit-tests/graphics/android/test_display_hotplug.cpp'
--- tests/unit-tests/graphics/android/test_display_hotplug.cpp 2015-10-06 02:30:52 +0000
+++ tests/unit-tests/graphics/android/test_display_hotplug.cpp 2015-12-02 16:15:28 +0000
@@ -103,6 +103,11 @@
103 new mga::LayerList(std::make_shared<mga::IntegerSourceCrop>(), {}, geom::Displacement{}));103 new mga::LayerList(std::make_shared<mga::IntegerSourceCrop>(), {}, geom::Displacement{}));
104 }104 }
105105
106 std::unique_ptr<mg::CommandStreamSync> create_command_stream_sync()
107 {
108 return nullptr;
109 }
110
106 StubHwcConfig stub_config;111 StubHwcConfig stub_config;
107 };112 };
108113
109114
=== modified file 'tests/unit-tests/graphics/android/test_native_buffer.cpp'
--- tests/unit-tests/graphics/android/test_native_buffer.cpp 2015-06-25 03:00:08 +0000
+++ tests/unit-tests/graphics/android/test_native_buffer.cpp 2015-12-02 16:15:28 +0000
@@ -17,25 +17,41 @@
17 */17 */
1818
19#include "mir/graphics/android/android_native_buffer.h"19#include "mir/graphics/android/android_native_buffer.h"
20#include "mir/graphics/egl_sync_fence.h"
20#include "mir/test/doubles/mock_fence.h"21#include "mir/test/doubles/mock_fence.h"
21#include <memory>22#include <memory>
22#include <gtest/gtest.h>23#include <gtest/gtest.h>
2324
24namespace mtd=mir::test::doubles;25namespace mtd=mir::test::doubles;
25namespace mga=mir::graphics::android;26namespace mga=mir::graphics::android;
27using namespace testing;
28
29namespace
30{
31struct MockCommandStreamSync : public mir::graphics::CommandStreamSync
32{
33 MOCK_METHOD0(raise, void());
34 MOCK_METHOD0(reset, void());
35 MOCK_METHOD1(wait_for, bool(std::chrono::nanoseconds));
36};
37}
2638
27struct NativeBuffer : public testing::Test39struct NativeBuffer : public testing::Test
28{40{
29 NativeBuffer() :41 NativeBuffer() :
30 a_native_window_buffer(std::make_shared<ANativeWindowBuffer>()),42 a_native_window_buffer(std::make_shared<ANativeWindowBuffer>()),
31 mock_fence(std::make_shared<testing::NiceMock<mtd::MockFence>>()),43 mock_fence(std::make_shared<testing::NiceMock<mtd::MockFence>>()),
32 fake_fd{48484}44 fake_fd{48484},
45 timeout{std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::seconds(2))},
46 mock_cmdstream_sync{std::make_shared<MockCommandStreamSync>()}
33 {47 {
34 }48 }
3549
36 std::shared_ptr<ANativeWindowBuffer> a_native_window_buffer;50 std::shared_ptr<ANativeWindowBuffer> a_native_window_buffer;
37 std::shared_ptr<mtd::MockFence> mock_fence;51 std::shared_ptr<mtd::MockFence> mock_fence;
38 int fake_fd;52 int fake_fd;
53 std::chrono::nanoseconds timeout;
54 std::shared_ptr<MockCommandStreamSync> mock_cmdstream_sync;
39};55};
4056
41TEST_F(NativeBuffer, extends_lifetime_when_driver_calls_external_refcount_hooks)57TEST_F(NativeBuffer, extends_lifetime_when_driver_calls_external_refcount_hooks)
@@ -88,7 +104,7 @@
88{104{
89 EXPECT_CALL(*mock_fence, wait())105 EXPECT_CALL(*mock_fence, wait())
90 .Times(0);106 .Times(0);
91 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::read);107 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read);
92 buffer.ensure_available_for(mga::BufferAccess::read);108 buffer.ensure_available_for(mga::BufferAccess::read);
93}109}
94110
@@ -96,7 +112,7 @@
96{112{
97 EXPECT_CALL(*mock_fence, wait())113 EXPECT_CALL(*mock_fence, wait())
98 .Times(1);114 .Times(1);
99 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::write);115 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::write);
100 buffer.ensure_available_for(mga::BufferAccess::read);116 buffer.ensure_available_for(mga::BufferAccess::read);
101}117}
102118
@@ -104,7 +120,7 @@
104{120{
105 EXPECT_CALL(*mock_fence, wait())121 EXPECT_CALL(*mock_fence, wait())
106 .Times(1);122 .Times(1);
107 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::read);123 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read);
108 buffer.ensure_available_for(mga::BufferAccess::write);124 buffer.ensure_available_for(mga::BufferAccess::write);
109}125}
110126
@@ -112,7 +128,7 @@
112{128{
113 EXPECT_CALL(*mock_fence, wait())129 EXPECT_CALL(*mock_fence, wait())
114 .Times(1);130 .Times(1);
115 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::write);131 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::write);
116 buffer.ensure_available_for(mga::BufferAccess::write);132 buffer.ensure_available_for(mga::BufferAccess::write);
117}133}
118134
@@ -120,7 +136,7 @@
120{136{
121 EXPECT_CALL(*mock_fence, merge_with(fake_fd))137 EXPECT_CALL(*mock_fence, merge_with(fake_fd))
122 .Times(1);138 .Times(1);
123 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::read);139 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read);
124 buffer.update_usage(fake_fd, mga::BufferAccess::write);140 buffer.update_usage(fake_fd, mga::BufferAccess::write);
125}141}
126142
@@ -129,7 +145,7 @@
129 EXPECT_CALL(*mock_fence, wait())145 EXPECT_CALL(*mock_fence, wait())
130 .Times(3);146 .Times(3);
131147
132 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_fence, mga::BufferAccess::read);148 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read);
133 buffer.ensure_available_for(mga::BufferAccess::write);149 buffer.ensure_available_for(mga::BufferAccess::write);
134 buffer.ensure_available_for(mga::BufferAccess::read);150 buffer.ensure_available_for(mga::BufferAccess::read);
135151
@@ -137,3 +153,30 @@
137 buffer.ensure_available_for(mga::BufferAccess::write);153 buffer.ensure_available_for(mga::BufferAccess::write);
138 buffer.ensure_available_for(mga::BufferAccess::read);154 buffer.ensure_available_for(mga::BufferAccess::read);
139}155}
156
157TEST_F(NativeBuffer, raises_egl_fence)
158{
159 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read);
160
161 EXPECT_CALL(*mock_cmdstream_sync, raise());
162 buffer.lock_for_gpu();
163}
164
165TEST_F(NativeBuffer, clears_egl_fence_successfully)
166{
167 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read);
168 EXPECT_CALL(*mock_cmdstream_sync, wait_for(timeout))
169 .Times(1)
170 .WillOnce(Return(true));
171 buffer.wait_for_unlock_by_gpu();
172}
173
174//not really helpful to throw if the timeout fails
175TEST_F(NativeBuffer, ignores_clears_egl_fence_failure)
176{
177 mga::AndroidNativeBuffer buffer(a_native_window_buffer, mock_cmdstream_sync, mock_fence, mga::BufferAccess::read);
178 EXPECT_CALL(*mock_cmdstream_sync, wait_for(timeout))
179 .Times(1)
180 .WillOnce(Return(false));
181 buffer.wait_for_unlock_by_gpu();
182}
140183
=== modified file 'tests/unit-tests/graphics/android/test_platform.cpp'
--- tests/unit-tests/graphics/android/test_platform.cpp 2015-11-24 12:00:40 +0000
+++ tests/unit-tests/graphics/android/test_platform.cpp 2015-12-02 16:15:28 +0000
@@ -26,6 +26,7 @@
26#include "mir/test/doubles/mock_display_report.h"26#include "mir/test/doubles/mock_display_report.h"
27#include "mir/test/doubles/mock_egl.h"27#include "mir/test/doubles/mock_egl.h"
28#include "mir/test/doubles/stub_display_builder.h"28#include "mir/test/doubles/stub_display_builder.h"
29#include "mir/test/doubles/stub_cmdstream_sync_factory.h"
29#include "mir/test/doubles/fd_matcher.h"30#include "mir/test/doubles/fd_matcher.h"
30#include "mir/test/fake_shared.h"31#include "mir/test/fake_shared.h"
31#include "mir/test/doubles/mock_android_native_buffer.h"32#include "mir/test/doubles/mock_android_native_buffer.h"
@@ -54,6 +55,7 @@
54 using namespace testing;55 using namespace testing;
5556
56 stub_display_builder = std::make_shared<mtd::StubDisplayBuilder>();57 stub_display_builder = std::make_shared<mtd::StubDisplayBuilder>();
58 stub_sync_factory = std::make_shared<mtd::StubCmdStreamSyncFactory>();
57 stub_display_report = mr::null_display_report();59 stub_display_report = mr::null_display_report();
58 stride = geom::Stride(300*4);60 stride = geom::Stride(300*4);
5961
@@ -86,6 +88,7 @@
86 std::shared_ptr<mtd::MockAndroidNativeBuffer> native_buffer;88 std::shared_ptr<mtd::MockAndroidNativeBuffer> native_buffer;
87 std::shared_ptr<mtd::StubBufferAllocator> stub_buffer_allocator;89 std::shared_ptr<mtd::StubBufferAllocator> stub_buffer_allocator;
88 std::shared_ptr<mtd::StubDisplayBuilder> stub_display_builder;90 std::shared_ptr<mtd::StubDisplayBuilder> stub_display_builder;
91 std::shared_ptr<mtd::StubCmdStreamSyncFactory> stub_sync_factory;
89 std::shared_ptr<mtd::MockBuffer> mock_buffer;92 std::shared_ptr<mtd::MockBuffer> mock_buffer;
90 std::shared_ptr<native_handle_t> native_buffer_handle;93 std::shared_ptr<native_handle_t> native_buffer_handle;
91 std::shared_ptr<mg::DisplayReport> stub_display_report;94 std::shared_ptr<mg::DisplayReport> stub_display_report;
@@ -99,10 +102,12 @@
99{102{
100 using namespace ::testing;103 using namespace ::testing;
101 int fake_fence{333};104 int fake_fence{333};
105 EXPECT_CALL(*native_buffer, wait_for_unlock_by_gpu());
102 EXPECT_CALL(*native_buffer, copy_fence())106 EXPECT_CALL(*native_buffer, copy_fence())
103 .WillOnce(Return(fake_fence));107 .WillOnce(Return(fake_fence));
104108
105 mga::Platform platform(stub_buffer_allocator, stub_display_builder, stub_display_report, mga::OverlayOptimization::enabled, quirks);109 mga::Platform platform(stub_buffer_allocator, stub_display_builder,
110 stub_sync_factory, stub_display_report, mga::OverlayOptimization::enabled, quirks);
106111
107 mtd::MockBufferIpcMessage mock_ipc_msg;112 mtd::MockBufferIpcMessage mock_ipc_msg;
108 int offset = 0;113 int offset = 0;
@@ -130,10 +135,12 @@
130TEST_F(PlatformBufferIPCPackaging, test_ipc_data_packed_correctly_for_full_ipc_without_fence)135TEST_F(PlatformBufferIPCPackaging, test_ipc_data_packed_correctly_for_full_ipc_without_fence)
131{136{
132 using namespace ::testing;137 using namespace ::testing;
138 EXPECT_CALL(*native_buffer, wait_for_unlock_by_gpu());
133 EXPECT_CALL(*native_buffer, copy_fence())139 EXPECT_CALL(*native_buffer, copy_fence())
134 .WillOnce(Return(-1));140 .WillOnce(Return(-1));
135141
136 mga::Platform platform(stub_buffer_allocator, stub_display_builder, stub_display_report, mga::OverlayOptimization::enabled, quirks);142 mga::Platform platform(stub_buffer_allocator, stub_display_builder,
143 stub_sync_factory, stub_display_report, mga::OverlayOptimization::enabled, quirks);
137144
138 mtd::MockBufferIpcMessage mock_ipc_msg;145 mtd::MockBufferIpcMessage mock_ipc_msg;
139 int offset = 0;146 int offset = 0;
@@ -169,10 +176,12 @@
169TEST_F(PlatformBufferIPCPackaging, test_ipc_data_packed_correctly_for_nested)176TEST_F(PlatformBufferIPCPackaging, test_ipc_data_packed_correctly_for_nested)
170{177{
171 using namespace ::testing;178 using namespace ::testing;
179 EXPECT_CALL(*native_buffer, wait_for_unlock_by_gpu());
172 EXPECT_CALL(*native_buffer, copy_fence())180 EXPECT_CALL(*native_buffer, copy_fence())
173 .WillOnce(Return(-1));181 .WillOnce(Return(-1));
174182
175 mga::Platform platform(stub_buffer_allocator, stub_display_builder, stub_display_report, mga::OverlayOptimization::enabled, quirks);183 mga::Platform platform(stub_buffer_allocator, stub_display_builder,
184 stub_sync_factory, stub_display_report, mga::OverlayOptimization::enabled, quirks);
176185
177 mtd::MockBufferIpcMessage mock_ipc_msg;186 mtd::MockBufferIpcMessage mock_ipc_msg;
178 int offset = 0;187 int offset = 0;
@@ -207,7 +216,8 @@
207 using namespace ::testing;216 using namespace ::testing;
208217
209 int fake_fence{33};218 int fake_fence{33};
210 mga::Platform platform(stub_buffer_allocator, stub_display_builder, stub_display_report, mga::OverlayOptimization::enabled, quirks);219 mga::Platform platform(stub_buffer_allocator, stub_display_builder,
220 stub_sync_factory, stub_display_report, mga::OverlayOptimization::enabled, quirks);
211 auto ipc_ops = platform.make_ipc_operations();221 auto ipc_ops = platform.make_ipc_operations();
212222
213 mtd::MockBufferIpcMessage mock_ipc_msg;223 mtd::MockBufferIpcMessage mock_ipc_msg;
@@ -234,6 +244,7 @@
234 mga::Platform platform(244 mga::Platform platform(
235 std::make_shared<mtd::StubBufferAllocator>(),245 std::make_shared<mtd::StubBufferAllocator>(),
236 std::make_shared<mtd::StubDisplayBuilder>(),246 std::make_shared<mtd::StubDisplayBuilder>(),
247 std::make_shared<mtd::StubCmdStreamSyncFactory>(),
237 mr::null_display_report(),248 mr::null_display_report(),
238 mga::OverlayOptimization::enabled,249 mga::OverlayOptimization::enabled,
239 std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{}));250 std::make_shared<mga::DeviceQuirks>(mga::PropertiesOps{}));

Subscribers

People subscribed via source and target branches