Recently, the deepin community made an appearance at COSCon'24, the 9th China Open Source Conference, where senior desktop R&D engineer Zhang Dingyuan presented a technical sharing session titled "Treeland: The Stepping Stone of DDE's Progress."
Taking this opportunity, let's discuss how to pursue gorgeous animations and smooth experiences while maintaining a lightweight and efficient system. It's like playing a balancing game, with designers and architects standing at opposite ends of a scale, one side being a visual feast and the other a performance beast. Striking the balance between these two requires our R&D team to cleverly "sacrifice" some hair (brainpower) to achieve.
deepin in COSCon'24
Historical Background
During the deepin 15 era, the development team utilized Mutter to provide smooth graphics effects for high-performance devices and Metacity to ensure system fluidity on low-specification devices. However, in the deepin 20 era, the team decided to adopt KWin as the new window manager due to its robust features and the ability to disable compositing, making it adaptable to various hardware configurations. As a result, the combination of Mutter and Metacity was abandoned to ensure a smooth and secure graphical interface experience across different devices. Nevertheless, the continuous advancement of technology has once again prompted us to face technological innovation.
Technical Choices: X11 and Wayland
Currently, under Linux, there are two technology stacks: the long-standing X11 and the relatively newer Wayland. Let's compare these two technologies together.
X11 | Wayland | |
Architecture | The traditional client-server model, supporting network transmission and remote display. | Simplified design, removing the complexity of the × server, improving efficiency and response speed, focusing on local display. |
Performance | Due to its outdated design, performance is suboptimal in modern scenarios, relying on extensions and patches to achieve modern graphical effects. | Modernized design, simplified rendering process, with significant performance improvements, especially in animation and window operations. |
Security | Significant security issues, applications can access each other's window information and are susceptible to interference from malicious programs. | Strong application isolation, unable to access the graphics or input/output of other programs, ensuring high security. |
Scalability and Compatibility | X11 has very extensive application support and compatibility, with many old applications and desktop environments still relying on the X11 protocol. | Gradually supported by mainstream desktop environments, but the ecosystem is not as widespread as X11, requiring compatibility layers to run X11 applications. |
Input Device Support | Mature support for traditional input devices, but not flexible enough in multi-touch and gesture support. | Optimized support for modern hardware, especially in multi-touch and gesture recognition. |
Remote Desktop and Network Transparency | Supports the remote transmission of display content over the network, suitable for professional use. | Lacks X11's network transparency, with limited remote desktop functionality, often requiring third-party tools. |
In summary, X11, as a veteran display server, boasts extensive compatibility and a mature ecosystem. However, its architecture has certain limitations in terms of security, performance, and ease of use. In contrast, Wayland, as an emerging display server, simplifies the communication process between clients and servers, reducing potential security vulnerabilities and thus enhancing overall security.
Furthermore, Wayland has significant advantages in performance, being better equipped to support modern display technologies, such as high-resolution and high-frame-rate display tasks. Lastly, Wayland's architectural design makes its configuration and management relatively straightforward, resulting in a more user-friendly experience, which helps attract more novice users.
Architectural Design and the New Window Manager Treeland
From a technical perspective, we believe it is time to update our technical solution. The former model of X11 + window manager + compositor was flexible but did not meet the demands. Wayland offers an updated mechanism that avoids screen tearing by integrating the window manager, compositor, and display system at the foundation level.
Therefore, DDE decided to develop a new window manager—Treeland—in conjunction with Wayland. It uses wlroots as the underlying Wayland base library, without modifying the wlroots code, allowing for synchronization with upstream progress at any time to obtain new features and fixes. The upper layer uses Qt, making the technology stack more unified. It is designed specifically to meet the needs of DDE, avoiding common issues such as destructive adjustments, synchronization problems, and maintenance costs associated with using third-party window managers.
The diagram above illustrates which projects or interfaces Treeland will use overall to complete its functions.
Treeland Structure Diagram
Treeland's Technical Structure and Features
1、Important Project Introduction
- Qwlroots: Qt bindings for wlroots, converting Wayland signals into Qt-style signals.
- Waylib: Encapsulates wlroots components into QtQuick objects, using QPA to provide event translation and distribution for Treeland.
- DtkDeclarative: QtQuick components of DTK, encapsulating most DTK style controls.
In Waylib, the QPA (Qt Platform Abstraction) plays a crucial role. System-level events first enter Waylib, where they are converted into internal Qt events and sent to the upper layers. When a user clicks on a window, Treeland generates an event through Waylib and sends it to the client, completing the interface interaction.
Treeland's Process for Handling Underlying and Upper-layer Events.
2、Interface Effects and Optimization
- Rounded Corners:
DDE and deepin community applications extensively use window rounded corners. Treeland provides its own corner-cutting widget, with a new shaping algorithm that reduces the number of geometric vertices and computational load, and employs a new anti-aliasing algorithm to improve GPU performance. QtQuick rounded corners are provided by the Rectangle component, which can only operate on all four corners at the same time (red block). However, DTK programs have the capability of irregular window shapes, so Treeland offers its own corner-cutting widget (yellow block).
The new shaping algorithm reduces the number of geometric vertices by 50% compared to the native Rectangle of QtQuick, and the performance of GPU vertex rendering and triangle tessellation is increased by 100%.
By adopting the new anti-aliasing algorithm, the performance of the GPU fragment shader is improved, reducing the computational load to 1/4 compared to the standard 4xMSAA anti-aliasing algorithm.
Red for QtQuick rounded corners / Yellow for Treeland rounded corners.
- Blur:
The blur component in QtQuick only supports blurring the control itself, which does not meet the needs of Treeland. Treeland re-implements the blur component, capable of obtaining image data from the memory below the component and using a fusion blur algorithm to optimize performance.
QtQuick Blur Component
Treeland Blur Component
- Shadows:
Treeland uses BorderImage as the window shadow texture, manually creating texture materials through ImageProvider, allowing the same material to be reused for the same size.
- Animations:
Directly use the animation components provided by QtQuick to provide animation effects for the interface. Define attribute changes for components using State and Transition, such as window maximization and restoration. Switching between two States triggers different Transitions to execute attribute changes. During attribute changes, use the animation components of QtQuick to complete the animation playback.
3、Multi-user Feature
As part of the solution, Treeland aims to enable multiple users to share a compositor. Compared to traditional models, DDM and Treeland redesign the workflow by separating Treeland. Users send window content to Treeland for composition and display through the same mechanism, saving memory and avoiding issues such as black screen flickering and state synchronization challenges.
一个简化的 DDM 与 Treeland 的多用户登录流程
4、Integration with systemd
Each user session in DDE switches to a systemd service, and under the Treeland model, a separate service is loaded to inject display environment variables into the user session, using systemd's socket mechanism for lazy loading to ensure that the user-side windows are displayed correctly.
A Simplified Multi-user Login Process for DDM and Treeland
Summary
The evolution of the Deepin Desktop Environment (DDE) in terms of window managers, from Mutter and Metacity, to KWin, and now to our own Treeland, demonstrates our ongoing innovation and improvement in system architecture and user experience.
Related Readings:
(1)International Rankings for deepin
(2)deepin Desktop Environment(DDE)
(3)deepin Community Monthly Report
Content source: deepin community
Reprinted with attribution