What is double buffering?

Source: Internet
Author: User

In the past, when I asked how to solve the flickering problem, many people would say that double buffering is used.

However, I am confused about the word double buffering.

What is double buffering, why is double buffering, and why does double buffering reduce flickering performance?

Double Buffering sounds very esoteric. In fact, its essence is very simple: a bitmap is formed, and all the drawing work is painted on this bitmap, and then draw the bitmap to the screen at one time.

Its key technology is: do not draw pictures directly on the screen, but draw all the drawing work first on the image.

Why give this technology a double buffer name?

We will study the process from plotting to displaying images on the screen.

Step 1: Buffer all drawings in place

Step 2: copy the bitmap to the screen. In this case, all the drawings jump to the screen.

The drawing performs two hops: The first hop is in place, and the second hop is on the screen. Therefore, this technology can be called double buffering.

// ...... Is it a little far-fetched? I personally think that it is only a single buffer with bitmap buffering. Why is it a dual buffer? For more information, see-0-

 

Why does double buffering reduce flickering performance?

Let's first analyze how flashes are generated?

The reason for the flash is the direct difference between the new graph and the old one.

1) when updating the image, use the background brush to brush the background, and then map the difference between the background brush and the image to cause flickering, this can eliminate onerasebkgnd (CDC * PDC) by checking background refreshing messages in response)

2) Draw a white image first, and then draw a red rectangle on the white image.

Assume that the response to onerasebkgnd (CDC * PDC) {. Return false...} is equivalent to a transparent brush. If double buffering is not required, what will happen when the invalidate redraws the window continuously:

At this point, the problem is solved, but a white image is first pasted on the screen, and then a red rectangle is painted on the white image. The color difference between the two is obvious, it will inevitably generate flashes.

 

If dual buffering is used, this phenomenon can be eliminated. The analysis is as follows:

First, draw a white image to the memory bitmap, then draw a red rectangle to the memory bitmap, and finally copy the bitmap to the screen.

Because the image on the original screen is slightly different from the image in the bitmap (both the white and red rectangles), it can effectively reduce the flicker when drawing frequently.

 

Well, how can we be convinced that there is no instance for analysis? Sometimes I read a lot of analysis, but it is better to give a specific small example.

Despise the guys who are confused and refuse to give an instance -- 0 --

The following is the pseudocode:

 

Bitmap BMP (width, height); // generates the graphics gbmp (& BMP) bitmap with the specified width and height ); // associate the bitmap with the GDI + drawing device with the solidbrush blackbrush (color (255,255,255); // set the background to gbmp. fillrectangle (& blackbrush, 0, 0, width, height); // click the bitmap gbmp. drawimage (m_pbmp, m_ulpoint.x, m_ulpoint.y, nwidth, nheight); // draw the image in gbmp. drawrectangle (........) // draw the rectangle in the position chart .... // draw other graphics (getdc ()-> m_hdc) in the in-place graph; // connect to graphics in the screen display area. drawimage (& BMP, width, height); // draw the bitmap to the screen at a time.

 

 

 

 

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.