History log of /frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
1b4ecc63c4eceb7c125d4e749fd5f747d99d6ec6 14-Jul-2010 Jack Palevich <jackpal@google.com> Fix deadlock when switching between two GLSurfaceViews

Some devices only support a single active EGL context.

On those devices, when a second activity that uses a GLSurfaceView
is started in the same process, the second activity can potentially
hang in GLSurfaceView.onWindowResize waiting for its GLSurfaceView
render thread to draw a frame. The second activity's render thread
is waiting to acquire an EGL context, but the first activity's render
thread doesn't know it should release the EGL context.

The fix is to detect the potential hang, and ask the first activity's
render thread to release the EGL context.

Change-Id: Ibb342c68772297744c973bcf5010581cd132db67
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
d6ddcb7f00a7af95b452233d965b922632f78f21 25-May-2010 Mathias Agopian <mathias@google.com> fix [2677468] some 3rd party GL ES apps get a 32-bits surface by default and fail

force all SurfaceView to 565

Change-Id: I8ebfa1239d8e4fa097c2e544677fb92fa20b39bd
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
0e4aa37872810e46775374596e0beb11f7123727 19-Apr-2010 Jack Palevich <jackpal@google.com> Quietly handle EGL_BAD_NATIVE_WINDOW errors

We believe these errors happen when the window
manager has told surface flinger to close the
native window.

If this error happens while we are creating the
EGL surface we exit the render loop (and
therefore exit the render thread.)

If the error happens while swapping the surface
we ignore it.

In either situation, we expect that the
application is about to be shut down by the
window manager, so it should not be necessary
to try and recover from the error.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
4a65900cd69b79e6e47d275575eaeb5bb2487f9f 27-Mar-2010 Jack Palevich <jackpal@google.com> Turn off logging.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
451a224c46c297bd6b25e3570b45f5053b4788be 26-Mar-2010 Jack Palevich <jackpal@google.com> GLSurfaceView pause and resume now synchronize
with the GLThread.

We used to just set the mPaused state and return,
now we wait until the rendering thread signals
that it has noticed the change in pause state.

This makes Pause/Resume more consistent with
other UI-thread-to-GLThread event communication.

This change was made in the hope of fixing some
race conditions observed in monkey testing.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
57c6a46bd0c84c4b349d49f8df12f30a8cfcdaa2 25-Mar-2010 Jack Palevich <jackpal@google.com> Turn off thread logging (too many messages.)

Leave some other logging on for the monkey test.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
e6c9448eb3228887c49f6ba9c4be2345443286e9 25-Mar-2010 Jack Palevich <jackpal@google.com> Add logging of GLSurfaceView pause/resume calls.

Turn on GLSurfaceView logging, so we can get better
information in the monkey tests.

Change-Id: Ifec0101f8a00ab09037dc9f7a1496fa1a374cc08
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
b1768998f14e03bd69cf049783d6cbeccf6d5839 24-Mar-2010 Jack Palevich <jackpal@google.com> Improve our EGL management when pausing / resuming.

We now release the EGL context when pausing. This
is required to reduce the chance of running out of
contexts on devices which support a limited number
of active EGL contexts.

Someday we may implement a global EGL context
manager that will allow us to let EGL contexts
persist until another activity needs an EGL
context. But for now, without such a manager,
we take the conservative approach.

Separately, we now terminate EGL when
pausing on Sapphire. This is a requirement of the
Sapphire OpenGL driver.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
07353a1e8598b1e2993b8b6763f630379ae6e8bb 23-Mar-2010 Jack Palevich <jackpal@google.com> GLSurfaceView: Log egl failures

Decode the EGL error code when throwing exceptions.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
04b17ab7b4a17a28f541f746c3d55046c5b87596 15-Mar-2010 Jack Palevich <jackpal@google.com> Improve eglSwapBuffers error handling.

We now distinguish EGL_CONTEXT_LOST errors from
other kinds of errors. We return "true" if
the swap completes successfully, "false" if
the swap fails due to EGL_CONTEXT_LOST, and
throw a RuntimeException if the swap fails due
to any other cause.

If eglSwapBuffers succeeds, we now avoid calling
eglGetError at all, which means we avoid clearing
any EGL errors that might already have been
pending before eglSwapBuffers is called.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
83835359e51ddb8be37cea9bf4bb32f9390d82b7 05-Mar-2010 Jack Palevich <jackpal@google.com> Clarify the default algorithm used to choose an EGLConfig.

Explicitly default to an RGB_565 android.view.Surface.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
4a2221ec4a929976be570ad096252c8dea326e19 06-Mar-2010 Jack Palevich <jackpal@google.com> Fix inverted release-EGLContext-on-pause logic.

This works around a bug in the
"Q3Dimension MSM7500" driver. That driver only
supports a single active EGLContext, so we must
release and restore the EGLContext when pausing
and unpausing.

Unfortunately the test for deciding whether to
release the context was inverted. We were
releasing the context on every device besides
the MSM7500 devices, which was a performance
drain, and we were not releasing the context on
the MSM7500, which meant the underlying driver
bug was not worked around.

Now we release the EGL context when pausing only
on the devices that have the bug.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
840e958847f31f835dbf17ce539c9f8317251cc9 18-Jan-2010 Jack Palevich <jackpal@google.com> Decouple the EGL context lifetime from the EGL surface lifetime.

The EGL context is now preserved when possible. Previously we would
destroy it whenever the EGL surface was destroyed. Preserving the
EGL context preserves loaded textures and VBO resources.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
66a4a6e45f59f72f24d710221c27db1bd233e154 21-Dec-2009 Jack Palevich <jackpal@google.com> Fix merge conflict markers that accidentally got checked in.

(They were in a comment, so it wasn't detected by the compiler.)
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
21799450ec751fd3c41c7e66e69fefb094b3050b 21-Dec-2009 Jack Palevich <jackpal@google.com> Fix bug 2325244 screen turns black for a brief period of time

The problem was a black first frame when creating a surface, or a
garbage frame when the surface was resized.

The cause was lack of synchronization between the render thread and the
UI thread. The UI thread would typically return before the render thread
had a chance to draw its first frame.

The fix was to make the UI thread wait until at least one frame had been
rendered by the rendering thread.

The waiting is done in the surfaceChanged method because we know
that surfaceChanged will be called in both the surface created
and surface changed cases.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
c373edbf1c7066668b8bf5fe90edd3fedd94c78b 07-Dec-2009 Jack Palevich <jackpal@google.com> am 9196034b: am 30d90523: Merge changes Id682ab72,I9bb4dbae into eclair-mr2

Merge commit '9196034b84c48844799a2904ef3ce31f18ee748e'

* commit '9196034b84c48844799a2904ef3ce31f18ee748e':
Improve error message thrown when eglCreateContext fails.
Improve error reporting by always returning the public
9bb4dbae91df0971038e955ef49c5d9a64d4a428 04-Dec-2009 Jack Palevich <jackpal@google.com> Improve error message thrown when eglCreateContext fails.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
355c20cb9276148fd9b7074c5199aedeb497406e 27-Nov-2009 Jack Palevich <jackpal@google.com> Unhide the Android OpenGL ES 2.0 API

Add a Matrix.setLookAtM method for computing a look-at viewing transform.

Change GLU.lookAt to use Matrix.setLook.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
6a9a87da47bcfb032d0585f41d77abb6300ea63c 25-Nov-2009 Jack Palevich <jackpal@google.com> am 85a9498a: am 9c0b39c4: am ca00dee2: Merge change I5aa3adcf into eclair

Merge commit '85a9498a2f33d62a4313a3561b5468456974696e'

* commit '85a9498a2f33d62a4313a3561b5468456974696e':
Improve the exception message text by including eglGetError().
9c0b39c47efade5ee2303a8f8ffbd9cf87c2c841 25-Nov-2009 Jack Palevich <jackpal@google.com> am ca00dee2: Merge change I5aa3adcf into eclair

Merge commit 'ca00dee21425882619aef4ecbe3e0d08de0544e5' into eclair-mr2

* commit 'ca00dee21425882619aef4ecbe3e0d08de0544e5':
Improve the exception message text by including eglGetError().
5aa3adcf304ec3767b3c22128acb23240d8d0bab 25-Nov-2009 Jack Palevich <jackpal@google.com> Improve the exception message text by including eglGetError().

Should help us track down the cause of bug 2285187
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
6ae4da75422bbb31c3e0a09f616cdaee1d465946 19-Nov-2009 Jack Palevich <jackpal@google.com> Extend GLSurfaceView to make it easy to create an OpenGL ES 2.0 context

Provide a new method, GLSurfaceView.setEGLContextClientVersion. Clients
call this method to define which level of OpenGL ES support they want.

This method only affects the default behavior of GLSurfaceView. If clients
have supplied their own EGLContextFactory or EGLConfigChooser then they
are on their own if they want to create an OpenGL ES 2.0 context.

This API is currently hidden.

Update the gl2_java test to use this new API.

Update the gl2_java test's AndroidManifest.xml file to indicate that
it requires OpenGL ES 2.0.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
a822f02bb9c7f5bf2e3fa3cb63effc391be158c5 17-Nov-2009 Jack Palevich <jackpal@google.com> resolved conflicts for merge of dc49acb0 to eclair-mr2
a08d46d8aaabb53eef4d5dc47272565d50f23c19 16-Nov-2009 Jack Palevich <jackpal@google.com> More GLSurfaceView cleanup.

+ The mDone flag is now a pair of flags: mShouldExit and mExited. The
problem with mDone was that it meant "had been asked to exit", but was
being used by some observers as "had exited". Using two variables means
that observers can observe either "had been asked to exit" or "had exited",
as they prefer.

+ Simplyify where we check for mShouldExit. We now check for it at the
top of our innermost guardedRun while loop.

+ requestExitAndWait now waits for mExited to be set to true to know
that a thread has exited, rather than using join(). This means we can use
wait() for the check, which releases the sGLThreadManager
monitor, avoiding a potential deadlock.

+ move the event queue into the sGLThreadManager monitor. This avoids
having to acquire two locks in order to enque/deque events, which also
avoids the potential for lock ordering deadlocks.

+ Simplify the event dequeueing code. We now deque one event each time
through the main GLSurfaceView loop. Events still have priority over
rendering, so there isn't any semantic change, it just cleans up the code.

+ Avoid trying to acquire an egl Surface if we're paused.

+ To simplify reasoning about the code, call sGLThreadManager.notifyAll()
in every case where we modify one of the variables that's protected by
the sGLThreadManager monitor. It would be slightly more efficient to only
notify when we change variables that could cause a thread to wait(), but
then we would have to redo our analysis every time we change any code.

+ Clean up the logic for creating the EGL surface and then calling the
renderer's onSurfaceCreated / onSurfaceChanged methods.

+ Implement work-around for bug 2263168 "Need to draw twice after
screen rotation..."
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
1179efbb3b8856eb8160e2dd67a300a5d64e8e98 11-Nov-2009 Jack Palevich <jackpal@google.com> resolved conflicts for merge of ba56915a to eclair-mr2
67dcd6c2392caf3ff98f35a3d1ec550d229c167b 10-Nov-2009 Jack Palevich <jackpal@google.com> Fix multi-lock ordering issues in GLSurfaceView

There were potential deadlocks between the per-GLThread monitors and the
GLThreadManager monitor.

To avoid these deadlocks we now use a single monitor for
both the GLThreadManager state and the per-GLThread state.

Converted GLThreadManager's semaphore into the equivalent
synchronized-wait-notifyAll code. This enables us to wait for
either mDone, or user events, or the EGL surface with a single "wait()".

Simplified the logic used to acquire and release the EGL surface. The
EGL surface is now only requested while the surfaceFlinger surface
is acquired.

Removed the "egl surface stealing" policy we had recently inserted.
It's not needed now that we reliably quit when requested.

Pulled user event processing outside of the GLThreadManager monitor
so that we don't call any potentially-long-running code while
inside the monitor.

This should help with bug 2228262.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
8da3ac92a6a6247ef06de4d4b684f8635d8fc003 10-Nov-2009 Jack Palevich <jackpal@google.com> resolved conflicts for merge of 3f857b78 to eclair-mr2
32d416518473f3bf5323d660e5910ca5633ffed6 08-Nov-2009 Jack Palevich <jackpal@google.com> Allow a GLThread to release and reacquire the EGL Surface as needed.

We currently only allow one GLThread to have an active EGL Surface at a
time.(This may be lifted in the future, when EGL and GL are reentrant.)

Prior to this change we would enforce this rule by having older GLThreads
quit when a new GLThread started. That had the drawback of leaving the
older GLSurfaceViews in a zombie state -- their GLThreads would be
gone.

We now enforce this rule by just releasing and reacquiring the EGL surface
context as needed.

Specific changes to the code:

created private helper methods - startEgl and stopEgl to help manage
starting and stopping EGL.

Move the calls to sGLThreadManager start and end from the outermost run
method into the startEgl / stopEgl methods.

Reworked the wait loop to handle starting and stopping EGL as needed.

needToWait() gets simpler -- just looks at current status.

sGLThreadManager.shouldQuit was replaced by shouldHaveEgl.


This is another step in fixing bug 2228262.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
a3a351e5d164d0c8b461ae7af86edc0227654a76 07-Nov-2009 Jack Palevich <jackpal@google.com> resolved conflicts for merge of 4e3fadd0 to eclair-mr2
a44249500f6c1c7a75b5c420fa2e81c2aa317a10 07-Nov-2009 Jack Palevich <jackpal@google.com> Fix stupid bug in GLThreadManager implementation.

The code intended to copy the old value of a field, before the
field was updated. However, what the code was actually doing was
copying the new value of the field, after the field was updated.

The fix was to move the copy to before the update.

This is work towards fixing bug 2228262
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
79447b2087c8c820d742185dda7305101f9656f0 06-Nov-2009 Jack Palevich <jackpal@google.com> resolved conflicts for merge of 84872738 to eclair-mr2
8b2c9c9ecb08d25244fa97fb42c2c315ae3cf03d 06-Nov-2009 Jack Palevich <jackpal@google.com> Improve GLSurfaceView to avoid deadlocks and race conditions.

This is work towards fixing bug 2228262

Specific issues fixed by this change:

+ GLThread names now include the thread id, making it easier to tell one
GLThread from another.

+ A private final static boolean LOG_THREADS can be set to true at compile
time to print out thread-related trace information, helpful for debugging
GLSurfaceView behavior. This static defaults to "false".

+ Changed calls to "notify" to "notifyAll" to make the code more
robust in case more than two threads are blocked on the same monitor.

+ Add a GLThreadManager to help manage the transition to
a new GLThread. Currently only one GLThread can be active in an address
space. When the second thread starts up, the GLThreadManager helps the old
GLThread to shut down,

+ Make sure we stop waiting for dead GLThreads. This is done by adding
checks for a variable mDone being true to our monitor wait loops. And
we use a "finally" clause at the end of GLThread.run() method to set mDone
and notifyAll any wait loops.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
28023911a4b572f0ca640e7a3e3f9a0dd6f535e9 14-Oct-2009 Jack Palevich <jackpal@google.com> Add additional error checking of EGL function calls.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
c52ba78cab001ff68b4823f4769c129b8acfddee 14-Oct-2009 Jack Palevich <jackpal@google.com> Allow multiple OpenGL contexts on systems that support them.

Previously we always restricted the number of OpenGL contexts to 1.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
2e26fc08aa1939c19e939d983bd608cdec050024 26-Sep-2009 Jack Palevich <jackpal@google.com> Check for failure to create EGL surfaces and contexts.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
d40dfbbbff81219258ca36b762a89ff503154345 24-Sep-2009 Jack Palevich <jackpal@google.com> Fix broken Javadoc link for GLSurfaceView.EGLWindowSurfaceFactory.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
82cbaab450d3c5d9f3d52c49881212f250d7cd97 24-Sep-2009 Jack Palevich <jackpal@google.com> Publish minor additions to GLSurfaceView API.

Clients can now modify the way that the EGL context and the EGL window
surface are created and destroyed.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
a8fecb87c5eaaefc9ca6272e3b59ef88d293dd6d 23-Sep-2009 Jack Palevich <jackpal@google.com> Create samples showing how to call OpenGL from JNI libraries.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
15e1c6dc7a778590068b1cad55beea2bc6159509 22-Sep-2009 Jack Palevich <jackpal@google.com> Allow GLSurfaceView clients to customize EGL Surfaces and Contexts.

This API is hidden for now, will expose once it's been tested more.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
1bd888ba2e0976a179258cfa65ef07be31602a0a 22-Sep-2009 Jack Palevich <jackpal@google.com> Fix GLSurfaceView to sync surfaceDestroyed with GL rendering thread

Until now we had a race condition where the GL rendering thread could
continue rendering a frame after we have returned from the
SurfaceHolder.Callback.surfaceDestroyed notification.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
82fd4fce16b9bbde25d044acc86ddf7306ebdd10 21-Aug-2009 Mathias Agopian <mathias@google.com> fix a bug in ComponentSizeChooser where it could pick a software EGLConfig instead of a better h/w one.

We now just try to honor the stencil / depth buffer "at least", while doing a "shortest distance" on the colors.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
317a6280cc109e873646e4652be1582d870eedfd 14-Aug-2009 Mathias Agopian <mathias@google.com> Surface::GPU and Surface::HARDWARE are now deprecated; they will be set automatically if needed.

this also ripples into the window manager API by making some constant there deprecated as well.
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
3e832dbe966c2ca0fde2f4bd87ad9c974a93a7cf 10-Apr-2009 Jack Palevich <> AI 145534: am: CL 145526 am: CL 145249 Correct misspelling of constant RENDERMODE_CONTUOUSLY --> RENDERMODE_CONTINUOUSLY
Original author: jackpal
Merged from: //branches/cupcake/...
Original author: android-build

Automated import of CL 145534
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
b47c641fe8330fc68dbed91163ff07015068d0ce 09-Apr-2009 Jack Palevich <> AI 145531: am: CL 145523 am: CL 145244 Fully document GLSurfaceView and related classes.
Original author: jackpal
Merged from: //branches/cupcake/...
Original author: android-build

Automated import of CL 145531
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
a605a51e63de2e7dc99ed085639a6f12b7f85af7 25-Mar-2009 Jack Palevich <> Automated import from //branches/master/...@142658,142658
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
9066cfe9886ac131c34d59ed0e2d287b0e3c0087 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
d83a98f4ce9cfa908f5c54bbd70f03eec07e7553 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java
f013e1afd1e68af5e3b868c26a653bbfb39538f8 18-Dec-2008 The Android Open Source Project <initial-contribution@android.com> Code drop from //branches/cupcake/...@124589
/frameworks/base/opengl/java/android/opengl/GLSurfaceView.java