📄 surface.c
字号:
//
// Permedia3 Sample Display Driver
// surface.c
//
// Copyright (c) 2000 Microsoft Corporation. All rights reserved.
//
// This module exposes the surface allocation and deallocation routines
// for both DirectDraw and GDI. These calls allow the various graphics
// APIs above us to create video memory surfaces. We assume that the
// layewrs above willmanage thier resources correctly and free all of
// the surfaces they allocate.
#include "pch.h" // Precompiled header support.
#include "debug.h"
#include "struct.h"
#include "proto.h"
#include "const.h"
HBITMAP
DrvCreateDeviceBitmap(
DHPDEV DeviceHandle,
SIZEL Size,
ULONG GdiFormat
)
{
// DrvCreateDeviceBitmap
// This function is called by GDI when it needs to create a video
// memory surface. It provides the dimensions and pixel format
// desired.
// Local variables.
ULONG SurfaceBytes;
HSURF BitmapHandle = (HSURF)0xFFFFFFFF;
PERM3_SURFACE * Surface;
// Check parameters.
// !TODO! Change this once we return something real from DrvEnablePDEV.
Assert((ULONG)DeviceHandle == 123);
// This assertion protects us when we copy a SIZEL to a SIZE below.
Assert(sizeof(SIZE) == sizeof(SIZEL));
// !TODO! Other parameter checks?
Enter(L"DrvCreateDeviceBitmap");
Surface = SystemAlloc(sizeof(PERM3_SURFACE));
if (Surface != NULL) {
Surface->FreeFormat = FALSE;
Surface->Format = (const FORMAT *)GdiFormatToPerm3Format(GdiFormat);
Surface->Stride = Surface->Format->BitsPerPixel * Size.cx / 8;
SurfaceBytes = Surface->Stride * Size.cy;
// !TODO! Should we be aligning these things?
Surface->Ptr = VideoAlloc(SurfaceBytes,
0);
if (Surface->Ptr != NULL) {
// Fill out the rest of the surface data members.
memcpy(&Surface->Size, &Size, sizeof(SIZE));
Surface->Type = VideoMemory;
BitmapHandle = EngCreateDeviceSurface((DHSURF)Surface,
Size,
GdiFormat);
Surface->BitmapHandle = BitmapHandle;
Surface->ColorKeyType = NoColorKey;
memset(&Surface->SourceColorKey, 0, sizeof(COLOR_SPACE));
memset(&Surface->DestColorKey, 0, sizeof(COLOR_SPACE));
}
else {
Error(L"Video memory allocate failed in DrvCreateDeviceBitmap.");
}
}
else {
Error(L"System memory allocation failure.");
}
Exit(L"DrvCreateDeviceBitmap");
// In Windows CE GDI, an HSURF and an HBITMAP are actually the same thing.
return (HBITMAP)BitmapHandle;
}
void
DrvDeleteDeviceBitmap(
DHSURF SurfaceHandle
)
{
// DrvDeleteDeviceBitmap
// This function is called by GDI when it needs to free surfaces previously
// allocated with DrvCreateDeviceBitmap. We assume that we will never be
// called with a surface that we did not allocate.
// Local variables.
PERM3_SURFACE * Surface;
// Check parameters.
// !TODO!
Enter(L"DrvDeleteDeviceBitmap");
Surface = (PERM3_SURFACE *)SurfaceHandle;
Assert(Surface != NULL);
Assert(Surface->FreeFormat == FALSE);
EngDeleteSurface(Surface->BitmapHandle);
Assert(Surface->Type == VideoMemory);
VideoFree(Surface->Ptr);
SystemFree(Surface);
Exit(L"DrvDeleteDeviceBitmap");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -