Android advanced Renderscript --- Andvanced Renderscript (1)

Source: Internet
Author: User

Because the application using Renderscript still runs inside the Android Virtual Machine (VM), you can access all the framework APIs you are familiar with, but you can also use Renderscript at the right time. To promote the interaction between the Renderscript runtime and the framework, use the intermediate layer code to help. Facilitate communication and memory management between two code layers. This article discusses more details about different code layers, as well as the shared memory between the Android VM and Renderscript runtime.

Renderscript Runtime Layer

Renderscript code is compiled and executed at a concise and clear Runtime layer. The Renderscript Runtime API provides intensive computing support, which can be conveniently and automatically extended to the available processor kernel.

Note: The Standard C functions in NDK must run on the CPU, so Renderscript cannot access these class libraries because Renderscript is designed to run on different types of processors.

The Renderscript code must be defined in the *. rs and *. rsh files in the src/directory of the Android project. The llvm compiler Renderscript code is compiled into an intermediate bytecode and runs as part of Android compilation. When an application runs on a device, the bytecode is instantly compiled into a machine code through another llvm compiler residing on the device. This machine code is optimized for the device and cached. Therefore, you do not need to re-compile this bytecode for later use of this Renderscript.

The Renderscript runtime class library includes the following key functions:

1. Memory Allocation request function;

2. mathematical function library with scalar and vector types. This function library is an overloaded version of many common routines. Such as addition operations, multiplication operations, dot matrix operations, cross-Product Operations, atomic computing, and comparison functions are all effective;

3. Conversion of raw data and vectors, matrices, dates and times;

4. Support the data types and structures of the Renderscript system, such as the two-dimensional, three-dimensional, and four-dimensional vectors defined for the vector type;

5. Log functions.

Reflection Layer

The reflection layer is a group of classes generated by Android compilation tools that allow access to Renderscript runtime from the Android framework. This layer also provides methods and constructors that allow memory allocation and related work by using the memory pointed to by pointers defined in Renderscript code. The following lists some major reflection components:

1. each. the rs file generates a class named project_root/gen/package/name/ScriptC_renderscript_filename of the ScriptC type. This file is yours. rs file. java version. You can call this class in the Android framework. This class contains the following items reflected from the. rs file:

A. Non-static functions;

B. Non-static, global Renderscript variables. The Android compilation tool generates accessors for each variable so that the Renderscript variables can be read and written in the Android framework. If a global variable is initialized at the Renderscript runtime layer, the initialized values are used to initialize the corresponding variables in the Android framework layer. If the global variable is marked as const, the set method is not generated.

C. Global pointer www.2cto.com

A struct reflected to its class named project_root/get/package/name/ScriptField_struct_name, which inherits the Script. FielBase class. This represents a struct array that allows memory allocation to multiple instances of this struct.

 


By FireOfStar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.