Android 前后台切换与OpenGL(EGL)创建销毁的周期

当Android应用在前台和后台切换时,EGL(包括display, context, config, surface)的生命周期受到影响。EGLNativeWindowType window的销毁会导致OpenGL不可用。恢复时需要重建EGL。NDK的native-activity和GLSurfaceView都会在window变化时销毁并重建EGL。为优化性能,可以只在window稳定后初始化EGL,并在window变化时仅销毁surface,恢复时重建。这样能保留OpenGL状态,提高切换速度。" 107149584,9717610,手机APP测试全方位攻略,"['Android', 'iOS', '测试方法', '性能测试', '兼容性测试']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

EGL的创建是这样的。

/**
 * Creates an EGL rendering context and all associated elements
 */
void CreateEGL(EGLNativeWindowType window, EGLDisplay* outDisplay, EGLContext* outContext, EGLSurface* outSurface, EGLConfig*  outConfig)
{

	*outDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);

	if (*outDisplay == EGL_NO_DISPLAY)
	{
		ALog_A(0, "CreateEGL failed EGL unable to eglGetDisplay");
	}

	if (!eglInitialize(*outDisplay, NULL/*major*/, NULL/*minor*/))
	{
		ALog_A(0, "CreateEGL failed EGL unable to eglInitialize");
	}

	EGLint numConfigs;

	// Here specify the attributes of the desired configuration.
	// Below, we select an EGLConfig with at least 8 bits per color
	// component compatible with on-screen windows
	const EGLint configAttribs[] =
	{
		   EGL_DEPTH_SIZE,      16,
		   EGL_RED_SIZE,        8,   //   5,
		   EGL_GREEN_SIZE,      8,   //   6,
		   EGL_BLUE_SIZE,       8,   //   5,
		   EGL_ALPHA_SIZE,    
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值