Windows graphic programming Reading Notes-Chapter 2

Source: Internet
Author: User

I wrote an ancient book based on Win2k, and even the libraries used in many examples in the book have been replaced, so debugging cannot be done. However, there are no other books on the market that detail the Internal principles of system graphics. The book has a lot of content and is relatively abstract. After studying for almost a month, I only learned a few chapters and suffered from a lot of problems that cannot be debugged. What I mentioned in the book cannot be used with the system. Now I just want to sort out some key points and lay a theoretical foundation.

Operating System graphics and multimedia systems are hierarchical systems. The top applications use WIN32API and a 32-bit user mode system DLL interface to implement functions. The system DLL layer includes similar DLL, such as gdi32.dll, user32.dll, and kernel32.dll. Most modules of the system DLL layer are provided by the operating system, but the components of this layer depend on the user-mode driver provided by the hardware vendor. Below is the system service call entry, which activates the system call provided by the system service routine in the kernel mode of the operating system. The WindowsNT/2000 executable in the kernel address space provides graphics engines, Io managers, and video port drivers to support graphics and multimedia systems.

In the user mode layer, the graphic device interface (GDI) and Image Color Management (ICM) provide a device-independent graphical programming interface for applications.

DirectX adds a new set of DLL for directxcom interface operations for Win32 system DLL, which executes the directxcom interface. For the interface actually executed by DirectX in the kernel address space, DirectX is implemented through GDI.

 

I. GDI Architecture

GDI provides functions that can be called in hundreds of Windows programs. These functions are mostly exported from Win32 subsystem DLL--GDI32. dll. The window management module user32.dll is a big user who uses the GDI function to draw details such as menus, icons, scroll bars, title bars, and frames of each window. Some drawing functions are exported from user32.dll and provided to the application. Windows 543 provides 714 entry points-win7 provides entry points.

These functions are divided into 17 categories by function. So far, the msdn descriptions of win7 are still classified as follows:

  • Bitmaps
  • Brushes
  • Clipping
  • Colors
  • Coordinate spaces and transformations
  • Device contexts
  • Filled shapes
  • Fonts and text
  • Lines and curves
  • Metafiles
  • Multiple display monitors
  • Painting and drawing
  • Paths
  • Pens
  • Printing and Print Spooler
  • Rectangles
  • Regions

    In Win32 subsystem DLL, gdi32.dll is a relatively small module. GDI uses the WindowsNT/2000 system call or local API to call the GDI graphics engine to implement most of its functions. Win32 subsystem dllgdi32.dll converts WIN32API call into system service call to implement win32gdiapi. System Service call is implemented by the GDI graphics engine in win32k. sys. Pixel files, Enhanced Meta files, and EMF printing and uninstallation are indeed new features provided by gdi32.dll, which are not directly assisted by the GDI engine.

    The book introduces the DirectX architecture, which is built on GDI and other OS services by using COM technology. You need to expand a part of DirectX: DirectDraw architecture.

    Ii. DirectDraw Architecture

    DirectDraw can be seen as the specialization of GDI. The first step of specialization is to restrict its access to a computer display card rather than other devices. Step 2: Reduce the features supported by GDI. The last step is to implement limited hardware acceleration functions and add functions that are critical to high-performance games and multimedia programming.

    The DirectDraw architecture includes the user mode and kernel mode components. The user mode component of DirectDraw is ddraw. dll, which is related to gdi32.dll and McD. dll (OpenGL. In fact, directdrawapi is implemented by ddraw. dll, while ddraw. dll interacts with the GDI engine through gdi32.dll, and then interacts with the DirectDraw device driver.

    DirectDraw is implemented in several layers. The top layer supports the DirectDraw COM interface, standard com export function (dllgetclassobject, etc.), and special DirectDraw creation routine (directdrawcreate ). The middle layer is the hardware simulation layer (EL), which imitates all or part of the DirectDraw functions not supported by the hardware. The underlying layer is called the hardware abstraction layer (HAL), which directly communicates with the display hardware. Both directdrawapi and El are in user mode and cannot directly access directdrawhal. directdrawhal is in kernel mode in WindowsNT/2 K.

    Iii. graphics engine

    WindowsNT/2 k graphics engine is the pillar of GDI, the door to graphics device drivers, and other drivers are the cornerstone. In a kernel-mode DLL, the graphics engine also implements the windows management function of the Operating System-win32k. sys. Win32k. sys can be seen as the kernel pillar to implement two important modules in the Windows operating system: user32.dll and gdi32.dll. Win32k. sys itself is a large DLL.

    The graphic engine system service generally starts with ntgdi. The Window Management Service generally starts with ntuser.

    The graphic engine (graphicsrenderengine), the graphics engine itself and the graphics engine driver use GRE. Greapi and win32gdiapi are very different. The following lists the main concepts used by GRE and graphics engines: bitmap managed by GDI, coordinate space, surface, hook-in and kick-back, and plot elements.

    The graphic engine combines and breaks down win32gdi drawing calls into some primitive drawing commands. They are drawing calls supported by GRE. The following is a summary:

    * Englineto and engw.kepath draw all straight lines and curves

    * Engfillpath and engpaint fill the closed surface with a paint brush

    * Engstoke and fillpath fill the closed surface with a paint brush and draw the border with the paint brush at 1.1 points.

    * Engbltblt, engplgblt, engstretchblt, engstretchbltrop, engcopybits, engalphablend, and engtransparenblt implement bitmap rendering APIs.

    * Enggradientfill completes face gradient Filling

    * Engtestout handles all text drawing calls

    In addition to simplified graphic elements, GRE uses a completely new data structure. This does not refer to the GDI handle. In fact, GRE is either under or after the GDI handle layer.

     

    Transform elements. The gdi api layer is responsible for converting WIN32API calls into GRE elements.

    * Coordinate system. WIN32API provides a variety of Coordinate Systems to complete the conversion from the view to the window, the ing mode and the world transformation. While GRE/DDI uses device coordinates. The size of device coordinates is determined by the size of the drawing surface. The coordinates in the winewapi call must be converted to the coordinates of the actual drawing surface device.

    * Elliptic curve. The GRE/DDI interface does not support elliptic curves, such as circles, arcs, or rectangles. They need to be converted to the besell curve.

    * Curve to path. The DDI interface only supports straight lines and paths. Therefore, the curve must be a path object internally. The graphic engine has a rich set of path object control functions.

     

  • 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.