Don't leave gralloc-only host connections hanging.

bug: 29318455

Memory leaks are becoming more of a problem, especially
with host machines that don't have much RAM and when
we use the emulator for long periods of time.

This CL fixes the problem detailed in the bug link,
which is that the number of render threads
(and thus thread-specific storage) skyrockets when
repeatedly pressing the Recents button while an app is active.

The thing is that there are lots of threads
that never use the EGL display, just gralloc, in order
to do gralloc things like update the screenshot display
of apps in recents.

These threads are not cleaned up because a thread pool
is often used to manage these sorts of tasks.
If a new or different thread suddenly wants to update
the recents screenshots through gralloc, a new connection
will be established.

This CL uses gralloc_unregister_buffer as a signal
for when a thread might be done with gralloc in general,
exiting the host connection immediately.

Of course, there may be other things that the thread wants
to do, but then it can just go ahead and create a new connection.

We also use the heuristic that we do not exit on gralloc_unregister_buffer
when the thread seems to be a bona fide rendering thread
(eglInitialize has been called).

There are still more leaks going on, this fixes just
one source of them.

After this CL, the render thread count should be held constant
when repeatedly starting apps and going to recents.

Change-Id: I5f57539429f149e3a938467e3b82fa911ab118c3
4 files changed
tree: c472067085956be2b7647d5cd7d05e6c999ab303
  1. host/
  2. shared/
  3. system/
  4. tests/
  5. Android.mk
  6. common.mk
  7. README