Mir

Merge lp:~afrantzis/mir/android-fix-memory-error into lp:~mir-team/mir/trunk

Proposed by Alexandros Frantzis
Status: Rejected
Rejected by: Alexandros Frantzis
Proposed branch: lp:~afrantzis/mir/android-fix-memory-error
Merge into: lp:~mir-team/mir/trunk
Diff against target: 68 lines (+7/-19)
2 files modified
src/server/graphics/android/android_platform.cpp (+2/-2)
tests/integration-tests/graphics/android/test_buffer_integration.cpp (+5/-17)
To merge this branch: bzr merge lp:~afrantzis/mir/android-fix-memory-error
Reviewer Review Type Date Requested Status
Kevin DuBois (community) Disapprove
PS Jenkins bot (community) continuous-integration Approve
Mir development team Pending
Review via email: mp+153331@code.launchpad.net

Commit message

android: Fix memory error

Description of the change

android: Fix memory error

Note: The conclusions below are based solely on experimentation on the Nexus 4.
Kevin could you please validate that this works properly on the Galaxy Nexus, too?

The native window associated with an EGLSurface is deallocated automatically
by the system when the EGLSurface is destroyed. Deallocating it manually
leads to memory errors and causes all kinds of interesting side effects.

One of these side effects seems to be that we can't create and destroy an
AndroidDisplay multiple times in a process, which forced us to create the display
statically in some integration tests. Since the error is now fixed, we can
remove the workaround and create the AndroidDisplay normally.

To post a comment you must log in.
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 found something strange was going on yesterday with this bit of code too... will try out this branch

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

okay, this is a weird problem that points out the problem of using android types. We pull then nativewindow type over hybris using a c-type, which casts away the ability to use the FramebufferNativeWindow's destructors. If we cast back to this type, we have to use FramebufferNativeWindow's private destructor, which isn't possible to pull over hybris.
*sigh*

you're right that we can't manage this object's deletion with our std::shared_ptr... but we also don't have a route to free up the framebuffers. (other than the process dying, where the kernel will free them up)

long story short.... this problem hits 'the perfect storm' of hybris limitations and silly android classes.
I just ported the annoying class over into our 3rd party, hope to mp, kill the strange dependency, and make multithreaded compositor landable for android.

I'm going to disapprove, in favor of porting the type over

review: Disapprove
Revision history for this message
Kevin DuBois (kdub) wrote :
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> you're right that we can't manage this object's deletion with our
> std::shared_ptr... but we also don't have a route to free up the framebuffers.
> (other than the process dying, where the kernel will free them up)

From my experimentation, I was given the impression that the native window type
is freed when the associated EGLSurface is destroyed. Is this not the case?

> long story short.... this problem hits 'the perfect storm' of hybris
> limitations and silly android classes.
> I just ported the annoying class over into our 3rd party, hope to mp, kill the
> strange dependency, and make multithreaded compositor landable for android.
>
> I'm going to disapprove, in favor of porting the type over

Always happy for a better way of doing things :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/server/graphics/android/android_platform.cpp'
2--- src/server/graphics/android/android_platform.cpp 2013-03-07 08:04:05 +0000
3+++ src/server/graphics/android/android_platform.cpp 2013-03-14 11:29:30 +0000
4@@ -40,10 +40,10 @@
5 return std::make_shared<mga::AndroidBufferAllocator>();
6 }
7
8-/* note: gralloc seems to choke when this is opened/closed more than once per process. must investigate drivers further */
9 std::shared_ptr<mg::Display> mga::AndroidPlatform::create_display()
10 {
11- auto android_window = std::shared_ptr<ANativeWindow>(android_createDisplaySurface());
12+ auto android_window = std::shared_ptr<ANativeWindow>(android_createDisplaySurface(),
13+ [](ANativeWindow*) {});
14 if (!android_window.get())
15 BOOST_THROW_EXCEPTION(std::runtime_error("could not open FB window"));
16 auto window = std::make_shared<mga::AndroidFramebufferWindow> (android_window);
17
18=== modified file 'tests/integration-tests/graphics/android/test_buffer_integration.cpp'
19--- tests/integration-tests/graphics/android/test_buffer_integration.cpp 2013-03-13 07:41:46 +0000
20+++ tests/integration-tests/graphics/android/test_buffer_integration.cpp 2013-03-14 11:29:30 +0000
21@@ -49,17 +49,12 @@
22 static void SetUpTestCase()
23 {
24 ASSERT_FALSE(mtd::is_surface_flinger_running());
25- ASSERT_NO_THROW(
26- {
27- platform = mg::create_platform(std::make_shared<mg::NullDisplayReport>());
28- display = platform->create_display();
29- });
30 }
31
32 virtual void SetUp()
33 {
34- ASSERT_TRUE(platform != NULL);
35- ASSERT_TRUE(display != NULL);
36+ platform = mg::create_platform(std::make_shared<mg::NullDisplayReport>());
37+ display = platform->create_display();
38
39 auto buffer_initializer = std::make_shared<mg::NullBufferInitializer>();
40 allocator = platform->create_buffer_allocator(buffer_initializer);
41@@ -70,24 +65,17 @@
42 buffer_properties = mc::BufferProperties{size, pf, mc::BufferUsage::software};
43 }
44
45- md::glAnimationBasic gl_animation;
46+ std::shared_ptr<mg::Platform> platform;
47+ std::shared_ptr<mg::Display> display;
48 std::shared_ptr<mc::GraphicBufferAllocator> allocator;
49 std::shared_ptr<mc::SwapperFactory> strategy;
50+ md::glAnimationBasic gl_animation;
51 geom::Size size;
52 geom::PixelFormat pf;
53 mc::BufferProperties buffer_properties;
54 mtd::TestGrallocMapper sw_renderer;
55-
56- /* note about display: android drivers seem to only be able to open fb once
57- per process (gralloc's framebuffer_close() doesn't seem to work). once we
58- figure out why, we can put display in the test fixture */
59- static std::shared_ptr<mg::Platform> platform;
60- static std::shared_ptr<mg::Display> display;
61 };
62
63-std::shared_ptr<mg::Display> AndroidBufferIntegration::display;
64-std::shared_ptr<mg::Platform> AndroidBufferIntegration::platform;
65-
66 }
67
68 TEST_F(AndroidBufferIntegration, post_does_not_throw)

Subscribers

People subscribed via source and target branches