reactos/win32ss/drivers/displays/framebuf/surface.c

202 lines
4.7 KiB
C
Raw Normal View History

/*
* ReactOS Generic Framebuffer display driver
*
* Copyright (C) 2004 Filip Navara
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "framebuf.h"
/*
* DrvEnableSurface
*
* Create engine bitmap around frame buffer and set the video mode requested
* when PDEV was initialized.
*
* Status
* @implemented
*/
HSURF APIENTRY
DrvEnableSurface(
IN DHPDEV dhpdev)
{
PPDEV ppdev = (PPDEV)dhpdev;
HSURF hSurface;
ULONG BitmapType;
SIZEL ScreenSize;
VIDEO_MEMORY VideoMemory;
VIDEO_MEMORY_INFORMATION VideoMemoryInfo;
ULONG ulTemp;
/*
* Set video mode of our adapter.
*/
if (EngDeviceIoControl(ppdev->hDriver, IOCTL_VIDEO_SET_CURRENT_MODE,
&(ppdev->ModeIndex), sizeof(ULONG), NULL, 0,
&ulTemp))
{
return FALSE;
}
/*
* Map the framebuffer into our memory.
*/
VideoMemory.RequestedVirtualAddress = NULL;
if (EngDeviceIoControl(ppdev->hDriver, IOCTL_VIDEO_MAP_VIDEO_MEMORY,
&VideoMemory, sizeof(VIDEO_MEMORY),
&VideoMemoryInfo, sizeof(VIDEO_MEMORY_INFORMATION),
&ulTemp))
{
return FALSE;
}
ppdev->ScreenPtr = VideoMemoryInfo.FrameBufferBase;
switch (ppdev->BitsPerPixel)
{
case 8:
IntSetPalette(dhpdev, ppdev->PaletteEntries, 0, 256);
BitmapType = BMF_8BPP;
break;
case 16:
BitmapType = BMF_16BPP;
break;
case 24:
BitmapType = BMF_24BPP;
break;
case 32:
BitmapType = BMF_32BPP;
break;
default:
return FALSE;
}
ppdev->iDitherFormat = BitmapType;
ScreenSize.cx = ppdev->ScreenWidth;
ScreenSize.cy = ppdev->ScreenHeight;
hSurface = (HSURF)EngCreateBitmap(ScreenSize, ppdev->ScreenDelta, BitmapType,
(ppdev->ScreenDelta > 0) ? BMF_TOPDOWN : 0,
ppdev->ScreenPtr);
if (hSurface == NULL)
{
return FALSE;
}
/*
* Associate the surface with our device.
*/
if (!EngAssociateSurface(hSurface, ppdev->hDevEng, 0))
{
EngDeleteSurface(hSurface);
return FALSE;
}
ppdev->hSurfEng = hSurface;
return hSurface;
}
/*
* DrvDisableSurface
*
* Used by GDI to notify a driver that the surface created by DrvEnableSurface
* for the current device is no longer needed.
*
* Status
* @implemented
*/
VOID APIENTRY
DrvDisableSurface(
IN DHPDEV dhpdev)
{
DWORD ulTemp;
VIDEO_MEMORY VideoMemory;
PPDEV ppdev = (PPDEV)dhpdev;
EngDeleteSurface(ppdev->hSurfEng);
ppdev->hSurfEng = NULL;
#ifdef EXPERIMENTAL_MOUSE_CURSOR_SUPPORT
/* Clear all mouse pointer surfaces. */
DrvSetPointerShape(NULL, NULL, NULL, NULL, 0, 0, 0, 0, NULL, 0);
#endif
/*
* Unmap the framebuffer.
*/
VideoMemory.RequestedVirtualAddress = ((PPDEV)dhpdev)->ScreenPtr;
EngDeviceIoControl(((PPDEV)dhpdev)->hDriver, IOCTL_VIDEO_UNMAP_VIDEO_MEMORY,
&VideoMemory, sizeof(VIDEO_MEMORY), NULL, 0, &ulTemp);
}
/*
* DrvAssertMode
*
* Sets the mode of the specified physical device to either the mode specified
* when the PDEV was initialized or to the default mode of the hardware.
*
* Status
* @implemented
*/
BOOL APIENTRY
DrvAssertMode(
IN DHPDEV dhpdev,
IN BOOL bEnable)
{
PPDEV ppdev = (PPDEV)dhpdev;
ULONG ulTemp;
if (bEnable)
{
BOOLEAN Result;
/*
* Reinitialize the device to a clean state.
*/
Result = EngDeviceIoControl(ppdev->hDriver, IOCTL_VIDEO_SET_CURRENT_MODE,
&(ppdev->ModeIndex), sizeof(ULONG), NULL, 0,
&ulTemp);
if (ppdev->BitsPerPixel == 8)
{
IntSetPalette(dhpdev, ppdev->PaletteEntries, 0, 256);
}
return Result;
}
else
{
/*
* Call the miniport driver to reset the device to a known state.
*/
return !EngDeviceIoControl(ppdev->hDriver, IOCTL_VIDEO_RESET_DEVICE,
NULL, 0, NULL, 0, &ulTemp);
}
}