I. Review

During the deepin 15 era, DDE utilized Mutter as a compositor-enabled window manager and Metacity as a compositor-disabled window manager. Mutter was designed for high-performance devices, while Metacity was intended for low-performance devices.

In the deepin 20 era, DDE switched to KWin as the window manager. Since KWin has a built-in mode to disable the compositor, DDE also abandoned the option of using Metacity as an alternative window manager.

 

II. Pain Points

Based on experience reports collected from the community, the vast majority of users are dissatisfied with screen scaling, and some users are unhappy with the user experience regarding stiff, rigid, and choppy animations.

In previous versions of DDE, due to the limitations of the X11 architecture, it was not possible to use different scaling for different screens. Many users might have a 1080p laptop screen connected to a 2K or 4K monitor. Under X11, users could only cater to the high-resolution screen at the expense of the low-resolution screen's usability. For example, enabling double screen scaling would make the display perfect on the high-resolution screen, but it would render the low-resolution screen unable to display any normal window properly.

 

III. Treeland

Treeland is a display server developed by the deepin community based on the Wayland protocol. It utilizes wlroots as the foundational library for Wayland at the lower level, without modifying the wlroots code. This means it can synchronize with upstream progress at any time, acquiring new features and fixes. The upper layer uses Qt, which allows for the full utilization of the extensive Qt developer community. There is no longer a need to have dedicated personnel for specific projects, making the DDE technology stack more unified.

 

IV. Optimizations

4.1 Screen Scaling

Treeland directly manages the screens, supporting the setting of independent scaling ratios for different screens, ensuring that high-resolution and standard-resolution screens can coexist perfectly. Through extended protocols, Treeland also supports fractional scaling ratios (such as 1.25 or 1.5), allowing for good display support across various resolutions. When windows move between different screens, Treeland adjusts their scaling ratio in real-time based on their location. When a window spans two screens, the system renders different parts of the window according to their respective scaling ratios, ensuring smooth display and natural transitions. This design allows users to always have a clear and user-friendly interface experience when working with multiple screens.

 

4.2 Clone Mode

Under X11, clone mode is achieved by setting both screens to the same resolution and overlapping their coordinates. However, this method has several significant drawbacks:

1、Redundant Rendering

X11 needs to render the same image for both screens, which is a very inefficient use of resources. In contrast, Treeland can directly send the same image data to multiple screens at the DRM level, avoiding redundant rendering and thus significantly reducing GPU load and improving performance.

2、Image Compression and Distortion

When the resolutions of the two screens differ significantly, X11 forcibly adjusts the resolution to maintain consistency, leading to image compression or distortion. Treeland, on the other hand, outputs at the native resolution and maintains the aspect ratio by leaving blank areas (letterboxing/pillarboxing) on the screen, effectively avoiding image distortion and optimizing the display effect in clone mode.

3、Enhanced Visual Effects

Treeland not only maintains the aspect ratio but can also draw additional content in the blank areas (such as the top, bottom, or sides), such as a blurred desktop wallpaper. This design enhances aesthetics and improves user experience, making clone mode more refined and natural.
Overall, Treeland's implementation significantly outperforms the traditional X11 clone mode in terms of performance, image quality, and user experience, bringing important optimizations for multi-screen application scenarios.

 

4.3 Window Effects

Treeland uses QtQuick as the rendering layer. However, some of the built-in components of QtQuick do not perform well. Here are the improvements and implementation details made to address the performance issues with QtQuick's built-in components.

1、Rounded Corners Optimization

The Rectangle component of QtQuick supports rounded corner effects, but it is limited to operating on all four corners at the same time and has certain performance bottlenecks. To address this issue, Treeland has implemented a custom rounded corner clipping control:

  • Irregular Window Support: Unlike the uniform corner clipping of the native QtQuick Rectangle, Treeland's custom control supports irregular rounded corner designs (such as the irregular window effects of DTK), greatly enhancing interface flexibility.
  • Algorithm Optimization:
    • The new rounded corner shaping algorithm reduces the number of geometric vertices by 50%, decreasing the GPU's vertex processing burden;
    • Triangle subdivision efficiency has been improved by 100%, further optimizing GPU rendering performance.
  • Anti-aliasing Improvement: A self-developed anti-aliasing algorithm has been introduced, which reduces the fragment shader computation by 25% compared to the traditional 4xMSAA algorithm, while maintaining visual quality.

2、Blur Effect Restructuring

QtQuick's native support for blur effects is relatively weak, and its performance is often insufficient for complex scenarios. Treeland has thoroughly restructured the blur effects:

  • Optimized Memory Access: By directly reading image data from the memory beneath the components, it avoids unnecessary CPU-GPU data exchange, enhancing the overall efficiency of blur processing.
  • Hybrid Blur Algorithm:
    • Integrating various blur algorithms (such as Gaussian blur and bilateral blur) to achieve a better balance of performance and visual quality;
    • For dynamic content scenarios, an incremental blur calculation method is used, further reducing the computational cost between frames.

3、Shadow Effect Optimization

QtQuick provides a BorderImage component that can add decorative effects to components through a nine-slice scaling technique. However, the native mechanism falls short in performance when applied on a large scale. The improvements in Treeland are as follows:

  • Material Reuse: Utilizes ImageProvider to manually control the creation and management of shadow map resources. When multiple components are of the same size, they share the same material resource, avoiding redundant loading and saving video memory;
  • Real-time Update: For windows that dynamically adjust in size, Treeland implements a real-time updating shadow clipping algorithm, eliminating the need to fully regenerate the map, further optimizing performance;
  • Visual Consistency: The transition effects of shadows are linked with window animations, enhancing the overall consistency and fluidity of the interface.

4、Animation Effect Improvements

Treeland directly uses QtQuick's State and Transition mechanisms for animation implementation, combined with custom optimizations, to achieve smooth interface dynamic effects:

State-driven:

    • Utilizes State to define different states of components (such as window maximize, minimize, restore, etc.);
    • Configures the logic of property changes during state transitions (such as position, size, opacity, etc.) through Transition.
  • Animation enhancement:
    • Leveraging QtQuick animation components (such as NumberAnimation and PropertyAnimation), high frame rate transitions are achieved.

Through these optimizations, Treeland has not only significantly improved the rendering efficiency of components but also made a leap forward in visual effects and user experience. Specifically, this is reflected in:

  • GPU performance enhancement: Compared to the native components of QtQuick, the rendering performance of Treeland has been improved overall;
  • Resource utilization optimization: By optimizing memory access and reusing materials, the memory and video memory usage has been greatly reduced, providing good compatibility even for low-performance devices.

 

4.4 Screenshot and Recording

Treeland offers an efficient quick region selection feature, supporting window snapping to automatically determine the selection boundaries, making the operation more intuitive and convenient. The system monitor can quickly obtain specific window-related information through this interface, simplifying the process of information extraction. Additionally, Treeland has significantly improved the efficiency of data copying by introducing DMA Buffer technology, supporting cross-screen screenshot functionality without the need for clients to handle complex window logic. To protect user privacy, Treeland strictly controls the information returned by screenshots and recordings, automatically redacting sensitive information from windows to prevent privacy leaks. In terms of screen recording functionality, Treeland comprehensively monitors recording sessions, providing real-time reminders to users that they are currently recording, effectively preventing privacy leaks without the user's knowledge. This design also addresses potential vulnerabilities caused by programs directly accessing screen data in the X11 environment, significantly enhancing the system's privacy protection capabilities.

 

4.5 Multi-User Support

Optimization for multi-user functionality is one of the core design goals of Treeland. In the traditional LightDM model, switching between different users relies on the transfer of control rights of the front-end program at the tty level, with each user having exclusive use of a tty for display. However, this approach has noticeable issues:

1、Switching Delays and Flicker

Since tty switching involves operations at the DRM and graphics driver level, the screen buffer is overlaid by different programs, causing the screen to flicker or even go black briefly.

2、Resource Consumption

Each user runs a separate process group, including the window manager, taskbar, file manager, etc. This not only consumes a significant amount of memory but also requires each user to run a separate lock screen interface, adding extra resource overhead.

3、Information Synchronization Challenges

To maintain interface consistency, state synchronization across users is required during user switching, which introduces complexity in implementation.

Treeland addresses these issues by introducing DDM (Deepin Display Manager) in its design, redefining the workflow to solve the above problems:

1、Centralized Composition

Treeland is decoupled as a unified compositor, with each user's window content being sent through a unified mechanism to Treeland for final composition and display. This architecture completely eliminates the flicker issues associated with switching between multiple ttys.

2、Memory Optimization

There is no longer a need to run separate processes such as window managers and lock screens for each user, significantly reducing memory overhead.

3、Unified State Management

Since all user interfaces are centrally managed by Treeland, there is no need to synchronize states across processes when switching users, simplifying the implementation.

Even under LightDM, Treeland can still operate normally as a user-level systemd service, serving as a standalone Wayland compositor. However, in this mode, Treeland cannot achieve the multi-user optimization features of DDM and only has the basic capabilities of a single-user Wayland compositor. Treeland's multi-user optimizations significantly enhance the user-switching experience through centralized composition and resource integration, improving system performance and simplifying implementation logic. Although it cannot fully leverage its advantages in the traditional LightDM environment, its flexible architectural design ensures broad applicability and good compatibility.

 

4.6 Gestures

Treeland has also made significant progress in gesture support. Here is a comparison between Treeland, X11, and the native Wayland protocol:

1、X11 Gesture Event Handling

  • Gesture events are generated by libinput and forwarded to the X Server via XInput2.
  • The X Server parses the events and, based on the configuration of the focused window, distributes them to the client application or window manager (such as KWin).
  • KWin handles global gestures through the XInput2 interface, including:
    • Registering the input manager;
    • Recognizing global gestures;
    • Blocking gesture event bubbling.
  • Since the events need to be passed multiple times between libinput, the X Server, and the window manager, this results in high latency, leading to unsmooth gesture animations and poor responsiveness.

2、Wayland Gesture Event Handling

  • Gesture events are directly passed from libinput to the Wayland compositor without the need for intermediate forwarding (such as XInput2);
  • The compositor (such as Treeland) can directly process gesture events, thereby increasing response speed and the ability to support complex gestures.

3、Treeland Optimizations

  • Use Waylib to convert libinput input events into Qt events;
  • Leverage Qt's native gesture event support to bind windows or animation components with gesture handlers, implementing smooth follow-hand animations with QtQuick.

Wayland uses a direct event processing mechanism, simplifying the path of gesture event transmission and significantly increasing response speed, effectively reducing latency. In contrast, X11's complex interaction process makes the gesture experience less satisfactory. Treeland combines Wayland and QtQuick technologies to achieve superior real-time gesture animation and follow-hand responsiveness, delivering a modern user experience.

 

V. Conclusion

In summary, as a new generation Wayland compositor, Treeland has made significant breakthroughs in many areas:

  • It has greatly enhanced visual effects and interactive experiences through state-driven animations and animation enhancements.
  • The introduction of DMA Buffer and privacy protection mechanisms has made the screenshot and recording features more secure and efficient.
  • It has innovatively adopted DDM and centralized composition to optimize the multi-user switching experience.
  • Based on Wayland and QtQuick technologies, it has implemented a smoother gesture control system.

The innovations of Treeland not only significantly improve system performance but also provide users with a more modern and secure user experience, fully demonstrating its great potential for development in the Linux desktop environment.

 

Related Readings:

(1)deepin 25 Pre Release Note

(2)Click to Support deepin Community

Leave a Reply