IOS off-screen rendering learning notes

Source: Internet
Author: User

Z

I. Conceptual understanding

In OpenGL, GPU screen rendering is available in the following two ways:

    • On-Screen Rendering

means the current screen rendering, which refers to the rendering operation of the GPU in the screen buffer currently used for display.

    • Off-screen Rendering

Off-screen rendering means that the GPU creates a new buffer outside the current screen buffer for rendering operations.

Second, off-screen rendering of the wrong

Compared to the current screen rendering, the cost of off-screen rendering is very high, mainly reflected in two aspects:

    • Create a new buffer

To perform off-screen rendering, you first create a new buffer.

    • Context Switches

The entire process of off-screen rendering requires multiple switching of the context: first switching from the current screen (on-screen) to off-screen (off-screen), and when the off-screen rendering is finished, the rendering of the off-screen buffer is displayed on the screen with the need to switch the context from off-screen to the current screen. And the context of the switch is to pay a great price.

Three, off-screen rendering trigger mode

When the following properties are set, off-screen drawing is triggered:

    • Shouldrasterize (rasterization)
    • Masks (matte)
    • Shadows (Shadow)
    • Edge antialiasing (anti-aliasing)
    • Group Opacity (opaque)

It is important to note that if Shouldrasterize is set to Yes, the rasterized content will be cached when the off-screen drawing is triggered, and if the corresponding layer and its sublayers are not changed, the next frame can be reused directly. This will improve rendering performance to a large extent.

If the other properties are turned on, there will be no cache, and the off-screen drawing will occur at each frame.

Iv. another special "off-screen rendering"

As previously said, if rendering in the current screen buffer that is not in the GPU is called off-screen rendering, there is another special "off-screen Rendering" method: CPU渲染 .

If we rewrite the DrawRect method and draw using any of the core graphics techniques, CPU rendering is involved. The entire rendering process is done by the CPU in the app 同步地 , and the rendered bitmap is finally transferred to the GPU for display.

Wu, Instruments

Instruments's core animation tool has several check options related to off-screen rendering:

    • Color offscreen-rendered Yellow

When turned on, the layers that need to be rendered off-screen are highlighted in yellow, which means there may be a performance problem with the yellow layer.

    • Color Hits Green and Misses Red

If Shouldrasterize is set to Yes, the corresponding render result is cached, if the layer is green, the cache is reused, and if it is red, the cache is created repeatedly, indicating that there is a performance problem.

Six, how to choose

Now in front of us there are three choices: current screen rendering, off-screen rendering, CPU rendering, which to use? This needs to be determined based on the specific usage scenario.

    • Use current screen rendering as much as possible

In view of the performance issues that can be caused by off-screen rendering and CPU rendering, in general, we try to use the current screen rendering as much as possible.

    • Off-screen rendering VS CPU rendering

Because the GPU has a higher floating-point capability than the CPU, CPU rendering may not be as efficient as off-screen rendering, but if you simply implement a simple effect, the efficiency of direct CPU rendering may be better than the off-screen rendering, after all, off-screen rendering involves time-consuming operations such as buffer creation and context switching.

In summary, the specific selection should be determined by the performance test results.

Seven, written in the last

In the Zhao Yan of the students to understand the concept of off-screen rendering, in this express thanks!

If you understand the error, please point out.

Reference documents

First draw pixel to screen

IOS off-screen rendering learning notes

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.