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