Graphics Device Interface

Last updated
The Graphics Device Interface in the architecture of Windows NT Windows 2000 architecture.svg
The Graphics Device Interface in the architecture of Windows NT
For example GDK makes use of GDI. GDK software architecture.svg
For example GDK makes use of GDI.

The Graphics Device Interface (GDI) is a legacy component of Microsoft Windows responsible for representing graphical objects and transmitting them to output devices such as monitors and printers. It was superseded by DirectDraw API and later Direct2D API.[ citation needed ] Windows apps use Windows API to interact with GDI, for such tasks as drawing lines and curves, rendering fonts, and handling palettes. The Windows USER subsystem uses GDI to render such UI elements as window frames and menus. Other systems have components that are similar to GDI; for example: Mac OS has QuickDraw, and Linux and Unix have X Window System core protocol.

Contents

GDI's most significant advantages over more direct methods of accessing the hardware are perhaps its scaling capabilities and its abstract representation of target devices. Using GDI, it is possible to draw on multiple devices, such as a screen and a printer, and expect proper reproduction in each case. This capability is at the center of most "What You See Is What You Get" applications for Microsoft Windows.

Simple games that do not require fast graphics rendering may use GDI. However, GDI is relatively hard to use for advanced animation, lacks a notion for synchronizing with individual video frames in the video card, and lacks hardware rasterization for 3D. Modern games usually use DirectX, Vulkan, or OpenGL instead.

Technical details

In GDI, a device context (DC) defines the attributes of text and images for the output device, e.g., screen or printer. GDI maintains the actual context. Generating the output requires a handle to the device context (HDC). After generating the output, the handle could be released.

GDI uses Bresenham's line drawing algorithm to draw aliased lines. [1]

Version history

Early versions

GDI was present in the initial release of Windows. MS-DOS programs had manipulated the graphics hardware using software interrupts (sometimes via the Video BIOS) and by manipulating video memory directly. Code written in this way expects that it is the only user of the video memory, which was not tenable on multi-tasked environment, such as Windows. The BYTE magazine, in December 1983, discussed Microsoft's plans for a system to output graphics to both printers and monitors with the same code in the forthcoming first release of Windows. [2]

On Windows 3.1x and Windows 9x, GDI can use Bit blit features for 2D acceleration, if suitable graphics card driver is installed. [3]

Windows XP

With the introduction of Windows XP, GDI+ complemented GDI. GDI+ has been written in C++. It adds anti-aliased 2D graphics, floating point coordinates, gradient shading, more complex path management, intrinsic support for modern graphics-file formats like JPEG and PNG, and support for composition of affine transformations in the 2D view pipeline. GDI+ uses RGBA values to represent color. Use of these features is apparent in Windows XP components, such as Microsoft Paint, Windows Picture and Fax Viewer, Photo Printing Wizard, and the My Pictures Slideshow screensaver. Their presence in the basic graphics layer greatly simplifies implementations of vector-graphics systems such as Adobe Flash or SVG. Besides, .NET Framework provides a managed interface for GDI+ via the System.Drawing namespace.

While GDI+ is included with Windows XP and later, the GDI+ dynamic library can also be shipped with an application and used on older versions of Windows. [4]

Because of the additional text processing and resolution independence capabilities in GDI+, the CPU undertakes text rendering. [5] The result is an order of magnitude slower than the hardware-accelerated GDI. [6] Chris Jackson published some tests indicating that a piece of text rendering code he had written could render 99,000 glyphs per second in GDI, but the same code using GDI+ rendered 16,600 glyphs per second.

GDI+ is similar (in purpose and structure) to Apple 's QuickDraw GX subsystem, and the open-source libart and Cairo libraries.

Windows Vista

In Windows Vista, all Windows applications including GDI and GDI+ applications run in the new compositing engine, Desktop Window Manager (DWM), which is hardware-accelerated. As such, the GDI itself is no longer hardware-accelerated. [7] [8] [9] Because of the nature of the composition operations, window moves can be faster or more responsive because underlying content does not need to be re-rendered by the application. [8]

Windows 7

Windows 7 includes GDI hardware acceleration for blitting operations in the Windows Display Driver Model v1.1. This improves GDI performance and allows DWM to use local video memory for compositing, thereby reducing system memory footprint and increasing the performance of graphics operations. Most primitive GDI operations are still not hardware-accelerated, unlike Direct2D. GDI+ continues to rely on software rendering in Windows 7. [10]

GDI printers

A GDI printer or Winprinter (analogous to a Winmodem) is a printer designed to accept output from a host computer running Windows. The host computer does all print processing: GDI renders a page as a bitmap, which the printer driver receives, processes, and sends to the associated printer. [11] [12] The combination of GDI and the driver is bidirectional; they receive information from the printer such as whether it is ready to print or is out of paper.

Printers that do not rely on GDI require hardware, firmware, and memory for page rendering while a GDI printer uses the host computer for this. However, a printer with its own control language can accept input from any device with a suitable driver, while a GDI printer requires a PC running Windows. GDI printers can be made available to computers on a network if they are connected as shared printers on a computer which is on and running Windows. Some "generic" GDI drivers such as pnm2ppa have been written; they aim to make GDI printers compatible with non-Windows operating systems such as FreeBSD, but they cannot support all printers. [11]

In order to allow simpler creation of drivers for Winprinters, the Microsoft Universal Printer Driver was created. This allows printer vendors to write Generic Printer Description (GPD) "minidrivers", which describe the printer's capabilities and command set in plaintext, rather than having to do kernel mode driver development.

Microsoft has moved away from this printing model with Open XML Paper Specification.

Limitations

Each window consumes GDI objects. As the complexity of the window increases, with additional features such as buttons and images, its GDI object usage also increases. When too many objects are in use, Windows is unable to draw any more GDI objects, leading to misbehaving software and frozen and unresponsive program operation. [13] Many applications are also incorrectly coded and fail to release GDI objects after use, which further adds to the problem. [14] The total available GDI objects varies from one version of Windows to the next: Windows 9x had a limit of 1,200 total objects; Windows 2000 has a limit of 16,384 objects; and Windows XP and later have a configurable limit (via the registry) that defaults to 10,000 objects per process (but a theoretical maximum of 65,536 for the entire session). [15] [16] Windows 8 and later increase the GDI object limit to 65,536 per user login session.

Earlier versions of Windows such as Windows 3.1 and Windows 98 included a Resource Meter program to allow the user to monitor how much of the total system GDI resources were in use. This resource meter consumed GDI objects itself. Later versions such as Windows 2000 and Windows XP can report GDI object usage for each program in the Task Manager, but they cannot tell the user the total GDI capacity available.

Overflowing GDI capacity can affect Windows itself, preventing new windows from opening, menus from displaying, and alert boxes from appearing. The situation can be difficult to clear and can potentially require a forced reset of the system, since it prevents core system programs from functioning. In Windows 8 and 8.1, a forced log-off occurs as a result of GDI capacity overflow, instead of a reboot.

Successor

Direct2D is the successor of GDI and GDI+. Its sibling, DirectWrite, replaces Uniscribe. They were shipped with Windows 7 and Windows Server 2008 R2, and were available for Windows Vista and Windows Server 2008 (with Platform Update installed). Later, Microsoft developed Win2D, a free and open-source GDI-like class library. Win2D's target audience are developers that use C++, C#, and Visual Basic.NET to develop Universal Windows Platform apps. [17]

See also

Notes and references

  1. Steven, White; David, Coulter; Mike, Jacobs (31 May 2018). "Comparing Direct2D and GDI Hardware Acceleration". Windows Developer. Microsoft.
  2. Butler, John (December 1983). "Device-Independent Graphics Output for Microsoft Windows". BYTE. p. 49. Retrieved 20 October 2013.
  3. https://www.dosdays.co.uk/media/cirrus_logic/CL-GD543X_Applications_and_Eratta_Book_Apr94.pdf.{{cite web}}: Missing or empty |title= (help)
  4. Platform SDK Redistributable: GDI+
  5. "2D Drawing APIs in Windows -". DirectX Developer Blog. MSDN Blogs. May 12, 2009. Retrieved July 19, 2012.
  6. Jackson, Chris. "GDI vs. GDI+ Text Rendering Performance". Chris Jackson's Semantic Consonance. Microsoft.
  7. MSDN: Comparing Direct2D and GDI Hardware Acceleration
  8. 1 2 GDI is not hardware accelerated in Windows Vista
  9. Layered windows...SW is sometimes faster than HW. Avalite on MSDN Blogs.
  10. Thomas Olsen (October 29, 2008). "Introducing the Microsoft Direct2D API".
  11. 1 2 "Generic GDI Printer". Open Printing. The Linux Foundation. Retrieved 21 July 2021.
  12. "Windows-only printers". Linux Documentation Project . Retrieved October 29, 2019.
  13. Microsoft Knowledgebase article 838283 - Desktop application menus are improperly displayed if a process exceeds its GDI object quota in Windows XP or in Windows 2000 http://support.microsoft.com/kb/838283
  14. Microsoft Developer Network Blog - GDI leak in Outlook 2007 causes problems when GDI usage reaches 10,000 objects http://blogs.msdn.com/rgregg/archive/2007/09/03/outlook-2007-gdi-leak-hotfix.aspx
  15. Microsoft Developer Network - GDI Object limits http://msdn.microsoft.com/en-us/library/ms724291(VS.85).aspx
  16. Microsoft Knowledge base Article 894500 - .NET programs designed on newer NT operating systems may malfunction on older Win 95 / Win 98 / Win ME due to lower GDI usage limits http://support.microsoft.com/kb/894500
  17. "Win2D". microsoft/Win2D repo. Microsoft. Retrieved 21 July 2021 via GitHub.com.

Related Research Articles

<span class="mw-page-title-main">ClearType</span> Font-rendering technology by Microsoft

ClearType is Microsoft's implementation of subpixel rendering technology in rendering text in a font system. ClearType attempts to improve the appearance of text on certain types of computer display screens by sacrificing color fidelity for additional intensity variation. This trade-off is asserted to work well on LCD flat panel monitors.

<span class="mw-page-title-main">DirectX</span> Collection of multimedia related APIs on Microsoft platforms

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", such as Direct3D, DirectDraw, DirectMusic, DirectPlay, DirectSound, and so forth. The name DirectX was coined as a shorthand term for all of these APIs and soon became the name of the collection. When Microsoft later set out to develop a gaming console, the X was used as the basis of the name Xbox to indicate that the console was based on DirectX technology. The X initial has been carried forward in the naming of APIs designed for the Xbox such as XInput and the Cross-platform Audio Creation Tool (XACT), while the DirectX pattern has been continued for Windows APIs such as Direct2D and DirectWrite.

DirectDraw (ddraw.dll) is an API that used to be a part of Microsoft's DirectX API. DirectDraw is used to accelerate rendering of 2D graphics in applications. DirectDraw also allows applications to run fullscreen or embedded in a window such as most other MS Windows applications. DirectDraw uses hardware acceleration if it is available on the client's computer. DirectDraw allows direct access to video memory, hardware overlays, hardware blitters, and page flipping. Its video memory manager can manipulate video memory with ease, taking full advantage of the blitting and color decompression capabilities of different types of display adapters.

Direct3D is a graphics application programming interface (API) for Microsoft Windows. Part of DirectX, Direct3D is used to render three-dimensional graphics in applications where performance is important, such as games. Direct3D uses hardware acceleration if available on the graphics card, allowing for hardware acceleration of the entire 3D rendering pipeline or even only partial acceleration. Direct3D exposes the advanced graphics capabilities of 3D graphics hardware, including Z-buffering, W-buffering, stencil buffering, spatial anti-aliasing, alpha blending, color blending, mipmapping, texture blending, clipping, culling, atmospheric effects, perspective-correct texture mapping, programmable HLSL shaders and effects. Integration with other DirectX technologies enables Direct3D to deliver such features as video mapping, hardware 3D rendering in 2D overlay planes, and even sprites, providing the use of 2D and 3D graphics in interactive media ties.

Quartz 2D is the native two-dimensional graphics rendering API for macOS and iOS platforms, part of the Core Graphics framework.

GLX is an extension to the X Window System core protocol providing an interface between OpenGL and the X Window System as well as extensions to OpenGL itself. It enables programs wishing to use OpenGL to do so within a window provided by the X Window System. GLX distinguishes two "states": indirect state and direct state.

DirectSound is a deprecated software component of the Microsoft DirectX library for the Windows operating system, superseded by XAudio2. It provides a low-latency interface to sound card drivers written for Windows 95 through Windows XP and can handle the mixing and recording of multiple audio streams. DirectSound was originally written for Microsoft by John Miles.

<span class="mw-page-title-main">DirectShow</span> Microsoft API

DirectShow, codename Quartz, is a multimedia framework and API produced by Microsoft for software developers to perform various operations with media files or streams. It is the replacement for Microsoft's earlier Video for Windows technology. Based on the Microsoft Windows Component Object Model (COM) framework, DirectShow provides a common interface for media across various programming languages, and is an extensible, filter-based framework that can render or record media files on demand at the request of the user or developer. The DirectShow development tools and documentation were originally distributed as part of the DirectX SDK. Currently, they are distributed as part of the Windows SDK.

The X video extension, often abbreviated as XVideo or Xv, is a video output mechanism for the X Window System. The protocol was designed by David Carver; the specification for version 2 of the protocol was written in July 1991. It is mainly used today to resize video content in the video controller hardware in order to enlarge a given video or to watch it in full screen mode. Without XVideo, X would have to do this scaling on the main CPU. That requires a considerable amount of processing power, which could slow down or degrade the video stream; video controllers are specifically designed for this kind of computation, so can do it much more cheaply. Similarly, the X video extension can have the video controller perform color space conversions, and change the contrast, brightness, and hue of a displayed video stream.

cairo (graphics) Vector graphics-based software library

Cairo is an open-source graphics library that provides a vector graphics-based, device-independent API for software developers. It provides primitives for two-dimensional drawing across a number of different backends. Cairo uses hardware acceleration when available.

<span class="mw-page-title-main">Architecture of Windows NT</span> Structure of the operating system

The architecture of Windows NT, a line of operating systems produced and sold by Microsoft, is a layered design that consists of two main components, user mode and kernel mode. It is a preemptive, reentrant multitasking operating system, which has been designed to work with uniprocessor and symmetrical multiprocessor (SMP)-based computers. To process input/output (I/O) requests, it uses packet-driven I/O, which utilizes I/O request packets (IRPs) and asynchronous I/O. Starting with Windows XP, Microsoft began making 64-bit versions of Windows available; before this, there were only 32-bit versions of these operating systems.

DirectX Video Acceleration (DXVA) is a Microsoft API specification for the Microsoft Windows and Xbox 360 platforms that allows video decoding to be hardware-accelerated. The pipeline allows certain CPU-intensive operations such as iDCT, motion compensation and deinterlacing to be offloaded to the GPU. DXVA 2.0 allows more operations, including video capturing and processing operations, to be hardware-accelerated as well.

Desktop Window Manager is the compositing window manager in Microsoft Windows since Windows Vista that enables the use of hardware acceleration to render the graphical user interface of Windows.

Resolution independence is where elements on a computer screen are rendered at sizes independent from the pixel grid, resulting in a graphical user interface that is displayed at a consistent physical size, regardless of the resolution of the screen.

Windows Display Driver Model is the graphic driver architecture for video card drivers running Microsoft Windows versions beginning with Windows Vista.

The Microsoft Windows operating system supports a form of shared libraries known as "dynamic-link libraries", which are code libraries that can be used by multiple processes while only one copy is loaded into memory. This article provides an overview of the core libraries that are included with every modern Windows installation, on top of which most Windows applications are built.

This article describes audio APIs and components in Microsoft Windows which are now obsolete or deprecated.

Windows Vista has many significant new features compared with previous Microsoft Windows versions, covering most aspects of the operating system.

Direct2D is a 2D vector graphics application programming interface (API) designed by Microsoft and implemented in Windows 10, Windows 8, Windows 7 and Windows Server 2008 R2, and also Windows Vista and Windows Server 2008.

DirectWrite is a text layout and glyph rendering API by Microsoft. It was designed to replace GDI/GDI+ and Uniscribe for screen-oriented rendering and was first shipped with Windows 7 and Windows Server 2008 R2, as well as Windows Vista and Windows Server 2008. DirectWrite is hardware-accelerated when running on top of Direct2D, but can also use the CPU to render on any target, including a GDI bitmap.