1 | /* $Id: VBoxVideoIPRT.h 69079 2017-10-13 15:27:12Z vboxsync $ */
|
---|
2 | /*
|
---|
3 | * Copyright (C) 2017 Oracle Corporation
|
---|
4 | *
|
---|
5 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
6 | * copy of this software and associated documentation files (the "Software"),
|
---|
7 | * to deal in the Software without restriction, including without limitation
|
---|
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
9 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
10 | * Software is furnished to do so, subject to the following conditions:
|
---|
11 | *
|
---|
12 | * The above copyright notice and this permission notice shall be included in
|
---|
13 | * all copies or substantial portions of the Software.
|
---|
14 | *
|
---|
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
---|
18 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
---|
19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
---|
20 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
---|
21 | * USE OR OTHER DEALINGS IN THE SOFTWARE.
|
---|
22 | */
|
---|
23 |
|
---|
24 | /* In builds inside of the VirtualBox source tree we override the default
|
---|
25 | * VBoxVideoIPRT.h using -include, therefore this define must match the one
|
---|
26 | * there. */
|
---|
27 | #ifndef ___VBox_Graphics_VBoxVideoIPRT_h
|
---|
28 | #define ___VBox_Graphics_VBoxVideoIPRT_h
|
---|
29 |
|
---|
30 | # include "VBoxVideoErr.h"
|
---|
31 |
|
---|
32 | #ifndef __cplusplus
|
---|
33 | typedef enum
|
---|
34 | {
|
---|
35 | false = 0,
|
---|
36 | true
|
---|
37 | } bool;
|
---|
38 | # define RT_C_DECLS_BEGIN
|
---|
39 | # define RT_C_DECLS_END
|
---|
40 | #else
|
---|
41 | # define RT_C_DECLS_BEGIN extern "C" {
|
---|
42 | # define RT_C_DECLS_END }
|
---|
43 | #endif
|
---|
44 |
|
---|
45 | #if defined(IN_XF86_MODULE) && !defined(NO_ANSIC)
|
---|
46 | # ifdef __cplusplus
|
---|
47 | /* xf86Module.h redefines this. */
|
---|
48 | # define NULL 0
|
---|
49 | # endif
|
---|
50 | RT_C_DECLS_BEGIN
|
---|
51 | # include "xf86_ansic.h"
|
---|
52 | RT_C_DECLS_END
|
---|
53 | #endif /* defined(IN_XF86_MODULE) && !defined(NO_ANSIC) */
|
---|
54 | #define __STDC_LIMIT_MACROS /* define *INT*_MAX on C++ too. */
|
---|
55 | #include "compiler.h" /* Pulls in <sdtint.h>. Must come after xf86_ansic.h on XFree86. */
|
---|
56 | #include <X11/Xfuncproto.h>
|
---|
57 | #if defined(IN_XF86_MODULE) && !defined(NO_ANSIC)
|
---|
58 | /* XFree86 did not have these. Not that I care much for micro-optimisations
|
---|
59 | * in most cases anyway. */
|
---|
60 | # define _X_LIKELY(x) (x)
|
---|
61 | # define _X_UNLIKELY(x) (x)
|
---|
62 | # ifndef offsetof
|
---|
63 | # define offsetof(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
|
---|
64 | # endif
|
---|
65 | # if !defined(_INT8_T_DECLARED) && !defined(_INT8_T) && !defined(__INT8_TYPE__) && !defined(INT8_MAX)
|
---|
66 | typedef signed char int8_t;
|
---|
67 | # endif
|
---|
68 | # if !defined(_UINT8_T_DECLARED) && !defined(_UINT8_T) && !defined(__UINT8_TYPE__) && !defined(UINT8_MAX)
|
---|
69 | typedef unsigned char uint8_t;
|
---|
70 | # endif
|
---|
71 | # if !defined(_INT16_T_DECLARED) && !defined(_INT16_T) && !defined(__INT16_TYPE__) && !defined(INT16_MAX)
|
---|
72 | typedef signed short int16_t;
|
---|
73 | # endif
|
---|
74 | # if !defined(_UINT16_T_DECLARED) && !defined(_UINT16_T) && !defined(__UINT16_TYPE__) && !defined(UINT16_MAX)
|
---|
75 | typedef unsigned short uint16_t;
|
---|
76 | # endif
|
---|
77 | # if !defined(_INT32_T_DECLARED) && !defined(_INT32_T) && !defined(__INT32_TYPE__) && !defined(INT32_MAX)
|
---|
78 | typedef signed int int32_t;
|
---|
79 | # endif
|
---|
80 | # if !defined(_UINT32_T_DECLARED) && !defined(_UINT32_T) && !defined(__UINT32_TYPE__) && !defined(UINT32_MAX)
|
---|
81 | typedef unsigned int uint32_t;
|
---|
82 | # endif
|
---|
83 | # if !defined(_INT64_T_DECLARED) && !defined(_INT64_T) && !defined(__INT64_TYPE__) && !defined(INT64_MAX)
|
---|
84 | typedef signed long long int64_t;
|
---|
85 | # endif
|
---|
86 | # if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T) && !defined(__UINT64_TYPE__) && !defined(UINT64_MAX)
|
---|
87 | typedef unsigned long long uint64_t;
|
---|
88 | # endif
|
---|
89 | # ifndef _XSERVER64
|
---|
90 | # if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T) && !defined(__INTPTR_TYPE__) && !defined(INTPTR_MAX)
|
---|
91 | typedef signed long intptr_t;
|
---|
92 | # endif
|
---|
93 | # if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T) && !defined(__UINTPTR_TYPE__) && !defined(UINTPTR_MAX)
|
---|
94 | typedef unsigned long uintptr_t;
|
---|
95 | # endif
|
---|
96 | # else
|
---|
97 | # if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T) && !defined(__INTPTR_TYPE__) && !defined(INTPTR_MAX)
|
---|
98 | typedef int64_t intptr_t;
|
---|
99 | # endif
|
---|
100 | # if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T) && !defined(__UINTPTR_TYPE__) && !defined(UINTPTR_MAX)
|
---|
101 | typedef uint64_t uintptr_t;
|
---|
102 | # endif
|
---|
103 | # endif
|
---|
104 | #else /* !(defined(IN_XF86_MODULE) && !defined(NO_ANSIC)) */
|
---|
105 | # include <stdarg.h>
|
---|
106 | # include <stddef.h>
|
---|
107 | # include <stdint.h>
|
---|
108 | # include <string.h>
|
---|
109 | #endif /* !(defined(IN_XF86_MODULE) && !defined(NO_ANSIC)) */
|
---|
110 |
|
---|
111 | RT_C_DECLS_BEGIN
|
---|
112 | extern int RTASSERTVAR[1];
|
---|
113 | RT_C_DECLS_END
|
---|
114 |
|
---|
115 | #define AssertCompile(expr) \
|
---|
116 | extern int RTASSERTVAR[1] __attribute__((__unused__)), \
|
---|
117 | RTASSERTVAR[(expr) ? 1 : 0] __attribute__((__unused__))
|
---|
118 | #define AssertCompileSize(type, size) \
|
---|
119 | AssertCompile(sizeof(type) == (size))
|
---|
120 | #define AssertPtrNullReturnVoid(a) do { } while(0)
|
---|
121 |
|
---|
122 | #if !defined(IN_XF86_MODULE) && defined(DEBUG)
|
---|
123 | # include <assert.h>
|
---|
124 | # define Assert assert
|
---|
125 | # define AssertFailed() assert(0)
|
---|
126 | # define AssertMsg(expr, msg) \
|
---|
127 | do { \
|
---|
128 | if (!(expr)) xf86ErrorF msg; \
|
---|
129 | assert((expr)); \
|
---|
130 | } while (0)
|
---|
131 | # define AssertPtr assert
|
---|
132 | # define AssertRC(expr) assert (!expr)
|
---|
133 | #else
|
---|
134 | # define Assert(expr) do { } while(0)
|
---|
135 | # define AssertFailed() do { } while(0)
|
---|
136 | # define AssertMsg(expr, msg) do { } while(0)
|
---|
137 | # define AssertPtr(expr) do { } while(0)
|
---|
138 | # define AssertRC(expr) do { } while(0)
|
---|
139 | #endif
|
---|
140 |
|
---|
141 | #define DECLCALLBACK(type) type
|
---|
142 | #define DECLCALLBACKMEMBER(type, name) type (* name)
|
---|
143 | #if __GNUC__ >= 4
|
---|
144 | # define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type
|
---|
145 | #else
|
---|
146 | # define DECLHIDDEN(type) type
|
---|
147 | #endif
|
---|
148 | #define DECLINLINE(type) static __inline__ type
|
---|
149 |
|
---|
150 | #define _1K 1024
|
---|
151 | #define ASMCompilerBarrier mem_barrier
|
---|
152 | #define RT_BIT(bit) ( 1U << (bit) )
|
---|
153 | #define RT_BOOL(Value) ( !!(Value) )
|
---|
154 | #define RT_BZERO(pv, cb) do { memset((pv), 0, cb); } while (0)
|
---|
155 | #define RT_CLAMP(Value, Min, Max) ( (Value) > (Max) ? (Max) : (Value) < (Min) ? (Min) : (Value) )
|
---|
156 | #define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
|
---|
157 | #define RTIOPORT unsigned short
|
---|
158 | #define RT_NOREF(...) (void)(__VA_ARGS__)
|
---|
159 | #define RT_OFFSETOF(type, member) offsetof(type, member)
|
---|
160 | #define RT_ZERO(Obj) RT_BZERO(&(Obj), sizeof(Obj))
|
---|
161 | #define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
|
---|
162 | #ifndef INT16_C
|
---|
163 | # define INT16_C(Value) (Value)
|
---|
164 | #endif
|
---|
165 | #ifndef UINT16_C
|
---|
166 | # define UINT16_C(Value) (Value)
|
---|
167 | #endif
|
---|
168 | #ifndef INT32_C
|
---|
169 | # define INT32_C(Value) (Value ## U)
|
---|
170 | #endif
|
---|
171 | #ifndef UINT32_C
|
---|
172 | # define UINT32_C(Value) (Value ## U)
|
---|
173 | #endif
|
---|
174 | #ifndef INT16_MAX
|
---|
175 | # define INT16_MAX INT16_C(0x7fff)
|
---|
176 | #endif
|
---|
177 | #ifndef UINT16_MAX
|
---|
178 | # define UINT16_MAX UINT16_C(0xffff)
|
---|
179 | #endif
|
---|
180 | #ifndef INT32_MAX
|
---|
181 | # define INT32_MAX INT32_C(0x7fffffff)
|
---|
182 | #endif
|
---|
183 | #ifndef UINT32_MAX
|
---|
184 | # define UINT32_MAX UINT32_C(0xffffffff)
|
---|
185 | #endif
|
---|
186 |
|
---|
187 | #define likely _X_LIKELY
|
---|
188 | #define unlikely _X_UNLIKELY
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * A point in a two dimentional coordinate system.
|
---|
192 | */
|
---|
193 | typedef struct RTPOINT
|
---|
194 | {
|
---|
195 | /** X coordinate. */
|
---|
196 | int32_t x;
|
---|
197 | /** Y coordinate. */
|
---|
198 | int32_t y;
|
---|
199 | } RTPOINT;
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * Rectangle data type, double point.
|
---|
203 | */
|
---|
204 | typedef struct RTRECT
|
---|
205 | {
|
---|
206 | /** left X coordinate. */
|
---|
207 | int32_t xLeft;
|
---|
208 | /** top Y coordinate. */
|
---|
209 | int32_t yTop;
|
---|
210 | /** right X coordinate. (exclusive) */
|
---|
211 | int32_t xRight;
|
---|
212 | /** bottom Y coordinate. (exclusive) */
|
---|
213 | int32_t yBottom;
|
---|
214 | } RTRECT;
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * Rectangle data type, point + size.
|
---|
218 | */
|
---|
219 | typedef struct RTRECT2
|
---|
220 | {
|
---|
221 | /** X coordinate.
|
---|
222 | * Unless stated otherwise, this is the top left corner. */
|
---|
223 | int32_t x;
|
---|
224 | /** Y coordinate.
|
---|
225 | * Unless stated otherwise, this is the top left corner. */
|
---|
226 | int32_t y;
|
---|
227 | /** The width.
|
---|
228 | * Unless stated otherwise, this is to the right of (x,y) and will not
|
---|
229 | * be a negative number. */
|
---|
230 | int32_t cx;
|
---|
231 | /** The height.
|
---|
232 | * Unless stated otherwise, this is down from (x,y) and will not be a
|
---|
233 | * negative number. */
|
---|
234 | int32_t cy;
|
---|
235 | } RTRECT2;
|
---|
236 |
|
---|
237 | /**
|
---|
238 | * The size of a rectangle.
|
---|
239 | */
|
---|
240 | typedef struct RTRECTSIZE
|
---|
241 | {
|
---|
242 | /** The width (along the x-axis). */
|
---|
243 | uint32_t cx;
|
---|
244 | /** The height (along the y-axis). */
|
---|
245 | uint32_t cy;
|
---|
246 | } RTRECTSIZE;
|
---|
247 |
|
---|
248 | /** @name Port I/O helpers
|
---|
249 | * @{ */
|
---|
250 |
|
---|
251 | /** Write an 8-bit value to an I/O port. */
|
---|
252 | #define VBVO_PORT_WRITE_U8(Port, Value) \
|
---|
253 | outb(Port, Value)
|
---|
254 | /** Write a 16-bit value to an I/O port. */
|
---|
255 | #define VBVO_PORT_WRITE_U16(Port, Value) \
|
---|
256 | outw(Port, Value)
|
---|
257 | /** Write a 32-bit value to an I/O port. */
|
---|
258 | #define VBVO_PORT_WRITE_U32(Port, Value) \
|
---|
259 | outl(Port, Value)
|
---|
260 | /** Read an 8-bit value from an I/O port. */
|
---|
261 | #define VBVO_PORT_READ_U8(Port) \
|
---|
262 | inb(Port)
|
---|
263 | /** Read a 16-bit value from an I/O port. */
|
---|
264 | #define VBVO_PORT_READ_U16(Port) \
|
---|
265 | inw(Port)
|
---|
266 | /** Read a 32-bit value from an I/O port. */
|
---|
267 | #define VBVO_PORT_READ_U32(Port) \
|
---|
268 | inl(Port)
|
---|
269 |
|
---|
270 | /** @} */
|
---|
271 |
|
---|
272 | #endif
|
---|