Skip to content

Most visited

Recently visited

navigation
Added in API level 11

RenderScript

public class RenderScript
extends Object

java.lang.Object
   ↳ android.renderscript.RenderScript


This class provides access to a RenderScript context, which controls RenderScript initialization, resource management, and teardown. An instance of the RenderScript class must be created before any other RS objects can be created.

Developer Guides

For more information about creating an application that uses RenderScript, read the RenderScript developer guide.

Summary

Nested classes

enum RenderScript.ContextType

ContextType specifies the specific type of context to be created. 

enum RenderScript.Priority

RenderScript worker thread priority enumeration. 

class RenderScript.RSErrorHandler

The runtime error handler base class. 

class RenderScript.RSMessageHandler

The base class from which an application should derive in order to receive RS messages from scripts. 

Constants

int CREATE_FLAG_LOW_LATENCY

int CREATE_FLAG_LOW_POWER

int CREATE_FLAG_NONE

Public methods

void contextDump()

Print the currently available debugging information about the state of the RS context to the log.

static RenderScript create(Context ctx, RenderScript.ContextType ct, int flags)

Gets or creates a RenderScript context of the specified type.

static RenderScript create(Context ctx, RenderScript.ContextType ct)

calls create(ctx, ct, CREATE_FLAG_NONE) See documentation for @create for details

static RenderScript create(Context ctx)

calls create(ctx, ContextType.NORMAL, CREATE_FLAG_NONE) See documentation for @create for details

static RenderScript createMultiContext(Context ctx, RenderScript.ContextType ct, int flags, int API_number)

Create a RenderScript context.

void destroy()

Destroys this RenderScript context.

void finish()

Wait for any pending asynchronous opeations (such as copies to a RS allocation or RS script executions) to complete.

final Context getApplicationContext()

Gets the application context associated with the RenderScript context.

RenderScript.RSErrorHandler getErrorHandler()
RenderScript.RSMessageHandler getMessageHandler()
static long getMinorVersion()

Returns an identifier that can be used to identify a particular minor version of RS.

static void releaseAllContexts()

Releases all the process contexts.

void sendMessage(int id, int[] data)

Place a message into the message queue to be sent back to the message handler once all previous commands have been executed.

void setErrorHandler(RenderScript.RSErrorHandler msg)
void setMessageHandler(RenderScript.RSMessageHandler msg)
void setPriority(RenderScript.Priority p)

Change the priority of the worker threads for this context.

Protected methods

void finalize()

Invoked when the garbage collector has detected that this instance is no longer reachable.

Inherited methods

From class java.lang.Object

Constants

CREATE_FLAG_LOW_LATENCY

Added in API level 21
int CREATE_FLAG_LOW_LATENCY

Constant Value: 2 (0x00000002)

CREATE_FLAG_LOW_POWER

Added in API level 21
int CREATE_FLAG_LOW_POWER

Constant Value: 4 (0x00000004)

CREATE_FLAG_NONE

Added in API level 21
int CREATE_FLAG_NONE

Constant Value: 0 (0x00000000)

Public methods

contextDump

Added in API level 11
void contextDump ()

Print the currently available debugging information about the state of the RS context to the log.

create

Added in API level 21
RenderScript create (Context ctx, 
                RenderScript.ContextType ct, 
                int flags)

Gets or creates a RenderScript context of the specified type. The returned context will be cached for future reuse within the process. When an application is finished using RenderScript it should call releaseAllContexts() A process context is a context designed for easy creation and lifecycle management. Multiple calls to this function will return the same object provided they are called with the same options. This allows it to be used any time a RenderScript context is needed. Prior to API 23 this always created a new context.

Parameters
ctx Context: The context.
ct RenderScript.ContextType: The type of context to be created.
flags int: The OR of the CREATE_FLAG_* options desired
Returns
RenderScript RenderScript

create

Added in API level 18
RenderScript create (Context ctx, 
                RenderScript.ContextType ct)

calls create(ctx, ct, CREATE_FLAG_NONE) See documentation for @create for details

Parameters
ctx Context: The context.
ct RenderScript.ContextType: The type of context to be created.
Returns
RenderScript RenderScript

create

Added in API level 11
RenderScript create (Context ctx)

calls create(ctx, ContextType.NORMAL, CREATE_FLAG_NONE) See documentation for @create for details

Parameters
ctx Context: The context.
Returns
RenderScript RenderScript

createMultiContext

Added in API level 23
RenderScript createMultiContext (Context ctx, 
                RenderScript.ContextType ct, 
                int flags, 
                int API_number)

Create a RenderScript context. This is an advanced function intended for applications which need to create more than one RenderScript context to be used at the same time. If you need a single context please use create()

Parameters
ctx Context: The context.
ct RenderScript.ContextType
flags int
API_number int
Returns
RenderScript RenderScript

destroy

Added in API level 11
void destroy ()

Destroys this RenderScript context. Once this function is called, using this context or any objects belonging to this context is illegal. API 23+, this function is a NOP if the context was created with create(). Please use releaseAllContexts() to clean up contexts created with the create function.

finish

Added in API level 11
void finish ()

Wait for any pending asynchronous opeations (such as copies to a RS allocation or RS script executions) to complete.

getApplicationContext

Added in API level 11
Context getApplicationContext ()

Gets the application context associated with the RenderScript context.

Returns
Context The application context.

getErrorHandler

Added in API level 11
RenderScript.RSErrorHandler getErrorHandler ()

Returns
RenderScript.RSErrorHandler

getMessageHandler

Added in API level 11
RenderScript.RSMessageHandler getMessageHandler ()

Returns
RenderScript.RSMessageHandler

getMinorVersion

Added in API level 23
long getMinorVersion ()

Returns an identifier that can be used to identify a particular minor version of RS.

Returns
long The minor RenderScript version number

releaseAllContexts

Added in API level 23
void releaseAllContexts ()

Releases all the process contexts. This is the same as calling .destroy() on each unique context retreived with create(...). If no contexts have been created this function does nothing. Typically you call this when your application is losing focus and will not be using a context for some time. This has no effect on a context created with createMultiContext()

sendMessage

Added in API level 18
void sendMessage (int id, 
                int[] data)

Place a message into the message queue to be sent back to the message handler once all previous commands have been executed.

setErrorHandler

Added in API level 11
void setErrorHandler (RenderScript.RSErrorHandler msg)

Parameters
msg RenderScript.RSErrorHandler

setMessageHandler

Added in API level 11
void setMessageHandler (RenderScript.RSMessageHandler msg)

Parameters
msg RenderScript.RSMessageHandler

setPriority

Added in API level 11
void setPriority (RenderScript.Priority p)

Change the priority of the worker threads for this context.

Parameters
p RenderScript.Priority: New priority to be set.

Protected methods

finalize

Added in API level 11
void finalize ()

Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

Throws
Throwable
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.