Android APIs
public class

RenderScript

extends Object
java.lang.Object
   ↳ android.renderscript.RenderScript

Class Overview

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.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int CREATE_FLAG_LOW_LATENCY

Added in API level 21

Constant Value: 2 (0x00000002)

public static final int CREATE_FLAG_LOW_POWER

Added in API level 21

Constant Value: 4 (0x00000004)

public static final int CREATE_FLAG_NONE

Added in API level 21

Constant Value: 0 (0x00000000)

Public Methods

public void contextDump ()

Added in API level 11

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

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

Added in API level 21

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 The context.
ct The type of context to be created.
flags The OR of the CREATE_FLAG_* options desired
Returns
  • RenderScript

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

Added in API level 18

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

Parameters
ctx The context.
ct The type of context to be created.
Returns
  • RenderScript

public static RenderScript create (Context ctx)

Added in API level 11

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

Parameters
ctx The context.
Returns
  • RenderScript

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

Added in API level 23

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 The context.
Returns
  • RenderScript

public void destroy ()

Added in API level 11

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.

public void finish ()

Added in API level 11

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

public final Context getApplicationContext ()

Added in API level 11

Gets the application context associated with the RenderScript context.

Returns
  • The application context.

public RenderScript.RSErrorHandler getErrorHandler ()

Added in API level 11

public RenderScript.RSMessageHandler getMessageHandler ()

Added in API level 11

public static long getMinorVersion ()

Added in API level 23

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

Returns
  • The minor RenderScript version number

public static void releaseAllContexts ()

Added in API level 23

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()

public void sendMessage (int id, int[] data)

Added in API level 18

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

public void setErrorHandler (RenderScript.RSErrorHandler msg)

Added in API level 11

public void setMessageHandler (RenderScript.RSMessageHandler msg)

Added in API level 11

public void setPriority (RenderScript.Priority p)

Added in API level 11

Change the priority of the worker threads for this context.

Parameters
p New priority to be set.

Protected Methods

protected void finalize ()

Added in API level 11

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