Fix potential GLThread / GLSurfaceView memory leak.

Until now a leak was possible under the following scenario:

Create a GLSurfaceView
Register a renderer (this automatically starts a GLThread).
Discard the GLSurfaceView without installing it in the view system.

This scenario can occur when a device is rotated rapidly from
orientation A to orientation B to orientation C. In that scenario,
orientation B's GLSurfaceView might be discarded without ever being
attached to a window.

If this issue had been identified before GLSurfaceView had clients, one
possible fix would have been to delay the construction of the GLThread
until the GLSurfaceView was attached to a window. Unfortunately, it's
too late, and so making that change would lead to observable changes in
behavior, possibly breaking some clients.

Instead, fixed by making GLThread and EGLHelper static classes that hold
onto a weak reference to the GLSurfaceView. This allows the GLSurfaceView
to be garbage collected when it is no longer used, even if the GLThread
is active. GLSurfaceView's finalize method will manually stop the GLThread
if it is still running when the GLSurfaceView exits.

Part of this change was to remove the Renderer reference from GLThread,
because Renderer is a user-supplied class that could contain a reference
chain that points back to the GLSurfaceView.

Fixes b/5606613 "GLSurfaceView that's never added to a window will
leak threads and views, can leak activities"

Change-Id: Iafdc329eb6e9e40062358e7c119f5547ffe23d5e
1 file changed