开发者

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

开发者 https://www.devze.com 2023-02-09 01:59 出处:网络
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 req开发者_如何学Goui

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 req开发者_如何学Gouired? What can happen if I don't?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消