About savelayer #122
-
Compared to skia, tgfx has removed the savelayer API. What was the reason behind this decision? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There are two reasons why tgfx does not implement the saveLayer API. Firstly, the saveLayer API is just a shortcut, offering a convenient way to create temporary surfaces. As such, it is not necessary since the same functionality can be achieved by manually creating surfaces. Secondly, this API can significantly impact rendering performance. To optimize rendering performance, it is crucial to minimize offscreen rendering phases whenever possible. However, the saveLayer API can introduce numerous unnecessary offscreen-rendering phases without the user's awareness. Therefore, to maintain optimal performance, tgfx has chosen not to implement this API. The question you've raised is a good one. The most notable performance improvement achieved by tgfx lies in its API design rather than its implementation. At the core of the tgfx engine, the implementation of each functionality closely resembles Skia. However, Skia offers an abundance of API choices for rendering the same result, but not all of them are optimal designed for the GPU rendering pipeline. In contrast, tgfx focus on delivering essential APIs that maximize GPU rendering performance. Consequently, users are compelled to adhere to best practices for GPU rendering, leaving them with no alternative but to optimize their approach. A real-world example would illustrates this point effectively. The Tencent Docs team have successfully upgraded their underlying rendering engine from Skia to tgfx, resulting in notable performance improvements and a considerably smaller binary size. However, this transition required an extensive project refactor to accommodate the missing APIs in tgfx compared to Skia. Interestingly, they also built a version that runs the refactored project on top of Skia, utilizing only the APIs available in tgfx. Surprisingly, this approach resulted in similar performance improvement. This outcome confirms that point, sometimes, less indeed is more. Skia remains the exceptional rendering engine, offering a plethora of techniques to learn from. However, we will carefully select and implement only the most valuable aspects. |
Beta Was this translation helpful? Give feedback.
There are two reasons why tgfx does not implement the saveLayer API. Firstly, the saveLayer API is just a shortcut, offering a convenient way to create temporary surfaces. As such, it is not necessary since the same functionality can be achieved by manually creating surfaces. Secondly, this API can significantly impact rendering performance. To optimize rendering performance, it is crucial to minimize offscreen rendering phases whenever possible. However, the saveLayer API can introduce numerous unnecessary offscreen-rendering phases without the user's awareness. Therefore, to maintain optimal performance, tgfx has chosen not to implement this API.
The question you've raised is a good one…