[KMS/DRM] Bugfix for #5489: Non-FULLSCREEN windows incorrecty use videomode changing to look fullscreen.
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
25 * Functions for reading and writing endian-specific values
31 #include "SDL_stdinc.h"
38 * \name The two types of endianness
41 #define SDL_LIL_ENDIAN 1234
42 #define SDL_BIG_ENDIAN 4321
45 #ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */
48 #define SDL_BYTEORDER __BYTE_ORDER
49 #elif defined(__OpenBSD__)
51 #define SDL_BYTEORDER BYTE_ORDER
52 #elif defined(__FreeBSD__)
53 #include <sys/endian.h>
54 #define SDL_BYTEORDER BYTE_ORDER
56 #if defined(__hppa__) || \
57 defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
58 (defined(__MIPS__) && defined(__MIPSEB__)) || \
59 defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
61 #define SDL_BYTEORDER SDL_BIG_ENDIAN
63 #define SDL_BYTEORDER SDL_LIL_ENDIAN
65 #endif /* __linux__ */
66 #endif /* !SDL_BYTEORDER */
69 #include "begin_code.h"
70 /* Set up for C function definitions, even when using C++ */
78 #if (defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 2))) || \
79 (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))
80 #define SDL_Swap16(x) __builtin_bswap16(x)
81 #elif defined(__GNUC__) && defined(__i386__) && \
82 !(__GNUC__ == 2 && __GNUC_MINOR__ <= 95 /* broken gcc version */)
83 SDL_FORCE_INLINE Uint16
86 __asm__("xchgb %b0,%h0": "=q"(x):"0"(x));
89 #elif defined(__GNUC__) && defined(__x86_64__)
90 SDL_FORCE_INLINE Uint16
93 __asm__("xchgb %b0,%h0": "=Q"(x):"0"(x));
96 #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
97 SDL_FORCE_INLINE Uint16
102 __asm__("rlwimi %0,%2,8,16,23": "=&r"(result):"0"(x >> 8), "r"(x));
103 return (Uint16)result;
105 #elif defined(__GNUC__) && defined(__aarch64__)
106 SDL_FORCE_INLINE Uint16
109 __asm__("rev16 %w1, %w0" : "=r"(x) : "r"(x));
112 #elif defined(__GNUC__) && (defined(__m68k__) && !defined(__mcoldfire__))
113 SDL_FORCE_INLINE Uint16
116 __asm__("rorw #8,%0": "=d"(x): "0"(x):"cc");
119 #elif defined(_MSC_VER)
120 #pragma intrinsic(_byteswap_ushort)
121 #define SDL_Swap16(x) _byteswap_ushort(x)
122 #elif defined(__WATCOMC__) && defined(__386__)
123 extern _inline Uint16 SDL_Swap16(Uint16);
124 #pragma aux SDL_Swap16 = \
129 SDL_FORCE_INLINE Uint16
132 return SDL_static_cast(Uint16, ((x << 8) | (x >> 8)));
136 #if (defined(__clang__) && (__clang_major__ > 2 || (__clang_major__ == 2 && __clang_minor__ >= 6))) || \
137 (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
138 #define SDL_Swap32(x) __builtin_bswap32(x)
139 #elif defined(__GNUC__) && defined(__i386__) && \
140 !(__GNUC__ == 2 && __GNUC_MINOR__ <= 95 /* broken gcc version */)
141 SDL_FORCE_INLINE Uint32
144 __asm__("bswap %0": "=r"(x):"0"(x));
147 #elif defined(__GNUC__) && defined(__x86_64__)
148 SDL_FORCE_INLINE Uint32
151 __asm__("bswapl %0": "=r"(x):"0"(x));
154 #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
155 SDL_FORCE_INLINE Uint32
160 __asm__("rlwimi %0,%2,24,16,23": "=&r"(result):"0"(x >> 24), "r"(x));
161 __asm__("rlwimi %0,%2,8,8,15": "=&r"(result):"0"(result), "r"(x));
162 __asm__("rlwimi %0,%2,24,0,7": "=&r"(result):"0"(result), "r"(x));
165 #elif defined(__GNUC__) && defined(__aarch64__)
166 SDL_FORCE_INLINE Uint32
169 __asm__("rev %w1, %w0": "=r"(x):"r"(x));
172 #elif defined(__GNUC__) && (defined(__m68k__) && !defined(__mcoldfire__))
173 SDL_FORCE_INLINE Uint32
176 __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0": "=d"(x): "0"(x):"cc");
179 #elif defined(__WATCOMC__) && defined(__386__)
180 extern _inline Uint32 SDL_Swap32(Uint32);
181 #ifndef __SW_3 /* 486+ */
182 #pragma aux SDL_Swap32 = \
187 #pragma aux SDL_Swap32 = \
194 #elif defined(_MSC_VER)
195 #pragma intrinsic(_byteswap_ulong)
196 #define SDL_Swap32(x) _byteswap_ulong(x)
198 SDL_FORCE_INLINE Uint32
201 return SDL_static_cast(Uint32, ((x << 24) | ((x << 8) & 0x00FF0000) |
202 ((x >> 8) & 0x0000FF00) | (x >> 24)));
206 #if (defined(__clang__) && (__clang_major__ > 2 || (__clang_major__ == 2 && __clang_minor__ >= 6))) || \
207 (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
208 #define SDL_Swap64(x) __builtin_bswap64(x)
209 #elif defined(__GNUC__) && defined(__i386__) && \
210 !(__GNUC__ == 2 && __GNUC_MINOR__ <= 95 /* broken gcc version */)
211 SDL_FORCE_INLINE Uint64
223 __asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1": "=r"(v.s.a), "=r"(v.s.b):"0"(v.s.a),
228 #elif defined(__GNUC__) && defined(__x86_64__)
229 SDL_FORCE_INLINE Uint64
232 __asm__("bswapq %0": "=r"(x):"0"(x));
235 #elif defined(_MSC_VER)
236 #pragma intrinsic(_byteswap_uint64)
237 #define SDL_Swap64(x) _byteswap_uint64(x)
239 SDL_FORCE_INLINE Uint64
244 /* Separate into high and low 32-bit values and swap them */
245 lo = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
247 hi = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
256 SDL_FORCE_INLINE float
257 SDL_SwapFloat(float x)
265 swapper.ui32 = SDL_Swap32(swapper.ui32);
271 * \name Swap to native
272 * Byteswap item from the specified endianness to the native endianness.
275 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
276 #define SDL_SwapLE16(X) (X)
277 #define SDL_SwapLE32(X) (X)
278 #define SDL_SwapLE64(X) (X)
279 #define SDL_SwapFloatLE(X) (X)
280 #define SDL_SwapBE16(X) SDL_Swap16(X)
281 #define SDL_SwapBE32(X) SDL_Swap32(X)
282 #define SDL_SwapBE64(X) SDL_Swap64(X)
283 #define SDL_SwapFloatBE(X) SDL_SwapFloat(X)
285 #define SDL_SwapLE16(X) SDL_Swap16(X)
286 #define SDL_SwapLE32(X) SDL_Swap32(X)
287 #define SDL_SwapLE64(X) SDL_Swap64(X)
288 #define SDL_SwapFloatLE(X) SDL_SwapFloat(X)
289 #define SDL_SwapBE16(X) (X)
290 #define SDL_SwapBE32(X) (X)
291 #define SDL_SwapBE64(X) (X)
292 #define SDL_SwapFloatBE(X) (X)
294 /* @} *//* Swap to native */
296 /* Ends C function definitions when using C++ */
300 #include "close_code.h"
302 #endif /* SDL_endian_h_ */
304 /* vi: set ts=4 sw=4 expandtab: */