Introduction to wince display driver development

Source: Internet
Author: User

In wince, the display driver is managed by the GWES module. Wince provides two display driver models to meet different hardware requirements. One is the display driver model based on WinCE DDI, and the other is the display driver model based on DirectDraw. The following describes the two architectures.

1. Display Driver Model

The display driver under wince is directly managed by the GWES module, which is directly managed and called by the GWES module. The display driver is actually layered, including The GPE library, which processes some default drawings, which is equivalent to the driving MDD layer. You only need to develop the hardware-related PDD driver. In wince, the entire architecture is as follows:

, Application is an applicationProgramThis program calls the graphic device interface function (GDI), which is exported by the coredll. dll module. Coredll. dll will package the function call parameters and then trigger the local process call to another process (LPC). All the drawing and window opening work will be passed to the GWES module in the kernel. The GWES module is called the graphics, window, and event subsystems. It handles graphics output, user input, and other events and all related interactions. The GWES module calls the display driver to complete the operation on the display hardware. The display driver consists of Gpe and DDL. DLL, GPE completes the basic default drawing work, while DDI. DLL actually inherits from The GPE class and implements related display hardware operations.

2. DirectDraw Display Driver Model

DirectDraw provides hardware-independent direct access to display devices. It can directly access some functions in the hardware abstraction layer (HAL) to directly operate on display devices. In this process, the conversion of graphical device interfaces (GDI) is no longer required. This direct method can make the image more coherent and improve the display performance. To implement this function, you need to extend the functions that can directly access the relevant hardware on the display driver. These functions are called by the DirectDraw module and form the DirectDraw Hardware Abstraction Layer (ddhal ). DirectDraw display driver architecture:

True implementation of DirectDrawCodeAll reside in GWES. in the DLL module, the application only connects to a small client called ddraw. DLL proxy, which is mainly responsible for the remote DirectDraw COM interface connection between the user process and the system. In this way, user requests are transmitted to the GWES module of the kernel. For DirectDraw, WinCE provides a GPE Library (ddgpe) named DirectDraw, which is inherited from the GPE class. In fact, the DirectDraw display driver is composed of ddgpe and ddhal, and ddgpe already contains the ddhal function. You need to inherit from the ddgpe class and implement relevant functions. The GWES. dll module contains the GDI and ddraw components. These two components call the ddgpe interface in the driver to complete hardware operations.

In the above two architectures, you can select the appropriate architecture based on your hardware situation. The first architecture is implemented based on GPE class inheritance, and the second architecture is implemented based on ddgpe class inheritance, the ddgpe class of the second architecture is inherited from the GPE class of the first architecture. For specific definitions of the two types, see GPE. h and ddgpe. H files in the "wince600publiccommonoak Inc" path.

This blog will introduce the DirectDraw display driver model based on the display driver model.

The display driver under wince is implemented based on The GPE class, And The GPE has implemented the basic drawing work, which is equivalent to the MDD layer. The user needs to inherit the class and implement some other functions, so the user implementation is equivalent to the PDD layer.

The GPE class is an abstract class that contains many pure virtual functions and can only be used for inheritance. After inheriting the GPE class, you must implement pure virtual functions in The GPE class. The general steps for developing the display driver are as follows:

(1) inherit The GPE class and define an instance of the class.

(2) Implement the getgpe () function to return the instance of this class to the DDI interface on the upper layer.

(3) Implement the drvenabledriver (..) and displayinit (..) Functions and export these two interfaces.

(4) Implement functions in The GPE class.

The following describes the implementation steps:

1 Inherit The GPE class

First, inherit from The GPE class. If you want to support rotation on the display driver, you can inherit from the gperotate class. In fact, "GPE. H" has the following definitions:

Typedef GPE gperotate;

It can be seen that the gperotate class is The GPE class. Here, you can inherit from The GPE class. For example:

  Class newgpe: Public GPE
{
PRIVATE:
Gpemode m_modeinfo;
DWORD m_colordepth;
DWORD m_virtualframebuffer;
DWORD m_framebuffersize;
Bool m_cursordisabled;
Bool m_cursorvisible;
...
Public:
Newgpe (void );
Virtual int nummodes (void );
Virtual scode setmode (INT modeid, hpalette * palette );
Virtual int invblank (void );
Virtual scode setpalette (const paletteentry * Source, ushort firstentry, ushort numentries );
Virtual scode getmodeinfo (gpemode * pmode, int modenumber );
Virtual scode setpointershape (gpesurf * mask, gpesurf * colorsurface, int xhot, int yhot, int CX, int CY );
Virtual scode movepointer (INT xposition, int yposition );
Virtual void waitfornotbusy (void );
Virtual int isbusy (void );
Virtual void getphysicalvideomemory (unsigned long * physicalmemorybase, unsigned long * videomemorysize );
Virtual scode allocsurface (gpesurf ** surface, int width, int height, egpeformat format, int surfaceflags );
Virtual scode line (gpelineparms * lineparameters, egpephase phase );
Virtual scode bltprepare (gpebltparms * blitparameters );
Virtual scode bltcomplete (gpebltparms * blitparameters );
Virtual ulong getgraphicscaps ();
Virtual ulong drvescape (
Surfobj * PSO,
Ulong iesc,
Ulong cjin,
Pvoid pvin,
Ulong cjout,
Pvoid pvout );
Scode wrappedemulatedline (gpelineparms * lineparameters );
Void cursoron (void );
Void cursoroff (void );
# Ifdef rotate
Void setrotateparms ();
Long dynrotate (INT angle );
# Endif
};

Newgpe class inherits from The GPE class, including some attributes, as follows:

M_modeinfo: display mode. The structure is as follows:

Struct gpemode {
Int modeid; // Index Number of the display mode defined by the developer
Int width; // display width
Int height; // display height
Int BPP; // display depth
Int frequency; // display frequency
Egpeformat format; // The number of BITs each in the RGB format
};

M_colordepth: Display depth

M_virtualframebuffer: The framebuffer address.

M_framebuffersize: The size of framebuffer.

M_cursordisabled: The cursor enables Marking

M_cursorvisible: visible cursor mark

You can define the corresponding attributes as needed. In the newgpe class, you need to define and implement pure virtual functions in the base class. The newgpe class above already contains the definitions of these functions, other functions are included, which will be described below.

2. Implement the getgpe Function

After defining the newgpe class, we need to implement an instance. First, define a pointer to this class:

Static GPE * ggpe = (GPE *) NULL;

Then implement the getgpe function as follows:

GPE * getgpe (void)
{
If (! Ggpe)
{
Ggpe = new newgpe ();
}

Return ggpe;
}

In this function, a newgpe instance is created. At this time, the newgpe constructor will be called. Generally, we will perform some initialization work related to the display. This function returns the ggpe pointer to the upper interface.

3. Implement the drvenabledriver and displayinit functions.

The display driver provides more than 20 function interfaces for the upper-layer GWES module. However, these functions are not provided directly. In fact, they are only implemented through a drvenabledriver (...) function. This function is not implemented in the MDD layer of the display driver. Therefore, it must be defined in the PDD layer as follows:

Bool apientry drvenabledriver (ulong engineversion, ulong CJ, drvenabledata * data, pengcallbacks enginecallbacks)
{
Bool Fok = false;

// Make sure we know where our registry configuration is
If (gszbaseinstance [0]! = 0 ){
Fok = gpeenabledriver (engineversion, CJ, Data, enginecallbacks );
}

Return Fok;
}

Engineversion: DDI version, which is currently ddi_driver_version.

CJ: size of the drvenabledata structure.

Data: point to the drvenabledata struct.

Enginecallbacks: points to a callback function struct and transmits some GDI functions to the display driver.

The drvenabledata structure contains the pointer of the device interface function in the display driver. The gpeenabledriver function is called in the drvenabledriver function, which exports all the display-driven interface functions required by the GWES module. At the same time, the GWES module provides a callback function through the fourth parameter enginecallbacks for the display driver to call. This function is defined in "ddi_if.

Another important function is the displayinit function, which is the first function to be executed in the display driver. This function is mainly used to read some information in the Registry and make judgments. This function is optional or not implemented in the driver.

Bool apientry displayinit (lpctstr pszinstance, DWORD dwnummonitors)
{
DWORD dwstatus;
Hkey hkdisplay;
Bool Fok = false;

If (pszinstance! = NULL ){
_ Tcsncpy (gszbaseinstance, pszinstance, dim (gszbaseinstance ));
}

// Sanity check the path by making sure it exists
Dwstatus = regopenkeyex (HKEY_LOCAL_MACHINE, gszbaseinstance, 0, 0, & hkdisplay );
If (dwstatus = error_success ){
Regclosekey (hkdisplay );
Fok = true;
}
Else
{
Retailmsg (0, (_ T ("salcd2: displayinit: Can't open '% s' RN"), gszbaseinstance ));
}

Return Fok;
}

Pszinstance: displays Driver-related registry values in the registry.

Dwnummonitors: number of supported monitors

In this function, the existence of the display driver is determined by reading the registry information. If an error is returned, GWES will stop the initialization of the display driver. You can also initialize the display device or initialize other devices as required.

4. Implement functions in The GPE class

Because newgpe inherits from The GPE class, all pure virtual functions in The GPE class must be implemented. These functions are actually the functions to be implemented in the driver of the PDD layer, as shown below:

4.1 virtual scode getmodeinfo (gpemode * pmode, int modenumber)

Obtain the display mode.

Pmode: Structure of the output Display Mode

Modenumber: Index Number of the display mode

4.2 virtual int nummodes (void)

Obtain the number of display modes supported by the current driver

4.3 virtual scode setmode (INT modeid, hpalette * palette)

Set the display mode.

Modeid: Index Number of the display mode

Palette: color palette pointer, pointing to a palette created by engcreatepalette Function

4.4 virtual scode allocsurface (gpesurf ** surface, int width, int height, egpeformat format, int surfaceflags)

Create a drawing plane in the system memory.

Surface: pointer to allocated memory

Width: width

Height: Height

Format: Drawing plane format

Surfaceflags: indicates the memory allocation location.

4.5 virtual scode setpointershape (gpesurf * pmask, gpesurf * pcolorsurface, int xhot, int yhot, int CX, int CY );

Set the cursor shape.

Pmask: points to a mask containing the cursor shape

Pcolorsurface: points to the color plotting plane used by the cursor

Xhot: X coordinate of the cursor hotspot

Yhot: Y coordinate of the cursor hotspot

CX: cursor width

Cy: cursor height

4.6 virtual scode movepointer (int x, int y)

Move the cursor to a specified position or hide the cursor

X: The X coordinate of the cursor moving position. If it is-1, the cursor is hidden.

Y: Y coordinate of the cursor moving position

4.7 virtual scode bltprepare (gpebltparms * blitparameters)

This function is executed before bit block transfer to determine the BLT execution function.

Blitparameters: refers to the structure of a GPE bit block transfer parameter

4.8 virtual scode bltcomplete (gpebltparms * blitparameters)

This function is used to release the resources applied in bltprepare.

Blitparameters: refers to the structure of a GPE bit block transfer parameter

4.9 virtual scode line (gpelineparms * lineparameters, egpephase phase)

Draw line function

Lineparameters: points to the line struct of a gpe and describes the line drawn.

Phase: the stage of the draw line, which is described as follows:

Gpesingle: draw a single line

Gpeprepare: Prepare to draw a line

Gpecontinue

Gpecomplete: finished

Here, we need to mention that sometimes we can see that another function wrappedemulatedline (...) is called in this function (..), this function can also be found in the display driver for reference under the public directory of wince. This function is a fast line drawing function, which uses bresenham to draw lines.AlgorithmTo draw a line by using addition and subtraction and shift operations with high running speed.

4.10 virtual scode setpalette (const paletteentry * psource, ushort firstentry, ushort numentries)

Set the color palette

Psource: the struct that points to the entry information of a palette.

Firstentry: the first entry

Numentries: number of entries

4.11 virtual int invblank (void)

Whether the device is in the vertical invisibility Period

The above functions are defined as pure virtual functions in The GPE class and need to be implemented in the inheritance class, that is, in our driver. These functions must be implemented. You can also add other functions to the display driver as needed, such as support for Optical indicator and rotation, as shown below:

4.12 void cursoron (void)

Enable cursor display.

4.13 void cursoroff (void)

Disable cursor display.

4.14 void setrotateparms (void)

Set screen flip parameters.

4.15 void dynrotate (INT Angel)

Supports dynamic flip.

ANGEL: flip angle

4.16 ulong * apientry drvgetmasks (dhpdev)

Obtain the RGB mask of the display mode.

Dhpdev: indicates the mask information. For example, if the rgb565 mode is (0xf800, 0x07e0, 0x001f)

Note: This function must be implemented in the driver.

4.17 powerhandler (bool boff)

Power supply control.

Boff: True indicates power off, false indicates power on

4.18 ulong drvescape (dhpdev, surfobj * PSO, ulong iesc, ulong cjin, pvoid pvin, ulong cjout, pvoid pvout)

This function provides an interface for applications to directly access the display driver, which is similar to the IOCTLs function in the stream device driver. The application sends the operation code and data to the display device driver by calling the extescape function. The drvescape function receives and processes the data and returns the corresponding result to the estescape function. You can also define the corresponding operation code as needed.

Dhpdev: Device handle

PSO: Structure pointing to a drawing plane

Iesc: operation code

Cjin: buffer size of input data

Pvin: pointing to the input data buffer

Cjout: buffer size of the output data

Pvout: pointing to the buffer of the output data

This is basically the content. Pure virtual functions in The GPE class must be implemented. Other functions can be implemented as needed. When I was writing this blog, I hesitated in some places and began to feel that my language was not good enough to express myself, however, it may be because you have not fully understood some of the display driver's knowledge. If you have any questions, please forgive me and give some advice.

 

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.