您的位置:首页 > 其它

了解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序列化)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: