了解RenderScript源码(0)
2016-12-13 18:42
302 查看
1、RenderScript的创建
create()方法最后都会调用这个方法RenderScript.create(Context ctx, int sdkVersion, ContextType ct, int flags);
flag:
CREATE_FLAG_LOW_POWER>省电,
CREATE_FLAG_LOW_LATENCY>高性能 ,`CREATE_FLAG_NONE:普通的,一般的
ContextType:
/** * NORMAL context, this is the default and what shipping apps should * use. */ NORMAL (0), /** DEBUG context, perform extra runtime checks to validate the kernels and APIs are being used as intended. Get and SetElementAt will be bounds checked in this mode. */ DEBUG (1), /** * PROFILE context, Intended to be used once the first time an * application is run on a new device. This mode allows the runtime to * do additional testing and performance tuning. */ PROFILE (2);
NORMAL:默认使用
DEBUG :执行额外的运行时检查以验证内核和API是否按预期使用。Get和SetElementAt将在此模式下检查边界。
PROFILE:第一次在新设备上运行应用程序时使用一次。此模式允许运行时执行额外的测试和性能调整。
遍历mProcessContextList,取出之前已经存在的RenderScript对象。
RenderScript构造方法:
RenderScript(Context ctx) { //默认ContextType类型 mContextType = ContextType.NORMAL; if (ctx != null) { mApplicationContext = ctx.getApplicationContext(); } mRWLock = new ReentrantReadWriteLock(); try { registerNativeAllocation.invoke(sRuntime, 4 * 1024 * 1024); // 4MB for GC sake } catch (Exception e) { Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e); throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e); } } 从构造方法可以看出RenderScript类中的Context会一直使用mApplicationContext; ###2、销毁RenderScript对象 public static void releaseAllContexts() >RenderScript中维护了一个mProcessContextList,里面存储了之前创建的RenderScript对象, 这个方法就是将所有的该对象清除,而且调用了每个对象中的destroy()方法,并且重新创建了该List对象, private void helpDestroy() >防止多次调用 下面的代码
if (shouldDestroy) {
nContextFinish();
nContextDeinitToClient(mContext); mMessageThread.mRun = false; try { mMessageThread.join(); } catch(InterruptedException e) { } nContextDestroy(); nDeviceDestroy(mDev); mDev = 0; }
``transient` 修饰的变量不被串行化(Serializable序列化)
相关文章推荐
- JFreeChart使用总结(四)
- 汇编(X86-64)
- Berkeley DB
- Java集合类源码分析
- oracle输出多行多列数据
- 模拟jquery的$()选择器的实现
- 设计模式之状态模式的理解运用
- Spring Boot中使用Spring Security自定义验证
- cartographer_ros+Ubuntu14.04 安装
- jboss服务僵死
- 第六章:如何对内容进行分类
- mongodb基础知识-内嵌文档相关
- Spring Boot 构建应用——整合 Elasticsearch 搜索引擎
- python---filecmp
- 地球坐标 火星坐标 百度坐标 相互转换
- 静态库和动态库的简单区别分析
- weblogic数据源配置oracle and mysql
- ubuntu 用户不在sudoers文件中
- linux VNC配置(解决:关闭防火墙仍不能访问端口的问题)
- java之旅之集合框架