Direct2D[1] is a2Dvector graphicsapplication programming interface (API) designed byMicrosoft and implemented inWindows 10,[2]Windows 8,Windows 7 andWindows Server 2008 R2, and alsoWindows Vista andWindows Server 2008 (withPlatform Update installed).[3]
Direct2D takes advantage of hardware acceleration via the graphics processing unit (GPU) found in compatiblegraphics 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 Win32graphics APIs such asGDI/GDI+ and modern graphics APIs such asDirect3D.[4]
Direct2D is anative code API based onC++ that can be called bymanaged code and uses a "lightweightCOM" approach[5] just likeDirect3D, with minimal amount of abstraction. However, unlikeWPF 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 withWDDM 1.1 drivers. Applications can choose to use it exclusively with CPU, the so-called software rendering by using it in conjunction withWARP10 in situations when hardware capability is not available, such as when running within a device with minimal GPU support, underterminal service, Windowssession 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[6][7] supports high-quality rendering with the following key features:
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 withWindows 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 inUniversal Windows Platform (UWP) application. Win2D is a highly-efficientWinRT 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.
An updated version of Direct2D was launched withWindows 8 in October 2012.[8] It was alsobackported to Windows 7 SP1 (but not to Windows Vista) via theWindows 7 platform update.[9][10][11] The original version of Direct2D was tied toDirectX 11 (in hardware, up toDirect3D 10.1 is used), whereas this version of Direct2D integrates with DirectX 11.1.[9] Windows 8 also added interoperability betweenXAML and Direct2D along with Direct3D components, which can be all mixed in an application.[12]
New features were added to Direct2D withWindows 8.1 in October 2013:[13]Geometry realizations,[14] Direct2D effects API,[15][16][17] command list API, multithreading APIs, per-device rendering priority, support for JPEG YCbCr images for smallermemory footprint, and support for block compressed formats (DDS files).
The release ofWindows 10 in July 2015 brought important updates and new features to Direct2D such as the performance improvement of rendering scalable text withoutfont 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 applygradient 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 theMicrosoft Edge browser as well as the ink canvasXAML control.
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 trapezoidaltessellation of each path. The result is a set of pixel-spacetrapezoids 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 orstencil state; Direct2D renders directly into an aliased framebuffer with properly antialiased results. Direct2D’s primary disadvantage is [that] 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."[18]
In July 2012, theWindows 8 team posted the following on the blog ofSteven 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."[19] 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 calledTarget 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."[19] This was followed by a benchmark using some 15SVGs, 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."[19]
The TIR feature was among those that caused a "war of words" betweenNvidia andAMD around December 2012, because Nvidia'sKepler GPU family does not support it, whereas AMD'sGCN does.[20] In response to customer demands, an Nvidia support staffer posted that TIR cannot be simply implemented at the driver level, but requires new hardware;[21][22] theMaxwell 2 architecture, introduced in September 2014, is such hardware.[23]
InWindows 8.1, Direct2D can use the Direct3D11 hardware tesselators, but only in conjunction withD2D1_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.[24]
Internet Explorer 9 and later versions use Direct2D andDirectWrite for improved performance and visual quality.[25][26][27] Direct2D support was added in thealpha version ofFirefox 3.7, roughly doubling its rendering speed.[28] (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.[29]Google Chrome uses its own 2D library calledSkia, which in turn renders throughANGLE on Windows.[30]) InFirefox 70.0, on old hardware, Direct2D is disabled on blacklisted old graphics drivers if they lack features and area is blacked out e.g. inGoogle Maps.[31]
Ars Technica's Peter Bright noted in the summer of 2012 that "most desktop applications don't use Direct2D."[32]
Microsoft Office 2013 supports either Direct2D+DirectWrite or GDI+Uniscribe for display rendering and typography.[33]
{{cite web}}
:|author=
has generic name (help)CS1 maint: multiple names: authors list (link) CS1 maint: numeric names: authors list (link){{cite web}}
: CS1 maint: numeric names: authors list (link)