From 6518f486a5b9cdcb48df3ca09732b51b6df249bf Mon Sep 17 00:00:00 2001 From: Robert Ly Date: Mon, 14 Feb 2011 18:57:46 -0800 Subject: Doc change: fixing renderscript samples Change-Id: Ie5d17df121ec4bc5fd46448c1670d306322b92d8 --- docs/html/guide/topics/graphics/renderscript.jd | 156 ++++++++++++------------ docs/html/resources/resources-data.js | 10 ++ 2 files changed, 90 insertions(+), 76 deletions(-) (limited to 'docs') diff --git a/docs/html/guide/topics/graphics/renderscript.jd b/docs/html/guide/topics/graphics/renderscript.jd index 54737ad..0e64c78 100644 --- a/docs/html/guide/topics/graphics/renderscript.jd +++ b/docs/html/guide/topics/graphics/renderscript.jd @@ -16,7 +16,7 @@ parent.link=index.html
  1. Native Renderscript APIs
  2. -
  3. Reflective layer APIs
  4. +
  5. Reflected layer APIs
  6. Graphics APIs
@@ -30,10 +30,18 @@ parent.link=index.html +

Related Samples

+
    +
  1. Balls
  2. +
  3. Fountain
  4. +
  5. Hello Compute
  6. +
  7. Hello World
  8. +
  9. Samples
  10. +
-

The Renderscript system offers high performance 3D rendering and mathematical computations at +

The Renderscript system offers high performance 3D rendering and mathematical computation at the native level. The Renderscript APIs are intended for developers who are comfortable with developing in C (C99 standard) and want to maximize performance in their applications. The Renderscript system improves performance by running as native code on the device, but it also @@ -46,47 +54,46 @@ parent.link=index.html intermediate code.

The disadvantage of the Renderscript system is that it adds complexity to the development and - debugging processes and is not a substitute for the Android system APIs. It is a portable native - language with pointers and explicit resource management. The target use is for performance - critical code where the existing Android APIs are not sufficient. If what you are rendering or - computing is very simple and does not require much processing power, you should still use the - Android APIs for ease of development. Debugging visibility can be limited, because the + debugging processes. Debugging visibility can be limited, because the Renderscript system can execute on processors other than the main CPU (such as the GPU), so if - this occurs, debugging becomes more difficult. Remember the tradeoffs between development and - debugging complexity versus performance when deciding to use Renderscript.

+ this occurs, debugging becomes more difficult. The target use is for performance + critical code where the traditional framework APIs (such as using {@link android.opengl}) are not sufficient. + If what you are rendering or computing is very simple and does not require much processing power, you should still use the + traditional framework APIs for ease of development. Remember the tradeoffs between development and + debugging complexity versus performance when deciding to use Renderscript.

For an example of Renderscript in action, see the 3D carousel view in the Android 3.0 versions of Google Books and YouTube or install the Renderscript sample applications that are shipped with - the SDK in <sdk_root>/platforms/android-3.0/samples.

+ the SDK in <sdk_root>/samples/android-11/Renderscript.

Renderscript System Overview

The Renderscript system adopts a control and slave architecture where the low-level native code is controlled by the higher level Android system that runs in the virtual machine (VM). When - you use the Renderscript system, there are three layers of APIs that exist:

+ you use the Renderscript system, there are three layers that exist:

To fully understand how the Renderscript system works, you must understand how the reflected layer is generated and how it interacts with the native Renderscript layer and Android system layer. The reflected layer provides the entry points into the native code, enabling the Android - system code to give high level commands like, "rotate the view" or "filter the bitmap." It - delegates all the heavy lifting to the native layer. To accomplish this, you need to create logic + system to give high level commands like, "rotate the view" or "filter the bitmap" to the + native layer, which does the heavy lifting. To accomplish this, you need to create logic to hook together all of these layers so that they can correctly communicate.

At the root of everything is your Renderscript, which is the actual C code that you write and @@ -94,11 +101,10 @@ parent.link=index.html and graphics. A compute Renderscript does not do any graphics rendering while a graphics Renderscript does.

-

When you create a Renderscript .rs file, an equivalent, reflective layer class, - {@link android.renderscript.ScriptC}, is generated by the build tools and exposes the native - functions to the Android system. This class is named - ScriptC_renderscript_filename. The following list describes the major - components of your native Renderscript code that is reflected:

+

When you create Renderscript .rs files, equivalent, reflected classes + are generated by the build tools and expose the native functions and data types and structures + to the Android system. The following list describes the major components of your native Renderscript + code that is reflected:

-

The Android system also has a corresponding Renderscript context object, {@link +

The Android framework API also has a corresponding Renderscript context object, {@link android.renderscript.RenderScript} (for a compute Renderscript) or {@link android.renderscript.RenderScriptGL} (for a graphics Renderscript). This context object allows you to bind to the reflected Renderscript class, so that the Renderscript context knows what its corresponding native Renderscript is. If you have a graphics Renderscript context, you can also specify a variety of Programs (stages in the graphics pipeline) to tweek how your graphics are rendered. A graphics Renderscript context also needs a surface to render on, {@link - android.renderscript.RSSurfaceView}, which gets passed into its constructor. When all three of - the layers are connected, the Renderscript system can compute or render graphics.

+ android.renderscript.RSSurfaceView}, which gets passed into its constructor.

API overview

@@ -145,15 +150,15 @@ parent.link=index.html because these functions are assumed to be running on a standard CPU. The Renderscript runtime chooses the best processor to execute the code, which may not be the CPU, so it cannot guarantee support for standard C libraries. What Renderscript does offer is an API that supports intensive - computation with an extensive collection of math APIs. Some key features of the Renderscript APIs - are:

+ computation with an extensive collection of math APIs. The following sections group the APIs + into three distinct categories.

Native Renderscript APIs

The Renderscript headers are located in the include and clang-include directories in the - <sdk_root>/platforms/android-3.0/renderscript directory of the Android SDK. + <sdk_root>/platforms/android-11/renderscript directory of the Android SDK. The headers are automatically included for you, except for the graphics specific header, which you can define as follows:

@@ -170,16 +175,14 @@ parent.link=index.html
  • Graphics rendering functions
  • Memory allocation request features
  • Data types and structures to support the Renderscript system such as - Vector types for defining two-, three-, or four-vectors.
  • - + Vector types for defining two-, three-, or four-vectors. -

    Reflective layer APIs

    +

    Reflected layer APIs

    -

    These classes are not generated by the reflection process, and are actually part of the - Android system APIs, but they are mainly used by the reflective layer classes to handle memory - allocation and management for your Renderscript. You normally do not need to be call these classes - directly.

    +

    These classes are mainly used by the reflected classes that are generated from your native Renderscript + code. They allocate and manage memory for your Renderscript on the Android system side. + You normally do not need to call these classes directly.

    Because of the constraints of the Renderscript native layer, you cannot do any dynamic memory allocation in your Renderscript .rs file. @@ -195,7 +198,7 @@ parent.link=index.html The Android system object, which at this point is just an empty shell, is eventually garbage collected.

    -

    The following classes are mainly used by the reflective layer classes:

    +

    The following classes are mainly used by the reflected layer classes:

    @@ -214,9 +217,9 @@ parent.link=index.html @@ -331,7 +333,7 @@ parent.link=index.html state is taken from the bind points as set in the {@link android.renderscript.RenderScriptGL} bind methods in the control environment (VM environment).

    -

    For example, you can define this at the top of your native Renderscript code:

    +

    For example, you can define this at the top of your native graphics Renderscript code:

     #pragma stateVertex(parent)
     #pragma stateStore(parent)
    @@ -354,9 +356,9 @@ parent.link=index.html
           
    - @@ -493,19 +497,19 @@ parent.link=index.html
    1. Analyze your application's requirements and figure out what you want to develop with - Renderscript. To take full advantage of Renderscript, you want to use it when the computation - or graphics performance you're getting with the normal Android system APIs is + Renderscript. To take full advantage of the Renderscript system, you want to use it when the computation + or graphics performance you're getting with the traditional framework APIs is insufficient.
    2. Design the interface of your Renderscript code and implement it using the native Renderscript APIs that are included in the Android SDK in - <sdk_root>/platforms/android-3.0/renderscript.
    3. + <sdk_root>/platforms/android-11/renderscript.
    4. Create an Android project as you would normally, in Eclipse or with the android tool.
    5. Place your Renderscript files in src folder of the Android project so that the - build tools can generate the reflective layer classes.
    6. + build tools can generate the reflected layer classes.
    7. Create your application, calling the Renderscript through the reflected class layer when you need to.
    8. @@ -513,16 +517,16 @@ parent.link=index.html
    9. Build, install, and run your application as you would normally.
    -

    To see how a simple Renderscript application is put together, see The - Hello World Renderscript Graphics Application. The SDK also ships with many Renderscript - samples in the<sdk_root>/samples/android-3.0/ directory.

    +

    To see how a simple Renderscript application is put together, see the + Renderscript samples + and The Hello Graphics Application section of the documentation.

    The Hello Graphics Application

    This small application demonstrates the structure of a simple Renderscript application. You can model your Renderscript application after the basic structure of this application. You can find the complete source in the SDK in the - <android-sdk>/platforms/android-3.0/samples/HelloWorldRS directory. The + <android-sdk>/samples/android-11/HelloWorldRS directory. The application uses Renderscript to draw the string, "Hello World!" to the screen and redraws the text whenever the user touches the screen at the location of the touch. This application is only a demonstration and you should not use the Renderscript system to do something this trivial. The @@ -544,7 +548,7 @@ parent.link=index.html screen.

  • -

    The <project_root>/gen directory contains the reflective layer classes +

    The <project_root>/gen directory contains the reflected layer classes that are generated by the Android build tools. You will notice a ScriptC_helloworld class, which is the reflective version of the Renderscript and contains the entry points into the helloworld.rs native code. This file does @@ -552,8 +556,8 @@ parent.link=index.html

  • -

    Each file has its own distinct use. The following section demonstrates in detail how the - sample works:

    +

    Each file has its own distinct use. The following files comprise the main parts of the sample and + demonstrate in detail how the sample works:

    helloworld.rs
    @@ -628,7 +632,7 @@ int root(int launchID) {
    This class is generated by the Android build tools and is the reflected version of the helloworld.rs Renderscript. It provides a a high level entry point into the helloworld.rs native code by defining the corresponding methods that you can call - from Android system APIs.
    + from the traditional framework APIs.
    helloworld.bc bytecode
    diff --git a/docs/html/resources/resources-data.js b/docs/html/resources/resources-data.js index 5839064..b80e59a 100644 --- a/docs/html/resources/resources-data.js +++ b/docs/html/resources/resources-data.js @@ -496,6 +496,16 @@ var ANDROID_RESOURCES = [ } }, { + tags: ['sample', 'new'], + path: 'samples/Renderscript/index.html', + title: { + en: 'Renderscript' + }, + description: { + en: 'A set of samples that demonstrate how to use various features of the Renderscript APIs.' + } + }, + { tags: ['sample', 'accountsync'], path: 'samples/SampleSyncAdapter/index.html', title: { -- cgit v1.1
    An {@link android.renderscript.Element} is the most basic element of a memory type. An element represents one cell of a memory allocation. An element can have two forms: Basic or - Complex. They are typically created from C structures that are used within Renderscript - code and cannot contain pointers or nested arrays. The other common source of elements is - bitmap formats. + Complex. They are typically created from C structures in your Renderscript + code during the reflection process. Elements cannot contain pointers or nested arrays. + The other common source of elements is bitmap formats.

    A basic element contains a single component of data of any valid Renderscript data type. Examples of basic element data types include a single float value, a float4 vector, or a @@ -253,12 +256,11 @@ parent.link=index.html

    rs_allocation - An {@link android.renderscript.Allocation} provides the memory for applications. An {@link +

    An {@link android.renderscript.Allocation} provides the memory for applications. An {@link android.renderscript.Allocation} allocates memory based on a description of the memory that - is represented by a {@link android.renderscript.Type}. The {@link - android.renderscript.Type} describes an array of {@link android.renderscript.Element}s that + is represented by a {@link android.renderscript.Type}. The type describes an array of elements that represent the memory to be allocated. Allocations are the primary way data moves into and - out of scripts. + out of scripts.

    Memory is user-synchronized and it's possible for allocations to exist in multiple memory spaces concurrently. For example, if you make a call to the graphics card to load a @@ -270,9 +272,9 @@ parent.link=index.html

    Allocation data is uploaded in one of two primary ways: type checked and type unchecked. For simple arrays there are copyFrom() functions that take an array from the - Android system code and copy it to the native layer memory store. Both type checked and + Android system and copy it to the native layer memory store. Both type checked and unchecked copies are provided. The unchecked variants allow the Android system to copy over - arrays of structures because it not support inherently support structures. For example, if + arrays of structures because it does not support structures. For example, if there is an allocation that is an array n floats, you can copy the data contained in a float[n] array or a byte[n*4] array.

    rs_program_vertex - The Renderscript vertex program, also known as a vertex shader, describes the stage in the +

    The Renderscript vertex program, also known as a vertex shader, describes the stage in the graphics pipeline responsible for manipulating geometric data in a user-defined way. The - object is constructed by providing Renderscript with the following data: + object is constructed by providing Renderscript with the following data:

    • An Element describing its varying inputs or attributes
    • @@ -367,7 +369,9 @@ parent.link=index.html inputs
    -

    Once the program is created, bind it to the graphics context. It is then used for all +

    Once the program is created, bind it to the {@link android.renderscript.RenderScriptGL} + graphics context by calling + {@link android.renderscript.RenderScriptGL#bindProgramVertex bindProgramVertex()}. It is then used for all subsequent draw calls until you bind a new program. If the program has constant inputs, the user needs to bind an allocation containing those inputs. The allocation’s type must match the one provided during creation. The Renderscript library then does all the necessary @@ -391,7 +395,7 @@ parent.link=index.html

    rs_program_fragmentThe Renderscript fragment program, also known as the fragment shader, is responsible for +

    The Renderscript fragment program, also known as the fragment shader, is responsible for manipulating pixel data in a user-defined way. It’s constructed from a GLSL shader string containing the program body, textures inputs, and a Type object describing the constants used by the program. Like the vertex programs, when an allocation with constant input values is @@ -401,7 +405,7 @@ parent.link=index.html rsgAllocationSyncAll so it could send the new values to hardware. Communication between the vertex and fragment programs is handled internally in the GLSL code. For example, if the fragment program is expecting a varying input called varTex0, the GLSL code inside the - program vertex must provide it. + program vertex must provide it.

    To bind shader constructs to the this Program, declare a struct containing the necessary shader constants in your native Renderscript code. This struct is generated into a reflected class that you can use as a constant input element during the Program's creation. It is an easy way to create an instance of this struct as an allocation. @@ -416,7 +420,7 @@ parent.link=index.html

    rs_program_store The Renderscript ProgramStore contains a set of parameters that control how the graphics - hardware writes to the framebuffer. It could be used to enable/disable depth writes and + hardware writes to the framebuffer. It could be used to enable and disable depth writes and testing, setup various blending modes for effects like transparency and define write masks for color components.