Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSurfaceView: Do I need to to call onPause/onResume?

I am using a GLSurfaceView (sdk version 7) in RENDERMODE_WHEN_DIRTY. The documentation says I need to call onPause/onResume, but it works fine without it, so I am wondering. Is it required? What can happen if I don't?

like image 788
ADB Avatar asked Feb 06 '11 16:02

ADB


1 Answers

The implementation of GLSurfaceView's onPause looks like this:

/**
 * Inform the view that the activity is paused. The owner of this view must
 * call this method when the activity is paused. Calling this method will
 * pause the rendering thread.
 * Must not be called before a renderer has been set.
 */
public void onPause() {
    mGLThread.onPause();
}

You can see (and the documentation states) that it pauses the rendering thread. This causes an internal call in the GLThread to stopEglLocked which looks like this:

 private void stopEglLocked() {
        if (mHaveEgl) {
            mHaveEgl = false;
            mEglHelper.destroySurface();
            mEglHelper.finish();
            sGLThreadManager.releaseEglSurface(this);
        }
 }

So you can see it destroys the surface which is an expensive system resource, and causes thread to wait(), which also saves system resources, cpu, baterry, etc.

So, calling GLSurfaceView's onPause and onResume is definitely required.

like image 148
Lior Avatar answered Oct 31 '22 21:10

Lior