Android core analysis (26) -- surfaceflinger of Android GDI

Source: Internet
Author: User
Surfaceflinger of Android GDI

Surfacefinger is translated as a surface shipper by English. The structure of sufaceflinger is not too complex, but the complexity of sufaceflinger is its client construction. The main functions of sufaceflinger are:

1) refresh the content of layers (surfaces) to the screen.

2) maintain the zorder sequence of the layer and perform the cropping calculation on the final output of the layer.

3) In response to client requirements, create a layer to establish a connection with the client's surface.

4) receive client requirements and modify layer attributes (output size, Alpha, and other settings)

But as the actual meaning of shipping, what we need to know first is how to deliver, throw, shipping route, and shipping destination.

1 basic architecture of surfaceflinger

Surfaceflinger management object:

Mclientsmap: manages the connection between the client and the server.

Isurface, isurfacecomposer: aidl call interface instance

Mlayermap: The management object of the server surface.

Mcurrentstate. layerssortedbyz: layer array arranged in the Z-order sequence of the surface.

Graphicplane buffer output management

OpenGL ES: Graphics libraries such as graphic computing and image synthesis.

Gralloc. XXX. So this is a platform-related graphics buffer manager.

Pmem device: Provides shared memory, which is only visible in gralloc. XXX. So and abstracted by gralloc. XXX. So on the upper layer.

2 surfacefinger client and server object Relationship Diagram

The connection between the client and surfaceflinger is shown in the following figure:

 

Client object: Generally, surfacecomposerclient is used on the client to deal with surfaceflinger.

3 main object description 3.1 displayhardware & framebuffer

First, surfaceflinger needs to operate on the screen, and a screen hardware buffer management framework needs to be established. When designing and supporting multiple screens, Android introduces the graphicplane concept. Surfaceflinger has a graphicplane array. Each graphicplane object corresponds to a displayhardware. In the current Android (2.1) design, the system supports a graphicplane, so it also supports a displayhardware.

Surfaceflinger: Data Structure Diagram of the hardware buffer.

3.2 Layer

Method: setbuffer creates a display buffer on the surfaceflinger side. The buffer here refers to the HW property, pmem Device File ing memory.

1) layer Rendering

Void layer: ondraw (const region & clip) const

{

Int Index = mfrontbufferindex;

Gluint texturename = mtextures [Index]. Name;

...

Drawwithopengl (clip, mtextures [Index]);

}

3.2 mcurrentstate. layerssortedbyz

Layerbase array arranged in the Z-order sequence of the surface, which is the basis for layer display occlusion. When each layer calculates its own visible area, it starts from the top layer of Z-order, considering the reduction of the blocked area, the visible area of its previous layer is its own invisible area. When the layer is drawn, it is drawn from the bottom layer of Z-order, which takes into account the superposition of the transparent layer.

4 surfaceflinger runtime framework

We can see from the basic principles of the previous chapter <Android service> that the surfaceflinger runtime framework exists in threadloop, which is the main loop body of surfaceflinger. Surfaceflinger will first run: surfaceflinger: readytorun () before entering the main body loop ().

4.1 surfaceflinger: readytorun ()

(1) Create graphicpanle

(2) establish framebufferhardware (determine the output target)

Initialization: OpenGL ES

Build compatible mainsurface. Use eglcreatewindowsurface.

Create the OpenGL ES process context.

Create a main surface (OpenGL ES ). The init () @ displayhardware. cpp function of displayhardware initializes OpenGL and creates the primary surface. Why is it the main surface? Because all layers need to be drawn on the main surface before the system throws the content of the main surface to the real screen.

(3) binding the primary surface

1) After displayhandware is started, HW. makecurrent () binds the context of the main surface and OpenGL ES processes to the context of surfaceflinger,

2) then all the operation destinations using EGL in all surfaceflinger processes are msurface @ displayhardware.

In this way, when OpenGL draws a graph, the main surface is recorded in the context of the process, so the displayed parameters of the main surfce cannot be transmitted. The following are the actions of layer-draw and hardware. Flip:

4.2 threadloop

(1) handletransaction (...) : It mainly calculates whether each layer has any Attribute Modification. If there is any modification, it needs to be re-painted.

(2) handlepageflip ()

Computevisibleregions: calculates the visible and overwritten regions of each layer based on the Z-order sequence. Crop output range calculation-

When generating a cropping area, each layer must perform the following steps to calculate its display area on the screen according to z_order:

1) Use your own W and H to show your initial visible regions

2) subtract the area covered by the window above

During painting, layer copies the data of the corresponding region based on its own region.

(3) handlerepaint ()

Composesurfaces (refresh area required ):

Based on the visible area of each layer and the intersection area of the area to be refreshed, the Z-order sequence is drawn from the bottom to the main surface.

(4) postframebuffer ()

(Displayhardware) HW. Flip (minvalidregion );

Eglswapbuffers (display, msurface): delivers msruface to the screen.

5. Summary

What surfaceflinger does now is shown below:

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.