Direct2D is a
2D vector graphics
application programming interface
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software Interface (computing), interface, offering a service to other pieces of software. A document or standard that des ...
(API) designed by
Microsoft
Microsoft Corporation is an American multinational corporation and technology company, technology conglomerate headquartered in Redmond, Washington. Founded in 1975, the company became influential in the History of personal computers#The ear ...
and implemented in
Windows 10
Windows 10 is a major release of Microsoft's Windows NT operating system. The successor to Windows 8.1, it was Software release cycle#Release to manufacturing (RTM), released to manufacturing on July 15, 2015, and later to retail on July 2 ...
,
Windows 8
Windows 8 is a major release of the Windows NT operating system developed by Microsoft. It was Software release life cycle#Release to manufacturing (RTM), released to manufacturing on August 1, 2012, made available for download via Microsoft ...
,
Windows 7
Windows 7 is a major release of the Windows NT operating system developed by Microsoft. It was Software release life cycle#Release to manufacturing (RTM), released to manufacturing on July 22, 2009, and became generally available on October 22, ...
and
Windows Server 2008 R2, and also
Windows Vista
Windows Vista is a major release of the Windows NT operating system developed by Microsoft. It was the direct successor to Windows XP, released five years earlier, which was then the longest time span between successive releases of Microsoft W ...
and
Windows Server 2008 (with
Platform Update installed).
Direct2D takes advantage of hardware acceleration via the graphics processing unit (
GPU) found in compatible
graphics cards within personal computer, tablet, smartphone and modern graphical device. It offers high visual quality and fast rendering performance while maintaining full interoperability with classic Win32
graphics APIs such as
GDI/GDI+ and modern graphics APIs such as
Direct3D.
Overview
Direct2D is a
native code
In computer programming, machine code is computer program, computer code consisting of machine language instruction set architecture, instructions, which are used to control a computer's central processing unit (CPU). For conventional binary ...
API based on
C++ that can be called by
managed code and uses a "lightweight
COM" approach just like
Direct3D, with minimal amount of abstraction. However, unlike
WPF and similarly to GDI/GDI+, Direct2D is an "immediate mode" rendering API with simple BeginDraw/Draw/EndDraw calls; Direct2D has no concept of a "scene" and does not use retained tree structures, and the rendering state is preserved between drawing calls.
Direct2D can minimize CPU usage and utilize hardware rendering on a graphics card with minimum support of Direct3D Feature Level 9 with
WDDM 1.1 drivers. Applications can choose to use it exclusively with CPU, the so-called software rendering by using it in conjunction with
WARP10 in situations when hardware capability is not available, such as when running within a device with minimal GPU support, under
terminal service, Windows
session 0, or when graphics rendering is performed in a remote server with the graphical result sent back to the client device. Direct2D performance and memory usage scale linearly with primitive counts in both software and hardware.
Direct2D supports high-quality rendering with the following key features:
* High-quality subpixel text rendering via
DirectWrite for both grayscale and
ClearType technique
* Per-primitive
antialiasing
*
Bézier geometry draw and fill
* Rich geometry operations (e.g.
Boolean operations, path widening, outlining, etc.)
* Composite layers
* Primitive blend modes (e.g. source-over, source-copy, min blends, etc.)
* Image built-in and custom effects for photo adjustment, graphical and color transform
*
Gradient
In vector calculus, the gradient of a scalar-valued differentiable function f of several variables is the vector field (or vector-valued function) \nabla f whose value at a point p gives the direction and the rate of fastest increase. The g ...
brush and mesh
* Command list for command buffering and printing
* Scalable ink stroke
*
Sprite batch for game development
Direct2D allows full interoperability with GDI, GDI+, and permits rendering to and from a Direct3D surface, as well as to and from a GDI/GDI+ device context (HDC). It can be used effectively together with
Windows Imaging Component (WIC) for image encoding/decoding, and with DirectWrite for text formatting and font processing. Such interoperability allows developers to gradually replace critical code paths with Direct2D code without the need to overhaul their entire source code. In Windows 10 timeframe, an Open Source project called Win2D was developed by Microsoft to further simplify the usage of Direct2D and DirectWrite in
Universal Windows Platform (UWP) application. Win2D is a highly-efficient
WinRT wrapper of Direct2D and DirectWrite designed from the ground up to integrate seamlessly with XAML Canvas control while preserving the power of the underlying graphics subsystem.
Subsequent versions
Direct2D 1.1
An updated version of Direct2D was launched with
Windows 8
Windows 8 is a major release of the Windows NT operating system developed by Microsoft. It was Software release life cycle#Release to manufacturing (RTM), released to manufacturing on August 1, 2012, made available for download via Microsoft ...
in October 2012. It was also
backported to Windows 7 SP1 (but not to Windows Vista) via the
Windows 7 platform update.
The original version of Direct2D was tied to
DirectX
Microsoft DirectX is a collection of application programming interfaces (APIs) for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with "Direct" ...
11 (in hardware, up to
Direct3D 10.1 is used), whereas this version of Direct2D integrates with DirectX 11.1.
Windows 8 also added interoperability between
XAML and Direct2D along with Direct3D components, which can be all mixed in an application.
Direct2D 1.2
New features were added to Direct2D with
Windows 8.1 in October 2013:
Geometry realizations,
Direct2D effects API, command list API, multithreading APIs, per-device rendering priority, support for JPEG YCbCr images for smaller
memory footprint
Memory footprint refers to the amount of main memory that a program uses or references while running.
The word footprint generally refers to the extent of physical dimensions that an object occupies, giving a sense of its size. In computing, t ...
, and support for block compressed formats (DDS files).
Direct2D 1.3
The release of
Windows 10
Windows 10 is a major release of Microsoft's Windows NT operating system. The successor to Windows 8.1, it was Software release cycle#Release to manufacturing (RTM), released to manufacturing on July 15, 2015, and later to retail on July 2 ...
in July 2015 brought important updates and new features to Direct2D such as the performance improvement of rendering scalable text without
font rasterization, the ability to download the needed font from the cloud on demand without requiring the font installation step, an optimization for faster image loading and image effect rendering, and a more sophisticated way to apply
gradient brush through the use of 2D mesh made of gradient patches. This release also introduced a brand-new API extension to support digital ink, which is highly leveraged by the
Microsoft Edge browser as well as the ink canvas
XAML control.
Implementation
In their 2012 paper on the competing NV path rendering OpenGL extension,
Mark Kilgard and Jeff Bolz explain (and criticize) the internals of Direct2D as follows: "Direct2D operates by transforming paths on the CPU and then performing a constrained trapezoidal
tessellation of each path. The result is a set of pixel-space
trapezoid
In geometry, a trapezoid () in North American English, or trapezium () in British English, is a quadrilateral that has at least one pair of parallel sides.
The parallel sides are called the ''bases'' of the trapezoid. The other two sides are ...
s and additional shaded geometry to compute fractional coverage for the left and right edges of the trapezoids. These trapezoids and shaded geometry are then rasterized by the GPU. The resulting performance is generally better than entirely CPU-based approaches and requires no ancillary storage for multisample or
stencil state; Direct2D renders directly into an aliased framebuffer with properly antialiased results. Direct2D’s primary disadvantage is
hat
A hat is a Headgear, head covering which is worn for various reasons, including protection against weather conditions, ceremonial reasons such as university graduation, religious reasons, safety, or as a fashion accessory. Hats which incorpor ...
the ultimate performance is determined not by the GPU (doing fairly trivial rasterization) but rather by the CPU performing the transformation and trapezoidal tessellation of each path and Direct3D validation work."
In July 2012, the
Windows 8
Windows 8 is a major release of the Windows NT operating system developed by Microsoft. It was Software release life cycle#Release to manufacturing (RTM), released to manufacturing on August 1, 2012, made available for download via Microsoft ...
team posted the following on the blog of
Steven Sinofsky: "To improve geometry rendering performance in Windows 8, we focused on reducing the CPU cost associated with tessellation in two ways. First, we optimized our implementation of tessellation when rendering simple geometries like rectangles, lines, rounded rectangles, and ellipses."
These common-case optimizations claimed to improve performance in the range of 184% to 438%, depending on the primitive. The post continued: "Second, to improve performance when rendering irregular geometry (e.g. geographical borders on a map), we use a new graphics hardware feature called ''
Target Independent Rasterization'', or TIR. TIR enables Direct2D to spend fewer CPU cycles on tessellation, so it can give drawing instructions to the GPU more quickly and efficiently, without sacrificing visual quality. TIR is available in new GPU hardware designed for Windows 8 that supports DirectX 11.1."
[Rob Copeland, with contributions from Sriram Subramanian, Dan McLachlan, Kam VedBrat, Steve Lim, and Jianye Lu, and introduction by Steven Sinofsk]
Hardware accelerating everything: Windows 8 graphics
/ref> This was followed by a benchmark using some 15 SVGs, claiming performance improvements in the range of 151% to 523%. The section concluded: "We worked closely with our graphics hardware partners to design TIR. Dramatic improvements were made possible because of that partnership. DirectX 11.1 hardware is already on the market today and we’re working with our partners to make sure more TIR-capable products will be broadly available."
The TIR feature was among those that caused a "war of words" between Nvidia
Nvidia Corporation ( ) is an American multinational corporation and technology company headquartered in Santa Clara, California, and incorporated in Delaware. Founded in 1993 by Jensen Huang (president and CEO), Chris Malachowsky, and Curti ...
and AMD around December 2012, because Nvidia's Kepler GPU family does not support it, whereas AMD's GCN does. In response to customer demands, an Nvidia support staffer posted that TIR cannot be simply implemented at the driver level, but requires new hardware; the Maxwell 2 architecture, introduced in September 2014, is such hardware.
In Windows 8.1, Direct2D can use the Direct3D11 hardware tesselators, but only in conjunction with D2D1_FILL_MODE_ALTERNATE
. If another fill mode is used (e.g. D2D1_FILL_MODE_WINDING
) then Direct2D falls back to tessellation on the CPU, but still uses TIR for anti-aliasing (if TIR is available). Since hardware tessellation is available in base Direct3D11 (not necessarily 11.1), Microsoft claimed significant performance improvements with Direct2D in Windows 8.1 (vs. Windows 8) on non-TIR hardware.
Uses and performance
Internet Explorer 9 and later versions use Direct2D and DirectWrite for improved performance and visual quality. Direct2D support was added in the alpha version of Firefox
Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. It uses the Gecko rendering engine to display web pages, which implements curr ...
3.7, roughly doubling its rendering speed. (Firefox 4 also added DirectWrite support, but this was made non-default for some fonts in Firefox 7 due to user complaints about the rendering quality. Google Chrome
Google Chrome is a web browser developed by Google. It was first released in 2008 for Microsoft Windows, built with free software components from Apple WebKit and Mozilla Firefox. Versions were later released for Linux, macOS, iOS, iPadOS, an ...
uses its own 2D library called Skia, which in turn renders through ANGLE
In Euclidean geometry, an angle can refer to a number of concepts relating to the intersection of two straight Line (geometry), lines at a Point (geometry), point. Formally, an angle is a figure lying in a Euclidean plane, plane formed by two R ...
on Windows.) In Firefox
Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. It uses the Gecko rendering engine to display web pages, which implements curr ...
70.0, on old hardware, Direct2D is disabled on blacklisted old graphics drivers if they lack features and area is blacked out e.g. in Google Maps
Google Maps is a web mapping platform and consumer application offered by Google. It offers satellite imagery, aerial photography, street maps, 360° interactive panorama, interactive panoramic views of streets (Google Street View, Street View ...
.
Ars Technica
''Ars Technica'' is a website covering news and opinions in technology, science, politics, and society, created by Ken Fisher and Jon Stokes in 1998. It publishes news, reviews, and guides on issues such as computer hardware and software, sci ...
's Peter Bright noted in the summer of 2012 that "most desktop applications don't use Direct2D."
Microsoft Office 2013 supports either Direct2D+DirectWrite or GDI+ Uniscribe for display rendering and typography.
See also
* DirectX
Microsoft DirectX is a collection of application programming interfaces (APIs) for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with "Direct" ...
* Direct3D
* Cairo
Cairo ( ; , ) is the Capital city, capital and largest city of Egypt and the Cairo Governorate, being home to more than 10 million people. It is also part of the List of urban agglomerations in Africa, largest urban agglomeration in Africa, L ...
– a cross platform vector graphics library
* OpenVG
* Simple and Fast Multimedia Library
* Starling Framework
* Quartz 2D
References
External links
Main Direct2D page at MSDN
with links t
the programming guide
new features in Windows 8.1
interoperability with Direct3D
etc.
Blog of Direct2D Lead Developer Thomas Olsen
Blog of Direct2D Developer Tom Mulcahy
Windows 7: Introducing Direct2D and DirectWrite
- PDC 2008 video
Windows API Code Pack for Microsoft .NET Framework
- allows developing Direct2D apps in managed code
Introducing Direct2D
- June 2009 issue of MSDN Magazine
Drawing with Direct2D
- September 2009 issue of MSDN Magazine
Direct2D API for Microsoft .Net Framework 4
- Direct2D API for Microsoft .Net Framework 4
USPTO application for target independent rasterization
Direct2D 1.1 Migration Guide for Windows 7 Developers
* Charles Petzold'
column on DirectX
has several articles on Direct2D ranging from introductory ones lik
Triangles and Tessellation
o
Direct2D Geometries and Their Manipulations
to more advanced ones lik
Finger Painting with Direct2D Geometries
A 2D Portal into a 3D World
etc.
{{Microsoft APIs
2d Direct2D
Graphics libraries