XPDM - Dump the graphic bmp

Hi All,

I’m working on an XPDM model graphic user mode driver to dump the current graphic into a bitmap file to do debugging. Now my application can send the escape code to notify the driver to dump. The problem is that I have no idea which Eng*** APIs I should call to do that. Can anyone here who are familiar with this point me to the right references? Should I call the EngCreateBitmap or EngCreateDeviceBitmap or EngCreateDeviceSurface?

Thanks,
Marshall

Take a look at EngModifySurface - lDelta parameter.
Anshul Makkarwww.justkernel.com

— On Wed, 24/8/11, xxxxx@hotmail.com wrote:

From: xxxxx@hotmail.com
Subject: [ntdev] XPDM - Dump the graphic bmp
To: “Windows System Software Devs Interest List”
Date: Wednesday, 24 August, 2011, 8:15 AM

Hi All,

I’m working on an XPDM model graphic user mode driver to dump the current graphic into a bitmap file to do debugging. Now my application can send the escape code to notify the driver to dump. The problem is that I have no idea which Eng*** APIs I should call to do that. Can anyone here who are familiar with this point me to the right references? Should I call the EngCreateBitmap or EngCreateDeviceBitmap or EngCreateDeviceSurface?

Thanks,
Marshall


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Thanks for your quick respond, Anshul.

However, I’m not quite sure what you really mean. Are you saying that I should do the following things?

  • Call the EngCreateDeviceSurface to create the device surface.
  • Associate the device surface with the device by calling EngAssociateSurface.
  • Call the EngModifySurface to copy the back buffer contents into the device surface.

Am I understanding right?

Thanks,
Marshall

If you have already allocated some memory and are using it as the Surface, then all you need to do is read your memory and write it to a file of your choice with a standard .bmp header describing the surface width, height, colour depth, etc.

Tim.


From: xxxxx@lists.osr.com [xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com [xxxxx@hotmail.com]
Sent: 24 August 2011 03:45
To: Windows System Software Devs Interest List
Subject: [ntdev] XPDM - Dump the graphic bmp

Hi All,

I’m working on an XPDM model graphic user mode driver to dump the current graphic into a bitmap file to do debugging. Now my application can send the escape code to notify the driver to dump. The problem is that I have no idea which Eng*** APIs I should call to do that. Can anyone here who are familiar with this point me to the right references? Should I call the EngCreateBitmap or EngCreateDeviceBitmap or EngCreateDeviceSurface?

Thanks,
Marshall

How can I retrieve the primary surface? Can it be the surface from calling the EngCreateDeviceSurface?

Thanks,
Marshall

Hi,
Yes, do EngCreateSurface.?Then in EngModifySurface, in lDelta parameter specify ppdev->pVideoMemory .
ppdev->pVideoMemory can be a kernel mode buffer or static file.
Please let me know in case of any further queries.
ThanksAnshul Makkarwww.justkernel.com
— On Wed, 24/8/11, xxxxx@hotmail.com wrote:

From: xxxxx@hotmail.com
Subject: RE:[ntdev] XPDM - Dump the graphic bmp
To: “Windows System Software Devs Interest List”
Date: Wednesday, 24 August, 2011, 9:12 AM

Thanks for your quick respond, Anshul.

However, I’m not quite sure what you really mean. Are you saying that I should do the following things?

- Call the EngCreateDeviceSurface to create the device surface.
- Associate the device surface with the device by calling EngAssociateSurface.
- Call the EngModifySurface to copy the back buffer contents into the device surface.

Am I understanding right?

Thanks,
Marshall


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

xxxxx@hotmail.com wrote:

How can I retrieve the primary surface?

You can’t. Your mirror driver has to maintain its OWN surface. Your
mirror driver stands completely on its own, with no connection to any
other display drivers. You will receive all of the same drawing
requests that the primary driver receives, and you have to update your
surface to reflect those calls. Then, when your user requests a copy,
you send him your surface.

Can it be the surface from calling the EngCreateDeviceSurface?

Probably.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thanks all for your great suggestion. I wrote some test code for that. I have an application to send the escape code to the display driver with allocating a HBITMAP object. The display driver handles that escape code, locks the bitmap and writes a pink rectangle. Then the applicaiton saves the HITMAP bits to a bmp file. However, it doesn’t work. The code is listed as below:

Application:
LPBYTE pBits = HeapAlloc(…);
HBITMAP hBitmap = CreateBitmap(pSize->cx,pSize->cy,1,32,pBits);

HDC hDc = CreateDC(L"DISPLAY", L"\\.\DISPLAY1", NULL, NULL);
MY_SCREENCAPTURE sc;
sc.hBmp = hBitmap;
ExtEscape(hDc, EscScreenCapture, sizeof(MY_SCREENCAPTURE), (LPCSTR)&sc, 0, NULL);

Display Driver:
ULONG MyDrvEscape(
SURFOBJ *pso,
ULONG iEsc,
ULONG cjIn,
PVOID pvIn,
ULONG cjOut,
PVOID pvOut
)
{
case EscScreenCapture:
{
MY_SCREENCAPTURE captureStruct;
SURFOBJ* pSurfObj;
LPDWORD pBits;
int x, y;

// Parameter extraction:
__try {captureStruct = *(MY_SCREENCAPTURE*)(pvIn);}
__except(EXCEPTION_EXECUTE_HANDLER) {goto lblAccessErr;}

pSurfObj = EngLockSurface((HSURF)captureStruct.hBmp);
pBits = (LPDWORD)captureStruct.pBits;
for (y = 0; y < 25; y++)
{
for (x = 0; x < 50; x++)
{
pBits = 0xFFFF00FF;
}
*(LPBYTE*)&pBits += pSurfObj->lDelta;
}
EngUnlockSurface(pSurfObj);
}
break;
}

Does anyone why it deosn’t work? The escape code should runs in the my applicaiton context.

Thanks,
Marshall

I mean I can’t see anything in the saved bmp file except the black background. I’m sure the correctness of the code of saving the bimap file.

xxxxx@hotmail.com wrote:

Thanks all for your great suggestion. I wrote some test code for that. I have an application to send the escape code to the display driver with allocating a HBITMAP object. The display driver handles that escape code, locks the bitmap and writes a pink rectangle. Then the applicaiton saves the HITMAP bits to a bmp file. However, it doesn’t work. The code is listed as below:

You are getting the address of the pixels from captureStruct.pBits, but
I don’t see you initializing that field in user mode. In any case, you
probably don’t want to pass a raw user-mode address anyway. When you do
EngLockSurface, the resulting SURFOBJ includes pvBits and pvScan0 fields
that point to the pixels. You should use pvScan0, since you are using
lDelta, and that will be negative in this case. pvScan0 points to the
topmost scan, which will be the last one in memory.

I guess I had forgotten that a user-mode HBITMAP could be used in kernel
mode as an HSURF, but that fact that this didn’t simply explode suggests
that must work.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thanks a lot, Tim. I can make the application save the bitmap with a pink rectangle in the upper left corner now.

However, I still have no idea how to save the graphic of the primary surface. Do I need to implement the DrvEnableSurface to create my own surface and associate the surface with the device? Or is there any way that I can retrieve the primary surface and call the EngBitBlt or EngCopyBits to my private surface?

Thanks again.

xxxxx@hotmail.com wrote:

Thanks a lot, Tim. I can make the application save the bitmap with a pink rectangle in the upper left corner now.

However, I still have no idea how to save the graphic of the primary surface. Do I need to implement the DrvEnableSurface to create my own surface and associate the surface with the device? Or is there any way that I can retrieve the primary surface and call the EngBitBlt or EngCopyBits to my private surface?

I think I already told you this.

You can’t touch “the primary surface”. There is no relationship between
your driver and whatever other graphics drivers are running. You are
all completely separate. You have to maintain your own “primary
surface”, as if you were the only driver in the system. Because you are
a mirror driver, GDI will send you the same drawing commands it sends to
the other graphics drivers. In reponse to those commands, you have to
update your surface (or allow GDI to do it).


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Hi Tim,

I may make my words misunderstood. As matter of fact, I’m not making a mirror driver. Instead, I’m making a real display driver something like those developed by NAVIDA, ATI or INTEL. Now my requirement is to dump the primary surface to a bitmap file to do debugging.

In this case, do you think whether I still need to do the things that you described in the above comments?

Thanks,
Marshall

xxxxx@hotmail.com wrote:

I may make my words misunderstood. As matter of fact, I’m not making a mirror driver. Instead, I’m making a real display driver something like those developed by NAVIDA, ATI or INTEL. Now my requirement is to dump the primary surface to a bitmap file to do debugging.

In this case, do you think whether I still need to do the things that you described in the above comments?

If you are making a real display driver, then you KNOW where to find the
primary surface. You created it at some point, so you know where to
find the address of the pixels.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

I totally agree with it, Tim:). I’m new to the Windows Display Driver 2000 Model and I need to maintian the code myself. I would like to dump the primary surface to watch its contents but I don’t know where I can get the primary surface which the MSDN doesn’t mention.

Would you point me to the place where I can find the answer? I think it pretty much normal requirement. Otherwise, how can developers watch the primary surface bits?

Thanks,
Marshall

xxxxx@hotmail.com wrote:

I totally agree with it, Tim:). I’m new to the Windows Display Driver 2000 Model and I need to maintian the code myself. I would like to dump the primary surface to watch its contents but I don’t know where I can get the primary surface which the MSDN doesn’t mention.

Right, because that’s a detail that is internal to the display driver.
Your graphic routines are handed a DHPDEV, which you returned from
DrvEnablePDEV. That DHPDEV is a pointer to a structure defined by your
driver, containing all of your context information. That context will
at least contain an HSURF or DSURF that wraps the surface object, and
commonly also contains a simple pointer to the frame buffer.

Would you point me to the place where I can find the answer? I think it pretty much normal requirement. Otherwise, how can developers watch the primary surface bits?

They watch the primary surface bits on the screen, of course! The
primary surface is usually just the graphics card’s frame buffer mapped
into virtual memory. Changes in the frame buffer are immediately
reflected on the monitor.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.