Windows Composition API guide, compositionapi

Source: Internet
Author: User

Windows Composition API guide, compositionapi

In Windows 10, Microsoft introduced a new set of API Composition for user interface Synthesis for Universal Windows Apps (UWA. The Composition API enables developers to use a small amount of code to implement more elegant Interface Effects in common Windows applications. This series of articles will introduce the origins, usage, and usage of this API.

This article is a personal blog backup article, the original address: http://validvoid.net/windows-composition-api-guide-introduction/

What is Composition API

To put it simply, the Composition API is a newly introduced Desktop Window Manager (DWM), a user interface synthesis API for general Windows applications. DWM is a component that combines and renders graphical user interfaces using hardware acceleration features. It was first introduced in Windows Vista. The purpose of DWM's birth is to provide higher-Performance Interface rendering and richer interface effects. It should be noted that many users may have an impression of DWM on the frosted glass effect in the Windows Aero visual style, but in fact DWM is far more powerful than that.

Desktop Window Manager

Since the introduction of DWM, the user interface that the user actually sees on the screen is actually the image produced by DWM to synthesize the buffer data from different applications. Based on DirectX, DWM uses graphics card Display memory and GPU to provide better performance than vintage GDI rendering to complete interface graphics and rendering. DWM maps the rendering method of old-fashioned GDI methods. In the DWM rendering process, the desktop is actually a full screen Direct3D surface, while the window in the desktop is a grid composed of two triangles and transformed into a 2D rectangle. The UI frame maps the texture to these rectangles. Window transition and other effects are achieved through shader processing, transformation, and other processes.

In DWM processing, each application has its own buffer zone. The application writes its own interface graphic data to its own buffer zone, and DWM reads the data in the buffer zone of each application for synthesis. DWM uses the unmanaged Media Integration Layer (MIL) to describe the window as the composition nodes in the composition tree for rendering. The compositing tree represents the desktop and the windows it contains. MIL renders the content of the entire user interface in the order from the back to the front of the compositing tree. With the MIL-based Retained Mode 1, applications are freed from refresh and re-painting. The features provided since Windows Vista, such as fuzzy, Flip 3D, and real-time thumbnails, are implemented based on real-time buffer, shader, and other features. In short, DWM is a new generation of high-performance Interface Engine driven by DirectX.

DirectComposition

In Windows 8, Microsoft introduced the DirectComposition API. The DirectComposition Component enables developers to perform high-performance bitmap synthesis and add transformations, special effects, and animations to create a more complex, vivid, and smooth user interface. DirectComposition uses the acceleration feature of graphics hardware for rendering unrelated to the UI thread. It supports 2D affine transformation, 3D perspective transformation, and other transformations, as well as basic effects such as cutting and opacity. As its name suggests, the design of DirectComposition is inspired by DirectX, but it provides a more friendly way for developers to use. It also gives developers a clearer understanding of the effects of DWM, a powerful synthesis engine.

However, DirectComposition is a set of Apis built for the Component Object Model (COM) and is not suitable for developers who usually use hosted languages for application development. In fact, the DirectComposition MSDN document clearly states:

The DirectComposition API is intended for experienced and highly-capable graphics developers who know C/C++, have a solid understanding of the Component Object Model (COM), and are familiar with Windows programming concepts.

That is, DirectComposition API is suitable for graphic processing developers familiar with C/C ++ and COM.

Windows Composition API

Now, with the advent of Windows 10, developers have a new option: Composition API. The Composition API is built based on Windows Runtime (Windows Runtime, WinRT). It integrates the Immediate Mode 2 graphics capabilities of Direct2D and Direct3D, and provides a visual tree mechanism in the Retained Mode, it provides a rich array of effects and supports high-performance animated interface synthesis rendering. The Composition API is applicable to common Windows applications and is provided through the Windows. UI. Composition namespace. This means that developers can use any Universal Windows Platform (UWP) language (C #, JavaScript, C ++/CX or Modern C ++) it is used in UWA applications and runs on almost all UWP platform devices (PCs, tablets, and mobile phones.

Windows.UI.CompositionAPIs in declarative and retained modes. It can not only be used in combination with the widely used XAML, but also be used independently from the XAML. This means that developers can now use their most familiar languages in a more flexible way and integrate the various features of XAML and DirectX to create a modern UI. Demonstrate the hierarchies used by generic Windows applications for rendering using XAML, Composition API, and DirectX:

With the help of the Composition API, developers can go from the framework layer to the visual layer for more complex graphic effects in XAML-based applications at any time.

Why use Composition API
  • High Performance Based on hardware acceleration
  • More powerful special effects and animation support
  • Built based on WinRT for all common Windows Applications
  • Ensure consistent experience on general Windows Platforms
  • Avoid using C/C ++ to operate DirectX
  • Provides an API for the retention mode to conveniently control the rendering process by manipulating the visual tree.
  • Seamless integration with XAML (almost)
Composition API features Overview

In addition to a visual tree mechanism, the Composition API also provides the following features, which will be described in detail in the following sections:

  • Special effects

    The Composition API supports real-time effects, which can be animated, custom, and linked. The effects include 2D affine transforms, arithmetic composites, blends, color source, and composite) contrast, exposure, grayscale, gamma transfer, hue rotate, and invert) saturate, sepia, temperature, and tint ).

  • Animation

    The Composition API contains a set of expressionized animation systems with unknown frames. The system supports two types of animations: Key Frame Animation and Expression Animation. Animations can be used to move visual elements, and transform, cut, or special effects can be animated. The animation system runs directly in the synthesizer process to ensure the smoothness and scalability of the animation, making it possible to make a large number of concurrent animations.

  • Interoperability with XAML

  • Interoperability with the native Layer

Object Model

 

, CompositionObject is the core base class of Composition API. It implementsICompositionObjectInterface, indicating a node in the visual tree.

ByCompositionObjectClass is derived from the following main types:

  • Visual: represents the basic object in the Visual tree. Most of the attributes to be operated are defined here. This class derives the container visual element type ContainerVisual,ContainerVisualDerives SpriteVisual. Later.
  • CompositionTarget: The target window drawn by the visual tree.
  • CompositionBrush: Specifies the painter base class.
  • CompositionAnimation: the animation base class that derives the KeyFrameAnimation and Expression Animation ). Later.

Windows.UI.CompositionContains an implementationICompositorThe interface synthesizer class Compositor, which acts as the factory role for creating synthetic objects and is responsible for creating almost all operation objects for visual tree trees. The MSDN document describes it as "Managing sessions between an application and a system synthesizer."

Link
  • Composition API Github Repository
  • API Documentation Reference (currently only English version is available, but this Guide series will basically cover all content in the API documentation)
  • Known issues
  • Windows Composition project team Twitter: @ WinComposition
Note Terms and translations

Some terms, such as "Sprite", are translated as Genie. I think it is better to retain the original text without translation, which may cause misunderstanding after translation, therefore, the concepts and terms involved in this series are translated or not translated as appropriate based on the context. Generally, a class name or original interface name is used for a type or interface. Otherwise, it is translated into generic Chinese as needed, for example, "Visual" indicates a type.VisualGenerally, narration is translated as a visual element.

References

Related Article

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.