Android‍Pixelflinger Research

Source: Internet
Author: User

From http://hi.baidu.com/aokikyon/blog/item/2e8ca6130db328906438db18.html

 

1. Introduction to Pixelflinger
Pixelflinger is a set of software renderer (renderer) provided for the OpenGL ES engine in the Android system ). When the system starts, you can view the startup log information to obtain the software version (CODE) of the current Pixelflinger ). The Pixelflinger software version is upgraded with the Android version. The latest version is 1.3 (based on Android2.2 ).
I/SurfaceFlinger (1931): OpenGL informations:
I/SurfaceFlinger (1931): vendor: Android
I/SurfaceFlinger (1931): renderer: Android PixelFlinger 1.2
I/SurfaceFlinger (1931): version: OpenGL ES-CM 1.0
As a software Renderer, Pixelflinger provides a series of basic drawing functions for the OpenGL ES engine. These features include defining pixel positions in various color formats, drawing points, drawing Rectangles and triangles, and filling textures. Since OpenGL ES is equivalent to a state machine, functions for configuring OpenGL ES State are also provided by Pixelflinger.
The source code of Pixelflinger is located in system/core/libpixelflinger.
The header file is located in system/core/include/libpixelflinger and system/core/include/private/pixelflinger.

2. Pixelflinger main Data Structure
Pixelflinger defines the context_t struct in the header file Ggl_context.h to store OpenGL ES states and data contexts. The context_t struct includes GGLContext, state_t, shade_t, iterators_t, generated_vars_t, and other structs.
The GGLContext struct contains some function interfaces that the Pixelflinger library can provide for upper-layer calls, including drawing points, drawing polygon, and configuring OpenGL ES state machines.
State_t struct is used to describe the state of the OpenGL ES state machine. It contains multiple child structures, and each child struct is responsible for processing some OpenGL ES functions. The options include storing textures and textures, cropping, raster operations, hybrid operations, depth of field operations, and atomization operations.

3. Pixelflinger Initialization
GglInit (GGLContext ** context)
Allocate space for context_t;
Call ggl_init_context (c );
Ggl_init_context (context_t * c)
Call ggl_init_procs (c) to hook the function pointer of the state_t struct with the function pointer in Pixelflinger. cpp.
Call ggl_init_trap (c) to configure the state of the OpenGL ES state machine.
Call ggl_init_scanline (c) to hook the scanline function with the context_t interface.
Call ggl_init_texture (c) to initialize the texture-related status.
Call ggl_init_picker (c), empty function.
Call ggl_init_raster (c) to hook the functions in Raster. cpp with the function pointer of the state_t struct.
Initialize other information and jitter Matrix
Ggl_init_procs (context_t * c)
Ggl_init_procs uses the GGL_INIT_PROC macro to hook the function pointer.
# Define GGL_INIT_PROC (p, f) p. f = ggl _ # f;

4. Main Function interfaces provided by GGLContext
Direct rendering Function
Pointx, linex, recti, trianglex
Cropping Function
Scissor
Set texture and color Buffering
ActiveTexture
BindTexture
ColorBuffer
ReadBuffer
DepthBuffer
Bindtexturelevels
Function Control Switch
Enable
Disable
EnableDisable
Specify the clip color
ShadeModel
Color4xv
Color iterator
ColorGrad12xv
Zcoordinate iterator
ZGrad3xv
Specify the W coordinate iterator
WGrad3xv
Specify the fog iterator and color
FogGrad3xv
FogColor3xv
Specify mixed Parameters
BlendFunc
BlendFuncSeparate
Texture environment (including four textures REPLACE/MODULATE/DECAL/BLEND)
TexEnvi
TexEnvxv
Texture parameters (packaging and filtering)
TexParameteri
Texture iterator
TexCoord2i
TexCoord2x
Use block floating point for texture ST coordinates
TexCoordGradScale8xv
TexGeni
Shield Function
ColorMask
DepthMask
StencilMask
Alpha Function
AlphaFuncx
Depth of field function
DepthFunc
Logical operation interface
LogicOp
Clear Function
Clear
ClearColorx
ClearDepthx
Clearstencel
Framebuffer operations
CopyPixels
RasterPos2x
RasterPos2i

5. Color formats supported by Pixelflinger
Pixelflinger defines the supported color formats and pixel positions in Format. cpp. Common color formats include RGBA8888, RGBX8888, RGB565, and BGRA8888. From the structure, we can see that the Alpha channel is 32-24 bits and is a high position. It can be seen that RGBA8888 uses the big-End sequence. The color format defined here can only be used by ANdroid OpenGL ES, and is irrelevant to the image drawn through Canvas.
Static GGLFormat const gPixelFormatInfos [] =
{// Alpha Red Green Blue
{0, 0, {0, 0, 0, 0, 0, 0, 0 }}, 0}, // PIXEL_FORMAT_NONE
{4, 32, {32, 24, 8, 0, 16, 8, 24, 16 }}, GGL_RGBA}, // PIXEL_FORMAT_RGBA_8888
{4, 24, {0, 0, 8, 0, 16, 8, 24, 16 }}, GGL_RGB}, // PIXEL_FORMAT_RGBX_8888
{3, 24, {0, 0, 8, 0, 16, 8, 24, 16 }}, GGL_RGB}, // PIXEL_FORMAT_RGB_888
{2, 16, {0, 0, 16, 11, 5, 5, 0 }}, GGL_RGB}, // PIXEL_FORMAT_RGB_565
{4, 32, {32, 24, 24, 16, 16, 8, 8, 0 }}, GGL_RGBA}, // PIXEL_FORMAT_BGRA_8888
{2, 16, {1, 0, 16, 11, 6, 6, 1 }}, GGL_RGBA}, // PIXEL_FORMAT_RGBA_5551
{2, 16, {4, 0, 16, 12, 8, 8, 4 }}, GGL_RGBA}, // PIXEL_FORMAT_RGBA_4444
{1, 8, {8, 0, 0, 0, 0, 0, 0 }}, GGL_ALPHA}, // PIXEL_FORMAT_A8
{1, 8, {0, 0, 8, 0, 8, 0, 8, 0 }}, GGL_LUMINANCE}, // PIXEL_FORMAT_L8
{2, 16, {16, 8, 8, 0, 8, 0, 8, 0 }}, GGL_LUMINANCE_ALPHA}, // PIXEL_FORMAT_LA_88
{1, 8, {0, 0, 8, 5, 5, 2, 2, 0 }}, GGL_RGB}, // PIXEL_FORMAT_RGB_332
{1, 16, {0, 8, 0, 8, 0, 0, 0 }}, GGL_Y_CB_CR_SP}, // PIXEL_FORMAT_YCbCr_422_SP
{1, 12, {0, 8, 0, 8, 0, 0, 0 }}, GGL_Y_CB_CR_SP}, // PIXEL_FORMAT_YCbCr_420_SP
{1, 16, {0, 8, 0, 8, 0, 0, 0 }}, GGL_Y_CB_CR_P}, // PIXEL_FORMAT_YCbCr_422_P
{1, 12, {0, 8, 0, 8, 0, 0 }}, GGL_Y_CB_CR_P}, // PIXEL_FORMAT_YCbCr_420_P
{1, 16, {0, 8, 0, 8, 0, 0, 0 }}, ggl_y_cb_cr_ I}, // pixel_format_ycbcr_422_ I
{1, 12, {0, 8, 0, 8, 0, 0, 0 }}, ggl_y_cb_cr_ I}, // pixel_format_ycbcr_420_ I
{0, 0, {0, 0, 0, 0, 0, 0, 0 }}, 0}, // pixel_format_none
{0, 0, {0, 0, 0, 0, 0, 0, 0 }}, 0}, // pixel_format_none
{2, 16, {0, 0, 16, 0, 0, 0, 0 }}, ggl_depth_component },
{1, 8, {8, 0, 0, 0, 0, 0, 0 }}, ggl_stencil_index },
{4, 24, {0, 0, 24, 0, 0, 0, 0 }}, GGL_DEPTH_COMPONENT },
{4, 8, {32, 24, 0, 0, 0, 0, 0 }}, GGL_STENCIL_INDEX },
};

6. Pixelflinger Optimization
1) Optimize the context_t storage space to ensure cache alignment and optimize performance. Context_t is the most common and largest data structure in Pixelflinger.

Void * const base = malloc (sizeof (context_t) + 32 );
Context_t * c = (context_t *) (ptrdiff_t (base) + 31 )&~ 0x1FL );
Ggl_init_context (c );

2) optimized through the compilation option in Android. mk
Ifeq ($ (TARGET_ARCH), arm)
# Special optimization flags for pixelflinger
PIXELFLINGER_CFLAGS + =-fstrict-aliasing-fomit-frame-pointer
Endif
-Fstrict-aliasing indicates that the compiler does not direct different types of objects to the same address.
-The fomit-frame-pointer option allows the compiler to save fp registers in function calls to improve efficiency.

3) directly optimize performance by replacing C language functions with Assembly
Ifeq ($ (TARGET_ARCH), arm)
PIXELFLINGER_SRC_FILES + = t32cb16blend. S
Endif

4) perform special optimization on different ARM versions
Ifeq ($ (TARGET_ARCH), arm)
LOCAL_ASFLAGS: =-march = armv6
LOCAL_SRC_FILES: = rotate90CW_4x4_16v6.S
LOCAL_MODULE: = libpixelflinger_armv6
Include $ (BUILD_STATIC_LIBRARY)
Endif

Rotate90CW_4x4_16v6:
// R0 = dst
// R1 = src
// R2 = dst stride in pixels
// R3 = src stride in pixels
Stmfd sp !, {R4, r5, r6, r7, r8, r9, r10, r11, lr}
Add r14, r3, r3
Add r12, r2, r2
Ldrd r2, r3, [r1], r14
Ldrd r4, r5, [r1], r14
Ldrd r6, r7, [r1], r14
Ldrd r8, r9, [r1]
Pkhbt r10, r8, r6, lsl #16
Pkhbt r11, r4, r2, lsl #16
Strd r10, r11, [r0], r12
Pkhtb r10, r6, r8, asr #16
Pkhtb r11, r2, r4, asr #16
Strd r10, r11, [r0], r12
Pkhbt r10, r9, r7, lsl #16
Pkhbt r11, r5, r3, lsl #16
Strd r10, r11, [r0], r12
Pkhtb r10, r7, r9, asr #16
Pkhtb r11, r3, r5, asr #16
Strd r10, r11, [r0]
Ldmfd sp !, {R4, r5, r6, r7, r8, r9, r10, r11, pc}

The rotate90CW_4x4_16v6 function uses the pkhtb command supported by the ARMv6 architecture to increase the processing speed.

5) system/core/libpixelflinger/codeflinger uses the C language to perform assembly operations by filling the machine code, and can dynamically generate assembly functions.

6) There are some open-source projects on the Internet that use the Neon coprocessor of the ARMv7 architecture to optimize the performance.
Http://code.google.com/p/0xdroid/issues/detail? Id = 57

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.