你的分享就是我们的动力 ---﹥

开启硬件加速 导致花屏问题 OpenGlRenderer 0x506 解决办法

时间:2015-02-02 14:54来源:www.chengxuyuans.com 点击:
(150114_17:08:32.461)I/dalvikvm-heap(  850): Grow heap (frag case) to 10.342MB for 2457616-byte allocation 
(150114_17:08:32.542)D/dalvikvm(  850): GC_FOR_ALLOC freed 20K, 25% free 10530K/14040K, paused 34ms, total 34ms 
(150114_17:08:32.551)D/dalvikvm(  850): GC_CONCURRENT freed 7K, 26% free 10524K/14040K, paused 1ms+5ms, total 24ms 
(150114_17:08:32.551)D/OpenGLRenderer(  850): GL error from OpenGLRenderer: 0x506


android4.2版定制的Launcher, 有几率出现应用整个绘制成花屏、黑屏或者字体绘制成方块等问题,出现花屏问题的时候出现以上LOG


解决办法:

当View 调用destroyLayer()的时候判断如果当前的硬件加速不可用的时候,调用mHardwareRenderer的safelyRun来删除mHardwareLayer的资源

修改View.java destroyLayer(boolean valid)方法

boolean destroyLayer(boolean valid) {
        if (mHardwareLayer != null) {
            AttachInfo info = mAttachInfo;
            if (info != null && info.mHardwareRenderer != null &&
                    info.mHardwareRenderer.isEnabled() &&
                    (valid || info.mHardwareRenderer.validate())) {

                info.mHardwareRenderer.cancelLayerUpdate(mHardwareLayer);
                mHardwareLayer.destroy();
                mHardwareLayer = null;

                invalidate(true);
                invalidateParentCaches();
            }
            else if(info != null && info.mHardwareRenderer != null)
            {
            	info.mHardwareRenderer.safelyRun(new Runnable() {

					@Override
					public void run() {
						// TODO Auto-generated method stub
						mHardwareLayer.destroy();
						mHardwareLayer = null;
						if (mDisplayList != null) 
							 mDisplayList.reset(); 

						 invalidate(true);
			             invalidateParentCaches();
						 }
					});
            }
            return true;
        }
        return false;
    }

附上代码优化方案http://zuiniuwang.blog.51cto.com/3709988/721798/


转载注明地址:http://www.chengxuyuans.com/Android/89720.html