Android Graphic System Analysis and transplantation-4. Surface Manager (surface flinger Introduction)

Source: Internet
Author: User

Surface manager is a module responsible for displaying information in libraries under the framework in a user space. When the system executes multiple applications at the same time, surfacemanager is responsible for managing interaction between display and access operations, it is also responsible for the synthesis of 2D and 3D graphics.

1. Surface manager Architecture Analysis

The image system in Android adopts the client/server architecture as follows:

Client: Application-related parts. The code is divided into two parts: one is the supplied APIs provided by Java, and the other is the underlying implementation written by C ++.

Server: surfaceflinger, responsible for merging and sending it to the buffer for display. It is mainly written by C ++ code.

The client and server communicate with each other through the binder IPC method. The overall structure is shown in Figure 1:

As shown in, the client part of the surface is actually a bridge for various applications to perform drawing operations. This bridge leads to surfaceflinger on the server through the binder, and surfaceflinger is responsible for synthesizing various surfaces, then, the buffer is transmitted to the framebuffer end for underlying display. Each surface corresponds to two buffers, one frontbuffer and one back buffer. when the data is updated, the data is updated on the back buffer. When the data needs to be displayed, the back buffer and the front buffer are exchanged.

Next we will focus on surface flinger.

2. Surface flinger

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) according to the requirements of the receiving client, modify the layer attribute (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.

3. Basic Structure of surface flinger

Shows the basic composition framework of surface flinger.

Surfaceflinger management object:

1) mclientsmap: manages the connection between the client and the server.

2) isurface, isurfacecomposer: aidl call interface instance

3) mlayermap: The management object of the server surface.

4) mcurrentstate. layerssortedbyz: layer array arranged in the Z-order sequence of the surface.

5) graphicplane buffer output management

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

7) gralloc. XXX. So is a platform-related graphics buffer manager and a hardware abstraction layer of FB.

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

4. surfaceflinger and 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.

Data structure diagram of surfaceflinger and hardware buffer zone:

5. Running framework of surfaceflinger

Surfaceflinger's runtime framework exists in threadloop, which is the main loop body of surfaceflinger. Threadloop flowchart:

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

3) During painting, the layer will copy the data in the corresponding area based on its visible area.

Process:

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 ()

This interface is called in threadloop to push the merged data (stored in back buffer) into the front buffer, and then call the Hal interface command to display the underlying layer.

The following is a summary of what surfaceflinger does:

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.