-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDirectDraw.cpp
105 lines (82 loc) · 2.07 KB
/
DirectDraw.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// DirectDraw.cpp
//
// Functions to help with DirectDraw
#include <windows.h>
#include "Alchemy.h"
#include "DirectXUtil.h"
struct SDDERRText
{
HRESULT hr;
char *pszText;
};
static SDDERRText g_DDERRTable[] =
{
{ DDERR_GENERIC, "DDERR_GENERIC" },
{ DDERR_IMPLICITLYCREATED, "DDERR_IMPLICITLYCREATED" },
{ DDERR_INCOMPATIBLEPRIMARY, "DDERR_INCOMPATIBLEPRIMARY" },
{ DDERR_INVALIDOBJECT, "DDERR_INVALIDOBJECT" },
{ DDERR_INVALIDPARAMS, "DDERR_INVALIDPARAMS" },
{ DDERR_NOEXCLUSIVEMODE, "DDERR_NOEXCLUSIVEMODE" },
{ DDERR_OUTOFMEMORY, "DDERR_OUTOFMEMORY" },
{ DDERR_UNSUPPORTED, "DDERR_UNSUPPORTED" },
{ DDERR_WRONGMODE, "DDERR_WRONGMODE" },
{ DD_OK, "DD_OK" },
};
void LogDDError (HRESULT hr);
void *SurfaceLock (LPDIRECTDRAWSURFACE7 pSurface, DDSURFACEDESC2 *retpDesc)
// SurfaceLock
//
// Locks the given surface and returns a pointer to it
{
HRESULT hr;
DDSURFACEDESC2 desc;
if (retpDesc == NULL)
retpDesc = &desc;
// Lock the surface
int iMaxCount = 10;
while (iMaxCount-- > 0)
{
retpDesc->dwSize = sizeof(desc);
hr = pSurface->Lock(NULL, retpDesc, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL);
// Return the pointer if successful
if (hr == DD_OK)
return (void *)retpDesc->lpSurface;
// Restore the surface if necessary
else if (hr == DDERR_SURFACELOST)
{
hr = pSurface->Restore();
::Sleep(500);
if (FAILED(hr))
kernelDebugLogPattern("Surface restore failed: %x", hr);
}
// Fail with an error otherwise
else
{
kernelDebugLogPattern("Lock failed: %x", hr);
return NULL;
}
}
// If we've tried 10 times (5 seconds) and still nothing, then we give up
kernelDebugLogPattern("Unable to lock surface");
return NULL;
}
void SurfaceUnlock (LPDIRECTDRAWSURFACE7 pSurface)
// SurfaceUnlock
//
// Unlocks the surface previously locked by SurfaceLock
{
pSurface->Unlock(NULL);
}
void LogDDError (HRESULT hr)
{
SDDERRText *pEntry = g_DDERRTable;
while (pEntry->hr != DD_OK)
{
if (pEntry->hr == hr)
{
kernelDebugLogString(CString(pEntry->pszText));
break;
}
pEntry++;
}
}