1 | /* $Id: VBoxVideoIPRT.h 90794 2021-08-23 13:16:11Z 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(a_RetType) a_RetType
|
---|
112 | #define DECLCALLBACKTYPE(a_RetType, a_Name, a_Args) a_RetType a_Name a_Args
|
---|
113 | #define DECLCALLBACKMEMBER(a_RetType, a_Name, a_Args) a_RetType (*a_Name) a_Args
|
---|
114 | #if __GNUC__ >= 4
|
---|
115 | # define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type
|
---|
116 | #else
|
---|
117 | # define DECLHIDDEN(type) type
|
---|
118 | #endif
|
---|
119 | #define DECLINLINE(type) static __inline__ type
|
---|
120 |
|
---|
121 | #define _1K 1024
|
---|
122 | #define ASMCompilerBarrier mem_barrier
|
---|
123 | #define RT_BIT(bit) ( 1U << (bit) )
|
---|
124 | #define RT_BOOL(Value) ( !!(Value) )
|
---|
125 | #define RT_BZERO(pv, cb) do { memset((pv), 0, cb); } while (0)
|
---|
126 | #define RT_CLAMP(Value, Min, Max) ( (Value) > (Max) ? (Max) : (Value) < (Min) ? (Min) : (Value) )
|
---|
127 | #define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
|
---|
128 | #define RTIOPORT unsigned short
|
---|
129 | #define RT_NOREF(...) (void)(__VA_ARGS__)
|
---|
130 | #define RT_OFFSETOF(type, member) offsetof(type, member)
|
---|
131 | #define RT_UOFFSETOF(type, member) offsetof(type, member)
|
---|
132 | #define RT_ZERO(Obj) RT_BZERO(&(Obj), sizeof(Obj))
|
---|
133 | #define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
|
---|
134 | #define VALID_PTR(ptr) RT_VALID_PTR(ptr)
|
---|
135 | #ifndef INT16_C
|
---|
136 | # define INT16_C(Value) (Value)
|
---|
137 | #endif
|
---|
138 | #ifndef UINT16_C
|
---|
139 | # define UINT16_C(Value) (Value)
|
---|
140 | #endif
|
---|
141 | #ifndef INT32_C
|
---|
142 | # define INT32_C(Value) (Value ## U)
|
---|
143 | #endif
|
---|
144 | #ifndef UINT32_C
|
---|
145 | # define UINT32_C(Value) (Value ## U)
|
---|
146 | #endif
|
---|
147 | #define RT_UNTRUSTED_GUEST
|
---|
148 | #define RT_UNTRUSTED_VOLATILE_GUEST volatile
|
---|
149 | #define RT_UNTRUSTED_HOST
|
---|
150 | #define RT_UNTRUSTED_VOLATILE_HOST volatile
|
---|
151 | #define RT_UNTRUSTED_HSTGST
|
---|
152 | #define RT_UNTRUSTED_VOLATILE_HSTGST volatile
|
---|
153 |
|
---|
154 | #define likely _X_LIKELY
|
---|
155 | #define unlikely _X_UNLIKELY
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * A point in a two dimentional coordinate system.
|
---|
159 | */
|
---|
160 | typedef struct RTPOINT
|
---|
161 | {
|
---|
162 | /** X coordinate. */
|
---|
163 | int32_t x;
|
---|
164 | /** Y coordinate. */
|
---|
165 | int32_t y;
|
---|
166 | } RTPOINT;
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Rectangle data type, double point.
|
---|
170 | */
|
---|
171 | typedef struct RTRECT
|
---|
172 | {
|
---|
173 | /** left X coordinate. */
|
---|
174 | int32_t xLeft;
|
---|
175 | /** top Y coordinate. */
|
---|
176 | int32_t yTop;
|
---|
177 | /** right X coordinate. (exclusive) */
|
---|
178 | int32_t xRight;
|
---|
179 | /** bottom Y coordinate. (exclusive) */
|
---|
180 | int32_t yBottom;
|
---|
181 | } RTRECT;
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * Rectangle data type, point + size.
|
---|
185 | */
|
---|
186 | typedef struct RTRECT2
|
---|
187 | {
|
---|
188 | /** X coordinate.
|
---|
189 | * Unless stated otherwise, this is the top left corner. */
|
---|
190 | int32_t x;
|
---|
191 | /** Y coordinate.
|
---|
192 | * Unless stated otherwise, this is the top left corner. */
|
---|
193 | int32_t y;
|
---|
194 | /** The width.
|
---|
195 | * Unless stated otherwise, this is to the right of (x,y) and will not
|
---|
196 | * be a negative number. */
|
---|
197 | int32_t cx;
|
---|
198 | /** The height.
|
---|
199 | * Unless stated otherwise, this is down from (x,y) and will not be a
|
---|
200 | * negative number. */
|
---|
201 | int32_t cy;
|
---|
202 | } RTRECT2;
|
---|
203 |
|
---|
204 | /**
|
---|
205 | * The size of a rectangle.
|
---|
206 | */
|
---|
207 | typedef struct RTRECTSIZE
|
---|
208 | {
|
---|
209 | /** The width (along the x-axis). */
|
---|
210 | uint32_t cx;
|
---|
211 | /** The height (along the y-axis). */
|
---|
212 | uint32_t cy;
|
---|
213 | } RTRECTSIZE;
|
---|
214 |
|
---|
215 | /** @name Port I/O helpers
|
---|
216 | * @{ */
|
---|
217 |
|
---|
218 | /** Write an 8-bit value to an I/O port. */
|
---|
219 | #define VBVO_PORT_WRITE_U8(Port, Value) \
|
---|
220 | outb(Port, Value)
|
---|
221 | /** Write a 16-bit value to an I/O port. */
|
---|
222 | #define VBVO_PORT_WRITE_U16(Port, Value) \
|
---|
223 | outw(Port, Value)
|
---|
224 | /** Write a 32-bit value to an I/O port. */
|
---|
225 | #define VBVO_PORT_WRITE_U32(Port, Value) \
|
---|
226 | outl(Port, Value)
|
---|
227 | /** Read an 8-bit value from an I/O port. */
|
---|
228 | #define VBVO_PORT_READ_U8(Port) \
|
---|
229 | inb(Port)
|
---|
230 | /** Read a 16-bit value from an I/O port. */
|
---|
231 | #define VBVO_PORT_READ_U16(Port) \
|
---|
232 | inw(Port)
|
---|
233 | /** Read a 32-bit value from an I/O port. */
|
---|
234 | #define VBVO_PORT_READ_U32(Port) \
|
---|
235 | inl(Port)
|
---|
236 |
|
---|
237 | /** @} */
|
---|
238 |
|
---|
239 | #endif /* !VBOX_INCLUDED_Graphics_VBoxVideoIPRT_h */
|
---|