enable.c revision e64031e20c39650a7bc902a3e1aba613b9415dee
/******************************Module*Header*******************************\
*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*
* Based in part on Microsoft DDK sample code
*
* *******************
* * GDI SAMPLE CODE *
* *******************
*
* Module Name: enable.c
*
* This module contains the functions that enable and disable the
* driver, the pdev, and the surface.
*
* Copyright (c) 1992-1998 Microsoft Corporation
\**************************************************************************/
#include "driver.h"
#include "dd.h"
#include <VBoxDisplay.h>
// Hook functions to track dirty rectangles and generate RDP orders.
// NT4 functions
DRVFN gadrvfn_nt4[] = {
// { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap }, // 10
// { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap }, // 11
#ifdef VBOX_WITH_DDRAW
#endif
};
/* Experimental begin */
{
return TRUE;
}
BOOL DrvNineGrid (PVOID x1, PVOID x2, PVOID x3, PVOID x4, PVOID x5, PVOID x6, PVOID x7, PVOID x8, PVOID x9)
{
DISPDBG((0, "Experimental %s: %p, %p, %p, %p, %p, %p, %p, %p, %p\n", __FUNCTION__, x1, x2, x3, x4, x5, x6, x7, x8, x9));
return FALSE;
}
{
}
ULONG APIENTRY DrvEscape(SURFOBJ *pso, ULONG iEsc, ULONG cjIn, PVOID pvIn, ULONG cjOut, PVOID pvOut)
{
switch(iEsc)
{
#ifdef VBOX_WITH_OPENGL
case OPENGL_GETINFO:
{
if ( cjOut >= sizeof(OPENGL_INFO)
&& pvOut)
{
DISPDBG((0, "OPENGL_GETINFO\n"));
return cjOut;
}
else
DISPDBG((0, "OPENGL_GETINFO invalid size %d\n", cjOut)); /* It doesn't matter that we fail here. Opengl32 will fall back to software rendering when this escape is not supported. */
break;
}
#endif
case VBOXESC_ISVRDPACTIVE:
{
#ifndef VBOX_WITH_HGSMI
{
{
ret = 1;
}
}
else
DISPDBG((0, "VBOXESC_ISVRDPACTIVE -> 0\n"));
#else
{
{
ret = 1;
}
}
else
DISPDBG((0, "VBOXESC_ISVRDPACTIVE -> 0\n"));
#endif /* VBOX_WITH_HGSMI */
return ret;
}
case VBOXESC_SETVISIBLEREGION:
{
DISPDBG((0, "VBOXESC_SETVISIBLEREGION\n"));
if ( cjIn >= sizeof(RGNDATAHEADER)
&& pvIn
{
{
DISPDBG((0, "New visible rectangle (%d,%d) (%d,%d)\n", pRect[i].left, pRect[i].bottom, pRect[i].right, pRect[i].top));
}
NULL,
0,
&ulReturn))
{
DISPDBG((0, "DISP DrvAssertMode failed IOCTL_VIDEO_VBOX_SETVISIBLEREGION\n"));
return 0;
}
else
{
DISPDBG((0, "DISP IOCTL_VIDEO_VBOX_SETVISIBLEREGION successful\n"));
return 1;
}
}
else
{
if (pvIn)
DISPDBG((0, "check failed rdh.dwSize=%x iType=%d size=%d expected size=%d\n", lpRgnData->rdh.dwSize, lpRgnData->rdh.iType, cjIn, lpRgnData->rdh.nCount * sizeof(RECT) + sizeof(RGNDATAHEADER)));
}
break;
}
case QUERYESCSUPPORT:
&& pvIn)
{
switch(nEscapeQuery)
{
#ifdef VBOX_WITH_OPENGL
case OPENGL_GETINFO:
return 1;
#endif
default:
break;
}
}
else
break;
default:
break;
}
return 0;
}
{
return TRUE;
}
{
return FALSE;
}
{
return FALSE;
}
{
return FALSE;
}
{
return FALSE;
}
/* Experimental end */
// W2K,XP functions
DRVFN gadrvfn_nt5[] = {
// { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap }, // 10
// { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap }, // 11
// { INDEX_DrvStrokeAndFillPath, (PFN) DrvStrokeAndFillPath }, // 16 0x10
#ifdef VBOX_WITH_DDRAW
#endif
// /* Experimental. */
// { 0x7, (PFN) DrvResetPDEV }, // 0x7
// { 0x5b, (PFN) DrvNineGrid }, // 0x5b
// { 0x2b, (PFN) DrvDestroyFont }, // 0x2b
// { 0x18, (PFN) DrvEscape }, // 0x18
// { 0x4d, (PFN) DrvConnect }, // 0x4d
// { 0x4e, (PFN) DrvDisconnect }, // 0x4e
// { 0x4f, (PFN) DrvReconnect }, // 0x4f
// { 0x50, (PFN) DrvShadowConnect }, // 0x50
// { 0x51, (PFN) DrvShadowDisconnect }, // 0x51
};
// Required hook bits will be set up according to DDI version
#define HOOKS_BMF8BPP gflHooks
#define HOOKS_BMF16BPP gflHooks
#define HOOKS_BMF24BPP gflHooks
#define HOOKS_BMF32BPP gflHooks
#ifndef VBOX_WITH_HGSMI
HSEMAPHORE ghsemHwBuffer = 0;
#endif /* !VBOX_WITH_HGSMI */
/******************************Public*Routine******************************\
* DrvEnableDriver
*
* Enables the driver by retrieving the drivers function table and version.
*
\**************************************************************************/
{
// Engine Version is passed down so future drivers can support previous
// engine versions. A next generation driver can support both the old
// and new engine conventions if told what version of engine it is
// working with. For the first version the driver does nothing with it.
// Set up hook flags to intercept all functions which can generate VRDP orders
#ifdef VBOX_NEW_SURFACE_CODE
#else
#endif
// Set up g_bOnNT40 based on the value in iEngineVersion
// Fill in as much as we can.
if (cj >= sizeof(DRVENABLEDATA))
sizeof(gadrvfn_nt5) / sizeof(DRVFN):
sizeof(gadrvfn_nt4) / sizeof(DRVFN);
// DDI version this driver was targeted for is passed back to engine.
// Future graphic's engine may break calls down to old driver format.
#ifndef VBOX_WITH_HGSMI
if (!ghsemHwBuffer)
{
}
#endif /* !VBOX_WITH_HGSMI */
return(TRUE);
}
/******************************Public*Routine******************************\
* DrvDisableDriver
*
* Tells the driver it is being disabled. Release any resources allocated in
* DrvEnableDriver.
*
\**************************************************************************/
{
DISPDBG((0, "VBoxDisp::DrvDisableDriver called.\n"));
#ifndef VBOX_WITH_HGSMI
if (ghsemHwBuffer)
{
}
#endif /* !VBOX_WITH_HGSMI */
return;
}
/******************************Public*Routine******************************\
* DrvEnablePDEV
*
* DDI function, Enables the Physical Device.
*
* Return Value: device handle to pdev.
*
\**************************************************************************/
{
DISPDBG((0, "VBoxDisp::DrvEnablePDEV called\n"));
// Allocate a physical device structure.
{
DISPDBG((0, "DISP DrvEnablePDEV failed EngAllocMem\n"));
return((DHPDEV) 0);
}
// Save the screen handle in the PDEV.
// Get the current screen mode information. Set up device caps and devinfo.
{
DISPDBG((0,"DISP DrvEnablePDEV failed\n"));
goto error_free;
}
// Initialize the cursor information.
{
// Not a fatal error...
DISPDBG((0, "DrvEnablePDEV failed bInitPointer\n"));
}
// Initialize palette information.
{
DISPDBG((0, "DrvEnablePDEV failed bInitPalette\n"));
goto error_free;
}
// // Start a thread that will process notifications from VMMDev
// if (!bInitNotificationThread(ppdev))
// {
// DISPDBG((0, "DrvEnablePDEV failed bInitNotificationThread\n"));
// goto error_free;
// }
// Copy the devinfo into the engine buffer.
DISPDBG((0, "VBoxDisp::DrvEnablePDEV: sizeof(DEVINFO) = %d, cjDevInfo = %d, alpha = %d\n", sizeof(DEVINFO), cjDevInfo, DevInfo.flGraphicsCaps2 & GCAPS2_ALPHACURSOR));
// @todo seems to be not necessary. these bits are initialized in screen.c DevInfo.flGraphicsCaps |= GCAPS_OPAQUERECT |
// GCAPS_DITHERONREALIZE |
// GCAPS_PALMANAGED |
// GCAPS_ALTERNATEFILL |
// GCAPS_WINDINGFILL |
// GCAPS_MONO_DITHER |
// GCAPS_COLOR_DITHER |
// GCAPS_ASYNCMOVE;
//
// DevInfo.flGraphicsCaps |= GCAPS_DITHERONREALIZE;
// Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
// pdev.
// Error case for failure.
return((DHPDEV) 0);
}
/******************************Public*Routine******************************\
* DrvCompletePDEV
*
* Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
*
\**************************************************************************/
{
}
/******************************Public*Routine******************************\
* DrvDisablePDEV
*
* Release the resources allocated in DrvEnablePDEV. If a surface has been
* enabled DrvDisableSurface will have already been called.
*
\**************************************************************************/
{
// vStopNotificationThread ((PPDEV) dhpdev);
}
/******************************Public*Routine******************************\
* VOID DrvOffset
*
* DescriptionText
*
\**************************************************************************/
{
// Add back last offset that we subtracted. I could combine the next
// two statements, but I thought this was more clear. It's not
// performance critical anyway.
// Subtract out new offset
return(TRUE);
}
/******************************Public*Routine******************************\
* DrvEnableSurface
*
* Enable the surface for the device. Hook the calls this driver supports.
*
* Return: Handle to the surface if successful, 0 for failure.
*
\**************************************************************************/
{
#ifdef VBOX_NEW_SURFACE_CODE
#endif
DISPDBG((0, "DISP DrvEnableSurface called\n"));
// Create engine bitmap around frame buffer.
{
DISPDBG((0, "DISP DrvEnableSurface failed bInitSURF\n"));
return(FALSE);
}
DISPDBG((0, "DISP DrvEnableSurface bInitSURF success\n"));
{
if (!bInit256ColorPalette(ppdev)) {
DISPDBG((0, "DISP DrvEnableSurface failed to init the 8bpp palette\n"));
return(FALSE);
}
}
{
}
{
}
else
{
}
#ifdef VBOX_NEW_SURFACE_CODE
{
DISPDBG((0, "DrvEnableSurface: failed pdsurf memory allocation\n"));
goto l_Failure;
}
//
// On NT4.0 we create a GDI managed bitmap as the primay surface. But
// on NT5.0 we create a device managed primary.
//
// On NT4.0 we still use our driver's accleration capabilities by
// doing a trick with EngLockSurface on the GDI managed primary.
//
if(g_bOnNT40)
{
}
else
{
}
if ( hsurf == 0 )
{
DISPDBG((0, "DrvEnableSurface: failed EngCreateDeviceBitmap\n"));
goto l_Failure;
}
//
// On NT5.0 we call EngModifSurface to expose our device surface to
// GDI. We cant do this on NT4.0 hence we call EngAssociateSurface.
//
if(g_bOnNT40)
{
//
// We have to associate the surface we just created with our physical
// device so that GDI can get information related to the PDEV when
// it's drawing to the surface (such as, for example, the length of
// styles on the device when simulating styled lines).
//
//
// On NT4.0 we dont want to be called to Synchronize Access
//
{
DISPDBG((0, "DrvEnableSurface: failed EngAssociateSurface\n"));
goto l_Failure;
}
//
// Jam in the value of dhsurf into screen SURFOBJ. We do this to
// make sure the driver acclerates Drv calls we hook and not
// punt them back to GDI as the SURFOBJ's dhsurf = 0.
//
if(ppdev->psoScreenBitmap == 0)
{
DISPDBG((0, "DrvEnableSurface: failed EngLockSurface\n"));
goto l_Failure;
}
}
else
{
//
// Tell GDI about the screen surface. This will enable GDI to render
// directly to the screen.
//
if ( !EngModifySurface(hsurf,
NULL))
{
DISPDBG((0, "DrvEnableSurface: failed EngModifySurface"));
goto l_Failure;
}
}
#else
/* Create a GDI bitmap which will be used to draw with Eng* functions. */
{
DISPDBG((0, "DISP DrvEnableSurface failed EngCreateBitmap ppdev->hsurfScreenBitmap\n"));
goto l_Failure;
}
else
{
/* Get the GDI bitmap SURFOBJ, which will be passed to Eng*. */
/* Create device managed surface, which will represent screen for GDI. */
ppdev->hsurfScreen = (HSURF)EngCreateDeviceSurface((DHSURF)ppdev, /* Handle assigned by the device. */
sizl,
{
DISPDBG((0, "DISP DrvEnableSurface failed EngCreateDeviceSurface ppdev->hsurfScreen\n"));
goto l_Failure;
}
else
{
/* Tell GDI that the driver will handle drawing operations on the screen surface. */
{
DISPDBG((0, "DISP DrvEnableSurface failed EngAssociateSurface for Screen.\n"));
goto l_Failure;
}
else
{
DISPDBG((0, "DISP DrvEnableSurface success ppdev %p, ppdev->hsurfScreen %p\n", ppdev, ppdev->hsurfScreen));
}
}
}
#endif /* VBOX_NEW_SURFACE_CODE */
return ppdev->hsurfScreen;
return((HSURF)0);
}
/******************************Public*Routine******************************\
* DrvDisableSurface
*
* Free resources allocated by DrvEnableSurface. Release the surface.
*
\**************************************************************************/
{
DISPDBG((0, "VBoxDisp::DrvDisableSurface called\n"));
if (ppdev->psoScreenBitmap)
{
}
if (ppdev->hsurfScreen)
{
}
#ifdef VBOX_NEW_SURFACE_CODE
if (ppdev->pdsurfScreen)
{
}
#else
if (ppdev->hsurfScreenBitmap)
{
}
#endif
}
/******************************Public*Routine******************************\
* DrvAssertMode
*
* This asks the device to reset itself to the mode of the pdev passed in.
*
\**************************************************************************/
{
if (bEnable)
{
{
DISPDBG((0, "DISP DrvAssertMode failed bInitSURF\n"));
return (FALSE);
}
#ifdef VBOX_NEW_SURFACE_CODE
#endif
{
DISPDBG((0, "DISP DrvAssertMode Screen pointer has changed!!!\n"));
{
DISPDBG((0, "DISP DrvAssertMode failed EngCreateBitmap\n"));
return FALSE;
}
if (ppdev->psoScreenBitmap)
{
}
if (ppdev->hsurfScreenBitmap)
{
}
}
{
DISPDBG((0, "DISP DrvAssertMode failed EngAssociateSurface for ScreenBitmap.\n"));
return FALSE;
}
{
DISPDBG((0, "DISP DrvAssertMode failed EngAssociateSurface for Screen.\n"));
return FALSE;
}
return TRUE;
}
else
{
#ifdef VBOX_WITH_VIDEOHWACCEL
/* tells we can not process host commands any more and ensures we've completed processing of the host VHWA commands */
#endif
#ifdef VBOX_WITH_HGSMI
/* Free the driver's VBVA resources. */
#endif
//
// We must give up the display.
// Call the kernel driver to reset the device to a known state.
//
NULL,
0,
NULL,
0,
&ulReturn))
{
DISPDBG((0, "DISP DrvAssertMode failed IOCTL\n"));
return FALSE;
}
else
{
return TRUE;
}
}
}
#if 0
/******************************Public*Routine**********************************\
* HBITMAP DrvCreateDeviceBitmap
*
* Function called by GDI to create a device-format-bitmap (DFB). We will
* always try to allocate the bitmap in off-screen; if we can't, we simply
* fail the call and GDI will create and manage the bitmap itself.
*
* Note: We do not have to zero the bitmap bits. GDI will automatically
* call us via DrvBitBlt to zero the bits (which is a security
* consideration).
*
\******************************************************************************/
{
/* Let GDI manage the bitmap */
return (HBITMAP)0;
}
/******************************Public*Routine**********************************\
* VOID DrvDeleteDeviceBitmap
*
* Deletes a DFB.
*
\******************************************************************************/
{
}
#endif /* 0 */
/******************************Public*Routine******************************\
* DrvGetModes
*
* Returns the list of available modes for the device.
*
\**************************************************************************/
{
&cbModeSize);
if (cModes == 0)
{
DISPDBG((0, "DrvGetModes failed to get mode information"));
return 0;
}
{
}
else
{
//
// Now copy the information for the supported modes back into the output
// buffer
//
cbOutputSize = 0;
do
{
if (pVideoTemp->Length != 0)
{
if (cOutputModes == 0)
{
break;
}
//
// Zero the entire structure to start off with.
//
//
// Set the name of the device to the name of the DLL.
//
pdm->dmDisplayFlags = 0;
//
// Go to the next DEVMODE entry in the buffer.
//
cOutputModes--;
}
} while (--cModes);
}
return cbOutputSize;
}
{
DISPDBG((0, "VBoxDisp::DrvSynchronize\n"));
}
/******************************Public*Routine******************************\
* DrvNotify
*
* Called by GDI to notify us of certain "interesting" events
*
* DN_DEVICE_ORIGIN is used to communicate the X/Y offsets of individual monitors
* when DualView is in effect.
*
\**************************************************************************/
{
DISPDBG((0, "VBoxDisp::DrvNotify called.\n"));
switch(iType)
{
case DN_DEVICE_ORIGIN:
#ifndef VBOX_WITH_HGSMI
{
}
break;
#else
{
{
}
} break;
#endif /* VBOX_WITH_HGSMI */
case DN_DRAWING_BEGIN:
break;
}
}
#ifdef VBOX_WITH_DDRAW
//--------------------------Public Routine-------------------------------------
//
// HBITMAP DrvDeriveSurface
//
// This function derives and creates a GDI surface from the specified
// DirectDraw surface.
//
// Parameters
// pDirectDraw-----Points to a DD_DIRECTDRAW_GLOBAL structure that describes
// the DirectDraw object.
// pSurface--------Points to a DD_SURFACE_LOCAL structure that describes the
// DirectDraw surface around which to wrap a GDI surface.
//
// Return Value
// DrvDeriveSurface returns a handle to the created GDI surface upon success.
// It returns NULL if the call fails or if the driver cannot accelerate GDI
// drawing to the specified DirectDraw surface.
//
// Comments
// DrvDeriveSurface allows the driver to create a GDI surface around a
// DirectDraw video memory or AGP surface object in order to allow accelerated
// GDI drawing to the surface. If the driver does not hook this call, all GDI
// drawing to DirectDraw surfaces is done in software using the DIB engine.
//
// GDI calls DrvDeriveSurface with RGB surfaces only.
//
// The driver should call DrvCreateDeviceBitmap to create a GDI surface of the
// same size and format as that of the DirectDraw surface. Space for the
// actual pixels need not be allocated since it already exists.
//
//-----------------------------------------------------------------------------
{
//
// GDI should never call us for a non-RGB surface, but let's assert just
// to make sure they're doing their job properly.
//
AssertMsg(!(pSurfaceGlobal->ddpfSurface.dwFlags & DDPF_FOURCC), ("GDI called us with a non-RGB surface!"));
// The GDI driver does not accelerate surfaces in AGP memory,
// thus we fail the call
{
DISPDBG((0, "DrvDeriveSurface return NULL, surface in AGP memory\n"));
return 0;
}
// The GDI driver does not accelerate managed surface,
// thus we fail the call
{
DISPDBG((0, "DrvDeriveSurface return NULL, surface is managed\n"));
return 0;
}
//
// The rest of our driver expects GDI calls to come in with the same
// format as the primary surface. So we'd better not wrap a device
// bitmap around an RGB format that the rest of our driver doesn't
// understand. Also, we must check to see that it is not a surface
// whose pitch does not match the primary surface.
//
// NOTE: Most surfaces created by this driver are allocated as 2D surfaces
// whose lPitch's are equal to the screen pitch. However, overlay surfaces
// are allocated such that there lPitch's are usually different then the
// screen pitch. The hardware can not accelerate drawing operations to
// these surfaces and thus we fail to derive these surfaces.
//
{
{
}
{
}
{
}
else
{
}
/* Create a bitmap that represents the DDRAW bits.
* Important is to calculate the address of the bitmap.
*/
if (hbmDevice)
{
if (pSurfaceGlobal->fpVidMem == 0)
{
/* Screen surface, mark it so it will be recognized by the driver.
* and so the driver will be called on any operations on the surface
* (required for VBVA and VRDP).
*/
{
return(hbmDevice);
}
}
else
{
return(hbmDevice);
}
DISPDBG((0, "DrvDeriveSurface: EngAssociateSurface failed\n"));
}
}
DISPDBG((0, "DrvDeriveSurface return NULL\n"));
DISPDBG((0, "pSurfaceGlobal->ddpfSurface.dwRGBBitCount = %d, lPitch =%ld\n", pSurfaceGlobal->ddpfSurface.dwRGBBitCount,pSurfaceGlobal->lPitch));
return(0);
}
#endif /* VBOX_WITH_DDRAW */