Theoretical Paper
- Computer Organization
- Data Structure
- Digital Electronics
- Object Oriented Programming
- Discrete Mathematics
- Graph Theory
- Operating Systems
- Software Engineering
- Computer Graphics
- Database Management System
- Operation Research
- Computer Networking
- Image Processing
- Internet Technologies
- Micro Processor
- E-Commerce & ERP
Practical Paper
Industrial Training
Android - RenderScript
In this chapter, we will learn about Android RenderScript. Usually the apps on android are designed as to consume as minimum resources as possible. But some applications like some 3D games need high level processing on android.
To provide these applications high performance android introduced the RenderScript. It is android based framework which is used for running applications that perform very highly computational tasks. The development on this framework is done in Native Development Kit(NDK) provided by android. RenderScript is extremely useful for applications which performs following types of actions −
- 3D Rendering
- Image Processing
- Computational Photography
- Computer Vision
How RenderScript Works
RenderScript framework is basically based on data parallel computation. It distributes your application workload on all the processors available on your device like multi-core CPUs or GPUs.
This parallel distribution of workload frees the programmer from the tension of load balancing and work scheduling. You can write more detailed and complex algorithms for your app without the worry of computational power.
How to Begin
To use the RenderScript Framework you must have following two things −
- A RenderScript Kernel
- RenderScript APIs
A RenderScript Kernel
A kernel is a program which manages data processing instructions and manage workload on Central Processing Units.A kernel is a fundamental part of the operating system.
Similarly to run the RenderScript framework we need a written script named as Kernel to manage all the data processing requests from our app and utilize more features of the android OS provided by the NDK and as mentioned earlier that the development of RenderScript is done in the Native Development Kit of Android.
The Kernel Script is written in C-99 standard of C-language. This Standard was before the development of C++. A RenderScript kernel script file usually placed in .rs file. Each file is called as a script. A RenderScript Kernel script can contain following elements −
Sr.No | Elements & Description |
1 | A Language declaration |
2 | A package declaration |
3 | Invokable functions |
4 | Script Global Variables |
Following is the Sample Code of a Kernel −
uchar4 __convert__((kernel)) invert(uchar4 in, uint32_t x, uint32_t y) { uchar4 out = in; out.r = 255 - in.r; out.g = 255 - in.g; return out; }
RenderScript APIs
If you want to use RenderScript in your API, you can do it in following two ways −
Sr.No | APIs & Description |
1 | android.renderscript |
2 | android.support.v8.renderscript |
To android support library following tools are required −
- Latest Android SDK Tools version
- Latest Android SDK Build-tools version
How to use RenderScript Support Library
First Open the project.properties file in your project and add following lines in the file −
renderscript.target=18 renderscript.support.mode=true sdk.buildtools=18.1.0
Now open your main class which use RenderScript and add an import for the Support Library classes as following −
import android.support.v8.renderscript.*;
Following are the purposes of above mentioned properties that we add in the project.properties file.
Sr.No | Project properties & Description |
1 | renderscript.target |
2 | renderscript.support.mode |
3 | sdk.buildtools |
Now call your RenderScript Kernel functions and compute complex algorithms in your app.