• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef Debug_hpp
16 #define Debug_hpp
17 
18 #ifndef WIN32_LEAN_AND_MEAN
19 	#define WIN32_LEAN_AND_MEAN
20 #endif
21 #include <windows.h>
22 #include <d3d8.h>
23 #include <stdio.h>
24 #include <guiddef.h>
25 #include <assert.h>
26 
27 void trace(const char *format, ...);
28 
29 #ifndef NDEBUG
30 	#define TRACE(format, ...) trace("[0x%0.8X]%s("format")\n", this, __FUNCTION__, ##__VA_ARGS__)
31 #else
32 	#define TRACE(...) ((void)0)
33 #endif
34 
35 #ifndef NDEBUG
36 	#define ASSERT(expression) {if(!(expression)) trace("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); assert(expression);}
37 #else
38 	#define ASSERT assert
39 #endif
40 
41 #ifndef NDEBUG
42 	#define UNIMPLEMENTED() {trace("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); ASSERT(false);}
43 #else
44 	#define UNIMPLEMENTED() ((void)0)
45 #endif
46 
47 #ifndef NDEBUG
48 	#define NOINTERFACE(iid) _NOINTERFACE(__FUNCTION__, iid)
49 
_NOINTERFACE(const char * function,const IID & iid)50 	inline long _NOINTERFACE(const char *function, const IID &iid)
51 	{
52 		trace("\t! No interface {0x%0.8X, 0x%0.4X, 0x%0.4X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X} for %s\n", iid.Data1, iid.Data2, iid.Data3, iid.Data4[0], iid.Data4[1], iid.Data4[2], iid.Data4[3], iid.Data4[4], iid.Data4[5], iid.Data4[6], iid.Data4[7], function);
53 
54 		return  E_NOINTERFACE;
55 	}
56 #else
57 	#define NOINTERFACE(iid) E_NOINTERFACE
58 #endif
59 
60 #ifndef NDEBUG
INVALIDCALL()61 	inline long INVALIDCALL()
62 	{
63 		trace("\t! D3DERR_INVALIDCALL\n");
64 
65 		return D3DERR_INVALIDCALL;
66 	}
67 #else
68 	#define INVALIDCALL() D3DERR_INVALIDCALL
69 #endif
70 
71 #ifndef NDEBUG
OUTOFMEMORY()72 	inline long OUTOFMEMORY()
73 	{
74 		trace("\t! E_OUTOFMEMORY\n");
75 
76 		return E_OUTOFMEMORY;
77 	}
78 #else
79 	#define OUTOFMEMORY() E_OUTOFMEMORY
80 #endif
81 
82 #ifndef NDEBUG
OUTOFVIDEOMEMORY()83 	inline long OUTOFVIDEOMEMORY()
84 	{
85 		trace("\t! D3DERR_OUTOFVIDEOMEMORY\n");
86 
87 		return D3DERR_OUTOFVIDEOMEMORY;
88 	}
89 #else
90 	#define OUTOFVIDEOMEMORY() D3DERR_OUTOFVIDEOMEMORY
91 #endif
92 
93 #ifndef NDEBUG
NOTAVAILABLE()94 	inline long NOTAVAILABLE()
95 	{
96 		trace("\t! D3DERR_NOTAVAILABLE\n");
97 
98 		return D3DERR_NOTAVAILABLE;
99 	}
100 #else
101 	#define NOTAVAILABLE() D3DERR_NOTAVAILABLE
102 #endif
103 
104 #ifndef NDEBUG
NOTFOUND()105 	inline long NOTFOUND()
106 	{
107 		trace("\t! D3DERR_NOTFOUND\n");
108 
109 		return D3DERR_NOTFOUND;
110 	}
111 #else
112 	#define NOTFOUND() D3DERR_NOTFOUND
113 #endif
114 
115 #ifndef NDEBUG
MOREDATA()116 	inline long MOREDATA()
117 	{
118 		trace("\t! D3DERR_MOREDATA\n");
119 
120 		return D3DERR_MOREDATA;
121 	}
122 #else
123 	#define MOREDATA() D3DERR_MOREDATA
124 #endif
125 
126 #endif   // Debug_hpp
127