Android 4.4 Fence application in SurfaceFlinger, androidflinger

Source: Internet
Author: User

Android 4.4 Fence application in SurfaceFlinger, androidflinger

There is very little information about android and fence on the Internet, but this mechanism plays an important role in the GUI system, so I read the source code and comments myself, I 'd like to share with you what Fence is like?

Fence is a barrier. The role of a barrier is very similar to its name. A group of threads can use barrier to synchronize with each other collectively. In essence, each thread calls the barrier wait () method when it reaches a certain rolling state to block it, wait until all other participating threads call the wait () method to indicate that they have reached this status. once all threads reach the barrier, they will collectively lift the blocking and continue execution together. The state that causes the program to call the wait () method of the barrier to block is called the barrier state;

This article mainly describes the theoretical basis of fence's Application in surfaceflinger. Specifically, fence can coordinate their synchronization work in the buffer processing process of producer and consumer, this ensures the accuracy of the buffer content without being tampered.

First, we know that a buffer has the following statuses:

FREE-> DEQUEUED-> QUEUED-> ACQUIRED-> FREE

Can the producer apply for the FREE status? The answer is wrong. He needs to wait for a signal, that is, the NO_FENCE signal, because it is possible that the buffer applied for last time is being processed by the consumer job, so he has to wait for the consumer to send the finish signal, at this time, the buffer in the FREE State is blocked by the barrier. Here we use the wait () or waitForever () method in Fence and wait for a NO_FENCCE signal to open the barrier. Go to the next process.

DEQUEUED indicates that the producer has applied for a buffer to come out of the queue and has not yet entered the queue or canceled the buffer, when the producer wants to modify the UI data, it must wait for a NO_FENCE signal, because other owners may be operating on it. When the signal arrives, poducer can operate it and then send a NO_FENCE signal.

In the QUEUED status, the buffer is put into the queue. However, before this operation, a NO_FENCE signal is required, such as the NO_FENCE sent after the dequeueBuffer is completed in the previous step. after receiving the signal, the system enters the queue or cancels the buffer operation. At this time, its owner becomes BufferQueue.

The ACQUIRED status means that the producer has filled the buffer. Like before, it will have to wait for a NO_FENCE signal before the consumer can operate on it. After the operation is complete, the buffer is released and a NO_FENCE signal is sent.

Now I know the Fence workflow.

Fence sends a signal when the previous owner finishes a job. When a buffer is free, the consumer has read something from the buffer, or if it calls cancelBuffer after some queuebuffer operations when the producer completes the write operation on the buffer. If the buffer is in the QUEUED state, this indicates that the buffer is filled by the producer. When the buffer is in the DEQUEUE or ACQUIRED state, fence has been passed to the consumer or producer together with the buffer. In this case, fence is set to NO_FENCE.

 

 

 


How to install new application software after meizu mx3 enables the Android 44 ART Mode

The newly installed software is in the ART mode, and the installation time is longer than that in the previous D mode. You do not need to switch back and forth.

What does SurfaceFlinger mean?

Touch sensor driver

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.