Android 4.4读取过度绘制数

原创
2017/09/06 14:45
阅读数 180
private float getOverDrawCounter(){
    Class<?> view= null;
    try {
        view = Class.forName("android.view.View");
        Method getHardwareRender=view.getDeclaredMethod("getHardwareRenderer");
        getHardwareRender.setAccessible(true);

        Object gl20Renderer=getHardwareRender.invoke(getWindow().getDecorView().getRootView());
        if(null!=gl20Renderer){
            Field debugOverdrawLayoutField=gl20Renderer.getClass().getSuperclass().getDeclaredField("mDebugOverdrawLayer");
            debugOverdrawLayoutField.setAccessible(true);

            Object GLES20RenderLayout=debugOverdrawLayoutField.get(gl20Renderer);
            if(null!=GLES20RenderLayout){
                Method getCanvasMethod=GLES20RenderLayout.getClass().getSuperclass().getSuperclass().getDeclaredMethod("getCanvas");
                getCanvasMethod.setAccessible(true);
                Object gles20Canvas=getCanvasMethod.invoke(GLES20RenderLayout);
                if(null!=gles20Canvas){
                    Method getOverdrawMethod=gles20Canvas.getClass().getDeclaredMethod("getOverdraw");
                    getOverdrawMethod.setAccessible(true);
                    Object o =getOverdrawMethod.invoke(gles20Canvas);
                    if(null!=o){
                        return (float)o;
                    }
                }
            }
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }

    return 0f;

}
展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部