簡體   English   中英

GLSurfaceView:我需要調用onPause / onResume嗎?

[英]GLSurfaceView: Do I need to to call onPause/onResume?

我在RENDERMODE_WHEN_DIRTY中使用GLSurfaceView(sdk版本7)。 文檔說我需要調用onPause / onResume,但沒有它就可以正常工作,所以我很想知道。 需要嗎? 如果我不這樣做會怎么樣?

GLSurfaceView的onPause的實現如下所示:

/**
 * 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();
}

您可以看到(以及文檔說明)它暫停渲染線程。 這會導致GLThread中的內部調用stopEglLocked,如下所示:

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

所以你可以看到它破壞了一個昂貴的系統資源的表面,並導致線程等待(),這也節省了系統資源,CPU,baterry等。

因此,確實需要調用GLSurfaceView的onPause和onResume。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM