Updates the SDL library to the latest standard bugfix release

This commit is contained in:
JeffR 2023-07-13 15:20:29 -05:00
parent cb766f2878
commit 083d2175ea
1280 changed files with 343926 additions and 179615 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,8 +26,8 @@
/* Useful functions and variables from SDL_RLEaccel.c */
extern int SDL_RLESurface(SDL_Surface * surface);
extern void SDL_UnRLESurface(SDL_Surface * surface, int recode);
extern int SDL_RLESurface(SDL_Surface *surface);
extern void SDL_UnRLESurface(SDL_Surface *surface, int recode);
#endif /* SDL_RLEaccel_c_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -30,9 +30,8 @@
#include "SDL_pixels_c.h"
/* The general purpose software blit routine */
static int SDLCALL
SDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect)
static int SDLCALL SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect)
{
int okay;
int src_locked;
@ -66,23 +65,23 @@ SDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect,
SDL_BlitInfo *info = &src->map->info;
/* Set up the blit information */
info->src = (Uint8 *) src->pixels +
(Uint16) srcrect->y * src->pitch +
(Uint16) srcrect->x * info->src_fmt->BytesPerPixel;
info->src = (Uint8 *)src->pixels +
(Uint16)srcrect->y * src->pitch +
(Uint16)srcrect->x * info->src_fmt->BytesPerPixel;
info->src_w = srcrect->w;
info->src_h = srcrect->h;
info->src_pitch = src->pitch;
info->src_skip =
info->src_pitch - info->src_w * info->src_fmt->BytesPerPixel;
info->dst =
(Uint8 *) dst->pixels + (Uint16) dstrect->y * dst->pitch +
(Uint16) dstrect->x * info->dst_fmt->BytesPerPixel;
(Uint8 *)dst->pixels + (Uint16)dstrect->y * dst->pitch +
(Uint16)dstrect->x * info->dst_fmt->BytesPerPixel;
info->dst_w = dstrect->w;
info->dst_h = dstrect->h;
info->dst_pitch = dst->pitch;
info->dst_skip =
info->dst_pitch - info->dst_w * info->dst_fmt->BytesPerPixel;
RunBlit = (SDL_BlitFunc) src->map->data;
RunBlit = (SDL_BlitFunc)src->map->data;
/* Run the actual software blit */
RunBlit(info);
@ -96,7 +95,7 @@ SDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect,
SDL_UnlockSurface(src);
}
/* Blit is done! */
return (okay ? 0 : -1);
return okay ? 0 : -1;
}
#if SDL_HAVE_BLIT_AUTO
@ -104,8 +103,7 @@ SDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect,
#ifdef __MACOSX__
#include <sys/sysctl.h>
static SDL_bool
SDL_UseAltivecPrefetch()
static SDL_bool SDL_UseAltivecPrefetch()
{
const char key[] = "hw.l3cachesize";
u_int64_t result = 0;
@ -118,17 +116,15 @@ SDL_UseAltivecPrefetch()
}
}
#else
static SDL_bool
SDL_UseAltivecPrefetch()
static SDL_bool SDL_UseAltivecPrefetch()
{
/* Just guess G4 */
return SDL_TRUE;
}
#endif /* __MACOSX__ */
static SDL_BlitFunc
SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags,
SDL_BlitFuncEntry * entries)
static SDL_BlitFunc SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags,
SDL_BlitFuncEntry *entries)
{
int i, flagcheck = (flags & (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL | SDL_COPY_COLORKEY | SDL_COPY_NEAREST));
static int features = 0x7fffffff;
@ -141,7 +137,7 @@ SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags,
/* Allow an override for testing .. */
if (override) {
SDL_sscanf(override, "%u", &features);
(void)SDL_sscanf(override, "%u", &features);
} else {
if (SDL_HasMMX()) {
features |= SDL_CPU_MMX;
@ -192,8 +188,7 @@ SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags,
#endif /* SDL_HAVE_BLIT_AUTO */
/* Figure out which of many blit routines to set up on a surface */
int
SDL_CalculateBlit(SDL_Surface * surface)
int SDL_CalculateBlit(SDL_Surface *surface)
{
SDL_BlitFunc blit = NULL;
SDL_BlitMap *map = surface->map;
@ -235,13 +230,13 @@ SDL_CalculateBlit(SDL_Surface * surface)
}
#if SDL_HAVE_BLIT_0
else if (surface->format->BitsPerPixel < 8 &&
SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
blit = SDL_CalculateBlit0(surface);
}
#endif
#if SDL_HAVE_BLIT_1
else if (surface->format->BytesPerPixel == 1 &&
SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
blit = SDL_CalculateBlit1(surface);
}
#endif

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -28,36 +28,36 @@
#include "SDL_surface.h"
/* pixman ARM blitters are 32 bit only : */
#if defined(__aarch64__)||defined(_M_ARM64)
#if defined(__aarch64__) || defined(_M_ARM64)
#undef SDL_ARM_SIMD_BLITTERS
#undef SDL_ARM_NEON_BLITTERS
#endif
/* Table to do pixel byte expansion */
extern Uint8* SDL_expand_byte[9];
extern Uint8 *SDL_expand_byte[9];
/* SDL blit copy flags */
#define SDL_COPY_MODULATE_COLOR 0x00000001
#define SDL_COPY_MODULATE_ALPHA 0x00000002
#define SDL_COPY_BLEND 0x00000010
#define SDL_COPY_ADD 0x00000020
#define SDL_COPY_MOD 0x00000040
#define SDL_COPY_MUL 0x00000080
#define SDL_COPY_COLORKEY 0x00000100
#define SDL_COPY_NEAREST 0x00000200
#define SDL_COPY_RLE_DESIRED 0x00001000
#define SDL_COPY_RLE_COLORKEY 0x00002000
#define SDL_COPY_RLE_ALPHAKEY 0x00004000
#define SDL_COPY_RLE_MASK (SDL_COPY_RLE_DESIRED|SDL_COPY_RLE_COLORKEY|SDL_COPY_RLE_ALPHAKEY)
#define SDL_COPY_MODULATE_COLOR 0x00000001
#define SDL_COPY_MODULATE_ALPHA 0x00000002
#define SDL_COPY_BLEND 0x00000010
#define SDL_COPY_ADD 0x00000020
#define SDL_COPY_MOD 0x00000040
#define SDL_COPY_MUL 0x00000080
#define SDL_COPY_COLORKEY 0x00000100
#define SDL_COPY_NEAREST 0x00000200
#define SDL_COPY_RLE_DESIRED 0x00001000
#define SDL_COPY_RLE_COLORKEY 0x00002000
#define SDL_COPY_RLE_ALPHAKEY 0x00004000
#define SDL_COPY_RLE_MASK (SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY | SDL_COPY_RLE_ALPHAKEY)
/* SDL blit CPU flags */
#define SDL_CPU_ANY 0x00000000
#define SDL_CPU_MMX 0x00000001
#define SDL_CPU_3DNOW 0x00000002
#define SDL_CPU_SSE 0x00000004
#define SDL_CPU_SSE2 0x00000008
#define SDL_CPU_ALTIVEC_PREFETCH 0x00000010
#define SDL_CPU_ALTIVEC_NOPREFETCH 0x00000020
#define SDL_CPU_ANY 0x00000000
#define SDL_CPU_MMX 0x00000001
#define SDL_CPU_3DNOW 0x00000002
#define SDL_CPU_SSE 0x00000004
#define SDL_CPU_SSE2 0x00000008
#define SDL_CPU_ALTIVEC_PREFETCH 0x00000010
#define SDL_CPU_ALTIVEC_NOPREFETCH 0x00000020
typedef struct
{
@ -77,8 +77,7 @@ typedef struct
Uint8 r, g, b, a;
} SDL_BlitInfo;
typedef void (*SDL_BlitFunc) (SDL_BlitInfo *info);
typedef void (*SDL_BlitFunc)(SDL_BlitInfo *info);
typedef struct
{
@ -90,7 +89,8 @@ typedef struct
} SDL_BlitFuncEntry;
/* Blit mapping definition */
typedef struct SDL_BlitMap
/* typedef'ed in SDL_surface.h */
struct SDL_BlitMap
{
SDL_Surface *dst;
int identity;
@ -102,370 +102,368 @@ typedef struct SDL_BlitMap
an invalid mapping */
Uint32 dst_palette_version;
Uint32 src_palette_version;
} SDL_BlitMap;
};
/* Functions found in SDL_blit.c */
extern int SDL_CalculateBlit(SDL_Surface * surface);
extern int SDL_CalculateBlit(SDL_Surface *surface);
/* Functions found in SDL_blit_*.c */
extern SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface * surface);
extern SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface * surface);
extern SDL_BlitFunc SDL_CalculateBlitN(SDL_Surface * surface);
extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface * surface);
extern SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface);
extern SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface *surface);
extern SDL_BlitFunc SDL_CalculateBlitN(SDL_Surface *surface);
extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
/*
* Useful macros for blitting routines
*/
#if defined(__GNUC__)
#define DECLARE_ALIGNED(t,v,a) t __attribute__((aligned(a))) v
#define DECLARE_ALIGNED(t, v, a) t __attribute__((aligned(a))) v
#elif defined(_MSC_VER)
#define DECLARE_ALIGNED(t,v,a) __declspec(align(a)) t v
#define DECLARE_ALIGNED(t, v, a) __declspec(align(a)) t v
#else
#define DECLARE_ALIGNED(t,v,a) t v
#define DECLARE_ALIGNED(t, v, a) t v
#endif
/* Load pixel of the specified format from a buffer and get its R-G-B values */
#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b) \
{ \
r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
}
#define RGB_FROM_RGB565(Pixel, r, g, b) \
{ \
r = SDL_expand_byte[3][((Pixel&0xF800)>>11)]; \
g = SDL_expand_byte[2][((Pixel&0x07E0)>>5)]; \
b = SDL_expand_byte[3][(Pixel&0x001F)]; \
}
#define RGB_FROM_RGB555(Pixel, r, g, b) \
{ \
r = SDL_expand_byte[3][((Pixel&0x7C00)>>10)]; \
g = SDL_expand_byte[3][((Pixel&0x03E0)>>5)]; \
b = SDL_expand_byte[3][(Pixel&0x001F)]; \
}
#define RGB_FROM_RGB888(Pixel, r, g, b) \
{ \
r = ((Pixel&0xFF0000)>>16); \
g = ((Pixel&0xFF00)>>8); \
b = (Pixel&0xFF); \
}
#define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel) \
do { \
switch (bpp) { \
case 1: \
Pixel = *((Uint8 *)(buf)); \
break; \
\
case 2: \
Pixel = *((Uint16 *)(buf)); \
break; \
\
case 3: { \
Uint8 *B = (Uint8 *)(buf); \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
Pixel = B[0] + (B[1] << 8) + (B[2] << 16); \
} else { \
Pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \
} \
} \
break; \
\
case 4: \
Pixel = *((Uint32 *)(buf)); \
break; \
\
default: \
Pixel = 0; /* stop gcc complaints */ \
break; \
} \
} while (0)
#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b) \
{ \
r = SDL_expand_byte[fmt->Rloss][((Pixel & fmt->Rmask) >> fmt->Rshift)]; \
g = SDL_expand_byte[fmt->Gloss][((Pixel & fmt->Gmask) >> fmt->Gshift)]; \
b = SDL_expand_byte[fmt->Bloss][((Pixel & fmt->Bmask) >> fmt->Bshift)]; \
}
#define RGB_FROM_RGB565(Pixel, r, g, b) \
{ \
r = SDL_expand_byte[3][((Pixel & 0xF800) >> 11)]; \
g = SDL_expand_byte[2][((Pixel & 0x07E0) >> 5)]; \
b = SDL_expand_byte[3][(Pixel & 0x001F)]; \
}
#define RGB_FROM_RGB555(Pixel, r, g, b) \
{ \
r = SDL_expand_byte[3][((Pixel & 0x7C00) >> 10)]; \
g = SDL_expand_byte[3][((Pixel & 0x03E0) >> 5)]; \
b = SDL_expand_byte[3][(Pixel & 0x001F)]; \
}
#define RGB_FROM_RGB888(Pixel, r, g, b) \
{ \
r = ((Pixel & 0xFF0000) >> 16); \
g = ((Pixel & 0xFF00) >> 8); \
b = (Pixel & 0xFF); \
}
#define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel) \
do { \
switch (bpp) { \
case 1: \
Pixel = *((Uint8 *)(buf)); \
break; \
\
case 2: \
Pixel = *((Uint16 *)(buf)); \
break; \
\
case 3: \
{ \
Uint8 *B = (Uint8 *)(buf); \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
Pixel = B[0] + (B[1] << 8) + (B[2] << 16); \
} else { \
Pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \
} \
} break; \
\
case 4: \
Pixel = *((Uint32 *)(buf)); \
break; \
\
default: \
Pixel = 0; /* stop gcc complaints */ \
break; \
} \
} while (0)
#define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b) \
do { \
switch (bpp) { \
case 1: \
Pixel = *((Uint8 *)(buf)); \
RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
break; \
\
case 2: \
Pixel = *((Uint16 *)(buf)); \
RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
break; \
\
case 3: { \
Pixel = 0; \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
r = *((buf)+fmt->Rshift/8); \
g = *((buf)+fmt->Gshift/8); \
b = *((buf)+fmt->Bshift/8); \
} else { \
r = *((buf)+2-fmt->Rshift/8); \
g = *((buf)+2-fmt->Gshift/8); \
b = *((buf)+2-fmt->Bshift/8); \
} \
} \
break; \
\
case 4: \
Pixel = *((Uint32 *)(buf)); \
RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
break; \
\
default: \
/* stop gcc complaints */ \
Pixel = 0; \
r = g = b = 0; \
break; \
} \
} while (0)
#define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b) \
do { \
switch (bpp) { \
case 1: \
Pixel = *((Uint8 *)(buf)); \
RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
break; \
\
case 2: \
Pixel = *((Uint16 *)(buf)); \
RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
break; \
\
case 3: \
{ \
Pixel = 0; \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
r = *((buf) + fmt->Rshift / 8); \
g = *((buf) + fmt->Gshift / 8); \
b = *((buf) + fmt->Bshift / 8); \
} else { \
r = *((buf) + 2 - fmt->Rshift / 8); \
g = *((buf) + 2 - fmt->Gshift / 8); \
b = *((buf) + 2 - fmt->Bshift / 8); \
} \
} break; \
\
case 4: \
Pixel = *((Uint32 *)(buf)); \
RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
break; \
\
default: \
/* stop gcc complaints */ \
Pixel = 0; \
r = g = b = 0; \
break; \
} \
} while (0)
/* Assemble R-G-B values into a specified pixel format and store them */
#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b) \
{ \
Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
((g>>fmt->Gloss)<<fmt->Gshift)| \
((b>>fmt->Bloss)<<fmt->Bshift)| \
fmt->Amask; \
}
#define RGB565_FROM_RGB(Pixel, r, g, b) \
{ \
Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3); \
}
#define RGB555_FROM_RGB(Pixel, r, g, b) \
{ \
Pixel = ((r>>3)<<10)|((g>>3)<<5)|(b>>3); \
}
#define RGB888_FROM_RGB(Pixel, r, g, b) \
{ \
Pixel = (r<<16)|(g<<8)|b; \
}
#define ARGB8888_FROM_RGBA(Pixel, r, g, b, a) \
{ \
Pixel = (a<<24)|(r<<16)|(g<<8)|b; \
}
#define RGBA8888_FROM_RGBA(Pixel, r, g, b, a) \
{ \
Pixel = (r<<24)|(g<<16)|(b<<8)|a; \
}
#define ABGR8888_FROM_RGBA(Pixel, r, g, b, a) \
{ \
Pixel = (a<<24)|(b<<16)|(g<<8)|r; \
}
#define BGRA8888_FROM_RGBA(Pixel, r, g, b, a) \
{ \
Pixel = (b<<24)|(g<<16)|(r<<8)|a; \
}
#define ARGB2101010_FROM_RGBA(Pixel, r, g, b, a) \
{ \
r = r ? ((r << 2) | 0x3) : 0; \
g = g ? ((g << 2) | 0x3) : 0; \
b = b ? ((b << 2) | 0x3) : 0; \
a = (a * 3) / 255; \
Pixel = (a<<30)|(r<<20)|(g<<10)|b; \
}
#define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b) \
{ \
switch (bpp) { \
case 1: { \
Uint8 _pixel; \
\
PIXEL_FROM_RGB(_pixel, fmt, r, g, b); \
*((Uint8 *)(buf)) = _pixel; \
} \
break; \
\
case 2: { \
Uint16 _pixel; \
\
PIXEL_FROM_RGB(_pixel, fmt, r, g, b); \
*((Uint16 *)(buf)) = _pixel; \
} \
break; \
\
case 3: { \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
*((buf)+fmt->Rshift/8) = r; \
*((buf)+fmt->Gshift/8) = g; \
*((buf)+fmt->Bshift/8) = b; \
} else { \
*((buf)+2-fmt->Rshift/8) = r; \
*((buf)+2-fmt->Gshift/8) = g; \
*((buf)+2-fmt->Bshift/8) = b; \
} \
} \
break; \
\
case 4: { \
Uint32 _pixel; \
\
PIXEL_FROM_RGB(_pixel, fmt, r, g, b); \
*((Uint32 *)(buf)) = _pixel; \
} \
break; \
} \
}
#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b) \
{ \
Pixel = ((r >> fmt->Rloss) << fmt->Rshift) | \
((g >> fmt->Gloss) << fmt->Gshift) | \
((b >> fmt->Bloss) << fmt->Bshift) | \
fmt->Amask; \
}
#define RGB565_FROM_RGB(Pixel, r, g, b) \
{ \
Pixel = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3); \
}
#define RGB555_FROM_RGB(Pixel, r, g, b) \
{ \
Pixel = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3); \
}
#define RGB888_FROM_RGB(Pixel, r, g, b) \
{ \
Pixel = (r << 16) | (g << 8) | b; \
}
#define ARGB8888_FROM_RGBA(Pixel, r, g, b, a) \
{ \
Pixel = (a << 24) | (r << 16) | (g << 8) | b; \
}
#define RGBA8888_FROM_RGBA(Pixel, r, g, b, a) \
{ \
Pixel = (r << 24) | (g << 16) | (b << 8) | a; \
}
#define ABGR8888_FROM_RGBA(Pixel, r, g, b, a) \
{ \
Pixel = (a << 24) | (b << 16) | (g << 8) | r; \
}
#define BGRA8888_FROM_RGBA(Pixel, r, g, b, a) \
{ \
Pixel = (b << 24) | (g << 16) | (r << 8) | a; \
}
#define ARGB2101010_FROM_RGBA(Pixel, r, g, b, a) \
{ \
r = r ? ((r << 2) | 0x3) : 0; \
g = g ? ((g << 2) | 0x3) : 0; \
b = b ? ((b << 2) | 0x3) : 0; \
a = (a * 3) / 255; \
Pixel = (a << 30) | (r << 20) | (g << 10) | b; \
}
#define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b) \
{ \
switch (bpp) { \
case 1: \
{ \
Uint8 _pixel; \
\
PIXEL_FROM_RGB(_pixel, fmt, r, g, b); \
*((Uint8 *)(buf)) = _pixel; \
} break; \
\
case 2: \
{ \
Uint16 _pixel; \
\
PIXEL_FROM_RGB(_pixel, fmt, r, g, b); \
*((Uint16 *)(buf)) = _pixel; \
} break; \
\
case 3: \
{ \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
*((buf) + fmt->Rshift / 8) = r; \
*((buf) + fmt->Gshift / 8) = g; \
*((buf) + fmt->Bshift / 8) = b; \
} else { \
*((buf) + 2 - fmt->Rshift / 8) = r; \
*((buf) + 2 - fmt->Gshift / 8) = g; \
*((buf) + 2 - fmt->Bshift / 8) = b; \
} \
} break; \
\
case 4: \
{ \
Uint32 _pixel; \
\
PIXEL_FROM_RGB(_pixel, fmt, r, g, b); \
*((Uint32 *)(buf)) = _pixel; \
} break; \
} \
}
/* FIXME: Should we rescale alpha into 0..255 here? */
#define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a) \
{ \
r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
a = SDL_expand_byte[fmt->Aloss][((Pixel&fmt->Amask)>>fmt->Ashift)]; \
}
#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a) \
{ \
r = (Pixel&fmt->Rmask)>>fmt->Rshift; \
g = (Pixel&fmt->Gmask)>>fmt->Gshift; \
b = (Pixel&fmt->Bmask)>>fmt->Bshift; \
a = (Pixel&fmt->Amask)>>fmt->Ashift; \
}
#define RGBA_FROM_RGBA8888(Pixel, r, g, b, a) \
{ \
r = (Pixel>>24); \
g = ((Pixel>>16)&0xFF); \
b = ((Pixel>>8)&0xFF); \
a = (Pixel&0xFF); \
}
#define RGBA_FROM_ARGB8888(Pixel, r, g, b, a) \
{ \
r = ((Pixel>>16)&0xFF); \
g = ((Pixel>>8)&0xFF); \
b = (Pixel&0xFF); \
a = (Pixel>>24); \
}
#define RGBA_FROM_ABGR8888(Pixel, r, g, b, a) \
{ \
r = (Pixel&0xFF); \
g = ((Pixel>>8)&0xFF); \
b = ((Pixel>>16)&0xFF); \
a = (Pixel>>24); \
}
#define RGBA_FROM_BGRA8888(Pixel, r, g, b, a) \
{ \
r = ((Pixel>>8)&0xFF); \
g = ((Pixel>>16)&0xFF); \
b = (Pixel>>24); \
a = (Pixel&0xFF); \
}
#define RGBA_FROM_ARGB2101010(Pixel, r, g, b, a) \
{ \
r = ((Pixel>>22)&0xFF); \
g = ((Pixel>>12)&0xFF); \
b = ((Pixel>>2)&0xFF); \
a = SDL_expand_byte[6][(Pixel>>30)]; \
}
#define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a) \
do { \
switch (bpp) { \
case 1: \
Pixel = *((Uint8 *)(buf)); \
RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
break; \
\
case 2: \
Pixel = *((Uint16 *)(buf)); \
RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
break; \
\
case 3: { \
Pixel = 0; \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
r = *((buf)+fmt->Rshift/8); \
g = *((buf)+fmt->Gshift/8); \
b = *((buf)+fmt->Bshift/8); \
} else { \
r = *((buf)+2-fmt->Rshift/8); \
g = *((buf)+2-fmt->Gshift/8); \
b = *((buf)+2-fmt->Bshift/8); \
} \
a = 0xFF; \
} \
break; \
\
case 4: \
Pixel = *((Uint32 *)(buf)); \
RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
break; \
\
default: \
/* stop gcc complaints */ \
Pixel = 0; \
r = g = b = a = 0; \
break; \
} \
} while (0)
#define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a) \
{ \
r = SDL_expand_byte[fmt->Rloss][((Pixel & fmt->Rmask) >> fmt->Rshift)]; \
g = SDL_expand_byte[fmt->Gloss][((Pixel & fmt->Gmask) >> fmt->Gshift)]; \
b = SDL_expand_byte[fmt->Bloss][((Pixel & fmt->Bmask) >> fmt->Bshift)]; \
a = SDL_expand_byte[fmt->Aloss][((Pixel & fmt->Amask) >> fmt->Ashift)]; \
}
#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a) \
{ \
r = (Pixel & fmt->Rmask) >> fmt->Rshift; \
g = (Pixel & fmt->Gmask) >> fmt->Gshift; \
b = (Pixel & fmt->Bmask) >> fmt->Bshift; \
a = (Pixel & fmt->Amask) >> fmt->Ashift; \
}
#define RGBA_FROM_RGBA8888(Pixel, r, g, b, a) \
{ \
r = (Pixel >> 24); \
g = ((Pixel >> 16) & 0xFF); \
b = ((Pixel >> 8) & 0xFF); \
a = (Pixel & 0xFF); \
}
#define RGBA_FROM_ARGB8888(Pixel, r, g, b, a) \
{ \
r = ((Pixel >> 16) & 0xFF); \
g = ((Pixel >> 8) & 0xFF); \
b = (Pixel & 0xFF); \
a = (Pixel >> 24); \
}
#define RGBA_FROM_ABGR8888(Pixel, r, g, b, a) \
{ \
r = (Pixel & 0xFF); \
g = ((Pixel >> 8) & 0xFF); \
b = ((Pixel >> 16) & 0xFF); \
a = (Pixel >> 24); \
}
#define RGBA_FROM_BGRA8888(Pixel, r, g, b, a) \
{ \
r = ((Pixel >> 8) & 0xFF); \
g = ((Pixel >> 16) & 0xFF); \
b = (Pixel >> 24); \
a = (Pixel & 0xFF); \
}
#define RGBA_FROM_ARGB2101010(Pixel, r, g, b, a) \
{ \
r = ((Pixel >> 22) & 0xFF); \
g = ((Pixel >> 12) & 0xFF); \
b = ((Pixel >> 2) & 0xFF); \
a = SDL_expand_byte[6][(Pixel >> 30)]; \
}
#define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a) \
do { \
switch (bpp) { \
case 1: \
Pixel = *((Uint8 *)(buf)); \
RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
break; \
\
case 2: \
Pixel = *((Uint16 *)(buf)); \
RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
break; \
\
case 3: \
{ \
Pixel = 0; \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
r = *((buf) + fmt->Rshift / 8); \
g = *((buf) + fmt->Gshift / 8); \
b = *((buf) + fmt->Bshift / 8); \
} else { \
r = *((buf) + 2 - fmt->Rshift / 8); \
g = *((buf) + 2 - fmt->Gshift / 8); \
b = *((buf) + 2 - fmt->Bshift / 8); \
} \
a = 0xFF; \
} break; \
\
case 4: \
Pixel = *((Uint32 *)(buf)); \
RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
break; \
\
default: \
/* stop gcc complaints */ \
Pixel = 0; \
r = g = b = a = 0; \
break; \
} \
} while (0)
/* FIXME: this isn't correct, especially for Alpha (maximum != 255) */
#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \
{ \
Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
((g>>fmt->Gloss)<<fmt->Gshift)| \
((b>>fmt->Bloss)<<fmt->Bshift)| \
((a>>fmt->Aloss)<<fmt->Ashift); \
}
#define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \
{ \
switch (bpp) { \
case 1: { \
Uint8 _pixel; \
\
PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
*((Uint8 *)(buf)) = _pixel; \
} \
break; \
\
case 2: { \
Uint16 _pixel; \
\
PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
*((Uint16 *)(buf)) = _pixel; \
} \
break; \
\
case 3: { \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
*((buf)+fmt->Rshift/8) = r; \
*((buf)+fmt->Gshift/8) = g; \
*((buf)+fmt->Bshift/8) = b; \
} else { \
*((buf)+2-fmt->Rshift/8) = r; \
*((buf)+2-fmt->Gshift/8) = g; \
*((buf)+2-fmt->Bshift/8) = b; \
} \
} \
break; \
\
case 4: { \
Uint32 _pixel; \
\
PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
*((Uint32 *)(buf)) = _pixel; \
} \
break; \
} \
}
#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \
{ \
Pixel = ((r >> fmt->Rloss) << fmt->Rshift) | \
((g >> fmt->Gloss) << fmt->Gshift) | \
((b >> fmt->Bloss) << fmt->Bshift) | \
((a >> fmt->Aloss) << fmt->Ashift); \
}
#define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \
{ \
switch (bpp) { \
case 1: \
{ \
Uint8 _pixel; \
\
PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
*((Uint8 *)(buf)) = _pixel; \
} break; \
\
case 2: \
{ \
Uint16 _pixel; \
\
PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
*((Uint16 *)(buf)) = _pixel; \
} break; \
\
case 3: \
{ \
if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
*((buf) + fmt->Rshift / 8) = r; \
*((buf) + fmt->Gshift / 8) = g; \
*((buf) + fmt->Bshift / 8) = b; \
} else { \
*((buf) + 2 - fmt->Rshift / 8) = r; \
*((buf) + 2 - fmt->Gshift / 8) = g; \
*((buf) + 2 - fmt->Bshift / 8) = b; \
} \
} break; \
\
case 4: \
{ \
Uint32 _pixel; \
\
PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
*((Uint32 *)(buf)) = _pixel; \
} break; \
} \
}
/* Blend the RGB values of two pixels with an alpha value */
#define ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB) \
do { \
dR = (Uint8)((((int)(sR-dR)*(int)A)/255)+dR); \
dG = (Uint8)((((int)(sG-dG)*(int)A)/255)+dG); \
dB = (Uint8)((((int)(sB-dB)*(int)A)/255)+dB); \
} while(0)
#define ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB) \
do { \
dR = (Uint8)((((int)(sR - dR) * (int)A) / 255) + dR); \
dG = (Uint8)((((int)(sG - dG) * (int)A) / 255) + dG); \
dB = (Uint8)((((int)(sB - dB) * (int)A) / 255) + dB); \
} while (0)
/* Blend the RGBA values of two pixels */
#define ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA) \
do { \
dR = (Uint8)((((int)(sR-dR)*(int)sA)/255)+dR); \
dG = (Uint8)((((int)(sG-dG)*(int)sA)/255)+dG); \
dB = (Uint8)((((int)(sB-dB)*(int)sA)/255)+dB); \
dA = (Uint8)((int)sA+dA-((int)sA*dA)/255); \
} while(0)
#define ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA) \
do { \
dR = (Uint8)((((int)(sR - dR) * (int)sA) / 255) + dR); \
dG = (Uint8)((((int)(sG - dG) * (int)sA) / 255) + dG); \
dB = (Uint8)((((int)(sB - dB) * (int)sA) / 255) + dB); \
dA = (Uint8)((int)sA + dA - ((int)sA * dA) / 255); \
} while (0)
/* This is a very useful loop for optimizing blitters */
#if defined(_MSC_VER) && (_MSC_VER == 1300)
@ -476,83 +474,114 @@ do { \
#ifdef USE_DUFFS_LOOP
/* 8-times unrolled loop */
#define DUFFS_LOOP8(pixel_copy_increment, width) \
{ int n = (width+7)/8; \
switch (width & 7) { \
case 0: do { pixel_copy_increment; SDL_FALLTHROUGH; \
case 7: pixel_copy_increment; SDL_FALLTHROUGH; \
case 6: pixel_copy_increment; SDL_FALLTHROUGH; \
case 5: pixel_copy_increment; SDL_FALLTHROUGH; \
case 4: pixel_copy_increment; SDL_FALLTHROUGH; \
case 3: pixel_copy_increment; SDL_FALLTHROUGH; \
case 2: pixel_copy_increment; SDL_FALLTHROUGH; \
case 1: pixel_copy_increment; \
} while ( --n > 0 ); \
} \
}
#define DUFFS_LOOP8(pixel_copy_increment, width) \
{ \
int n = (width + 7) / 8; \
switch (width & 7) { \
case 0: \
do { \
pixel_copy_increment; \
SDL_FALLTHROUGH; \
case 7: \
pixel_copy_increment; \
SDL_FALLTHROUGH; \
case 6: \
pixel_copy_increment; \
SDL_FALLTHROUGH; \
case 5: \
pixel_copy_increment; \
SDL_FALLTHROUGH; \
case 4: \
pixel_copy_increment; \
SDL_FALLTHROUGH; \
case 3: \
pixel_copy_increment; \
SDL_FALLTHROUGH; \
case 2: \
pixel_copy_increment; \
SDL_FALLTHROUGH; \
case 1: \
pixel_copy_increment; \
} while (--n > 0); \
} \
}
/* 4-times unrolled loop */
#define DUFFS_LOOP4(pixel_copy_increment, width) \
{ int n = (width+3)/4; \
switch (width & 3) { \
case 0: do { pixel_copy_increment; SDL_FALLTHROUGH; \
case 3: pixel_copy_increment; SDL_FALLTHROUGH; \
case 2: pixel_copy_increment; SDL_FALLTHROUGH; \
case 1: pixel_copy_increment; \
} while (--n > 0); \
} \
}
#define DUFFS_LOOP4(pixel_copy_increment, width) \
{ \
int n = (width + 3) / 4; \
switch (width & 3) { \
case 0: \
do { \
pixel_copy_increment; \
SDL_FALLTHROUGH; \
case 3: \
pixel_copy_increment; \
SDL_FALLTHROUGH; \
case 2: \
pixel_copy_increment; \
SDL_FALLTHROUGH; \
case 1: \
pixel_copy_increment; \
} while (--n > 0); \
} \
}
/* Use the 8-times version of the loop by default */
#define DUFFS_LOOP(pixel_copy_increment, width) \
#define DUFFS_LOOP(pixel_copy_increment, width) \
DUFFS_LOOP8(pixel_copy_increment, width)
/* Special version of Duff's device for even more optimization */
#define DUFFS_LOOP_124(pixel_copy_increment1, \
pixel_copy_increment2, \
pixel_copy_increment4, width) \
{ int n = width; \
if (n & 1) { \
pixel_copy_increment1; n -= 1; \
} \
if (n & 2) { \
pixel_copy_increment2; n -= 2; \
} \
if (n & 4) { \
pixel_copy_increment4; n -= 4; \
} \
if (n) { \
n /= 8; \
do { \
pixel_copy_increment4; \
pixel_copy_increment4; \
} while (--n > 0); \
} \
}
#define DUFFS_LOOP_124(pixel_copy_increment1, \
pixel_copy_increment2, \
pixel_copy_increment4, width) \
{ \
int n = width; \
if (n & 1) { \
pixel_copy_increment1; \
n -= 1; \
} \
if (n & 2) { \
pixel_copy_increment2; \
n -= 2; \
} \
if (n & 4) { \
pixel_copy_increment4; \
n -= 4; \
} \
if (n) { \
n /= 8; \
do { \
pixel_copy_increment4; \
pixel_copy_increment4; \
} while (--n > 0); \
} \
}
#else
/* Don't use Duff's device to unroll loops */
#define DUFFS_LOOP(pixel_copy_increment, width) \
{ int n; \
for ( n=width; n > 0; --n ) { \
pixel_copy_increment; \
} \
}
#define DUFFS_LOOP8(pixel_copy_increment, width) \
#define DUFFS_LOOP(pixel_copy_increment, width) \
{ \
int n; \
for (n = width; n > 0; --n) { \
pixel_copy_increment; \
} \
}
#define DUFFS_LOOP8(pixel_copy_increment, width) \
DUFFS_LOOP(pixel_copy_increment, width)
#define DUFFS_LOOP4(pixel_copy_increment, width) \
#define DUFFS_LOOP4(pixel_copy_increment, width) \
DUFFS_LOOP(pixel_copy_increment, width)
#define DUFFS_LOOP_124(pixel_copy_increment1, \
pixel_copy_increment2, \
pixel_copy_increment4, width) \
#define DUFFS_LOOP_124(pixel_copy_increment1, \
pixel_copy_increment2, \
pixel_copy_increment4, width) \
DUFFS_LOOP(pixel_copy_increment1, width)
#endif /* USE_DUFFS_LOOP */
/* Prevent Visual C++ 6.0 from printing out stupid warnings */
#if defined(_MSC_VER) && (_MSC_VER >= 600)
#pragma warning(disable: 4550)
#pragma warning(disable : 4550)
#endif
#endif /* SDL_blit_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -27,8 +27,7 @@
/* Functions to blit from bitmaps to other surfaces */
static void
BlitBto1(SDL_BlitInfo * info)
static void BlitBto1(SDL_BlitInfo *info)
{
int c;
int width, height;
@ -46,44 +45,81 @@ BlitBto1(SDL_BlitInfo * info)
srcskip += width - (width + 7) / 8;
if (map) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
*dst = map[bit];
}
dst++;
byte >>= 1;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
dst++;
byte <<= 1;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
*dst = bit;
}
dst++;
byte >>= 1;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = bit;
}
dst++;
byte <<= 1;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = bit;
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
}
static void
BlitBto2(SDL_BlitInfo * info)
static void BlitBto2(SDL_BlitInfo *info)
{
int c;
int width, height;
@ -96,31 +132,49 @@ BlitBto2(SDL_BlitInfo * info)
height = info->dst_h;
src = info->src;
srcskip = info->src_skip;
dst = (Uint16 *) info->dst;
dst = (Uint16 *)info->dst;
dstskip = info->dst_skip / 2;
map = (Uint16 *) info->table;
map = (Uint16 *)info->table;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
*dst = map[bit];
}
byte >>= 1;
dst++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
byte <<= 1;
dst++;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
byte <<= 1;
dst++;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
static void
BlitBto3(SDL_BlitInfo * info)
static void BlitBto3(SDL_BlitInfo *info)
{
int c, o;
int width, height;
@ -137,29 +191,50 @@ BlitBto3(SDL_BlitInfo * info)
map = info->table;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
o = bit * 4;
dst[0] = map[o++];
dst[1] = map[o++];
dst[2] = map[o++];
}
byte >>= 1;
dst += 3;
}
bit = (byte & 0x80) >> 7;
if (1) {
o = bit * 4;
dst[0] = map[o++];
dst[1] = map[o++];
dst[2] = map[o++];
}
byte <<= 1;
dst += 3;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
o = bit * 4;
dst[0] = map[o++];
dst[1] = map[o++];
dst[2] = map[o++];
}
byte <<= 1;
dst += 3;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
static void
BlitBto4(SDL_BlitInfo * info)
static void BlitBto4(SDL_BlitInfo *info)
{
int width, height;
Uint8 *src;
@ -172,31 +247,49 @@ BlitBto4(SDL_BlitInfo * info)
height = info->dst_h;
src = info->src;
srcskip = info->src_skip;
dst = (Uint32 *) info->dst;
dst = (Uint32 *)info->dst;
dstskip = info->dst_skip / 4;
map = (Uint32 *) info->table;
map = (Uint32 *)info->table;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
*dst = map[bit];
}
byte >>= 1;
dst++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
byte <<= 1;
dst++;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
byte <<= 1;
dst++;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
static void
BlitBto1Key(SDL_BlitInfo * info)
static void BlitBto1Key(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -212,49 +305,86 @@ BlitBto1Key(SDL_BlitInfo * info)
srcskip += width - (width + 7) / 8;
if (palmap) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
*dst = palmap[bit];
}
dst++;
byte >>= 1;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dst = palmap[bit];
}
dst++;
byte <<= 1;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dst = palmap[bit];
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
*dst = bit;
}
dst++;
byte >>= 1;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dst = bit;
}
dst++;
byte <<= 1;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dst = bit;
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
}
static void
BlitBto2Key(SDL_BlitInfo * info)
static void BlitBto2Key(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint16 *dstp = (Uint16 *) info->dst;
Uint16 *dstp = (Uint16 *)info->dst;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
@ -265,26 +395,44 @@ BlitBto2Key(SDL_BlitInfo * info)
srcskip += width - (width + 7) / 8;
dstskip /= 2;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
*dstp = ((Uint16 *)palmap)[bit];
}
byte >>= 1;
dstp++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dstp = ((Uint16 *) palmap)[bit];
}
byte <<= 1;
dstp++;
src += srcskip;
dstp += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dstp = ((Uint16 *)palmap)[bit];
}
byte <<= 1;
dstp++;
}
src += srcskip;
dstp += dstskip;
}
src += srcskip;
dstp += dstskip;
}
}
static void
BlitBto3Key(SDL_BlitInfo * info)
static void BlitBto3Key(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -299,31 +447,49 @@ BlitBto3Key(SDL_BlitInfo * info)
/* Set up some basic variables */
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
SDL_memcpy(dst, &palmap[bit * 4], 3);
}
byte >>= 1;
dst += 3;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
SDL_memcpy(dst, &palmap[bit * 4], 3);
}
byte <<= 1;
dst += 3;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
SDL_memcpy(dst, &palmap[bit * 4], 3);
}
byte <<= 1;
dst += 3;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
static void
BlitBto4Key(SDL_BlitInfo * info)
static void BlitBto4Key(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint32 *dstp = (Uint32 *) info->dst;
Uint32 *dstp = (Uint32 *)info->dst;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
@ -334,26 +500,44 @@ BlitBto4Key(SDL_BlitInfo * info)
srcskip += width - (width + 7) / 8;
dstskip /= 4;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
*dstp = ((Uint32 *)palmap)[bit];
}
byte >>= 1;
dstp++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dstp = ((Uint32 *) palmap)[bit];
}
byte <<= 1;
dstp++;
src += srcskip;
dstp += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dstp = ((Uint32 *)palmap)[bit];
}
byte <<= 1;
dstp++;
}
src += srcskip;
dstp += dstskip;
}
src += srcskip;
dstp += dstskip;
}
}
static void
BlitBtoNAlpha(SDL_BlitInfo * info)
static void BlitBtoNAlpha(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -374,31 +558,54 @@ BlitBtoNAlpha(SDL_BlitInfo * info)
dstbpp = dstfmt->BytesPerPixel;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (1) {
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
byte >>= 1;
dst += dstbpp;
}
bit = (byte & 0x80) >> 7;
if (1) {
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
byte <<= 1;
dst += dstbpp;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
byte <<= 1;
dst += dstbpp;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
static void
BlitBtoNAlphaKey(SDL_BlitInfo * info)
static void BlitBtoNAlphaKey(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -421,48 +628,70 @@ BlitBtoNAlphaKey(SDL_BlitInfo * info)
dstbpp = dstfmt->BytesPerPixel;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
if (info->src_fmt->format == SDL_PIXELFORMAT_INDEX1LSB) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x01);
if (bit != ckey) {
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
byte >>= 1;
dst += dstbpp;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
byte <<= 1;
dst += dstbpp;
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if (!(c & 7)) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
byte <<= 1;
dst += dstbpp;
}
src += srcskip;
dst += dstskip;
}
src += srcskip;
dst += dstskip;
}
}
static const SDL_BlitFunc bitmap_blit[] = {
(SDL_BlitFunc) NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4
(SDL_BlitFunc)NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4
};
static const SDL_BlitFunc colorkey_blit[] = {
(SDL_BlitFunc) NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key
(SDL_BlitFunc)NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key
};
static void
Blit4bto4(SDL_BlitInfo * info)
static void Blit4bto4(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint32 *dst = (Uint32 *) info->dst;
Uint32 *dst = (Uint32 *)info->dst;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
Uint32 *map = (Uint32 *) info->table;
Uint32 *map = (Uint32 *)info->table;
int c;
/* Set up some basic variables */
@ -471,7 +700,7 @@ Blit4bto4(SDL_BlitInfo * info)
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 0x1) == 0) {
if (!(c & 0x1)) {
byte = *src++;
}
bit = (byte & 0xF0) >> 4;
@ -482,21 +711,20 @@ Blit4bto4(SDL_BlitInfo * info)
dst++;
}
src += srcskip;
dst = (Uint32 *) ((Uint8 *) dst + dstskip);
dst = (Uint32 *)((Uint8 *)dst + dstskip);
}
}
static void
Blit4bto4Key(SDL_BlitInfo * info)
static void Blit4bto4Key(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint32 *dst = (Uint32 *) info->dst;
Uint32 *dst = (Uint32 *)info->dst;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
Uint32 *map = (Uint32 *) info->table;
Uint32 *map = (Uint32 *)info->table;
int c;
/* Set up some basic variables */
@ -505,7 +733,7 @@ Blit4bto4Key(SDL_BlitInfo * info)
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 0x1) == 0) {
if (!(c & 0x1)) {
byte = *src++;
}
bit = (byte & 0xF0) >> 4;
@ -516,12 +744,11 @@ Blit4bto4Key(SDL_BlitInfo * info)
dst++;
}
src += srcskip;
dst = (Uint32 *) ((Uint8 *) dst + dstskip);
dst = (Uint32 *)((Uint8 *)dst + dstskip);
}
}
SDL_BlitFunc
SDL_CalculateBlit0(SDL_Surface * surface)
SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
{
int which;
@ -529,11 +756,11 @@ SDL_CalculateBlit0(SDL_Surface * surface)
if (surface->format->BitsPerPixel == 4) {
if (surface->map->dst->format->BytesPerPixel == 4) {
switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
case 0:
return Blit4bto4;
case 0:
return Blit4bto4;
case SDL_COPY_COLORKEY:
return Blit4bto4Key;
case SDL_COPY_COLORKEY:
return Blit4bto4Key;
}
}
/* We don't fully support 4-bit packed pixel modes */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -29,8 +29,7 @@
/* Functions to blit from 8-bit surfaces to other surfaces */
static void
Blit1to1(SDL_BlitInfo * info)
static void Blit1to1(SDL_BlitInfo *info)
{
#ifndef USE_DUFFS_LOOP
int c;
@ -73,16 +72,15 @@ Blit1to1(SDL_BlitInfo * info)
/* This is now endian dependent */
#ifndef USE_DUFFS_LOOP
# if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )
# define HI 1
# define LO 0
# else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */
# define HI 0
# define LO 1
# endif
#if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
#define HI 1
#define LO 0
#else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */
#define HI 0
#define LO 1
#endif
static void
Blit1to2(SDL_BlitInfo * info)
#endif
static void Blit1to2(SDL_BlitInfo *info)
{
#ifndef USE_DUFFS_LOOP
int c;
@ -99,7 +97,7 @@ Blit1to2(SDL_BlitInfo * info)
srcskip = info->src_skip;
dst = info->dst;
dstskip = info->dst_skip;
map = (Uint16 *) info->table;
map = (Uint16 *)info->table;
#ifdef USE_DUFFS_LOOP
while (height--) {
@ -116,7 +114,7 @@ Blit1to2(SDL_BlitInfo * info)
}
#else
/* Memory align at 4-byte boundary, if necessary */
if ((long) dst & 0x03) {
if ((long)dst & 0x03) {
/* Don't do anything if width is 0 */
if (width == 0) {
return;
@ -125,30 +123,31 @@ Blit1to2(SDL_BlitInfo * info)
while (height--) {
/* Perform copy alignment */
*(Uint16 *) dst = map[*src++];
*(Uint16 *)dst = map[*src++];
dst += 2;
/* Copy in 4 pixel chunks */
for (c = width / 4; c; --c) {
*(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
*(Uint32 *)dst = (map[src[HI]] << 16) | (map[src[LO]]);
src += 2;
dst += 4;
*(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
*(Uint32 *)dst = (map[src[HI]] << 16) | (map[src[LO]]);
src += 2;
dst += 4;
}
/* Get any leftovers */
switch (width & 3) {
case 3:
*(Uint16 *) dst = map[*src++];
*(Uint16 *)dst = map[*src++];
dst += 2;
SDL_FALLTHROUGH;
case 2:
*(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
*(Uint32 *)dst = (map[src[HI]] << 16) | (map[src[LO]]);
src += 2;
dst += 4;
break;
case 1:
*(Uint16 *) dst = map[*src++];
*(Uint16 *)dst = map[*src++];
dst += 2;
break;
}
@ -159,25 +158,26 @@ Blit1to2(SDL_BlitInfo * info)
while (height--) {
/* Copy in 4 pixel chunks */
for (c = width / 4; c; --c) {
*(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
*(Uint32 *)dst = (map[src[HI]] << 16) | (map[src[LO]]);
src += 2;
dst += 4;
*(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
*(Uint32 *)dst = (map[src[HI]] << 16) | (map[src[LO]]);
src += 2;
dst += 4;
}
/* Get any leftovers */
switch (width & 3) {
case 3:
*(Uint16 *) dst = map[*src++];
*(Uint16 *)dst = map[*src++];
dst += 2;
SDL_FALLTHROUGH;
case 2:
*(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
*(Uint32 *)dst = (map[src[HI]] << 16) | (map[src[LO]]);
src += 2;
dst += 4;
break;
case 1:
*(Uint16 *) dst = map[*src++];
*(Uint16 *)dst = map[*src++];
dst += 2;
break;
}
@ -188,8 +188,7 @@ Blit1to2(SDL_BlitInfo * info)
#endif /* USE_DUFFS_LOOP */
}
static void
Blit1to3(SDL_BlitInfo * info)
static void Blit1to3(SDL_BlitInfo *info)
{
#ifndef USE_DUFFS_LOOP
int c;
@ -237,8 +236,7 @@ Blit1to3(SDL_BlitInfo * info)
}
}
static void
Blit1to4(SDL_BlitInfo * info)
static void Blit1to4(SDL_BlitInfo *info)
{
#ifndef USE_DUFFS_LOOP
int c;
@ -253,9 +251,9 @@ Blit1to4(SDL_BlitInfo * info)
height = info->dst_h;
src = info->src;
srcskip = info->src_skip;
dst = (Uint32 *) info->dst;
dst = (Uint32 *)info->dst;
dstskip = info->dst_skip / 4;
map = (Uint32 *) info->table;
map = (Uint32 *)info->table;
while (height--) {
#ifdef USE_DUFFS_LOOP
@ -274,8 +272,10 @@ Blit1to4(SDL_BlitInfo * info)
switch (width & 3) {
case 3:
*dst++ = map[*src++];
SDL_FALLTHROUGH;
case 2:
*dst++ = map[*src++];
SDL_FALLTHROUGH;
case 1:
*dst++ = map[*src++];
}
@ -285,8 +285,7 @@ Blit1to4(SDL_BlitInfo * info)
}
}
static void
Blit1to1Key(SDL_BlitInfo * info)
static void Blit1to1Key(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -332,16 +331,15 @@ Blit1to1Key(SDL_BlitInfo * info)
}
}
static void
Blit1to2Key(SDL_BlitInfo * info)
static void Blit1to2Key(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
int srcskip = info->src_skip;
Uint16 *dstp = (Uint16 *) info->dst;
Uint16 *dstp = (Uint16 *)info->dst;
int dstskip = info->dst_skip;
Uint16 *palmap = (Uint16 *) info->table;
Uint16 *palmap = (Uint16 *)info->table;
Uint32 ckey = info->colorkey;
/* Set up some basic variables */
@ -364,8 +362,7 @@ Blit1to2Key(SDL_BlitInfo * info)
}
}
static void
Blit1to3Key(SDL_BlitInfo * info)
static void Blit1to3Key(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -397,16 +394,15 @@ Blit1to3Key(SDL_BlitInfo * info)
}
}
static void
Blit1to4Key(SDL_BlitInfo * info)
static void Blit1to4Key(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
int srcskip = info->src_skip;
Uint32 *dstp = (Uint32 *) info->dst;
Uint32 *dstp = (Uint32 *)info->dst;
int dstskip = info->dst_skip;
Uint32 *palmap = (Uint32 *) info->table;
Uint32 *palmap = (Uint32 *)info->table;
Uint32 ckey = info->colorkey;
/* Set up some basic variables */
@ -429,8 +425,7 @@ Blit1to4Key(SDL_BlitInfo * info)
}
}
static void
Blit1toNAlpha(SDL_BlitInfo * info)
static void Blit1toNAlpha(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -469,8 +464,7 @@ Blit1toNAlpha(SDL_BlitInfo * info)
}
}
static void
Blit1toNAlphaKey(SDL_BlitInfo * info)
static void Blit1toNAlphaKey(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -513,15 +507,14 @@ Blit1toNAlphaKey(SDL_BlitInfo * info)
}
static const SDL_BlitFunc one_blit[] = {
(SDL_BlitFunc) NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4
(SDL_BlitFunc)NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4
};
static const SDL_BlitFunc one_blitkey[] = {
(SDL_BlitFunc) NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key
(SDL_BlitFunc)NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key
};
SDL_BlitFunc
SDL_CalculateBlit1(SDL_Surface * surface)
SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface *surface)
{
int which;
SDL_PixelFormat *dstfmt;
@ -539,16 +532,19 @@ SDL_CalculateBlit1(SDL_Surface * surface)
case SDL_COPY_COLORKEY:
return one_blitkey[which];
case SDL_COPY_COLORKEY | SDL_COPY_BLEND: /* this is not super-robust but handles a specific case we found sdl12-compat. */
return (surface->map->info.a == 255) ? one_blitkey[which] : (SDL_BlitFunc)NULL;
case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
/* Supporting 8bpp->8bpp alpha is doable but requires lots of
tables which consume space and takes time to precompute,
so is better left to the user */
return which >= 2 ? Blit1toNAlpha : (SDL_BlitFunc) NULL;
return which >= 2 ? Blit1toNAlpha : (SDL_BlitFunc)NULL;
case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? Blit1toNAlphaKey : (SDL_BlitFunc) NULL;
return which >= 2 ? Blit1toNAlphaKey : (SDL_BlitFunc)NULL;
}
return (SDL_BlitFunc) NULL;
return (SDL_BlitFunc)NULL;
}
#endif /* SDL_HAVE_BLIT_1 */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -28,8 +28,7 @@
/* Functions to perform alpha blended blitting */
/* N->1 blending with per-surface alpha */
static void
BlitNto1SurfaceAlpha(SDL_BlitInfo * info)
static void BlitNto1SurfaceAlpha(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -75,8 +74,7 @@ BlitNto1SurfaceAlpha(SDL_BlitInfo * info)
}
/* N->1 blending with pixel alpha */
static void
BlitNto1PixelAlpha(SDL_BlitInfo * info)
static void BlitNto1PixelAlpha(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -121,8 +119,7 @@ BlitNto1PixelAlpha(SDL_BlitInfo * info)
}
/* colorkeyed N->1 blending with per-surface alpha */
static void
BlitNto1SurfaceAlphaKey(SDL_BlitInfo * info)
static void BlitNto1SurfaceAlphaKey(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -173,51 +170,49 @@ BlitNto1SurfaceAlphaKey(SDL_BlitInfo * info)
#ifdef __MMX__
/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
static void
BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo * info)
static void BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint32 *srcp = (Uint32 *) info->src;
Uint32 *srcp = (Uint32 *)info->src;
int srcskip = info->src_skip >> 2;
Uint32 *dstp = (Uint32 *) info->dst;
Uint32 *dstp = (Uint32 *)info->dst;
int dstskip = info->dst_skip >> 2;
Uint32 dalpha = info->dst_fmt->Amask;
__m64 src1, src2, dst1, dst2, lmask, hmask, dsta;
hmask = _mm_set_pi32(0x00fefefe, 0x00fefefe); /* alpha128 mask -> hmask */
lmask = _mm_set_pi32(0x00010101, 0x00010101); /* !alpha128 mask -> lmask */
dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */
hmask = _mm_set_pi32(0x00fefefe, 0x00fefefe); /* alpha128 mask -> hmask */
lmask = _mm_set_pi32(0x00010101, 0x00010101); /* !alpha128 mask -> lmask */
dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */
while (height--) {
int n = width;
if (n & 1) {
Uint32 s = *srcp++;
Uint32 d = *dstp;
*dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
+ (s & d & 0x00010101)) | dalpha;
*dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) + (s & d & 0x00010101)) | dalpha;
n--;
}
for (n >>= 1; n > 0; --n) {
dst1 = *(__m64 *) dstp; /* 2 x dst -> dst1(ARGBARGB) */
dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */
dst1 = *(__m64 *)dstp; /* 2 x dst -> dst1(ARGBARGB) */
dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */
src1 = *(__m64 *) srcp; /* 2 x src -> src1(ARGBARGB) */
src2 = src1; /* 2 x src -> src2(ARGBARGB) */
src1 = *(__m64 *)srcp; /* 2 x src -> src1(ARGBARGB) */
src2 = src1; /* 2 x src -> src2(ARGBARGB) */
dst2 = _mm_and_si64(dst2, hmask); /* dst & mask -> dst2 */
src2 = _mm_and_si64(src2, hmask); /* src & mask -> src2 */
src2 = _mm_add_pi32(src2, dst2); /* dst2 + src2 -> src2 */
src2 = _mm_srli_pi32(src2, 1); /* src2 >> 1 -> src2 */
dst2 = _mm_and_si64(dst2, hmask); /* dst & mask -> dst2 */
src2 = _mm_and_si64(src2, hmask); /* src & mask -> src2 */
src2 = _mm_add_pi32(src2, dst2); /* dst2 + src2 -> src2 */
src2 = _mm_srli_pi32(src2, 1); /* src2 >> 1 -> src2 */
dst1 = _mm_and_si64(dst1, src1); /* src & dst -> dst1 */
dst1 = _mm_and_si64(dst1, lmask); /* dst1 & !mask -> dst1 */
dst1 = _mm_add_pi32(dst1, src2); /* src2 + dst1 -> dst1 */
dst1 = _mm_or_si64(dst1, dsta); /* dsta(full alpha) | dst1 -> dst1 */
dst1 = _mm_and_si64(dst1, src1); /* src & dst -> dst1 */
dst1 = _mm_and_si64(dst1, lmask); /* dst1 & !mask -> dst1 */
dst1 = _mm_add_pi32(dst1, src2); /* src2 + dst1 -> dst1 */
dst1 = _mm_or_si64(dst1, dsta); /* dsta(full alpha) | dst1 -> dst1 */
*(__m64 *) dstp = dst1; /* dst1 -> 2 x dst pixels */
*(__m64 *)dstp = dst1; /* dst1 -> 2 x dst pixels */
dstp += 2;
srcp += 2;
}
@ -229,8 +224,7 @@ BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo * info)
}
/* fast RGB888->(A)RGB888 blending with surface alpha */
static void
BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo * info)
static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo *info)
{
SDL_PixelFormat *df = info->dst_fmt;
Uint32 chanmask;
@ -242,45 +236,44 @@ BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo * info)
} else {
int width = info->dst_w;
int height = info->dst_h;
Uint32 *srcp = (Uint32 *) info->src;
Uint32 *srcp = (Uint32 *)info->src;
int srcskip = info->src_skip >> 2;
Uint32 *dstp = (Uint32 *) info->dst;
Uint32 *dstp = (Uint32 *)info->dst;
int dstskip = info->dst_skip >> 2;
Uint32 dalpha = df->Amask;
Uint32 amult;
__m64 src1, src2, dst1, dst2, mm_alpha, mm_zero, dsta;
mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
/* form the alpha mult */
amult = alpha | (alpha << 8);
amult = amult | (amult << 16);
chanmask =
(0xff << df->Rshift) | (0xff << df->
Gshift) | (0xff << df->Bshift);
(0xff << df->Rshift) | (0xff << df->Gshift) | (0xff << df->Bshift);
mm_alpha = _mm_set_pi32(0, amult & chanmask); /* 0000AAAA -> mm_alpha, minus 1 chan */
mm_alpha = _mm_unpacklo_pi8(mm_alpha, mm_zero); /* 0A0A0A0A -> mm_alpha, minus 1 chan */
/* at this point mm_alpha can be 000A0A0A or 0A0A0A00 or another combo */
dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */
dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */
while (height--) {
int n = width;
if (n & 1) {
/* One Pixel Blend */
src2 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src2 (0000ARGB) */
src2 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src2 (0000ARGB) */
src2 = _mm_unpacklo_pi8(src2, mm_zero); /* 0A0R0G0B -> src2 */
dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */
dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */
dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */
src2 = _mm_sub_pi16(src2, dst1); /* src2 - dst2 -> src2 */
src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */
dst1 = _mm_add_pi8(src2, dst1); /* src2 + dst1 -> dst1 */
src2 = _mm_sub_pi16(src2, dst1); /* src2 - dst2 -> src2 */
src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */
dst1 = _mm_add_pi8(src2, dst1); /* src2 + dst1 -> dst1 */
dst1 = _mm_packs_pu16(dst1, mm_zero); /* 0000ARGB -> dst1 */
dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */
*dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
dst1 = _mm_packs_pu16(dst1, mm_zero); /* 0000ARGB -> dst1 */
dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */
*dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
++srcp;
++dstp;
@ -290,30 +283,30 @@ BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo * info)
for (n >>= 1; n > 0; --n) {
/* Two Pixels Blend */
src1 = *(__m64 *) srcp; /* 2 x src -> src1(ARGBARGB) */
src2 = src1; /* 2 x src -> src2(ARGBARGB) */
src1 = *(__m64 *)srcp; /* 2 x src -> src1(ARGBARGB) */
src2 = src1; /* 2 x src -> src2(ARGBARGB) */
src1 = _mm_unpacklo_pi8(src1, mm_zero); /* low - 0A0R0G0B -> src1 */
src2 = _mm_unpackhi_pi8(src2, mm_zero); /* high - 0A0R0G0B -> src2 */
dst1 = *(__m64 *) dstp; /* 2 x dst -> dst1(ARGBARGB) */
dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */
dst1 = *(__m64 *)dstp; /* 2 x dst -> dst1(ARGBARGB) */
dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */
dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* low - 0A0R0G0B -> dst1 */
dst2 = _mm_unpackhi_pi8(dst2, mm_zero); /* high - 0A0R0G0B -> dst2 */
src1 = _mm_sub_pi16(src1, dst1); /* src1 - dst1 -> src1 */
src1 = _mm_mullo_pi16(src1, mm_alpha); /* src1 * alpha -> src1 */
src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1 */
dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1(dst1) -> dst1 */
src1 = _mm_sub_pi16(src1, dst1); /* src1 - dst1 -> src1 */
src1 = _mm_mullo_pi16(src1, mm_alpha); /* src1 * alpha -> src1 */
src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1 */
dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1(dst1) -> dst1 */
src2 = _mm_sub_pi16(src2, dst2); /* src2 - dst2 -> src2 */
src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */
dst2 = _mm_add_pi8(src2, dst2); /* src2 + dst2(dst2) -> dst2 */
src2 = _mm_sub_pi16(src2, dst2); /* src2 - dst2 -> src2 */
src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */
dst2 = _mm_add_pi8(src2, dst2); /* src2 + dst2(dst2) -> dst2 */
dst1 = _mm_packs_pu16(dst1, dst2); /* 0A0R0G0B(res1), 0A0R0G0B(res2) -> dst1(ARGBARGB) */
dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */
dst1 = _mm_packs_pu16(dst1, dst2); /* 0A0R0G0B(res1), 0A0R0G0B(res2) -> dst1(ARGBARGB) */
dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */
*(__m64 *) dstp = dst1; /* dst1 -> 2 x pixel */
*(__m64 *)dstp = dst1; /* dst1 -> 2 x pixel */
srcp += 2;
dstp += 2;
@ -326,23 +319,32 @@ BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo * info)
}
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
static void
BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo * info)
static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint32 *srcp = (Uint32 *) info->src;
Uint32 *srcp = (Uint32 *)info->src;
int srcskip = info->src_skip >> 2;
Uint32 *dstp = (Uint32 *) info->dst;
Uint32 *dstp = (Uint32 *)info->dst;
int dstskip = info->dst_skip >> 2;
SDL_PixelFormat *sf = info->src_fmt;
Uint32 amask = sf->Amask;
Uint32 ashift = sf->Ashift;
Uint64 multmask, multmask2;
__m64 src1, dst1, mm_alpha, mm_zero, mm_alpha2;
__m64 src1, dst1, mm_alpha, mm_zero, mm_alpha2, mm_one_alpha;
mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
if (amask == 0xFF000000) { /* 1 in the alpha channel -> mm_one_alpha */
mm_one_alpha = _mm_set_pi16(1, 0, 0, 0);
} else if (amask == 0x00FF0000) {
mm_one_alpha = _mm_set_pi16(0, 1, 0, 0);
} else if (amask == 0x0000FF00) {
mm_one_alpha = _mm_set_pi16(0, 0, 1, 0);
} else {
mm_one_alpha = _mm_set_pi16(0, 0, 0, 1);
}
mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
multmask = 0x00FF;
multmask <<= (ashift * 2);
multmask2 = 0x00FF00FF00FF00FFULL;
@ -369,14 +371,33 @@ BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo * info)
mm_alpha = _mm_or_si64(mm_alpha2, *(__m64 *) & multmask); /* 0F0A0A0A -> mm_alpha */
mm_alpha2 = _mm_xor_si64(mm_alpha2, *(__m64 *) & multmask2); /* 255 - mm_alpha -> mm_alpha */
/* blend */
/*
Alpha blending is:
dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
dstA = srcA + (dstA * (1-srcA)) *
Here, 'src1' is:
srcRGB * srcA
srcA
And 'dst1' is:
dstRGB * (1-srcA)
dstA * (1-srcA)
so that *dstp is 'src1 + dst1'
src1 is computed using mullo_pi16: (X * mask) >> 8, but is approximate for srcA ((srcA * 255) >> 8).
need to a 1 to get an exact result: (srcA * 256) >> 8 == srcA
*/
mm_alpha = _mm_add_pi16(mm_alpha, mm_one_alpha);
/* blend */
src1 = _mm_mullo_pi16(src1, mm_alpha);
src1 = _mm_srli_pi16(src1, 8);
dst1 = _mm_mullo_pi16(dst1, mm_alpha2);
dst1 = _mm_srli_pi16(dst1, 8);
dst1 = _mm_add_pi16(src1, dst1);
dst1 = _mm_packs_pu16(dst1, mm_zero);
*dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
}
++srcp;
@ -394,8 +415,7 @@ BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo * info)
#if SDL_ARM_SIMD_BLITTERS
void BlitARGBto565PixelAlphaARMSIMDAsm(int32_t w, int32_t h, uint16_t *dst, int32_t dst_stride, uint32_t *src, int32_t src_stride);
static void
BlitARGBto565PixelAlphaARMSIMD(SDL_BlitInfo * info)
static void BlitARGBto565PixelAlphaARMSIMD(SDL_BlitInfo *info)
{
int32_t width = info->dst_w;
int32_t height = info->dst_h;
@ -409,8 +429,7 @@ BlitARGBto565PixelAlphaARMSIMD(SDL_BlitInfo * info)
void BlitRGBtoRGBPixelAlphaARMSIMDAsm(int32_t w, int32_t h, uint32_t *dst, int32_t dst_stride, uint32_t *src, int32_t src_stride);
static void
BlitRGBtoRGBPixelAlphaARMSIMD(SDL_BlitInfo * info)
static void BlitRGBtoRGBPixelAlphaARMSIMD(SDL_BlitInfo *info)
{
int32_t width = info->dst_w;
int32_t height = info->dst_h;
@ -426,8 +445,7 @@ BlitRGBtoRGBPixelAlphaARMSIMD(SDL_BlitInfo * info)
#if SDL_ARM_NEON_BLITTERS
void BlitARGBto565PixelAlphaARMNEONAsm(int32_t w, int32_t h, uint16_t *dst, int32_t dst_stride, uint32_t *src, int32_t src_stride);
static void
BlitARGBto565PixelAlphaARMNEON(SDL_BlitInfo * info)
static void BlitARGBto565PixelAlphaARMNEON(SDL_BlitInfo *info)
{
int32_t width = info->dst_w;
int32_t height = info->dst_h;
@ -441,8 +459,7 @@ BlitARGBto565PixelAlphaARMNEON(SDL_BlitInfo * info)
void BlitRGBtoRGBPixelAlphaARMNEONAsm(int32_t w, int32_t h, uint32_t *dst, int32_t dst_stride, uint32_t *src, int32_t src_stride);
static void
BlitRGBtoRGBPixelAlphaARMNEON(SDL_BlitInfo * info)
static void BlitRGBtoRGBPixelAlphaARMNEON(SDL_BlitInfo *info)
{
int32_t width = info->dst_w;
int32_t height = info->dst_h;
@ -456,14 +473,13 @@ BlitRGBtoRGBPixelAlphaARMNEON(SDL_BlitInfo * info)
#endif
/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
static void
BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo * info)
static void BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint32 *srcp = (Uint32 *) info->src;
Uint32 *srcp = (Uint32 *)info->src;
int srcskip = info->src_skip >> 2;
Uint32 *dstp = (Uint32 *) info->dst;
Uint32 *dstp = (Uint32 *)info->dst;
int dstskip = info->dst_skip >> 2;
while (height--) {
@ -481,8 +497,7 @@ BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo * info)
}
/* fast RGB888->(A)RGB888 blending with surface alpha */
static void
BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo * info)
static void BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo *info)
{
unsigned alpha = info->a;
if (alpha == 128) {
@ -490,9 +505,9 @@ BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo * info)
} else {
int width = info->dst_w;
int height = info->dst_h;
Uint32 *srcp = (Uint32 *) info->src;
Uint32 *srcp = (Uint32 *)info->src;
int srcskip = info->src_skip >> 2;
Uint32 *dstp = (Uint32 *) info->dst;
Uint32 *dstp = (Uint32 *)info->dst;
int dstskip = info->dst_skip >> 2;
Uint32 s;
Uint32 d;
@ -523,14 +538,13 @@ BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo * info)
}
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
static void
BlitRGBtoRGBPixelAlpha(SDL_BlitInfo * info)
static void BlitRGBtoRGBPixelAlpha(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint32 *srcp = (Uint32 *) info->src;
Uint32 *srcp = (Uint32 *)info->src;
int srcskip = info->src_skip >> 2;
Uint32 *dstp = (Uint32 *) info->dst;
Uint32 *dstp = (Uint32 *)info->dst;
int dstskip = info->dst_skip >> 2;
while (height--) {
@ -576,14 +590,13 @@ BlitRGBtoRGBPixelAlpha(SDL_BlitInfo * info)
}
/* fast ARGB888->(A)BGR888 blending with pixel alpha */
static void
BlitRGBtoBGRPixelAlpha(SDL_BlitInfo * info)
static void BlitRGBtoBGRPixelAlpha(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint32 *srcp = (Uint32 *) info->src;
Uint32 *srcp = (Uint32 *)info->src;
int srcskip = info->src_skip >> 2;
Uint32 *dstp = (Uint32 *) info->dst;
Uint32 *dstp = (Uint32 *)info->dst;
int dstskip = info->dst_skip >> 2;
while (height--) {
@ -632,23 +645,32 @@ BlitRGBtoBGRPixelAlpha(SDL_BlitInfo * info)
#ifdef __3dNOW__
/* fast (as in MMX with prefetch) ARGB888->(A)RGB888 blending with pixel alpha */
static void
BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo * info)
static void BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint32 *srcp = (Uint32 *) info->src;
Uint32 *srcp = (Uint32 *)info->src;
int srcskip = info->src_skip >> 2;
Uint32 *dstp = (Uint32 *) info->dst;
Uint32 *dstp = (Uint32 *)info->dst;
int dstskip = info->dst_skip >> 2;
SDL_PixelFormat *sf = info->src_fmt;
Uint32 amask = sf->Amask;
Uint32 ashift = sf->Ashift;
Uint64 multmask, multmask2;
__m64 src1, dst1, mm_alpha, mm_zero, mm_alpha2;
__m64 src1, dst1, mm_alpha, mm_zero, mm_alpha2, mm_one_alpha;
mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
if (amask == 0xFF000000) { /* 1 in the alpha channel -> mm_one_alpha */
mm_one_alpha = _mm_set_pi16(1, 0, 0, 0);
} else if (amask == 0x00FF0000) {
mm_one_alpha = _mm_set_pi16(0, 1, 0, 0);
} else if (amask == 0x0000FF00) {
mm_one_alpha = _mm_set_pi16(0, 0, 1, 0);
} else {
mm_one_alpha = _mm_set_pi16(0, 0, 0, 1);
}
mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
multmask = 0x00FF;
multmask <<= (ashift * 2);
multmask2 = 0x00FF00FF00FF00FFULL;
@ -680,15 +702,33 @@ BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo * info)
mm_alpha = _mm_or_si64(mm_alpha2, *(__m64 *) & multmask); /* 0F0A0A0A -> mm_alpha */
mm_alpha2 = _mm_xor_si64(mm_alpha2, *(__m64 *) & multmask2); /* 255 - mm_alpha -> mm_alpha */
/*
Alpha blending is:
dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
dstA = srcA + (dstA * (1-srcA)) *
/* blend */
Here, 'src1' is:
srcRGB * srcA
srcA
And 'dst1' is:
dstRGB * (1-srcA)
dstA * (1-srcA)
so that *dstp is 'src1 + dst1'
src1 is computed using mullo_pi16: (X * mask) >> 8, but is approximate for srcA ((srcA * 255) >> 8).
need to a 1 to get an exact result: (srcA * 256) >> 8 == srcA
*/
mm_alpha = _mm_add_pi16(mm_alpha, mm_one_alpha);
/* blend */
src1 = _mm_mullo_pi16(src1, mm_alpha);
src1 = _mm_srli_pi16(src1, 8);
dst1 = _mm_mullo_pi16(dst1, mm_alpha2);
dst1 = _mm_srli_pi16(dst1, 8);
dst1 = _mm_add_pi16(src1, dst1);
dst1 = _mm_packs_pu16(dst1, mm_zero);
*dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
}
++srcp;
@ -706,26 +746,24 @@ BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo * info)
/* 16bpp special case for per-surface alpha=50%: blend 2 pixels in parallel */
/* blend a single 16 bit pixel at 50% */
#define BLEND16_50(d, s, mask) \
#define BLEND16_50(d, s, mask) \
((((s & mask) + (d & mask)) >> 1) + (s & d & (~mask & 0xffff)))
/* blend two 16 bit pixels at 50% */
#define BLEND2x16_50(d, s, mask) \
(((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) \
+ (s & d & (~(mask | mask << 16))))
#define BLEND2x16_50(d, s, mask) \
(((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) + (s & d & (~(mask | mask << 16))))
static void
Blit16to16SurfaceAlpha128(SDL_BlitInfo * info, Uint16 mask)
static void Blit16to16SurfaceAlpha128(SDL_BlitInfo *info, Uint16 mask)
{
int width = info->dst_w;
int height = info->dst_h;
Uint16 *srcp = (Uint16 *) info->src;
Uint16 *srcp = (Uint16 *)info->src;
int srcskip = info->src_skip >> 1;
Uint16 *dstp = (Uint16 *) info->dst;
Uint16 *dstp = (Uint16 *)info->dst;
int dstskip = info->dst_skip >> 1;
while (height--) {
if (((uintptr_t) srcp ^ (uintptr_t) dstp) & 2) {
if (((uintptr_t)srcp ^ (uintptr_t)dstp) & 2) {
/*
* Source and destination not aligned, pipeline it.
* This is mostly a win for big blits but no loss for
@ -735,29 +773,29 @@ Blit16to16SurfaceAlpha128(SDL_BlitInfo * info, Uint16 mask)
int w = width;
/* handle odd destination */
if ((uintptr_t) dstp & 2) {
if ((uintptr_t)dstp & 2) {
Uint16 d = *dstp, s = *srcp;
*dstp = BLEND16_50(d, s, mask);
dstp++;
srcp++;
w--;
}
srcp++; /* srcp is now 32-bit aligned */
srcp++; /* srcp is now 32-bit aligned */
/* bootstrap pipeline with first halfword */
prev_sw = ((Uint32 *) srcp)[-1];
prev_sw = ((Uint32 *)srcp)[-1];
while (w > 1) {
Uint32 sw, dw, s;
sw = *(Uint32 *) srcp;
dw = *(Uint32 *) dstp;
sw = *(Uint32 *)srcp;
dw = *(Uint32 *)dstp;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
s = (prev_sw << 16) + (sw >> 16);
#else
s = (prev_sw >> 16) + (sw << 16);
#endif
prev_sw = sw;
*(Uint32 *) dstp = BLEND2x16_50(dw, s, mask);
*(Uint32 *)dstp = BLEND2x16_50(dw, s, mask);
dstp += 2;
srcp += 2;
w -= 2;
@ -767,9 +805,9 @@ Blit16to16SurfaceAlpha128(SDL_BlitInfo * info, Uint16 mask)
if (w) {
Uint16 d = *dstp, s;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
s = (Uint16) prev_sw;
s = (Uint16)prev_sw;
#else
s = (Uint16) (prev_sw >> 16);
s = (Uint16)(prev_sw >> 16);
#endif
*dstp = BLEND16_50(d, s, mask);
srcp++;
@ -782,7 +820,7 @@ Blit16to16SurfaceAlpha128(SDL_BlitInfo * info, Uint16 mask)
int w = width;
/* first odd pixel? */
if ((uintptr_t) srcp & 2) {
if ((uintptr_t)srcp & 2) {
Uint16 d = *dstp, s = *srcp;
*dstp = BLEND16_50(d, s, mask);
srcp++;
@ -792,9 +830,9 @@ Blit16to16SurfaceAlpha128(SDL_BlitInfo * info, Uint16 mask)
/* srcp and dstp are now 32-bit aligned */
while (w > 1) {
Uint32 sw = *(Uint32 *) srcp;
Uint32 dw = *(Uint32 *) dstp;
*(Uint32 *) dstp = BLEND2x16_50(dw, sw, mask);
Uint32 sw = *(Uint32 *)srcp;
Uint32 dw = *(Uint32 *)dstp;
*(Uint32 *)dstp = BLEND2x16_50(dw, sw, mask);
srcp += 2;
dstp += 2;
w -= 2;
@ -816,8 +854,7 @@ Blit16to16SurfaceAlpha128(SDL_BlitInfo * info, Uint16 mask)
#ifdef __MMX__
/* fast RGB565->RGB565 blending with surface alpha */
static void
Blit565to565SurfaceAlphaMMX(SDL_BlitInfo * info)
static void Blit565to565SurfaceAlphaMMX(SDL_BlitInfo *info)
{
unsigned alpha = info->a;
if (alpha == 128) {
@ -825,27 +862,29 @@ Blit565to565SurfaceAlphaMMX(SDL_BlitInfo * info)
} else {
int width = info->dst_w;
int height = info->dst_h;
Uint16 *srcp = (Uint16 *) info->src;
Uint16 *srcp = (Uint16 *)info->src;
int srcskip = info->src_skip >> 1;
Uint16 *dstp = (Uint16 *) info->dst;
Uint16 *dstp = (Uint16 *)info->dst;
int dstskip = info->dst_skip >> 1;
Uint32 s, d;
#ifdef USE_DUFFS_LOOP
__m64 src1, dst1, src2, dst2, gmask, bmask, mm_res, mm_alpha;
alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */
mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */
alpha >>= 3; /* downscale alpha to 5 bits */
alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */
mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */
alpha >>= 3; /* downscale alpha to 5 bits */
mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */
mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */
/* position alpha to allow for mullo and mulhi on diff channels
to reduce the number of operations */
mm_alpha = _mm_slli_si64(mm_alpha, 3);
/* Setup the 565 color channel masks */
gmask = _mm_set_pi32(0x07E007E0, 0x07E007E0); /* MASKGREEN -> gmask */
bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */
gmask = _mm_set_pi32(0x07E007E0, 0x07E007E0); /* MASKGREEN -> gmask */
bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */
#endif
while (height--) {
/* *INDENT-OFF* */ /* clang-format off */
@ -953,8 +992,7 @@ Blit565to565SurfaceAlphaMMX(SDL_BlitInfo * info)
}
/* fast RGB555->RGB555 blending with surface alpha */
static void
Blit555to555SurfaceAlphaMMX(SDL_BlitInfo * info)
static void Blit555to555SurfaceAlphaMMX(SDL_BlitInfo *info)
{
unsigned alpha = info->a;
if (alpha == 128) {
@ -962,29 +1000,30 @@ Blit555to555SurfaceAlphaMMX(SDL_BlitInfo * info)
} else {
int width = info->dst_w;
int height = info->dst_h;
Uint16 *srcp = (Uint16 *) info->src;
Uint16 *srcp = (Uint16 *)info->src;
int srcskip = info->src_skip >> 1;
Uint16 *dstp = (Uint16 *) info->dst;
Uint16 *dstp = (Uint16 *)info->dst;
int dstskip = info->dst_skip >> 1;
Uint32 s, d;
#ifdef USE_DUFFS_LOOP
__m64 src1, dst1, src2, dst2, rmask, gmask, bmask, mm_res, mm_alpha;
alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */
mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */
alpha >>= 3; /* downscale alpha to 5 bits */
alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */
mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */
alpha >>= 3; /* downscale alpha to 5 bits */
mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */
mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */
/* position alpha to allow for mullo and mulhi on diff channels
to reduce the number of operations */
mm_alpha = _mm_slli_si64(mm_alpha, 3);
/* Setup the 555 color channel masks */
rmask = _mm_set_pi32(0x7C007C00, 0x7C007C00); /* MASKRED -> rmask */
gmask = _mm_set_pi32(0x03E003E0, 0x03E003E0); /* MASKGREEN -> gmask */
bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */
rmask = _mm_set_pi32(0x7C007C00, 0x7C007C00); /* MASKRED -> rmask */
gmask = _mm_set_pi32(0x03E003E0, 0x03E003E0); /* MASKGREEN -> gmask */
bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */
#endif
while (height--) {
/* *INDENT-OFF* */ /* clang-format off */
DUFFS_LOOP_124(
@ -1045,7 +1084,7 @@ Blit555to555SurfaceAlphaMMX(SDL_BlitInfo * info)
dst2 = _mm_and_si64(dst2, rmask); /* dst2 & MASKRED -> dst2 */
mm_res = dst2; /* RED -> mm_res */
/* green -- process the bits in place */
src2 = src1;
src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */
@ -1093,8 +1132,7 @@ Blit555to555SurfaceAlphaMMX(SDL_BlitInfo * info)
#endif /* __MMX__ */
/* fast RGB565->RGB565 blending with surface alpha */
static void
Blit565to565SurfaceAlpha(SDL_BlitInfo * info)
static void Blit565to565SurfaceAlpha(SDL_BlitInfo *info)
{
unsigned alpha = info->a;
if (alpha == 128) {
@ -1102,11 +1140,11 @@ Blit565to565SurfaceAlpha(SDL_BlitInfo * info)
} else {
int width = info->dst_w;
int height = info->dst_h;
Uint16 *srcp = (Uint16 *) info->src;
Uint16 *srcp = (Uint16 *)info->src;
int srcskip = info->src_skip >> 1;
Uint16 *dstp = (Uint16 *) info->dst;
Uint16 *dstp = (Uint16 *)info->dst;
int dstskip = info->dst_skip >> 1;
alpha >>= 3; /* downscale alpha to 5 bits */
alpha >>= 3; /* downscale alpha to 5 bits */
while (height--) {
/* *INDENT-OFF* */ /* clang-format off */
@ -1132,20 +1170,19 @@ Blit565to565SurfaceAlpha(SDL_BlitInfo * info)
}
/* fast RGB555->RGB555 blending with surface alpha */
static void
Blit555to555SurfaceAlpha(SDL_BlitInfo * info)
static void Blit555to555SurfaceAlpha(SDL_BlitInfo *info)
{
unsigned alpha = info->a; /* downscale alpha to 5 bits */
unsigned alpha = info->a; /* downscale alpha to 5 bits */
if (alpha == 128) {
Blit16to16SurfaceAlpha128(info, 0xfbde);
} else {
int width = info->dst_w;
int height = info->dst_h;
Uint16 *srcp = (Uint16 *) info->src;
Uint16 *srcp = (Uint16 *)info->src;
int srcskip = info->src_skip >> 1;
Uint16 *dstp = (Uint16 *) info->dst;
Uint16 *dstp = (Uint16 *)info->dst;
int dstskip = info->dst_skip >> 1;
alpha >>= 3; /* downscale alpha to 5 bits */
alpha >>= 3; /* downscale alpha to 5 bits */
while (height--) {
/* *INDENT-OFF* */ /* clang-format off */
@ -1171,14 +1208,13 @@ Blit555to555SurfaceAlpha(SDL_BlitInfo * info)
}
/* fast ARGB8888->RGB565 blending with pixel alpha */
static void
BlitARGBto565PixelAlpha(SDL_BlitInfo * info)
static void BlitARGBto565PixelAlpha(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint32 *srcp = (Uint32 *) info->src;
Uint32 *srcp = (Uint32 *)info->src;
int srcskip = info->src_skip >> 2;
Uint16 *dstp = (Uint16 *) info->dst;
Uint16 *dstp = (Uint16 *)info->dst;
int dstskip = info->dst_skip >> 1;
while (height--) {
@ -1190,8 +1226,8 @@ BlitARGBto565PixelAlpha(SDL_BlitInfo * info)
compositioning used (>>8 instead of /255) doesn't handle
it correctly. Also special-case alpha=0 for speed?
Benchmark this! */
if(alpha) {
if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
if (alpha) {
if (alpha == (SDL_ALPHA_OPAQUE >> 3)) {
*dstp = (Uint16)((s >> 8 & 0xf800) + (s >> 5 & 0x7e0) + (s >> 3 & 0x1f));
} else {
Uint32 d = *dstp;
@ -1217,14 +1253,13 @@ BlitARGBto565PixelAlpha(SDL_BlitInfo * info)
}
/* fast ARGB8888->RGB555 blending with pixel alpha */
static void
BlitARGBto555PixelAlpha(SDL_BlitInfo * info)
static void BlitARGBto555PixelAlpha(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint32 *srcp = (Uint32 *) info->src;
Uint32 *srcp = (Uint32 *)info->src;
int srcskip = info->src_skip >> 2;
Uint16 *dstp = (Uint16 *) info->dst;
Uint16 *dstp = (Uint16 *)info->dst;
int dstskip = info->dst_skip >> 1;
while (height--) {
@ -1237,8 +1272,8 @@ BlitARGBto555PixelAlpha(SDL_BlitInfo * info)
compositioning used (>>8 instead of /255) doesn't handle
it correctly. Also special-case alpha=0 for speed?
Benchmark this! */
if(alpha) {
if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
if (alpha) {
if (alpha == (SDL_ALPHA_OPAQUE >> 3)) {
*dstp = (Uint16)((s >> 9 & 0x7c00) + (s >> 6 & 0x3e0) + (s >> 3 & 0x1f));
} else {
Uint32 d = *dstp;
@ -1264,8 +1299,7 @@ BlitARGBto555PixelAlpha(SDL_BlitInfo * info)
}
/* General (slow) N->N blending with per-surface alpha */
static void
BlitNtoNSurfaceAlpha(SDL_BlitInfo * info)
static void BlitNtoNSurfaceAlpha(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -1284,7 +1318,7 @@ BlitNtoNSurfaceAlpha(SDL_BlitInfo * info)
if (sA) {
while (height--) {
/* *INDENT-OFF* */ /* clang-format off */
/* *INDENT-OFF* */ /* clang-format off */
DUFFS_LOOP4(
{
DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
@ -1303,8 +1337,7 @@ BlitNtoNSurfaceAlpha(SDL_BlitInfo * info)
}
/* General (slow) colorkeyed N->N blending with per-surface alpha */
static void
BlitNtoNSurfaceAlphaKey(SDL_BlitInfo * info)
static void BlitNtoNSurfaceAlphaKey(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -1327,7 +1360,7 @@ BlitNtoNSurfaceAlphaKey(SDL_BlitInfo * info)
DUFFS_LOOP4(
{
RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel);
if(sA && Pixel != ckey) {
if (sA && Pixel != ckey) {
RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB);
DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
@ -1344,8 +1377,7 @@ BlitNtoNSurfaceAlphaKey(SDL_BlitInfo * info)
}
/* General (slow) N->N blending with pixel alpha */
static void
BlitNtoNPixelAlpha(SDL_BlitInfo * info)
static void BlitNtoNPixelAlpha(SDL_BlitInfo *info)
{
int width = info->dst_w;
int height = info->dst_h;
@ -1370,7 +1402,7 @@ BlitNtoNPixelAlpha(SDL_BlitInfo * info)
DUFFS_LOOP4(
{
DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
if(sA) {
if (sA) {
DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
@ -1385,9 +1417,7 @@ BlitNtoNPixelAlpha(SDL_BlitInfo * info)
}
}
SDL_BlitFunc
SDL_CalculateBlitA(SDL_Surface * surface)
SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface)
{
SDL_PixelFormat *sf = surface->format;
SDL_PixelFormat *df = surface->map->dst->format;
@ -1406,65 +1436,58 @@ SDL_CalculateBlitA(SDL_Surface * surface)
case 2:
#if SDL_ARM_NEON_BLITTERS || SDL_ARM_SIMD_BLITTERS
if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000
&& sf->Gmask == 0xff00 && df->Gmask == 0x7e0
&& ((sf->Rmask == 0xff && df->Rmask == 0x1f)
|| (sf->Bmask == 0xff && df->Bmask == 0x1f)))
{
if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000 && sf->Gmask == 0xff00 && df->Gmask == 0x7e0 && ((sf->Rmask == 0xff && df->Rmask == 0x1f) || (sf->Bmask == 0xff && df->Bmask == 0x1f))) {
#if SDL_ARM_NEON_BLITTERS
if (SDL_HasNEON())
return BlitARGBto565PixelAlphaARMNEON;
#endif
#if SDL_ARM_SIMD_BLITTERS
if (SDL_HasARMSIMD())
return BlitARGBto565PixelAlphaARMSIMD;
#endif
if (SDL_HasNEON()) {
return BlitARGBto565PixelAlphaARMNEON;
}
#endif
if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000
&& sf->Gmask == 0xff00
&& ((sf->Rmask == 0xff && df->Rmask == 0x1f)
|| (sf->Bmask == 0xff && df->Bmask == 0x1f))) {
if (df->Gmask == 0x7e0)
#if SDL_ARM_SIMD_BLITTERS
if (SDL_HasARMSIMD()) {
return BlitARGBto565PixelAlphaARMSIMD;
}
#endif
}
#endif
if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000 && sf->Gmask == 0xff00 && ((sf->Rmask == 0xff && df->Rmask == 0x1f) || (sf->Bmask == 0xff && df->Bmask == 0x1f))) {
if (df->Gmask == 0x7e0) {
return BlitARGBto565PixelAlpha;
else if (df->Gmask == 0x3e0)
} else if (df->Gmask == 0x3e0) {
return BlitARGBto555PixelAlpha;
}
}
return BlitNtoNPixelAlpha;
case 4:
if (sf->Rmask == df->Rmask
&& sf->Gmask == df->Gmask
&& sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) {
if (sf->Rmask == df->Rmask && sf->Gmask == df->Gmask && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) {
#if defined(__MMX__) || defined(__3dNOW__)
if (sf->Rshift % 8 == 0
&& sf->Gshift % 8 == 0
&& sf->Bshift % 8 == 0
&& sf->Ashift % 8 == 0 && sf->Aloss == 0) {
if (sf->Rshift % 8 == 0 && sf->Gshift % 8 == 0 && sf->Bshift % 8 == 0 && sf->Ashift % 8 == 0 && sf->Aloss == 0) {
#ifdef __3dNOW__
if (SDL_Has3DNow())
if (SDL_Has3DNow()) {
return BlitRGBtoRGBPixelAlphaMMX3DNOW;
}
#endif
#ifdef __MMX__
if (SDL_HasMMX())
if (SDL_HasMMX()) {
return BlitRGBtoRGBPixelAlphaMMX;
}
#endif
}
#endif /* __MMX__ || __3dNOW__ */
if (sf->Amask == 0xff000000) {
#if SDL_ARM_NEON_BLITTERS
if (SDL_HasNEON())
if (SDL_HasNEON()) {
return BlitRGBtoRGBPixelAlphaARMNEON;
}
#endif
#if SDL_ARM_SIMD_BLITTERS
if (SDL_HasARMSIMD())
if (SDL_HasARMSIMD()) {
return BlitRGBtoRGBPixelAlphaARMSIMD;
}
#endif
return BlitRGBtoRGBPixelAlpha;
}
} else if (sf->Rmask == df->Bmask
&& sf->Gmask == df->Gmask
&& sf->Bmask == df->Rmask && sf->BytesPerPixel == 4) {
} else if (sf->Rmask == df->Bmask && sf->Gmask == df->Gmask && sf->Bmask == df->Rmask && sf->BytesPerPixel == 4) {
if (sf->Amask == 0xff000000) {
return BlitRGBtoBGRPixelAlpha;
}
@ -1493,31 +1516,32 @@ SDL_CalculateBlitA(SDL_Surface * surface)
if (surface->map->identity) {
if (df->Gmask == 0x7e0) {
#ifdef __MMX__
if (SDL_HasMMX())
if (SDL_HasMMX()) {
return Blit565to565SurfaceAlphaMMX;
else
} else
#endif
{
return Blit565to565SurfaceAlpha;
}
} else if (df->Gmask == 0x3e0) {
#ifdef __MMX__
if (SDL_HasMMX())
if (SDL_HasMMX()) {
return Blit555to555SurfaceAlphaMMX;
else
} else
#endif
{
return Blit555to555SurfaceAlpha;
}
}
}
return BlitNtoNSurfaceAlpha;
case 4:
if (sf->Rmask == df->Rmask
&& sf->Gmask == df->Gmask
&& sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) {
if (sf->Rmask == df->Rmask && sf->Gmask == df->Gmask && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) {
#ifdef __MMX__
if (sf->Rshift % 8 == 0
&& sf->Gshift % 8 == 0
&& sf->Bshift % 8 == 0 && SDL_HasMMX())
if (sf->Rshift % 8 == 0 && sf->Gshift % 8 == 0 && sf->Bshift % 8 == 0 && SDL_HasMMX()) {
return BlitRGBtoRGBSurfaceAlphaMMX;
}
#endif
if ((sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff) {
return BlitRGBtoRGBSurfaceAlpha;

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
/* DO NOT EDIT! This file is generated by sdlgenblit.pl */
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -823,7 +823,6 @@ static void SDL_Blit_RGB888_ARGB8888_Blend(SDL_BlitInfo *info)
dstR = (srcR * dstR) / 255;
dstG = (srcG * dstG) / 255;
dstB = (srcB * dstB) / 255;
dstA = 0xFF;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -886,7 +885,6 @@ static void SDL_Blit_RGB888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
dstR = (srcR * dstR) / 255;
dstG = (srcG * dstG) / 255;
dstB = (srcB * dstB) / 255;
dstA = 0xFF;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -1033,7 +1031,6 @@ static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -1114,7 +1111,6 @@ static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -1923,7 +1919,6 @@ static void SDL_Blit_BGR888_ARGB8888_Blend(SDL_BlitInfo *info)
dstR = (srcR * dstR) / 255;
dstG = (srcG * dstG) / 255;
dstB = (srcB * dstB) / 255;
dstA = 0xFF;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -1986,7 +1981,6 @@ static void SDL_Blit_BGR888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
dstR = (srcR * dstR) / 255;
dstG = (srcG * dstG) / 255;
dstB = (srcB * dstB) / 255;
dstA = 0xFF;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -2133,7 +2127,6 @@ static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -2214,7 +2207,6 @@ static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -3068,7 +3060,6 @@ static void SDL_Blit_ARGB8888_ARGB8888_Blend(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -3139,7 +3130,6 @@ static void SDL_Blit_ARGB8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -3292,7 +3282,6 @@ static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -3375,7 +3364,6 @@ static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -4232,7 +4220,6 @@ static void SDL_Blit_RGBA8888_ARGB8888_Blend(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -4303,7 +4290,6 @@ static void SDL_Blit_RGBA8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -4456,7 +4442,6 @@ static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -4539,7 +4524,6 @@ static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -5398,7 +5382,6 @@ static void SDL_Blit_ABGR8888_ARGB8888_Blend(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -5469,7 +5452,6 @@ static void SDL_Blit_ABGR8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -5622,7 +5604,6 @@ static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -5705,7 +5686,6 @@ static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -6564,7 +6544,6 @@ static void SDL_Blit_BGRA8888_ARGB8888_Blend(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -6635,7 +6614,6 @@ static void SDL_Blit_BGRA8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -6788,7 +6766,6 @@ static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
@ -6871,7 +6848,6 @@ static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255; if (dstR > 255) dstR = 255;
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255; if (dstG > 255) dstG = 255;
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255; if (dstB > 255) dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255; if (dstA > 255) dstA = 255;
break;
}
dstpixel = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;

View file

@ -1,7 +1,7 @@
/* DO NOT EDIT! This file is generated by sdlgenblit.pl */
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,11 +23,11 @@
#if SDL_HAVE_BLIT_AUTO
/* *INDENT-OFF* */
/* *INDENT-OFF* */ /* clang-format off */
extern SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[];
/* *INDENT-ON* */
/* *INDENT-ON* */ /* clang-format on */
#endif /* SDL_HAVE_BLIT_AUTO */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,48 +24,46 @@
#include "SDL_blit.h"
#include "SDL_blit_copy.h"
#ifdef __SSE__
/* This assumes 16-byte aligned src and dst */
static SDL_INLINE void
SDL_memcpySSE(Uint8 * dst, const Uint8 * src, int len)
static SDL_INLINE void SDL_memcpySSE(Uint8 *dst, const Uint8 *src, int len)
{
int i;
__m128 values[4];
for (i = len / 64; i--;) {
_mm_prefetch((const char *)src, _MM_HINT_NTA);
values[0] = *(__m128 *) (src + 0);
values[1] = *(__m128 *) (src + 16);
values[2] = *(__m128 *) (src + 32);
values[3] = *(__m128 *) (src + 48);
_mm_stream_ps((float *) (dst + 0), values[0]);
_mm_stream_ps((float *) (dst + 16), values[1]);
_mm_stream_ps((float *) (dst + 32), values[2]);
_mm_stream_ps((float *) (dst + 48), values[3]);
values[0] = *(__m128 *)(src + 0);
values[1] = *(__m128 *)(src + 16);
values[2] = *(__m128 *)(src + 32);
values[3] = *(__m128 *)(src + 48);
_mm_stream_ps((float *)(dst + 0), values[0]);
_mm_stream_ps((float *)(dst + 16), values[1]);
_mm_stream_ps((float *)(dst + 32), values[2]);
_mm_stream_ps((float *)(dst + 48), values[3]);
src += 64;
dst += 64;
}
if (len & 63)
if (len & 63) {
SDL_memcpy(dst, src, len & 63);
}
}
#endif /* __SSE__ */
#ifdef __MMX__
#ifdef _MSC_VER
#pragma warning(disable:4799)
#pragma warning(disable : 4799)
#endif
static SDL_INLINE void
SDL_memcpyMMX(Uint8 * dst, const Uint8 * src, int len)
static SDL_INLINE void SDL_memcpyMMX(Uint8 *dst, const Uint8 *src, int len)
{
const int remain = (len & 63);
int remain = len & 63;
int i;
__m64* d64 = (__m64*)dst;
__m64* s64 = (__m64*)src;
__m64 *d64 = (__m64 *)dst;
__m64 *s64 = (__m64 *)src;
for(i= len / 64; i--;) {
for (i = len / 64; i--;) {
d64[0] = s64[0];
d64[1] = s64[1];
d64[2] = s64[2];
@ -79,16 +77,18 @@ SDL_memcpyMMX(Uint8 * dst, const Uint8 * src, int len)
s64 += 8;
}
if (remain)
{
if (remain) {
const int skip = len - remain;
SDL_memcpy(dst + skip, src + skip, remain);
dst += skip;
src += skip;
while (remain--) {
*dst++ = *src++;
}
}
}
#endif /* __MMX__ */
void
SDL_BlitCopy(SDL_BlitInfo * info)
void SDL_BlitCopy(SDL_BlitInfo *info)
{
SDL_bool overlap;
Uint8 *src, *dst;
@ -104,33 +104,33 @@ SDL_BlitCopy(SDL_BlitInfo * info)
/* Properly handle overlapping blits */
if (src < dst) {
overlap = (dst < (src + h*srcskip));
overlap = (dst < (src + h * srcskip));
} else {
overlap = (src < (dst + h*dstskip));
overlap = (src < (dst + h * dstskip));
}
if (overlap) {
if ( dst < src ) {
while ( h-- ) {
SDL_memmove(dst, src, w);
src += srcskip;
dst += dstskip;
}
if (dst < src) {
while (h--) {
SDL_memmove(dst, src, w);
src += srcskip;
dst += dstskip;
}
} else {
src += ((h-1) * srcskip);
dst += ((h-1) * dstskip);
while ( h-- ) {
SDL_memmove(dst, src, w);
src -= srcskip;
dst -= dstskip;
}
src += ((h - 1) * srcskip);
dst += ((h - 1) * dstskip);
while (h--) {
SDL_memmove(dst, src, w);
src -= srcskip;
dst -= dstskip;
}
}
return;
}
#ifdef __SSE__
if (SDL_HasSSE() &&
!((uintptr_t) src & 15) && !(srcskip & 15) &&
!((uintptr_t) dst & 15) && !(dstskip & 15)) {
!((uintptr_t)src & 15) && !(srcskip & 15) &&
!((uintptr_t)dst & 15) && !(dstskip & 15)) {
while (h--) {
SDL_memcpySSE(dst, src, w);
src += srcskip;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,7 +22,7 @@
#ifndef SDL_blit_copy_h_
#define SDL_blit_copy_h_
void SDL_BlitCopy(SDL_BlitInfo * info);
void SDL_BlitCopy(SDL_BlitInfo *info);
#endif /* SDL_blit_copy_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,12 +24,13 @@
#include "SDL_blit.h"
#include "SDL_blit_slow.h"
#define FORMAT_ALPHA 0
#define FORMAT_NO_ALPHA -1
#define FORMAT_2101010 1
#define FORMAT_HAS_ALPHA(format) format == 0
#define FORMAT_HAS_NO_ALPHA(format) format < 0
static int SDL_INLINE detect_format(SDL_PixelFormat *pf) {
#define FORMAT_ALPHA 0
#define FORMAT_NO_ALPHA -1
#define FORMAT_2101010 1
#define FORMAT_HAS_ALPHA(format) format == 0
#define FORMAT_HAS_NO_ALPHA(format) format < 0
static int SDL_INLINE detect_format(SDL_PixelFormat *pf)
{
if (pf->format == SDL_PIXELFORMAT_ARGB2101010) {
return FORMAT_2101010;
} else if (pf->Amask) {
@ -42,8 +43,7 @@ static int SDL_INLINE detect_format(SDL_PixelFormat *pf) {
/* The ONE TRUE BLITTER
* This puppy has to handle all the unoptimized cases - yes, it's slow.
*/
void
SDL_Blit_Slow(SDL_BlitInfo * info)
void SDL_Blit_Slow(SDL_BlitInfo *info)
{
const int flags = info->flags;
const Uint32 modulateR = info->r;
@ -98,7 +98,7 @@ SDL_Blit_Slow(SDL_BlitInfo * info)
/* srcpixel isn't set for 24 bpp */
if (srcbpp == 3) {
srcpixel = (srcR << src_fmt->Rshift) |
(srcG << src_fmt->Gshift) | (srcB << src_fmt->Bshift);
(srcG << src_fmt->Gshift) | (srcB << src_fmt->Bshift);
}
if ((srcpixel & rgbmask) == ckey) {
posx += incx;
@ -148,14 +148,17 @@ SDL_Blit_Slow(SDL_BlitInfo * info)
break;
case SDL_COPY_ADD:
dstR = srcR + dstR;
if (dstR > 255)
if (dstR > 255) {
dstR = 255;
}
dstG = srcG + dstG;
if (dstG > 255)
if (dstG > 255) {
dstG = 255;
}
dstB = srcB + dstB;
if (dstB > 255)
if (dstB > 255) {
dstB = 255;
}
break;
case SDL_COPY_MOD:
dstR = (srcR * dstR) / 255;
@ -164,17 +167,17 @@ SDL_Blit_Slow(SDL_BlitInfo * info)
break;
case SDL_COPY_MUL:
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255;
if (dstR > 255)
if (dstR > 255) {
dstR = 255;
}
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255;
if (dstG > 255)
if (dstG > 255) {
dstG = 255;
}
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255;
if (dstB > 255)
if (dstB > 255) {
dstB = 255;
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255;
if (dstA > 255)
dstA = 255;
}
break;
}
if (FORMAT_HAS_ALPHA(dstfmt_val)) {

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,7 +24,7 @@
#include "../SDL_internal.h"
extern void SDL_Blit_Slow(SDL_BlitInfo * info);
extern void SDL_Blit_Slow(SDL_BlitInfo *info);
#endif /* SDL_blit_slow_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -41,19 +41,19 @@
/* Compression encodings for BMP files */
#ifndef BI_RGB
#define BI_RGB 0
#define BI_RLE8 1
#define BI_RLE4 2
#define BI_BITFIELDS 3
#define BI_RGB 0
#define BI_RLE8 1
#define BI_RLE4 2
#define BI_BITFIELDS 3
#endif
/* Logical color space values for BMP files */
#ifndef LCS_WINDOWS_COLOR_SPACE
/* 0x57696E20 == "Win " */
#define LCS_WINDOWS_COLOR_SPACE 0x57696E20
#define LCS_WINDOWS_COLOR_SPACE 0x57696E20
#endif
static SDL_bool readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8)
static SDL_bool readRlePixels(SDL_Surface *surface, SDL_RWops *src, int isRle8)
{
/*
| Sets the surface pixels from src. A bmp image is upside down.
@ -61,35 +61,46 @@ static SDL_bool readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8
int pitch = surface->pitch;
int height = surface->h;
Uint8 *start = (Uint8 *)surface->pixels;
Uint8 *end = start + (height*pitch);
Uint8 *bits = end-pitch, *spot;
Uint8 *end = start + (height * pitch);
Uint8 *bits = end - pitch, *spot;
int ofs = 0;
Uint8 ch;
Uint8 needsPad;
#define COPY_PIXEL(x) spot = &bits[ofs++]; if(spot >= start && spot < end) *spot = (x)
#define COPY_PIXEL(x) \
spot = &bits[ofs++]; \
if (spot >= start && spot < end) \
*spot = (x)
for (;;) {
if (!SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE;
if (!SDL_RWread(src, &ch, 1, 1)) {
return SDL_TRUE;
}
/*
| encoded mode starts with a run length, and then a byte
| with two colour indexes to alternate between for the run
*/
if (ch) {
Uint8 pixel;
if (!SDL_RWread(src, &pixel, 1, 1)) return SDL_TRUE;
if (isRle8) { /* 256-color bitmap, compressed */
if (!SDL_RWread(src, &pixel, 1, 1)) {
return SDL_TRUE;
}
if (isRle8) { /* 256-color bitmap, compressed */
do {
COPY_PIXEL(pixel);
} while (--ch);
} else { /* 16-color bitmap, compressed */
} else { /* 16-color bitmap, compressed */
Uint8 pixel0 = pixel >> 4;
Uint8 pixel1 = pixel & 0x0F;
for (;;) {
COPY_PIXEL(pixel0); /* even count, high nibble */
if (!--ch) break;
if (!--ch) {
break;
}
COPY_PIXEL(pixel1); /* odd count, low nibble */
if (!--ch) break;
if (!--ch) {
break;
}
}
}
} else {
@ -98,41 +109,57 @@ static SDL_bool readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8
| a cursor move, or some absolute data.
| zero tag may be absolute mode or an escape
*/
if (!SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE;
if (!SDL_RWread(src, &ch, 1, 1)) {
return SDL_TRUE;
}
switch (ch) {
case 0: /* end of line */
case 0: /* end of line */
ofs = 0;
bits -= pitch; /* go to previous */
bits -= pitch; /* go to previous */
break;
case 1: /* end of bitmap */
return SDL_FALSE; /* success! */
case 2: /* delta */
if (!SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE;
case 1: /* end of bitmap */
return SDL_FALSE; /* success! */
case 2: /* delta */
if (!SDL_RWread(src, &ch, 1, 1)) {
return SDL_TRUE;
}
ofs += ch;
if (!SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE;
if (!SDL_RWread(src, &ch, 1, 1)) {
return SDL_TRUE;
}
bits -= (ch * pitch);
break;
default: /* no compression */
default: /* no compression */
if (isRle8) {
needsPad = (ch & 1);
do {
Uint8 pixel;
if (!SDL_RWread(src, &pixel, 1, 1)) return SDL_TRUE;
if (!SDL_RWread(src, &pixel, 1, 1)) {
return SDL_TRUE;
}
COPY_PIXEL(pixel);
} while (--ch);
} else {
needsPad = (((ch+1)>>1) & 1); /* (ch+1)>>1: bytes size */
needsPad = (((ch + 1) >> 1) & 1); /* (ch+1)>>1: bytes size */
for (;;) {
Uint8 pixel;
if (!SDL_RWread(src, &pixel, 1, 1)) return SDL_TRUE;
if (!SDL_RWread(src, &pixel, 1, 1)) {
return SDL_TRUE;
}
COPY_PIXEL(pixel >> 4);
if (!--ch) break;
if (!--ch) {
break;
}
COPY_PIXEL(pixel & 0x0F);
if (!--ch) break;
if (!--ch) {
break;
}
}
}
/* pad at even boundary */
if (needsPad && !SDL_RWread(src, &ch, 1, 1)) return SDL_TRUE;
if (needsPad && !SDL_RWread(src, &ch, 1, 1)) {
return SDL_TRUE;
}
break;
}
}
@ -148,7 +175,7 @@ static void CorrectAlphaChannel(SDL_Surface *surface)
#else
int alphaChannelOffset = 3;
#endif
Uint8 *alpha = ((Uint8*)surface->pixels) + alphaChannelOffset;
Uint8 *alpha = ((Uint8 *)surface->pixels) + alphaChannelOffset;
Uint8 *end = alpha + surface->h * surface->pitch;
while (alpha < end) {
@ -160,7 +187,7 @@ static void CorrectAlphaChannel(SDL_Surface *surface)
}
if (!hasAlpha) {
alpha = ((Uint8*)surface->pixels) + alphaChannelOffset;
alpha = ((Uint8 *)surface->pixels) + alphaChannelOffset;
while (alpha < end) {
*alpha = SDL_ALPHA_OPAQUE;
alpha += 4;
@ -168,8 +195,7 @@ static void CorrectAlphaChannel(SDL_Surface *surface)
}
}
SDL_Surface *
SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
SDL_Surface *SDL_LoadBMP_RW(SDL_RWops *src, int freesrc)
{
SDL_bool was_error;
Sint64 fp_offset = 0;
@ -238,13 +264,13 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
/* bfSize = */ SDL_ReadLE32(src);
/* bfReserved1 = */ SDL_ReadLE16(src);
/* bfReserved2 = */ SDL_ReadLE16(src);
bfOffBits = SDL_ReadLE32(src);
bfOffBits = SDL_ReadLE32(src);
/* Read the Win32 BITMAPINFOHEADER */
biSize = SDL_ReadLE32(src);
if (biSize == 12) { /* really old BITMAPCOREHEADER */
biWidth = (Uint32) SDL_ReadLE16(src);
biHeight = (Uint32) SDL_ReadLE16(src);
if (biSize == 12) { /* really old BITMAPCOREHEADER */
biWidth = (Uint32)SDL_ReadLE16(src);
biHeight = (Uint32)SDL_ReadLE16(src);
/* biPlanes = */ SDL_ReadLE16(src);
biBitCount = SDL_ReadLE16(src);
biCompression = BI_RGB;
@ -253,7 +279,7 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
/* biYPelsPerMeter = 0; */
biClrUsed = 0;
/* biClrImportant = 0; */
} else if (biSize >= 40) { /* some version of BITMAPINFOHEADER */
} else if (biSize >= 40) { /* some version of BITMAPINFOHEADER */
Uint32 headerSize;
biWidth = SDL_ReadLE32(src);
biHeight = SDL_ReadLE32(src);
@ -282,18 +308,18 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
Bmask = SDL_ReadLE32(src);
/* ...v3 adds an alpha mask. */
if (biSize >= 56) { /* BITMAPV3INFOHEADER; adds alpha mask */
if (biSize >= 56) { /* BITMAPV3INFOHEADER; adds alpha mask */
haveAlphaMask = SDL_TRUE;
Amask = SDL_ReadLE32(src);
}
} else {
/* the mask fields are ignored for v2+ headers if not BI_BITFIELD. */
if (biSize >= 52) { /* BITMAPV2INFOHEADER; adds RGB masks */
if (biSize >= 52) { /* BITMAPV2INFOHEADER; adds RGB masks */
/*Rmask = */ SDL_ReadLE32(src);
/*Gmask = */ SDL_ReadLE32(src);
/*Bmask = */ SDL_ReadLE32(src);
}
if (biSize >= 56) { /* BITMAPV3INFOHEADER; adds alpha mask */
if (biSize >= 56) { /* BITMAPV3INFOHEADER; adds alpha mask */
/*Amask = */ SDL_ReadLE32(src);
}
}
@ -305,7 +331,7 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
}
/* skip any header bytes we didn't handle... */
headerSize = (Uint32) (SDL_RWtell(src) - (fp_offset + 14));
headerSize = (Uint32)(SDL_RWtell(src) - (fp_offset + 14));
if (biSize > headerSize) {
SDL_RWseek(src, (biSize - headerSize), RW_SEEK_CUR);
}
@ -328,15 +354,15 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
goto done;
}
/* Expand 1 and 4 bit bitmaps to 8 bits per pixel */
/* Expand 1, 2 and 4 bit bitmaps to 8 bits per pixel */
switch (biBitCount) {
case 1:
case 2:
case 4:
ExpandBMP = biBitCount;
biBitCount = 8;
break;
case 0:
case 2:
case 3:
case 5:
case 6:
@ -388,7 +414,7 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
break;
case BI_BITFIELDS:
break; /* we handled this in the info header. */
break; /* we handled this in the info header. */
default:
break;
@ -406,13 +432,13 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
/* Load the palette, if any */
palette = (surface->format)->palette;
if (palette) {
if (SDL_RWseek(src, fp_offset+14+biSize, RW_SEEK_SET) < 0) {
if (SDL_RWseek(src, fp_offset + 14 + biSize, RW_SEEK_SET) < 0) {
SDL_Error(SDL_EFSEEK);
was_error = SDL_TRUE;
goto done;
}
if (biBitCount >= 32) { /* we shift biClrUsed by this value later. */
if (biBitCount >= 32) { /* we shift biClrUsed by this value later. */
SDL_SetError("Unsupported or incorrect biBitCount field");
was_error = SDL_TRUE;
goto done;
@ -423,7 +449,7 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
}
if (biClrUsed > (Uint32)palette->ncolors) {
biClrUsed = 1 << biBitCount; /* try forcing it? */
biClrUsed = 1 << biBitCount; /* try forcing it? */
if (biClrUsed > (Uint32)palette->ncolors) {
SDL_SetError("Unsupported or incorrect biClrUsed field");
was_error = SDL_TRUE;
@ -431,15 +457,15 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
}
}
if (biSize == 12) {
for (i = 0; i < (int) biClrUsed; ++i) {
if (biSize == 12) {
for (i = 0; i < (int)biClrUsed; ++i) {
SDL_RWread(src, &palette->colors[i].b, 1, 1);
SDL_RWread(src, &palette->colors[i].g, 1, 1);
SDL_RWread(src, &palette->colors[i].r, 1, 1);
palette->colors[i].a = SDL_ALPHA_OPAQUE;
}
} else {
for (i = 0; i < (int) biClrUsed; ++i) {
for (i = 0; i < (int)biClrUsed; ++i) {
SDL_RWread(src, &palette->colors[i].b, 1, 1);
SDL_RWread(src, &palette->colors[i].g, 1, 1);
SDL_RWread(src, &palette->colors[i].r, 1, 1);
@ -463,16 +489,22 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
}
if ((biCompression == BI_RLE4) || (biCompression == BI_RLE8)) {
was_error = readRlePixels(surface, src, biCompression == BI_RLE8);
if (was_error) SDL_Error(SDL_EFREAD);
if (was_error) {
SDL_Error(SDL_EFREAD);
}
goto done;
}
top = (Uint8 *)surface->pixels;
end = (Uint8 *)surface->pixels+(surface->h*surface->pitch);
end = (Uint8 *)surface->pixels + (surface->h * surface->pitch);
switch (ExpandBMP) {
case 1:
bmpPitch = (biWidth + 7) >> 3;
pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
break;
case 2:
bmpPitch = (biWidth + 3) >> 2;
pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
break;
case 4:
bmpPitch = (biWidth + 1) >> 1;
pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
@ -489,27 +521,28 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
while (bits >= top && bits < end) {
switch (ExpandBMP) {
case 1:
case 4:{
Uint8 pixel = 0;
int shift = (8 - ExpandBMP);
for (i = 0; i < surface->w; ++i) {
if (i % (8 / ExpandBMP) == 0) {
if (!SDL_RWread(src, &pixel, 1, 1)) {
SDL_Error(SDL_EFREAD);
was_error = SDL_TRUE;
goto done;
}
}
bits[i] = (pixel >> shift);
if (bits[i] >= biClrUsed) {
SDL_SetError("A BMP image contains a pixel with a color out of the palette");
case 2:
case 4:
{
Uint8 pixel = 0;
int shift = (8 - ExpandBMP);
for (i = 0; i < surface->w; ++i) {
if (i % (8 / ExpandBMP) == 0) {
if (!SDL_RWread(src, &pixel, 1, 1)) {
SDL_Error(SDL_EFREAD);
was_error = SDL_TRUE;
goto done;
}
pixel <<= ExpandBMP;
}
bits[i] = (pixel >> shift);
if (bits[i] >= biClrUsed) {
SDL_SetError("A BMP image contains a pixel with a color out of the palette");
was_error = SDL_TRUE;
goto done;
}
pixel <<= ExpandBMP;
}
break;
} break;
default:
if (SDL_RWread(src, bits, 1, surface->pitch) != surface->pitch) {
@ -531,19 +564,23 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
case has already been taken care of above. */
switch (biBitCount) {
case 15:
case 16:{
Uint16 *pix = (Uint16 *) bits;
for (i = 0; i < surface->w; i++)
pix[i] = SDL_Swap16(pix[i]);
break;
case 16:
{
Uint16 *pix = (Uint16 *)bits;
for (i = 0; i < surface->w; i++) {
pix[i] = SDL_Swap16(pix[i]);
}
break;
}
case 32:{
Uint32 *pix = (Uint32 *) bits;
for (i = 0; i < surface->w; i++)
pix[i] = SDL_Swap32(pix[i]);
break;
case 32:
{
Uint32 *pix = (Uint32 *)bits;
for (i = 0; i < surface->w; i++) {
pix[i] = SDL_Swap32(pix[i]);
}
break;
}
}
#endif
break;
@ -564,28 +601,25 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
if (correctAlpha) {
CorrectAlphaChannel(surface);
}
done:
done:
if (was_error) {
if (src) {
SDL_RWseek(src, fp_offset, RW_SEEK_SET);
}
if (surface) {
SDL_FreeSurface(surface);
}
SDL_FreeSurface(surface);
surface = NULL;
}
if (freesrc && src) {
SDL_RWclose(src);
}
return (surface);
return surface;
}
int
SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
int SDL_SaveBMP_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)
{
Sint64 fp_offset;
int i, pad;
SDL_Surface *surface;
SDL_Surface *intermediate_surface;
Uint8 *bits;
SDL_bool save32bit = SDL_FALSE;
SDL_bool saveLegacyBMP = SDL_FALSE;
@ -616,41 +650,42 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
Uint32 bV4BlueMask = 0;
Uint32 bV4AlphaMask = 0;
Uint32 bV4CSType = 0;
Sint32 bV4Endpoints[3 * 3] = {0};
Sint32 bV4Endpoints[3 * 3] = { 0 };
Uint32 bV4GammaRed = 0;
Uint32 bV4GammaGreen = 0;
Uint32 bV4GammaBlue = 0;
/* Make sure we have somewhere to save */
surface = NULL;
intermediate_surface = NULL;
if (dst) {
#ifdef SAVE_32BIT_BMP
/* We can save alpha information in a 32-bit BMP */
if (saveme->format->BitsPerPixel >= 8 && (saveme->format->Amask ||
saveme->map->info.flags & SDL_COPY_COLORKEY)) {
if (surface->format->BitsPerPixel >= 8 &&
(surface->format->Amask != 0 ||
surface->map->info.flags & SDL_COPY_COLORKEY)) {
save32bit = SDL_TRUE;
}
#endif /* SAVE_32BIT_BMP */
if (saveme->format->palette && !save32bit) {
if (saveme->format->BitsPerPixel == 8) {
surface = saveme;
if (surface->format->palette != NULL && !save32bit) {
if (surface->format->BitsPerPixel == 8) {
intermediate_surface = surface;
} else {
SDL_SetError("%d bpp BMP files not supported",
saveme->format->BitsPerPixel);
surface->format->BitsPerPixel);
}
} else if ((saveme->format->BitsPerPixel == 24) && !save32bit &&
} else if ((surface->format->BitsPerPixel == 24) && !save32bit &&
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
(saveme->format->Rmask == 0x00FF0000) &&
(saveme->format->Gmask == 0x0000FF00) &&
(saveme->format->Bmask == 0x000000FF)
(surface->format->Rmask == 0x00FF0000) &&
(surface->format->Gmask == 0x0000FF00) &&
(surface->format->Bmask == 0x000000FF)
#else
(saveme->format->Rmask == 0x000000FF) &&
(saveme->format->Gmask == 0x0000FF00) &&
(saveme->format->Bmask == 0x00FF0000)
(surface->format->Rmask == 0x000000FF) &&
(surface->format->Gmask == 0x0000FF00) &&
(surface->format->Bmask == 0x00FF0000)
#endif
) {
surface = saveme;
) {
intermediate_surface = surface;
} else {
SDL_PixelFormat format;
@ -661,8 +696,8 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
} else {
SDL_InitFormat(&format, SDL_PIXELFORMAT_BGR24);
}
surface = SDL_ConvertSurface(saveme, &format, 0);
if (!surface) {
intermediate_surface = SDL_ConvertSurface(surface, &format, 0);
if (intermediate_surface == NULL) {
SDL_SetError("Couldn't convert image to %d bpp",
format.BitsPerPixel);
}
@ -677,14 +712,14 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
saveLegacyBMP = SDL_GetHintBoolean(SDL_HINT_BMP_SAVE_LEGACY_FORMAT, SDL_FALSE);
}
if (surface && (SDL_LockSurface(surface) == 0)) {
const int bw = surface->w * surface->format->BytesPerPixel;
if (intermediate_surface && (SDL_LockSurface(intermediate_surface) == 0)) {
const int bw = intermediate_surface->w * intermediate_surface->format->BytesPerPixel;
/* Set the BMP file header values */
bfSize = 0; /* We'll write this when we're done */
bfSize = 0; /* We'll write this when we're done */
bfReserved1 = 0;
bfReserved2 = 0;
bfOffBits = 0; /* We'll write this when we're done */
bfOffBits = 0; /* We'll write this when we're done */
/* Write the BMP file header values */
fp_offset = SDL_RWtell(dst);
@ -697,16 +732,16 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
/* Set the BMP info values */
biSize = 40;
biWidth = surface->w;
biHeight = surface->h;
biWidth = intermediate_surface->w;
biHeight = intermediate_surface->h;
biPlanes = 1;
biBitCount = surface->format->BitsPerPixel;
biBitCount = intermediate_surface->format->BitsPerPixel;
biCompression = BI_RGB;
biSizeImage = surface->h * surface->pitch;
biSizeImage = intermediate_surface->h * intermediate_surface->pitch;
biXPelsPerMeter = 0;
biYPelsPerMeter = 0;
if (surface->format->palette) {
biClrUsed = surface->format->palette->ncolors;
if (intermediate_surface->format->palette) {
biClrUsed = intermediate_surface->format->palette->ncolors;
} else {
biClrUsed = 0;
}
@ -717,9 +752,9 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
biSize = 108;
biCompression = BI_BITFIELDS;
/* The BMP format is always little endian, these masks stay the same */
bV4RedMask = 0x00ff0000;
bV4RedMask = 0x00ff0000;
bV4GreenMask = 0x0000ff00;
bV4BlueMask = 0x000000ff;
bV4BlueMask = 0x000000ff;
bV4AlphaMask = 0xff000000;
bV4CSType = LCS_WINDOWS_COLOR_SPACE;
bV4GammaRed = 0;
@ -756,12 +791,12 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
}
/* Write the palette (in BGR color order) */
if (surface->format->palette) {
if (intermediate_surface->format->palette) {
SDL_Color *colors;
int ncolors;
colors = surface->format->palette->colors;
ncolors = surface->format->palette->ncolors;
colors = intermediate_surface->format->palette->colors;
ncolors = intermediate_surface->format->palette->ncolors;
for (i = 0; i < ncolors; ++i) {
SDL_RWwrite(dst, &colors[i].b, 1, 1);
SDL_RWwrite(dst, &colors[i].g, 1, 1);
@ -781,10 +816,10 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
}
/* Write the bitmap image upside down */
bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch);
bits = (Uint8 *)intermediate_surface->pixels + (intermediate_surface->h * intermediate_surface->pitch);
pad = ((bw % 4) ? (4 - (bw % 4)) : 0);
while (bits > (Uint8 *) surface->pixels) {
bits -= surface->pitch;
while (bits > (Uint8 *)intermediate_surface->pixels) {
bits -= intermediate_surface->pitch;
if (SDL_RWwrite(dst, bits, 1, bw) != bw) {
SDL_Error(SDL_EFWRITE);
break;
@ -808,16 +843,16 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
}
/* Close it up.. */
SDL_UnlockSurface(surface);
if (surface != saveme) {
SDL_FreeSurface(surface);
SDL_UnlockSurface(intermediate_surface);
if (intermediate_surface != surface) {
SDL_FreeSurface(intermediate_surface);
}
}
if (freedst && dst) {
SDL_RWclose(dst);
}
return ((SDL_strcmp(SDL_GetError(), "") == 0) ? 0 : -1);
return (SDL_strcmp(SDL_GetError(), "") == 0) ? 0 : -1;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,17 +23,15 @@
#include "SDL_clipboard.h"
#include "SDL_sysvideo.h"
int
SDL_SetClipboardText(const char *text)
int SDL_SetClipboardText(const char *text)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (!_this) {
if (_this == NULL) {
return SDL_SetError("Video subsystem must be initialized to set clipboard text");
}
if (!text) {
if (text == NULL) {
text = "";
}
if (_this->SetClipboardText) {
@ -45,12 +43,31 @@ SDL_SetClipboardText(const char *text)
}
}
char *
SDL_GetClipboardText(void)
int SDL_SetPrimarySelectionText(const char *text)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (!_this) {
if (_this == NULL) {
return SDL_SetError("Video subsystem must be initialized to set primary selection text");
}
if (text == NULL) {
text = "";
}
if (_this->SetPrimarySelectionText) {
return _this->SetPrimarySelectionText(_this, text);
} else {
SDL_free(_this->primary_selection_text);
_this->primary_selection_text = SDL_strdup(text);
return 0;
}
}
char *SDL_GetClipboardText(void)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (_this == NULL) {
SDL_SetError("Video subsystem must be initialized to get clipboard text");
return SDL_strdup("");
}
@ -59,19 +76,38 @@ SDL_GetClipboardText(void)
return _this->GetClipboardText(_this);
} else {
const char *text = _this->clipboard_text;
if (!text) {
if (text == NULL) {
text = "";
}
return SDL_strdup(text);
}
}
SDL_bool
SDL_HasClipboardText(void)
char *SDL_GetPrimarySelectionText(void)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (!_this) {
if (_this == NULL) {
SDL_SetError("Video subsystem must be initialized to get primary selection text");
return SDL_strdup("");
}
if (_this->GetPrimarySelectionText) {
return _this->GetPrimarySelectionText(_this);
} else {
const char *text = _this->primary_selection_text;
if (text == NULL) {
text = "";
}
return SDL_strdup(text);
}
}
SDL_bool SDL_HasClipboardText(void)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (_this == NULL) {
SDL_SetError("Video subsystem must be initialized to check clipboard text");
return SDL_FALSE;
}
@ -87,4 +123,24 @@ SDL_HasClipboardText(void)
}
}
SDL_bool SDL_HasPrimarySelectionText(void)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (_this == NULL) {
SDL_SetError("Video subsystem must be initialized to check primary selection text");
return SDL_FALSE;
}
if (_this->HasPrimarySelectionText) {
return _this->HasPrimarySelectionText(_this);
}
if (_this->primary_selection_text && _this->primary_selection_text[0] != '\0') {
return SDL_TRUE;
}
return SDL_FALSE;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,15 +1,15 @@
/*
* Simple DirectMedia Layer
* Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
*
* Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
@ -45,57 +45,64 @@
#endif
#endif /* EGL_KHR_create_context */
#ifndef EGL_EXT_pixel_format_float
#define EGL_EXT_pixel_format_float
#define EGL_COLOR_COMPONENT_TYPE_EXT 0x3339
#define EGL_COLOR_COMPONENT_TYPE_FIXED_EXT 0x333A
#define EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT 0x333B
#endif
#ifndef EGL_EXT_present_opaque
#define EGL_EXT_present_opaque 1
#define EGL_PRESENT_OPAQUE_EXT 0x31DF
#define EGL_PRESENT_OPAQUE_EXT 0x31DF
#endif /* EGL_EXT_present_opaque */
#if SDL_VIDEO_DRIVER_RPI
/* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
#define DEFAULT_EGL ( vc4 ? "libEGL.so.1" : "libbrcmEGL.so" )
#define DEFAULT_OGL_ES2 ( vc4 ? "libGLESv2.so.2" : "libbrcmGLESv2.so" )
#define ALT_EGL "libEGL.so"
#define ALT_OGL_ES2 "libGLESv2.so"
#define DEFAULT_OGL_ES_PVR ( vc4 ? "libGLES_CM.so.1" : "libbrcmGLESv2.so" )
#define DEFAULT_OGL_ES ( vc4 ? "libGLESv1_CM.so.1" : "libbrcmGLESv2.so" )
#define DEFAULT_EGL (vc4 ? "libEGL.so.1" : "libbrcmEGL.so")
#define DEFAULT_OGL_ES2 (vc4 ? "libGLESv2.so.2" : "libbrcmGLESv2.so")
#define ALT_EGL "libEGL.so"
#define ALT_OGL_ES2 "libGLESv2.so"
#define DEFAULT_OGL_ES_PVR (vc4 ? "libGLES_CM.so.1" : "libbrcmGLESv2.so")
#define DEFAULT_OGL_ES (vc4 ? "libGLESv1_CM.so.1" : "libbrcmGLESv2.so")
#elif SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_VIVANTE
/* Android */
#define DEFAULT_EGL "libEGL.so"
#define DEFAULT_OGL_ES2 "libGLESv2.so"
#define DEFAULT_EGL "libEGL.so"
#define DEFAULT_OGL_ES2 "libGLESv2.so"
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
#define DEFAULT_OGL_ES "libGLESv1_CM.so"
#define DEFAULT_OGL_ES "libGLESv1_CM.so"
#elif SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
/* EGL AND OpenGL ES support via ANGLE */
#define DEFAULT_EGL "libEGL.dll"
#define DEFAULT_OGL_ES2 "libGLESv2.dll"
#define DEFAULT_OGL_ES_PVR "libGLES_CM.dll"
#define DEFAULT_OGL_ES "libGLESv1_CM.dll"
#define DEFAULT_OGL_ES "libGLESv1_CM.dll"
#elif SDL_VIDEO_DRIVER_COCOA
/* EGL AND OpenGL ES support via ANGLE */
#define DEFAULT_EGL "libEGL.dylib"
#define DEFAULT_OGL_ES2 "libGLESv2.dylib"
#define DEFAULT_EGL "libEGL.dylib"
#define DEFAULT_OGL_ES2 "libGLESv2.dylib"
#define DEFAULT_OGL_ES_PVR "libGLES_CM.dylib" //???
#define DEFAULT_OGL_ES "libGLESv1_CM.dylib" //???
#define DEFAULT_OGL_ES "libGLESv1_CM.dylib" //???
#elif defined(__OpenBSD__)
/* OpenBSD */
#define DEFAULT_OGL "libGL.so"
#define DEFAULT_EGL "libEGL.so"
#define DEFAULT_OGL_ES2 "libGLESv2.so"
#define DEFAULT_OGL "libGL.so"
#define DEFAULT_EGL "libEGL.so"
#define DEFAULT_OGL_ES2 "libGLESv2.so"
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
#define DEFAULT_OGL_ES "libGLESv1_CM.so"
#define DEFAULT_OGL_ES "libGLESv1_CM.so"
#else
/* Desktop Linux/Unix-like */
#define DEFAULT_OGL "libGL.so.1"
#define DEFAULT_EGL "libEGL.so.1"
#define ALT_OGL "libOpenGL.so.0"
#define DEFAULT_OGL_ES2 "libGLESv2.so.2"
#define DEFAULT_OGL "libGL.so.1"
#define DEFAULT_EGL "libEGL.so.1"
#define ALT_OGL "libOpenGL.so.0"
#define DEFAULT_OGL_ES2 "libGLESv2.so.2"
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so.1"
#define DEFAULT_OGL_ES "libGLESv1_CM.so.1"
#define DEFAULT_OGL_ES "libGLESv1_CM.so.1"
#endif /* SDL_VIDEO_DRIVER_RPI */
#if SDL_VIDEO_OPENGL && !SDL_VIDEO_VITA_PVR_OGL
@ -111,23 +118,24 @@
#if defined(SDL_VIDEO_STATIC_ANGLE) || defined(SDL_VIDEO_DRIVER_VITA)
#define LOAD_FUNC(NAME) \
_this->egl_data->NAME = (void *)NAME;
_this->egl_data->NAME = (void *)NAME;
#else
#define LOAD_FUNC(NAME) \
_this->egl_data->NAME = SDL_LoadFunction(_this->egl_data->dll_handle, #NAME); \
if (!_this->egl_data->NAME) \
{ \
return SDL_SetError("Could not retrieve EGL function " #NAME); \
}
#define LOAD_FUNC(NAME) \
_this->egl_data->NAME = SDL_LoadFunction(_this->egl_data->egl_dll_handle, #NAME); \
if (!_this->egl_data->NAME) { \
return SDL_SetError("Could not retrieve EGL function " #NAME); \
}
#endif
/* it is allowed to not have some of the EGL extensions on start - attempts to use them will fail later. */
#define LOAD_FUNC_EGLEXT(NAME) \
_this->egl_data->NAME = _this->egl_data->eglGetProcAddress(#NAME);
static const char * SDL_EGL_GetErrorName(EGLint eglErrorCode)
static const char *SDL_EGL_GetErrorName(EGLint eglErrorCode)
{
#define SDL_EGL_ERROR_TRANSLATE(e) case e: return #e;
#define SDL_EGL_ERROR_TRANSLATE(e) \
case e: \
return #e;
switch (eglErrorCode) {
SDL_EGL_ERROR_TRANSLATE(EGL_SUCCESS);
SDL_EGL_ERROR_TRANSLATE(EGL_NOT_INITIALIZED);
@ -148,13 +156,13 @@ static const char * SDL_EGL_GetErrorName(EGLint eglErrorCode)
return "";
}
int SDL_EGL_SetErrorEx(const char * message, const char * eglFunctionName, EGLint eglErrorCode)
int SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint eglErrorCode)
{
const char * errorText = SDL_EGL_GetErrorName(eglErrorCode);
const char *errorText = SDL_EGL_GetErrorName(eglErrorCode);
char altErrorText[32];
if (errorText[0] == '\0') {
/* An unknown-to-SDL error code was reported. Report its hexadecimal value, instead of its name. */
SDL_snprintf(altErrorText, SDL_arraysize(altErrorText), "0x%x", (unsigned int)eglErrorCode);
(void)SDL_snprintf(altErrorText, SDL_arraysize(altErrorText), "0x%x", (unsigned int)eglErrorCode);
errorText = altErrorText;
}
return SDL_SetError("%s (call to %s failed, reporting an error of %s)", message, eglFunctionName, errorText);
@ -234,45 +242,34 @@ SDL_bool SDL_EGL_HasExtension(_THIS, SDL_EGL_ExtensionType type, const char *ext
return SDL_FALSE;
}
void *
SDL_EGL_GetProcAddress(_THIS, const char *proc)
void *SDL_EGL_GetProcAddress(_THIS, const char *proc)
{
const Uint32 eglver = (((Uint32) _this->egl_data->egl_version_major) << 16) | ((Uint32) _this->egl_data->egl_version_minor);
const SDL_bool is_egl_15_or_later = eglver >= ((((Uint32) 1) << 16) | 5);
void *retval = NULL;
if (_this->egl_data != NULL) {
const Uint32 eglver = (((Uint32)_this->egl_data->egl_version_major) << 16) | ((Uint32)_this->egl_data->egl_version_minor);
const SDL_bool is_egl_15_or_later = eglver >= ((((Uint32)1) << 16) | 5);
/* EGL 1.5 can use eglGetProcAddress() for any symbol. 1.4 and earlier can't use it for core entry points. */
if (!retval && is_egl_15_or_later && _this->egl_data->eglGetProcAddress) {
retval = _this->egl_data->eglGetProcAddress(proc);
}
/* EGL 1.5 can use eglGetProcAddress() for any symbol. 1.4 and earlier can't use it for core entry points. */
if (retval == NULL && is_egl_15_or_later && _this->egl_data->eglGetProcAddress) {
retval = _this->egl_data->eglGetProcAddress(proc);
}
#if !defined(__EMSCRIPTEN__) && !defined(SDL_VIDEO_DRIVER_VITA) /* LoadFunction isn't needed on Emscripten and will call dlsym(), causing other problems. */
/* Try SDL_LoadFunction() first for EGL <= 1.4, or as a fallback for >= 1.5. */
if (!retval) {
static char procname[64];
retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, proc);
/* just in case you need an underscore prepended... */
if (!retval && (SDL_strlen(proc) < (sizeof (procname) - 1))) {
procname[0] = '_';
SDL_strlcpy(procname + 1, proc, sizeof (procname) - 1);
retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, procname);
#if !defined(__EMSCRIPTEN__) && !defined(SDL_VIDEO_DRIVER_VITA) /* LoadFunction isn't needed on Emscripten and will call dlsym(), causing other problems. */
/* Try SDL_LoadFunction() first for EGL <= 1.4, or as a fallback for >= 1.5. */
if (retval == NULL) {
retval = SDL_LoadFunction(_this->egl_data->opengl_dll_handle, proc);
}
#endif
/* Try eglGetProcAddress if we're on <= 1.4 and still searching... */
if (retval == NULL && !is_egl_15_or_later && _this->egl_data->eglGetProcAddress) {
retval = _this->egl_data->eglGetProcAddress(proc);
}
}
#endif
/* Try eglGetProcAddress if we're on <= 1.4 and still searching... */
if (!retval && !is_egl_15_or_later && _this->egl_data->eglGetProcAddress) {
retval = _this->egl_data->eglGetProcAddress(proc);
if (retval) {
return retval;
}
}
return retval;
}
void
SDL_EGL_UnloadLibrary(_THIS)
void SDL_EGL_UnloadLibrary(_THIS)
{
if (_this->egl_data) {
if (_this->egl_data->egl_display) {
@ -280,24 +277,23 @@ SDL_EGL_UnloadLibrary(_THIS)
_this->egl_data->egl_display = NULL;
}
if (_this->egl_data->dll_handle) {
SDL_UnloadObject(_this->egl_data->dll_handle);
_this->egl_data->dll_handle = NULL;
}
if (_this->egl_data->egl_dll_handle) {
SDL_UnloadObject(_this->egl_data->egl_dll_handle);
_this->egl_data->egl_dll_handle = NULL;
}
if (_this->egl_data->opengl_dll_handle) {
SDL_UnloadObject(_this->egl_data->opengl_dll_handle);
_this->egl_data->opengl_dll_handle = NULL;
}
SDL_free(_this->egl_data);
_this->egl_data = NULL;
}
}
int
SDL_EGL_LoadLibraryOnly(_THIS, const char *egl_path)
static int SDL_EGL_LoadLibraryInternal(_THIS, const char *egl_path)
{
void *dll_handle = NULL, *egl_dll_handle = NULL; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
void *egl_dll_handle = NULL, *opengl_dll_handle = NULL;
const char *path = NULL;
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
const char *d3dcompiler;
@ -306,15 +302,6 @@ SDL_EGL_LoadLibraryOnly(_THIS, const char *egl_path)
SDL_bool vc4 = (0 == access("/sys/module/vc4/", F_OK));
#endif
if (_this->egl_data) {
return SDL_SetError("EGL context already created");
}
_this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
if (!_this->egl_data) {
return SDL_OutOfMemory();
}
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
d3dcompiler = SDL_GetHint(SDL_HINT_VIDEO_WIN_D3DCOMPILER);
if (d3dcompiler) {
@ -327,7 +314,8 @@ SDL_EGL_LoadLibraryOnly(_THIS, const char *egl_path)
if (WIN_IsWindowsVistaOrGreater()) {
/* Try the newer d3d compilers first */
const char *d3dcompiler_list[] = {
"d3dcompiler_47.dll", "d3dcompiler_46.dll",
"d3dcompiler_47.dll",
"d3dcompiler_46.dll",
};
int i;
@ -349,80 +337,80 @@ SDL_EGL_LoadLibraryOnly(_THIS, const char *egl_path)
/* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
if (path != NULL) {
egl_dll_handle = SDL_LoadObject(path);
opengl_dll_handle = SDL_LoadObject(path);
}
if (egl_dll_handle == NULL) {
if (opengl_dll_handle == NULL) {
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
if (_this->gl_config.major_version > 1) {
path = DEFAULT_OGL_ES2;
egl_dll_handle = SDL_LoadObject(path);
opengl_dll_handle = SDL_LoadObject(path);
#ifdef ALT_OGL_ES2
if (egl_dll_handle == NULL && !vc4) {
if (opengl_dll_handle == NULL && !vc4) {
path = ALT_OGL_ES2;
egl_dll_handle = SDL_LoadObject(path);
opengl_dll_handle = SDL_LoadObject(path);
}
#endif
} else {
path = DEFAULT_OGL_ES;
egl_dll_handle = SDL_LoadObject(path);
if (egl_dll_handle == NULL) {
opengl_dll_handle = SDL_LoadObject(path);
if (opengl_dll_handle == NULL) {
path = DEFAULT_OGL_ES_PVR;
egl_dll_handle = SDL_LoadObject(path);
opengl_dll_handle = SDL_LoadObject(path);
}
#ifdef ALT_OGL_ES2
if (egl_dll_handle == NULL && !vc4) {
if (opengl_dll_handle == NULL && !vc4) {
path = ALT_OGL_ES2;
egl_dll_handle = SDL_LoadObject(path);
opengl_dll_handle = SDL_LoadObject(path);
}
#endif
}
}
#ifdef DEFAULT_OGL
#ifdef DEFAULT_OGL
else {
path = DEFAULT_OGL;
egl_dll_handle = SDL_LoadObject(path);
opengl_dll_handle = SDL_LoadObject(path);
#ifdef ALT_OGL
if (egl_dll_handle == NULL) {
if (opengl_dll_handle == NULL) {
path = ALT_OGL;
egl_dll_handle = SDL_LoadObject(path);
opengl_dll_handle = SDL_LoadObject(path);
}
#endif
}
#endif
#endif
}
_this->egl_data->egl_dll_handle = egl_dll_handle;
_this->egl_data->opengl_dll_handle = opengl_dll_handle;
if (egl_dll_handle == NULL) {
if (opengl_dll_handle == NULL) {
return SDL_SetError("Could not initialize OpenGL / GLES library");
}
/* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */
if (egl_path != NULL) {
dll_handle = SDL_LoadObject(egl_path);
}
egl_dll_handle = SDL_LoadObject(egl_path);
}
/* Try loading a EGL symbol, if it does not work try the default library paths */
if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
if (dll_handle != NULL) {
SDL_UnloadObject(dll_handle);
if (egl_dll_handle == NULL || SDL_LoadFunction(egl_dll_handle, "eglChooseConfig") == NULL) {
if (egl_dll_handle != NULL) {
SDL_UnloadObject(egl_dll_handle);
}
path = SDL_getenv("SDL_VIDEO_EGL_DRIVER");
if (path == NULL) {
path = DEFAULT_EGL;
}
dll_handle = SDL_LoadObject(path);
egl_dll_handle = SDL_LoadObject(path);
#ifdef ALT_EGL
if (dll_handle == NULL && !vc4) {
if (egl_dll_handle == NULL && !vc4) {
path = ALT_EGL;
dll_handle = SDL_LoadObject(path);
egl_dll_handle = SDL_LoadObject(path);
}
#endif
if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
if (dll_handle != NULL) {
SDL_UnloadObject(dll_handle);
if (egl_dll_handle == NULL || SDL_LoadFunction(egl_dll_handle, "eglChooseConfig") == NULL) {
if (egl_dll_handle != NULL) {
SDL_UnloadObject(egl_dll_handle);
}
return SDL_SetError("Could not load EGL library");
}
@ -430,9 +418,9 @@ SDL_EGL_LoadLibraryOnly(_THIS, const char *egl_path)
}
#endif
_this->egl_data->dll_handle = dll_handle;
#if SDL_VIDEO_DRIVER_VITA
_this->egl_data->egl_dll_handle = egl_dll_handle;
#if SDL_VIDEO_DRIVER_VITA
_this->egl_data->opengl_dll_handle = opengl_dll_handle;
#endif
/* Load new function pointers */
@ -475,8 +463,27 @@ SDL_EGL_LoadLibraryOnly(_THIS, const char *egl_path)
return 0;
}
static void
SDL_EGL_GetVersion(_THIS) {
int SDL_EGL_LoadLibraryOnly(_THIS, const char *egl_path)
{
if (_this->egl_data) {
return SDL_SetError("EGL context already created");
}
_this->egl_data = (struct SDL_EGL_VideoData *)SDL_calloc(1, sizeof(SDL_EGL_VideoData));
if (!_this->egl_data) {
return SDL_OutOfMemory();
}
if (SDL_EGL_LoadLibraryInternal(_this, egl_path) < 0) {
SDL_free(_this->egl_data);
_this->egl_data = NULL;
return -1;
}
return 0;
}
static void SDL_EGL_GetVersion(_THIS)
{
if (_this->egl_data->eglQueryString) {
const char *egl_version = _this->egl_data->eglQueryString(_this->egl_data->egl_display, EGL_VERSION);
if (egl_version) {
@ -491,8 +498,7 @@ SDL_EGL_GetVersion(_THIS) {
}
}
int
SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display, EGLenum platform)
int SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display, EGLenum platform)
{
int library_load_retcode = SDL_EGL_LoadLibraryOnly(_this, egl_path);
if (library_load_retcode != 0) {
@ -561,8 +567,7 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
valid available GPU for EGL to use.
*/
int
SDL_EGL_InitializeOffscreen(_THIS, int device)
int SDL_EGL_InitializeOffscreen(_THIS, int device)
{
void *egl_devices[SDL_EGL_MAX_DEVICES];
EGLint num_egl_devices = 0;
@ -602,8 +607,7 @@ SDL_EGL_InitializeOffscreen(_THIS, int device)
if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
return SDL_SetError("Could not initialize EGL");
}
}
else {
} else {
int i;
SDL_bool found = SDL_FALSE;
EGLDisplay attempted_egl_display;
@ -641,63 +645,64 @@ SDL_EGL_InitializeOffscreen(_THIS, int device)
return 0;
}
void
SDL_EGL_SetRequiredVisualId(_THIS, int visual_id)
void SDL_EGL_SetRequiredVisualId(_THIS, int visual_id)
{
_this->egl_data->egl_required_visual_id=visual_id;
_this->egl_data->egl_required_visual_id = visual_id;
}
#ifdef DUMP_EGL_CONFIG
#define ATTRIBUTE(_attr) { _attr, #_attr }
#define ATTRIBUTE(_attr) \
{ \
_attr, #_attr \
}
typedef struct {
typedef struct
{
EGLint attribute;
char const* name;
char const *name;
} Attribute;
static
Attribute all_attributes[] = {
ATTRIBUTE( EGL_BUFFER_SIZE ),
ATTRIBUTE( EGL_ALPHA_SIZE ),
ATTRIBUTE( EGL_BLUE_SIZE ),
ATTRIBUTE( EGL_GREEN_SIZE ),
ATTRIBUTE( EGL_RED_SIZE ),
ATTRIBUTE( EGL_DEPTH_SIZE ),
ATTRIBUTE( EGL_STENCIL_SIZE ),
ATTRIBUTE( EGL_CONFIG_CAVEAT ),
ATTRIBUTE( EGL_CONFIG_ID ),
ATTRIBUTE( EGL_LEVEL ),
ATTRIBUTE( EGL_MAX_PBUFFER_HEIGHT ),
ATTRIBUTE( EGL_MAX_PBUFFER_WIDTH ),
ATTRIBUTE( EGL_MAX_PBUFFER_PIXELS ),
ATTRIBUTE( EGL_NATIVE_RENDERABLE ),
ATTRIBUTE( EGL_NATIVE_VISUAL_ID ),
ATTRIBUTE( EGL_NATIVE_VISUAL_TYPE ),
ATTRIBUTE( EGL_SAMPLES ),
ATTRIBUTE( EGL_SAMPLE_BUFFERS ),
ATTRIBUTE( EGL_SURFACE_TYPE ),
ATTRIBUTE( EGL_TRANSPARENT_TYPE ),
ATTRIBUTE( EGL_TRANSPARENT_BLUE_VALUE ),
ATTRIBUTE( EGL_TRANSPARENT_GREEN_VALUE ),
ATTRIBUTE( EGL_TRANSPARENT_RED_VALUE ),
ATTRIBUTE( EGL_BIND_TO_TEXTURE_RGB ),
ATTRIBUTE( EGL_BIND_TO_TEXTURE_RGBA ),
ATTRIBUTE( EGL_MIN_SWAP_INTERVAL ),
ATTRIBUTE( EGL_MAX_SWAP_INTERVAL ),
ATTRIBUTE( EGL_LUMINANCE_SIZE ),
ATTRIBUTE( EGL_ALPHA_MASK_SIZE ),
ATTRIBUTE( EGL_COLOR_BUFFER_TYPE ),
ATTRIBUTE( EGL_RENDERABLE_TYPE ),
ATTRIBUTE( EGL_MATCH_NATIVE_PIXMAP ),
ATTRIBUTE( EGL_CONFORMANT ),
static Attribute all_attributes[] = {
ATTRIBUTE(EGL_BUFFER_SIZE),
ATTRIBUTE(EGL_ALPHA_SIZE),
ATTRIBUTE(EGL_BLUE_SIZE),
ATTRIBUTE(EGL_GREEN_SIZE),
ATTRIBUTE(EGL_RED_SIZE),
ATTRIBUTE(EGL_DEPTH_SIZE),
ATTRIBUTE(EGL_STENCIL_SIZE),
ATTRIBUTE(EGL_CONFIG_CAVEAT),
ATTRIBUTE(EGL_CONFIG_ID),
ATTRIBUTE(EGL_LEVEL),
ATTRIBUTE(EGL_MAX_PBUFFER_HEIGHT),
ATTRIBUTE(EGL_MAX_PBUFFER_WIDTH),
ATTRIBUTE(EGL_MAX_PBUFFER_PIXELS),
ATTRIBUTE(EGL_NATIVE_RENDERABLE),
ATTRIBUTE(EGL_NATIVE_VISUAL_ID),
ATTRIBUTE(EGL_NATIVE_VISUAL_TYPE),
ATTRIBUTE(EGL_SAMPLES),
ATTRIBUTE(EGL_SAMPLE_BUFFERS),
ATTRIBUTE(EGL_SURFACE_TYPE),
ATTRIBUTE(EGL_TRANSPARENT_TYPE),
ATTRIBUTE(EGL_TRANSPARENT_BLUE_VALUE),
ATTRIBUTE(EGL_TRANSPARENT_GREEN_VALUE),
ATTRIBUTE(EGL_TRANSPARENT_RED_VALUE),
ATTRIBUTE(EGL_BIND_TO_TEXTURE_RGB),
ATTRIBUTE(EGL_BIND_TO_TEXTURE_RGBA),
ATTRIBUTE(EGL_MIN_SWAP_INTERVAL),
ATTRIBUTE(EGL_MAX_SWAP_INTERVAL),
ATTRIBUTE(EGL_LUMINANCE_SIZE),
ATTRIBUTE(EGL_ALPHA_MASK_SIZE),
ATTRIBUTE(EGL_COLOR_BUFFER_TYPE),
ATTRIBUTE(EGL_RENDERABLE_TYPE),
ATTRIBUTE(EGL_MATCH_NATIVE_PIXMAP),
ATTRIBUTE(EGL_CONFORMANT),
};
static void dumpconfig(_THIS, EGLConfig config)
{
int attr;
for (attr = 0 ; attr<sizeof(all_attributes)/sizeof(Attribute) ; attr++) {
for (attr = 0; attr < sizeof(all_attributes) / sizeof(Attribute); attr++) {
EGLint value;
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, config, all_attributes[attr].attribute, &value);
SDL_Log("\t%-32s: %10d (0x%08x)\n", all_attributes[attr].name, value, value);
@ -706,8 +711,7 @@ static void dumpconfig(_THIS, EGLConfig config)
#endif /* DUMP_EGL_CONFIG */
static int
SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none)
static int SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none)
{
/* 64 seems nice. */
EGLint attribs[64];
@ -762,6 +766,11 @@ SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none)
attribs[i++] = _this->gl_config.multisamplesamples;
}
if (_this->gl_config.floatbuffers) {
attribs[i++] = EGL_COLOR_COMPONENT_TYPE_EXT;
attribs[i++] = EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT;
}
if (_this->egl_data->is_offscreen) {
attribs[i++] = EGL_SURFACE_TYPE;
attribs[i++] = EGL_PBUFFER_BIT;
@ -775,7 +784,7 @@ SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none)
attribs[i++] = EGL_OPENGL_ES3_BIT_KHR;
} else
#endif
if (_this->gl_config.major_version >= 2) {
if (_this->gl_config.major_version >= 2) {
attribs[i++] = EGL_OPENGL_ES2_BIT;
} else {
attribs[i++] = EGL_OPENGL_ES_BIT;
@ -796,21 +805,20 @@ SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none)
SDL_assert(i < SDL_arraysize(attribs));
if (_this->egl_data->eglChooseConfig(_this->egl_data->egl_display,
attribs,
configs, SDL_arraysize(configs),
&found_configs) == EGL_FALSE ||
attribs,
configs, SDL_arraysize(configs),
&found_configs) == EGL_FALSE ||
found_configs == 0) {
return -1;
}
/* first ensure that a found config has a matching format, or the function will fall through. */
if (_this->egl_data->egl_required_visual_id)
{
for (i = 0; i < found_configs; i++ ) {
if (_this->egl_data->egl_required_visual_id) {
for (i = 0; i < found_configs; i++) {
EGLint format;
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
configs[i],
EGL_NATIVE_VISUAL_ID, &format);
configs[i],
EGL_NATIVE_VISUAL_ID, &format);
if (_this->egl_data->egl_required_visual_id == format) {
has_matching_format = SDL_TRUE;
break;
@ -821,15 +829,15 @@ SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none)
/* eglChooseConfig returns a number of configurations that match or exceed the requested attribs. */
/* From those, we select the one that matches our requirements more closely via a makeshift algorithm */
for (i = 0; i < found_configs; i++ ) {
for (i = 0; i < found_configs; i++) {
SDL_bool is_truecolor = SDL_FALSE;
int bitdiff = 0;
if (has_matching_format && _this->egl_data->egl_required_visual_id) {
EGLint format;
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
configs[i],
EGL_NATIVE_VISUAL_ID, &format);
configs[i],
EGL_NATIVE_VISUAL_ID, &format);
if (_this->egl_data->egl_required_visual_id != format) {
continue;
}
@ -848,16 +856,15 @@ SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none)
for (j = 0; j < SDL_arraysize(attribs) - 1; j += 2) {
if (attribs[j] == EGL_NONE) {
break;
break;
}
if ( attribs[j+1] != EGL_DONT_CARE && (
attribs[j] == EGL_RED_SIZE ||
attribs[j] == EGL_GREEN_SIZE ||
attribs[j] == EGL_BLUE_SIZE ||
attribs[j] == EGL_ALPHA_SIZE ||
attribs[j] == EGL_DEPTH_SIZE ||
attribs[j] == EGL_STENCIL_SIZE)) {
if (attribs[j + 1] != EGL_DONT_CARE && (attribs[j] == EGL_RED_SIZE ||
attribs[j] == EGL_GREEN_SIZE ||
attribs[j] == EGL_BLUE_SIZE ||
attribs[j] == EGL_ALPHA_SIZE ||
attribs[j] == EGL_DEPTH_SIZE ||
attribs[j] == EGL_STENCIL_SIZE)) {
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, configs[i], attribs[j], &value);
bitdiff += value - attribs[j + 1]; /* value is always >= attrib */
}
@ -874,8 +881,8 @@ SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none)
}
}
#define FAVOR_TRUECOLOR 1
#if FAVOR_TRUECOLOR
#define FAVOR_TRUECOLOR 1
#if FAVOR_TRUECOLOR
/* Some apps request a low color depth, either because they _assume_
they'll get a larger one but don't want to fail if only smaller ones
are available, or they just never called SDL_GL_SetAttribute at all and
@ -888,12 +895,12 @@ SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none)
on small hardware that all expected to actually get 16-bit color. In this
case, turn off FAVOR_TRUECOLOR (and maybe send a patch to make this more
flexible). */
if ( ((_this->gl_config.red_size + _this->gl_config.blue_size + _this->gl_config.green_size) <= 16) ) {
if (((_this->gl_config.red_size + _this->gl_config.blue_size + _this->gl_config.green_size) <= 16)) {
if (truecolor_config_idx != -1) {
_this->egl_data->egl_config = configs[truecolor_config_idx];
}
}
#endif
#endif
#ifdef DUMP_EGL_CONFIG
dumpconfig(_this, _this->egl_data->egl_config);
@ -902,8 +909,7 @@ SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none)
return 0;
}
int
SDL_EGL_ChooseConfig(_THIS)
int SDL_EGL_ChooseConfig(_THIS)
{
int ret;
@ -927,8 +933,7 @@ SDL_EGL_ChooseConfig(_THIS)
return SDL_EGL_SetError("Couldn't find matching EGL config", "eglChooseConfig");
}
SDL_GLContext
SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
SDL_GLContext SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
{
/* max 14 values plus terminator. */
EGLint attribs[15];
@ -950,7 +955,7 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
}
#if SDL_VIDEO_DRIVER_ANDROID
if ((_this->gl_config.flags & SDL_GL_CONTEXT_DEBUG_FLAG) != 0) {
if (_this->gl_config.flags & SDL_GL_CONTEXT_DEBUG_FLAG) {
/* If SDL_GL_CONTEXT_DEBUG_FLAG is set but EGL_KHR_debug unsupported, unset.
* This is required because some Android devices like to complain about it
* by "silently" failing, logging a hint which could be easily overlooked:
@ -1031,8 +1036,8 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
_this->egl_data->eglBindAPI(_this->egl_data->apitype);
egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
_this->egl_data->egl_config,
share_context, attribs);
_this->egl_data->egl_config,
share_context, attribs);
if (egl_context == EGL_NO_CONTEXT) {
SDL_EGL_SetError("Could not create EGL context", "eglCreateContext");
@ -1052,8 +1057,7 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
* or later, or if the EGL_KHR_surfaceless_context extension is present. */
if ((_this->egl_data->egl_version_major > 1) ||
((_this->egl_data->egl_version_major == 1) && (_this->egl_data->egl_version_minor >= 5)) ||
SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_surfaceless_context"))
{
SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_surfaceless_context")) {
/* Secondary condition: The client API must support it. */
if (profile_es) {
/* On OpenGL ES, the GL_OES_surfaceless_context extension must be
@ -1064,7 +1068,7 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
#if SDL_VIDEO_OPENGL && !defined(SDL_VIDEO_DRIVER_VITA)
} else {
/* Desktop OpenGL supports it by default from version 3.0 on. */
void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
void(APIENTRY * glGetIntegervFunc)(GLenum pname, GLint * params);
glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
if (glGetIntegervFunc) {
GLint v = 0;
@ -1077,13 +1081,12 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
}
}
return (SDL_GLContext) egl_context;
return (SDL_GLContext)egl_context;
}
int
SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context)
int SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context)
{
EGLContext egl_context = (EGLContext) context;
EGLContext egl_context = (EGLContext)context;
if (!_this->egl_data) {
return SDL_SetError("EGL not initialized");
@ -1094,7 +1097,7 @@ SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context)
/* Can't do the nothing there is to do? Probably trying to cleanup a failed startup, just return. */
return 0;
} else {
return SDL_SetError("EGL not initialized"); /* something clearly went wrong somewhere. */
return SDL_SetError("EGL not initialized"); /* something clearly went wrong somewhere. */
}
}
@ -1103,14 +1106,14 @@ SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context)
_this->egl_data->eglBindAPI(_this->egl_data->apitype);
}
/* The android emulator crashes badly if you try to eglMakeCurrent
/* The android emulator crashes badly if you try to eglMakeCurrent
* with a valid context and invalid surface, so we have to check for both here.
*/
if (!egl_context || (!egl_surface && !_this->gl_allow_no_surface)) {
_this->egl_data->eglMakeCurrent(_this->egl_data->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
_this->egl_data->eglMakeCurrent(_this->egl_data->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
} else {
if (!_this->egl_data->eglMakeCurrent(_this->egl_data->egl_display,
egl_surface, egl_surface, egl_context)) {
egl_surface, egl_surface, egl_context)) {
return SDL_EGL_SetError("Unable to make EGL context current", "eglMakeCurrent");
}
}
@ -1118,11 +1121,10 @@ SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context)
return 0;
}
int
SDL_EGL_SetSwapInterval(_THIS, int interval)
int SDL_EGL_SetSwapInterval(_THIS, int interval)
{
EGLBoolean status;
if (!_this->egl_data) {
return SDL_SetError("EGL not initialized");
}
@ -1133,29 +1135,27 @@ SDL_EGL_SetSwapInterval(_THIS, int interval)
if (interval < 0) {
return SDL_SetError("Late swap tearing currently unsupported");
}
status = _this->egl_data->eglSwapInterval(_this->egl_data->egl_display, interval);
if (status == EGL_TRUE) {
_this->egl_data->egl_swapinterval = interval;
return 0;
}
return SDL_EGL_SetError("Unable to set the EGL swap interval", "eglSwapInterval");
}
int
SDL_EGL_GetSwapInterval(_THIS)
int SDL_EGL_GetSwapInterval(_THIS)
{
if (!_this->egl_data) {
SDL_SetError("EGL not initialized");
return 0;
}
return _this->egl_data->egl_swapinterval;
}
int
SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface)
int SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface)
{
if (!_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, egl_surface)) {
return SDL_EGL_SetError("unable to show color buffer in an OS-native window", "eglSwapBuffers");
@ -1163,24 +1163,21 @@ SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface)
return 0;
}
void
SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
void SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
{
EGLContext egl_context = (EGLContext) context;
EGLContext egl_context = (EGLContext)context;
/* Clean up GLES and EGL */
if (!_this->egl_data) {
return;
}
if (egl_context != NULL && egl_context != EGL_NO_CONTEXT) {
_this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context);
}
}
EGLSurface *
SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
EGLSurface *SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
{
#if SDL_VIDEO_DRIVER_ANDROID
EGLint format_wanted;
@ -1190,7 +1187,7 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
EGLint attribs[5];
int attr = 0;
EGLSurface * surface;
EGLSurface *surface;
if (SDL_EGL_ChooseConfig(_this) != 0) {
return EGL_NO_SURFACE;
@ -1200,8 +1197,8 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
/* On Android, EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
* guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). */
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
_this->egl_data->egl_config,
EGL_NATIVE_VISUAL_ID, &format_wanted);
_this->egl_data->egl_config,
EGL_NATIVE_VISUAL_ID, &format_wanted);
/* Format based on selected egl config. */
ANativeWindow_setBuffersGeometry(nw, 0, 0, format_wanted);
@ -1229,11 +1226,11 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
#endif
attribs[attr++] = EGL_NONE;
surface = _this->egl_data->eglCreateWindowSurface(
_this->egl_data->egl_display,
_this->egl_data->egl_config,
nw, &attribs[0]);
_this->egl_data->egl_display,
_this->egl_data->egl_config,
nw, &attribs[0]);
if (surface == EGL_NO_SURFACE) {
SDL_EGL_SetError("unable to create an EGL window surface", "eglCreateWindowSurface");
}
@ -1267,13 +1264,12 @@ SDL_EGL_CreateOffscreenSurface(_THIS, int width, int height)
attributes);
}
void
SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface)
void SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface)
{
if (!_this->egl_data) {
return;
}
if (egl_surface != EGL_NO_SURFACE) {
_this->egl_data->eglDestroySurface(_this->egl_data->egl_display, egl_surface);
}
@ -1282,4 +1278,3 @@ SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface)
#endif /* SDL_VIDEO_OPENGL_EGL */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -29,11 +29,11 @@
#include "SDL_sysvideo.h"
#define SDL_EGL_MAX_DEVICES 8
#define SDL_EGL_MAX_DEVICES 8
typedef struct SDL_EGL_VideoData
{
void *egl_dll_handle, *dll_handle;
void *opengl_dll_handle, *egl_dll_handle;
EGLDisplay egl_display;
EGLConfig egl_config;
int egl_swapinterval;
@ -119,7 +119,8 @@ typedef struct SDL_EGL_VideoData
} SDL_EGL_VideoData;
/* OpenGLES functions */
typedef enum SDL_EGL_ExtensionType {
typedef enum SDL_EGL_ExtensionType
{
SDL_EGL_DISPLAY_EXTENSION,
SDL_EGL_CLIENT_EXTENSION
} SDL_EGL_ExtensionType;
@ -152,28 +153,31 @@ extern int SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext cont
extern int SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface);
/* SDL Error-reporting */
extern int SDL_EGL_SetErrorEx(const char * message, const char * eglFunctionName, EGLint eglErrorCode);
extern int SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint eglErrorCode);
#define SDL_EGL_SetError(message, eglFunctionName) SDL_EGL_SetErrorEx(message, eglFunctionName, _this->egl_data->eglGetError())
/* A few of useful macros */
#define SDL_EGL_SwapWindow_impl(BACKEND) int \
BACKEND ## _GLES_SwapWindow(_THIS, SDL_Window * window) \
{\
return SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);\
}
#define SDL_EGL_SwapWindow_impl(BACKEND) \
int \
BACKEND##_GLES_SwapWindow(_THIS, SDL_Window *window) \
{ \
return SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *)window->driverdata)->egl_surface); \
}
#define SDL_EGL_MakeCurrent_impl(BACKEND) int \
BACKEND ## _GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) \
{\
return SDL_EGL_MakeCurrent(_this, window ? ((SDL_WindowData *) window->driverdata)->egl_surface : EGL_NO_SURFACE, context);\
}
#define SDL_EGL_MakeCurrent_impl(BACKEND) \
int \
BACKEND##_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) \
{ \
return SDL_EGL_MakeCurrent(_this, window ? ((SDL_WindowData *)window->driverdata)->egl_surface : EGL_NO_SURFACE, context); \
}
#define SDL_EGL_CreateContext_impl(BACKEND) SDL_GLContext \
BACKEND ## _GLES_CreateContext(_THIS, SDL_Window * window) \
{\
return SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);\
}
#define SDL_EGL_CreateContext_impl(BACKEND) \
SDL_GLContext \
BACKEND##_GLES_CreateContext(_THIS, SDL_Window *window) \
{ \
return SDL_EGL_CreateContext(_this, ((SDL_WindowData *)window->driverdata)->egl_surface); \
}
#endif /* SDL_VIDEO_OPENGL_EGL */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,7 +24,6 @@
#include "SDL_blit.h"
#include "SDL_cpuinfo.h"
#ifdef __SSE__
/* *INDENT-OFF* */ /* clang-format off */
@ -58,8 +57,7 @@
#define SSE_END
#define DEFINE_SSE_FILLRECT(bpp, type) \
static void \
SDL_FillRect##bpp##SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
static void SDL_FillRect##bpp##SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
{ \
int i, n; \
Uint8 *p = NULL; \
@ -96,8 +94,7 @@ SDL_FillRect##bpp##SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
SSE_END; \
}
static void
SDL_FillRect1SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
static void SDL_FillRect1SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
{
int i, n;
@ -129,28 +126,29 @@ DEFINE_SSE_FILLRECT(2, Uint16)
DEFINE_SSE_FILLRECT(4, Uint32)
/* *INDENT-ON* */ /* clang-format on */
#endif /* __SSE__ */
#endif /* __SSE__ */
static void
SDL_FillRect1(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
static void SDL_FillRect1(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
{
int n;
Uint8 *p = NULL;
while (h--) {
n = w;
p = pixels;
if (n > 3) {
switch ((uintptr_t) p & 3) {
switch ((uintptr_t)p & 3) {
case 1:
*p++ = (Uint8) color;
--n; SDL_FALLTHROUGH;
*p++ = (Uint8)color;
--n;
SDL_FALLTHROUGH;
case 2:
*p++ = (Uint8) color;
--n; SDL_FALLTHROUGH;
*p++ = (Uint8)color;
--n;
SDL_FALLTHROUGH;
case 3:
*p++ = (Uint8) color;
*p++ = (Uint8)color;
--n;
}
SDL_memset4(p, color, (n >> 2));
@ -159,52 +157,52 @@ SDL_FillRect1(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
p += (n & ~3);
switch (n & 3) {
case 3:
*p++ = (Uint8) color; SDL_FALLTHROUGH;
*p++ = (Uint8)color;
SDL_FALLTHROUGH;
case 2:
*p++ = (Uint8) color; SDL_FALLTHROUGH;
*p++ = (Uint8)color;
SDL_FALLTHROUGH;
case 1:
*p++ = (Uint8) color;
*p++ = (Uint8)color;
}
}
pixels += pitch;
}
}
static void
SDL_FillRect2(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
static void SDL_FillRect2(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
{
int n;
Uint16 *p = NULL;
while (h--) {
n = w;
p = (Uint16 *) pixels;
p = (Uint16 *)pixels;
if (n > 1) {
if ((uintptr_t) p & 2) {
*p++ = (Uint16) color;
if ((uintptr_t)p & 2) {
*p++ = (Uint16)color;
--n;
}
SDL_memset4(p, color, (n >> 1));
}
if (n & 1) {
p[n - 1] = (Uint16) color;
p[n - 1] = (Uint16)color;
}
pixels += pitch;
}
}
static void
SDL_FillRect3(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
static void SDL_FillRect3(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
{
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
Uint8 b1 = (Uint8) (color & 0xFF);
Uint8 b2 = (Uint8) ((color >> 8) & 0xFF);
Uint8 b3 = (Uint8) ((color >> 16) & 0xFF);
Uint8 b1 = (Uint8)(color & 0xFF);
Uint8 b2 = (Uint8)((color >> 8) & 0xFF);
Uint8 b3 = (Uint8)((color >> 16) & 0xFF);
#elif SDL_BYTEORDER == SDL_BIG_ENDIAN
Uint8 b1 = (Uint8) ((color >> 16) & 0xFF);
Uint8 b2 = (Uint8) ((color >> 8) & 0xFF);
Uint8 b3 = (Uint8) (color & 0xFF);
Uint8 b1 = (Uint8)((color >> 16) & 0xFF);
Uint8 b2 = (Uint8)((color >> 8) & 0xFF);
Uint8 b3 = (Uint8)(color & 0xFF);
#endif
int n;
Uint8 *p = NULL;
@ -222,8 +220,7 @@ SDL_FillRect3(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
}
}
static void
SDL_FillRect4(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
static void SDL_FillRect4(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
{
while (h--) {
SDL_memset4(pixels, color, w);
@ -231,18 +228,17 @@ SDL_FillRect4(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
}
}
/*
/*
* This function performs a fast fill of the given rectangle with 'color'
*/
int
SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
int SDL_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
{
if (!dst) {
if (dst == NULL) {
return SDL_InvalidParamError("SDL_FillRect(): dst");
}
/* If 'rect' == NULL, then fill the whole surface */
if (!rect) {
if (rect == NULL) {
rect = &dst->clip_rect;
/* Don't attempt to fill if the surface's clip_rect is empty */
if (SDL_RectEmpty(rect)) {
@ -258,18 +254,21 @@ void FillRect8ARMNEONAsm(int32_t w, int32_t h, uint8_t *dst, int32_t dst_stride,
void FillRect16ARMNEONAsm(int32_t w, int32_t h, uint16_t *dst, int32_t dst_stride, uint16_t src);
void FillRect32ARMNEONAsm(int32_t w, int32_t h, uint32_t *dst, int32_t dst_stride, uint32_t src);
static void fill_8_neon(Uint8 * pixels, int pitch, Uint32 color, int w, int h) {
FillRect8ARMNEONAsm(w, h, (uint8_t *) pixels, pitch >> 0, color);
static void fill_8_neon(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
{
FillRect8ARMNEONAsm(w, h, (uint8_t *)pixels, pitch >> 0, color);
return;
}
static void fill_16_neon(Uint8 * pixels, int pitch, Uint32 color, int w, int h) {
FillRect16ARMNEONAsm(w, h, (uint16_t *) pixels, pitch >> 1, color);
static void fill_16_neon(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
{
FillRect16ARMNEONAsm(w, h, (uint16_t *)pixels, pitch >> 1, color);
return;
}
static void fill_32_neon(Uint8 * pixels, int pitch, Uint32 color, int w, int h) {
FillRect32ARMNEONAsm(w, h, (uint32_t *) pixels, pitch >> 2, color);
static void fill_32_neon(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
{
FillRect32ARMNEONAsm(w, h, (uint32_t *)pixels, pitch >> 2, color);
return;
}
#endif
@ -279,33 +278,35 @@ void FillRect8ARMSIMDAsm(int32_t w, int32_t h, uint8_t *dst, int32_t dst_stride,
void FillRect16ARMSIMDAsm(int32_t w, int32_t h, uint16_t *dst, int32_t dst_stride, uint16_t src);
void FillRect32ARMSIMDAsm(int32_t w, int32_t h, uint32_t *dst, int32_t dst_stride, uint32_t src);
static void fill_8_simd(Uint8 * pixels, int pitch, Uint32 color, int w, int h) {
FillRect8ARMSIMDAsm(w, h, (uint8_t *) pixels, pitch >> 0, color);
static void fill_8_simd(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
{
FillRect8ARMSIMDAsm(w, h, (uint8_t *)pixels, pitch >> 0, color);
return;
}
static void fill_16_simd(Uint8 * pixels, int pitch, Uint32 color, int w, int h) {
FillRect16ARMSIMDAsm(w, h, (uint16_t *) pixels, pitch >> 1, color);
static void fill_16_simd(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
{
FillRect16ARMSIMDAsm(w, h, (uint16_t *)pixels, pitch >> 1, color);
return;
}
static void fill_32_simd(Uint8 * pixels, int pitch, Uint32 color, int w, int h) {
FillRect32ARMSIMDAsm(w, h, (uint32_t *) pixels, pitch >> 2, color);
static void fill_32_simd(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
{
FillRect32ARMSIMDAsm(w, h, (uint32_t *)pixels, pitch >> 2, color);
return;
}
#endif
int
SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
Uint32 color)
int SDL_FillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
Uint32 color)
{
SDL_Rect clipped;
Uint8 *pixels;
const SDL_Rect* rect;
const SDL_Rect *rect;
void (*fill_function)(Uint8 * pixels, int pitch, Uint32 color, int w, int h) = NULL;
int i;
if (!dst) {
if (dst == NULL) {
return SDL_InvalidParamError("SDL_FillRects(): dst");
}
@ -319,7 +320,7 @@ SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
return SDL_SetError("SDL_FillRects(): You must lock the surface");
}
if (!rects) {
if (rects == NULL) {
return SDL_InvalidParamError("SDL_FillRects(): rects");
}
@ -329,10 +330,10 @@ SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
if (dst->format->BitsPerPixel < 8) {
if (count == 1) {
const SDL_Rect *r = &rects[0];
if (r->x == 0 && r->y == 0 && r->w == dst->w && r->w == dst->h) {
if (r->x == 0 && r->y == 0 && r->w == dst->w && r->h == dst->h) {
if (dst->format->BitsPerPixel == 4) {
Uint8 b = (((Uint8) color << 4) | (Uint8) color);
SDL_memset(dst->pixels, b, dst->h * dst->pitch);
Uint8 b = (((Uint8)color << 4) | (Uint8)color);
SDL_memset(dst->pixels, b, (size_t)dst->h * dst->pitch);
return 1;
}
}
@ -374,31 +375,31 @@ SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
if (fill_function == NULL) {
switch (dst->format->BytesPerPixel) {
case 1:
{
color |= (color << 8);
color |= (color << 16);
{
color |= (color << 8);
color |= (color << 16);
#ifdef __SSE__
if (SDL_HasSSE()) {
fill_function = SDL_FillRect1SSE;
break;
}
#endif
fill_function = SDL_FillRect1;
if (SDL_HasSSE()) {
fill_function = SDL_FillRect1SSE;
break;
}
#endif
fill_function = SDL_FillRect1;
break;
}
case 2:
{
color |= (color << 16);
{
color |= (color << 16);
#ifdef __SSE__
if (SDL_HasSSE()) {
fill_function = SDL_FillRect2SSE;
break;
}
#endif
fill_function = SDL_FillRect2;
if (SDL_HasSSE()) {
fill_function = SDL_FillRect2SSE;
break;
}
#endif
fill_function = SDL_FillRect2;
break;
}
case 3:
/* 24-bit RGB is a slow path, at least for now. */
@ -408,16 +409,16 @@ SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
}
case 4:
{
{
#ifdef __SSE__
if (SDL_HasSSE()) {
fill_function = SDL_FillRect4SSE;
break;
}
#endif
fill_function = SDL_FillRect4;
if (SDL_HasSSE()) {
fill_function = SDL_FillRect4SSE;
break;
}
#endif
fill_function = SDL_FillRect4;
break;
}
default:
return SDL_SetError("Unsupported pixel format");
@ -432,8 +433,8 @@ SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
}
rect = &clipped;
pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch +
rect->x * dst->format->BytesPerPixel;
pixels = (Uint8 *)dst->pixels + rect->y * dst->pitch +
rect->x * dst->format->BytesPerPixel;
fill_function(pixels, dst->pitch, color, rect->w, rect->h);
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -30,46 +30,45 @@
#include "SDL_RLEaccel_c.h"
#include "../SDL_list.h"
/* Lookup tables to expand partial bytes to the full 0..255 range */
static Uint8 lookup_0[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
};
static Uint8 lookup_1[] = {
0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 255
0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 255
};
static Uint8 lookup_2[] = {
0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 214, 218, 222, 226, 230, 234, 238, 242, 246, 250, 255
0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 214, 218, 222, 226, 230, 234, 238, 242, 246, 250, 255
};
static Uint8 lookup_3[] = {
0, 8, 16, 24, 32, 41, 49, 57, 65, 74, 82, 90, 98, 106, 115, 123, 131, 139, 148, 156, 164, 172, 180, 189, 197, 205, 213, 222, 230, 238, 246, 255
0, 8, 16, 24, 32, 41, 49, 57, 65, 74, 82, 90, 98, 106, 115, 123, 131, 139, 148, 156, 164, 172, 180, 189, 197, 205, 213, 222, 230, 238, 246, 255
};
static Uint8 lookup_4[] = {
0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255
0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255
};
static Uint8 lookup_5[] = {
0, 36, 72, 109, 145, 182, 218, 255
0, 36, 72, 109, 145, 182, 218, 255
};
static Uint8 lookup_6[] = {
0, 85, 170, 255
0, 85, 170, 255
};
static Uint8 lookup_7[] = {
0, 255
0, 255
};
static Uint8 lookup_8[] = {
255
255
};
Uint8* SDL_expand_byte[9] = {
Uint8 *SDL_expand_byte[9] = {
lookup_0,
lookup_1,
lookup_2,
@ -83,58 +82,61 @@ Uint8* SDL_expand_byte[9] = {
/* Helper functions */
const char*
SDL_GetPixelFormatName(Uint32 format)
#define CASE(X) \
case X: \
return #X;
const char *SDL_GetPixelFormatName(Uint32 format)
{
switch (format) {
#define CASE(X) case X: return #X;
CASE(SDL_PIXELFORMAT_INDEX1LSB)
CASE(SDL_PIXELFORMAT_INDEX1MSB)
CASE(SDL_PIXELFORMAT_INDEX4LSB)
CASE(SDL_PIXELFORMAT_INDEX4MSB)
CASE(SDL_PIXELFORMAT_INDEX8)
CASE(SDL_PIXELFORMAT_RGB332)
CASE(SDL_PIXELFORMAT_RGB444)
CASE(SDL_PIXELFORMAT_BGR444)
CASE(SDL_PIXELFORMAT_RGB555)
CASE(SDL_PIXELFORMAT_BGR555)
CASE(SDL_PIXELFORMAT_ARGB4444)
CASE(SDL_PIXELFORMAT_RGBA4444)
CASE(SDL_PIXELFORMAT_ABGR4444)
CASE(SDL_PIXELFORMAT_BGRA4444)
CASE(SDL_PIXELFORMAT_ARGB1555)
CASE(SDL_PIXELFORMAT_RGBA5551)
CASE(SDL_PIXELFORMAT_ABGR1555)
CASE(SDL_PIXELFORMAT_BGRA5551)
CASE(SDL_PIXELFORMAT_RGB565)
CASE(SDL_PIXELFORMAT_BGR565)
CASE(SDL_PIXELFORMAT_RGB24)
CASE(SDL_PIXELFORMAT_BGR24)
CASE(SDL_PIXELFORMAT_RGB888)
CASE(SDL_PIXELFORMAT_RGBX8888)
CASE(SDL_PIXELFORMAT_BGR888)
CASE(SDL_PIXELFORMAT_BGRX8888)
CASE(SDL_PIXELFORMAT_ARGB8888)
CASE(SDL_PIXELFORMAT_RGBA8888)
CASE(SDL_PIXELFORMAT_ABGR8888)
CASE(SDL_PIXELFORMAT_BGRA8888)
CASE(SDL_PIXELFORMAT_ARGB2101010)
CASE(SDL_PIXELFORMAT_YV12)
CASE(SDL_PIXELFORMAT_IYUV)
CASE(SDL_PIXELFORMAT_YUY2)
CASE(SDL_PIXELFORMAT_UYVY)
CASE(SDL_PIXELFORMAT_YVYU)
CASE(SDL_PIXELFORMAT_NV12)
CASE(SDL_PIXELFORMAT_NV21)
#undef CASE
CASE(SDL_PIXELFORMAT_INDEX1LSB)
CASE(SDL_PIXELFORMAT_INDEX1MSB)
CASE(SDL_PIXELFORMAT_INDEX4LSB)
CASE(SDL_PIXELFORMAT_INDEX4MSB)
CASE(SDL_PIXELFORMAT_INDEX8)
CASE(SDL_PIXELFORMAT_RGB332)
CASE(SDL_PIXELFORMAT_RGB444)
CASE(SDL_PIXELFORMAT_BGR444)
CASE(SDL_PIXELFORMAT_RGB555)
CASE(SDL_PIXELFORMAT_BGR555)
CASE(SDL_PIXELFORMAT_ARGB4444)
CASE(SDL_PIXELFORMAT_RGBA4444)
CASE(SDL_PIXELFORMAT_ABGR4444)
CASE(SDL_PIXELFORMAT_BGRA4444)
CASE(SDL_PIXELFORMAT_ARGB1555)
CASE(SDL_PIXELFORMAT_RGBA5551)
CASE(SDL_PIXELFORMAT_ABGR1555)
CASE(SDL_PIXELFORMAT_BGRA5551)
CASE(SDL_PIXELFORMAT_RGB565)
CASE(SDL_PIXELFORMAT_BGR565)
CASE(SDL_PIXELFORMAT_RGB24)
CASE(SDL_PIXELFORMAT_BGR24)
CASE(SDL_PIXELFORMAT_RGB888)
CASE(SDL_PIXELFORMAT_RGBX8888)
CASE(SDL_PIXELFORMAT_BGR888)
CASE(SDL_PIXELFORMAT_BGRX8888)
CASE(SDL_PIXELFORMAT_ARGB8888)
CASE(SDL_PIXELFORMAT_RGBA8888)
CASE(SDL_PIXELFORMAT_ABGR8888)
CASE(SDL_PIXELFORMAT_BGRA8888)
CASE(SDL_PIXELFORMAT_ARGB2101010)
CASE(SDL_PIXELFORMAT_YV12)
CASE(SDL_PIXELFORMAT_IYUV)
CASE(SDL_PIXELFORMAT_YUY2)
CASE(SDL_PIXELFORMAT_UYVY)
CASE(SDL_PIXELFORMAT_YVYU)
CASE(SDL_PIXELFORMAT_NV12)
CASE(SDL_PIXELFORMAT_NV21)
CASE(SDL_PIXELFORMAT_EXTERNAL_OES)
default:
return "SDL_PIXELFORMAT_UNKNOWN";
}
}
#undef CASE
SDL_bool
SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask,
Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask)
SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 *Rmask,
Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
{
Uint32 masks[4];
@ -291,9 +293,7 @@ SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask,
return SDL_TRUE;
}
Uint32
SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
Uint32 Amask)
Uint32 SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
{
switch (bpp) {
case 1:
@ -435,6 +435,7 @@ SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
return SDL_PIXELFORMAT_RGB24;
#endif
}
break;
case 32:
if (Rmask == 0) {
return SDL_PIXELFORMAT_RGB888;
@ -500,8 +501,7 @@ SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
static SDL_PixelFormat *formats;
static SDL_SpinLock formats_lock = 0;
SDL_PixelFormat *
SDL_AllocFormat(Uint32 pixel_format)
SDL_PixelFormat *SDL_AllocFormat(Uint32 pixel_format)
{
SDL_PixelFormat *format;
@ -526,7 +526,6 @@ SDL_AllocFormat(Uint32 pixel_format)
if (SDL_InitFormat(format, pixel_format) < 0) {
SDL_AtomicUnlock(&formats_lock);
SDL_free(format);
SDL_InvalidParamError("format");
return NULL;
}
@ -541,8 +540,7 @@ SDL_AllocFormat(Uint32 pixel_format)
return format;
}
int
SDL_InitFormat(SDL_PixelFormat * format, Uint32 pixel_format)
int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
{
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
@ -563,40 +561,48 @@ SDL_InitFormat(SDL_PixelFormat * format, Uint32 pixel_format)
format->Rshift = 0;
format->Rloss = 8;
if (Rmask) {
for (mask = Rmask; !(mask & 0x01); mask >>= 1)
for (mask = Rmask; !(mask & 0x01); mask >>= 1) {
++format->Rshift;
for (; (mask & 0x01); mask >>= 1)
}
for (; (mask & 0x01); mask >>= 1) {
--format->Rloss;
}
}
format->Gmask = Gmask;
format->Gshift = 0;
format->Gloss = 8;
if (Gmask) {
for (mask = Gmask; !(mask & 0x01); mask >>= 1)
for (mask = Gmask; !(mask & 0x01); mask >>= 1) {
++format->Gshift;
for (; (mask & 0x01); mask >>= 1)
}
for (; (mask & 0x01); mask >>= 1) {
--format->Gloss;
}
}
format->Bmask = Bmask;
format->Bshift = 0;
format->Bloss = 8;
if (Bmask) {
for (mask = Bmask; !(mask & 0x01); mask >>= 1)
for (mask = Bmask; !(mask & 0x01); mask >>= 1) {
++format->Bshift;
for (; (mask & 0x01); mask >>= 1)
}
for (; (mask & 0x01); mask >>= 1) {
--format->Bloss;
}
}
format->Amask = Amask;
format->Ashift = 0;
format->Aloss = 8;
if (Amask) {
for (mask = Amask; !(mask & 0x01); mask >>= 1)
for (mask = Amask; !(mask & 0x01); mask >>= 1) {
++format->Ashift;
for (; (mask & 0x01); mask >>= 1)
}
for (; (mask & 0x01); mask >>= 1) {
--format->Aloss;
}
}
format->palette = NULL;
@ -606,12 +612,11 @@ SDL_InitFormat(SDL_PixelFormat * format, Uint32 pixel_format)
return 0;
}
void
SDL_FreeFormat(SDL_PixelFormat *format)
void SDL_FreeFormat(SDL_PixelFormat *format)
{
SDL_PixelFormat *prev;
if (!format) {
if (format == NULL) {
SDL_InvalidParamError("format");
return;
}
@ -643,26 +648,26 @@ SDL_FreeFormat(SDL_PixelFormat *format)
SDL_free(format);
}
SDL_Palette *
SDL_AllocPalette(int ncolors)
SDL_Palette *SDL_AllocPalette(int ncolors)
{
SDL_Palette *palette;
/* Input validation */
if (ncolors < 1) {
SDL_InvalidParamError("ncolors");
return NULL;
SDL_InvalidParamError("ncolors");
return NULL;
}
palette = (SDL_Palette *) SDL_malloc(sizeof(*palette));
if (!palette) {
palette = (SDL_Palette *)SDL_malloc(sizeof(*palette));
if (palette == NULL) {
SDL_OutOfMemory();
return NULL;
}
palette->colors =
(SDL_Color *) SDL_malloc(ncolors * sizeof(*palette->colors));
(SDL_Color *)SDL_malloc(ncolors * sizeof(*palette->colors));
if (!palette->colors) {
SDL_free(palette);
SDL_OutOfMemory();
return NULL;
}
palette->ncolors = ncolors;
@ -674,10 +679,9 @@ SDL_AllocPalette(int ncolors)
return palette;
}
int
SDL_SetPixelFormatPalette(SDL_PixelFormat * format, SDL_Palette *palette)
int SDL_SetPixelFormatPalette(SDL_PixelFormat *format, SDL_Palette *palette)
{
if (!format) {
if (format == NULL) {
return SDL_InvalidParamError("SDL_SetPixelFormatPalette(): format");
}
@ -702,14 +706,13 @@ SDL_SetPixelFormatPalette(SDL_PixelFormat * format, SDL_Palette *palette)
return 0;
}
int
SDL_SetPaletteColors(SDL_Palette * palette, const SDL_Color * colors,
int firstcolor, int ncolors)
int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors,
int firstcolor, int ncolors)
{
int status = 0;
/* Verify the parameters */
if (!palette) {
if (palette == NULL) {
return -1;
}
if (ncolors > (palette->ncolors - firstcolor)) {
@ -729,10 +732,9 @@ SDL_SetPaletteColors(SDL_Palette * palette, const SDL_Color * colors,
return status;
}
void
SDL_FreePalette(SDL_Palette * palette)
void SDL_FreePalette(SDL_Palette *palette)
{
if (!palette) {
if (palette == NULL) {
SDL_InvalidParamError("palette");
return;
}
@ -746,12 +748,12 @@ SDL_FreePalette(SDL_Palette * palette)
/*
* Calculate an 8-bit (3 red, 3 green, 2 blue) dithered palette of colors
*/
void
SDL_DitherColors(SDL_Color * colors, int bpp)
void SDL_DitherColors(SDL_Color *colors, int bpp)
{
int i;
if (bpp != 8)
return; /* only 8bpp supported right now */
if (bpp != 8) {
return; /* only 8bpp supported right now */
}
for (i = 0; i < 256; i++) {
int r, g, b;
@ -774,8 +776,7 @@ SDL_DitherColors(SDL_Color * colors, int bpp)
/*
* Match an RGB value to a particular palette index
*/
Uint8
SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
/* Do colorspace distance matching */
unsigned int smallest;
@ -793,18 +794,17 @@ SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
distance = (rd * rd) + (gd * gd) + (bd * bd) + (ad * ad);
if (distance < smallest) {
pixel = i;
if (distance == 0) { /* Perfect match! */
if (distance == 0) { /* Perfect match! */
break;
}
smallest = distance;
}
}
return (pixel);
return pixel;
}
/* Tell whether palette is opaque, and if it has an alpha_channel */
void
SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_channel)
void SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_channel)
{
int i;
@ -849,38 +849,36 @@ SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_cha
*has_alpha_channel = SDL_TRUE;
}
/* Find the opaque pixel value corresponding to an RGB triple */
Uint32
SDL_MapRGB(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b)
Uint32 SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
{
if (!format) {
SDL_InvalidParamError("format");
return 0;
}
if (format->palette == NULL) {
return (r >> format->Rloss) << format->Rshift
| (g >> format->Gloss) << format->Gshift
| (b >> format->Bloss) << format->Bshift | format->Amask;
return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | format->Amask;
} else {
return SDL_FindColor(format->palette, r, g, b, SDL_ALPHA_OPAQUE);
}
}
/* Find the pixel value corresponding to an RGBA quadruple */
Uint32
SDL_MapRGBA(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b,
Uint8 a)
Uint32 SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
if (!format) {
SDL_InvalidParamError("format");
return 0;
}
if (format->palette == NULL) {
return (r >> format->Rloss) << format->Rshift
| (g >> format->Gloss) << format->Gshift
| (b >> format->Bloss) << format->Bshift
| ((Uint32)(a >> format->Aloss) << format->Ashift & format->Amask);
return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | ((Uint32)(a >> format->Aloss) << format->Ashift & format->Amask);
} else {
return SDL_FindColor(format->palette, r, g, b, a);
}
}
void
SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format, Uint8 * r, Uint8 * g,
Uint8 * b)
void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g,
Uint8 *b)
{
if (format->palette == NULL) {
unsigned v;
@ -901,9 +899,8 @@ SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format, Uint8 * r, Uint8 * g,
}
}
void
SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format,
Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat *format,
Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
{
if (format->palette == NULL) {
unsigned v;
@ -928,8 +925,7 @@ SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format,
}
/* Map from Palette to Palette */
static Uint8 *
Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical)
static Uint8 *Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical)
{
Uint8 *map;
int i;
@ -937,34 +933,31 @@ Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical)
if (identical) {
if (src->ncolors <= dst->ncolors) {
/* If an identical palette, no need to map */
if (src == dst
||
(SDL_memcmp
(src->colors, dst->colors,
src->ncolors * sizeof(SDL_Color)) == 0)) {
if (src == dst ||
(SDL_memcmp(src->colors, dst->colors,
src->ncolors * sizeof(SDL_Color)) == 0)) {
*identical = 1;
return (NULL);
return NULL;
}
}
*identical = 0;
}
map = (Uint8 *) SDL_calloc(256, sizeof(Uint8));
map = (Uint8 *)SDL_calloc(256, sizeof(Uint8));
if (map == NULL) {
SDL_OutOfMemory();
return (NULL);
return NULL;
}
for (i = 0; i < src->ncolors; ++i) {
map[i] = SDL_FindColor(dst,
src->colors[i].r, src->colors[i].g,
src->colors[i].b, src->colors[i].a);
}
return (map);
return map;
}
/* Map from Palette to BitField */
static Uint8 *
Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod,
SDL_PixelFormat * dst)
static Uint8 *Map1toN(SDL_PixelFormat *src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod,
SDL_PixelFormat *dst)
{
Uint8 *map;
int i;
@ -972,26 +965,25 @@ Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod,
SDL_Palette *pal = src->palette;
bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
map = (Uint8 *) SDL_calloc(256, bpp);
map = (Uint8 *)SDL_calloc(256, bpp);
if (map == NULL) {
SDL_OutOfMemory();
return (NULL);
return NULL;
}
/* We memory copy to the pixel map so the endianness is preserved */
for (i = 0; i < pal->ncolors; ++i) {
Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255);
Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255);
Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255);
Uint8 A = (Uint8) ((pal->colors[i].a * Amod) / 255);
Uint8 R = (Uint8)((pal->colors[i].r * Rmod) / 255);
Uint8 G = (Uint8)((pal->colors[i].g * Gmod) / 255);
Uint8 B = (Uint8)((pal->colors[i].b * Bmod) / 255);
Uint8 A = (Uint8)((pal->colors[i].a * Amod) / 255);
ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, (Uint32)R, (Uint32)G, (Uint32)B, (Uint32)A);
}
return (map);
return map;
}
/* Map from BitField to Dithered-Palette to Palette */
static Uint8 *
MapNto1(SDL_PixelFormat * src, SDL_PixelFormat * dst, int *identical)
static Uint8 *MapNto1(SDL_PixelFormat *src, SDL_PixelFormat *dst, int *identical)
{
/* Generate a 256 color dither palette */
SDL_Palette dithered;
@ -1001,19 +993,18 @@ MapNto1(SDL_PixelFormat * src, SDL_PixelFormat * dst, int *identical)
dithered.ncolors = 256;
SDL_DitherColors(colors, 8);
dithered.colors = colors;
return (Map1to1(&dithered, pal, identical));
return Map1to1(&dithered, pal, identical);
}
SDL_BlitMap *
SDL_AllocBlitMap(void)
SDL_BlitMap *SDL_AllocBlitMap(void)
{
SDL_BlitMap *map;
/* Allocate the empty map */
map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map));
map = (SDL_BlitMap *)SDL_calloc(1, sizeof(*map));
if (map == NULL) {
SDL_OutOfMemory();
return (NULL);
return NULL;
}
map->info.r = 0xFF;
map->info.g = 0xFF;
@ -1021,12 +1012,10 @@ SDL_AllocBlitMap(void)
map->info.a = 0xFF;
/* It's ready to go */
return (map);
return map;
}
void
SDL_InvalidateAllBlitMap(SDL_Surface *surface)
void SDL_InvalidateAllBlitMap(SDL_Surface *surface)
{
SDL_ListNode *l = surface->list_blitmap;
@ -1040,10 +1029,9 @@ SDL_InvalidateAllBlitMap(SDL_Surface *surface)
}
}
void
SDL_InvalidateMap(SDL_BlitMap * map)
void SDL_InvalidateMap(SDL_BlitMap *map)
{
if (!map) {
if (map == NULL) {
return;
}
if (map->dst) {
@ -1057,8 +1045,7 @@ SDL_InvalidateMap(SDL_BlitMap * map)
map->info.table = NULL;
}
int
SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst)
int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
{
SDL_PixelFormat *srcfmt;
SDL_PixelFormat *dstfmt;
@ -1084,18 +1071,19 @@ SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst)
Map1to1(srcfmt->palette, dstfmt->palette, &map->identity);
if (!map->identity) {
if (map->info.table == NULL) {
return (-1);
return -1;
}
}
if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel)
if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel) {
map->identity = 0;
}
} else {
/* Palette --> BitField */
map->info.table =
Map1toN(srcfmt, src->map->info.r, src->map->info.g,
src->map->info.b, src->map->info.a, dstfmt);
if (map->info.table == NULL) {
return (-1);
return -1;
}
}
} else {
@ -1104,10 +1092,10 @@ SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst)
map->info.table = MapNto1(srcfmt, dstfmt, &map->identity);
if (!map->identity) {
if (map->info.table == NULL) {
return (-1);
return -1;
}
}
map->identity = 0; /* Don't optimize to copy */
map->identity = 0; /* Don't optimize to copy */
} else {
/* BitField --> BitField */
if (srcfmt == dstfmt) {
@ -1136,11 +1124,10 @@ SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst)
}
/* Choose your blitters wisely */
return (SDL_CalculateBlit(src));
return SDL_CalculateBlit(src);
}
void
SDL_FreeBlitMap(SDL_BlitMap * map)
void SDL_FreeBlitMap(SDL_BlitMap *map)
{
if (map) {
SDL_InvalidateMap(map);
@ -1148,8 +1135,7 @@ SDL_FreeBlitMap(SDL_BlitMap * map)
}
}
void
SDL_CalculateGammaRamp(float gamma, Uint16 * ramp)
void SDL_CalculateGammaRamp(float gamma, Uint16 * ramp)
{
int i;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -29,19 +29,19 @@
#include "SDL_blit.h"
/* Pixel format functions */
extern int SDL_InitFormat(SDL_PixelFormat * format, Uint32 pixel_format);
extern int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format);
/* Blit mapping functions */
extern SDL_BlitMap *SDL_AllocBlitMap(void);
extern void SDL_InvalidateMap(SDL_BlitMap * map);
extern int SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst);
extern void SDL_FreeBlitMap(SDL_BlitMap * map);
extern void SDL_InvalidateMap(SDL_BlitMap *map);
extern int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst);
extern void SDL_FreeBlitMap(SDL_BlitMap *map);
extern void SDL_InvalidateAllBlitMap(SDL_Surface *surface);
/* Miscellaneous functions */
extern void SDL_DitherColors(SDL_Color * colors, int bpp);
extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern void SDL_DitherColors(SDL_Color *colors, int bpp);
extern Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern void SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_channel);
#endif /* SDL_pixels_c_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -25,9 +25,8 @@
/* There's no float version of this at the moment, because it's not a public API
and internally we only need the int version. */
SDL_bool
SDL_GetSpanEnclosingRect(int width, int height,
int numrects, const SDL_Rect * rects, SDL_Rect *span)
SDL_bool SDL_GetSpanEnclosingRect(int width, int height,
int numrects, const SDL_Rect *rects, SDL_Rect *span)
{
int i;
int span_y1, span_y2;
@ -39,10 +38,10 @@ SDL_GetSpanEnclosingRect(int width, int height,
} else if (height < 1) {
SDL_InvalidParamError("height");
return SDL_FALSE;
} else if (!rects) {
} else if (rects == NULL) {
SDL_InvalidParamError("rects");
return SDL_FALSE;
} else if (!span) {
} else if (span == NULL) {
SDL_InvalidParamError("span");
return SDL_FALSE;
} else if (numrects < 1) {
@ -80,7 +79,6 @@ SDL_GetSpanEnclosingRect(int width, int height,
return SDL_FALSE;
}
/* For use with the Cohen-Sutherland algorithm for line clipping, in SDL_rect_impl.h */
#define CODE_BOTTOM 1
#define CODE_TOP 2
@ -88,27 +86,27 @@ SDL_GetSpanEnclosingRect(int width, int height,
#define CODE_RIGHT 8
/* Same code twice, for float and int versions... */
#define RECTTYPE SDL_Rect
#define POINTTYPE SDL_Point
#define SCALARTYPE int
#define COMPUTEOUTCODE ComputeOutCode
#define SDL_HASINTERSECTION SDL_HasIntersection
#define SDL_INTERSECTRECT SDL_IntersectRect
#define SDL_RECTEMPTY SDL_RectEmpty
#define SDL_UNIONRECT SDL_UnionRect
#define SDL_ENCLOSEPOINTS SDL_EnclosePoints
#define RECTTYPE SDL_Rect
#define POINTTYPE SDL_Point
#define SCALARTYPE int
#define COMPUTEOUTCODE ComputeOutCode
#define SDL_HASINTERSECTION SDL_HasIntersection
#define SDL_INTERSECTRECT SDL_IntersectRect
#define SDL_RECTEMPTY SDL_RectEmpty
#define SDL_UNIONRECT SDL_UnionRect
#define SDL_ENCLOSEPOINTS SDL_EnclosePoints
#define SDL_INTERSECTRECTANDLINE SDL_IntersectRectAndLine
#include "SDL_rect_impl.h"
#define RECTTYPE SDL_FRect
#define POINTTYPE SDL_FPoint
#define SCALARTYPE float
#define COMPUTEOUTCODE ComputeOutCodeF
#define SDL_HASINTERSECTION SDL_HasIntersectionF
#define SDL_INTERSECTRECT SDL_IntersectFRect
#define SDL_RECTEMPTY SDL_FRectEmpty
#define SDL_UNIONRECT SDL_UnionFRect
#define SDL_ENCLOSEPOINTS SDL_EncloseFPoints
#define RECTTYPE SDL_FRect
#define POINTTYPE SDL_FPoint
#define SCALARTYPE float
#define COMPUTEOUTCODE ComputeOutCodeF
#define SDL_HASINTERSECTION SDL_HasIntersectionF
#define SDL_INTERSECTRECT SDL_IntersectFRect
#define SDL_RECTEMPTY SDL_FRectEmpty
#define SDL_UNIONRECT SDL_UnionFRect
#define SDL_ENCLOSEPOINTS SDL_EncloseFPoints
#define SDL_INTERSECTRECTANDLINE SDL_IntersectFRectAndLine
#include "SDL_rect_impl.h"

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,7 +24,7 @@
#include "../SDL_internal.h"
extern SDL_bool SDL_GetSpanEnclosingRect(int width, int height, int numrects, const SDL_Rect * rects, SDL_Rect *span);
extern SDL_bool SDL_GetSpanEnclosingRect(int width, int height, int numrects, const SDL_Rect *rects, SDL_Rect *span);
#endif /* SDL_rect_c_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -21,19 +21,18 @@
/* This file is #included twice to support int and float versions with the same code. */
SDL_bool
SDL_HASINTERSECTION(const RECTTYPE * A, const RECTTYPE * B)
SDL_bool SDL_HASINTERSECTION(const RECTTYPE *A, const RECTTYPE *B)
{
SCALARTYPE Amin, Amax, Bmin, Bmax;
if (!A) {
if (A == NULL) {
SDL_InvalidParamError("A");
return SDL_FALSE;
} else if (!B) {
} else if (B == NULL) {
SDL_InvalidParamError("B");
return SDL_FALSE;
} else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) {
return SDL_FALSE; /* Special cases for empty rects */
return SDL_FALSE; /* Special cases for empty rects */
}
/* Horizontal intersection */
@ -67,21 +66,20 @@ SDL_HASINTERSECTION(const RECTTYPE * A, const RECTTYPE * B)
return SDL_TRUE;
}
SDL_bool
SDL_INTERSECTRECT(const RECTTYPE * A, const RECTTYPE * B, RECTTYPE * result)
SDL_bool SDL_INTERSECTRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
{
SCALARTYPE Amin, Amax, Bmin, Bmax;
if (!A) {
if (A == NULL) {
SDL_InvalidParamError("A");
return SDL_FALSE;
} else if (!B) {
} else if (B == NULL) {
SDL_InvalidParamError("B");
return SDL_FALSE;
} else if (!result) {
} else if (result == NULL) {
SDL_InvalidParamError("result");
return SDL_FALSE;
} else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) { /* Special cases for empty rects */
} else if (SDL_RECTEMPTY(A) || SDL_RECTEMPTY(B)) { /* Special cases for empty rects */
result->w = 0;
result->h = 0;
return SDL_FALSE;
@ -118,30 +116,29 @@ SDL_INTERSECTRECT(const RECTTYPE * A, const RECTTYPE * B, RECTTYPE * result)
return !SDL_RECTEMPTY(result);
}
void
SDL_UNIONRECT(const RECTTYPE * A, const RECTTYPE * B, RECTTYPE * result)
void SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
{
SCALARTYPE Amin, Amax, Bmin, Bmax;
if (!A) {
if (A == NULL) {
SDL_InvalidParamError("A");
return;
} else if (!B) {
} else if (B == NULL) {
SDL_InvalidParamError("B");
return;
} else if (!result) {
} else if (result == NULL) {
SDL_InvalidParamError("result");
return;
} else if (SDL_RECTEMPTY(A)) { /* Special cases for empty Rects */
if (SDL_RECTEMPTY(B)) { /* A and B empty */
} else if (SDL_RECTEMPTY(A)) { /* Special cases for empty Rects */
if (SDL_RECTEMPTY(B)) { /* A and B empty */
SDL_zerop(result);
} else { /* A empty, B not empty */
} else { /* A empty, B not empty */
*result = *B;
}
return;
} else if (SDL_RECTEMPTY(B)) { /* A not empty, B empty */
*result = *A;
return;
} else if (SDL_RECTEMPTY(B)) { /* A not empty, B empty */
*result = *A;
return;
}
/* Horizontal union */
@ -173,8 +170,8 @@ SDL_UNIONRECT(const RECTTYPE * A, const RECTTYPE * B, RECTTYPE * result)
result->h = Amax - Amin;
}
SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE * points, int count, const RECTTYPE * clip,
RECTTYPE * result)
SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE *points, int count, const RECTTYPE *clip,
RECTTYPE *result)
{
SCALARTYPE minx = 0;
SCALARTYPE miny = 0;
@ -183,7 +180,7 @@ SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE * points, int count, const RECTTYPE *
SCALARTYPE x, y;
int i;
if (!points) {
if (points == NULL) {
SDL_InvalidParamError("points");
return SDL_FALSE;
} else if (count < 1) {
@ -195,8 +192,8 @@ SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE * points, int count, const RECTTYPE *
SDL_bool added = SDL_FALSE;
const SCALARTYPE clip_minx = clip->x;
const SCALARTYPE clip_miny = clip->y;
const SCALARTYPE clip_maxx = clip->x+clip->w-1;
const SCALARTYPE clip_maxy = clip->y+clip->h-1;
const SCALARTYPE clip_maxx = clip->x + clip->w - 1;
const SCALARTYPE clip_maxy = clip->y + clip->h - 1;
/* Special case for empty rectangle */
if (SDL_RECTEMPTY(clip)) {
@ -267,15 +264,14 @@ SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE * points, int count, const RECTTYPE *
if (result) {
result->x = minx;
result->y = miny;
result->w = (maxx-minx)+1;
result->h = (maxy-miny)+1;
result->w = (maxx - minx) + 1;
result->h = (maxy - miny) + 1;
}
return SDL_TRUE;
}
/* Use the Cohen-Sutherland algorithm for line clipping */
static int
COMPUTEOUTCODE(const RECTTYPE * rect, SCALARTYPE x, SCALARTYPE y)
static int COMPUTEOUTCODE(const RECTTYPE *rect, SCALARTYPE x, SCALARTYPE y)
{
int code = 0;
if (y < rect->y) {
@ -291,9 +287,7 @@ COMPUTEOUTCODE(const RECTTYPE * rect, SCALARTYPE x, SCALARTYPE y)
return code;
}
SDL_bool
SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1, SCALARTYPE *X2,
SCALARTYPE *Y2)
SDL_bool SDL_INTERSECTRECTANDLINE(const RECTTYPE *rect, SCALARTYPE *X1, SCALARTYPE *Y1, SCALARTYPE *X2, SCALARTYPE *Y2)
{
SCALARTYPE x = 0;
SCALARTYPE y = 0;
@ -305,23 +299,23 @@ SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1,
SCALARTYPE recty2;
int outcode1, outcode2;
if (!rect) {
if (rect == NULL) {
SDL_InvalidParamError("rect");
return SDL_FALSE;
} else if (!X1) {
} else if (X1 == NULL) {
SDL_InvalidParamError("X1");
return SDL_FALSE;
} else if (!Y1) {
} else if (Y1 == NULL) {
SDL_InvalidParamError("Y1");
return SDL_FALSE;
} else if (!X2) {
} else if (X2 == NULL) {
SDL_InvalidParamError("X2");
return SDL_FALSE;
} else if (!Y2) {
} else if (Y2 == NULL) {
SDL_InvalidParamError("Y2");
return SDL_FALSE;
} else if (SDL_RECTEMPTY(rect)) {
return SDL_FALSE; /* Special case for empty rect */
return SDL_FALSE; /* Special case for empty rect */
}
x1 = *X1;
@ -345,7 +339,7 @@ SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1,
return SDL_FALSE;
}
if (y1 == y2) { /* Horizontal line, easy to clip */
if (y1 == y2) { /* Horizontal line, easy to clip */
if (x1 < rectx1) {
*X1 = rectx1;
} else if (x1 > rectx2) {
@ -359,7 +353,7 @@ SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1,
return SDL_TRUE;
}
if (x1 == x2) { /* Vertical line, easy to clip */
if (x1 == x2) { /* Vertical line, easy to clip */
if (y1 < recty1) {
*Y1 = recty1;
} else if (y1 > recty2) {
@ -400,21 +394,23 @@ SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1,
outcode1 = COMPUTEOUTCODE(rect, x, y);
} else {
if (outcode2 & CODE_TOP) {
SDL_assert(y2 != y1); /* if equal: division by zero. */
y = recty1;
x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1);
} else if (outcode2 & CODE_BOTTOM) {
SDL_assert(y2 != y1); /* if equal: division by zero. */
y = recty2;
x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1);
} else if (outcode2 & CODE_LEFT) {
/* If this assertion ever fires, here's the static analysis that warned about it:
http://buildbot.libsdl.org/sdl-static-analysis/sdl-macosx-static-analysis/sdl-macosx-static-analysis-1101/report-b0d01a.html#EndPath */
SDL_assert(x2 != x1); /* if equal: division by zero. */
SDL_assert(x2 != x1); /* if equal: division by zero. */
x = rectx1;
y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);
} else if (outcode2 & CODE_RIGHT) {
/* If this assertion ever fires, here's the static analysis that warned about it:
http://buildbot.libsdl.org/sdl-static-analysis/sdl-macosx-static-analysis/sdl-macosx-static-analysis-1101/report-39b114.html#EndPath */
SDL_assert(x2 != x1); /* if equal: division by zero. */
SDL_assert(x2 != x1); /* if equal: division by zero. */
x = rectx2;
y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -28,149 +28,157 @@
#include "SDL_shape.h"
#include "SDL_shape_internals.h"
SDL_Window*
SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags)
SDL_Window *SDL_CreateShapedWindow(const char *title, unsigned int x, unsigned int y, unsigned int w, unsigned int h, Uint32 flags)
{
SDL_Window *result = NULL;
result = SDL_CreateWindow(title,-1000,-1000,w,h,(flags | SDL_WINDOW_BORDERLESS) & (~SDL_WINDOW_FULLSCREEN) & (~SDL_WINDOW_RESIZABLE) /* & (~SDL_WINDOW_SHOWN) */);
if(result != NULL) {
result = SDL_CreateWindow(title, -1000, -1000, w, h, (flags | SDL_WINDOW_BORDERLESS) & (~SDL_WINDOW_FULLSCREEN) & (~SDL_WINDOW_RESIZABLE) /* & (~SDL_WINDOW_SHOWN) */);
if (result != NULL) {
if (SDL_GetVideoDevice()->shape_driver.CreateShaper == NULL) {
SDL_DestroyWindow(result);
return NULL;
}
result->shaper = SDL_GetVideoDevice()->shape_driver.CreateShaper(result);
if(result->shaper != NULL) {
if (result->shaper != NULL) {
result->shaper->userx = x;
result->shaper->usery = y;
result->shaper->mode.mode = ShapeModeDefault;
result->shaper->mode.parameters.binarizationCutoff = 1;
result->shaper->hasshape = SDL_FALSE;
return result;
}
else {
} else {
SDL_DestroyWindow(result);
return NULL;
}
}
else
return NULL;
return NULL;
}
SDL_bool
SDL_IsShapedWindow(const SDL_Window *window)
SDL_bool SDL_IsShapedWindow(const SDL_Window *window)
{
if(window == NULL)
if (window == NULL) {
return SDL_FALSE;
else
return (SDL_bool)(window->shaper != NULL);
}
return (SDL_bool)(window->shaper != NULL);
}
/* REQUIRES that bitmap point to a w-by-h bitmap with ppb pixels-per-byte. */
void
SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb)
void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode, SDL_Surface *shape, Uint8 *bitmap, Uint8 ppb)
{
int x = 0;
int y = 0;
Uint8 r = 0,g = 0,b = 0,alpha = 0;
Uint8* pixel = NULL;
Uint32 pixel_value = 0,mask_value = 0;
int bytes_per_scanline = (shape->w + (ppb - 1)) / ppb;
Uint8 r = 0, g = 0, b = 0, alpha = 0;
Uint8 *pixel = NULL;
Uint32 pixel_value = 0, mask_value = 0;
size_t bytes_per_scanline = (size_t)(shape->w + (ppb - 1)) / ppb;
Uint8 *bitmap_scanline;
SDL_Color key;
if(SDL_MUSTLOCK(shape))
if (SDL_MUSTLOCK(shape)) {
SDL_LockSurface(shape);
for(y = 0;y<shape->h;y++) {
}
SDL_memset(bitmap, 0, shape->h * bytes_per_scanline);
for (y = 0; y < shape->h; y++) {
bitmap_scanline = bitmap + y * bytes_per_scanline;
for(x=0;x<shape->w;x++) {
for (x = 0; x < shape->w; x++) {
alpha = 0;
pixel_value = 0;
pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel);
switch(shape->format->BytesPerPixel) {
case(1):
pixel_value = *pixel;
break;
case(2):
pixel_value = *(Uint16*)pixel;
break;
case(3):
pixel_value = *(Uint32*)pixel & (~shape->format->Amask);
break;
case(4):
pixel_value = *(Uint32*)pixel;
break;
pixel = (Uint8 *)(shape->pixels) + (y * shape->pitch) + (x * shape->format->BytesPerPixel);
switch (shape->format->BytesPerPixel) {
case (1):
pixel_value = *pixel;
break;
case (2):
pixel_value = *(Uint16 *)pixel;
break;
case (3):
pixel_value = *(Uint32 *)pixel & (~shape->format->Amask);
break;
case (4):
pixel_value = *(Uint32 *)pixel;
break;
}
SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha);
switch(mode.mode) {
case(ShapeModeDefault):
mask_value = (alpha >= 1 ? 1 : 0);
break;
case(ShapeModeBinarizeAlpha):
mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0);
break;
case(ShapeModeReverseBinarizeAlpha):
mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0);
break;
case(ShapeModeColorKey):
key = mode.parameters.colorKey;
mask_value = ((key.r != r || key.g != g || key.b != b) ? 1 : 0);
break;
SDL_GetRGBA(pixel_value, shape->format, &r, &g, &b, &alpha);
switch (mode.mode) {
case (ShapeModeDefault):
mask_value = (alpha >= 1 ? 1 : 0);
break;
case (ShapeModeBinarizeAlpha):
mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0);
break;
case (ShapeModeReverseBinarizeAlpha):
mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0);
break;
case (ShapeModeColorKey):
key = mode.parameters.colorKey;
mask_value = ((key.r != r || key.g != g || key.b != b) ? 1 : 0);
break;
}
bitmap_scanline[x / ppb] |= mask_value << (x % ppb);
}
}
if(SDL_MUSTLOCK(shape))
if (SDL_MUSTLOCK(shape)) {
SDL_UnlockSurface(shape);
}
}
static SDL_ShapeTree*
RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_Rect dimensions) {
int x = 0,y = 0;
Uint8* pixel = NULL;
static SDL_ShapeTree *RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode, SDL_Surface *mask, SDL_Rect dimensions)
{
int x = 0, y = 0;
Uint8 *pixel = NULL;
Uint32 pixel_value = 0;
Uint8 r = 0,g = 0,b = 0,a = 0;
Uint8 r = 0, g = 0, b = 0, a = 0;
SDL_bool pixel_opaque = SDL_FALSE;
int last_opaque = -1;
SDL_Color key;
SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree));
SDL_Rect next = {0,0,0,0};
SDL_ShapeTree *result = (SDL_ShapeTree *)SDL_malloc(sizeof(SDL_ShapeTree));
SDL_Rect next = { 0, 0, 0, 0 };
for(y=dimensions.y;y<dimensions.y + dimensions.h;y++) {
for(x=dimensions.x;x<dimensions.x + dimensions.w;x++) {
if (result == NULL) {
SDL_OutOfMemory();
return NULL;
}
for (y = dimensions.y; y < dimensions.y + dimensions.h; y++) {
for (x = dimensions.x; x < dimensions.x + dimensions.w; x++) {
pixel_value = 0;
pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel);
switch(mask->format->BytesPerPixel) {
case(1):
pixel_value = *pixel;
break;
case(2):
pixel_value = *(Uint16*)pixel;
break;
case(3):
pixel_value = *(Uint32*)pixel & (~mask->format->Amask);
break;
case(4):
pixel_value = *(Uint32*)pixel;
break;
pixel = (Uint8 *)(mask->pixels) + (y * mask->pitch) + (x * mask->format->BytesPerPixel);
switch (mask->format->BytesPerPixel) {
case (1):
pixel_value = *pixel;
break;
case (2):
pixel_value = *(Uint16 *)pixel;
break;
case (3):
pixel_value = *(Uint32 *)pixel & (~mask->format->Amask);
break;
case (4):
pixel_value = *(Uint32 *)pixel;
break;
}
SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a);
switch(mode.mode) {
case(ShapeModeDefault):
pixel_opaque = (a >= 1 ? SDL_TRUE : SDL_FALSE);
break;
case(ShapeModeBinarizeAlpha):
pixel_opaque = (a >= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
break;
case(ShapeModeReverseBinarizeAlpha):
pixel_opaque = (a <= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
break;
case(ShapeModeColorKey):
key = mode.parameters.colorKey;
pixel_opaque = ((key.r != r || key.g != g || key.b != b) ? SDL_TRUE : SDL_FALSE);
break;
SDL_GetRGBA(pixel_value, mask->format, &r, &g, &b, &a);
switch (mode.mode) {
case (ShapeModeDefault):
pixel_opaque = (a >= 1 ? SDL_TRUE : SDL_FALSE);
break;
case (ShapeModeBinarizeAlpha):
pixel_opaque = (a >= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
break;
case (ShapeModeReverseBinarizeAlpha):
pixel_opaque = (a <= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
break;
case (ShapeModeColorKey):
key = mode.parameters.colorKey;
pixel_opaque = ((key.r != r || key.g != g || key.b != b) ? SDL_TRUE : SDL_FALSE);
break;
}
if(last_opaque == -1)
if (last_opaque == -1) {
last_opaque = pixel_opaque;
if(last_opaque != pixel_opaque) {
}
if (last_opaque != pixel_opaque) {
const int halfwidth = dimensions.w / 2;
const int halfheight = dimensions.h / 2;
@ -180,129 +188,154 @@ RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_Rec
next.y = dimensions.y;
next.w = halfwidth;
next.h = halfheight;
result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode, mask, next);
next.x = dimensions.x + halfwidth;
next.w = dimensions.w - halfwidth;
result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode, mask, next);
next.x = dimensions.x;
next.w = halfwidth;
next.y = dimensions.y + halfheight;
next.h = dimensions.h - halfheight;
result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode, mask, next);
next.x = dimensions.x + halfwidth;
next.w = dimensions.w - halfwidth;
result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode, mask, next);
return result;
}
}
}
/* If we never recursed, all the pixels in this quadrant have the same "value". */
result->kind = (last_opaque == SDL_TRUE ? OpaqueShape : TransparentShape);
result->data.shape = dimensions;
return result;
}
SDL_ShapeTree*
SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape)
SDL_ShapeTree *SDL_CalculateShapeTree(SDL_WindowShapeMode mode, SDL_Surface *shape)
{
SDL_Rect dimensions;
SDL_ShapeTree* result = NULL;
SDL_ShapeTree *result = NULL;
dimensions.x = 0;
dimensions.y = 0;
dimensions.w = shape->w;
dimensions.h = shape->h;
if(SDL_MUSTLOCK(shape))
if (SDL_MUSTLOCK(shape)) {
SDL_LockSurface(shape);
result = RecursivelyCalculateShapeTree(mode,shape,dimensions);
if(SDL_MUSTLOCK(shape))
}
result = RecursivelyCalculateShapeTree(mode, shape, dimensions);
if (SDL_MUSTLOCK(shape)) {
SDL_UnlockSurface(shape);
}
return result;
}
void
SDL_TraverseShapeTree(SDL_ShapeTree *tree,SDL_TraversalFunction function,void* closure)
void SDL_TraverseShapeTree(SDL_ShapeTree *tree, SDL_TraversalFunction function, void *closure)
{
SDL_assert(tree != NULL);
if(tree->kind == QuadShape) {
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure);
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure);
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft,function,closure);
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,closure);
if (tree->kind == QuadShape) {
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft, function, closure);
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright, function, closure);
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft, function, closure);
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright, function, closure);
} else {
function(tree, closure);
}
else
function(tree,closure);
}
void
SDL_FreeShapeTree(SDL_ShapeTree** shape_tree)
void SDL_FreeShapeTree(SDL_ShapeTree **shape_tree)
{
if((*shape_tree)->kind == QuadShape) {
SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.upleft);
SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.upright);
SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.downleft);
SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.downright);
if ((*shape_tree)->kind == QuadShape) {
SDL_FreeShapeTree((SDL_ShapeTree **)(char *)&(*shape_tree)->data.children.upleft);
SDL_FreeShapeTree((SDL_ShapeTree **)(char *)&(*shape_tree)->data.children.upright);
SDL_FreeShapeTree((SDL_ShapeTree **)(char *)&(*shape_tree)->data.children.downleft);
SDL_FreeShapeTree((SDL_ShapeTree **)(char *)&(*shape_tree)->data.children.downright);
}
SDL_free(*shape_tree);
*shape_tree = NULL;
}
int
SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode)
int SDL_SetWindowShape(SDL_Window *window, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
int result;
if(window == NULL || !SDL_IsShapedWindow(window))
if (window == NULL || !SDL_IsShapedWindow(window)) {
/* The window given was not a shapeable window. */
return SDL_NONSHAPEABLE_WINDOW;
if(shape == NULL)
}
if (shape == NULL) {
/* Invalid shape argument. */
return SDL_INVALID_SHAPE_ARGUMENT;
}
if(shape_mode != NULL)
if (shape_mode != NULL) {
window->shaper->mode = *shape_mode;
result = SDL_GetVideoDevice()->shape_driver.SetWindowShape(window->shaper,shape,shape_mode);
}
result = _this->shape_driver.SetWindowShape(window->shaper, shape, shape_mode);
window->shaper->hasshape = SDL_TRUE;
if(window->shaper->userx != 0 && window->shaper->usery != 0) {
SDL_SetWindowPosition(window,window->shaper->userx,window->shaper->usery);
if (window->shaper->userx != 0 && window->shaper->usery != 0) {
int x = window->shaper->userx;
int y = window->shaper->usery;
if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISUNDEFINED(y) ||
SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
int displayIndex;
SDL_Rect bounds;
if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) {
displayIndex = (x & 0xFFFF);
if (displayIndex >= _this->num_displays) {
displayIndex = 0;
}
} else {
displayIndex = (y & 0xFFFF);
if (displayIndex >= _this->num_displays) {
displayIndex = 0;
}
}
SDL_GetDisplayBounds(displayIndex, &bounds);
if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) {
window->x = bounds.x + (bounds.w - window->w) / 2;
}
if (SDL_WINDOWPOS_ISUNDEFINED(y) || SDL_WINDOWPOS_ISCENTERED(y)) {
window->y = bounds.y + (bounds.h - window->h) / 2;
}
}
SDL_SetWindowPosition(window, x, y);
window->shaper->userx = 0;
window->shaper->usery = 0;
}
return result;
}
static SDL_bool
SDL_WindowHasAShape(SDL_Window *window)
static SDL_bool SDL_WindowHasAShape(SDL_Window *window)
{
if (window == NULL || !SDL_IsShapedWindow(window))
if (window == NULL || !SDL_IsShapedWindow(window)) {
return SDL_FALSE;
}
return window->shaper->hasshape;
}
int
SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shape_mode)
int SDL_GetShapedWindowMode(SDL_Window *window, SDL_WindowShapeMode *shape_mode)
{
if(window != NULL && SDL_IsShapedWindow(window)) {
if(shape_mode == NULL) {
if(SDL_WindowHasAShape(window))
/* The window given has a shape. */
return 0;
else
/* The window given is shapeable but lacks a shape. */
return SDL_WINDOW_LACKS_SHAPE;
}
else {
if (window != NULL && SDL_IsShapedWindow(window)) {
if (shape_mode == NULL) {
if (SDL_WindowHasAShape(window)) {
return 0; /* The window given has a shape. */
} else {
return SDL_WINDOW_LACKS_SHAPE; /* The window given is shapeable but lacks a shape. */
}
} else {
*shape_mode = window->shaper->mode;
return 0;
}
}
else
/* The window given is not a valid shapeable window. */
return SDL_NONSHAPEABLE_WINDOW;
return SDL_NONSHAPEABLE_WINDOW; /* The window given is not a valid shapeable window. */
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -37,28 +37,36 @@ extern "C" {
struct SDL_ShapeTree;
typedef struct {
struct SDL_ShapeTree *upleft,*upright,*downleft,*downright;
typedef struct
{
struct SDL_ShapeTree *upleft, *upright, *downleft, *downright;
} SDL_QuadTreeChildren;
typedef union {
typedef union
{
SDL_QuadTreeChildren children;
SDL_Rect shape;
} SDL_ShapeUnion;
typedef enum { QuadShape,TransparentShape,OpaqueShape } SDL_ShapeKind;
typedef enum
{
QuadShape,
TransparentShape,
OpaqueShape
} SDL_ShapeKind;
typedef struct SDL_ShapeTree {
typedef struct SDL_ShapeTree
{
SDL_ShapeKind kind;
SDL_ShapeUnion data;
} SDL_ShapeTree;
typedef void(*SDL_TraversalFunction)(SDL_ShapeTree*,void*);
typedef void (*SDL_TraversalFunction)(SDL_ShapeTree *, void *);
extern void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb);
extern SDL_ShapeTree* SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape);
extern void SDL_TraverseShapeTree(SDL_ShapeTree *tree,SDL_TraversalFunction function,void* closure);
extern void SDL_FreeShapeTree(SDL_ShapeTree** shape_tree);
extern void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode, SDL_Surface *shape, Uint8 *bitmap, Uint8 ppb);
extern SDL_ShapeTree *SDL_CalculateShapeTree(SDL_WindowShapeMode mode, SDL_Surface *shape);
extern void SDL_TraverseShapeTree(SDL_ShapeTree *tree, SDL_TraversalFunction function, void *closure);
extern void SDL_FreeShapeTree(SDL_ShapeTree **shape_tree);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,25 +26,22 @@
static int SDL_LowerSoftStretchNearest(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
static int SDL_LowerSoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
static int SDL_UpperSoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, SDL_Surface * dst, const SDL_Rect * dstrect, SDL_ScaleMode scaleMode);
static int SDL_UpperSoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
int
SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect)
int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect)
{
return SDL_UpperSoftStretch(src, srcrect, dst, dstrect, SDL_ScaleModeNearest);
}
int
SDL_SoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect)
int SDL_SoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect)
{
return SDL_UpperSoftStretch(src, srcrect, dst, dstrect, SDL_ScaleModeLinear);
}
static int
SDL_UpperSoftStretch(SDL_Surface * src, const SDL_Rect * srcrect,
SDL_Surface * dst, const SDL_Rect * dstrect, SDL_ScaleMode scaleMode)
static int SDL_UpperSoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode)
{
int ret;
int src_locked;
@ -140,55 +137,53 @@ SDL_UpperSoftStretch(SDL_Surface * src, const SDL_Rect * srcrect,
Because with SSE: add-multiply: _mm_madd_epi16 works with signed int
so pixels 0xb1...... are negatives and false the result
same in NEON probably */
#define PRECISION 7
#define PRECISION 7
#define FIXED_POINT(i) ((Uint32)(i) << 16)
#define SRC_INDEX(fp) ((Uint32)(fp) >> 16)
#define INTEGER(fp) ((Uint32)(fp) >> PRECISION)
#define FRAC(fp) ((Uint32)(fp >> (16 - PRECISION)) & ((1<<PRECISION) - 1))
#define FRAC_ZERO 0
#define FRAC_ONE (1 << PRECISION)
#define FP_ONE FIXED_POINT(1)
#define BILINEAR___START \
int i; \
int fp_sum_h, fp_step_h, left_pad_h, right_pad_h; \
int fp_sum_w, fp_step_w, left_pad_w, right_pad_w; \
int fp_sum_w_init, left_pad_w_init, right_pad_w_init, dst_gap, middle_init; \
get_scaler_datas(src_h, dst_h, &fp_sum_h, &fp_step_h, &left_pad_h, &right_pad_h); \
get_scaler_datas(src_w, dst_w, &fp_sum_w, &fp_step_w, &left_pad_w, &right_pad_w); \
fp_sum_w_init = fp_sum_w + left_pad_w * fp_step_w; \
left_pad_w_init = left_pad_w; \
right_pad_w_init = right_pad_w; \
dst_gap = dst_pitch - 4 * dst_w; \
middle_init = dst_w - left_pad_w - right_pad_w; \
#define BILINEAR___HEIGHT \
int index_h, frac_h0, frac_h1, middle; \
const Uint32 *src_h0, *src_h1; \
int no_padding, incr_h0, incr_h1; \
\
no_padding = !(i < left_pad_h || i > dst_h - 1 - right_pad_h); \
index_h = SRC_INDEX(fp_sum_h); \
frac_h0 = FRAC(fp_sum_h); \
\
index_h = no_padding ? index_h : (i < left_pad_h ? 0 : src_h - 1); \
frac_h0 = no_padding ? frac_h0 : 0; \
incr_h1 = no_padding ? src_pitch : 0; \
incr_h0 = index_h * src_pitch; \
\
src_h0 = (const Uint32 *)((const Uint8 *)src + incr_h0); \
src_h1 = (const Uint32 *)((const Uint8 *)src_h0 + incr_h1); \
\
fp_sum_h += fp_step_h; \
\
frac_h1 = FRAC_ONE - frac_h0; \
fp_sum_w = fp_sum_w_init; \
right_pad_w = right_pad_w_init; \
left_pad_w = left_pad_w_init; \
middle = middle_init; \
#define FIXED_POINT(i) ((Uint32)(i) << 16)
#define SRC_INDEX(fp) ((Uint32)(fp) >> 16)
#define INTEGER(fp) ((Uint32)(fp) >> PRECISION)
#define FRAC(fp) ((Uint32)(fp >> (16 - PRECISION)) & ((1 << PRECISION) - 1))
#define FRAC_ZERO 0
#define FRAC_ONE (1 << PRECISION)
#define FP_ONE FIXED_POINT(1)
#define BILINEAR___START \
int i; \
int fp_sum_h, fp_step_h, left_pad_h, right_pad_h; \
int fp_sum_w, fp_step_w, left_pad_w, right_pad_w; \
int fp_sum_w_init, left_pad_w_init, right_pad_w_init, dst_gap, middle_init; \
get_scaler_datas(src_h, dst_h, &fp_sum_h, &fp_step_h, &left_pad_h, &right_pad_h); \
get_scaler_datas(src_w, dst_w, &fp_sum_w, &fp_step_w, &left_pad_w, &right_pad_w); \
fp_sum_w_init = fp_sum_w + left_pad_w * fp_step_w; \
left_pad_w_init = left_pad_w; \
right_pad_w_init = right_pad_w; \
dst_gap = dst_pitch - 4 * dst_w; \
middle_init = dst_w - left_pad_w - right_pad_w;
#define BILINEAR___HEIGHT \
int index_h, frac_h0, frac_h1, middle; \
const Uint32 *src_h0, *src_h1; \
int no_padding, incr_h0, incr_h1; \
\
no_padding = !(i < left_pad_h || i > dst_h - 1 - right_pad_h); \
index_h = SRC_INDEX(fp_sum_h); \
frac_h0 = FRAC(fp_sum_h); \
\
index_h = no_padding ? index_h : (i < left_pad_h ? 0 : src_h - 1); \
frac_h0 = no_padding ? frac_h0 : 0; \
incr_h1 = no_padding ? src_pitch : 0; \
incr_h0 = index_h * src_pitch; \
\
src_h0 = (const Uint32 *)((const Uint8 *)src + incr_h0); \
src_h1 = (const Uint32 *)((const Uint8 *)src_h0 + incr_h1); \
\
fp_sum_h += fp_step_h; \
\
frac_h1 = FRAC_ONE - frac_h0; \
fp_sum_w = fp_sum_w_init; \
right_pad_w = right_pad_w_init; \
left_pad_w = left_pad_w_init; \
middle = middle_init;
#if defined(__clang__)
// Remove inlining of this function
@ -198,12 +193,11 @@ SDL_UpperSoftStretch(SDL_Surface * src, const SDL_Rect * srcrect,
// OK with clang 12.0.0 / Xcode
__attribute__((noinline))
#endif
static void
get_scaler_datas(int src_nb, int dst_nb, int *fp_start, int *fp_step, int *left_pad, int *right_pad)
static void get_scaler_datas(int src_nb, int dst_nb, int *fp_start, int *fp_step, int *left_pad, int *right_pad)
{
int step = FIXED_POINT(src_nb) / (dst_nb); /* source step in fixed point */
int x0 = FP_ONE / 2; /* dst first pixel center at 0.5 in fixed point */
int step = FIXED_POINT(src_nb) / (dst_nb); /* source step in fixed point */
int x0 = FP_ONE / 2; /* dst first pixel center at 0.5 in fixed point */
int fp_sum;
int i;
#if 0
@ -215,7 +209,7 @@ get_scaler_datas(int src_nb, int dst_nb, int *fp_start, int *fp_step, int *left_
Sint64 tmp[2];
tmp[0] = (Sint64)step * (x0 >> 16);
tmp[1] = (Sint64)step * (x0 & 0xFFFF);
x0 = (int) (tmp[0] + ((tmp[1] + 0x8000) >> 16)); /* x0 == (step + 1) / 2 */
x0 = (int)(tmp[0] + ((tmp[1] + 0x8000) >> 16)); /* x0 == (step + 1) / 2 */
#endif
/* -= 0.5, get back the pixel origin, in source coordinates */
x0 -= FP_ONE / 2;
@ -237,19 +231,19 @@ get_scaler_datas(int src_nb, int dst_nb, int *fp_start, int *fp_step, int *left_
}
fp_sum += step;
}
// SDL_Log("%d -> %d x0=%d step=%d left_pad=%d right_pad=%d", src_nb, dst_nb, *fp_start, *fp_step, *left_pad, *right_pad);
// SDL_Log("%d -> %d x0=%d step=%d left_pad=%d right_pad=%d", src_nb, dst_nb, *fp_start, *fp_step, *left_pad, *right_pad);
}
typedef struct color_t {
Uint8 a;
Uint8 b;
Uint8 c;
Uint8 d;
typedef struct color_t
{
Uint8 a;
Uint8 b;
Uint8 c;
Uint8 d;
} color_t;
#if 0
static void
printf_64(const char *str, void *var)
static void printf_64(const char *str, void *var)
{
uint8_t *val = (uint8_t*) var;
printf(" * %s: %02x %02x %02x %02x _ %02x %02x %02x %02x\n",
@ -259,12 +253,11 @@ printf_64(const char *str, void *var)
/* Interpolated == x0 + frac * (x1 - x0) == x0 * (1 - frac) + x1 * frac */
static SDL_INLINE void
INTERPOL(const Uint32 *src_x0, const Uint32 *src_x1, int frac0, int frac1, Uint32 *dst)
static SDL_INLINE void INTERPOL(const Uint32 *src_x0, const Uint32 *src_x1, int frac0, int frac1, Uint32 *dst)
{
const color_t *c0 = (const color_t *)src_x0;
const color_t *c1 = (const color_t *)src_x1;
color_t *cx = (color_t *)dst;
color_t *cx = (color_t *)dst;
#if 0
cx->a = c0->a + INTEGER(frac0 * (c1->a - c0->a));
cx->b = c0->b + INTEGER(frac0 * (c1->b - c0->b));
@ -278,23 +271,21 @@ INTERPOL(const Uint32 *src_x0, const Uint32 *src_x1, int frac0, int frac1, Uint3
#endif
}
static SDL_INLINE void
INTERPOL_BILINEAR(const Uint32 *s0, const Uint32 *s1, int frac_w0, int frac_h0, int frac_h1, Uint32 *dst)
static SDL_INLINE void INTERPOL_BILINEAR(const Uint32 *s0, const Uint32 *s1, int frac_w0, int frac_h0, int frac_h1, Uint32 *dst)
{
Uint32 tmp[2];
unsigned int frac_w1 = FRAC_ONE - frac_w0;
/* Vertical first, store to 'tmp' */
INTERPOL(s0, s1, frac_h0, frac_h1, tmp);
INTERPOL(s0, s1, frac_h0, frac_h1, tmp);
INTERPOL(s0 + 1, s1 + 1, frac_h0, frac_h1, tmp + 1);
/* Horizontal, store to 'dst' */
INTERPOL(tmp, tmp + 1, frac_w0, frac_w1, dst);
INTERPOL(tmp, tmp + 1, frac_w0, frac_w1, dst);
}
static int
scale_mat(const Uint32 *src, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static int scale_mat(const Uint32 *src, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
BILINEAR___START
@ -314,14 +305,14 @@ scale_mat(const Uint32 *src, int src_w, int src_h, int src_pitch,
int frac_w = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
/*
x00 ... x0_ ..... x01
. . .
. x .
. . .
. . .
x10 ... x1_ ..... x11
*/
/*
x00 ... x0_ ..... x01
. . .
. x .
. . .
. . .
x10 ... x1_ ..... x11
*/
s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w);
s_10_11 = (const Uint32 *)((const Uint8 *)src_h1 + index_w);
@ -343,29 +334,28 @@ scale_mat(const Uint32 *src, int src_w, int src_h, int src_pitch,
}
#if defined(__SSE2__)
# define HAVE_SSE2_INTRINSICS 1
#define HAVE_SSE2_INTRINSICS 1
#endif
#if defined(__ARM_NEON)
# define HAVE_NEON_INTRINSICS 1
# define CAST_uint8x8_t (uint8x8_t)
# define CAST_uint32x2_t (uint32x2_t)
#define HAVE_NEON_INTRINSICS 1
#define CAST_uint8x8_t (uint8x8_t)
#define CAST_uint32x2_t (uint32x2_t)
#endif
#if defined(__WINRT__) || defined(_MSC_VER)
# if defined(HAVE_NEON_INTRINSICS)
# undef CAST_uint8x8_t
# undef CAST_uint32x2_t
# define CAST_uint8x8_t
# define CAST_uint32x2_t
# endif
#if defined(HAVE_NEON_INTRINSICS)
#undef CAST_uint8x8_t
#undef CAST_uint32x2_t
#define CAST_uint8x8_t
#define CAST_uint32x2_t
#endif
#endif
#if defined(HAVE_SSE2_INTRINSICS)
#if 0
static void
printf_128(const char *str, __m128i var)
static void printf_128(const char *str, __m128i var)
{
uint16_t *val = (uint16_t*) &var;
printf(" * %s: %04x %04x %04x %04x _ %04x %04x %04x %04x\n",
@ -373,8 +363,7 @@ printf_128(const char *str, __m128i var)
}
#endif
static SDL_INLINE int
hasSSE2()
static SDL_INLINE int hasSSE2()
{
static int val = -1;
if (val != -1) {
@ -384,8 +373,7 @@ hasSSE2()
return val;
}
static SDL_INLINE void
INTERPOL_BILINEAR_SSE(const Uint32 *s0, const Uint32 *s1, int frac_w, __m128i v_frac_h0, __m128i v_frac_h1, Uint32 *dst, __m128i zero)
static SDL_INLINE void INTERPOL_BILINEAR_SSE(const Uint32 *s0, const Uint32 *s1, int frac_w, __m128i v_frac_h0, __m128i v_frac_h1, Uint32 *dst, __m128i zero)
{
__m128i x_00_01, x_10_11; /* Pixels in 4*uint8 in row */
__m128i v_frac_w0, k0, l0, d0, e0;
@ -395,8 +383,7 @@ INTERPOL_BILINEAR_SSE(const Uint32 *s0, const Uint32 *s1, int frac_w, __m128i v_
f2 = FRAC_ONE - frac_w;
v_frac_w0 = _mm_set_epi16(f, f2, f, f2, f, f2, f, f2);
x_00_01 = _mm_loadl_epi64((const __m128i *)s0); /* Load x00 and x01 */
x_00_01 = _mm_loadl_epi64((const __m128i *)s0); /* Load x00 and x01 */
x_10_11 = _mm_loadl_epi64((const __m128i *)s1);
/* Interpolated == x0 + frac * (x1 - x0) == x0 * (1 - frac) + x1 * frac */
@ -423,8 +410,7 @@ INTERPOL_BILINEAR_SSE(const Uint32 *s0, const Uint32 *s1, int frac_w, __m128i v_
*dst = _mm_cvtsi128_si32(e0);
}
static int
scale_mat_SSE(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static int scale_mat_SSE(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
BILINEAR___START
@ -453,7 +439,7 @@ scale_mat_SSE(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *ds
const Uint32 *s_00_01, *s_02_03, *s_10_11, *s_12_13;
__m128i x_00_01, x_10_11, x_02_03, x_12_13;/* Pixels in 4*uint8 in row */
__m128i x_00_01, x_10_11, x_02_03, x_12_13; /* Pixels in 4*uint8 in row */
__m128i v_frac_w0, k0, l0, d0, e0;
__m128i v_frac_w1, k1, l1, d1, e1;
@ -464,15 +450,15 @@ scale_mat_SSE(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *ds
index_w_1 = 4 * SRC_INDEX(fp_sum_w);
frac_w_1 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
/*
x00............ x01 x02...........x03
. . . . . .
j0 f0 j1 j2 f1 j3
. . . . . .
. . . . . .
. . . . . .
x10............ x11 x12...........x13
*/
/*
x00............ x01 x02...........x03
. . . . . .
j0 f0 j1 j2 f1 j3
. . . . . .
. . . . . .
. . . . . .
x10............ x11 x12...........x13
*/
s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_0);
s_02_03 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_1);
s_10_11 = (const Uint32 *)((const Uint8 *)src_h1 + index_w_0);
@ -546,8 +532,7 @@ scale_mat_SSE(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *ds
#if defined(HAVE_NEON_INTRINSICS)
static SDL_INLINE int
hasNEON()
static SDL_INLINE int hasNEON()
{
static int val = -1;
if (val != -1) {
@ -557,8 +542,7 @@ hasNEON()
return val;
}
static SDL_INLINE void
INTERPOL_BILINEAR_NEON(const Uint32 *s0, const Uint32 *s1, int frac_w, uint8x8_t v_frac_h0, uint8x8_t v_frac_h1, Uint32 *dst)
static SDL_INLINE void INTERPOL_BILINEAR_NEON(const Uint32 *s0, const Uint32 *s1, int frac_w, uint8x8_t v_frac_h0, uint8x8_t v_frac_h1, Uint32 *dst)
{
uint8x8_t x_00_01, x_10_11; /* Pixels in 4*uint8 in row */
uint16x8_t k0;
@ -570,8 +554,8 @@ INTERPOL_BILINEAR_NEON(const Uint32 *s0, const Uint32 *s1, int frac_w, uint8x8_t
x_10_11 = CAST_uint8x8_t vld1_u32(s1);
/* Interpolated == x0 + frac * (x1 - x0) == x0 * (1 - frac) + x1 * frac */
k0 = vmull_u8(x_00_01, v_frac_h1); /* k0 := x0 * (1 - frac) */
k0 = vmlal_u8(k0, x_10_11, v_frac_h0); /* k0 += x1 * frac */
k0 = vmull_u8(x_00_01, v_frac_h1); /* k0 := x0 * (1 - frac) */
k0 = vmlal_u8(k0, x_10_11, v_frac_h0); /* k0 += x1 * frac */
/* k0 now contains 2 interpolated pixels { j0, j1 } */
l0 = vshll_n_u16(vget_low_u16(k0), PRECISION);
@ -580,9 +564,8 @@ INTERPOL_BILINEAR_NEON(const Uint32 *s0, const Uint32 *s1, int frac_w, uint8x8_t
/* Shift and narrow */
d0 = vcombine_u16(
/* uint16x4_t */ vshrn_n_u32(l0, 2 * PRECISION),
/* uint16x4_t */ vshrn_n_u32(l0, 2 * PRECISION)
);
/* uint16x4_t */ vshrn_n_u32(l0, 2 * PRECISION),
/* uint16x4_t */ vshrn_n_u32(l0, 2 * PRECISION));
/* Narrow again */
e0 = vmovn_u16(d0);
@ -591,8 +574,7 @@ INTERPOL_BILINEAR_NEON(const Uint32 *s0, const Uint32 *s1, int frac_w, uint8x8_t
*dst = vget_lane_u32(CAST_uint32x2_t e0, 0);
}
static int
scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static int scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
BILINEAR___START
@ -621,7 +603,7 @@ scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *d
const Uint32 *s_00_01, *s_02_03, *s_04_05, *s_06_07;
const Uint32 *s_10_11, *s_12_13, *s_14_15, *s_16_17;
uint8x8_t x_00_01, x_10_11, x_02_03, x_12_13;/* Pixels in 4*uint8 in row */
uint8x8_t x_00_01, x_10_11, x_02_03, x_12_13; /* Pixels in 4*uint8 in row */
uint8x8_t x_04_05, x_14_15, x_06_07, x_16_17;
uint16x8_t k0, k1, k2, k3;
@ -631,17 +613,17 @@ scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *d
uint32x4_t f0;
index_w_0 = 4 * SRC_INDEX(fp_sum_w);
frac_w_0 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
frac_w_0 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
index_w_1 = 4 * SRC_INDEX(fp_sum_w);
frac_w_1 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
frac_w_1 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
index_w_2 = 4 * SRC_INDEX(fp_sum_w);
frac_w_2 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
frac_w_2 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
index_w_3 = 4 * SRC_INDEX(fp_sum_w);
frac_w_3 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
frac_w_3 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_0);
s_02_03 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_1);
@ -663,8 +645,8 @@ scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *d
x_16_17 = CAST_uint8x8_t vld1_u32(s_16_17);
/* Interpolated == x0 + frac * (x1 - x0) == x0 * (1 - frac) + x1 * frac */
k0 = vmull_u8(x_00_01, v_frac_h1); /* k0 := x0 * (1 - frac) */
k0 = vmlal_u8(k0, x_10_11, v_frac_h0); /* k0 += x1 * frac */
k0 = vmull_u8(x_00_01, v_frac_h1); /* k0 := x0 * (1 - frac) */
k0 = vmlal_u8(k0, x_10_11, v_frac_h0); /* k0 += x1 * frac */
k1 = vmull_u8(x_02_03, v_frac_h1);
k1 = vmlal_u8(k1, x_12_13, v_frac_h0);
@ -698,17 +680,15 @@ scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *d
/* shift and narrow */
d0 = vcombine_u16(
/* uint16x4_t */ vshrn_n_u32(l0, 2 * PRECISION),
/* uint16x4_t */ vshrn_n_u32(l1, 2 * PRECISION)
);
/* uint16x4_t */ vshrn_n_u32(l0, 2 * PRECISION),
/* uint16x4_t */ vshrn_n_u32(l1, 2 * PRECISION));
/* narrow again */
e0 = vmovn_u16(d0);
/* Shift and narrow */
d1 = vcombine_u16(
/* uint16x4_t */ vshrn_n_u32(l2, 2 * PRECISION),
/* uint16x4_t */ vshrn_n_u32(l3, 2 * PRECISION)
);
/* uint16x4_t */ vshrn_n_u32(l2, 2 * PRECISION),
/* uint16x4_t */ vshrn_n_u32(l3, 2 * PRECISION));
/* Narrow again */
e1 = vmovn_u16(d1);
@ -724,41 +704,41 @@ scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *d
int index_w_1, frac_w_1;
const Uint32 *s_00_01, *s_02_03;
const Uint32 *s_10_11, *s_12_13;
uint8x8_t x_00_01, x_10_11, x_02_03, x_12_13;/* Pixels in 4*uint8 in row */
uint8x8_t x_00_01, x_10_11, x_02_03, x_12_13; /* Pixels in 4*uint8 in row */
uint16x8_t k0, k1;
uint32x4_t l0, l1;
uint16x8_t d0;
uint8x8_t e0;
index_w_0 = 4 * SRC_INDEX(fp_sum_w);
frac_w_0 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
frac_w_0 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
index_w_1 = 4 * SRC_INDEX(fp_sum_w);
frac_w_1 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
/*
x00............ x01 x02...........x03
. . . . . .
j0 dest0 j1 j2 dest1 j3
. . . . . .
. . . . . .
. . . . . .
x10............ x11 x12...........x13
*/
frac_w_1 = FRAC(fp_sum_w);
fp_sum_w += fp_step_w;
/*
x00............ x01 x02...........x03
. . . . . .
j0 dest0 j1 j2 dest1 j3
. . . . . .
. . . . . .
. . . . . .
x10............ x11 x12...........x13
*/
s_00_01 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_0);
s_02_03 = (const Uint32 *)((const Uint8 *)src_h0 + index_w_1);
s_10_11 = (const Uint32 *)((const Uint8 *)src_h1 + index_w_0);
s_12_13 = (const Uint32 *)((const Uint8 *)src_h1 + index_w_1);
/* Interpolation vertical */
x_00_01 = CAST_uint8x8_t vld1_u32(s_00_01);/* Load 2 pixels */
x_00_01 = CAST_uint8x8_t vld1_u32(s_00_01); /* Load 2 pixels */
x_02_03 = CAST_uint8x8_t vld1_u32(s_02_03);
x_10_11 = CAST_uint8x8_t vld1_u32(s_10_11);
x_12_13 = CAST_uint8x8_t vld1_u32(s_12_13);
/* Interpolated == x0 + frac * (x1 - x0) == x0 * (1 - frac) + x1 * frac */
k0 = vmull_u8(x_00_01, v_frac_h1); /* k0 := x0 * (1 - frac) */
k0 = vmlal_u8(k0, x_10_11, v_frac_h0); /* k0 += x1 * frac */
k0 = vmull_u8(x_00_01, v_frac_h1); /* k0 := x0 * (1 - frac) */
k0 = vmlal_u8(k0, x_10_11, v_frac_h0); /* k0 += x1 * frac */
k1 = vmull_u8(x_02_03, v_frac_h1);
k1 = vmlal_u8(k1, x_12_13, v_frac_h0);
@ -777,9 +757,8 @@ scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *d
/* Shift and narrow */
d0 = vcombine_u16(
/* uint16x4_t */ vshrn_n_u32(l0, 2 * PRECISION),
/* uint16x4_t */ vshrn_n_u32(l1, 2 * PRECISION)
);
/* uint16x4_t */ vshrn_n_u32(l0, 2 * PRECISION),
/* uint16x4_t */ vshrn_n_u32(l1, 2 * PRECISION));
/* Narrow again */
e0 = vmovn_u16(d0);
@ -813,9 +792,8 @@ scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *d
}
#endif
int
SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect,
SDL_Surface *d, const SDL_Rect *dstrect)
int SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect,
SDL_Surface *d, const SDL_Rect *dstrect)
{
int ret = -1;
int src_w = srcrect->w;
@ -824,8 +802,8 @@ SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect,
int dst_h = dstrect->h;
int src_pitch = s->pitch;
int dst_pitch = d->pitch;
Uint32 *src = (Uint32 *) ((Uint8 *)s->pixels + srcrect->x * 4 + srcrect->y * src_pitch);
Uint32 *dst = (Uint32 *) ((Uint8 *)d->pixels + dstrect->x * 4 + dstrect->y * dst_pitch);
Uint32 *src = (Uint32 *)((Uint8 *)s->pixels + srcrect->x * 4 + srcrect->y * src_pitch);
Uint32 *dst = (Uint32 *)((Uint8 *)d->pixels + dstrect->x * 4 + dstrect->y * dst_pitch);
#if defined(HAVE_NEON_INTRINSICS)
if (ret == -1 && hasNEON()) {
@ -846,30 +824,27 @@ SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect,
return ret;
}
#define SDL_SCALE_NEAREST__START \
int i; \
Uint32 posy, incy; \
Uint32 posx, incx; \
int dst_gap; \
int srcy, n; \
const Uint32 *src_h0; \
incy = (src_h << 16) / dst_h; \
incx = (src_w << 16) / dst_w; \
dst_gap = dst_pitch - bpp * dst_w; \
posy = incy / 2;
#define SDL_SCALE_NEAREST__START \
int i; \
Uint32 posy, incy; \
Uint32 posx, incx; \
int dst_gap; \
int srcy, n; \
const Uint32 *src_h0; \
incy = (src_h << 16) / dst_h; \
incx = (src_w << 16) / dst_w; \
dst_gap = dst_pitch - bpp * dst_w; \
posy = incy / 2; \
#define SDL_SCALE_NEAREST__HEIGHT \
srcy = (posy >> 16); \
src_h0 = (const Uint32 *)((const Uint8 *)src_ptr + srcy * src_pitch); \
posy += incy; \
posx = incx / 2; \
#define SDL_SCALE_NEAREST__HEIGHT \
srcy = (posy >> 16); \
src_h0 = (const Uint32 *)((const Uint8 *)src_ptr + srcy * src_pitch); \
posy += incy; \
posx = incx / 2; \
n = dst_w;
static int
scale_mat_nearest_1(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static int scale_mat_nearest_1(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
Uint32 bpp = 1;
SDL_SCALE_NEAREST__START
@ -880,17 +855,16 @@ scale_mat_nearest_1(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
int srcx = bpp * (posx >> 16);
posx += incx;
src = (const Uint8 *)src_h0 + srcx;
*(Uint8*)dst = *src;
dst = (Uint32 *)((Uint8*)dst + bpp);
*(Uint8 *)dst = *src;
dst = (Uint32 *)((Uint8 *)dst + bpp);
}
dst = (Uint32 *)((Uint8 *)dst + dst_gap);
}
return 0;
}
static int
scale_mat_nearest_2(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static int scale_mat_nearest_2(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
Uint32 bpp = 2;
SDL_SCALE_NEAREST__START
@ -901,17 +875,16 @@ scale_mat_nearest_2(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
int srcx = bpp * (posx >> 16);
posx += incx;
src = (const Uint16 *)((const Uint8 *)src_h0 + srcx);
*(Uint16*)dst = *src;
dst = (Uint32 *)((Uint8*)dst + bpp);
*(Uint16 *)dst = *src;
dst = (Uint32 *)((Uint8 *)dst + bpp);
}
dst = (Uint32 *)((Uint8 *)dst + dst_gap);
}
return 0;
}
static int
scale_mat_nearest_3(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static int scale_mat_nearest_3(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
Uint32 bpp = 3;
SDL_SCALE_NEAREST__START
@ -922,19 +895,18 @@ scale_mat_nearest_3(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
int srcx = bpp * (posx >> 16);
posx += incx;
src = (const Uint8 *)src_h0 + srcx;
((Uint8*)dst)[0] = src[0];
((Uint8*)dst)[1] = src[1];
((Uint8*)dst)[2] = src[2];
dst = (Uint32 *)((Uint8*)dst + bpp);
((Uint8 *)dst)[0] = src[0];
((Uint8 *)dst)[1] = src[1];
((Uint8 *)dst)[2] = src[2];
dst = (Uint32 *)((Uint8 *)dst + bpp);
}
dst = (Uint32 *)((Uint8 *)dst + dst_gap);
}
return 0;
}
static int
scale_mat_nearest_4(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static int scale_mat_nearest_4(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
Uint32 bpp = 4;
SDL_SCALE_NEAREST__START
@ -946,16 +918,15 @@ scale_mat_nearest_4(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
posx += incx;
src = (const Uint32 *)((const Uint8 *)src_h0 + srcx);
*dst = *src;
dst = (Uint32 *)((Uint8*)dst + bpp);
dst = (Uint32 *)((Uint8 *)dst + bpp);
}
dst = (Uint32 *)((Uint8 *)dst + dst_gap);
}
return 0;
}
int
SDL_LowerSoftStretchNearest(SDL_Surface *s, const SDL_Rect *srcrect,
SDL_Surface *d, const SDL_Rect *dstrect)
int SDL_LowerSoftStretchNearest(SDL_Surface *s, const SDL_Rect *srcrect,
SDL_Surface *d, const SDL_Rect *dstrect)
{
int src_w = srcrect->w;
int src_h = srcrect->h;
@ -963,11 +934,11 @@ SDL_LowerSoftStretchNearest(SDL_Surface *s, const SDL_Rect *srcrect,
int dst_h = dstrect->h;
int src_pitch = s->pitch;
int dst_pitch = d->pitch;
const int bpp = d->format->BytesPerPixel;
Uint32 *src = (Uint32 *) ((Uint8 *)s->pixels + srcrect->x * bpp + srcrect->y * src_pitch);
Uint32 *dst = (Uint32 *) ((Uint8 *)d->pixels + dstrect->x * bpp + dstrect->y * dst_pitch);
Uint32 *src = (Uint32 *)((Uint8 *)s->pixels + srcrect->x * bpp + srcrect->y * src_pitch);
Uint32 *dst = (Uint32 *)((Uint8 *)d->pixels + dstrect->x * bpp + dstrect->y * dst_pitch);
if (bpp == 4) {
return scale_mat_nearest_4(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -28,53 +28,85 @@
#include "SDL_yuv_c.h"
#include "../render/SDL_sysrender.h"
/* Check to make sure we can safely check multiplication of surface w and pitch and it won't overflow size_t */
SDL_COMPILE_TIME_ASSERT(surface_size_assumptions,
sizeof(int) == sizeof(Sint32) && sizeof(size_t) >= sizeof(Sint32));
sizeof(int) == sizeof(Sint32) && sizeof(size_t) >= sizeof(Sint32));
SDL_COMPILE_TIME_ASSERT(can_indicate_overflow, SDL_SIZE_MAX > SDL_MAX_SINT32);
/* Public routines */
/*
* Calculate the pad-aligned scanline width of a surface
* Calculate the pad-aligned scanline width of a surface.
* Return SDL_SIZE_MAX on overflow.
*
* for FOURCC, use SDL_CalculateYUVSize()
*/
static Sint64
SDL_CalculatePitch(Uint32 format, int width)
static size_t SDL_CalculatePitch(Uint32 format, size_t width, SDL_bool minimal)
{
Sint64 pitch;
size_t pitch;
if (SDL_ISPIXELFORMAT_FOURCC(format) || SDL_BITSPERPIXEL(format) >= 8) {
pitch = ((Sint64)width * SDL_BYTESPERPIXEL(format));
if (SDL_BITSPERPIXEL(format) >= 8) {
if (SDL_size_mul_overflow(width, SDL_BYTESPERPIXEL(format), &pitch)) {
return SDL_SIZE_MAX;
}
} else {
pitch = (((Sint64)width * SDL_BITSPERPIXEL(format)) + 7) / 8;
if (SDL_size_mul_overflow(width, SDL_BITSPERPIXEL(format), &pitch)) {
return SDL_SIZE_MAX;
}
if (SDL_size_add_overflow(pitch, 7, &pitch)) {
return SDL_SIZE_MAX;
}
pitch /= 8;
}
if (!minimal) {
/* 4-byte aligning for speed */
if (SDL_size_add_overflow(pitch, 3, &pitch)) {
return SDL_SIZE_MAX;
}
pitch &= ~3;
}
pitch = (pitch + 3) & ~3; /* 4-byte aligning for speed */
return pitch;
}
/* TODO: In SDL 3, drop the unused flags and depth parameters */
/*
* Create an empty RGB surface of the appropriate depth using the given
* enum SDL_PIXELFORMAT_* format
*/
SDL_Surface *
SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,
SDL_Surface *SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,
Uint32 format)
{
Sint64 pitch;
size_t pitch;
SDL_Surface *surface;
/* The flags are no longer used, make the compiler happy */
(void)flags;
pitch = SDL_CalculatePitch(format, width);
if (pitch < 0 || pitch > SDL_MAX_SINT32) {
/* Overflow... */
SDL_OutOfMemory();
if (width < 0) {
SDL_InvalidParamError("width");
return NULL;
}
if (height < 0) {
SDL_InvalidParamError("height");
return NULL;
}
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
SDL_SetError("invalid format");
return NULL;
} else {
pitch = SDL_CalculatePitch(format, width, SDL_FALSE);
if (pitch > SDL_MAX_SINT32) {
/* Overflow... */
SDL_OutOfMemory();
return NULL;
}
}
/* Allocate the surface */
surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface));
surface = (SDL_Surface *)SDL_calloc(1, sizeof(*surface));
if (surface == NULL) {
SDL_OutOfMemory();
return NULL;
@ -93,7 +125,7 @@ SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,
if (SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
SDL_Palette *palette =
SDL_AllocPalette((1 << surface->format->BitsPerPixel));
if (!palette) {
if (palette == NULL) {
SDL_FreeSurface(surface);
return NULL;
}
@ -113,15 +145,15 @@ SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,
/* Get the pixels */
if (surface->w && surface->h) {
/* Assumptions checked in surface_size_assumptions assert above */
Sint64 size = ((Sint64)surface->h * surface->pitch);
if (size < 0 || size > SDL_MAX_SINT32) {
size_t size;
if (SDL_size_mul_overflow(surface->h, surface->pitch, &size)) {
/* Overflow... */
SDL_FreeSurface(surface);
SDL_OutOfMemory();
return NULL;
}
surface->pixels = SDL_SIMDAlloc((size_t)size);
surface->pixels = SDL_SIMDAlloc(size);
if (!surface->pixels) {
SDL_FreeSurface(surface);
SDL_OutOfMemory();
@ -129,7 +161,7 @@ SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,
}
surface->flags |= SDL_SIMD_ALIGNED;
/* This is important for bitmaps */
SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
SDL_memset(surface->pixels, 0, size);
}
/* Allocate an empty mapping */
@ -149,11 +181,11 @@ SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,
return surface;
}
/* TODO: In SDL 3, drop the unused flags parameter */
/*
* Create an empty RGB surface of the appropriate depth
*/
SDL_Surface *
SDL_CreateRGBSurface(Uint32 flags,
SDL_Surface *SDL_CreateRGBSurface(Uint32 flags,
int width, int height, int depth,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
{
@ -172,36 +204,38 @@ SDL_CreateRGBSurface(Uint32 flags,
/*
* Create an RGB surface from an existing memory buffer
*/
SDL_Surface *
SDL_CreateRGBSurfaceFrom(void *pixels,
SDL_Surface *SDL_CreateRGBSurfaceFrom(void *pixels,
int width, int height, int depth, int pitch,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
Uint32 Amask)
{
SDL_Surface *surface;
Uint32 format;
size_t minimalPitch;
surface = SDL_CreateRGBSurface(0, 0, 0, depth, Rmask, Gmask, Bmask, Amask);
if (surface != NULL) {
surface->flags |= SDL_PREALLOC;
surface->pixels = pixels;
surface->w = width;
surface->h = height;
surface->pitch = pitch;
SDL_SetClipRect(surface, NULL);
if (width < 0) {
SDL_InvalidParamError("width");
return NULL;
}
return surface;
}
/*
* Create an RGB surface from an existing memory buffer using the given given
* enum SDL_PIXELFORMAT_* format
*/
SDL_Surface *
SDL_CreateRGBSurfaceWithFormatFrom(void *pixels,
int width, int height, int depth, int pitch,
Uint32 format)
{
SDL_Surface *surface;
if (height < 0) {
SDL_InvalidParamError("height");
return NULL;
}
format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask);
if (format == SDL_PIXELFORMAT_UNKNOWN) {
SDL_SetError("Unknown pixel format");
return NULL;
}
minimalPitch = SDL_CalculatePitch(format, width, SDL_TRUE);
if (pitch < 0 || (pitch > 0 && ((size_t)pitch) < minimalPitch)) {
SDL_InvalidParamError("pitch");
return NULL;
}
surface = SDL_CreateRGBSurfaceWithFormat(0, 0, 0, depth, format);
if (surface != NULL) {
@ -215,10 +249,55 @@ SDL_CreateRGBSurfaceWithFormatFrom(void *pixels,
return surface;
}
int
SDL_SetSurfacePalette(SDL_Surface * surface, SDL_Palette * palette)
/* TODO: In SDL 3, drop the unused depth parameter */
/*
* Create an RGB surface from an existing memory buffer using the given given
* enum SDL_PIXELFORMAT_* format
*/
SDL_Surface *SDL_CreateRGBSurfaceWithFormatFrom(void *pixels,
int width, int height, int depth, int pitch,
Uint32 format)
{
if (!surface) {
SDL_Surface *surface;
size_t minimalPitch;
if (width < 0) {
SDL_InvalidParamError("width");
return NULL;
}
if (height < 0) {
SDL_InvalidParamError("height");
return NULL;
}
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
SDL_SetError("invalid format");
return NULL;
} else {
minimalPitch = SDL_CalculatePitch(format, width, SDL_TRUE);
}
if (pitch < 0 || (pitch > 0 && ((size_t)pitch) < minimalPitch)) {
SDL_InvalidParamError("pitch");
return NULL;
}
surface = SDL_CreateRGBSurfaceWithFormat(0, 0, 0, depth, format);
if (surface != NULL) {
surface->flags |= SDL_PREALLOC;
surface->pixels = pixels;
surface->w = width;
surface->h = height;
surface->pitch = pitch;
SDL_SetClipRect(surface, NULL);
}
return surface;
}
int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
{
if (surface == NULL) {
return SDL_InvalidParamError("SDL_SetSurfacePalette(): surface");
}
if (SDL_SetPixelFormatPalette(surface->format, palette) < 0) {
@ -229,12 +308,11 @@ SDL_SetSurfacePalette(SDL_Surface * surface, SDL_Palette * palette)
return 0;
}
int
SDL_SetSurfaceRLE(SDL_Surface * surface, int flag)
int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
{
int flags;
if (!surface) {
if (surface == NULL) {
return -1;
}
@ -250,10 +328,9 @@ SDL_SetSurfaceRLE(SDL_Surface * surface, int flag)
return 0;
}
SDL_bool
SDL_HasSurfaceRLE(SDL_Surface * surface)
SDL_bool SDL_HasSurfaceRLE(SDL_Surface *surface)
{
if (!surface) {
if (surface == NULL) {
return SDL_FALSE;
}
@ -264,16 +341,15 @@ SDL_HasSurfaceRLE(SDL_Surface * surface)
return SDL_TRUE;
}
int
SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key)
int SDL_SetColorKey(SDL_Surface *surface, int flag, Uint32 key)
{
int flags;
if (!surface) {
if (surface == NULL) {
return SDL_InvalidParamError("surface");
}
if (surface->format->palette && key >= ((Uint32) surface->format->palette->ncolors)) {
if (surface->format->palette && key >= ((Uint32)surface->format->palette->ncolors)) {
return SDL_InvalidParamError("key");
}
@ -295,10 +371,9 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key)
return 0;
}
SDL_bool
SDL_HasColorKey(SDL_Surface * surface)
SDL_bool SDL_HasColorKey(SDL_Surface *surface)
{
if (!surface) {
if (surface == NULL) {
return SDL_FALSE;
}
@ -309,10 +384,9 @@ SDL_HasColorKey(SDL_Surface * surface)
return SDL_TRUE;
}
int
SDL_GetColorKey(SDL_Surface * surface, Uint32 * key)
int SDL_GetColorKey(SDL_Surface *surface, Uint32 *key)
{
if (!surface) {
if (surface == NULL) {
return SDL_InvalidParamError("surface");
}
@ -326,14 +400,13 @@ SDL_GetColorKey(SDL_Surface * surface, Uint32 * key)
return 0;
}
/* This is a fairly slow function to switch from colorkey to alpha
/* This is a fairly slow function to switch from colorkey to alpha
NB: it doesn't handle bpp 1 or 3, because they have no alpha channel */
static void
SDL_ConvertColorkeyToAlpha(SDL_Surface * surface, SDL_bool ignore_alpha)
static void SDL_ConvertColorkeyToAlpha(SDL_Surface *surface, SDL_bool ignore_alpha)
{
int x, y, bpp;
if (!surface) {
if (surface == NULL) {
return;
}
@ -348,13 +421,13 @@ SDL_ConvertColorkeyToAlpha(SDL_Surface * surface, SDL_bool ignore_alpha)
if (bpp == 2) {
Uint16 *row, *spot;
Uint16 ckey = (Uint16) surface->map->info.colorkey;
Uint16 mask = (Uint16) (~surface->format->Amask);
Uint16 ckey = (Uint16)surface->map->info.colorkey;
Uint16 mask = (Uint16)(~surface->format->Amask);
/* Ignore, or not, alpha in colorkey comparison */
if (ignore_alpha) {
ckey &= mask;
row = (Uint16 *) surface->pixels;
row = (Uint16 *)surface->pixels;
for (y = surface->h; y--;) {
spot = row;
for (x = surface->w; x--;) {
@ -366,7 +439,7 @@ SDL_ConvertColorkeyToAlpha(SDL_Surface * surface, SDL_bool ignore_alpha)
row += surface->pitch / 2;
}
} else {
row = (Uint16 *) surface->pixels;
row = (Uint16 *)surface->pixels;
for (y = surface->h; y--;) {
spot = row;
for (x = surface->w; x--;) {
@ -386,7 +459,7 @@ SDL_ConvertColorkeyToAlpha(SDL_Surface * surface, SDL_bool ignore_alpha)
/* Ignore, or not, alpha in colorkey comparison */
if (ignore_alpha) {
ckey &= mask;
row = (Uint32 *) surface->pixels;
row = (Uint32 *)surface->pixels;
for (y = surface->h; y--;) {
spot = row;
for (x = surface->w; x--;) {
@ -398,7 +471,7 @@ SDL_ConvertColorkeyToAlpha(SDL_Surface * surface, SDL_bool ignore_alpha)
row += surface->pitch / 4;
}
} else {
row = (Uint32 *) surface->pixels;
row = (Uint32 *)surface->pixels;
for (y = surface->h; y--;) {
spot = row;
for (x = surface->w; x--;) {
@ -418,12 +491,11 @@ SDL_ConvertColorkeyToAlpha(SDL_Surface * surface, SDL_bool ignore_alpha)
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
}
int
SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b)
int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
{
int flags;
if (!surface) {
if (surface == NULL) {
return -1;
}
@ -443,11 +515,9 @@ SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b)
return 0;
}
int
SDL_GetSurfaceColorMod(SDL_Surface * surface, Uint8 * r, Uint8 * g, Uint8 * b)
int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
{
if (!surface) {
if (surface == NULL) {
return -1;
}
@ -463,12 +533,11 @@ SDL_GetSurfaceColorMod(SDL_Surface * surface, Uint8 * r, Uint8 * g, Uint8 * b)
return 0;
}
int
SDL_SetSurfaceAlphaMod(SDL_Surface * surface, Uint8 alpha)
int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
{
int flags;
if (!surface) {
if (surface == NULL) {
return -1;
}
@ -486,10 +555,9 @@ SDL_SetSurfaceAlphaMod(SDL_Surface * surface, Uint8 alpha)
return 0;
}
int
SDL_GetSurfaceAlphaMod(SDL_Surface * surface, Uint8 * alpha)
int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
{
if (!surface) {
if (surface == NULL) {
return -1;
}
@ -499,12 +567,11 @@ SDL_GetSurfaceAlphaMod(SDL_Surface * surface, Uint8 * alpha)
return 0;
}
int
SDL_SetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode blendMode)
int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
{
int flags, status;
if (!surface) {
if (surface == NULL) {
return -1;
}
@ -539,19 +606,17 @@ SDL_SetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode blendMode)
return status;
}
int
SDL_GetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode *blendMode)
int SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode)
{
if (!surface) {
if (surface == NULL) {
return -1;
}
if (!blendMode) {
if (blendMode == NULL) {
return 0;
}
switch (surface->map->
info.flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL)) {
switch (surface->map->info.flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL)) {
case SDL_COPY_BLEND:
*blendMode = SDL_BLENDMODE_BLEND;
break;
@ -571,13 +636,12 @@ SDL_GetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode *blendMode)
return 0;
}
SDL_bool
SDL_SetClipRect(SDL_Surface * surface, const SDL_Rect * rect)
SDL_bool SDL_SetClipRect(SDL_Surface *surface, const SDL_Rect *rect)
{
SDL_Rect full_rect;
/* Don't do anything if there's no surface to act on */
if (!surface) {
if (surface == NULL) {
return SDL_FALSE;
}
@ -588,15 +652,14 @@ SDL_SetClipRect(SDL_Surface * surface, const SDL_Rect * rect)
full_rect.h = surface->h;
/* Set the clipping rectangle */
if (!rect) {
if (rect == NULL) {
surface->clip_rect = full_rect;
return SDL_TRUE;
}
return SDL_IntersectRect(rect, &full_rect, &surface->clip_rect);
}
void
SDL_GetClipRect(SDL_Surface * surface, SDL_Rect * rect)
void SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect)
{
if (surface && rect) {
*rect = surface->clip_rect;
@ -614,9 +677,8 @@ SDL_GetClipRect(SDL_Surface * surface, SDL_Rect * rect)
* you know exactly what you are doing, you can optimize your code
* by calling the one(s) you need.
*/
int
SDL_LowerBlit(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect)
int SDL_LowerBlit(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect)
{
/* Check to make sure the blit mapping is valid */
if ((src->map->dst != dst) ||
@ -625,27 +687,25 @@ SDL_LowerBlit(SDL_Surface * src, SDL_Rect * srcrect,
(src->format->palette &&
src->map->src_palette_version != src->format->palette->version)) {
if (SDL_MapSurface(src, dst) < 0) {
return (-1);
return -1;
}
/* just here for debugging */
/* printf */
/* ("src = 0x%08X src->flags = %08X src->map->info.flags = %08x\ndst = 0x%08X dst->flags = %08X dst->map->info.flags = %08X\nsrc->map->blit = 0x%08x\n", */
/* src, dst->flags, src->map->info.flags, dst, dst->flags, */
/* dst->map->info.flags, src->map->blit); */
/* printf */
/* ("src = 0x%08X src->flags = %08X src->map->info.flags = %08x\ndst = 0x%08X dst->flags = %08X dst->map->info.flags = %08X\nsrc->map->blit = 0x%08x\n", */
/* src, dst->flags, src->map->info.flags, dst, dst->flags, */
/* dst->map->info.flags, src->map->blit); */
}
return (src->map->blit(src, srcrect, dst, dstrect));
return src->map->blit(src, srcrect, dst, dstrect);
}
int
SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect)
int SDL_UpperBlit(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect)
{
SDL_Rect fulldst;
int srcx, srcy, w, h;
/* Make sure the surfaces aren't locked */
if (!src || !dst) {
if (src == NULL || dst == NULL) {
return SDL_InvalidParamError("SDL_UpperBlit(): src/dst");
}
if (src->locked || dst->locked) {
@ -672,8 +732,9 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect,
srcx = 0;
}
maxw = src->w - srcx;
if (maxw < w)
if (maxw < w) {
w = maxw;
}
srcy = srcrect->y;
h = srcrect->h;
@ -683,8 +744,9 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect,
srcy = 0;
}
maxh = src->h - srcy;
if (maxh < h)
if (maxh < h) {
h = maxh;
}
} else {
srcx = srcy = 0;
@ -704,8 +766,9 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect,
srcx += dx;
}
dx = dstrect->x + w - clip->x - clip->w;
if (dx > 0)
if (dx > 0) {
w -= dx;
}
dy = clip->y - dstrect->y;
if (dy > 0) {
@ -714,8 +777,9 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect,
srcy += dy;
}
dy = dstrect->y + h - clip->y - clip->h;
if (dy > 0)
if (dy > 0) {
h -= dy;
}
}
/* Switch back to a fast blit if we were previously stretching */
@ -736,17 +800,14 @@ SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect,
return 0;
}
int
SDL_UpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect)
int SDL_UpperBlitScaled(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect)
{
return SDL_PrivateUpperBlitScaled(src, srcrect, dst, dstrect, SDL_ScaleModeNearest);
}
int
SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect, SDL_ScaleMode scaleMode)
int SDL_PrivateUpperBlitScaled(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode)
{
double src_x0, src_y0, src_x1, src_y1;
double dst_x0, dst_y0, dst_x1, dst_y1;
@ -756,14 +817,14 @@ SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
int dst_w, dst_h;
/* Make sure the surfaces aren't locked */
if (!src || !dst) {
if (src == NULL || dst == NULL) {
return SDL_InvalidParamError("SDL_UpperBlitScaled(): src/dst");
}
if (src->locked || dst->locked) {
return SDL_SetError("Surfaces must not be locked during blit");
}
if (NULL == srcrect) {
if (srcrect == NULL) {
src_w = src->w;
src_h = src->h;
} else {
@ -771,7 +832,7 @@ SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
src_h = srcrect->h;
}
if (NULL == dstrect) {
if (dstrect == NULL) {
dst_w = dst->w;
dst_h = dst->h;
} else {
@ -787,7 +848,7 @@ SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
scaling_w = (double)dst_w / src_w;
scaling_h = (double)dst_h / src_h;
if (NULL == dstrect) {
if (dstrect == NULL) {
dst_x0 = 0;
dst_y0 = 0;
dst_x1 = dst_w;
@ -799,7 +860,7 @@ SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
dst_y1 = dst_y0 + dst_h;
}
if (NULL == srcrect) {
if (srcrect == NULL) {
src_x0 = 0;
src_y0 = 0;
src_x1 = src_w;
@ -907,22 +968,18 @@ SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
* This is a semi-private blit function and it performs low-level surface
* scaled blitting only.
*/
int
SDL_LowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect)
int SDL_LowerBlitScaled(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect)
{
return SDL_PrivateLowerBlitScaled(src, srcrect, dst, dstrect, SDL_ScaleModeNearest);
}
int
SDL_PrivateLowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect, SDL_ScaleMode scaleMode)
int SDL_PrivateLowerBlitScaled(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode)
{
static const Uint32 complex_copy_flags = (
SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA |
SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL |
SDL_COPY_COLORKEY
);
static const Uint32 complex_copy_flags = (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA |
SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL |
SDL_COPY_COLORKEY);
if (srcrect->w > SDL_MAX_UINT16 || srcrect->h > SDL_MAX_UINT16 ||
dstrect->w > SDL_MAX_UINT16 || dstrect->h > SDL_MAX_UINT16) {
@ -935,19 +992,19 @@ SDL_PrivateLowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
}
if (scaleMode == SDL_ScaleModeNearest) {
if ( !(src->map->info.flags & complex_copy_flags) &&
src->format->format == dst->format->format &&
!SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) {
return SDL_SoftStretch( src, srcrect, dst, dstrect );
if (!(src->map->info.flags & complex_copy_flags) &&
src->format->format == dst->format->format &&
!SDL_ISPIXELFORMAT_INDEXED(src->format->format)) {
return SDL_SoftStretch(src, srcrect, dst, dstrect);
} else {
return SDL_LowerBlit( src, srcrect, dst, dstrect );
return SDL_LowerBlit(src, srcrect, dst, dstrect);
}
} else {
if ( !(src->map->info.flags & complex_copy_flags) &&
src->format->format == dst->format->format &&
!SDL_ISPIXELFORMAT_INDEXED(src->format->format) &&
src->format->BytesPerPixel == 4 &&
src->format->format != SDL_PIXELFORMAT_ARGB2101010) {
if (!(src->map->info.flags & complex_copy_flags) &&
src->format->format == dst->format->format &&
!SDL_ISPIXELFORMAT_INDEXED(src->format->format) &&
src->format->BytesPerPixel == 4 &&
src->format->format != SDL_PIXELFORMAT_ARGB2101010) {
/* fast path */
return SDL_SoftStretchLinear(src, srcrect, dst, dstrect);
} else {
@ -988,7 +1045,6 @@ SDL_PrivateLowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
tmp1 = SDL_CreateRGBSurfaceWithFormat(flags, src->w, src->h, 0, fmt);
SDL_LowerBlit(src, srcrect, tmp1, &tmprect);
srcrect2.x = 0;
srcrect2.y = 0;
SDL_SetSurfaceColorMod(tmp1, r, g, b);
@ -1027,15 +1083,14 @@ SDL_PrivateLowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
/*
* Lock a surface to directly access the pixels
*/
int
SDL_LockSurface(SDL_Surface * surface)
int SDL_LockSurface(SDL_Surface *surface)
{
if (!surface->locked) {
#if SDL_HAVE_RLE
/* Perform the lock */
if (surface->flags & SDL_RLEACCEL) {
SDL_UnRLESurface(surface, 1);
surface->flags |= SDL_RLEACCEL; /* save accel'd state */
surface->flags |= SDL_RLEACCEL; /* save accel'd state */
}
#endif
}
@ -1044,14 +1099,13 @@ SDL_LockSurface(SDL_Surface * surface)
++surface->locked;
/* Ready to go.. */
return (0);
return 0;
}
/*
* Unlock a previously locked surface
*/
void
SDL_UnlockSurface(SDL_Surface * surface)
void SDL_UnlockSurface(SDL_Surface *surface)
{
/* Only perform an unlock if we are locked */
if (!surface->locked || (--surface->locked > 0)) {
@ -1061,7 +1115,7 @@ SDL_UnlockSurface(SDL_Surface * surface)
#if SDL_HAVE_RLE
/* Update RLE encoded surface with new data */
if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
surface->flags &= ~SDL_RLEACCEL; /* stop lying */
surface->flags &= ~SDL_RLEACCEL; /* stop lying */
SDL_RLESurface(surface);
}
#endif
@ -1070,8 +1124,7 @@ SDL_UnlockSurface(SDL_Surface * surface)
/*
* Creates a new surface identical to the existing surface
*/
SDL_Surface *
SDL_DuplicateSurface(SDL_Surface * surface)
SDL_Surface *SDL_DuplicateSurface(SDL_Surface *surface)
{
return SDL_ConvertSurface(surface, surface->format, surface->flags);
}
@ -1079,8 +1132,7 @@ SDL_DuplicateSurface(SDL_Surface * surface)
/*
* Convert a surface into the specified pixel format.
*/
SDL_Surface *
SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
SDL_Surface *SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
Uint32 flags)
{
SDL_Surface *convert;
@ -1094,11 +1146,11 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
Uint8 *palette_saved_alpha = NULL;
int palette_saved_alpha_ncolors = 0;
if (!surface) {
if (surface == NULL) {
SDL_InvalidParamError("surface");
return NULL;
}
if (!format) {
if (format == NULL) {
SDL_InvalidParamError("format");
return NULL;
}
@ -1107,14 +1159,13 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
if (format->palette != NULL) {
int i;
for (i = 0; i < format->palette->ncolors; ++i) {
if ((format->palette->colors[i].r != 0xFF) ||
(format->palette->colors[i].g != 0xFF) ||
(format->palette->colors[i].b != 0xFF))
if ((format->palette->colors[i].r != 0xFF) || (format->palette->colors[i].g != 0xFF) || (format->palette->colors[i].b != 0xFF)) {
break;
}
}
if (i == format->palette->ncolors) {
SDL_SetError("Empty destination palette");
return (NULL);
return NULL;
}
}
@ -1124,7 +1175,7 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
format->Gmask, format->Bmask,
format->Amask);
if (convert == NULL) {
return (NULL);
return NULL;
}
/* Copy the palette if any */
@ -1216,8 +1267,7 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
convert->map->info.a = copy_color.a;
convert->map->info.flags =
(copy_flags &
~(SDL_COPY_COLORKEY | SDL_COPY_BLEND
| SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY |
~(SDL_COPY_COLORKEY | SDL_COPY_BLEND | SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY |
SDL_COPY_RLE_ALPHAKEY));
surface->map->info.r = copy_color.r;
surface->map->info.g = copy_color.g;
@ -1240,7 +1290,7 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
if (format->palette &&
surface->format->palette->ncolors <= format->palette->ncolors &&
(SDL_memcmp(surface->format->palette->colors, format->palette->colors,
surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
/* The palette is identical, just set the same colorkey */
SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
} else if (!format->palette) {
@ -1310,11 +1360,10 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
}
/* We're ready to go! */
return (convert);
return convert;
}
SDL_Surface *
SDL_ConvertSurfaceFormat(SDL_Surface * surface, Uint32 pixel_format,
SDL_Surface *SDL_ConvertSurfaceFormat(SDL_Surface * surface, Uint32 pixel_format,
Uint32 flags)
{
SDL_PixelFormat *fmt;
@ -1331,10 +1380,9 @@ SDL_ConvertSurfaceFormat(SDL_Surface * surface, Uint32 pixel_format,
/*
* Create a surface on the stack for quick blit operations
*/
static SDL_INLINE SDL_bool
SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format,
void * pixels, int pitch, SDL_Surface * surface,
SDL_PixelFormat * format, SDL_BlitMap * blitmap)
static SDL_INLINE SDL_bool SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format,
void *pixels, int pitch, SDL_Surface *surface,
SDL_PixelFormat *format, SDL_BlitMap *blitmap)
{
if (SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
SDL_SetError("Indexed pixel formats not supported");
@ -1371,23 +1419,23 @@ SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format,
* Copy a block of pixels of one format to another format
*/
int SDL_ConvertPixels(int width, int height,
Uint32 src_format, const void * src, int src_pitch,
Uint32 dst_format, void * dst, int dst_pitch)
Uint32 src_format, const void *src, int src_pitch,
Uint32 dst_format, void *dst, int dst_pitch)
{
SDL_Surface src_surface, dst_surface;
SDL_PixelFormat src_fmt, dst_fmt;
SDL_BlitMap src_blitmap, dst_blitmap;
SDL_Rect rect;
void *nonconst_src = (void *) src;
void *nonconst_src = (void *)src;
int ret;
if (!src) {
if (src == NULL) {
return SDL_InvalidParamError("src");
}
if (!src_pitch) {
return SDL_InvalidParamError("src_pitch");
}
if (!dst) {
if (dst == NULL) {
return SDL_InvalidParamError("dst");
}
if (!dst_pitch) {
@ -1415,8 +1463,8 @@ int SDL_ConvertPixels(int width, int height,
width *= bpp;
for (i = height; i--;) {
SDL_memcpy(dst, src, width);
src = (const Uint8*)src + src_pitch;
dst = (Uint8*)dst + dst_pitch;
src = (const Uint8 *)src + src_pitch;
dst = (Uint8 *)dst + dst_pitch;
}
return 0;
}
@ -1454,8 +1502,8 @@ int SDL_ConvertPixels(int width, int height,
* https://developer.arm.com/documentation/101964/0201/Pre-multiplied-alpha-channel-data
*/
int SDL_PremultiplyAlpha(int width, int height,
Uint32 src_format, const void * src, int src_pitch,
Uint32 dst_format, void * dst, int dst_pitch)
Uint32 src_format, const void *src, int src_pitch,
Uint32 dst_format, void *dst, int dst_pitch)
{
int c;
Uint32 srcpixel;
@ -1463,13 +1511,13 @@ int SDL_PremultiplyAlpha(int width, int height,
Uint32 dstpixel;
Uint32 dstR, dstG, dstB, dstA;
if (!src) {
if (src == NULL) {
return SDL_InvalidParamError("src");
}
if (!src_pitch) {
return SDL_InvalidParamError("src_pitch");
}
if (!dst) {
if (dst == NULL) {
return SDL_InvalidParamError("dst");
}
if (!dst_pitch) {
@ -1509,8 +1557,7 @@ int SDL_PremultiplyAlpha(int width, int height,
/*
* Free a surface created by the above function.
*/
void
SDL_FreeSurface(SDL_Surface * surface)
void SDL_FreeSurface(SDL_Surface *surface)
{
if (surface == NULL) {
return;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -44,7 +44,7 @@ struct SDL_WindowShaper
SDL_Window *window;
/* The user's specified coordinates for the window, for once we give it a shape. */
Uint32 userx,usery;
Uint32 userx, usery;
/* The parameters for shape calculation. */
SDL_WindowShapeMode mode;
@ -58,8 +58,8 @@ struct SDL_WindowShaper
/* Define the SDL shape driver structure */
struct SDL_ShapeDriver
{
SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
SDL_WindowShaper *(*CreateShaper)(SDL_Window *window);
int (*SetWindowShape)(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode);
int (*ResizeWindowShape)(SDL_Window *window);
};
@ -101,7 +101,7 @@ struct SDL_Window
SDL_bool is_hiding;
SDL_bool is_destroying;
SDL_bool is_dropping; /* drag/drop in progress, expecting SDL_SendDropComplete(). */
SDL_bool is_dropping; /* drag/drop in progress, expecting SDL_SendDropComplete(). */
SDL_Rect mouse_rect;
@ -117,9 +117,9 @@ struct SDL_Window
SDL_Window *prev;
SDL_Window *next;
};
#define FULLSCREEN_VISIBLE(W) \
#define FULLSCREEN_VISIBLE(W) \
(((W)->flags & SDL_WINDOW_FULLSCREEN) && \
((W)->flags & SDL_WINDOW_SHOWN) && \
((W)->flags & SDL_WINDOW_SHOWN) && \
!((W)->flags & SDL_WINDOW_MINIMIZED))
/*
@ -147,7 +147,14 @@ struct SDL_VideoDisplay
struct SDL_SysWMinfo;
/* Define the SDL video driver structure */
#define _THIS SDL_VideoDevice *_this
#define _THIS SDL_VideoDevice *_this
/* Video device flags */
typedef enum
{
VIDEO_DEVICE_QUIRK_DISABLE_DISPLAY_MODE_SWITCHING = 0x01,
VIDEO_DEVICE_QUIRK_DISABLE_UNSET_FULLSCREEN_ON_MINIMIZE = 0x02,
} DeviceQuirkFlags;
struct SDL_VideoDevice
{
@ -162,43 +169,48 @@ struct SDL_VideoDevice
* Initialize the native video subsystem, filling in the list of
* displays for this driver, returning 0 or -1 if there's an error.
*/
int (*VideoInit) (_THIS);
int (*VideoInit)(_THIS);
/*
* Reverse the effects VideoInit() -- called if VideoInit() fails or
* if the application is shutting down the video subsystem.
*/
void (*VideoQuit) (_THIS);
void (*VideoQuit)(_THIS);
/*
* Reinitialize the touch devices -- called if an unknown touch ID occurs.
*/
void (*ResetTouch) (_THIS);
void (*ResetTouch)(_THIS);
/* * * */
/*
* Display functions
*/
/*
* Refresh the display list
*/
void (*RefreshDisplays)(_THIS);
/*
* Get the bounds of a display
*/
int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
int (*GetDisplayBounds)(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
/*
* Get the usable bounds of a display (bounds minus menubar or whatever)
*/
int (*GetDisplayUsableBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
int (*GetDisplayUsableBounds)(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
/*
* Get the dots/pixels-per-inch of a display
*/
int (*GetDisplayDPI) (_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi);
int (*GetDisplayDPI)(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
/*
* Get a list of the available display modes for a display.
*/
void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
void (*GetDisplayModes)(_THIS, SDL_VideoDisplay *display);
/*
* Setting the display mode is independent of creating windows, so
@ -206,21 +218,22 @@ struct SDL_VideoDevice
* their data updated accordingly, including the display surfaces
* associated with them.
*/
int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
int (*SetDisplayMode)(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
/* * * */
/*
* Window functions
*/
int (*CreateSDLWindow) (_THIS, SDL_Window * window);
int (*CreateSDLWindowFrom) (_THIS, SDL_Window * window, const void *data);
void (*SetWindowTitle) (_THIS, SDL_Window * window);
void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
void (*SetWindowPosition) (_THIS, SDL_Window * window);
void (*SetWindowSize) (_THIS, SDL_Window * window);
void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
int (*GetWindowBordersSize) (_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
int (*CreateSDLWindow)(_THIS, SDL_Window *window);
int (*CreateSDLWindowFrom)(_THIS, SDL_Window *window, const void *data);
void (*SetWindowTitle)(_THIS, SDL_Window *window);
void (*SetWindowIcon)(_THIS, SDL_Window *window, SDL_Surface *icon);
void (*SetWindowPosition)(_THIS, SDL_Window *window);
void (*SetWindowSize)(_THIS, SDL_Window *window);
void (*SetWindowMinimumSize)(_THIS, SDL_Window *window);
void (*SetWindowMaximumSize)(_THIS, SDL_Window *window);
int (*GetWindowBordersSize)(_THIS, SDL_Window *window, int *top, int *left, int *bottom, int *right);
void (*GetWindowSizeInPixels)(_THIS, SDL_Window *window, int *w, int *h);
int (*SetWindowOpacity) (_THIS, SDL_Window * window, float opacity);
int (*SetWindowModalFor) (_THIS, SDL_Window * modal_window, SDL_Window * parent_window);
int (*SetWindowInputFocus) (_THIS, SDL_Window * window);
@ -278,58 +291,61 @@ struct SDL_VideoDevice
/*
* Vulkan support
*/
int (*Vulkan_LoadLibrary) (_THIS, const char *path);
void (*Vulkan_UnloadLibrary) (_THIS);
SDL_bool (*Vulkan_GetInstanceExtensions) (_THIS, SDL_Window *window, unsigned *count, const char **names);
SDL_bool (*Vulkan_CreateSurface) (_THIS, SDL_Window *window, VkInstance instance, VkSurfaceKHR *surface);
void (*Vulkan_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
int (*Vulkan_LoadLibrary)(_THIS, const char *path);
void (*Vulkan_UnloadLibrary)(_THIS);
SDL_bool (*Vulkan_GetInstanceExtensions)(_THIS, SDL_Window *window, unsigned *count, const char **names);
SDL_bool (*Vulkan_CreateSurface)(_THIS, SDL_Window *window, VkInstance instance, VkSurfaceKHR *surface);
void (*Vulkan_GetDrawableSize)(_THIS, SDL_Window *window, int *w, int *h);
/* * * */
/*
* Metal support
*/
SDL_MetalView (*Metal_CreateView) (_THIS, SDL_Window * window);
void (*Metal_DestroyView) (_THIS, SDL_MetalView view);
void *(*Metal_GetLayer) (_THIS, SDL_MetalView view);
void (*Metal_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
SDL_MetalView (*Metal_CreateView)(_THIS, SDL_Window *window);
void (*Metal_DestroyView)(_THIS, SDL_MetalView view);
void *(*Metal_GetLayer)(_THIS, SDL_MetalView view);
void (*Metal_GetDrawableSize)(_THIS, SDL_Window *window, int *w, int *h);
/* * * */
/*
* Event manager functions
*/
int (*WaitEventTimeout) (_THIS, int timeout);
void (*SendWakeupEvent) (_THIS, SDL_Window *window);
void (*PumpEvents) (_THIS);
int (*WaitEventTimeout)(_THIS, int timeout);
void (*SendWakeupEvent)(_THIS, SDL_Window *window);
void (*PumpEvents)(_THIS);
/* Suspend the screensaver */
void (*SuspendScreenSaver) (_THIS);
void (*SuspendScreenSaver)(_THIS);
/* Text input */
void (*StartTextInput) (_THIS);
void (*StopTextInput) (_THIS);
void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
void (*ClearComposition) (_THIS);
SDL_bool (*IsTextInputShown) (_THIS);
void (*StartTextInput)(_THIS);
void (*StopTextInput)(_THIS);
void (*SetTextInputRect)(_THIS, const SDL_Rect *rect);
void (*ClearComposition)(_THIS);
SDL_bool (*IsTextInputShown)(_THIS);
/* Screen keyboard */
SDL_bool (*HasScreenKeyboardSupport) (_THIS);
void (*ShowScreenKeyboard) (_THIS, SDL_Window *window);
void (*HideScreenKeyboard) (_THIS, SDL_Window *window);
SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window);
SDL_bool (*HasScreenKeyboardSupport)(_THIS);
void (*ShowScreenKeyboard)(_THIS, SDL_Window *window);
void (*HideScreenKeyboard)(_THIS, SDL_Window *window);
SDL_bool (*IsScreenKeyboardShown)(_THIS, SDL_Window *window);
/* Clipboard */
int (*SetClipboardText) (_THIS, const char *text);
char * (*GetClipboardText) (_THIS);
SDL_bool (*HasClipboardText) (_THIS);
int (*SetClipboardText)(_THIS, const char *text);
char *(*GetClipboardText)(_THIS);
SDL_bool (*HasClipboardText)(_THIS);
int (*SetPrimarySelectionText)(_THIS, const char *text);
char *(*GetPrimarySelectionText)(_THIS);
SDL_bool (*HasPrimarySelectionText)(_THIS);
/* MessageBox */
int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
int (*ShowMessageBox)(_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
/* Hit-testing */
int (*SetWindowHitTest)(SDL_Window * window, SDL_bool enabled);
int (*SetWindowHitTest)(SDL_Window *window, SDL_bool enabled);
/* Tell window that app enabled drag'n'drop events */
void (*AcceptDragAndDrop)(SDL_Window * window, SDL_bool accept);
void (*AcceptDragAndDrop)(SDL_Window *window, SDL_bool accept);
/* * * */
/* Data common to all drivers */
@ -346,8 +362,9 @@ struct SDL_VideoDevice
Uint8 window_magic;
Uint32 next_object_id;
char *clipboard_text;
char *primary_selection_text;
SDL_bool setting_display_mode;
SDL_bool disable_display_mode_switching;
Uint32 quirk_flags;
/* * * */
/* Data used by the GL drivers */
@ -368,6 +385,7 @@ struct SDL_VideoDevice
int stereo;
int multisamplebuffers;
int multisamplesamples;
int floatbuffers;
int accelerated;
int major_version;
int minor_version;
@ -414,25 +432,25 @@ struct SDL_VideoDevice
/* Data private to this driver */
void *driverdata;
struct SDL_GLDriverData *gl_data;
#if SDL_VIDEO_OPENGL_EGL
struct SDL_EGL_VideoData *egl_data;
#endif
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
struct SDL_PrivateGLESData *gles_data;
#endif
/* * * */
/* The function used to dispose of this structure */
void (*free) (_THIS);
void (*free)(_THIS);
};
typedef struct VideoBootStrap
{
const char *name;
const char *desc;
SDL_VideoDevice *(*create) (int devindex);
SDL_VideoDevice *(*create)(void);
} VideoBootStrap;
/* Not all of these are available in a given build. Use #ifdefs, etc. */
@ -445,13 +463,16 @@ extern VideoBootStrap HAIKU_bootstrap;
extern VideoBootStrap PND_bootstrap;
extern VideoBootStrap UIKIT_bootstrap;
extern VideoBootStrap Android_bootstrap;
extern VideoBootStrap PS2_bootstrap;
extern VideoBootStrap PSP_bootstrap;
extern VideoBootStrap VITA_bootstrap;
extern VideoBootStrap RISCOS_bootstrap;
extern VideoBootStrap N3DS_bootstrap;
extern VideoBootStrap RPI_bootstrap;
extern VideoBootStrap KMSDRM_bootstrap;
extern VideoBootStrap KMSDRM_LEGACY_bootstrap;
extern VideoBootStrap DUMMY_bootstrap;
extern VideoBootStrap DUMMY_evdev_bootstrap;
extern VideoBootStrap Wayland_bootstrap;
extern VideoBootStrap NACL_bootstrap;
extern VideoBootStrap VIVANTE_bootstrap;
@ -465,37 +486,37 @@ extern VideoBootStrap OS2VMAN_bootstrap;
/* Use SDL_OnVideoThread() sparingly, to avoid regressions in use cases that currently happen to work */
extern SDL_bool SDL_OnVideoThread(void);
extern SDL_VideoDevice *SDL_GetVideoDevice(void);
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display, SDL_bool send_event);
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode);
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send_event);
extern void SDL_DelVideoDisplay(int index);
extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
extern void SDL_SetCurrentDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
extern void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode);
extern void SDL_SetCurrentDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode);
extern void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode);
extern void SDL_ResetDisplayModes(int displayIndex);
extern int SDL_GetIndexOfDisplay(SDL_VideoDisplay *display);
extern SDL_VideoDisplay *SDL_GetDisplay(int displayIndex);
extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
extern void *SDL_GetDisplayDriverData( int displayIndex );
extern void *SDL_GetDisplayDriverData(int displayIndex);
extern SDL_bool SDL_IsVideoContextExternal(void);
extern int SDL_GetMessageBoxCount(void);
extern void SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor);
extern void SDL_GL_DeduceMaxSupportedESProfile(int *major, int *minor);
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
extern int SDL_RecreateWindow(SDL_Window *window, Uint32 flags);
extern SDL_bool SDL_HasWindows(void);
extern void SDL_OnWindowShown(SDL_Window * window);
extern void SDL_OnWindowHidden(SDL_Window * window);
extern void SDL_OnWindowMoved(SDL_Window * window);
extern void SDL_OnWindowResized(SDL_Window * window);
extern void SDL_OnWindowMinimized(SDL_Window * window);
extern void SDL_OnWindowRestored(SDL_Window * window);
extern void SDL_OnWindowEnter(SDL_Window * window);
extern void SDL_OnWindowLeave(SDL_Window * window);
extern void SDL_OnWindowFocusGained(SDL_Window * window);
extern void SDL_OnWindowFocusLost(SDL_Window * window);
extern void SDL_UpdateWindowGrab(SDL_Window * window);
extern SDL_Window * SDL_GetFocusWindow(void);
extern void SDL_OnWindowShown(SDL_Window *window);
extern void SDL_OnWindowHidden(SDL_Window *window);
extern void SDL_OnWindowMoved(SDL_Window *window);
extern void SDL_OnWindowResized(SDL_Window *window);
extern void SDL_OnWindowMinimized(SDL_Window *window);
extern void SDL_OnWindowRestored(SDL_Window *window);
extern void SDL_OnWindowEnter(SDL_Window *window);
extern void SDL_OnWindowLeave(SDL_Window *window);
extern void SDL_OnWindowFocusGained(SDL_Window *window);
extern void SDL_OnWindowFocusLost(SDL_Window *window);
extern void SDL_UpdateWindowGrab(SDL_Window *window);
extern SDL_Window *SDL_GetFocusWindow(void);
extern SDL_bool SDL_ShouldAllowTopmost(void);
@ -503,6 +524,10 @@ extern float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vin
extern void SDL_ToggleDragAndDropSupport(void);
extern int SDL_GetPointDisplayIndex(const SDL_Point *point);
extern int SDL_GL_SwapWindowWithResult(SDL_Window *window);
#endif /* SDL_sysvideo_h_ */
/* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -34,12 +34,14 @@
#define VK_USE_PLATFORM_ANDROID_KHR
#endif
#if SDL_VIDEO_DRIVER_COCOA
#define VK_USE_PLATFORM_METAL_EXT
#define VK_USE_PLATFORM_MACOS_MVK
#endif
#if SDL_VIDEO_DRIVER_DIRECTFB
#define VK_USE_PLATFORM_DIRECTFB_EXT
#endif
#if SDL_VIDEO_DRIVER_UIKIT
#define VK_USE_PLATFORM_METAL_EXT
#define VK_USE_PLATFORM_IOS_MVK
#endif
#if SDL_VIDEO_DRIVER_WAYLAND
@ -60,7 +62,6 @@
#include "SDL_vulkan.h"
extern const char *SDL_Vulkan_GetResultString(VkResult result);
extern VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
@ -86,8 +87,8 @@ extern SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr,
/* No SDL Vulkan support, just include the header for typedefs */
#include "SDL_vulkan.h"
typedef void (*PFN_vkGetInstanceProcAddr) (void);
typedef int (*PFN_vkEnumerateInstanceExtensionProperties) (void);
typedef void (*PFN_vkGetInstanceProcAddr)(void);
typedef int (*PFN_vkEnumerateInstanceExtensionProperties)(void);
#endif /* SDL_VIDEO_VULKAN */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -28,88 +28,88 @@
const char *SDL_Vulkan_GetResultString(VkResult result)
{
switch ((int)result) {
case VK_SUCCESS:
return "VK_SUCCESS";
case VK_NOT_READY:
return "VK_NOT_READY";
case VK_TIMEOUT:
return "VK_TIMEOUT";
case VK_EVENT_SET:
return "VK_EVENT_SET";
case VK_EVENT_RESET:
return "VK_EVENT_RESET";
case VK_INCOMPLETE:
return "VK_INCOMPLETE";
case VK_ERROR_OUT_OF_HOST_MEMORY:
return "VK_ERROR_OUT_OF_HOST_MEMORY";
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
case VK_ERROR_INITIALIZATION_FAILED:
return "VK_ERROR_INITIALIZATION_FAILED";
case VK_ERROR_DEVICE_LOST:
return "VK_ERROR_DEVICE_LOST";
case VK_ERROR_MEMORY_MAP_FAILED:
return "VK_ERROR_MEMORY_MAP_FAILED";
case VK_ERROR_LAYER_NOT_PRESENT:
return "VK_ERROR_LAYER_NOT_PRESENT";
case VK_ERROR_EXTENSION_NOT_PRESENT:
return "VK_ERROR_EXTENSION_NOT_PRESENT";
case VK_ERROR_FEATURE_NOT_PRESENT:
return "VK_ERROR_FEATURE_NOT_PRESENT";
case VK_ERROR_INCOMPATIBLE_DRIVER:
return "VK_ERROR_INCOMPATIBLE_DRIVER";
case VK_ERROR_TOO_MANY_OBJECTS:
return "VK_ERROR_TOO_MANY_OBJECTS";
case VK_ERROR_FORMAT_NOT_SUPPORTED:
return "VK_ERROR_FORMAT_NOT_SUPPORTED";
case VK_ERROR_FRAGMENTED_POOL:
return "VK_ERROR_FRAGMENTED_POOL";
case VK_ERROR_UNKNOWN:
return "VK_ERROR_UNKNOWN";
case VK_ERROR_OUT_OF_POOL_MEMORY:
return "VK_ERROR_OUT_OF_POOL_MEMORY";
case VK_ERROR_INVALID_EXTERNAL_HANDLE:
return "VK_ERROR_INVALID_EXTERNAL_HANDLE";
case VK_ERROR_FRAGMENTATION:
return "VK_ERROR_FRAGMENTATION";
case VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS:
return "VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS";
case VK_ERROR_SURFACE_LOST_KHR:
return "VK_ERROR_SURFACE_LOST_KHR";
case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:
return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
case VK_SUBOPTIMAL_KHR:
return "VK_SUBOPTIMAL_KHR";
case VK_ERROR_OUT_OF_DATE_KHR:
return "VK_ERROR_OUT_OF_DATE_KHR";
case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:
return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
case VK_ERROR_VALIDATION_FAILED_EXT:
return "VK_ERROR_VALIDATION_FAILED_EXT";
case VK_ERROR_INVALID_SHADER_NV:
return "VK_ERROR_INVALID_SHADER_NV";
case VK_SUCCESS:
return "VK_SUCCESS";
case VK_NOT_READY:
return "VK_NOT_READY";
case VK_TIMEOUT:
return "VK_TIMEOUT";
case VK_EVENT_SET:
return "VK_EVENT_SET";
case VK_EVENT_RESET:
return "VK_EVENT_RESET";
case VK_INCOMPLETE:
return "VK_INCOMPLETE";
case VK_ERROR_OUT_OF_HOST_MEMORY:
return "VK_ERROR_OUT_OF_HOST_MEMORY";
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
case VK_ERROR_INITIALIZATION_FAILED:
return "VK_ERROR_INITIALIZATION_FAILED";
case VK_ERROR_DEVICE_LOST:
return "VK_ERROR_DEVICE_LOST";
case VK_ERROR_MEMORY_MAP_FAILED:
return "VK_ERROR_MEMORY_MAP_FAILED";
case VK_ERROR_LAYER_NOT_PRESENT:
return "VK_ERROR_LAYER_NOT_PRESENT";
case VK_ERROR_EXTENSION_NOT_PRESENT:
return "VK_ERROR_EXTENSION_NOT_PRESENT";
case VK_ERROR_FEATURE_NOT_PRESENT:
return "VK_ERROR_FEATURE_NOT_PRESENT";
case VK_ERROR_INCOMPATIBLE_DRIVER:
return "VK_ERROR_INCOMPATIBLE_DRIVER";
case VK_ERROR_TOO_MANY_OBJECTS:
return "VK_ERROR_TOO_MANY_OBJECTS";
case VK_ERROR_FORMAT_NOT_SUPPORTED:
return "VK_ERROR_FORMAT_NOT_SUPPORTED";
case VK_ERROR_FRAGMENTED_POOL:
return "VK_ERROR_FRAGMENTED_POOL";
case VK_ERROR_UNKNOWN:
return "VK_ERROR_UNKNOWN";
case VK_ERROR_OUT_OF_POOL_MEMORY:
return "VK_ERROR_OUT_OF_POOL_MEMORY";
case VK_ERROR_INVALID_EXTERNAL_HANDLE:
return "VK_ERROR_INVALID_EXTERNAL_HANDLE";
case VK_ERROR_FRAGMENTATION:
return "VK_ERROR_FRAGMENTATION";
case VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS:
return "VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS";
case VK_ERROR_SURFACE_LOST_KHR:
return "VK_ERROR_SURFACE_LOST_KHR";
case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:
return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
case VK_SUBOPTIMAL_KHR:
return "VK_SUBOPTIMAL_KHR";
case VK_ERROR_OUT_OF_DATE_KHR:
return "VK_ERROR_OUT_OF_DATE_KHR";
case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:
return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
case VK_ERROR_VALIDATION_FAILED_EXT:
return "VK_ERROR_VALIDATION_FAILED_EXT";
case VK_ERROR_INVALID_SHADER_NV:
return "VK_ERROR_INVALID_SHADER_NV";
#if VK_HEADER_VERSION >= 135 && VK_HEADER_VERSION < 162
case VK_ERROR_INCOMPATIBLE_VERSION_KHR:
return "VK_ERROR_INCOMPATIBLE_VERSION_KHR";
case VK_ERROR_INCOMPATIBLE_VERSION_KHR:
return "VK_ERROR_INCOMPATIBLE_VERSION_KHR";
#endif
case VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT:
return "VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT";
case VK_ERROR_NOT_PERMITTED_EXT:
return "VK_ERROR_NOT_PERMITTED_EXT";
case VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT:
return "VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT";
case VK_THREAD_IDLE_KHR:
return "VK_THREAD_IDLE_KHR";
case VK_THREAD_DONE_KHR:
return "VK_THREAD_DONE_KHR";
case VK_OPERATION_DEFERRED_KHR:
return "VK_OPERATION_DEFERRED_KHR";
case VK_OPERATION_NOT_DEFERRED_KHR:
return "VK_OPERATION_NOT_DEFERRED_KHR";
case VK_PIPELINE_COMPILE_REQUIRED_EXT:
return "VK_PIPELINE_COMPILE_REQUIRED_EXT";
default:
break;
case VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT:
return "VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT";
case VK_ERROR_NOT_PERMITTED_EXT:
return "VK_ERROR_NOT_PERMITTED_EXT";
case VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT:
return "VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT";
case VK_THREAD_IDLE_KHR:
return "VK_THREAD_IDLE_KHR";
case VK_THREAD_DONE_KHR:
return "VK_THREAD_DONE_KHR";
case VK_OPERATION_DEFERRED_KHR:
return "VK_OPERATION_DEFERRED_KHR";
case VK_OPERATION_NOT_DEFERRED_KHR:
return "VK_OPERATION_NOT_DEFERRED_KHR";
case VK_PIPELINE_COMPILE_REQUIRED_EXT:
return "VK_PIPELINE_COMPILE_REQUIRED_EXT";
default:
break;
}
if (result < 0) {
return "VK_ERROR_<Unknown>";
@ -149,7 +149,7 @@ VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
retval = SDL_calloc(count, sizeof(VkExtensionProperties));
}
if (!retval) {
if (retval == NULL) {
SDL_OutOfMemory();
return NULL;
}
@ -198,12 +198,12 @@ static const VkDisplayPlaneAlphaFlagBitsKHR alphaModes[4] = {
};
SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
VkInstance instance,
VkSurfaceKHR *surface)
VkInstance instance,
VkSurfaceKHR *surface)
{
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
(PFN_vkGetInstanceProcAddr)vkGetInstanceProcAddr_;
#define VULKAN_INSTANCE_FUNCTION(name) \
#define VULKAN_INSTANCE_FUNCTION(name) \
PFN_##name name = (PFN_##name)vkGetInstanceProcAddr((VkInstance)instance, #name)
VULKAN_INSTANCE_FUNCTION(vkEnumeratePhysicalDevices);
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayPropertiesKHR);
@ -222,17 +222,17 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
int displayId = 0; /* Counting from physical device 0, display 0 */
if (!vkEnumeratePhysicalDevices ||
!vkGetPhysicalDeviceDisplayPropertiesKHR ||
!vkGetDisplayModePropertiesKHR ||
!vkGetPhysicalDeviceDisplayPlanePropertiesKHR ||
!vkGetDisplayPlaneCapabilitiesKHR ||
!vkGetDisplayPlaneSupportedDisplaysKHR ||
!vkCreateDisplayPlaneSurfaceKHR) {
!vkGetPhysicalDeviceDisplayPropertiesKHR ||
!vkGetDisplayModePropertiesKHR ||
!vkGetPhysicalDeviceDisplayPlanePropertiesKHR ||
!vkGetDisplayPlaneCapabilitiesKHR ||
!vkGetDisplayPlaneSupportedDisplaysKHR ||
!vkCreateDisplayPlaneSurfaceKHR) {
SDL_SetError(VK_KHR_DISPLAY_EXTENSION_NAME " extension is not enabled in the Vulkan instance.");
goto error;
}
if ((chosenDisplayId = SDL_getenv("SDL_VULKAN_DISPLAY")) != NULL) {
chosenDisplayId = SDL_getenv("SDL_VULKAN_DISPLAY");
if (chosenDisplayId != NULL) {
displayId = SDL_atoi(chosenDisplayId);
}
@ -249,7 +249,7 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
}
physicalDevices = SDL_malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount);
if (!physicalDevices) {
if (physicalDevices == NULL) {
SDL_OutOfMemory();
goto error;
}
@ -283,16 +283,16 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
continue;
}
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Number of display properties for device %u: %u",
physicalDeviceIndex, displayPropertiesCount);
physicalDeviceIndex, displayPropertiesCount);
if (displayId < 0 || (uint32_t) displayId >= displayPropertiesCount) {
if (displayId < 0 || (uint32_t)displayId >= displayPropertiesCount) {
/* Display id specified was higher than number of available displays, move to next physical device. */
displayId -= displayPropertiesCount;
continue;
}
displayProperties = SDL_malloc(sizeof(VkDisplayPropertiesKHR) * displayPropertiesCount);
if (!displayProperties) {
if (displayProperties == NULL) {
SDL_OutOfMemory();
goto error;
}
@ -307,22 +307,21 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
display = displayProperties[displayId].display;
extent = displayProperties[displayId].physicalResolution;
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Display: %s Native resolution: %ux%u",
displayProperties[displayId].displayName, extent.width, extent.height);
displayProperties[displayId].displayName, extent.width, extent.height);
SDL_free(displayProperties);
displayProperties = NULL;
/* Get display mode properties for the chosen display */
result = vkGetDisplayModePropertiesKHR(physicalDevice, display, &displayModePropertiesCount, NULL);
if (result != VK_SUCCESS || displayModePropertiesCount == 0)
{
if (result != VK_SUCCESS || displayModePropertiesCount == 0) {
SDL_SetError("Error enumerating display modes");
goto error;
}
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Number of display modes: %u", displayModePropertiesCount);
displayModeProperties = SDL_malloc(sizeof(VkDisplayModePropertiesKHR) * displayModePropertiesCount);
if (!displayModeProperties) {
if (displayModeProperties == NULL) {
SDL_OutOfMemory();
goto error;
}
@ -353,9 +352,9 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
SDL_zero(createInfo);
createInfo.displayMode = displayModeProperties[bestMatchIndex].displayMode;
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Matching mode %ux%u with refresh rate %u",
displayModeProperties[bestMatchIndex].parameters.visibleRegion.width,
displayModeProperties[bestMatchIndex].parameters.visibleRegion.height,
refreshRate);
displayModeProperties[bestMatchIndex].parameters.visibleRegion.width,
displayModeProperties[bestMatchIndex].parameters.visibleRegion.height,
refreshRate);
SDL_free(displayModeProperties);
displayModeProperties = NULL;
@ -369,7 +368,7 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Number of display planes: %u", displayPlanePropertiesCount);
displayPlaneProperties = SDL_malloc(sizeof(VkDisplayPlanePropertiesKHR) * displayPlanePropertiesCount);
if (!displayPlaneProperties) {
if (displayPlaneProperties == NULL) {
SDL_OutOfMemory();
goto error;
}
@ -394,13 +393,13 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
/* Check supported displays for this plane. */
result = vkGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, i, &planeSupportedDisplaysCount, NULL);
if (result != VK_SUCCESS || planeSupportedDisplaysCount == 0) {
continue; /* No supported displays, on to next plane. */
continue; /* No supported displays, on to next plane. */
}
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Number of supported displays for plane %u: %u", i, planeSupportedDisplaysCount);
planeSupportedDisplays = SDL_malloc(sizeof(VkDisplayKHR) * planeSupportedDisplaysCount);
if (!planeSupportedDisplays) {
if (planeSupportedDisplays == NULL) {
SDL_free(displayPlaneProperties);
SDL_OutOfMemory();
goto error;
@ -414,8 +413,7 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
goto error;
}
for (j = 0; j < planeSupportedDisplaysCount && planeSupportedDisplays[j] != display; ++j)
{
for (j = 0; j < planeSupportedDisplaysCount && planeSupportedDisplays[j] != display; ++j) {
}
SDL_free(planeSupportedDisplays);
@ -438,8 +436,8 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
extent.width <= planeCaps.maxDstExtent.width && extent.height <= planeCaps.maxDstExtent.height) {
/* If it does, choose this plane. */
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Choosing plane %d, minimum extent %dx%d maximum extent %dx%d", i,
planeCaps.minDstExtent.width, planeCaps.minDstExtent.height,
planeCaps.maxDstExtent.width, planeCaps.maxDstExtent.height);
planeCaps.minDstExtent.width, planeCaps.minDstExtent.height,
planeCaps.maxDstExtent.width, planeCaps.maxDstExtent.height);
planeIndex = i;
break;
}

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,13 +24,15 @@
#include "../SDL_internal.h"
/* YUV conversion functions */
extern int SDL_ConvertPixels_YUV_to_RGB(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch);
extern int SDL_ConvertPixels_RGB_to_YUV(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch);
extern int SDL_ConvertPixels_YUV_to_YUV(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch);
extern int SDL_CalculateYUVSize(Uint32 format, int w, int h, size_t *size, int *pitch);
#endif /* SDL_yuv_c_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,14 +26,12 @@
#include "SDL_androidclipboard.h"
#include "../../core/android/SDL_android.h"
int
Android_SetClipboardText(_THIS, const char *text)
int Android_SetClipboardText(_THIS, const char *text)
{
return Android_JNI_SetClipboardText(text);
}
char *
Android_GetClipboardText(_THIS)
char *Android_GetClipboardText(_THIS)
{
return Android_JNI_GetClipboardText();
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -44,40 +44,40 @@ static void ANDROIDAUDIO_PauseDevices(void) {}
extern void openslES_ResumeDevices(void);
extern void openslES_PauseDevices(void);
#else
static void openslES_ResumeDevices(void) {}
static void openslES_ResumeDevices(void)
{
}
static void openslES_PauseDevices(void) {}
#endif
#if !SDL_AUDIO_DISABLED && SDL_AUDIO_DRIVER_AAUDIO
extern void aaudio_ResumeDevices(void);
extern void aaudio_PauseDevices(void);
SDL_bool aaudio_DetectBrokenPlayState( void );
SDL_bool aaudio_DetectBrokenPlayState(void);
#else
static void aaudio_ResumeDevices(void) {}
static void aaudio_ResumeDevices(void)
{
}
static void aaudio_PauseDevices(void) {}
static SDL_bool aaudio_DetectBrokenPlayState( void ) { return SDL_FALSE; }
static SDL_bool aaudio_DetectBrokenPlayState(void) { return SDL_FALSE; }
#endif
/* Number of 'type' events in the event queue */
static int
SDL_NumberOfEvents(Uint32 type)
static int SDL_NumberOfEvents(Uint32 type)
{
return SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type);
}
#if SDL_VIDEO_OPENGL_EGL
static void
android_egl_context_restore(SDL_Window *window)
static void android_egl_context_restore(SDL_Window *window)
{
if (window) {
SDL_Event event;
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if (SDL_GL_MakeCurrent(window, (SDL_GLContext) data->egl_context) < 0) {
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
if (SDL_GL_MakeCurrent(window, (SDL_GLContext)data->egl_context) < 0) {
/* The context is no longer valid, create a new one */
data->egl_context = (EGLContext) SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, (SDL_GLContext) data->egl_context);
data->egl_context = (EGLContext)SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, (SDL_GLContext)data->egl_context);
event.type = SDL_RENDER_DEVICE_RESET;
SDL_PushEvent(&event);
}
@ -85,12 +85,11 @@ android_egl_context_restore(SDL_Window *window)
}
}
static void
android_egl_context_backup(SDL_Window *window)
static void android_egl_context_backup(SDL_Window *window)
{
if (window) {
/* Keep a copy of the EGL Context so we can try to restore it when we resume */
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
data->egl_context = SDL_GL_GetCurrentContext();
/* We need to do this so the EGLSurface can be freed */
SDL_GL_MakeCurrent(window, NULL);
@ -106,8 +105,7 @@ android_egl_context_backup(SDL_Window *window)
* No polling necessary
*/
void
Android_PumpEvents_Blocking(_THIS)
void Android_PumpEvents_Blocking(_THIS)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
@ -176,14 +174,13 @@ Android_PumpEvents_Blocking(_THIS)
}
}
if ( aaudio_DetectBrokenPlayState() ) {
if (aaudio_DetectBrokenPlayState()) {
aaudio_PauseDevices();
aaudio_ResumeDevices();
}
}
void
Android_PumpEvents_NonBlocking(_THIS)
void Android_PumpEvents_NonBlocking(_THIS)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
static int backup_context = 0;
@ -210,7 +207,6 @@ Android_PumpEvents_NonBlocking(_THIS)
backup_context = 0;
}
if (SDL_SemTryWait(Android_ResumeSem) == 0) {
videodata->isPaused = 0;
@ -263,7 +259,7 @@ Android_PumpEvents_NonBlocking(_THIS)
}
}
if ( aaudio_DetectBrokenPlayState() ) {
if (aaudio_DetectBrokenPlayState()) {
aaudio_PauseDevices();
aaudio_ResumeDevices();
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -36,32 +36,29 @@
#include <dlfcn.h>
int
Android_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
int Android_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
{
if (window && context) {
return SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context);
return SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *)window->driverdata)->egl_surface, context);
} else {
return SDL_EGL_MakeCurrent(_this, NULL, NULL);
}
}
SDL_GLContext
Android_GLES_CreateContext(_THIS, SDL_Window * window)
SDL_GLContext Android_GLES_CreateContext(_THIS, SDL_Window *window)
{
SDL_GLContext ret;
Android_ActivityMutex_Lock_Running();
ret = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
ret = SDL_EGL_CreateContext(_this, ((SDL_WindowData *)window->driverdata)->egl_surface);
SDL_UnlockMutex(Android_ActivityMutex);
return ret;
}
int
Android_GLES_SwapWindow(_THIS, SDL_Window * window)
int Android_GLES_SwapWindow(_THIS, SDL_Window *window)
{
int retval;
@ -74,16 +71,16 @@ Android_GLES_SwapWindow(_THIS, SDL_Window * window)
/*_this->egl_data->eglWaitNative(EGL_CORE_NATIVE_ENGINE);
_this->egl_data->eglWaitGL();*/
retval = SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
retval = SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *)window->driverdata)->egl_surface);
SDL_UnlockMutex(Android_ActivityMutex);
return retval;
}
int
Android_GLES_LoadLibrary(_THIS, const char *path) {
return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) 0, 0);
int Android_GLES_LoadLibrary(_THIS, const char *path)
{
return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)0, 0);
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,12 +23,11 @@
#ifndef SDL_androidgl_h_
#define SDL_androidgl_h_
SDL_GLContext Android_GLES_CreateContext(_THIS, SDL_Window * window);
int Android_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
int Android_GLES_SwapWindow(_THIS, SDL_Window * window);
SDL_GLContext Android_GLES_CreateContext(_THIS, SDL_Window *window);
int Android_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context);
int Android_GLES_SwapWindow(_THIS, SDL_Window *window);
int Android_GLES_LoadLibrary(_THIS, const char *path);
#endif /* SDL_androidgl_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -30,300 +30,290 @@
#include "../../core/android/SDL_android.h"
void Android_InitKeyboard(void)
{
SDL_Keycode keymap[SDL_NUM_SCANCODES];
/* Add default scancode to key mapping */
SDL_GetDefaultKeymap(keymap);
SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
}
static SDL_Scancode Android_Keycodes[] = {
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_UNKNOWN */
SDL_SCANCODE_SOFTLEFT, /* AKEYCODE_SOFT_LEFT */
SDL_SCANCODE_SOFTRIGHT, /* AKEYCODE_SOFT_RIGHT */
SDL_SCANCODE_AC_HOME, /* AKEYCODE_HOME */
SDL_SCANCODE_AC_BACK, /* AKEYCODE_BACK */
SDL_SCANCODE_CALL, /* AKEYCODE_CALL */
SDL_SCANCODE_ENDCALL, /* AKEYCODE_ENDCALL */
SDL_SCANCODE_0, /* AKEYCODE_0 */
SDL_SCANCODE_1, /* AKEYCODE_1 */
SDL_SCANCODE_2, /* AKEYCODE_2 */
SDL_SCANCODE_3, /* AKEYCODE_3 */
SDL_SCANCODE_4, /* AKEYCODE_4 */
SDL_SCANCODE_5, /* AKEYCODE_5 */
SDL_SCANCODE_6, /* AKEYCODE_6 */
SDL_SCANCODE_7, /* AKEYCODE_7 */
SDL_SCANCODE_8, /* AKEYCODE_8 */
SDL_SCANCODE_9, /* AKEYCODE_9 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STAR */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_POUND */
SDL_SCANCODE_UP, /* AKEYCODE_DPAD_UP */
SDL_SCANCODE_DOWN, /* AKEYCODE_DPAD_DOWN */
SDL_SCANCODE_LEFT, /* AKEYCODE_DPAD_LEFT */
SDL_SCANCODE_RIGHT, /* AKEYCODE_DPAD_RIGHT */
SDL_SCANCODE_SELECT, /* AKEYCODE_DPAD_CENTER */
SDL_SCANCODE_VOLUMEUP, /* AKEYCODE_VOLUME_UP */
SDL_SCANCODE_VOLUMEDOWN, /* AKEYCODE_VOLUME_DOWN */
SDL_SCANCODE_POWER, /* AKEYCODE_POWER */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CAMERA */
SDL_SCANCODE_CLEAR, /* AKEYCODE_CLEAR */
SDL_SCANCODE_A, /* AKEYCODE_A */
SDL_SCANCODE_B, /* AKEYCODE_B */
SDL_SCANCODE_C, /* AKEYCODE_C */
SDL_SCANCODE_D, /* AKEYCODE_D */
SDL_SCANCODE_E, /* AKEYCODE_E */
SDL_SCANCODE_F, /* AKEYCODE_F */
SDL_SCANCODE_G, /* AKEYCODE_G */
SDL_SCANCODE_H, /* AKEYCODE_H */
SDL_SCANCODE_I, /* AKEYCODE_I */
SDL_SCANCODE_J, /* AKEYCODE_J */
SDL_SCANCODE_K, /* AKEYCODE_K */
SDL_SCANCODE_L, /* AKEYCODE_L */
SDL_SCANCODE_M, /* AKEYCODE_M */
SDL_SCANCODE_N, /* AKEYCODE_N */
SDL_SCANCODE_O, /* AKEYCODE_O */
SDL_SCANCODE_P, /* AKEYCODE_P */
SDL_SCANCODE_Q, /* AKEYCODE_Q */
SDL_SCANCODE_R, /* AKEYCODE_R */
SDL_SCANCODE_S, /* AKEYCODE_S */
SDL_SCANCODE_T, /* AKEYCODE_T */
SDL_SCANCODE_U, /* AKEYCODE_U */
SDL_SCANCODE_V, /* AKEYCODE_V */
SDL_SCANCODE_W, /* AKEYCODE_W */
SDL_SCANCODE_X, /* AKEYCODE_X */
SDL_SCANCODE_Y, /* AKEYCODE_Y */
SDL_SCANCODE_Z, /* AKEYCODE_Z */
SDL_SCANCODE_COMMA, /* AKEYCODE_COMMA */
SDL_SCANCODE_PERIOD, /* AKEYCODE_PERIOD */
SDL_SCANCODE_LALT, /* AKEYCODE_ALT_LEFT */
SDL_SCANCODE_RALT, /* AKEYCODE_ALT_RIGHT */
SDL_SCANCODE_LSHIFT, /* AKEYCODE_SHIFT_LEFT */
SDL_SCANCODE_RSHIFT, /* AKEYCODE_SHIFT_RIGHT */
SDL_SCANCODE_TAB, /* AKEYCODE_TAB */
SDL_SCANCODE_SPACE, /* AKEYCODE_SPACE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SYM */
SDL_SCANCODE_WWW, /* AKEYCODE_EXPLORER */
SDL_SCANCODE_MAIL, /* AKEYCODE_ENVELOPE */
SDL_SCANCODE_RETURN, /* AKEYCODE_ENTER */
SDL_SCANCODE_BACKSPACE, /* AKEYCODE_DEL */
SDL_SCANCODE_GRAVE, /* AKEYCODE_GRAVE */
SDL_SCANCODE_MINUS, /* AKEYCODE_MINUS */
SDL_SCANCODE_EQUALS, /* AKEYCODE_EQUALS */
SDL_SCANCODE_LEFTBRACKET, /* AKEYCODE_LEFT_BRACKET */
SDL_SCANCODE_RIGHTBRACKET, /* AKEYCODE_RIGHT_BRACKET */
SDL_SCANCODE_BACKSLASH, /* AKEYCODE_BACKSLASH */
SDL_SCANCODE_SEMICOLON, /* AKEYCODE_SEMICOLON */
SDL_SCANCODE_APOSTROPHE, /* AKEYCODE_APOSTROPHE */
SDL_SCANCODE_SLASH, /* AKEYCODE_SLASH */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NUM */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_HEADSETHOOK */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_FOCUS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PLUS */
SDL_SCANCODE_MENU, /* AKEYCODE_MENU */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NOTIFICATION */
SDL_SCANCODE_AC_SEARCH, /* AKEYCODE_SEARCH */
SDL_SCANCODE_AUDIOPLAY, /* AKEYCODE_MEDIA_PLAY_PAUSE */
SDL_SCANCODE_AUDIOSTOP, /* AKEYCODE_MEDIA_STOP */
SDL_SCANCODE_AUDIONEXT, /* AKEYCODE_MEDIA_NEXT */
SDL_SCANCODE_AUDIOPREV, /* AKEYCODE_MEDIA_PREVIOUS */
SDL_SCANCODE_AUDIOREWIND, /* AKEYCODE_MEDIA_REWIND */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_UNKNOWN */
SDL_SCANCODE_SOFTLEFT, /* AKEYCODE_SOFT_LEFT */
SDL_SCANCODE_SOFTRIGHT, /* AKEYCODE_SOFT_RIGHT */
SDL_SCANCODE_AC_HOME, /* AKEYCODE_HOME */
SDL_SCANCODE_AC_BACK, /* AKEYCODE_BACK */
SDL_SCANCODE_CALL, /* AKEYCODE_CALL */
SDL_SCANCODE_ENDCALL, /* AKEYCODE_ENDCALL */
SDL_SCANCODE_0, /* AKEYCODE_0 */
SDL_SCANCODE_1, /* AKEYCODE_1 */
SDL_SCANCODE_2, /* AKEYCODE_2 */
SDL_SCANCODE_3, /* AKEYCODE_3 */
SDL_SCANCODE_4, /* AKEYCODE_4 */
SDL_SCANCODE_5, /* AKEYCODE_5 */
SDL_SCANCODE_6, /* AKEYCODE_6 */
SDL_SCANCODE_7, /* AKEYCODE_7 */
SDL_SCANCODE_8, /* AKEYCODE_8 */
SDL_SCANCODE_9, /* AKEYCODE_9 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STAR */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_POUND */
SDL_SCANCODE_UP, /* AKEYCODE_DPAD_UP */
SDL_SCANCODE_DOWN, /* AKEYCODE_DPAD_DOWN */
SDL_SCANCODE_LEFT, /* AKEYCODE_DPAD_LEFT */
SDL_SCANCODE_RIGHT, /* AKEYCODE_DPAD_RIGHT */
SDL_SCANCODE_SELECT, /* AKEYCODE_DPAD_CENTER */
SDL_SCANCODE_VOLUMEUP, /* AKEYCODE_VOLUME_UP */
SDL_SCANCODE_VOLUMEDOWN, /* AKEYCODE_VOLUME_DOWN */
SDL_SCANCODE_POWER, /* AKEYCODE_POWER */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CAMERA */
SDL_SCANCODE_CLEAR, /* AKEYCODE_CLEAR */
SDL_SCANCODE_A, /* AKEYCODE_A */
SDL_SCANCODE_B, /* AKEYCODE_B */
SDL_SCANCODE_C, /* AKEYCODE_C */
SDL_SCANCODE_D, /* AKEYCODE_D */
SDL_SCANCODE_E, /* AKEYCODE_E */
SDL_SCANCODE_F, /* AKEYCODE_F */
SDL_SCANCODE_G, /* AKEYCODE_G */
SDL_SCANCODE_H, /* AKEYCODE_H */
SDL_SCANCODE_I, /* AKEYCODE_I */
SDL_SCANCODE_J, /* AKEYCODE_J */
SDL_SCANCODE_K, /* AKEYCODE_K */
SDL_SCANCODE_L, /* AKEYCODE_L */
SDL_SCANCODE_M, /* AKEYCODE_M */
SDL_SCANCODE_N, /* AKEYCODE_N */
SDL_SCANCODE_O, /* AKEYCODE_O */
SDL_SCANCODE_P, /* AKEYCODE_P */
SDL_SCANCODE_Q, /* AKEYCODE_Q */
SDL_SCANCODE_R, /* AKEYCODE_R */
SDL_SCANCODE_S, /* AKEYCODE_S */
SDL_SCANCODE_T, /* AKEYCODE_T */
SDL_SCANCODE_U, /* AKEYCODE_U */
SDL_SCANCODE_V, /* AKEYCODE_V */
SDL_SCANCODE_W, /* AKEYCODE_W */
SDL_SCANCODE_X, /* AKEYCODE_X */
SDL_SCANCODE_Y, /* AKEYCODE_Y */
SDL_SCANCODE_Z, /* AKEYCODE_Z */
SDL_SCANCODE_COMMA, /* AKEYCODE_COMMA */
SDL_SCANCODE_PERIOD, /* AKEYCODE_PERIOD */
SDL_SCANCODE_LALT, /* AKEYCODE_ALT_LEFT */
SDL_SCANCODE_RALT, /* AKEYCODE_ALT_RIGHT */
SDL_SCANCODE_LSHIFT, /* AKEYCODE_SHIFT_LEFT */
SDL_SCANCODE_RSHIFT, /* AKEYCODE_SHIFT_RIGHT */
SDL_SCANCODE_TAB, /* AKEYCODE_TAB */
SDL_SCANCODE_SPACE, /* AKEYCODE_SPACE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SYM */
SDL_SCANCODE_WWW, /* AKEYCODE_EXPLORER */
SDL_SCANCODE_MAIL, /* AKEYCODE_ENVELOPE */
SDL_SCANCODE_RETURN, /* AKEYCODE_ENTER */
SDL_SCANCODE_BACKSPACE, /* AKEYCODE_DEL */
SDL_SCANCODE_GRAVE, /* AKEYCODE_GRAVE */
SDL_SCANCODE_MINUS, /* AKEYCODE_MINUS */
SDL_SCANCODE_EQUALS, /* AKEYCODE_EQUALS */
SDL_SCANCODE_LEFTBRACKET, /* AKEYCODE_LEFT_BRACKET */
SDL_SCANCODE_RIGHTBRACKET, /* AKEYCODE_RIGHT_BRACKET */
SDL_SCANCODE_BACKSLASH, /* AKEYCODE_BACKSLASH */
SDL_SCANCODE_SEMICOLON, /* AKEYCODE_SEMICOLON */
SDL_SCANCODE_APOSTROPHE, /* AKEYCODE_APOSTROPHE */
SDL_SCANCODE_SLASH, /* AKEYCODE_SLASH */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NUM */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_HEADSETHOOK */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_FOCUS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PLUS */
SDL_SCANCODE_MENU, /* AKEYCODE_MENU */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NOTIFICATION */
SDL_SCANCODE_AC_SEARCH, /* AKEYCODE_SEARCH */
SDL_SCANCODE_AUDIOPLAY, /* AKEYCODE_MEDIA_PLAY_PAUSE */
SDL_SCANCODE_AUDIOSTOP, /* AKEYCODE_MEDIA_STOP */
SDL_SCANCODE_AUDIONEXT, /* AKEYCODE_MEDIA_NEXT */
SDL_SCANCODE_AUDIOPREV, /* AKEYCODE_MEDIA_PREVIOUS */
SDL_SCANCODE_AUDIOREWIND, /* AKEYCODE_MEDIA_REWIND */
SDL_SCANCODE_AUDIOFASTFORWARD, /* AKEYCODE_MEDIA_FAST_FORWARD */
SDL_SCANCODE_MUTE, /* AKEYCODE_MUTE */
SDL_SCANCODE_PAGEUP, /* AKEYCODE_PAGE_UP */
SDL_SCANCODE_PAGEDOWN, /* AKEYCODE_PAGE_DOWN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PICTSYMBOLS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SWITCH_CHARSET */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_A */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_B */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_C */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_X */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Y */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Z */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBL */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBR */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_START */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_SELECT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_MODE */
SDL_SCANCODE_ESCAPE, /* AKEYCODE_ESCAPE */
SDL_SCANCODE_DELETE, /* AKEYCODE_FORWARD_DEL */
SDL_SCANCODE_LCTRL, /* AKEYCODE_CTRL_LEFT */
SDL_SCANCODE_RCTRL, /* AKEYCODE_CTRL_RIGHT */
SDL_SCANCODE_CAPSLOCK, /* AKEYCODE_CAPS_LOCK */
SDL_SCANCODE_SCROLLLOCK, /* AKEYCODE_SCROLL_LOCK */
SDL_SCANCODE_LGUI, /* AKEYCODE_META_LEFT */
SDL_SCANCODE_RGUI, /* AKEYCODE_META_RIGHT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_FUNCTION */
SDL_SCANCODE_PRINTSCREEN, /* AKEYCODE_SYSRQ */
SDL_SCANCODE_PAUSE, /* AKEYCODE_BREAK */
SDL_SCANCODE_HOME, /* AKEYCODE_MOVE_HOME */
SDL_SCANCODE_END, /* AKEYCODE_MOVE_END */
SDL_SCANCODE_INSERT, /* AKEYCODE_INSERT */
SDL_SCANCODE_AC_FORWARD, /* AKEYCODE_FORWARD */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_PLAY */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_PAUSE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_CLOSE */
SDL_SCANCODE_EJECT, /* AKEYCODE_MEDIA_EJECT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_RECORD */
SDL_SCANCODE_F1, /* AKEYCODE_F1 */
SDL_SCANCODE_F2, /* AKEYCODE_F2 */
SDL_SCANCODE_F3, /* AKEYCODE_F3 */
SDL_SCANCODE_F4, /* AKEYCODE_F4 */
SDL_SCANCODE_F5, /* AKEYCODE_F5 */
SDL_SCANCODE_F6, /* AKEYCODE_F6 */
SDL_SCANCODE_F7, /* AKEYCODE_F7 */
SDL_SCANCODE_F8, /* AKEYCODE_F8 */
SDL_SCANCODE_F9, /* AKEYCODE_F9 */
SDL_SCANCODE_F10, /* AKEYCODE_F10 */
SDL_SCANCODE_F11, /* AKEYCODE_F11 */
SDL_SCANCODE_F12, /* AKEYCODE_F12 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NUM_LOCK */
SDL_SCANCODE_KP_0, /* AKEYCODE_NUMPAD_0 */
SDL_SCANCODE_KP_1, /* AKEYCODE_NUMPAD_1 */
SDL_SCANCODE_KP_2, /* AKEYCODE_NUMPAD_2 */
SDL_SCANCODE_KP_3, /* AKEYCODE_NUMPAD_3 */
SDL_SCANCODE_KP_4, /* AKEYCODE_NUMPAD_4 */
SDL_SCANCODE_KP_5, /* AKEYCODE_NUMPAD_5 */
SDL_SCANCODE_KP_6, /* AKEYCODE_NUMPAD_6 */
SDL_SCANCODE_KP_7, /* AKEYCODE_NUMPAD_7 */
SDL_SCANCODE_KP_8, /* AKEYCODE_NUMPAD_8 */
SDL_SCANCODE_KP_9, /* AKEYCODE_NUMPAD_9 */
SDL_SCANCODE_KP_DIVIDE, /* AKEYCODE_NUMPAD_DIVIDE */
SDL_SCANCODE_KP_MULTIPLY, /* AKEYCODE_NUMPAD_MULTIPLY */
SDL_SCANCODE_KP_MINUS, /* AKEYCODE_NUMPAD_SUBTRACT */
SDL_SCANCODE_KP_PLUS, /* AKEYCODE_NUMPAD_ADD */
SDL_SCANCODE_KP_PERIOD, /* AKEYCODE_NUMPAD_DOT */
SDL_SCANCODE_KP_COMMA, /* AKEYCODE_NUMPAD_COMMA */
SDL_SCANCODE_KP_ENTER, /* AKEYCODE_NUMPAD_ENTER */
SDL_SCANCODE_KP_EQUALS, /* AKEYCODE_NUMPAD_EQUALS */
SDL_SCANCODE_KP_LEFTPAREN, /* AKEYCODE_NUMPAD_LEFT_PAREN */
SDL_SCANCODE_KP_RIGHTPAREN, /* AKEYCODE_NUMPAD_RIGHT_PAREN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_VOLUME_MUTE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_INFO */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CHANNEL_UP */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CHANNEL_DOWN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ZOOM_IN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ZOOM_OUT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_WINDOW */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_GUIDE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DVR */
SDL_SCANCODE_AC_BOOKMARKS, /* AKEYCODE_BOOKMARK */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CAPTIONS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SETTINGS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_POWER */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STB_POWER */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STB_INPUT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AVR_POWER */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AVR_INPUT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_RED */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_GREEN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_YELLOW */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_BLUE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_APP_SWITCH */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_3 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_4 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_5 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_6 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_7 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_8 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_9 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_10 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_11 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_12 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_13 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_14 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_15 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_16 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_LANGUAGE_SWITCH */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MANNER_MODE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_3D_MODE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CONTACTS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CALENDAR */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MUSIC */
SDL_SCANCODE_CALCULATOR, /* AKEYCODE_CALCULATOR */
SDL_SCANCODE_LANG5, /* AKEYCODE_ZENKAKU_HANKAKU */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_EISU */
SDL_SCANCODE_INTERNATIONAL5, /* AKEYCODE_MUHENKAN */
SDL_SCANCODE_INTERNATIONAL4, /* AKEYCODE_HENKAN */
SDL_SCANCODE_LANG3, /* AKEYCODE_KATAKANA_HIRAGANA */
SDL_SCANCODE_INTERNATIONAL3, /* AKEYCODE_YEN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_RO */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_KANA */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ASSIST */
SDL_SCANCODE_BRIGHTNESSDOWN, /* AKEYCODE_BRIGHTNESS_DOWN */
SDL_SCANCODE_BRIGHTNESSUP, /* AKEYCODE_BRIGHTNESS_UP */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_AUDIO_TRACK */
SDL_SCANCODE_SLEEP, /* AKEYCODE_SLEEP */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_WAKEUP */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PAIRING */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_TOP_MENU */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_11 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_12 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_LAST_CHANNEL */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_DATA_SERVICE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_VOICE_ASSIST */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_RADIO_SERVICE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TELETEXT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_NUMBER_ENTRY */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TERRESTRIAL_ANALOG */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TERRESTRIAL_DIGITAL */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE_BS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE_CS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE_SERVICE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_NETWORK */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_ANTENNA_CABLE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_3 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_4 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPOSITE_1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPOSITE_2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPONENT_1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPONENT_2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_VGA_1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_AUDIO_DESCRIPTION */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_ZOOM_MODE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_CONTENTS_MENU */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_MEDIA_CONTEXT_MENU */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TIMER_PROGRAMMING */
SDL_SCANCODE_HELP, /* AKEYCODE_HELP */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_PREVIOUS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_NEXT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_IN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_OUT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_PRIMARY */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_3 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_UP_LEFT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_DOWN_LEFT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_UP_RIGHT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_DOWN_RIGHT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_SKIP_FORWARD */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_SKIP_BACKWARD */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_STEP_FORWARD */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_STEP_BACKWARD */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_SLEEP */
SDL_SCANCODE_CUT, /* AKEYCODE_CUT */
SDL_SCANCODE_COPY, /* AKEYCODE_COPY */
SDL_SCANCODE_PASTE, /* AKEYCODE_PASTE */
SDL_SCANCODE_MUTE, /* AKEYCODE_MUTE */
SDL_SCANCODE_PAGEUP, /* AKEYCODE_PAGE_UP */
SDL_SCANCODE_PAGEDOWN, /* AKEYCODE_PAGE_DOWN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PICTSYMBOLS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SWITCH_CHARSET */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_A */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_B */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_C */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_X */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Y */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Z */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBL */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBR */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_START */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_SELECT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_MODE */
SDL_SCANCODE_ESCAPE, /* AKEYCODE_ESCAPE */
SDL_SCANCODE_DELETE, /* AKEYCODE_FORWARD_DEL */
SDL_SCANCODE_LCTRL, /* AKEYCODE_CTRL_LEFT */
SDL_SCANCODE_RCTRL, /* AKEYCODE_CTRL_RIGHT */
SDL_SCANCODE_CAPSLOCK, /* AKEYCODE_CAPS_LOCK */
SDL_SCANCODE_SCROLLLOCK, /* AKEYCODE_SCROLL_LOCK */
SDL_SCANCODE_LGUI, /* AKEYCODE_META_LEFT */
SDL_SCANCODE_RGUI, /* AKEYCODE_META_RIGHT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_FUNCTION */
SDL_SCANCODE_PRINTSCREEN, /* AKEYCODE_SYSRQ */
SDL_SCANCODE_PAUSE, /* AKEYCODE_BREAK */
SDL_SCANCODE_HOME, /* AKEYCODE_MOVE_HOME */
SDL_SCANCODE_END, /* AKEYCODE_MOVE_END */
SDL_SCANCODE_INSERT, /* AKEYCODE_INSERT */
SDL_SCANCODE_AC_FORWARD, /* AKEYCODE_FORWARD */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_PLAY */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_PAUSE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_CLOSE */
SDL_SCANCODE_EJECT, /* AKEYCODE_MEDIA_EJECT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_RECORD */
SDL_SCANCODE_F1, /* AKEYCODE_F1 */
SDL_SCANCODE_F2, /* AKEYCODE_F2 */
SDL_SCANCODE_F3, /* AKEYCODE_F3 */
SDL_SCANCODE_F4, /* AKEYCODE_F4 */
SDL_SCANCODE_F5, /* AKEYCODE_F5 */
SDL_SCANCODE_F6, /* AKEYCODE_F6 */
SDL_SCANCODE_F7, /* AKEYCODE_F7 */
SDL_SCANCODE_F8, /* AKEYCODE_F8 */
SDL_SCANCODE_F9, /* AKEYCODE_F9 */
SDL_SCANCODE_F10, /* AKEYCODE_F10 */
SDL_SCANCODE_F11, /* AKEYCODE_F11 */
SDL_SCANCODE_F12, /* AKEYCODE_F12 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NUM_LOCK */
SDL_SCANCODE_KP_0, /* AKEYCODE_NUMPAD_0 */
SDL_SCANCODE_KP_1, /* AKEYCODE_NUMPAD_1 */
SDL_SCANCODE_KP_2, /* AKEYCODE_NUMPAD_2 */
SDL_SCANCODE_KP_3, /* AKEYCODE_NUMPAD_3 */
SDL_SCANCODE_KP_4, /* AKEYCODE_NUMPAD_4 */
SDL_SCANCODE_KP_5, /* AKEYCODE_NUMPAD_5 */
SDL_SCANCODE_KP_6, /* AKEYCODE_NUMPAD_6 */
SDL_SCANCODE_KP_7, /* AKEYCODE_NUMPAD_7 */
SDL_SCANCODE_KP_8, /* AKEYCODE_NUMPAD_8 */
SDL_SCANCODE_KP_9, /* AKEYCODE_NUMPAD_9 */
SDL_SCANCODE_KP_DIVIDE, /* AKEYCODE_NUMPAD_DIVIDE */
SDL_SCANCODE_KP_MULTIPLY, /* AKEYCODE_NUMPAD_MULTIPLY */
SDL_SCANCODE_KP_MINUS, /* AKEYCODE_NUMPAD_SUBTRACT */
SDL_SCANCODE_KP_PLUS, /* AKEYCODE_NUMPAD_ADD */
SDL_SCANCODE_KP_PERIOD, /* AKEYCODE_NUMPAD_DOT */
SDL_SCANCODE_KP_COMMA, /* AKEYCODE_NUMPAD_COMMA */
SDL_SCANCODE_KP_ENTER, /* AKEYCODE_NUMPAD_ENTER */
SDL_SCANCODE_KP_EQUALS, /* AKEYCODE_NUMPAD_EQUALS */
SDL_SCANCODE_KP_LEFTPAREN, /* AKEYCODE_NUMPAD_LEFT_PAREN */
SDL_SCANCODE_KP_RIGHTPAREN, /* AKEYCODE_NUMPAD_RIGHT_PAREN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_VOLUME_MUTE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_INFO */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CHANNEL_UP */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CHANNEL_DOWN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ZOOM_IN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ZOOM_OUT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_WINDOW */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_GUIDE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DVR */
SDL_SCANCODE_AC_BOOKMARKS, /* AKEYCODE_BOOKMARK */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CAPTIONS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SETTINGS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_POWER */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STB_POWER */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STB_INPUT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AVR_POWER */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AVR_INPUT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_RED */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_GREEN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_YELLOW */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_BLUE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_APP_SWITCH */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_3 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_4 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_5 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_6 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_7 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_8 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_9 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_10 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_11 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_12 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_13 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_14 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_15 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_16 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_LANGUAGE_SWITCH */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MANNER_MODE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_3D_MODE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CONTACTS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CALENDAR */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MUSIC */
SDL_SCANCODE_CALCULATOR, /* AKEYCODE_CALCULATOR */
SDL_SCANCODE_LANG5, /* AKEYCODE_ZENKAKU_HANKAKU */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_EISU */
SDL_SCANCODE_INTERNATIONAL5, /* AKEYCODE_MUHENKAN */
SDL_SCANCODE_INTERNATIONAL4, /* AKEYCODE_HENKAN */
SDL_SCANCODE_LANG3, /* AKEYCODE_KATAKANA_HIRAGANA */
SDL_SCANCODE_INTERNATIONAL3, /* AKEYCODE_YEN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_RO */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_KANA */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ASSIST */
SDL_SCANCODE_BRIGHTNESSDOWN, /* AKEYCODE_BRIGHTNESS_DOWN */
SDL_SCANCODE_BRIGHTNESSUP, /* AKEYCODE_BRIGHTNESS_UP */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_AUDIO_TRACK */
SDL_SCANCODE_SLEEP, /* AKEYCODE_SLEEP */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_WAKEUP */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PAIRING */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_TOP_MENU */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_11 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_12 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_LAST_CHANNEL */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_DATA_SERVICE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_VOICE_ASSIST */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_RADIO_SERVICE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TELETEXT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_NUMBER_ENTRY */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TERRESTRIAL_ANALOG */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TERRESTRIAL_DIGITAL */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE_BS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE_CS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE_SERVICE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_NETWORK */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_ANTENNA_CABLE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_3 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_4 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPOSITE_1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPOSITE_2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPONENT_1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPONENT_2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_VGA_1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_AUDIO_DESCRIPTION */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_ZOOM_MODE */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_CONTENTS_MENU */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_MEDIA_CONTEXT_MENU */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TIMER_PROGRAMMING */
SDL_SCANCODE_HELP, /* AKEYCODE_HELP */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_PREVIOUS */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_NEXT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_IN */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_OUT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_PRIMARY */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_1 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_2 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_3 */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_UP_LEFT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_DOWN_LEFT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_UP_RIGHT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_DOWN_RIGHT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_SKIP_FORWARD */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_SKIP_BACKWARD */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_STEP_FORWARD */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_STEP_BACKWARD */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_SLEEP */
SDL_SCANCODE_CUT, /* AKEYCODE_CUT */
SDL_SCANCODE_COPY, /* AKEYCODE_COPY */
SDL_SCANCODE_PASTE, /* AKEYCODE_PASTE */
};
static SDL_Scancode
TranslateKeycode(int keycode)
static SDL_Scancode TranslateKeycode(int keycode)
{
SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
@ -336,49 +326,42 @@ TranslateKeycode(int keycode)
return scancode;
}
int
Android_OnKeyDown(int keycode)
int Android_OnKeyDown(int keycode)
{
return SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode(keycode));
}
int
Android_OnKeyUp(int keycode)
int Android_OnKeyUp(int keycode)
{
return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode));
}
SDL_bool
Android_HasScreenKeyboardSupport(_THIS)
SDL_bool Android_HasScreenKeyboardSupport(_THIS)
{
return SDL_TRUE;
}
SDL_bool
Android_IsScreenKeyboardShown(_THIS, SDL_Window * window)
SDL_bool Android_IsScreenKeyboardShown(_THIS, SDL_Window *window)
{
return Android_JNI_IsScreenKeyboardShown();
}
void
Android_StartTextInput(_THIS)
void Android_StartTextInput(_THIS)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
Android_JNI_ShowTextInput(&videodata->textRect);
}
void
Android_StopTextInput(_THIS)
void Android_StopTextInput(_THIS)
{
Android_JNI_HideTextInput();
}
void
Android_SetTextInputRect(_THIS, SDL_Rect *rect)
void Android_SetTextInputRect(_THIS, const SDL_Rect *rect)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
if (!rect) {
if (rect == NULL) {
SDL_InvalidParamError("rect");
return;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,15 +22,14 @@
#include "SDL_androidvideo.h"
extern void Android_InitKeyboard(void);
extern int Android_OnKeyDown(int keycode);
extern int Android_OnKeyUp(int keycode);
extern SDL_bool Android_HasScreenKeyboardSupport(_THIS);
extern SDL_bool Android_IsScreenKeyboardShown(_THIS, SDL_Window * window);
extern SDL_bool Android_IsScreenKeyboardShown(_THIS, SDL_Window *window);
extern void Android_StartTextInput(_THIS);
extern void Android_StopTextInput(_THIS);
extern void Android_SetTextInputRect(_THIS, SDL_Rect *rect);
extern void Android_SetTextInputRect(_THIS, const SDL_Rect *rect);
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,8 +26,7 @@
#include "SDL_androidmessagebox.h"
#include "../../core/android/SDL_android.h"
int
Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
int Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
{
return Android_JNI_ShowMessageBox(messageboxdata, buttonid);
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -31,16 +31,16 @@
#include "../../core/android/SDL_android.h"
/* See Android's MotionEvent class for constants */
#define ACTION_DOWN 0
#define ACTION_UP 1
#define ACTION_MOVE 2
#define ACTION_DOWN 0
#define ACTION_UP 1
#define ACTION_MOVE 2
#define ACTION_HOVER_MOVE 7
#define ACTION_SCROLL 8
#define BUTTON_PRIMARY 1
#define BUTTON_SECONDARY 2
#define BUTTON_TERTIARY 4
#define BUTTON_BACK 8
#define BUTTON_FORWARD 16
#define ACTION_SCROLL 8
#define BUTTON_PRIMARY 1
#define BUTTON_SECONDARY 2
#define BUTTON_TERTIARY 4
#define BUTTON_BACK 8
#define BUTTON_FORWARD 16
typedef struct
{
@ -55,8 +55,7 @@ static int last_state;
/* Blank cursor */
static SDL_Cursor *empty_cursor;
static SDL_Cursor *
Android_WrapCursor(int custom_cursor, int system_cursor)
static SDL_Cursor *Android_WrapCursor(int custom_cursor, int system_cursor)
{
SDL_Cursor *cursor;
@ -79,20 +78,18 @@ Android_WrapCursor(int custom_cursor, int system_cursor)
return cursor;
}
static SDL_Cursor *
Android_CreateDefaultCursor()
static SDL_Cursor *Android_CreateDefaultCursor()
{
return Android_WrapCursor(0, SDL_SYSTEM_CURSOR_ARROW);
}
static SDL_Cursor *
Android_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
static SDL_Cursor *Android_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
{
int custom_cursor;
SDL_Surface *converted;
converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0);
if (!converted) {
if (converted == NULL) {
return NULL;
}
custom_cursor = Android_JNI_CreateCustomCursor(converted, hot_x, hot_y);
@ -104,16 +101,14 @@ Android_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
return Android_WrapCursor(custom_cursor, 0);
}
static SDL_Cursor *
Android_CreateSystemCursor(SDL_SystemCursor id)
static SDL_Cursor *Android_CreateSystemCursor(SDL_SystemCursor id)
{
return Android_WrapCursor(0, id);
}
static void
Android_FreeCursor(SDL_Cursor * cursor)
static void Android_FreeCursor(SDL_Cursor *cursor)
{
SDL_AndroidCursorData *data = (SDL_AndroidCursorData*) cursor->driverdata;
SDL_AndroidCursorData *data = (SDL_AndroidCursorData *)cursor->driverdata;
if (data->custom_cursor != 0) {
Android_JNI_DestroyCustomCursor(data->custom_cursor);
}
@ -121,13 +116,12 @@ Android_FreeCursor(SDL_Cursor * cursor)
SDL_free(cursor);
}
static SDL_Cursor *
Android_CreateEmptyCursor()
static SDL_Cursor *Android_CreateEmptyCursor()
{
if (!empty_cursor) {
if (empty_cursor == NULL) {
SDL_Surface *empty_surface = SDL_CreateRGBSurfaceWithFormat(0, 1, 1, 32, SDL_PIXELFORMAT_ARGB8888);
if (empty_surface) {
SDL_memset(empty_surface->pixels, 0, empty_surface->h * empty_surface->pitch);
SDL_memset(empty_surface->pixels, 0, (size_t)empty_surface->h * empty_surface->pitch);
empty_cursor = Android_CreateCursor(empty_surface, 0, 0);
SDL_FreeSurface(empty_surface);
}
@ -135,8 +129,7 @@ Android_CreateEmptyCursor()
return empty_cursor;
}
static void
Android_DestroyEmptyCursor()
static void Android_DestroyEmptyCursor()
{
if (empty_cursor) {
Android_FreeCursor(empty_cursor);
@ -144,10 +137,9 @@ Android_DestroyEmptyCursor()
}
}
static int
Android_ShowCursor(SDL_Cursor *cursor)
static int Android_ShowCursor(SDL_Cursor *cursor)
{
if (!cursor) {
if (cursor == NULL) {
cursor = Android_CreateEmptyCursor();
}
if (cursor) {
@ -168,8 +160,7 @@ Android_ShowCursor(SDL_Cursor *cursor)
}
}
static int
Android_SetRelativeMouseMode(SDL_bool enabled)
static int Android_SetRelativeMouseMode(SDL_bool enabled)
{
if (!Android_JNI_SupportsRelativeMouse()) {
return SDL_Unsupported();
@ -182,8 +173,7 @@ Android_SetRelativeMouseMode(SDL_bool enabled)
return 0;
}
void
Android_InitMouse(void)
void Android_InitMouse(void)
{
SDL_Mouse *mouse = SDL_GetMouse();
@ -198,15 +188,13 @@ Android_InitMouse(void)
last_state = 0;
}
void
Android_QuitMouse(void)
void Android_QuitMouse(void)
{
Android_DestroyEmptyCursor();
}
/* Translate Android mouse button state to SDL mouse button */
static Uint8
TranslateButton(int state)
static Uint8 TranslateButton(int state)
{
if (state & BUTTON_PRIMARY) {
return SDL_BUTTON_LEFT;
@ -223,48 +211,46 @@ TranslateButton(int state)
}
}
void
Android_OnMouse(SDL_Window *window, int state, int action, float x, float y, SDL_bool relative)
void Android_OnMouse(SDL_Window *window, int state, int action, float x, float y, SDL_bool relative)
{
int changes;
Uint8 button;
if (!window) {
if (window == NULL) {
return;
}
switch(action) {
case ACTION_DOWN:
changes = state & ~last_state;
button = TranslateButton(changes);
last_state = state;
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
break;
switch (action) {
case ACTION_DOWN:
changes = state & ~last_state;
button = TranslateButton(changes);
last_state = state;
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
break;
case ACTION_UP:
changes = last_state & ~state;
button = TranslateButton(changes);
last_state = state;
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
break;
case ACTION_UP:
changes = last_state & ~state;
button = TranslateButton(changes);
last_state = state;
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
break;
case ACTION_MOVE:
case ACTION_HOVER_MOVE:
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
break;
case ACTION_MOVE:
case ACTION_HOVER_MOVE:
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
break;
case ACTION_SCROLL:
SDL_SendMouseWheel(window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
break;
case ACTION_SCROLL:
SDL_SendMouseWheel(window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
break;
default:
break;
default:
break;
}
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -32,12 +32,12 @@
#include "../../core/android/SDL_android.h"
#define ACTION_DOWN 0
#define ACTION_UP 1
#define ACTION_UP 1
#define ACTION_MOVE 2
/* #define ACTION_CANCEL 3 */
/* #define ACTION_OUTSIDE 4 */
#define ACTION_POINTER_DOWN 5
#define ACTION_POINTER_UP 6
#define ACTION_POINTER_UP 6
void Android_InitTouch(void)
{
@ -54,7 +54,7 @@ void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_fin
SDL_TouchID touchDeviceId = 0;
SDL_FingerID fingerId = 0;
if (!window) {
if (window == NULL) {
return;
}
@ -65,22 +65,22 @@ void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_fin
fingerId = (SDL_FingerID)pointer_finger_id_in;
switch (action) {
case ACTION_DOWN:
case ACTION_POINTER_DOWN:
SDL_SendTouch(touchDeviceId, fingerId, window, SDL_TRUE, x, y, p);
break;
case ACTION_DOWN:
case ACTION_POINTER_DOWN:
SDL_SendTouch(touchDeviceId, fingerId, window, SDL_TRUE, x, y, p);
break;
case ACTION_MOVE:
SDL_SendTouchMotion(touchDeviceId, fingerId, window, x, y, p);
break;
case ACTION_MOVE:
SDL_SendTouchMotion(touchDeviceId, fingerId, window, x, y, p);
break;
case ACTION_UP:
case ACTION_POINTER_UP:
SDL_SendTouch(touchDeviceId, fingerId, window, SDL_FALSE, x, y, p);
break;
case ACTION_UP:
case ACTION_POINTER_UP:
SDL_SendTouch(touchDeviceId, fingerId, window, SDL_FALSE, x, y, p);
break;
default:
break;
default:
break;
}
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -54,51 +54,47 @@ int Android_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *
#define Android_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
#define Android_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
#define Android_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
#define Android_GLES_DeleteContext SDL_EGL_DeleteContext
#define Android_GLES_DeleteContext SDL_EGL_DeleteContext
/* Android driver bootstrap functions */
/* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
int Android_SurfaceWidth = 0;
int Android_SurfaceHeight = 0;
static int Android_DeviceWidth = 0;
static int Android_DeviceHeight = 0;
int Android_SurfaceWidth = 0;
int Android_SurfaceHeight = 0;
static int Android_DeviceWidth = 0;
static int Android_DeviceHeight = 0;
static Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_RGB565; /* Default SurfaceView format, in case this is queried before being filled */
static int Android_ScreenRate = 0;
SDL_sem *Android_PauseSem = NULL;
SDL_sem *Android_ResumeSem = NULL;
SDL_mutex *Android_ActivityMutex = NULL;
static int Android_ScreenRate = 0;
SDL_sem *Android_PauseSem = NULL;
SDL_sem *Android_ResumeSem = NULL;
SDL_mutex *Android_ActivityMutex = NULL;
static void
Android_SuspendScreenSaver(_THIS)
static void Android_SuspendScreenSaver(_THIS)
{
Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
}
static void
Android_DeleteDevice(SDL_VideoDevice *device)
static void Android_DeleteDevice(SDL_VideoDevice *device)
{
SDL_free(device->driverdata);
SDL_free(device);
}
static SDL_VideoDevice *
Android_CreateDevice(int devindex)
static SDL_VideoDevice *Android_CreateDevice(void)
{
SDL_VideoDevice *device;
SDL_VideoData *data;
SDL_bool block_on_pause;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (!device) {
device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
if (device == NULL) {
SDL_OutOfMemory();
return NULL;
}
data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
if (!data) {
data = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData));
if (data == NULL) {
SDL_OutOfMemory();
SDL_free(device);
return NULL;
@ -173,24 +169,22 @@ VideoBootStrap Android_bootstrap = {
Android_CreateDevice
};
int
Android_VideoInit(_THIS)
int Android_VideoInit(_THIS)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
int display_index;
SDL_VideoDisplay *display;
SDL_DisplayMode mode;
videodata->isPaused = SDL_FALSE;
videodata->isPaused = SDL_FALSE;
videodata->isPausing = SDL_FALSE;
videodata->pauseAudio = SDL_GetHintBoolean(SDL_HINT_ANDROID_BLOCK_ON_PAUSE_PAUSEAUDIO, SDL_TRUE);
mode.format = Android_ScreenFormat;
mode.w = Android_DeviceWidth;
mode.h = Android_DeviceHeight;
mode.refresh_rate = Android_ScreenRate;
mode.driverdata = NULL;
mode.format = Android_ScreenFormat;
mode.w = Android_DeviceWidth;
mode.h = Android_DeviceHeight;
mode.refresh_rate = Android_ScreenRate;
mode.driverdata = NULL;
display_index = SDL_AddBasicVideoDisplay(&mode);
if (display_index < 0) {
@ -201,8 +195,6 @@ Android_VideoInit(_THIS)
SDL_AddDisplayMode(&_this->displays[0], &mode);
Android_InitKeyboard();
Android_InitTouch();
Android_InitMouse();
@ -211,33 +203,30 @@ Android_VideoInit(_THIS)
return 0;
}
void
Android_VideoQuit(_THIS)
void Android_VideoQuit(_THIS)
{
Android_QuitMouse();
Android_QuitTouch();
}
int
Android_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi)
int Android_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi)
{
return Android_JNI_GetDisplayDPI(ddpi, hdpi, vdpi);
}
void
Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, float rate)
void Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, float rate)
{
Android_SurfaceWidth = surfaceWidth;
Android_SurfaceWidth = surfaceWidth;
Android_SurfaceHeight = surfaceHeight;
Android_DeviceWidth = deviceWidth;
Android_DeviceHeight = deviceHeight;
Android_ScreenRate = (int)rate;
Android_DeviceWidth = deviceWidth;
Android_DeviceHeight = deviceHeight;
Android_ScreenRate = (int)rate;
}
static
Uint32 format_to_pixelFormat(int format) {
static Uint32 format_to_pixelFormat(int format)
{
Uint32 pf;
if (format == AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM) { /* 1 */
if (format == AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM) { /* 1 */
pf = SDL_PIXELFORMAT_RGBA8888;
} else if (format == AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM) { /* 2 */
pf = SDL_PIXELFORMAT_RGBX8888;
@ -251,14 +240,16 @@ Uint32 format_to_pixelFormat(int format) {
pf = SDL_PIXELFORMAT_RGBA5551;
} else if (format == 7) {
pf = SDL_PIXELFORMAT_RGBA4444;
} else if (format == 0x115) {
/* HAL_PIXEL_FORMAT_BGR_565 */
pf = SDL_PIXELFORMAT_RGB565;
} else {
pf = SDL_PIXELFORMAT_UNKNOWN;
}
return pf;
}
void
Android_SetFormat(int format_wanted, int format_got)
void Android_SetFormat(int format_wanted, int format_got)
{
Uint32 pf_wanted;
Uint32 pf_got;
@ -282,24 +273,23 @@ void Android_SendResize(SDL_Window *window)
which can happen after VideoInit().
*/
SDL_VideoDevice *device = SDL_GetVideoDevice();
if (device && device->num_displays > 0)
{
SDL_VideoDisplay *display = &device->displays[0];
display->desktop_mode.format = Android_ScreenFormat;
display->desktop_mode.w = Android_DeviceWidth;
display->desktop_mode.h = Android_DeviceHeight;
if (device && device->num_displays > 0) {
SDL_VideoDisplay *display = &device->displays[0];
display->desktop_mode.format = Android_ScreenFormat;
display->desktop_mode.w = Android_DeviceWidth;
display->desktop_mode.h = Android_DeviceHeight;
display->desktop_mode.refresh_rate = Android_ScreenRate;
}
if (window) {
/* Force the current mode to match the resize otherwise the SDL_WINDOWEVENT_RESTORED event
* will fall back to the old mode */
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
display->display_modes[0].format = Android_ScreenFormat;
display->display_modes[0].w = Android_DeviceWidth;
display->display_modes[0].h = Android_DeviceHeight;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
display->display_modes[0].format = Android_ScreenFormat;
display->display_modes[0].w = Android_DeviceWidth;
display->display_modes[0].h = Android_DeviceHeight;
display->display_modes[0].refresh_rate = Android_ScreenRate;
display->current_mode = display->display_modes[0];
display->current_mode = display->display_modes[0];
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, Android_SurfaceWidth, Android_SurfaceHeight);
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -37,9 +37,9 @@ extern void Android_SendResize(SDL_Window *window);
typedef struct SDL_VideoData
{
SDL_Rect textRect;
int isPaused;
int isPausing;
int pauseAudio;
int isPaused;
int isPausing;
int pauseAudio;
} SDL_VideoData;
extern int Android_SurfaceWidth;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -42,53 +42,55 @@ int Android_Vulkan_LoadLibrary(_THIS, const char *path)
SDL_bool hasSurfaceExtension = SDL_FALSE;
SDL_bool hasAndroidSurfaceExtension = SDL_FALSE;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
if(_this->vulkan_config.loader_handle)
if (_this->vulkan_config.loader_handle) {
return SDL_SetError("Vulkan already loaded");
}
/* Load the Vulkan loader library */
if(!path)
if (path == NULL) {
path = SDL_getenv("SDL_VULKAN_LIBRARY");
if(!path)
}
if (path == NULL) {
path = "libvulkan.so";
}
_this->vulkan_config.loader_handle = SDL_LoadObject(path);
if(!_this->vulkan_config.loader_handle)
if (!_this->vulkan_config.loader_handle) {
return -1;
}
SDL_strlcpy(_this->vulkan_config.loader_path, path,
SDL_arraysize(_this->vulkan_config.loader_path));
vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
_this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
if(!vkGetInstanceProcAddr)
if (!vkGetInstanceProcAddr) {
goto fail;
}
_this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
_this->vulkan_config.vkEnumerateInstanceExtensionProperties =
(void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties)
if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) {
goto fail;
}
extensions = SDL_Vulkan_CreateInstanceExtensionsList(
(PFN_vkEnumerateInstanceExtensionProperties)
_this->vulkan_config.vkEnumerateInstanceExtensionProperties,
&extensionCount);
if(!extensions)
if (extensions == NULL) {
goto fail;
for(i = 0; i < extensionCount; i++)
{
if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
}
for (i = 0; i < extensionCount; i++) {
if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
hasSurfaceExtension = SDL_TRUE;
else if(SDL_strcmp(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
} else if (SDL_strcmp(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
hasAndroidSurfaceExtension = SDL_TRUE;
}
}
SDL_free(extensions);
if(!hasSurfaceExtension)
{
SDL_SetError("Installed Vulkan doesn't implement the "
VK_KHR_SURFACE_EXTENSION_NAME " extension");
if (!hasSurfaceExtension) {
SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_SURFACE_EXTENSION_NAME " extension");
goto fail;
}
else if(!hasAndroidSurfaceExtension)
{
SDL_SetError("Installed Vulkan doesn't implement the "
VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "extension");
} else if (!hasAndroidSurfaceExtension) {
SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "extension");
goto fail;
}
return 0;
@ -101,54 +103,50 @@ fail:
void Android_Vulkan_UnloadLibrary(_THIS)
{
if(_this->vulkan_config.loader_handle)
{
if (_this->vulkan_config.loader_handle) {
SDL_UnloadObject(_this->vulkan_config.loader_handle);
_this->vulkan_config.loader_handle = NULL;
}
}
SDL_bool Android_Vulkan_GetInstanceExtensions(_THIS,
SDL_Window *window,
unsigned *count,
const char **names)
SDL_Window *window,
unsigned *count,
const char **names)
{
static const char *const extensionsForAndroid[] = {
VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_ANDROID_SURFACE_EXTENSION_NAME
};
if(!_this->vulkan_config.loader_handle)
{
if (!_this->vulkan_config.loader_handle) {
SDL_SetError("Vulkan is not loaded");
return SDL_FALSE;
}
return SDL_Vulkan_GetInstanceExtensions_Helper(
count, names, SDL_arraysize(extensionsForAndroid),
extensionsForAndroid);
count, names, SDL_arraysize(extensionsForAndroid),
extensionsForAndroid);
}
SDL_bool Android_Vulkan_CreateSurface(_THIS,
SDL_Window *window,
VkInstance instance,
VkSurfaceKHR *surface)
SDL_Window *window,
VkInstance instance,
VkSurfaceKHR *surface)
{
SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
(PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr;
PFN_vkCreateAndroidSurfaceKHR vkCreateAndroidSurfaceKHR =
(PFN_vkCreateAndroidSurfaceKHR)vkGetInstanceProcAddr(
instance,
"vkCreateAndroidSurfaceKHR");
instance,
"vkCreateAndroidSurfaceKHR");
VkAndroidSurfaceCreateInfoKHR createInfo;
VkResult result;
if(!_this->vulkan_config.loader_handle)
{
if (!_this->vulkan_config.loader_handle) {
SDL_SetError("Vulkan is not loaded");
return SDL_FALSE;
}
if(!vkCreateAndroidSurfaceKHR)
{
if (!vkCreateAndroidSurfaceKHR) {
SDL_SetError(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME
" extension is not enabled in the Vulkan instance.");
return SDL_FALSE;
@ -160,8 +158,7 @@ SDL_bool Android_Vulkan_CreateSurface(_THIS,
createInfo.window = windowData->native_window;
result = vkCreateAndroidSurfaceKHR(instance, &createInfo,
NULL, surface);
if(result != VK_SUCCESS)
{
if (result != VK_SUCCESS) {
SDL_SetError("vkCreateAndroidSurfaceKHR failed: %s",
SDL_Vulkan_GetResultString(result));
return SDL_FALSE;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -37,13 +37,13 @@
int Android_Vulkan_LoadLibrary(_THIS, const char *path);
void Android_Vulkan_UnloadLibrary(_THIS);
SDL_bool Android_Vulkan_GetInstanceExtensions(_THIS,
SDL_Window *window,
unsigned *count,
const char **names);
SDL_Window *window,
unsigned *count,
const char **names);
SDL_bool Android_Vulkan_CreateSurface(_THIS,
SDL_Window *window,
VkInstance instance,
VkSurfaceKHR *surface);
SDL_Window *window,
VkInstance instance,
VkSurfaceKHR *surface);
#endif

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -36,8 +36,7 @@
/* Currently only one window */
SDL_Window *Android_Window = NULL;
int
Android_CreateWindow(_THIS, SDL_Window * window)
int Android_CreateWindow(_THIS, SDL_Window *window)
{
SDL_WindowData *data;
int retval = 0;
@ -59,14 +58,14 @@ Android_CreateWindow(_THIS, SDL_Window * window)
window->h = Android_SurfaceHeight;
window->flags &= ~SDL_WINDOW_HIDDEN;
window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */
window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */
/* One window, it always has focus */
SDL_SetMouseFocus(window);
SDL_SetKeyboardFocus(window);
data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
if (!data) {
data = (SDL_WindowData *)SDL_calloc(1, sizeof(*data));
if (data == NULL) {
retval = SDL_OutOfMemory();
goto endfunction;
}
@ -82,8 +81,8 @@ Android_CreateWindow(_THIS, SDL_Window * window)
/* Do not create EGLSurface for Vulkan window since it will then make the window
incompatible with vkCreateAndroidSurfaceKHR */
#if SDL_VIDEO_OPENGL_EGL
if ((window->flags & SDL_WINDOW_OPENGL) != 0) {
data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
if (window->flags & SDL_WINDOW_OPENGL) {
data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)data->native_window);
if (data->egl_surface == EGL_NO_SURFACE) {
ANativeWindow_release(data->native_window);
@ -104,18 +103,18 @@ endfunction:
return retval;
}
void
Android_SetWindowTitle(_THIS, SDL_Window *window)
void Android_SetWindowTitle(_THIS, SDL_Window *window)
{
Android_JNI_SetActivityTitle(window->title);
}
void
Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
void Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
{
SDL_LockMutex(Android_ActivityMutex);
if (window == Android_Window) {
SDL_WindowData *data;
int old_w, old_h, new_w, new_h;
/* If the window is being destroyed don't change visible state */
if (!window->is_destroying) {
@ -132,20 +131,19 @@ Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display
goto endfunction;
}
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
if (!data || !data->native_window) {
data = (SDL_WindowData *)window->driverdata;
if (data == NULL || !data->native_window) {
if (data && !data->native_window) {
SDL_SetError("Missing native window");
}
goto endfunction;
}
int old_w = window->w;
int old_h = window->h;
old_w = window->w;
old_h = window->h;
int new_w = ANativeWindow_getWidth(data->native_window);
int new_h = ANativeWindow_getHeight(data->native_window);
new_w = ANativeWindow_getWidth(data->native_window);
new_h = ANativeWindow_getHeight(data->native_window);
if (new_w < 0 || new_h < 0) {
SDL_SetError("ANativeWindow_getWidth/Height() fails");
@ -161,8 +159,7 @@ endfunction:
SDL_UnlockMutex(Android_ActivityMutex);
}
void
Android_MinimizeWindow(_THIS, SDL_Window *window)
void Android_MinimizeWindow(_THIS, SDL_Window *window)
{
Android_JNI_MinizeWindow();
}
@ -173,8 +170,7 @@ void Android_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
Android_JNI_SetOrientation(window->w, window->h, window->flags & SDL_WINDOW_RESIZABLE, SDL_GetHint(SDL_HINT_ORIENTATIONS));
}
void
Android_DestroyWindow(_THIS, SDL_Window *window)
void Android_DestroyWindow(_THIS, SDL_Window *window)
{
SDL_LockMutex(Android_ActivityMutex);
@ -182,7 +178,7 @@ Android_DestroyWindow(_THIS, SDL_Window *window)
Android_Window = NULL;
if (window->driverdata) {
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
#if SDL_VIDEO_OPENGL_EGL
if (data->egl_surface != EGL_NO_SURFACE) {
@ -201,13 +197,11 @@ Android_DestroyWindow(_THIS, SDL_Window *window)
SDL_UnlockMutex(Android_ActivityMutex);
}
SDL_bool
Android_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
if (info->version.major == SDL_MAJOR_VERSION &&
info->version.minor == SDL_MINOR_VERSION) {
if (info->version.major == SDL_MAJOR_VERSION) {
info->subsystem = SDL_SYSWM_ANDROID;
info->info.android.window = data->native_window;
@ -217,8 +211,8 @@ Android_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
return SDL_TRUE;
} else {
SDL_SetError("Application not compiled with SDL %d.%d",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
SDL_SetError("Application not compiled with SDL %d",
SDL_MAJOR_VERSION);
return SDL_FALSE;
}
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -42,9 +42,9 @@ typedef struct
EGLSurface egl_surface;
EGLContext egl_context; /* We use this to preserve the context when losing focus */
#endif
SDL_bool backup_done;
SDL_bool backup_done;
ANativeWindow *native_window;
} SDL_WindowData;
#endif /* SDL_androidwindow_h_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -25,8 +25,7 @@
#include "SDL_cocoavideo.h"
#include "../../events/SDL_clipboardevents_c.h"
int
Cocoa_SetClipboardText(_THIS, const char *text)
int Cocoa_SetClipboardText(_THIS, const char *text)
{ @autoreleasepool
{
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
@ -44,8 +43,7 @@ Cocoa_SetClipboardText(_THIS, const char *text)
return 0;
}}
char *
Cocoa_GetClipboardText(_THIS)
char *Cocoa_GetClipboardText(_THIS)
{ @autoreleasepool
{
NSPasteboard *pasteboard;
@ -73,8 +71,7 @@ Cocoa_GetClipboardText(_THIS)
return text;
}}
SDL_bool
Cocoa_HasClipboardText(_THIS)
SDL_bool Cocoa_HasClipboardText(_THIS)
{
SDL_bool result = SDL_FALSE;
char *text = Cocoa_GetClipboardText(_this);
@ -85,8 +82,7 @@ Cocoa_HasClipboardText(_THIS)
return result;
}
void
Cocoa_CheckClipboardUpdate(SDL_VideoData * data)
void Cocoa_CheckClipboardUpdate(SDL_VideoData * data)
{ @autoreleasepool
{
NSPasteboard *pasteboard;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -46,8 +46,9 @@ static SDL_Window *FindSDLWindowForNSWindow(NSWindow *win)
if (device && device->windows) {
for (sdlwindow = device->windows; sdlwindow; sdlwindow = sdlwindow->next) {
NSWindow *nswindow = ((__bridge SDL_WindowData *) sdlwindow->driverdata).nswindow;
if (win == nswindow)
if (win == nswindow) {
return sdlwindow;
}
}
}
@ -192,8 +193,9 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
}
/* Don't do anything if this was not an SDL window that was closed */
if (FindSDLWindowForNSWindow(win) == NULL)
if (FindSDLWindowForNSWindow(win) == NULL) {
return;
}
/* HACK: Make the next window in the z-order key when the key window is
* closed. The custom event loop and/or windowing code we have seems to
@ -229,6 +231,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
- (void)focusSomeWindow:(NSNotification *)aNotification
{
SDL_VideoDevice *device;
/* HACK: Ignore the first call. The application gets a
* applicationDidBecomeActive: a little bit after the first window is
* created, and if we don't ignore it, a window that has been created with
@ -246,7 +249,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
return;
}
SDL_VideoDevice *device = SDL_GetVideoDevice();
device = SDL_GetVideoDevice();
if (device && device->windows) {
SDL_Window *window = device->windows;
int i;
@ -311,8 +314,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
static SDLAppDelegate *appDelegate = nil;
static NSString *
GetApplicationName(void)
static NSString *GetApplicationName(void)
{
NSString *appName;
@ -329,9 +331,9 @@ GetApplicationName(void)
return appName;
}
static bool
LoadMainMenuNibIfAvailable(void)
static bool LoadMainMenuNibIfAvailable(void)
{
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
NSDictionary *infoDict;
NSString *mainNibFileName;
bool success = false;
@ -342,17 +344,19 @@ LoadMainMenuNibIfAvailable(void)
infoDict = [[NSBundle mainBundle] infoDictionary];
if (infoDict) {
mainNibFileName = [infoDict valueForKey:@"NSMainNibFile"];
if (mainNibFileName) {
success = [[NSBundle mainBundle] loadNibNamed:mainNibFileName owner:[NSApplication sharedApplication] topLevelObjects:nil];
}
}
return success;
#else
return false;
#endif
}
static void
CreateApplicationMenus(void)
static void CreateApplicationMenus(void)
{
NSString *appName;
NSString *title;
@ -365,7 +369,7 @@ CreateApplicationMenus(void)
if (NSApp == nil) {
return;
}
mainMenu = [[NSMenu alloc] init];
/* Create the main menu bar */
@ -386,7 +390,7 @@ CreateApplicationMenus(void)
[appleMenu addItem:[NSMenuItem separatorItem]];
serviceMenu = [[NSMenu alloc] initWithTitle:@""];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
menuItem = [appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
[menuItem setSubmenu:serviceMenu];
[NSApp setServicesMenu:serviceMenu];
@ -423,7 +427,7 @@ CreateApplicationMenus(void)
[windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
[windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
/* Add the fullscreen toggle menu option. */
/* Cocoa should update the title to Enter or Exit Full Screen automatically.
* But if not, then just fallback to Toggle Full Screen.
@ -441,8 +445,7 @@ CreateApplicationMenus(void)
[NSApp setWindowsMenu:windowMenu];
}
void
Cocoa_RegisterApp(void)
void Cocoa_RegisterApp(void)
{ @autoreleasepool
{
/* This can get called more than once! Be careful what you initialize! */
@ -463,7 +466,7 @@ Cocoa_RegisterApp(void)
*/
if ([NSApp mainMenu] == nil) {
bool nibLoaded;
nibLoaded = LoadMainMenuNibIfAvailable();
if (!nibLoaded) {
CreateApplicationMenus();
@ -500,8 +503,7 @@ Cocoa_RegisterApp(void)
}
}}
int
Cocoa_PumpEventsUntilDate(_THIS, NSDate *expiration, bool accumulate)
int Cocoa_PumpEventsUntilDate(_THIS, NSDate *expiration, bool accumulate)
{
for ( ; ; ) {
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:expiration inMode:NSDefaultRunLoopMode dequeue:YES ];
@ -522,8 +524,7 @@ Cocoa_PumpEventsUntilDate(_THIS, NSDate *expiration, bool accumulate)
return 1;
}
int
Cocoa_WaitEventTimeout(_THIS, int timeout)
int Cocoa_WaitEventTimeout(_THIS, int timeout)
{ @autoreleasepool
{
if (timeout > 0) {
@ -538,8 +539,7 @@ Cocoa_WaitEventTimeout(_THIS, int timeout)
return 1;
}}
void
Cocoa_PumpEvents(_THIS)
void Cocoa_PumpEvents(_THIS)
{ @autoreleasepool
{
Cocoa_PumpEventsUntilDate(_this, [NSDate distantPast], true);
@ -548,13 +548,11 @@ Cocoa_PumpEvents(_THIS)
void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
{ @autoreleasepool
{
NSWindow *nswindow = ((__bridge SDL_WindowData *) window->driverdata).nswindow;
NSEvent* event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
location: NSMakePoint(0,0)
modifierFlags: 0
timestamp: 0.0
windowNumber: nswindow.windowNumber
windowNumber: ((__bridge SDL_WindowData *) window->driverdata).window_number
context: nil
subtype: 0
data1: 0
@ -563,8 +561,7 @@ void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window)
[NSApp postEvent: event atStart: YES];
}}
void
Cocoa_SuspendScreenSaver(_THIS)
void Cocoa_SuspendScreenSaver(_THIS)
{ @autoreleasepool
{
SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -29,7 +29,7 @@ extern void Cocoa_QuitKeyboard(_THIS);
extern void Cocoa_StartTextInput(_THIS);
extern void Cocoa_StopTextInput(_THIS);
extern void Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect);
extern void Cocoa_SetTextInputRect(_THIS, const SDL_Rect *rect);
extern void Cocoa_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -40,12 +40,12 @@
SDL_Rect _inputRect;
}
- (void)doCommandBySelector:(SEL)myselector;
- (void)setInputRect:(SDL_Rect *)rect;
- (void)setInputRect:(const SDL_Rect *)rect;
@end
@implementation SDLTranslatorResponder
- (void)setInputRect:(SDL_Rect *)rect
- (void)setInputRect:(const SDL_Rect *)rect
{
_inputRect = *rect;
}
@ -66,6 +66,11 @@
str = [aString UTF8String];
}
/* We're likely sending the composed text, so we reset the IME status. */
if ([self hasMarkedText]) {
[self unmarkText];
}
SDL_SendKeyboardText(str);
}
@ -114,7 +119,7 @@
(int) selectedRange.location, (int) selectedRange.length);
DEBUG_IME(@"setMarkedText: %@, (%d, %d)", _markedText,
selRange.location, selRange.length);
selectedRange.location, selectedRange.length);
}
- (void)unmarkText
@ -177,219 +182,68 @@
@end
/* This is a helper function for HandleModifierSide. This
* function reverts back to behavior before the distinction between
* sides was made.
*/
static void
HandleNonDeviceModifier(unsigned int device_independent_mask,
unsigned int oldMods,
unsigned int newMods,
SDL_Scancode scancode)
static bool IsModifierKeyPressed(unsigned int flags,
unsigned int target_mask,
unsigned int other_mask,
unsigned int either_mask)
{
unsigned int oldMask, newMask;
bool target_pressed = (flags & target_mask) != 0;
bool other_pressed = (flags & other_mask) != 0;
bool either_pressed = (flags & either_mask) != 0;
/* Isolate just the bits we care about in the depedent bits so we can
* figure out what changed
*/
oldMask = oldMods & device_independent_mask;
newMask = newMods & device_independent_mask;
if (either_pressed != (target_pressed || other_pressed))
return either_pressed;
if (oldMask && oldMask != newMask) {
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
} else if (newMask && oldMask != newMask) {
SDL_SendKeyboardKey(SDL_PRESSED, scancode);
}
return target_pressed;
}
/* This is a helper function for HandleModifierSide.
* This function sets the actual SDL_PrivateKeyboard event.
*/
static void
HandleModifierOneSide(unsigned int oldMods, unsigned int newMods,
SDL_Scancode scancode,
unsigned int sided_device_dependent_mask)
static void HandleModifiers(_THIS, SDL_Scancode code, unsigned int modifierFlags)
{
unsigned int old_dep_mask, new_dep_mask;
bool pressed = false;
/* Isolate just the bits we care about in the depedent bits so we can
* figure out what changed
*/
old_dep_mask = oldMods & sided_device_dependent_mask;
new_dep_mask = newMods & sided_device_dependent_mask;
/* We now know that this side bit flipped. But we don't know if
* it went pressed to released or released to pressed, so we must
* find out which it is.
*/
if (new_dep_mask && old_dep_mask != new_dep_mask) {
SDL_SendKeyboardKey(SDL_PRESSED, scancode);
if (code == SDL_SCANCODE_LSHIFT) {
pressed = IsModifierKeyPressed(modifierFlags, NX_DEVICELSHIFTKEYMASK,
NX_DEVICERSHIFTKEYMASK, NX_SHIFTMASK);
} else if (code == SDL_SCANCODE_LCTRL) {
pressed = IsModifierKeyPressed(modifierFlags, NX_DEVICELCTLKEYMASK,
NX_DEVICERCTLKEYMASK, NX_CONTROLMASK);
} else if (code == SDL_SCANCODE_LALT) {
pressed = IsModifierKeyPressed(modifierFlags, NX_DEVICELALTKEYMASK,
NX_DEVICERALTKEYMASK, NX_ALTERNATEMASK);
} else if (code == SDL_SCANCODE_LGUI) {
pressed = IsModifierKeyPressed(modifierFlags, NX_DEVICELCMDKEYMASK,
NX_DEVICERCMDKEYMASK, NX_COMMANDMASK);
} else if (code == SDL_SCANCODE_RSHIFT) {
pressed = IsModifierKeyPressed(modifierFlags, NX_DEVICERSHIFTKEYMASK,
NX_DEVICELSHIFTKEYMASK, NX_SHIFTMASK);
} else if (code == SDL_SCANCODE_RCTRL) {
pressed = IsModifierKeyPressed(modifierFlags, NX_DEVICERCTLKEYMASK,
NX_DEVICELCTLKEYMASK, NX_CONTROLMASK);
} else if (code == SDL_SCANCODE_RALT) {
pressed = IsModifierKeyPressed(modifierFlags, NX_DEVICERALTKEYMASK,
NX_DEVICELALTKEYMASK, NX_ALTERNATEMASK);
} else if (code == SDL_SCANCODE_RGUI) {
pressed = IsModifierKeyPressed(modifierFlags, NX_DEVICERCMDKEYMASK,
NX_DEVICELCMDKEYMASK, NX_COMMANDMASK);
} else {
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
}
}
/* This is a helper function for DoSidedModifiers.
* This function will figure out if the modifier key is the left or right side,
* e.g. left-shift vs right-shift.
*/
static void
HandleModifierSide(int device_independent_mask,
unsigned int oldMods, unsigned int newMods,
SDL_Scancode left_scancode,
SDL_Scancode right_scancode,
unsigned int left_device_dependent_mask,
unsigned int right_device_dependent_mask)
{
unsigned int device_dependent_mask = (left_device_dependent_mask |
right_device_dependent_mask);
unsigned int diff_mod;
/* On the basis that the device independent mask is set, but there are
* no device dependent flags set, we'll assume that we can't detect this
* keyboard and revert to the unsided behavior.
*/
if ((device_dependent_mask & newMods) == 0) {
/* Revert to the old behavior */
HandleNonDeviceModifier(device_independent_mask, oldMods, newMods, left_scancode);
return;
}
/* XOR the previous state against the new state to see if there's a change */
diff_mod = (device_dependent_mask & oldMods) ^
(device_dependent_mask & newMods);
if (diff_mod) {
/* A change in state was found. Isolate the left and right bits
* to handle them separately just in case the values can simulataneously
* change or if the bits don't both exist.
*/
if (left_device_dependent_mask & diff_mod) {
HandleModifierOneSide(oldMods, newMods, left_scancode, left_device_dependent_mask);
}
if (right_device_dependent_mask & diff_mod) {
HandleModifierOneSide(oldMods, newMods, right_scancode, right_device_dependent_mask);
}
if (pressed) {
SDL_SendKeyboardKey(SDL_PRESSED, code);
} else {
SDL_SendKeyboardKey(SDL_RELEASED, code);
}
}
/* This is a helper function for DoSidedModifiers.
* This function will release a key press in the case that
* it is clear that the modifier has been released (i.e. one side
* can't still be down).
*/
static void
ReleaseModifierSide(unsigned int device_independent_mask,
unsigned int oldMods, unsigned int newMods,
SDL_Scancode left_scancode,
SDL_Scancode right_scancode,
unsigned int left_device_dependent_mask,
unsigned int right_device_dependent_mask)
{
unsigned int device_dependent_mask = (left_device_dependent_mask |
right_device_dependent_mask);
/* On the basis that the device independent mask is set, but there are
* no device dependent flags set, we'll assume that we can't detect this
* keyboard and revert to the unsided behavior.
*/
if ((device_dependent_mask & oldMods) == 0) {
/* In this case, we can't detect the keyboard, so use the left side
* to represent both, and release it.
*/
SDL_SendKeyboardKey(SDL_RELEASED, left_scancode);
return;
}
/*
* This could have been done in an if-else case because at this point,
* we know that all keys have been released when calling this function.
* But I'm being paranoid so I want to handle each separately,
* so I hope this doesn't cause other problems.
*/
if ( left_device_dependent_mask & oldMods ) {
SDL_SendKeyboardKey(SDL_RELEASED, left_scancode);
}
if ( right_device_dependent_mask & oldMods ) {
SDL_SendKeyboardKey(SDL_RELEASED, right_scancode);
}
}
/* This function will handle the modifier keys and also determine the
* correct side of the key.
*/
static void
DoSidedModifiers(unsigned short scancode,
unsigned int oldMods, unsigned int newMods)
{
/* Set up arrays for the key syms for the left and right side. */
const SDL_Scancode left_mapping[] = {
SDL_SCANCODE_LSHIFT,
SDL_SCANCODE_LCTRL,
SDL_SCANCODE_LALT,
SDL_SCANCODE_LGUI
};
const SDL_Scancode right_mapping[] = {
SDL_SCANCODE_RSHIFT,
SDL_SCANCODE_RCTRL,
SDL_SCANCODE_RALT,
SDL_SCANCODE_RGUI
};
/* Set up arrays for the device dependent masks with indices that
* correspond to the _mapping arrays
*/
const unsigned int left_device_mapping[] = { NX_DEVICELSHIFTKEYMASK, NX_DEVICELCTLKEYMASK, NX_DEVICELALTKEYMASK, NX_DEVICELCMDKEYMASK };
const unsigned int right_device_mapping[] = { NX_DEVICERSHIFTKEYMASK, NX_DEVICERCTLKEYMASK, NX_DEVICERALTKEYMASK, NX_DEVICERCMDKEYMASK };
unsigned int i, bit;
/* Iterate through the bits, testing each against the old modifiers */
for (i = 0, bit = NSEventModifierFlagShift; bit <= NSEventModifierFlagCommand; bit <<= 1, ++i) {
unsigned int oldMask, newMask;
oldMask = oldMods & bit;
newMask = newMods & bit;
/* If the bit is set, we must always examine it because the left
* and right side keys may alternate or both may be pressed.
*/
if (newMask) {
HandleModifierSide(bit, oldMods, newMods,
left_mapping[i], right_mapping[i],
left_device_mapping[i], right_device_mapping[i]);
}
/* If the state changed from pressed to unpressed, we must examine
* the device dependent bits to release the correct keys.
*/
else if (oldMask && oldMask != newMask) {
ReleaseModifierSide(bit, oldMods, newMods,
left_mapping[i], right_mapping[i],
left_device_mapping[i], right_device_mapping[i]);
}
}
}
static void
HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags)
{
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
if (modifierFlags == data.modifierFlags) {
return;
}
DoSidedModifiers(scancode, data.modifierFlags, modifierFlags);
data.modifierFlags = modifierFlags;
}
static void
UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
static void UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
{
TISInputSourceRef key_layout;
const void *chr_data;
int i;
SDL_Scancode scancode;
SDL_Keycode keymap[SDL_NUM_SCANCODES];
CFDataRef uchrDataRef;
/* See if the keymap needs to be updated */
key_layout = TISCopyCurrentKeyboardLayoutInputSource();
@ -401,7 +255,7 @@ UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
SDL_GetDefaultKeymap(keymap);
/* Try Unicode data first */
CFDataRef uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData);
uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData);
if (uchrDataRef) {
chr_data = CFDataGetBytePtr(uchrDataRef);
} else {
@ -424,6 +278,17 @@ UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
continue;
}
/*
* Swap the scancode for these two wrongly translated keys
* UCKeyTranslate() function does not do its job properly for ISO layout keyboards, where the key '@',
* which is located in the top left corner of the keyboard right under the Escape key, and the additional
* key '<', which is on the right of the Shift key, are inverted
*/
if ((scancode == SDL_SCANCODE_NONUSBACKSLASH || scancode == SDL_SCANCODE_GRAVE) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) {
/* see comments in scancodes_darwin.h */
scancode = (SDL_Scancode)((SDL_SCANCODE_NONUSBACKSLASH + SDL_SCANCODE_GRAVE) - scancode);
}
dead_key_state = 0;
err = UCKeyTranslate ((UCKeyboardLayout *) chr_data,
i, kUCKeyActionDown,
@ -438,10 +303,7 @@ UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
keymap[scancode] = s[0];
}
}
SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
if (send_event) {
SDL_SendKeymapChangedEvent();
}
SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES, send_event);
return;
}
@ -449,8 +311,7 @@ cleanup:
CFRelease(key_layout);
}
void
Cocoa_InitKeyboard(_THIS)
void Cocoa_InitKeyboard(_THIS)
{
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
@ -465,13 +326,13 @@ Cocoa_InitKeyboard(_THIS)
SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");
data.modifierFlags = (unsigned int)[NSEvent modifierFlags];
SDL_ToggleModState(KMOD_CAPS, (data.modifierFlags & NSEventModifierFlagCapsLock) != 0);
SDL_ToggleModState(KMOD_CAPS, (data.modifierFlags & NSEventModifierFlagCapsLock) ? SDL_TRUE : SDL_FALSE);
}
void
Cocoa_StartTextInput(_THIS)
void Cocoa_StartTextInput(_THIS)
{ @autoreleasepool
{
NSView *parentView;
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
SDL_Window *window = SDL_GetKeyboardFocus();
NSWindow *nswindow = nil;
@ -479,7 +340,7 @@ Cocoa_StartTextInput(_THIS)
nswindow = ((__bridge SDL_WindowData*)window->driverdata).nswindow;
}
NSView *parentView = [nswindow contentView];
parentView = [nswindow contentView];
/* We only keep one field editor per process, since only the front most
* window can receive text input events, so it make no sense to keep more
@ -499,8 +360,7 @@ Cocoa_StartTextInput(_THIS)
}
}}
void
Cocoa_StopTextInput(_THIS)
void Cocoa_StopTextInput(_THIS)
{ @autoreleasepool
{
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
@ -511,8 +371,7 @@ Cocoa_StopTextInput(_THIS)
}
}}
void
Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
void Cocoa_SetTextInputRect(_THIS, const SDL_Rect *rect)
{
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
@ -524,22 +383,22 @@ Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
[data.fieldEdit setInputRect:rect];
}
void
Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
{
unsigned short scancode;
SDL_Scancode code;
SDL_VideoData *data = _this ? ((__bridge SDL_VideoData *) _this->driverdata) : nil;
if (!data) {
return; /* can happen when returning from fullscreen Space on shutdown */
}
unsigned short scancode = [event keyCode];
SDL_Scancode code;
scancode = [event keyCode];
#if 0
const char *text;
#endif
if ((scancode == 10 || scancode == 50) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) {
/* see comments in SDL_cocoakeys.h */
/* see comments in scancodes_darwin.h */
scancode = 60 - scancode;
}
@ -558,9 +417,9 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
}
SDL_SendKeyboardKey(SDL_PRESSED, code);
#if 1
#ifdef DEBUG_SCANCODES
if (code == SDL_SCANCODE_UNKNOWN) {
fprintf(stderr, "The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL forums/mailing list <https://discourse.libsdl.org/> or to Christian Walther <cwalther@gmx.ch>. Mac virtual key code is %d.\n", scancode);
SDL_Log("The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL forums/mailing list <https://discourse.libsdl.org/> or to Christian Walther <cwalther@gmx.ch>. Mac virtual key code is %d.\n", scancode);
}
#endif
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
@ -579,16 +438,14 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
SDL_SendKeyboardKey(SDL_RELEASED, code);
break;
case NSEventTypeFlagsChanged:
/* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */
HandleModifiers(_this, scancode, (unsigned int)[event modifierFlags]);
HandleModifiers(_this, code, (unsigned int)[event modifierFlags]);
break;
default: /* just to avoid compiler warnings */
break;
}
}
void
Cocoa_QuitKeyboard(_THIS)
void Cocoa_QuitKeyboard(_THIS)
{
}
@ -601,8 +458,7 @@ typedef enum {
extern CGSConnection _CGSDefaultConnection(void);
extern CGError CGSSetGlobalHotKeyOperatingMode(CGSConnection connection, CGSGlobalHotKeyOperatingMode mode);
void
Cocoa_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
void Cocoa_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
{
#if SDL_MAC_NO_SANDBOX
CGSSetGlobalHotKeyOperatingMode(_CGSDefaultConnection(), grabbed ? CGSGlobalHotKeyDisable : CGSGlobalHotKeyEnable);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -32,8 +32,7 @@
NSInteger clicked;
NSWindow *nswindow;
}
- (id) initWithParentWindow:(SDL_Window *)window;
- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
- (id)initWithParentWindow:(SDL_Window *)window;
@end
@implementation SDLMessageBoxPresenter
@ -57,44 +56,29 @@
- (void)showAlert:(NSAlert*)alert
{
if (nswindow) {
#ifdef MAC_OS_X_VERSION_10_9
if ([alert respondsToSelector:@selector(beginSheetModalForWindow:completionHandler:)]) {
[alert beginSheetModalForWindow:nswindow completionHandler:^(NSModalResponse returnCode) {
self->clicked = returnCode;
}];
} else
#endif
{
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
[alert beginSheetModalForWindow:nswindow modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
#endif
}
while (clicked < 0) {
SDL_PumpEvents();
SDL_Delay(100);
}
[alert beginSheetModalForWindow:nswindow
completionHandler:^(NSModalResponse returnCode) {
[NSApp stopModalWithCode:returnCode];
}];
clicked = [NSApp runModalForWindow:nswindow];
nswindow = nil;
} else {
clicked = [alert runModal];
}
}
- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
clicked = returnCode;
}
@end
static void
Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid, int *returnValue)
static void Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid, int *returnValue)
{
NSAlert* alert;
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
SDLMessageBoxPresenter* presenter;
NSInteger clicked;
int i;
Cocoa_RegisterApp();
NSAlert* alert = [[NSAlert alloc] init];
alert = [[NSAlert alloc] init];
if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
[alert setAlertStyle:NSAlertStyleCritical];
@ -107,8 +91,6 @@ Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid
[alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
[alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
int i;
for (i = 0; i < messageboxdata->numbuttons; ++i) {
const SDL_MessageBoxButtonData *sdlButton;
NSButton *button;
@ -129,11 +111,11 @@ Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid
}
}
SDLMessageBoxPresenter* presenter = [[SDLMessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window];
presenter = [[SDLMessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window];
[presenter showAlert:alert];
NSInteger clicked = presenter->clicked;
clicked = presenter->clicked;
if (clicked >= NSAlertFirstButtonReturn) {
clicked -= NSAlertFirstButtonReturn;
if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT) {
@ -147,8 +129,7 @@ Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid
}
/* Display a Cocoa message box */
int
Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
int Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
{ @autoreleasepool
{
__block int returnValue = 0;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -21,8 +21,8 @@
/*
* @author Mark Callow, www.edgewise-consulting.com.
*
* Thanks to Alex Szpakowski, @slime73 on GitHub, for his gist showing
* how to add a CAMetalLayer backed view.
* Thanks to @slime73 on GitHub for their gist showing how to add a CAMetalLayer
* backed view.
*/
#include "../../SDL_internal.h"

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -21,8 +21,8 @@
/*
* @author Mark Callow, www.edgewise-consulting.com.
*
* Thanks to Alex Szpakowski, @slime73 on GitHub, for his gist showing
* how to add a CAMetalLayer backed view.
* Thanks to @slime73 on GitHub for their gist showing how to add a CAMetalLayer
* backed view.
*/
#include "../../SDL_internal.h"
@ -81,7 +81,8 @@ SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
highDPI:(BOOL)highDPI
windowID:(Uint32)windowID;
{
if ((self = [super initWithFrame:frame])) {
self = [super initWithFrame:frame];
if (self != nil) {
self.highDPI = highDPI;
self.sdlWindowID = windowID;
self.wantsLayer = YES;
@ -93,7 +94,7 @@ SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
[self updateDrawableSize];
}
return self;
}
@ -130,8 +131,7 @@ SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
@end
SDL_MetalView
Cocoa_Metal_CreateView(_THIS, SDL_Window * window)
SDL_MetalView Cocoa_Metal_CreateView(_THIS, SDL_Window * window)
{ @autoreleasepool {
SDL_WindowData* data = (__bridge SDL_WindowData *)window->driverdata;
NSView *view = data.nswindow.contentView;
@ -144,32 +144,33 @@ Cocoa_Metal_CreateView(_THIS, SDL_Window * window)
highDPI:highDPI
windowID:windowID];
if (newview == nil) {
SDL_OutOfMemory();
return NULL;
}
[view addSubview:newview];
/* Make sure the drawable size is up to date after attaching the view. */
[newview updateDrawableSize];
metalview = (SDL_MetalView)CFBridgingRetain(newview);
return metalview;
}}
void
Cocoa_Metal_DestroyView(_THIS, SDL_MetalView view)
void Cocoa_Metal_DestroyView(_THIS, SDL_MetalView view)
{ @autoreleasepool {
SDL_cocoametalview *metalview = CFBridgingRelease(view);
[metalview removeFromSuperview];
}}
void *
Cocoa_Metal_GetLayer(_THIS, SDL_MetalView view)
void *Cocoa_Metal_GetLayer(_THIS, SDL_MetalView view)
{ @autoreleasepool {
SDL_cocoametalview *cocoaview = (__bridge SDL_cocoametalview *)view;
return (__bridge void *)cocoaview.layer;
}}
void
Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
void Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
{ @autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
NSView *contentView = data.sdlContentView;
@ -185,17 +186,7 @@ Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
}
} else {
/* Fall back to the viewport size. */
NSRect viewport = [contentView bounds];
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
/* This gives us the correct viewport for a Retina-enabled view. */
viewport = [contentView convertRectToBacking:viewport];
}
if (w) {
*w = viewport.size.width;
}
if (h) {
*h = viewport.size.height;
}
SDL_GetWindowSizeInPixels(window, w, h);
}
}}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -42,8 +42,7 @@
#endif
static int
CG_SetError(const char *prefix, CGDisplayErr result)
static int CG_SetError(const char *prefix, CGDisplayErr result)
{
const char *error;
@ -85,8 +84,7 @@ CG_SetError(const char *prefix, CGDisplayErr result)
return SDL_SetError("%s: %s", prefix, error);
}
static int
GetDisplayModeRefreshRate(CGDisplayModeRef vidmode, CVDisplayLinkRef link)
static int GetDisplayModeRefreshRate(CGDisplayModeRef vidmode, CVDisplayLinkRef link)
{
int refreshRate = (int) (CGDisplayModeGetRefreshRate(vidmode) + 0.5);
@ -101,8 +99,7 @@ GetDisplayModeRefreshRate(CGDisplayModeRef vidmode, CVDisplayLinkRef link)
return refreshRate;
}
static SDL_bool
HasValidDisplayModeFlags(CGDisplayModeRef vidmode)
static SDL_bool HasValidDisplayModeFlags(CGDisplayModeRef vidmode)
{
uint32_t ioflags = CGDisplayModeGetIOFlags(vidmode);
@ -119,8 +116,7 @@ HasValidDisplayModeFlags(CGDisplayModeRef vidmode)
return SDL_TRUE;
}
static Uint32
GetDisplayModePixelFormat(CGDisplayModeRef vidmode)
static Uint32 GetDisplayModePixelFormat(CGDisplayModeRef vidmode)
{
/* This API is deprecated in 10.11 with no good replacement (as of 10.15). */
CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
@ -144,8 +140,7 @@ GetDisplayModePixelFormat(CGDisplayModeRef vidmode)
return pixelformat;
}
static SDL_bool
GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmodeCurrent, CFArrayRef modelist, CVDisplayLinkRef link, SDL_DisplayMode *mode)
static SDL_bool GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmodeCurrent, CFArrayRef modelist, CVDisplayLinkRef link, SDL_DisplayMode *mode)
{
SDL_DisplayModeData *data;
bool usableForGUI = CGDisplayModeIsUsableForDesktopGUI(vidmode);
@ -185,6 +180,9 @@ GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmodeCurrent, CFArray
int i;
for (i = 0; i < modescount; i++) {
int otherW, otherH, otherpixelW, otherpixelH, otherrefresh;
Uint32 otherformat;
bool otherGUI;
CGDisplayModeRef othermode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modelist, i);
uint32_t otherioflags = CGDisplayModeGetIOFlags(othermode);
@ -196,13 +194,13 @@ GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmodeCurrent, CFArray
continue;
}
int otherW = (int) CGDisplayModeGetWidth(othermode);
int otherH = (int) CGDisplayModeGetHeight(othermode);
int otherpixelW = (int) CGDisplayModeGetPixelWidth(othermode);
int otherpixelH = (int) CGDisplayModeGetPixelHeight(othermode);
int otherrefresh = GetDisplayModeRefreshRate(othermode, link);
Uint32 otherformat = GetDisplayModePixelFormat(othermode);
bool otherGUI = CGDisplayModeIsUsableForDesktopGUI(othermode);
otherW = (int) CGDisplayModeGetWidth(othermode);
otherH = (int) CGDisplayModeGetHeight(othermode);
otherpixelW = (int) CGDisplayModeGetPixelWidth(othermode);
otherpixelH = (int) CGDisplayModeGetPixelHeight(othermode);
otherrefresh = GetDisplayModeRefreshRate(othermode, link);
otherformat = GetDisplayModePixelFormat(othermode);
otherGUI = CGDisplayModeIsUsableForDesktopGUI(othermode);
/* Ignore this mode if it's low-dpi (@1x) and we have a high-dpi
* mode in the list with the same size in points.
@ -280,8 +278,7 @@ GetDisplayMode(_THIS, CGDisplayModeRef vidmode, SDL_bool vidmodeCurrent, CFArray
return SDL_TRUE;
}
static const char *
Cocoa_GetDisplayName(CGDirectDisplayID displayID)
static const char *Cocoa_GetDisplayName(CGDirectDisplayID displayID)
{
/* This API is deprecated in 10.9 with no good replacement (as of 10.15). */
io_service_t servicePort = CGDisplayIOServicePort(displayID);
@ -296,8 +293,7 @@ Cocoa_GetDisplayName(CGDirectDisplayID displayID)
return displayName;
}
void
Cocoa_InitModes(_THIS)
void Cocoa_InitModes(_THIS)
{ @autoreleasepool
{
CGDisplayErr result;
@ -381,8 +377,7 @@ Cocoa_InitModes(_THIS)
SDL_small_free(displays, isstack);
}}
int
Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
{
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
CGRect cgrect;
@ -395,8 +390,7 @@ Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
return 0;
}
int
Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
{
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
const CGDirectDisplayID cgdisplay = displaydata->display;
@ -417,17 +411,18 @@ Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
return -1;
}
const NSRect frame = [screen visibleFrame];
rect->x = (int)frame.origin.x;
rect->y = (int)(CGDisplayPixelsHigh(kCGDirectMainDisplay) - frame.origin.y - frame.size.height);
rect->w = (int)frame.size.width;
rect->h = (int)frame.size.height;
{
const NSRect frame = [screen visibleFrame];
rect->x = (int)frame.origin.x;
rect->y = (int)(CGDisplayPixelsHigh(kCGDirectMainDisplay) - frame.origin.y - frame.size.height);
rect->w = (int)frame.size.width;
rect->h = (int)frame.size.height;
}
return 0;
}
int
Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
int Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
{ @autoreleasepool
{
const float MM_IN_INCH = 25.4f;
@ -440,7 +435,7 @@ Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdp
NSSize displayNativeSize;
displayNativeSize.width = (int) CGDisplayPixelsWide(data->display);
displayNativeSize.height = (int) CGDisplayPixelsHigh(data->display);
for (NSScreen *screen in screens) {
const CGDirectDisplayID dpyid = (const CGDirectDisplayID ) [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
if (dpyid == data->display) {
@ -457,7 +452,7 @@ Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdp
CGFloat width = CGDisplayModeGetPixelWidth(m);
CGFloat height = CGDisplayModeGetPixelHeight(m);
CGFloat HiDPIWidth = CGDisplayModeGetWidth(m);
//Only check 1x mode
if(width == HiDPIWidth) {
if (CGDisplayModeGetIOFlags(m) & kDisplayModeNativeFlag) {
@ -465,7 +460,7 @@ Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdp
displayNativeSize.height = height;
break;
}
//Get the largest size even if kDisplayModeNativeFlag is not present e.g. iMac 27-Inch with 5K Retina
if(width > displayNativeSize.width) {
displayNativeSize.width = width;
@ -487,25 +482,25 @@ Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdp
}
}
const CGSize displaySize = CGDisplayScreenSize(data->display);
const int pixelWidth = displayNativeSize.width;
const int pixelHeight = displayNativeSize.height;
{
const CGSize displaySize = CGDisplayScreenSize(data->display);
const int pixelWidth = displayNativeSize.width;
const int pixelHeight = displayNativeSize.height;
if (ddpi) {
*ddpi = (SDL_ComputeDiagonalDPI(pixelWidth, pixelHeight, displaySize.width / MM_IN_INCH, displaySize.height / MM_IN_INCH));
if (ddpi) {
*ddpi = (SDL_ComputeDiagonalDPI(pixelWidth, pixelHeight, displaySize.width / MM_IN_INCH, displaySize.height / MM_IN_INCH));
}
if (hdpi) {
*hdpi = (pixelWidth * MM_IN_INCH / displaySize.width);
}
if (vdpi) {
*vdpi = (pixelHeight * MM_IN_INCH / displaySize.height);
}
}
if (hdpi) {
*hdpi = (pixelWidth * MM_IN_INCH / displaySize.width);
}
if (vdpi) {
*vdpi = (pixelHeight * MM_IN_INCH / displaySize.height);
}
return 0;
}}
void
Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
void Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
CVDisplayLinkRef link = NULL;
@ -585,8 +580,7 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
CVDisplayLinkRelease(link);
}
static CGError
SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayModeData *data)
static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayModeData *data)
{
/* SDL_DisplayModeData can contain multiple CGDisplayModes to try (with
* identical properties), some of which might not work. See GetDisplayMode.
@ -604,8 +598,7 @@ SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayModeData *data)
return result;
}
int
Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
int Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
@ -670,8 +663,7 @@ ERR_NO_CAPTURE:
return -1;
}
void
Cocoa_QuitModes(_THIS)
void Cocoa_QuitModes(_THIS)
{
int i, j;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -32,7 +32,7 @@ extern void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y);
extern void Cocoa_QuitMouse(_THIS);
typedef struct {
/* Wether we've seen a cursor warp since the last move event. */
/* Whether we've seen a cursor warp since the last move event. */
SDL_bool seenWarp;
/* What location our last cursor warp was to. */
CGFloat lastWarpX;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -63,8 +63,7 @@
@end
static SDL_Cursor *
Cocoa_CreateDefaultCursor()
static SDL_Cursor *Cocoa_CreateDefaultCursor()
{ @autoreleasepool
{
NSCursor *nscursor;
@ -82,8 +81,7 @@ Cocoa_CreateDefaultCursor()
return cursor;
}}
static SDL_Cursor *
Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
static SDL_Cursor *Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
{ @autoreleasepool
{
NSImage *nsimage;
@ -108,44 +106,44 @@ Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
/* there are .pdf files of some of the cursors we need, installed by default on macOS, but not available through NSCursor.
If we can load them ourselves, use them, otherwise fallback to something standard but not super-great.
Since these are under /System, they should be available even to sandboxed apps. */
static NSCursor *
LoadHiddenSystemCursor(NSString *cursorName, SEL fallback)
static NSCursor *LoadHiddenSystemCursor(NSString *cursorName, SEL fallback)
{
NSString *cursorPath = [@"/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors" stringByAppendingPathComponent:cursorName];
NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[cursorPath stringByAppendingPathComponent:@"info.plist"]];
/* we can't do animation atm. :/ */
const int frames = (int)[[info valueForKey:@"frames"] integerValue];
NSCursor *cursor;
NSImage *image = [[NSImage alloc] initWithContentsOfFile:[cursorPath stringByAppendingPathComponent:@"cursor.pdf"]];
if ((image == nil) || (image.valid == NO)) {
if ((image == nil) || (image.isValid == NO)) {
return [NSCursor performSelector:fallback];
}
NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[cursorPath stringByAppendingPathComponent:@"info.plist"]];
/* we can't do animation atm. :/ */
const int frames = [[info valueForKey:@"frames"] integerValue];
if (frames > 1) {
#ifdef MAC_OS_VERSION_12_0 /* same value as deprecated symbol. */
const NSCompositingOperation operation = NSCompositingOperationCopy;
#else
const NSCompositingOperation operation = NSCompositeCopy;
#endif
const NSSize cropped_size = NSMakeSize(image.size.width, (int) (image.size.height / frames));
NSImage *cropped = [[NSImage alloc] initWithSize:cropped_size];
if (cropped == nil) {
return [NSCursor performSelector:fallback];
}
#ifdef MAC_OS_VERSION_12_0 /* same value as deprecated symbol. */
const NSCompositingOperation operation = NSCompositingOperationCopy;
#else
const NSCompositingOperation operation = NSCompositeCopy;
#endif
[cropped lockFocus];
const NSRect cropped_rect = NSMakeRect(0, 0, cropped_size.width, cropped_size.height);
[image drawInRect:cropped_rect fromRect:cropped_rect operation:operation fraction:1];
{
const NSRect cropped_rect = NSMakeRect(0, 0, cropped_size.width, cropped_size.height);
[image drawInRect:cropped_rect fromRect:cropped_rect operation:operation fraction:1];
}
[cropped unlockFocus];
image = cropped;
}
NSCursor *cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint([[info valueForKey:@"hotx"] doubleValue], [[info valueForKey:@"hoty"] doubleValue])];
cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint([[info valueForKey:@"hotx"] doubleValue], [[info valueForKey:@"hoty"] doubleValue])];
return cursor;
}
static SDL_Cursor *
Cocoa_CreateSystemCursor(SDL_SystemCursor id)
static SDL_Cursor *Cocoa_CreateSystemCursor(SDL_SystemCursor id)
{ @autoreleasepool
{
NSCursor *nscursor = NULL;
@ -204,16 +202,14 @@ Cocoa_CreateSystemCursor(SDL_SystemCursor id)
return cursor;
}}
static void
Cocoa_FreeCursor(SDL_Cursor * cursor)
static void Cocoa_FreeCursor(SDL_Cursor * cursor)
{ @autoreleasepool
{
CFBridgingRelease(cursor->driverdata);
SDL_free(cursor);
}}
static int
Cocoa_ShowCursor(SDL_Cursor * cursor)
static int Cocoa_ShowCursor(SDL_Cursor * cursor)
{ @autoreleasepool
{
SDL_VideoDevice *device = SDL_GetVideoDevice();
@ -229,8 +225,7 @@ Cocoa_ShowCursor(SDL_Cursor * cursor)
return 0;
}}
static SDL_Window *
SDL_FindWindowAtPoint(const int x, const int y)
static SDL_Window *SDL_FindWindowAtPoint(const int x, const int y)
{
const SDL_Point pt = { x, y };
SDL_Window *i;
@ -244,9 +239,9 @@ SDL_FindWindowAtPoint(const int x, const int y)
return NULL;
}
static int
Cocoa_WarpMouseGlobal(int x, int y)
static int Cocoa_WarpMouseGlobal(int x, int y)
{
CGPoint point;
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse->focus) {
SDL_WindowData *data = (__bridge SDL_WindowData *) mouse->focus->driverdata;
@ -256,7 +251,7 @@ Cocoa_WarpMouseGlobal(int x, int y)
return 0;
}
}
const CGPoint point = CGPointMake((float)x, (float)y);
point = CGPointMake((float)x, (float)y);
Cocoa_HandleMouseWarp(point.x, point.y);
@ -285,17 +280,23 @@ Cocoa_WarpMouseGlobal(int x, int y)
return 0;
}
static void
Cocoa_WarpMouse(SDL_Window * window, int x, int y)
static void Cocoa_WarpMouse(SDL_Window * window, int x, int y)
{
Cocoa_WarpMouseGlobal(window->x + x, window->y + y);
}
static int
Cocoa_SetRelativeMouseMode(SDL_bool enabled)
static int Cocoa_SetRelativeMouseMode(SDL_bool enabled)
{
SDL_Window *window = SDL_GetKeyboardFocus();
CGError result;
SDL_WindowData *data;
if (enabled) {
if (window) {
/* make sure the mouse isn't at the corner of the window, as this can confuse things if macOS thinks a window resize is happening on the first click. */
const CGPoint point = CGPointMake((float)(window->x + (window->w / 2)), (float)(window->y + (window->h / 2)));
Cocoa_HandleMouseWarp(point.x, point.y);
CGWarpMouseCursorPosition(point);
}
DLog("Turning on.");
result = CGAssociateMouseAndMouseCursorPosition(NO);
} else {
@ -309,7 +310,6 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled)
/* We will re-apply the non-relative mode when the window gets focus, if it
* doesn't have focus right now.
*/
SDL_Window *window = SDL_GetKeyboardFocus();
if (!window) {
return 0;
}
@ -317,7 +317,7 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled)
/* We will re-apply the non-relative mode when the window finishes being moved,
* if it is being moved right now.
*/
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
data = (__bridge SDL_WindowData *) window->driverdata;
if ([data.listener isMovingOrFocusClickPending]) {
return 0;
}
@ -333,16 +333,14 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled)
return 0;
}
static int
Cocoa_CaptureMouse(SDL_Window *window)
static int Cocoa_CaptureMouse(SDL_Window *window)
{
/* our Cocoa event code already tracks the mouse outside the window,
so all we have to do here is say "okay" and do what we always do. */
return 0;
}
static Uint32
Cocoa_GetGlobalMouseState(int *x, int *y)
static Uint32 Cocoa_GetGlobalMouseState(int *x, int *y)
{
const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
const NSPoint cocoaLocation = [NSEvent mouseLocation];
@ -360,9 +358,9 @@ Cocoa_GetGlobalMouseState(int *x, int *y)
return retval;
}
int
Cocoa_InitMouse(_THIS)
int Cocoa_InitMouse(_THIS)
{
NSPoint location;
SDL_Mouse *mouse = SDL_GetMouse();
SDL_MouseData *driverdata = (SDL_MouseData*) SDL_calloc(1, sizeof(SDL_MouseData));
if (driverdata == NULL) {
@ -382,18 +380,23 @@ Cocoa_InitMouse(_THIS)
SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
const NSPoint location = [NSEvent mouseLocation];
location = [NSEvent mouseLocation];
driverdata->lastMoveX = location.x;
driverdata->lastMoveY = location.y;
return 0;
}
static void
Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event)
static void Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event)
{
SDL_Window *window;
NSWindow *nswindow = [event window];
/* You might land in this function before SDL_Init if showing a message box.
Don't derefence a NULL pointer if that happens. */
if (_this == NULL) {
return;
}
for (window = _this->windows; window; window = window->next) {
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
if (data && data.nswindow == nswindow) {
@ -416,9 +419,15 @@ Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event)
}
}
void
Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
void Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
{
SDL_Mouse *mouse;
SDL_MouseData *driverdata;
SDL_MouseID mouseID;
NSPoint location;
CGFloat lastMoveX, lastMoveY;
float deltaX, deltaY;
SDL_bool seenWarp;
switch ([event type]) {
case NSEventTypeMouseMoved:
case NSEventTypeLeftMouseDragged:
@ -446,19 +455,19 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
return;
}
SDL_Mouse *mouse = SDL_GetMouse();
SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
mouse = SDL_GetMouse();
driverdata = (SDL_MouseData*)mouse->driverdata;
if (!driverdata) {
return; /* can happen when returning from fullscreen Space on shutdown */
}
SDL_MouseID mouseID = mouse ? mouse->mouseID : 0;
const SDL_bool seenWarp = driverdata->seenWarp;
mouseID = mouse ? mouse->mouseID : 0;
seenWarp = driverdata->seenWarp;
driverdata->seenWarp = NO;
const NSPoint location = [NSEvent mouseLocation];
const CGFloat lastMoveX = driverdata->lastMoveX;
const CGFloat lastMoveY = driverdata->lastMoveY;
location = [NSEvent mouseLocation];
lastMoveX = driverdata->lastMoveX;
lastMoveY = driverdata->lastMoveY;
driverdata->lastMoveX = location.x;
driverdata->lastMoveY = location.y;
DLog("Last seen mouse: (%g, %g)", location.x, location.y);
@ -476,8 +485,8 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
}
}
float deltaX = [event deltaX];
float deltaY = [event deltaY];
deltaX = [event deltaX];
deltaY = [event deltaY];
if (seenWarp) {
deltaX += (lastMoveX - driverdata->lastWarpX);
@ -489,18 +498,20 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
SDL_SendMouseMotion(mouse->focus, mouseID, 1, (int)deltaX, (int)deltaY);
}
void
Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
{
SDL_MouseID mouseID;
SDL_MouseWheelDirection direction;
CGFloat x, y;
SDL_Mouse *mouse = SDL_GetMouse();
if (!mouse) {
return;
}
SDL_MouseID mouseID = mouse->mouseID;
CGFloat x = -[event deltaX];
CGFloat y = [event deltaY];
SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL;
mouseID = mouse->mouseID;
x = -[event deltaX];
y = [event deltaY];
direction = SDL_MOUSEWHEEL_NORMAL;
if ([event isDirectionInvertedFromDevice] == YES) {
direction = SDL_MOUSEWHEEL_FLIPPED;
@ -524,8 +535,7 @@ Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
SDL_SendMouseWheel(window, mouseID, x, y, direction);
}
void
Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
{
/* This makes Cocoa_HandleMouseEvent ignore the delta caused by the warp,
* since it gets included in the next movement event.
@ -538,8 +548,7 @@ Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
DLog("(%g, %g)", x, y);
}
void
Cocoa_QuitMouse(_THIS)
void Cocoa_QuitMouse(_THIS)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse) {

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -27,6 +27,7 @@
#include "SDL_atomic.h"
#import <Cocoa/Cocoa.h>
#import <QuartzCore/CVDisplayLink.h>
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#ifdef __clang__
@ -42,15 +43,24 @@ struct SDL_GLDriverData
@interface SDLOpenGLContext : NSOpenGLContext {
SDL_atomic_t dirty;
SDL_Window *window;
CVDisplayLinkRef displayLink;
@public SDL_mutex *swapIntervalMutex;
@public SDL_cond *swapIntervalCond;
@public SDL_atomic_t swapIntervalSetting;
@public SDL_atomic_t swapIntervalsPassed;
}
- (id)initWithFormat:(NSOpenGLPixelFormat *)format
shareContext:(NSOpenGLContext *)share;
- (void)scheduleUpdate;
- (void)updateIfNeeded;
- (void)movedToNewScreen;
- (void)setWindow:(SDL_Window *)window;
- (SDL_Window*)window;
- (void)explicitUpdate;
- (void)cleanup;
@property (retain, nonatomic) NSOpenGLPixelFormat* openglPixelFormat; // macOS 10.10 has -[NSOpenGLContext pixelFormat] but this handles older OS releases.
@end
@ -61,8 +71,6 @@ extern void Cocoa_GL_UnloadLibrary(_THIS);
extern SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window * window);
extern int Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window,
SDL_GLContext context);
extern void Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window,
int * w, int * h);
extern int Cocoa_GL_SetSwapInterval(_THIS, int interval);
extern int Cocoa_GL_GetSwapInterval(_THIS);
extern int Cocoa_GL_SwapWindow(_THIS, SDL_Window * window);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -31,8 +31,10 @@
#include <OpenGL/OpenGL.h>
#include <OpenGL/CGLRenderers.h>
#include "SDL_hints.h"
#include "SDL_loadso.h"
#include "SDL_opengl.h"
#include "../../SDL_hints_c.h"
#define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
@ -42,6 +44,40 @@
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
/* _Nullable is available starting Xcode 7 */
#ifdef __has_feature
#if __has_feature(nullability)
#define HAS_FEATURE_NULLABLE
#endif
#endif
#ifndef HAS_FEATURE_NULLABLE
#define _Nullable
#endif
static SDL_bool SDL_opengl_async_dispatch = SDL_FALSE;
static void SDLCALL
SDL_OpenGLAsyncDispatchChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
SDL_opengl_async_dispatch = SDL_GetStringBoolean(hint, SDL_FALSE);
}
static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext)
{
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *) displayLinkContext;
/*printf("DISPLAY LINK! %u\n", (unsigned int) SDL_GetTicks()); */
const int setting = SDL_AtomicGet(&nscontext->swapIntervalSetting);
if (setting != 0) { /* nothing to do if vsync is disabled, don't even lock */
SDL_LockMutex(nscontext->swapIntervalMutex);
SDL_AtomicAdd(&nscontext->swapIntervalsPassed, 1);
SDL_CondSignal(nscontext->swapIntervalCond);
SDL_UnlockMutex(nscontext->swapIntervalMutex);
}
return kCVReturnSuccess;
}
@implementation SDLOpenGLContext : NSOpenGLContext
- (id)initWithFormat:(NSOpenGLPixelFormat *)format
@ -49,12 +85,35 @@
{
self = [super initWithFormat:format shareContext:share];
if (self) {
self.openglPixelFormat = format;
SDL_AtomicSet(&self->dirty, 0);
self->window = NULL;
SDL_AtomicSet(&self->swapIntervalSetting, 0);
SDL_AtomicSet(&self->swapIntervalsPassed, 0);
self->swapIntervalCond = SDL_CreateCond();
self->swapIntervalMutex = SDL_CreateMutex();
if (!self->swapIntervalCond || !self->swapIntervalMutex) {
return nil;
}
/* !!! FIXME: check return values. */
CVDisplayLinkCreateWithActiveCGDisplays(&self->displayLink);
CVDisplayLinkSetOutputCallback(self->displayLink, &DisplayLinkCallback, (__bridge void * _Nullable) self);
CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(self->displayLink, [self CGLContextObj], [format CGLPixelFormatObj]);
CVDisplayLinkStart(displayLink);
}
SDL_AddHintCallback(SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH, SDL_OpenGLAsyncDispatchChanged, NULL);
return self;
}
- (void)movedToNewScreen
{
if (self->displayLink) {
CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(self->displayLink, [self CGLContextObj], [[self openglPixelFormat] CGLPixelFormatObj]);
}
}
- (void)scheduleUpdate
{
SDL_AtomicAdd(&self->dirty, 1);
@ -116,11 +175,10 @@
}
}
} else {
[self clearDrawable];
if (self == [NSOpenGLContext currentContext]) {
[self explicitUpdate];
if ([NSThread isMainThread]) {
[self setView:nil];
} else {
[self scheduleUpdate];
dispatch_sync(dispatch_get_main_queue(), ^{ [self setView:nil]; });
}
}
}
@ -135,15 +193,37 @@
if ([NSThread isMainThread]) {
[super update];
} else {
dispatch_async(dispatch_get_main_queue(), ^{ [super update]; });
if (SDL_opengl_async_dispatch) {
dispatch_async(dispatch_get_main_queue(), ^{ [super update]; });
} else {
dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; });
}
}
}
- (void)cleanup
{
[self setWindow:NULL];
SDL_DelHintCallback(SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH, SDL_OpenGLAsyncDispatchChanged, NULL);
if (self->displayLink) {
CVDisplayLinkRelease(self->displayLink);
self->displayLink = nil;
}
if (self->swapIntervalCond) {
SDL_DestroyCond(self->swapIntervalCond);
self->swapIntervalCond = NULL;
}
if (self->swapIntervalMutex) {
SDL_DestroyMutex(self->swapIntervalMutex);
self->swapIntervalMutex = NULL;
}
}
@end
int
Cocoa_GL_LoadLibrary(_THIS, const char *path)
int Cocoa_GL_LoadLibrary(_THIS, const char *path)
{
/* Load the OpenGL library */
if (path == NULL) {
@ -161,21 +241,18 @@ Cocoa_GL_LoadLibrary(_THIS, const char *path)
return 0;
}
void *
Cocoa_GL_GetProcAddress(_THIS, const char *proc)
void *Cocoa_GL_GetProcAddress(_THIS, const char *proc)
{
return SDL_LoadFunction(_this->gl_config.dll_handle, proc);
}
void
Cocoa_GL_UnloadLibrary(_THIS)
void Cocoa_GL_UnloadLibrary(_THIS)
{
SDL_UnloadObject(_this->gl_config.dll_handle);
_this->gl_config.dll_handle = NULL;
}
SDL_GLContext
Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
@ -189,6 +266,8 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
const char *glversion;
int glversion_major;
int glversion_minor;
NSOpenGLPixelFormatAttribute profile;
int interval;
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
#if SDL_VIDEO_OPENGL_EGL
@ -203,7 +282,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
_this->GL_GetSwapInterval = Cocoa_GLES_GetSwapInterval;
_this->GL_SwapWindow = Cocoa_GLES_SwapWindow;
_this->GL_DeleteContext = Cocoa_GLES_DeleteContext;
if (Cocoa_GLES_LoadLibrary(_this, NULL) != 0) {
return NULL;
}
@ -216,7 +295,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
attr[i++] = NSOpenGLPFAAllowOfflineRenderers;
NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
profile = NSOpenGLProfileVersionLegacy;
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
profile = NSOpenGLProfileVersion3_2Core;
}
@ -260,6 +339,9 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
attr[i++] = _this->gl_config.multisamplesamples;
attr[i++] = NSOpenGLPFANoRecovery;
}
if (_this->gl_config.floatbuffers) {
attr[i++] = NSOpenGLPFAColorFloat;
}
if (_this->gl_config.accelerated >= 0) {
if (_this->gl_config.accelerated) {
@ -293,8 +375,12 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
sdlcontext = (SDL_GLContext)CFBridgingRetain(context);
if ( Cocoa_GL_MakeCurrent(_this, window, (__bridge SDL_GLContext)context) < 0 ) {
Cocoa_GL_DeleteContext(_this, (__bridge SDL_GLContext)context);
/* vsync is handled separately by synchronizing with a display link. */
interval = 0;
[context setValues:&interval forParameter:NSOpenGLCPSwapInterval];
if (Cocoa_GL_MakeCurrent(_this, window, sdlcontext) < 0) {
SDL_GL_DeleteContext(sdlcontext);
SDL_SetError("Failed making OpenGL context current");
return NULL;
}
@ -308,27 +394,27 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
glGetStringFunc = (const GLubyte *(APIENTRY *)(GLenum)) SDL_GL_GetProcAddress("glGetString");
if (!glGetStringFunc) {
Cocoa_GL_DeleteContext(_this, (__bridge SDL_GLContext)context);
SDL_GL_DeleteContext(sdlcontext);
SDL_SetError ("Failed getting OpenGL glGetString entry point");
return NULL;
}
glversion = (const char *)glGetStringFunc(GL_VERSION);
if (glversion == NULL) {
Cocoa_GL_DeleteContext(_this, (__bridge SDL_GLContext)context);
SDL_GL_DeleteContext(sdlcontext);
SDL_SetError ("Failed getting OpenGL context version");
return NULL;
}
if (SDL_sscanf(glversion, "%d.%d", &glversion_major, &glversion_minor) != 2) {
Cocoa_GL_DeleteContext(_this, (__bridge SDL_GLContext)context);
SDL_GL_DeleteContext(sdlcontext);
SDL_SetError ("Failed parsing OpenGL context version");
return NULL;
}
if ((glversion_major < _this->gl_config.major_version) ||
((glversion_major == _this->gl_config.major_version) && (glversion_minor < _this->gl_config.minor_version))) {
Cocoa_GL_DeleteContext(_this, (__bridge SDL_GLContext)context);
SDL_GL_DeleteContext(sdlcontext);
SDL_SetError ("Failed creating OpenGL context at version requested");
return NULL;
}
@ -342,8 +428,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
return sdlcontext;
}}
int
Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
int Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{ @autoreleasepool
{
if (context) {
@ -360,75 +445,58 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
return 0;
}}
void
Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
int Cocoa_GL_SetSwapInterval(_THIS, int interval)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
NSView *contentView = windata.sdlContentView;
NSRect viewport = [contentView bounds];
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
/* This gives us the correct viewport for a Retina-enabled view. */
viewport = [contentView convertRectToBacking:viewport];
}
if (w) {
*w = viewport.size.width;
}
if (h) {
*h = viewport.size.height;
}
}}
int
Cocoa_GL_SetSwapInterval(_THIS, int interval)
{ @autoreleasepool
{
NSOpenGLContext *nscontext;
GLint value;
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *) SDL_GL_GetCurrentContext();
int status;
if (interval < 0) { /* no extension for this on Mac OS X at the moment. */
return SDL_SetError("Late swap tearing currently unsupported");
}
nscontext = (__bridge NSOpenGLContext*)SDL_GL_GetCurrentContext();
if (nscontext != nil) {
value = interval;
[nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
status = 0;
} else {
if (nscontext == nil) {
status = SDL_SetError("No current OpenGL context");
} else {
SDL_LockMutex(nscontext->swapIntervalMutex);
SDL_AtomicSet(&nscontext->swapIntervalsPassed, 0);
SDL_AtomicSet(&nscontext->swapIntervalSetting, interval);
SDL_UnlockMutex(nscontext->swapIntervalMutex);
status = 0;
}
return status;
}}
int
Cocoa_GL_GetSwapInterval(_THIS)
int Cocoa_GL_GetSwapInterval(_THIS)
{ @autoreleasepool
{
NSOpenGLContext *nscontext;
GLint value;
int status = 0;
nscontext = (__bridge NSOpenGLContext*)SDL_GL_GetCurrentContext();
if (nscontext != nil) {
[nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
status = (int)value;
}
return status;
SDLOpenGLContext* nscontext = (__bridge SDLOpenGLContext*)SDL_GL_GetCurrentContext();
return nscontext ? SDL_AtomicGet(&nscontext->swapIntervalSetting) : 0;
}}
int
Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
int Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDLOpenGLContext* nscontext = (__bridge SDLOpenGLContext*)SDL_GL_GetCurrentContext();
SDL_VideoData *videodata = (__bridge SDL_VideoData *) _this->driverdata;
const int setting = SDL_AtomicGet(&nscontext->swapIntervalSetting);
if (setting == 0) {
/* nothing to do if vsync is disabled, don't even lock */
} else if (setting < 0) { /* late swap tearing */
SDL_LockMutex(nscontext->swapIntervalMutex);
while (SDL_AtomicGet(&nscontext->swapIntervalsPassed) == 0) {
SDL_CondWait(nscontext->swapIntervalCond, nscontext->swapIntervalMutex);
}
SDL_AtomicSet(&nscontext->swapIntervalsPassed, 0);
SDL_UnlockMutex(nscontext->swapIntervalMutex);
} else {
SDL_LockMutex(nscontext->swapIntervalMutex);
do { /* always wait here so we know we just hit a swap interval. */
SDL_CondWait(nscontext->swapIntervalCond, nscontext->swapIntervalMutex);
} while ((SDL_AtomicGet(&nscontext->swapIntervalsPassed) % setting) != 0);
SDL_AtomicSet(&nscontext->swapIntervalsPassed, 0);
SDL_UnlockMutex(nscontext->swapIntervalMutex);
}
/*{ static Uint64 prev = 0; const Uint64 now = SDL_GetTicks64(); const unsigned int diff = (unsigned int) (now - prev); prev = now; printf("GLSWAPBUFFERS TICKS %u\n", diff); }*/
/* on 10.14 ("Mojave") and later, this deadlocks if two contexts in two
threads try to swap at the same time, so put a mutex around it. */
@ -439,12 +507,12 @@ Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
return 0;
}}
void
Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
void Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
{ @autoreleasepool
{
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)CFBridgingRelease(context);
[nscontext setWindow:NULL];
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)context;
[nscontext cleanup];
CFRelease(context);
}}
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -28,8 +28,7 @@
/* EGL implementation of SDL OpenGL support */
int
Cocoa_GLES_LoadLibrary(_THIS, const char *path)
int Cocoa_GLES_LoadLibrary(_THIS, const char *path)
{
/* If the profile requested is not GL ES, switch over to WIN_GL functions */
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
@ -49,7 +48,7 @@ Cocoa_GLES_LoadLibrary(_THIS, const char *path)
return SDL_SetError("SDL not configured with OpenGL/CGL support");
#endif
}
if (_this->egl_data == NULL) {
return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0);
}
@ -57,8 +56,7 @@ Cocoa_GLES_LoadLibrary(_THIS, const char *path)
return 0;
}
SDL_GLContext
Cocoa_GLES_CreateContext(_THIS, SDL_Window * window)
SDL_GLContext Cocoa_GLES_CreateContext(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_GLContext context;
@ -90,31 +88,27 @@ Cocoa_GLES_CreateContext(_THIS, SDL_Window * window)
return context;
}}
void
Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context)
void Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context)
{ @autoreleasepool
{
SDL_EGL_DeleteContext(_this, context);
Cocoa_GLES_UnloadLibrary(_this);
}}
int
Cocoa_GLES_SwapWindow(_THIS, SDL_Window * window)
int Cocoa_GLES_SwapWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
return SDL_EGL_SwapBuffers(_this, ((__bridge SDL_WindowData *) window->driverdata).egl_surface);
}}
int
Cocoa_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
int Cocoa_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{ @autoreleasepool
{
return SDL_EGL_MakeCurrent(_this, window ? ((__bridge SDL_WindowData *) window->driverdata).egl_surface : EGL_NO_SURFACE, context);
}}
int
Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
int Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
{
NSView* v;
/* The current context is lost in here; save it and reset it. */
SDL_WindowData *windowdata = (__bridge SDL_WindowData *) window->driverdata;
SDL_Window *current_win = SDL_GL_GetCurrentWindow();
@ -132,9 +126,9 @@ Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
}
_this->gl_config.driver_loaded = 1;
}
/* Create the GLES window surface */
NSView* v = windowdata.nswindow.contentView;
v = windowdata.nswindow.contentView;
windowdata.egl_surface = SDL_EGL_CreateSurface(_this, (__bridge NativeWindowType)[v layer]);
if (windowdata.egl_surface == EGL_NO_SURFACE) {

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -29,12 +29,11 @@
#include "SDL_shape.h"
#include "../SDL_shape_internals.h"
typedef struct {
NSGraphicsContext* context;
SDL_bool saved;
SDL_ShapeTree* shape;
} SDL_ShapeData;
@interface SDL_ShapeData : NSObject
@property (nonatomic) NSGraphicsContext* context;
@property (nonatomic) SDL_bool saved;
@property (nonatomic) SDL_ShapeTree* shape;
@end
extern SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window);
extern int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -27,85 +27,100 @@
#include "SDL_cocoashape.h"
#include "../SDL_sysvideo.h"
SDL_WindowShaper*
Cocoa_CreateShaper(SDL_Window* window)
@implementation SDL_ShapeData
@end
@interface SDL_CocoaClosure : NSObject
@property (nonatomic) NSView* view;
@property (nonatomic) NSBezierPath* path;
@property (nonatomic) SDL_Window* window;
@end
@implementation SDL_CocoaClosure
@end
SDL_WindowShaper *Cocoa_CreateShaper(SDL_Window* window)
{ @autoreleasepool
{
SDL_WindowShaper* result;
SDL_ShapeData* data;
int resized_properly;
SDL_WindowData* windata = (__bridge SDL_WindowData*)window->driverdata;
result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
if (!result) {
SDL_OutOfMemory();
return NULL;
}
[windata.nswindow setOpaque:NO];
[windata.nswindow setStyleMask:NSWindowStyleMaskBorderless];
SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
result->window = window;
result->mode.mode = ShapeModeDefault;
result->mode.parameters.binarizationCutoff = 1;
result->userx = result->usery = 0;
window->shaper = result;
SDL_ShapeData* data = (SDL_ShapeData *)SDL_malloc(sizeof(SDL_ShapeData));
result->driverdata = data;
data->context = [windata.nswindow graphicsContext];
data->saved = SDL_FALSE;
data->shape = NULL;
data = [[SDL_ShapeData alloc] init];
data.context = [windata.nswindow graphicsContext];
data.saved = SDL_FALSE;
data.shape = NULL;
int resized_properly = Cocoa_ResizeWindowShape(window);
/* TODO: There's no place to release this... */
result->driverdata = (void*) CFBridgingRetain(data);
resized_properly = Cocoa_ResizeWindowShape(window);
SDL_assert(resized_properly == 0);
return result;
}}
typedef struct {
NSView* view;
NSBezierPath* path;
SDL_Window* window;
} SDL_CocoaClosure;
void
ConvertRects(SDL_ShapeTree* tree, void* closure)
static void ConvertRects(SDL_ShapeTree* tree, void* closure)
{
SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
SDL_CocoaClosure* data = (__bridge SDL_CocoaClosure*)closure;
if(tree->kind == OpaqueShape) {
NSRect rect = NSMakeRect(tree->data.shape.x,data->window->h - tree->data.shape.y,tree->data.shape.w,tree->data.shape.h);
[data->path appendBezierPathWithRect:[data->view convertRect:rect toView:nil]];
NSRect rect = NSMakeRect(tree->data.shape.x, data.window->h - tree->data.shape.y, tree->data.shape.w, tree->data.shape.h);
[data.path appendBezierPathWithRect:[data.view convertRect:rect toView:nil]];
}
}
int
Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
int Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
{ @autoreleasepool
{
SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
SDL_ShapeData* data = (__bridge SDL_ShapeData*)shaper->driverdata;
SDL_WindowData* windata = (__bridge SDL_WindowData*)shaper->window->driverdata;
SDL_CocoaClosure closure;
if(data->saved == SDL_TRUE) {
[data->context restoreGraphicsState];
data->saved = SDL_FALSE;
SDL_CocoaClosure* closure;
if(data.saved == SDL_TRUE) {
[data.context restoreGraphicsState];
data.saved = SDL_FALSE;
}
/*[data->context saveGraphicsState];*/
/*data->saved = SDL_TRUE;*/
[NSGraphicsContext setCurrentContext:data->context];
/*[data.context saveGraphicsState];*/
/*data.saved = SDL_TRUE;*/
[NSGraphicsContext setCurrentContext:data.context];
[[NSColor clearColor] set];
NSRectFill([windata.sdlContentView frame]);
data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
data.shape = SDL_CalculateShapeTree(*shape_mode, shape);
closure = [[SDL_CocoaClosure alloc] init];
closure.view = windata.sdlContentView;
closure.path = [NSBezierPath bezierPath];
closure.window = shaper->window;
SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
SDL_TraverseShapeTree(data.shape, &ConvertRects, (__bridge void*)closure);
[closure.path addClip];
return 0;
}}
int
Cocoa_ResizeWindowShape(SDL_Window *window)
{
SDL_ShapeData* data = window->shaper->driverdata;
int Cocoa_ResizeWindowShape(SDL_Window *window)
{ @autoreleasepool {
SDL_ShapeData* data = (__bridge SDL_ShapeData*)window->shaper->driverdata;
SDL_assert(data != NULL);
return 0;
}
}}
#endif /* SDL_VIDEO_DRIVER_COCOA */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -99,6 +99,7 @@ DECLARE_ALERT_STYLE(Critical);
@interface SDL_VideoData : NSObject
@property (nonatomic) int allow_spaces;
@property (nonatomic) int trackpad_is_touch_only;
@property (nonatomic) unsigned int modifierFlags;
@property (nonatomic) void *key_layout;
@property (nonatomic) SDLTranslatorResponder *fieldEdit;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -32,6 +32,7 @@
#include "SDL_cocoashape.h"
#include "SDL_cocoavulkan.h"
#include "SDL_cocoametalview.h"
#include "SDL_cocoaopengles.h"
@implementation SDL_VideoData
@ -43,8 +44,7 @@ static void Cocoa_VideoQuit(_THIS);
/* Cocoa driver bootstrap functions */
static void
Cocoa_DeleteDevice(SDL_VideoDevice * device)
static void Cocoa_DeleteDevice(SDL_VideoDevice * device)
{ @autoreleasepool
{
if (device->wakeup_lock) {
@ -54,8 +54,7 @@ Cocoa_DeleteDevice(SDL_VideoDevice * device)
SDL_free(device);
}}
static SDL_VideoDevice *
Cocoa_CreateDevice(int devindex)
static SDL_VideoDevice *Cocoa_CreateDevice(void)
{ @autoreleasepool
{
SDL_VideoDevice *device;
@ -100,6 +99,7 @@ Cocoa_CreateDevice(int devindex)
device->SetWindowMinimumSize = Cocoa_SetWindowMinimumSize;
device->SetWindowMaximumSize = Cocoa_SetWindowMaximumSize;
device->SetWindowOpacity = Cocoa_SetWindowOpacity;
device->GetWindowSizeInPixels = Cocoa_GetWindowSizeInPixels;
device->ShowWindow = Cocoa_ShowWindow;
device->HideWindow = Cocoa_HideWindow;
device->RaiseWindow = Cocoa_RaiseWindow;
@ -133,7 +133,6 @@ Cocoa_CreateDevice(int devindex)
device->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary;
device->GL_CreateContext = Cocoa_GL_CreateContext;
device->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
device->GL_GetDrawableSize = Cocoa_GL_GetDrawableSize;
device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
device->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
device->GL_SwapWindow = Cocoa_GL_SwapWindow;
@ -184,8 +183,7 @@ VideoBootStrap COCOA_bootstrap = {
};
int
Cocoa_VideoInit(_THIS)
int Cocoa_VideoInit(_THIS)
{ @autoreleasepool
{
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
@ -197,6 +195,7 @@ Cocoa_VideoInit(_THIS)
}
data.allow_spaces = SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE);
data.trackpad_is_touch_only = SDL_GetHintBoolean(SDL_HINT_TRACKPAD_IS_TOUCH_ONLY, SDL_FALSE);
data.swaplock = SDL_CreateMutex();
if (!data.swaplock) {
@ -206,8 +205,7 @@ Cocoa_VideoInit(_THIS)
return 0;
}}
void
Cocoa_VideoQuit(_THIS)
void Cocoa_VideoQuit(_THIS)
{ @autoreleasepool
{
SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
@ -219,8 +217,7 @@ Cocoa_VideoQuit(_THIS)
}}
/* This function assumes that it's called from within an autorelease pool */
NSImage *
Cocoa_CreateImage(SDL_Surface * surface)
NSImage *Cocoa_CreateImage(SDL_Surface * surface)
{
SDL_Surface *converted;
NSBitmapImageRep *imgrep;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -53,6 +53,7 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
VkExtensionProperties *extensions = NULL;
Uint32 extensionCount = 0;
SDL_bool hasSurfaceExtension = SDL_FALSE;
SDL_bool hasMetalSurfaceExtension = SDL_FALSE;
SDL_bool hasMacOSSurfaceExtension = SDL_FALSE;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
@ -130,6 +131,8 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
for (Uint32 i = 0; i < extensionCount; i++) {
if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
hasSurfaceExtension = SDL_TRUE;
} else if (SDL_strcmp(VK_EXT_METAL_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
hasMetalSurfaceExtension = SDL_TRUE;
} else if (SDL_strcmp(VK_MVK_MACOS_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
hasMacOSSurfaceExtension = SDL_TRUE;
}
@ -139,9 +142,10 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
SDL_SetError("Installed Vulkan Portability library doesn't implement the "
VK_KHR_SURFACE_EXTENSION_NAME " extension");
goto fail;
} else if (!hasMacOSSurfaceExtension) {
} else if (!hasMetalSurfaceExtension && !hasMacOSSurfaceExtension) {
SDL_SetError("Installed Vulkan Portability library doesn't implement the "
VK_MVK_MACOS_SURFACE_EXTENSION_NAME "extension");
VK_EXT_METAL_SURFACE_EXTENSION_NAME " or "
VK_MVK_MACOS_SURFACE_EXTENSION_NAME " extensions");
goto fail;
}
return 0;
@ -168,7 +172,7 @@ SDL_bool Cocoa_Vulkan_GetInstanceExtensions(_THIS,
const char **names)
{
static const char *const extensionsForCocoa[] = {
VK_KHR_SURFACE_EXTENSION_NAME, VK_MVK_MACOS_SURFACE_EXTENSION_NAME
VK_KHR_SURFACE_EXTENSION_NAME, VK_EXT_METAL_SURFACE_EXTENSION_NAME
};
if (!_this->vulkan_config.loader_handle) {
SDL_SetError("Vulkan is not loaded");
@ -186,11 +190,14 @@ SDL_bool Cocoa_Vulkan_CreateSurface(_THIS,
{
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
(PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr;
PFN_vkCreateMetalSurfaceEXT vkCreateMetalSurfaceEXT =
(PFN_vkCreateMetalSurfaceEXT)vkGetInstanceProcAddr(
(VkInstance)instance,
"vkCreateMetalSurfaceEXT");
PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK =
(PFN_vkCreateMacOSSurfaceMVK)vkGetInstanceProcAddr(
(VkInstance)instance,
"vkCreateMacOSSurfaceMVK");
VkMacOSSurfaceCreateInfoMVK createInfo = {};
VkResult result;
SDL_MetalView metalview;
@ -199,9 +206,10 @@ SDL_bool Cocoa_Vulkan_CreateSurface(_THIS,
return SDL_FALSE;
}
if (!vkCreateMacOSSurfaceMVK) {
SDL_SetError(VK_MVK_MACOS_SURFACE_EXTENSION_NAME
" extension is not enabled in the Vulkan instance.");
if (!vkCreateMetalSurfaceEXT && !vkCreateMacOSSurfaceMVK) {
SDL_SetError(VK_EXT_METAL_SURFACE_EXTENSION_NAME " or "
VK_MVK_MACOS_SURFACE_EXTENSION_NAME
" extensions are not enabled in the Vulkan instance.");
return SDL_FALSE;
}
@ -210,17 +218,34 @@ SDL_bool Cocoa_Vulkan_CreateSurface(_THIS,
return SDL_FALSE;
}
createInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.pView = (const void *)metalview;
result = vkCreateMacOSSurfaceMVK(instance, &createInfo,
NULL, surface);
if (result != VK_SUCCESS) {
Cocoa_Metal_DestroyView(_this, metalview);
SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s",
SDL_Vulkan_GetResultString(result));
return SDL_FALSE;
if (vkCreateMetalSurfaceEXT) {
VkMetalSurfaceCreateInfoEXT createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.pLayer = (__bridge const CAMetalLayer *)
Cocoa_Metal_GetLayer(_this, metalview);
result = vkCreateMetalSurfaceEXT(instance, &createInfo, NULL, surface);
if (result != VK_SUCCESS) {
Cocoa_Metal_DestroyView(_this, metalview);
SDL_SetError("vkCreateMetalSurfaceEXT failed: %s",
SDL_Vulkan_GetResultString(result));
return SDL_FALSE;
}
} else {
VkMacOSSurfaceCreateInfoMVK createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.pView = (const void *)metalview;
result = vkCreateMacOSSurfaceMVK(instance, &createInfo,
NULL, surface);
if (result != VK_SUCCESS) {
Cocoa_Metal_DestroyView(_this, metalview);
SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s",
SDL_Vulkan_GetResultString(result));
return SDL_FALSE;
}
}
/* Unfortunately there's no SDL_Vulkan_DestroySurface function we can call

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -56,6 +56,7 @@ typedef enum
BOOL isDragAreaRunning;
}
-(BOOL) isTouchFromTrackpad:(NSEvent *)theEvent;
-(void) listen:(SDL_WindowData *) data;
-(void) pauseVisibleObservation;
-(void) resumeVisibleObservation;
@ -84,6 +85,7 @@ typedef enum
-(void) windowDidResignKey:(NSNotification *) aNotification;
-(void) windowDidChangeBackingProperties:(NSNotification *) aNotification;
-(void) windowDidChangeScreenProfile:(NSNotification *) aNotification;
-(void) windowDidChangeScreen:(NSNotification *) aNotification;
-(void) windowWillEnterFullScreen:(NSNotification *) aNotification;
-(void) windowDidEnterFullScreen:(NSNotification *) aNotification;
-(void) windowWillExitFullScreen:(NSNotification *) aNotification;
@ -126,6 +128,7 @@ typedef enum
@property (nonatomic) NSMutableArray *nscontexts;
@property (nonatomic) SDL_bool created;
@property (nonatomic) SDL_bool inWindowFullscreenTransition;
@property (nonatomic) NSInteger window_number;
@property (nonatomic) NSInteger flash_request;
@property (nonatomic) Cocoa_WindowListener *listener;
@property (nonatomic) SDL_VideoData *videodata;
@ -143,6 +146,7 @@ extern void Cocoa_SetWindowPosition(_THIS, SDL_Window * window);
extern void Cocoa_SetWindowSize(_THIS, SDL_Window * window);
extern void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window);
extern void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window);
extern void Cocoa_GetWindowSizeInPixels(_THIS, SDL_Window * window, int *w, int *h);
extern int Cocoa_SetWindowOpacity(_THIS, SDL_Window * window, float opacity);
extern void Cocoa_ShowWindow(_THIS, SDL_Window * window);
extern void Cocoa_HideWindow(_THIS, SDL_Window * window);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -102,7 +102,7 @@
SDL_Window *window = [self findSDLWindow];
if (window == NULL) {
return NO;
} else if ((window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_FULLSCREEN_DESKTOP)) != 0) {
} else if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_FULLSCREEN_DESKTOP)) {
return NO;
} else if ((window->flags & SDL_WINDOW_RESIZABLE) == 0) {
return NO;
@ -123,13 +123,14 @@
- (void)sendEvent:(NSEvent *)event
{
id delegate;
[super sendEvent:event];
if ([event type] != NSEventTypeLeftMouseUp) {
return;
}
id delegate = [self delegate];
delegate = [self delegate];
if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
return;
}
@ -163,24 +164,29 @@
NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
NSString *desiredType = [pasteboard availableTypeFromArray:types];
SDL_Window *sdlwindow = [self findSDLWindow];
NSData *data;
NSArray *array;
NSPoint point;
SDL_Mouse *mouse;
int x, y;
if (desiredType == nil) {
return NO; /* can't accept anything that's being dropped here. */
}
NSData *data = [pasteboard dataForType:desiredType];
data = [pasteboard dataForType:desiredType];
if (data == nil) {
return NO;
}
SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
/* Code addon to update the mouse location */
NSPoint point = [sender draggingLocation];
SDL_Mouse *mouse = SDL_GetMouse();
int x = (int)point.x;
int y = (int)(sdlwindow->h - point.y);
point = [sender draggingLocation];
mouse = SDL_GetMouse();
x = (int)point.x;
y = (int)(sdlwindow->h - point.y);
if (x >= 0 && x < sdlwindow->w && y >= 0 && y < sdlwindow->h) {
SDL_SendMouseMotion(sdlwindow, mouse->mouseID, 0, x, y);
}
@ -251,21 +257,24 @@ static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
}
static void
ScheduleContextUpdates(SDL_WindowData *data)
static void ScheduleContextUpdates(SDL_WindowData *data)
{
if (!data || !data.nscontexts) {
return;
}
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#if SDL_VIDEO_OPENGL
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
NSMutableArray *contexts = data.nscontexts;
NSOpenGLContext *currentContext;
NSMutableArray *contexts;
if (!data || !data.nscontexts) {
return;
}
currentContext = [NSOpenGLContext currentContext];
contexts = data.nscontexts;
@synchronized (contexts) {
for (SDLOpenGLContext *context in contexts) {
if (context == currentContext) {
@ -279,24 +288,29 @@ ScheduleContextUpdates(SDL_WindowData *data)
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif /* SDL_VIDEO_OPENGL */
}
/* !!! FIXME: this should use a hint callback. */
static int
GetHintCtrlClickEmulateRightClick()
static int GetHintCtrlClickEmulateRightClick()
{
return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, SDL_FALSE);
}
static NSUInteger
GetWindowWindowedStyle(SDL_Window * window)
static NSUInteger GetWindowWindowedStyle(SDL_Window * window)
{
NSUInteger style = 0;
/* IF YOU CHANGE ANY FLAGS IN HERE, PLEASE READ
the NSWindowStyleMaskBorderless comments in SetupWindowData()! */
/* always allow miniaturization, otherwise you can't programatically
minimize the window, whether there's a title bar or not */
NSUInteger style = NSWindowStyleMaskMiniaturizable;
if (window->flags & SDL_WINDOW_BORDERLESS) {
style = NSWindowStyleMaskBorderless;
style |= NSWindowStyleMaskBorderless;
} else {
style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
style |= (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable);
}
if (window->flags & SDL_WINDOW_RESIZABLE) {
style |= NSWindowStyleMaskResizable;
@ -304,8 +318,7 @@ GetWindowWindowedStyle(SDL_Window * window)
return style;
}
static NSUInteger
GetWindowStyle(SDL_Window * window)
static NSUInteger GetWindowStyle(SDL_Window * window)
{
NSUInteger style = 0;
@ -317,8 +330,7 @@ GetWindowStyle(SDL_Window * window)
return style;
}
static SDL_bool
SetWindowStyle(SDL_Window * window, NSUInteger style)
static SDL_bool SetWindowStyle(SDL_Window * window, NSUInteger style)
{
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
NSWindow *nswindow = data.nswindow;
@ -338,8 +350,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
return SDL_TRUE;
}
static SDL_bool
ShouldAdjustCoordinatesForGrab(SDL_Window * window)
static SDL_bool ShouldAdjustCoordinatesForGrab(SDL_Window * window)
{
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -357,8 +368,7 @@ ShouldAdjustCoordinatesForGrab(SDL_Window * window)
return SDL_FALSE;
}
static SDL_bool
AdjustCoordinatesForGrab(SDL_Window * window, int x, int y, CGPoint *adjusted)
static SDL_bool AdjustCoordinatesForGrab(SDL_Window * window, int x, int y, CGPoint *adjusted)
{
if (window->mouse_rect.w > 0 && window->mouse_rect.h > 0) {
SDL_Rect window_rect;
@ -383,7 +393,7 @@ AdjustCoordinatesForGrab(SDL_Window * window, int x, int y, CGPoint *adjusted)
}
}
if ((window->flags & SDL_WINDOW_MOUSE_GRABBED) != 0) {
if (window->flags & SDL_WINDOW_MOUSE_GRABBED) {
int left = window->x;
int right = left + window->w - 1;
int top = window->y;
@ -397,8 +407,7 @@ AdjustCoordinatesForGrab(SDL_Window * window, int x, int y, CGPoint *adjusted)
return SDL_FALSE;
}
static void
Cocoa_UpdateClipCursor(SDL_Window * window)
static void Cocoa_UpdateClipCursor(SDL_Window * window)
{
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -483,6 +492,7 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
[center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
[center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
[center addObserver:self selector:@selector(windowDidChangeScreenProfile:) name:NSWindowDidChangeScreenProfileNotification object:window];
[center addObserver:self selector:@selector(windowDidChangeScreen:) name:NSWindowDidChangeScreenNotification object:window];
[center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
[center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
[center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
@ -615,6 +625,7 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
[center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
[center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
[center removeObserver:self name:NSWindowDidChangeScreenProfileNotification object:window];
[center removeObserver:self name:NSWindowDidChangeScreenNotification object:window];
[center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
[center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
[center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
@ -652,7 +663,7 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
-(void) clearFocusClickPending:(NSInteger) button
{
if ((focusClickPending & (1 << button)) != 0) {
if (focusClickPending & (1 << button)) {
focusClickPending &= ~(1 << button);
if (focusClickPending == 0) {
[self onMovingOrFocusClickPendingStateCleared];
@ -763,15 +774,24 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
- (void)windowDidResize:(NSNotification *)aNotification
{
SDL_Window *window;
NSWindow *nswindow;
NSRect rect;
int x, y, w, h;
BOOL zoomed;
if (inFullscreenTransition) {
/* We'll take care of this at the end of the transition */
return;
}
SDL_Window *window = _data.window;
NSWindow *nswindow = _data.nswindow;
int x, y, w, h;
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
if (focusClickPending) {
focusClickPending = 0;
[self onMovingOrFocusClickPendingStateCleared];
}
window = _data.window;
nswindow = _data.nswindow;
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
x = (int)rect.origin.x;
y = (int)rect.origin.y;
@ -789,7 +809,12 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
const BOOL zoomed = [nswindow isZoomed];
/* isZoomed always returns true if the window is not resizable */
if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
zoomed = YES;
} else {
zoomed = NO;
}
if (!zoomed) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
} else if (zoomed) {
@ -844,10 +869,11 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
if ((isFullscreenSpace) && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
[NSMenu setMenuBarVisible:NO];
}
const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock;
_data.videodata.modifierFlags = (_data.videodata.modifierFlags & ~NSEventModifierFlagCapsLock) | newflags;
SDL_ToggleModState(KMOD_CAPS, newflags != 0);
{
const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock;
_data.videodata.modifierFlags = (_data.videodata.modifierFlags & ~NSEventModifierFlagCapsLock) | newflags;
SDL_ToggleModState(KMOD_CAPS, newflags ? SDL_TRUE : SDL_FALSE);
}
}
- (void)windowDidResignKey:(NSNotification *)aNotification
@ -893,6 +919,16 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
SDL_SendWindowEvent(_data.window, SDL_WINDOWEVENT_ICCPROF_CHANGED, 0, 0);
}
- (void)windowDidChangeScreen:(NSNotification *)aNotification
{
/*printf("WINDOWDIDCHANGESCREEN\n");*/
if (_data && _data.nscontexts) {
for (SDLOpenGLContext *context in _data.nscontexts) {
[context movedToNewScreen];
}
}
}
- (void)windowWillEnterFullScreen:(NSNotification *)aNotification
{
SDL_Window *window = _data.window;
@ -915,15 +951,13 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
isFullscreenSpace = NO;
inFullscreenTransition = NO;
[self windowDidExitFullScreen:nil];
}
- (void)windowDidEnterFullScreen:(NSNotification *)aNotification
{
SDL_Window *window = _data.window;
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
NSWindow *nswindow = data.nswindow;
inFullscreenTransition = NO;
@ -931,11 +965,6 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
pendingWindowOperation = PENDING_OPERATION_NONE;
[self setFullscreenSpace:NO];
} else {
/* Unset the resizable flag.
This is a workaround for https://bugzilla.libsdl.org/show_bug.cgi?id=3697
*/
SetWindowStyle(window, [nswindow styleMask] & (~NSWindowStyleMaskResizable));
if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
[NSMenu setMenuBarVisible:NO];
}
@ -972,16 +1001,16 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
- (void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
{
SDL_Window *window = _data.window;
if (window->is_destroying) {
return;
}
SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
isFullscreenSpace = YES;
inFullscreenTransition = NO;
[self windowDidEnterFullScreen:nil];
}
@ -1155,8 +1184,7 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
return NO; /* not a special area, carry on. */
}
static int
Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * window, const Uint8 state, const Uint8 button)
static int Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * window, const Uint8 state, const Uint8 button)
{
const SDL_MouseID mouseID = mouse->mouseID;
const int clicks = (int) [theEvent clickCount];
@ -1187,12 +1215,12 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
- (void)mouseDown:(NSEvent *)theEvent
{
SDL_Mouse *mouse = SDL_GetMouse();
int button;
if (!mouse) {
return;
}
int button;
/* Ignore events that aren't inside the client area (i.e. title bar.) */
if ([theEvent window]) {
NSRect windowRect = [[[theEvent window] contentView] frame];
@ -1244,12 +1272,12 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
- (void)mouseUp:(NSEvent *)theEvent
{
SDL_Mouse *mouse = SDL_GetMouse();
int button;
if (!mouse) {
return;
}
int button;
if ([self processHitTest:theEvent]) {
SDL_SendWindowEvent(_data.window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
return; /* stopped dragging, drop event. */
@ -1291,14 +1319,17 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
- (void)mouseMoved:(NSEvent *)theEvent
{
SDL_Mouse *mouse = SDL_GetMouse();
SDL_MouseID mouseID;
NSPoint point;
int x, y;
SDL_Window *window;
if (!mouse) {
return;
}
const SDL_MouseID mouseID = mouse->mouseID;
SDL_Window *window = _data.window;
NSPoint point;
int x, y;
mouseID = mouse->mouseID;
window = _data.window;
if ([self processHitTest:theEvent]) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
@ -1348,26 +1379,43 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
Cocoa_HandleMouseWheel(_data.window, theEvent);
}
- (BOOL)isTouchFromTrackpad:(NSEvent *)theEvent
{
SDL_Window *window = _data.window;
SDL_VideoData *videodata = ((__bridge SDL_WindowData *) window->driverdata).videodata;
/* if this a MacBook trackpad, we'll make input look like a synthesized
event. This is backwards from reality, but better matches user
expectations. You can make it look like a generic touch device instead
with the SDL_HINT_TRACKPAD_IS_TOUCH_ONLY hint. */
BOOL istrackpad = NO;
if (!videodata.trackpad_is_touch_only) {
@try {
istrackpad = ([theEvent subtype] == NSEventSubtypeMouseEvent);
}
@catch (NSException *e) {
/* if NSEvent type doesn't have subtype, such as NSEventTypeBeginGesture on
* macOS 10.5 to 10.10, then NSInternalInconsistencyException is thrown.
* This still prints a message to terminal so catching it's not an ideal solution.
*
* *** Assertion failure in -[NSEvent subtype]
*/
}
}
return istrackpad;
}
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
{
/* probably a MacBook trackpad; make this look like a synthesized event.
This is backwards from reality, but better matches user expectations. */
BOOL istrackpad = NO;
@try {
istrackpad = ([theEvent subtype] == NSEventSubtypeMouseEvent);
}
@catch (NSException *e) {
/* if NSEvent type doesn't have subtype, such as NSEventTypeBeginGesture on
* macOS 10.5 to 10.10, then NSInternalInconsistencyException is thrown.
* This still prints a message to terminal so catching it's not an ideal solution.
*
* *** Assertion failure in -[NSEvent subtype]
*/
}
NSSet *touches;
SDL_TouchID touchID;
int existingTouchCount;
const BOOL istrackpad = [self isTouchFromTrackpad:theEvent];
NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
const SDL_TouchID touchID = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[[touches anyObject] device];
int existingTouchCount = 0;
touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
touchID = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[[touches anyObject] device];
existingTouchCount = 0;
for (NSTouch* touch in touches) {
if ([touch phase] != NSTouchPhaseBegan) {
@ -1411,21 +1459,9 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
{
NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
/* probably a MacBook trackpad; make this look like a synthesized event.
This is backwards from reality, but better matches user expectations. */
BOOL istrackpad = NO;
@try {
istrackpad = ([theEvent subtype] == NSEventSubtypeMouseEvent);
}
@catch (NSException *e) {
/* if NSEvent type doesn't have subtype, such as NSEventTypeBeginGesture on
* macOS 10.5 to 10.10, then NSInternalInconsistencyException is thrown.
* This still prints a message to terminal so catching it's not an ideal solution.
*
* *** Assertion failure in -[NSEvent subtype]
*/
}
const BOOL istrackpad = [self isTouchFromTrackpad:theEvent];
SDL_FingerID fingerId;
float x, y;
for (NSTouch *touch in touches) {
const SDL_TouchID touchId = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[touch device];
@ -1457,9 +1493,9 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
return;
}
const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity];
float x = [touch normalizedPosition].x;
float y = [touch normalizedPosition].y;
fingerId = (SDL_FingerID)(intptr_t)[touch identity];
x = [touch normalizedPosition].x;
y = [touch normalizedPosition].y;
/* Make the origin the upper left instead of the lower left */
y = 1.0f - y;
@ -1554,8 +1590,9 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
- (void)resetCursorRects
{
SDL_Mouse *mouse;
[super resetCursorRects];
SDL_Mouse *mouse = SDL_GetMouse();
mouse = SDL_GetMouse();
if (mouse->cursor_shown && mouse->cur_cursor && !mouse->relative_mode) {
[self addCursorRect:[self bounds]
@ -1576,8 +1613,7 @@ Cocoa_SendMouseButtonClicks(SDL_Mouse * mouse, NSEvent *theEvent, SDL_Window * w
}
@end
static int
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, NSView *nsview, SDL_bool created)
static int SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, NSView *nsview, SDL_bool created)
{ @autoreleasepool
{
SDL_VideoData *videodata = (__bridge SDL_VideoData *) _this->driverdata;
@ -1592,6 +1628,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, NSView *nsview,
data.nswindow = nswindow;
data.created = created;
data.videodata = videodata;
data.window_number = nswindow.windowNumber;
data.nscontexts = [[NSMutableArray alloc] init];
data.sdlContentView = nsview;
@ -1623,7 +1660,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, NSView *nsview,
/* NSWindowStyleMaskBorderless is zero, and it's possible to be
Resizeable _and_ borderless, so we can't do a simple bitwise AND
of NSWindowStyleMaskBorderless here. */
if ((style & ~NSWindowStyleMaskResizable) == NSWindowStyleMaskBorderless) {
if ((style & ~(NSWindowStyleMaskResizable|NSWindowStyleMaskMiniaturizable)) == NSWindowStyleMaskBorderless) {
window->flags |= SDL_WINDOW_BORDERLESS;
} else {
window->flags &= ~SDL_WINDOW_BORDERLESS;
@ -1669,8 +1706,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, NSView *nsview,
return 0;
}}
int
Cocoa_CreateWindow(_THIS, SDL_Window * window)
int Cocoa_CreateWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_VideoData *videodata = (__bridge SDL_VideoData *) _this->driverdata;
@ -1680,6 +1716,9 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
SDL_Rect bounds;
NSUInteger style;
NSArray *screens = [NSScreen screens];
NSScreen *screen = nil;
SDLView *contentView;
BOOL highdpi;
Cocoa_GetDisplayBounds(_this, display, &bounds);
rect.origin.x = window->x;
@ -1691,7 +1730,6 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
style = GetWindowStyle(window);
/* Figure out which screen to place this window */
NSScreen *screen = nil;
for (NSScreen *candidate in screens) {
NSRect screenRect = [candidate frame];
if (rect.origin.x >= screenRect.origin.x &&
@ -1711,6 +1749,8 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
return SDL_SetError("%s", [[e reason] UTF8String]);
}
[nswindow setColorSpace:[NSColorSpace sRGBColorSpace]];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 /* Added in the 10.12.0 SDK. */
/* By default, don't allow users to make our window tabbed in 10.12 or later */
if ([nswindow respondsToSelector:@selector(setTabbingMode:)]) {
@ -1732,7 +1772,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
/* Create a default view for this window */
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
contentView = [[SDLView alloc] initWithFrame:rect];
[contentView setSDLWindow:window];
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
@ -1742,7 +1782,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
#endif
/* Note: as of the macOS 10.15 SDK, this defaults to YES instead of NO when
* the NSHighResolutionCapable boolean is set in Info.plist. */
BOOL highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
[contentView setWantsBestResolutionOpenGLSurface:highdpi];
#ifdef __clang__
#pragma clang diagnostic pop
@ -1765,7 +1805,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
if (!(window->flags & SDL_WINDOW_OPENGL)) {
return 0;
}
/* The rest of this macro mess is for OpenGL or OpenGL ES windows */
#if SDL_VIDEO_OPENGL_ES2
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
@ -1783,12 +1823,13 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
return 0;
}}
int
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
int Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
{ @autoreleasepool
{
NSView* nsview = nil;
NSWindow *nswindow = nil;
NSString *title;
BOOL highdpi;
if ([(__bridge id)data isKindOfClass:[NSWindow class]]) {
nswindow = (__bridge NSWindow*)data;
@ -1800,8 +1841,6 @@ Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
SDL_assert(false);
}
NSString *title;
/* Query the title from the existing window */
title = [nswindow title];
if (title) {
@ -1815,7 +1854,7 @@ Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
#endif
/* Note: as of the macOS 10.15 SDK, this defaults to YES instead of NO when
* the NSHighResolutionCapable boolean is set in Info.plist. */
BOOL highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
highdpi = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
[nsview setWantsBestResolutionOpenGLSurface:highdpi];
#ifdef __clang__
#pragma clang diagnostic pop
@ -1824,8 +1863,7 @@ Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
return SetupWindowData(_this, window, nswindow, nsview, SDL_FALSE);
}}
void
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
void Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
{ @autoreleasepool
{
const char *title = window->title ? window->title : "";
@ -1834,8 +1872,7 @@ Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
[nswindow setTitle:string];
}}
void
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
void Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
{ @autoreleasepool
{
NSImage *nsimage = Cocoa_CreateImage(icon);
@ -1845,8 +1882,7 @@ Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
}
}}
void
Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
void Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
@ -1868,8 +1904,7 @@ Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
ScheduleContextUpdates(windata);
}}
void
Cocoa_SetWindowSize(_THIS, SDL_Window * window)
void Cocoa_SetWindowSize(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
@ -1895,8 +1930,7 @@ Cocoa_SetWindowSize(_THIS, SDL_Window * window)
ScheduleContextUpdates(windata);
}}
void
Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
@ -1908,8 +1942,7 @@ Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
[windata.nswindow setContentMinSize:minSize];
}}
void
Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
@ -1921,8 +1954,24 @@ Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
[windata.nswindow setContentMaxSize:maxSize];
}}
void
Cocoa_ShowWindow(_THIS, SDL_Window * window)
void Cocoa_GetWindowSizeInPixels(_THIS, SDL_Window * window, int *w, int *h)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
NSView *contentView = windata.sdlContentView;
NSRect viewport = [contentView bounds];
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
/* This gives us the correct viewport for a Retina-enabled view. */
viewport = [contentView convertRectToBacking:viewport];
}
*w = viewport.size.width;
*h = viewport.size.height;
}}
void Cocoa_ShowWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windowData = ((__bridge SDL_WindowData *) window->driverdata);
@ -1935,8 +1984,7 @@ Cocoa_ShowWindow(_THIS, SDL_Window * window)
}
}}
void
Cocoa_HideWindow(_THIS, SDL_Window * window)
void Cocoa_HideWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSWindow *nswindow = ((__bridge SDL_WindowData *) window->driverdata).nswindow;
@ -1944,8 +1992,7 @@ Cocoa_HideWindow(_THIS, SDL_Window * window)
[nswindow orderOut:nil];
}}
void
Cocoa_RaiseWindow(_THIS, SDL_Window * window)
void Cocoa_RaiseWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windowData = ((__bridge SDL_WindowData *) window->driverdata);
@ -1962,8 +2009,7 @@ Cocoa_RaiseWindow(_THIS, SDL_Window * window)
[windowData.listener resumeVisibleObservation];
}}
void
Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
void Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *windata = (__bridge SDL_WindowData *) window->driverdata;
@ -1974,8 +2020,7 @@ Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
ScheduleContextUpdates(windata);
}}
void
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
void Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -1987,8 +2032,7 @@ Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
}
}}
void
Cocoa_RestoreWindow(_THIS, SDL_Window * window)
void Cocoa_RestoreWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSWindow *nswindow = ((__bridge SDL_WindowData *) window->driverdata).nswindow;
@ -2000,8 +2044,7 @@ Cocoa_RestoreWindow(_THIS, SDL_Window * window)
}
}}
void
Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
{ @autoreleasepool
{
if (SetWindowStyle(window, GetWindowStyle(window))) {
@ -2011,8 +2054,7 @@ Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
}
}}
void
Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
void Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
{ @autoreleasepool
{
/* Don't set this if we're in a space!
@ -2036,8 +2078,7 @@ Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
}
}}
void
Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window * window, SDL_bool on_top)
void Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window * window, SDL_bool on_top)
{ @autoreleasepool
{
NSWindow *nswindow = ((__bridge SDL_WindowData *) window->driverdata).nswindow;
@ -2048,8 +2089,7 @@ Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window * window, SDL_bool on_top)
}
}}
void
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
{ @autoreleasepool
{
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -2083,6 +2123,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
[nswindow setStyleMask:NSWindowStyleMaskBorderless];
} else {
NSRect frameRect;
rect.origin.x = window->windowed.x;
rect.origin.y = window->windowed.y;
rect.size.width = window->windowed.w;
@ -2098,7 +2139,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
[nswindow setStyleMask:GetWindowWindowedStyle(window)];
/* Hack to restore window decorations on Mac OS X 10.10 */
NSRect frameRect = [nswindow frame];
frameRect = [nswindow frame];
[nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
[nswindow setFrame:frameRect display:NO];
}
@ -2136,8 +2177,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
ScheduleContextUpdates(data);
}}
int
Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
{ @autoreleasepool
{
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
@ -2163,8 +2203,7 @@ Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
return 0;
}}
void*
Cocoa_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size)
void *Cocoa_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size)
{ @autoreleasepool
{
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -2200,41 +2239,45 @@ Cocoa_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size)
return retIccProfileData;
}}
int
Cocoa_GetWindowDisplayIndex(_THIS, SDL_Window * window)
int Cocoa_GetWindowDisplayIndex(_THIS, SDL_Window * window)
{ @autoreleasepool
{
NSScreen *screen;
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
/* Not recognized via CHECK_WINDOW_MAGIC */
if (data == NULL){
return 0;
if (data == nil) {
/* Don't set the error here, it hides other errors and is ignored anyway */
/*return SDL_SetError("Window data not set");*/
return -1;
}
/*
Considering that we already have the display coordinates in which the window is placed (described via displayframe)
instead of checking in which display the window is placed, we should check which SDL display matches the display described
via displayframe.
*/
NSRect displayframe = data.nswindow.screen.frame;
SDL_Point display_center;
SDL_Rect sdl_display_rect;
display_center.x = displayframe.origin.x + displayframe.size.width / 2;
display_center.y = displayframe.origin.y + displayframe.size.height / 2;
for (int i = 0; i < SDL_GetNumVideoDisplays(); i++){
SDL_GetDisplayBounds(i, &sdl_display_rect);
if (SDL_EnclosePoints(&display_center, 1, &sdl_display_rect, NULL)) {
return i;
/* NSWindow.screen may be nil when the window is off-screen. */
screen = data.nswindow.screen;
if (screen != nil) {
CGDirectDisplayID displayid;
int i;
/* https://developer.apple.com/documentation/appkit/nsscreen/1388360-devicedescription?language=objc */
displayid = [[screen.deviceDescription objectForKey:@"NSScreenNumber"] unsignedIntValue];
for (i = 0; i < _this->num_displays; i++) {
SDL_DisplayData *displaydata = (SDL_DisplayData *)_this->displays[i].driverdata;
if (displaydata != NULL && displaydata->display == displayid) {
return i;
}
}
}
SDL_SetError("Couldn't find the display where the window is attached to.");
return -1;
/* Other code may expect SDL_GetWindowDisplayIndex to always return a valid
* index for a window. The higher level GetWindowDisplayIndex code will fall
* back to a generic position-based query if the backend implementation
* fails. */
return SDL_SetError("Couldn't find the display where the window is located.");
}}
int
Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
{
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
@ -2257,14 +2300,12 @@ Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
return 0;
}
void
Cocoa_SetWindowMouseRect(_THIS, SDL_Window * window)
void Cocoa_SetWindowMouseRect(_THIS, SDL_Window * window)
{
Cocoa_UpdateClipCursor(window);
}
void
Cocoa_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
void Cocoa_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
{ @autoreleasepool
{
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -2285,13 +2326,13 @@ Cocoa_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
}
}}
void
Cocoa_DestroyWindow(_THIS, SDL_Window * window)
void Cocoa_DestroyWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *data = (SDL_WindowData *) CFBridgingRelease(window->driverdata);
if (data) {
NSArray *contexts;
if ([data.listener isInFullscreenSpace]) {
[NSMenu setMenuBarVisible:YES];
}
@ -2303,17 +2344,26 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window)
[data.nswindow close];
}
NSArray *contexts = [data.nscontexts copy];
#if SDL_VIDEO_OPENGL
contexts = [data.nscontexts copy];
for (SDLOpenGLContext *context in contexts) {
/* Calling setWindow:NULL causes the context to remove itself from the context list. */
/* Calling setWindow:NULL causes the context to remove itself from the context list. */
[context setWindow:NULL];
}
#endif /* SDL_VIDEO_OPENGL */
if (window->shaper) {
CFBridgingRelease(window->shaper->driverdata);
SDL_free(window->shaper);
window->shaper = NULL;
}
}
window->driverdata = NULL;
}}
SDL_bool
Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
{ @autoreleasepool
{
NSWindow *nswindow = ((__bridge SDL_WindowData *) window->driverdata).nswindow;
@ -2323,14 +2373,13 @@ Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
info->info.cocoa.window = nswindow;
return SDL_TRUE;
} else {
SDL_SetError("Application not compiled with SDL %d.%d",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
SDL_SetError("Application not compiled with SDL %d",
SDL_MAJOR_VERSION);
return SDL_FALSE;
}
}}
SDL_bool
Cocoa_IsWindowInFullscreenSpace(SDL_Window * window)
SDL_bool Cocoa_IsWindowInFullscreenSpace(SDL_Window * window)
{ @autoreleasepool
{
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -2342,8 +2391,7 @@ Cocoa_IsWindowInFullscreenSpace(SDL_Window * window)
}
}}
SDL_bool
Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
SDL_bool Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
{ @autoreleasepool
{
SDL_bool succeeded = SDL_FALSE;
@ -2385,14 +2433,12 @@ Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
return succeeded;
}}
int
Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)
int Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)
{
return 0; /* just succeed, the real work is done elsewhere. */
}
void
Cocoa_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept)
void Cocoa_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept)
{ @autoreleasepool
{
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
@ -2403,8 +2449,7 @@ Cocoa_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept)
}
}}
int
Cocoa_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation)
int Cocoa_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation)
{ @autoreleasepool
{
/* Note that this is app-wide and not window-specific! */
@ -2431,8 +2476,7 @@ Cocoa_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation)
return 0;
}}
int
Cocoa_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
int Cocoa_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
{ @autoreleasepool
{
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -51,8 +51,7 @@ static DFB_Theme theme_none = {
NULL
};
static void
DrawTriangle(IDirectFBSurface * s, int down, int x, int y, int w)
static void DrawTriangle(IDirectFBSurface * s, int down, int x, int y, int w)
{
int x1, x2, x3;
int y1, y2, y3;
@ -75,8 +74,7 @@ DrawTriangle(IDirectFBSurface * s, int down, int x, int y, int w)
s->FillTriangle(s, x1, y1, x2, y2, x3, y3);
}
static void
LoadFont(_THIS, SDL_Window * window)
static void LoadFont(_THIS, SDL_Window * window)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
@ -101,8 +99,7 @@ LoadFont(_THIS, SDL_Window * window)
}
}
static void
DrawCraption(_THIS, IDirectFBSurface * s, int x, int y, char *text)
static void DrawCraption(_THIS, IDirectFBSurface * s, int x, int y, char *text)
{
DFBSurfaceTextFlags flags;
@ -111,8 +108,7 @@ DrawCraption(_THIS, IDirectFBSurface * s, int x, int y, char *text)
s->DrawString(s, text, -1, x, y, flags);
}
void
DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window)
void DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
IDirectFBSurface *s = windata->window_surface;
@ -180,8 +176,7 @@ DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window)
windata->wm_needs_redraw = 0;
}
DFBResult
DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch)
DFBResult DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch)
{
SDL_DFB_WINDOWDATA(window);
IDirectFBWindow *dfbwin = windata->dfbwin;
@ -195,8 +190,7 @@ DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch)
return DFB_OK;
}
void
DirectFB_WM_AdjustWindowLayout(SDL_Window * window, int flags, int w, int h)
void DirectFB_WM_AdjustWindowLayout(SDL_Window * window, int flags, int w, int h)
{
SDL_DFB_WINDOWDATA(window);
@ -241,8 +235,7 @@ enum
WM_POS_BOTTOM = 0x40,
};
static int
WMIsClient(DFB_WindowData * p, int x, int y)
static int WMIsClient(DFB_WindowData * p, int x, int y)
{
x -= p->client.x;
y -= p->client.y;
@ -253,8 +246,7 @@ WMIsClient(DFB_WindowData * p, int x, int y)
return 1;
}
static int
WMPos(DFB_WindowData * p, int x, int y)
static int WMPos(DFB_WindowData * p, int x, int y)
{
int pos = WM_POS_NONE;
@ -284,8 +276,7 @@ WMPos(DFB_WindowData * p, int x, int y)
return pos;
}
int
DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
int DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
{
SDL_DFB_WINDOWDATA(window);
SDL_Window *grabbed_window = SDL_GetGrabbedWindow();

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -45,8 +45,7 @@ DFB_SYMS
static void *handle = NULL;
int
SDL_DirectFB_LoadLibrary(void)
int SDL_DirectFB_LoadLibrary(void)
{
int retval = 0;
@ -92,8 +91,7 @@ SDL_DirectFB_LoadLibrary(void)
return retval;
}
void
SDL_DirectFB_UnLoadLibrary(void)
void SDL_DirectFB_UnLoadLibrary(void)
{
if (handle != NULL) {
SDL_UnloadObject(handle);
@ -102,16 +100,16 @@ SDL_DirectFB_UnLoadLibrary(void)
}
#else
int
SDL_DirectFB_LoadLibrary(void)
int SDL_DirectFB_LoadLibrary(void)
{
return 1;
}
void
SDL_DirectFB_UnLoadLibrary(void)
void SDL_DirectFB_UnLoadLibrary(void)
{
}
#endif
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -34,8 +34,7 @@
#include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_windowevents_c.h"
#include "../../events/SDL_events_c.h"
#include "../../events/scancodes_linux.h"
#include "../../events/scancodes_xfree86.h"
#include "../../events/SDL_scancode_tables_c.h"
#include "SDL_DirectFB_events.h"
@ -92,8 +91,7 @@ static void UnicodeToUtf8( Uint16 w , char *utf8buf)
}
}
static void
FocusAllMice(_THIS, SDL_Window *window)
static void FocusAllMice(_THIS, SDL_Window *window)
{
#if USE_MULTI_API
SDL_DFB_DEVICEDATA(_this);
@ -107,8 +105,7 @@ FocusAllMice(_THIS, SDL_Window *window)
}
static void
FocusAllKeyboards(_THIS, SDL_Window *window)
static void FocusAllKeyboards(_THIS, SDL_Window *window)
{
#if USE_MULTI_API
SDL_DFB_DEVICEDATA(_this);
@ -121,8 +118,7 @@ FocusAllKeyboards(_THIS, SDL_Window *window)
#endif
}
static void
MotionAllMice(_THIS, int x, int y)
static void MotionAllMice(_THIS, int x, int y)
{
#if USE_MULTI_API
SDL_DFB_DEVICEDATA(_this);
@ -137,8 +133,7 @@ MotionAllMice(_THIS, int x, int y)
#endif
}
static int
KbdIndex(_THIS, int id)
static int KbdIndex(_THIS, int id)
{
SDL_DFB_DEVICEDATA(_this);
int index;
@ -150,8 +145,7 @@ KbdIndex(_THIS, int id)
return -1;
}
static int
ClientXY(DFB_WindowData * p, int *x, int *y)
static int ClientXY(DFB_WindowData * p, int *x, int *y)
{
int cx, cy;
@ -170,8 +164,7 @@ ClientXY(DFB_WindowData * p, int *x, int *y)
return 1;
}
static void
ProcessWindowEvent(_THIS, SDL_Window *sdlwin, DFBWindowEvent * evt)
static void ProcessWindowEvent(_THIS, SDL_Window *sdlwin, DFBWindowEvent * evt)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(sdlwin);
@ -304,8 +297,7 @@ ProcessWindowEvent(_THIS, SDL_Window *sdlwin, DFBWindowEvent * evt)
printf("Event Clazz %d\n", evt->clazz);
}
static void
ProcessInputEvent(_THIS, DFBInputEvent * ievt)
static void ProcessInputEvent(_THIS, DFBInputEvent * ievt)
{
SDL_DFB_DEVICEDATA(_this);
SDL_Keysym keysym;
@ -407,8 +399,7 @@ ProcessInputEvent(_THIS, DFBInputEvent * ievt)
}
}
void
DirectFB_PumpEventsWindow(_THIS)
void DirectFB_PumpEventsWindow(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
DFBInputEvent ievt;
@ -449,8 +440,7 @@ DirectFB_PumpEventsWindow(_THIS)
}
}
void
DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keymap, int numkeys)
void DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keymap, int numkeys)
{
int i;
@ -577,8 +567,7 @@ DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keymap, int numkeys)
}
static SDL_Keysym *
DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_Keysym * keysym, Uint32 *unicode)
static SDL_Keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_Keysym * keysym, Uint32 *unicode)
{
SDL_DFB_DEVICEDATA(_this);
int kbd_idx = 0; /* Window events lag the device source KbdIndex(_this, evt->device_id); */
@ -607,8 +596,7 @@ DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_Keysym * keysym, Uint32 *
return keysym;
}
static SDL_Keysym *
DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
static SDL_Keysym *DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
SDL_Keysym * keysym, Uint32 *unicode)
{
SDL_DFB_DEVICEDATA(_this);
@ -637,8 +625,7 @@ DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
return keysym;
}
static int
DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
{
switch (button) {
case DIBI_LEFT:
@ -652,16 +639,13 @@ DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
}
}
static DFBEnumerationResult
EnumKeyboards(DFBInputDeviceID device_id,
DFBInputDeviceDescription desc, void *callbackdata)
static DFBEnumerationResult EnumKeyboards(DFBInputDeviceID device_id, DFBInputDeviceDescription desc, void *callbackdata)
{
cb_data *cb = callbackdata;
DFB_DeviceData *devdata = cb->devdata;
#if USE_MULTI_API
SDL_Keyboard keyboard;
#endif
SDL_Keycode keymap[SDL_NUM_SCANCODES];
if (!cb->sys_kbd) {
if (cb->sys_ids) {
@ -685,23 +669,15 @@ EnumKeyboards(DFBInputDeviceID device_id,
devdata->keyboard[devdata->num_keyboard].is_generic = 0;
if (!SDL_strncmp("X11", desc.name, 3))
{
devdata->keyboard[devdata->num_keyboard].map = xfree86_scancode_table2;
devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(xfree86_scancode_table2);
devdata->keyboard[devdata->num_keyboard].map = SDL_GetScancodeTable(SDL_SCANCODE_TABLE_XFREE86_2, &devdata->keyboard[devdata->num_keyboard].map_size);
devdata->keyboard[devdata->num_keyboard].map_adjust = 8;
} else {
devdata->keyboard[devdata->num_keyboard].map = linux_scancode_table;
devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(linux_scancode_table);
devdata->keyboard[devdata->num_keyboard].map = SDL_GetScancodeTable(SDL_SCANCODE_TABLE_LINUX, &devdata->keyboard[devdata->num_keyboard].map_size);
devdata->keyboard[devdata->num_keyboard].map_adjust = 0;
}
SDL_DFB_LOG("Keyboard %d - %s\n", device_id, desc.name);
SDL_GetDefaultKeymap(keymap);
#if USE_MULTI_API
SDL_SetKeymap(devdata->num_keyboard, 0, keymap, SDL_NUM_SCANCODES);
#else
SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
#endif
devdata->num_keyboard++;
if (cb->sys_kbd)
@ -710,8 +686,7 @@ EnumKeyboards(DFBInputDeviceID device_id,
return DFENUM_OK;
}
void
DirectFB_InitKeyboard(_THIS)
void DirectFB_InitKeyboard(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
cb_data cb;
@ -740,8 +715,7 @@ DirectFB_InitKeyboard(_THIS)
}
}
void
DirectFB_QuitKeyboard(_THIS)
void DirectFB_QuitKeyboard(_THIS)
{
/* SDL_DFB_DEVICEDATA(_this); */
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -42,8 +42,7 @@ struct modes_callback_t
SDL_DisplayMode *modelist;
};
static DFBEnumerationResult
EnumModesCallback(int width, int height, int bpp, void *data)
static DFBEnumerationResult EnumModesCallback(int width, int height, int bpp, void *data)
{
struct modes_callback_t *modedata = (struct modes_callback_t *) data;
SDL_DisplayMode mode;
@ -61,9 +60,7 @@ EnumModesCallback(int width, int height, int bpp, void *data)
return DFENUM_OK;
}
static DFBEnumerationResult
EnumScreensCallback(DFBScreenID screen_id, DFBScreenDescription desc,
void *callbackdata)
static DFBEnumerationResult EnumScreensCallback(DFBScreenID screen_id, DFBScreenDescription desc, void *callbackdata)
{
struct screen_callback_t *devdata = (struct screen_callback_t *) callbackdata;
@ -71,9 +68,7 @@ EnumScreensCallback(DFBScreenID screen_id, DFBScreenDescription desc,
return DFENUM_OK;
}
static DFBEnumerationResult
EnumLayersCallback(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
void *callbackdata)
static DFBEnumerationResult EnumLayersCallback(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc, void *callbackdata)
{
struct screen_callback_t *devdata = (struct screen_callback_t *) callbackdata;
@ -89,8 +84,7 @@ EnumLayersCallback(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
return DFENUM_OK;
}
static void
CheckSetDisplayMode(_THIS, SDL_VideoDisplay * display, DFB_DisplayData * data, SDL_DisplayMode * mode)
static void CheckSetDisplayMode(_THIS, SDL_VideoDisplay * display, DFB_DisplayData * data, SDL_DisplayMode * mode)
{
SDL_DFB_DEVICEDATA(_this);
DFBDisplayLayerConfig config;
@ -125,8 +119,7 @@ CheckSetDisplayMode(_THIS, SDL_VideoDisplay * display, DFB_DisplayData * data, S
}
void
DirectFB_SetContext(_THIS, SDL_Window *window)
void DirectFB_SetContext(_THIS, SDL_Window *window)
{
#if (DFB_VERSION_ATLEAST(1,0,0))
/* FIXME: does not work on 1.0/1.2 with radeon driver
@ -144,8 +137,7 @@ DirectFB_SetContext(_THIS, SDL_Window *window)
#endif
}
void
DirectFB_InitModes(_THIS)
void DirectFB_InitModes(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
IDirectFBDisplayLayer *layer = NULL;
@ -269,8 +261,7 @@ DirectFB_InitModes(_THIS)
return;
}
void
DirectFB_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
void DirectFB_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{
SDL_DFB_DEVICEDATA(_this);
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
@ -304,8 +295,7 @@ error:
return;
}
int
DirectFB_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
int DirectFB_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
/*
* FIXME: video mode switch is currently broken for 1.2.0
@ -375,8 +365,7 @@ DirectFB_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mod
return -1;
}
void
DirectFB_QuitModes(_THIS)
void DirectFB_QuitModes(_THIS)
{
SDL_DisplayMode tmode;
int i;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -74,8 +74,7 @@ static const char *arrow[] = {
" ",
};
static SDL_Cursor *
DirectFB_CreateDefaultCursor(void)
static SDL_Cursor *DirectFB_CreateDefaultCursor(void)
{
SDL_VideoDevice *dev = SDL_GetVideoDevice();
@ -127,8 +126,7 @@ DirectFB_CreateDefaultCursor(void)
}
/* Create a cursor from a surface */
static SDL_Cursor *
DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
static SDL_Cursor *DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
{
SDL_VideoDevice *dev = SDL_GetVideoDevice();
@ -174,8 +172,7 @@ DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
}
/* Show the specified cursor, or hide if cursor is NULL */
static int
DirectFB_ShowCursor(SDL_Cursor * cursor)
static int DirectFB_ShowCursor(SDL_Cursor * cursor)
{
SDL_DFB_CURSORDATA(cursor);
SDL_Window *window;
@ -215,8 +212,7 @@ DirectFB_ShowCursor(SDL_Cursor * cursor)
}
/* Free a window manager cursor */
static void
DirectFB_FreeCursor(SDL_Cursor * cursor)
static void DirectFB_FreeCursor(SDL_Cursor * cursor)
{
SDL_DFB_CURSORDATA(cursor);
@ -226,8 +222,7 @@ DirectFB_FreeCursor(SDL_Cursor * cursor)
}
/* Warp the mouse to (x,y) */
static void
DirectFB_WarpMouse(SDL_Window * window, int x, int y)
static void DirectFB_WarpMouse(SDL_Window * window, int x, int y)
{
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
@ -252,9 +247,7 @@ static void DirectFB_FreeMouse(SDL_Mouse * mouse);
static int id_mask;
static DFBEnumerationResult
EnumMice(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
void *callbackdata)
static DFBEnumerationResult EnumMice(DFBInputDeviceID device_id, DFBInputDeviceDescription desc, void *callbackdata)
{
DFB_DeviceData *devdata = callbackdata;
@ -277,8 +270,7 @@ EnumMice(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
return DFENUM_OK;
}
void
DirectFB_InitMouse(_THIS)
void DirectFB_InitMouse(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
@ -310,8 +302,7 @@ DirectFB_InitMouse(_THIS)
}
}
void
DirectFB_QuitMouse(_THIS)
void DirectFB_QuitMouse(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
@ -324,15 +315,13 @@ DirectFB_QuitMouse(_THIS)
/* This is called when a mouse motion event occurs */
static void
DirectFB_MoveCursor(SDL_Cursor * cursor)
static void DirectFB_MoveCursor(SDL_Cursor * cursor)
{
}
/* Warp the mouse to (x,y) */
static void
DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_Window * window, int x, int y)
static void DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_Window * window, int x, int y)
{
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
@ -350,16 +339,14 @@ DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_Window * window, int x, int y)
}
/* Free the mouse when it's time */
static void
DirectFB_FreeMouse(SDL_Mouse * mouse)
static void DirectFB_FreeMouse(SDL_Mouse * mouse)
{
/* nothing yet */
}
#else /* USE_MULTI_API */
void
DirectFB_InitMouse(_THIS)
void DirectFB_InitMouse(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
@ -375,12 +362,10 @@ DirectFB_InitMouse(_THIS)
devdata->num_mice = 1;
}
void
DirectFB_QuitMouse(_THIS)
void DirectFB_QuitMouse(_THIS)
{
}
#endif
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -60,8 +60,7 @@ struct SDL_GLDriverData
static void DirectFB_GL_UnloadLibrary(_THIS);
int
DirectFB_GL_Initialize(_THIS)
int DirectFB_GL_Initialize(_THIS)
{
if (_this->gl_data) {
return 0;
@ -91,8 +90,7 @@ DirectFB_GL_Initialize(_THIS)
return 0;
}
void
DirectFB_GL_Shutdown(_THIS)
void DirectFB_GL_Shutdown(_THIS)
{
if (!_this->gl_data || (--_this->gl_data->initialized > 0)) {
return;
@ -104,8 +102,7 @@ DirectFB_GL_Shutdown(_THIS)
_this->gl_data = NULL;
}
int
DirectFB_GL_LoadLibrary(_THIS, const char *path)
int DirectFB_GL_LoadLibrary(_THIS, const char *path)
{
void *handle = NULL;
@ -146,8 +143,7 @@ DirectFB_GL_LoadLibrary(_THIS, const char *path)
return 0;
}
static void
DirectFB_GL_UnloadLibrary(_THIS)
static void DirectFB_GL_UnloadLibrary(_THIS)
{
#if 0
int ret = GL_UnloadObject(_this->gl_config.dll_handle);
@ -160,8 +156,7 @@ DirectFB_GL_UnloadLibrary(_THIS)
_this->gl_data = NULL;
}
void *
DirectFB_GL_GetProcAddress(_THIS, const char *proc)
void *DirectFB_GL_GetProcAddress(_THIS, const char *proc)
{
void *handle;
@ -169,8 +164,7 @@ DirectFB_GL_GetProcAddress(_THIS, const char *proc)
return GL_LoadFunction(handle, proc);
}
SDL_GLContext
DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
SDL_GLContext DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
DirectFB_GLContext *context;
@ -202,8 +196,7 @@ DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
return NULL;
}
int
DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
int DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{
DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
DirectFB_GLContext *p;
@ -227,20 +220,17 @@ DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
return -1;
}
int
DirectFB_GL_SetSwapInterval(_THIS, int interval)
int DirectFB_GL_SetSwapInterval(_THIS, int interval)
{
return SDL_Unsupported();
}
int
DirectFB_GL_GetSwapInterval(_THIS)
int DirectFB_GL_GetSwapInterval(_THIS)
{
return 0;
}
int
DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
int DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
DirectFB_GLContext *p;
@ -265,8 +255,7 @@ DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
return -1;
}
void
DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context)
void DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context)
{
DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
DirectFB_GLContext *p;
@ -285,8 +274,7 @@ DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context)
SDL_DFB_FREE(ctx);
}
void
DirectFB_GL_FreeWindowContexts(_THIS, SDL_Window * window)
void DirectFB_GL_FreeWindowContexts(_THIS, SDL_Window * window)
{
DirectFB_GLContext *p;
@ -299,8 +287,7 @@ DirectFB_GL_FreeWindowContexts(_THIS, SDL_Window * window)
}
}
void
DirectFB_GL_ReAllocWindowContexts(_THIS, SDL_Window * window)
void DirectFB_GL_ReAllocWindowContexts(_THIS, SDL_Window * window)
{
DirectFB_GLContext *p;
@ -315,8 +302,7 @@ DirectFB_GL_ReAllocWindowContexts(_THIS, SDL_Window * window)
}
}
void
DirectFB_GL_DestroyWindowContexts(_THIS, SDL_Window * window)
void DirectFB_GL_DestroyWindowContexts(_THIS, SDL_Window * window)
{
DirectFB_GLContext *p;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -79,16 +79,14 @@ typedef struct
#endif
} DirectFB_TextureData;
static SDL_INLINE void
SDLtoDFBRect(const SDL_Rect * sr, DFBRectangle * dr)
static void SDLtoDFBRect(const SDL_Rect * sr, DFBRectangle * dr)
{
dr->x = sr->x;
dr->y = sr->y;
dr->h = sr->h;
dr->w = sr->w;
}
static SDL_INLINE void
SDLtoDFBRect_Float(const SDL_FRect * sr, DFBRectangle * dr)
static void SDLtoDFBRect_Float(const SDL_FRect * sr, DFBRectangle * dr)
{
dr->x = sr->x;
dr->y = sr->y;
@ -97,8 +95,7 @@ SDLtoDFBRect_Float(const SDL_FRect * sr, DFBRectangle * dr)
}
static int
TextureHasAlpha(DirectFB_TextureData * data)
static int TextureHasAlpha(DirectFB_TextureData * data)
{
/* Drawing primitive ? */
if (!data)
@ -149,9 +146,7 @@ static SDL_INLINE IDirectFBWindow *get_dfb_window(SDL_Window *window)
return wm_info.info.dfb.window;
}
static void
SetBlendMode(DirectFB_RenderData * data, int blendMode,
DirectFB_TextureData * source)
static void SetBlendMode(DirectFB_RenderData * data, int blendMode, DirectFB_TextureData * source)
{
IDirectFBSurface *destsurf = data->target;
@ -201,6 +196,7 @@ SetBlendMode(DirectFB_RenderData * data, int blendMode,
case SDL_BLENDMODE_MUL:
data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
data->drawFlags = DSDRAW_BLEND;
/* FIXME SDL_BLENDMODE_MUL is simplified, and dstA is in fact un-changed.*/
SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_DESTCOLOR));
SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA));
@ -210,8 +206,7 @@ SetBlendMode(DirectFB_RenderData * data, int blendMode,
}
}
static int
PrepareDraw(SDL_Renderer * renderer, const SDL_RenderCommand *cmd)
static int PrepareDraw(SDL_Renderer * renderer, const SDL_RenderCommand *cmd)
{
DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
IDirectFBSurface *destsurf = data->target;
@ -245,8 +240,7 @@ PrepareDraw(SDL_Renderer * renderer, const SDL_RenderCommand *cmd)
return -1;
}
static void
DirectFB_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
static void DirectFB_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
{
SDL_DFB_RENDERERDATA(renderer);
@ -258,8 +252,7 @@ DirectFB_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
}
}
static void
DirectFB_ActivateRenderer(SDL_Renderer * renderer)
static void DirectFB_ActivateRenderer(SDL_Renderer * renderer)
{
SDL_DFB_RENDERERDATA(renderer);
@ -268,8 +261,7 @@ DirectFB_ActivateRenderer(SDL_Renderer * renderer)
}
}
static int
DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture)
static int DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture)
{
SDL_Window *window = renderer->window;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
@ -340,8 +332,7 @@ void DirectFB_SetTexturePalette(SDL_Renderer *renderer, SDL_Texture *texture, SD
data->palette->SetEntries(data->palette, dfbpal, pal->ncolors, 0);
}
static int
DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
static int DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
SDL_Window *window = renderer->window;
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
@ -436,8 +427,7 @@ DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
}
#if 0
static int
DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
static int DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
#if (DFB_VERSION_ATLEAST(1,2,0))
@ -465,8 +455,7 @@ DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
}
#endif
static int
DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
static int DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{
DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
@ -522,8 +511,7 @@ DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
}
static int
DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
static int DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch)
{
DirectFB_TextureData *texturedata =
@ -560,8 +548,7 @@ DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
return -1;
}
static void
DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
static void DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
DirectFB_TextureData *texturedata =
(DirectFB_TextureData *) texture->driverdata;
@ -574,14 +561,12 @@ DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
}
}
static void
DirectFB_SetTextureScaleMode()
static void DirectFB_SetTextureScaleMode()
{
}
#if 0
static void
DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
static void DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
int numrects, const SDL_Rect * rects)
{
DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
@ -610,16 +595,14 @@ static int DirectFB_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * textu
}
static int
DirectFB_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
static int DirectFB_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
{
return 0; /* nothing to do in this backend. */
}
static int
DirectFB_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
static int DirectFB_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
{
const size_t len = count * sizeof (SDL_FPoint);
const size_t len = count * sizeof(SDL_FPoint);
SDL_FPoint *verts = (SDL_FPoint *) SDL_AllocateRenderVertices(renderer, len, 0, &cmd->data.draw.first);
if (!verts) {
@ -631,8 +614,7 @@ DirectFB_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const
return 0;
}
static int
DirectFB_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
static int DirectFB_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y)
@ -642,7 +624,7 @@ DirectFB_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Textu
float *verts;
int sz = 2 + 4 + (texture ? 2 : 0);
verts = (float *) SDL_AllocateRenderVertices(renderer, count * sz * sizeof (float), 0, &cmd->data.draw.first);
verts = (float *) SDL_AllocateRenderVertices(renderer, count * sz * sizeof(float), 0, &cmd->data.draw.first);
if (!verts) {
return -1;
}
@ -684,10 +666,9 @@ DirectFB_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Textu
return 0;
}
static int
DirectFB_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
static int DirectFB_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
{
const size_t len = count * sizeof (SDL_FRect);
const size_t len = count * sizeof(SDL_FRect);
SDL_FRect *verts = (SDL_FRect *) SDL_AllocateRenderVertices(renderer, len, 0, &cmd->data.draw.first);
if (!verts) {
@ -699,11 +680,10 @@ DirectFB_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const S
return 0;
}
static int
DirectFB_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
static int DirectFB_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect)
{
DFBRectangle *verts = (DFBRectangle *) SDL_AllocateRenderVertices(renderer, 2 * sizeof (DFBRectangle), 0, &cmd->data.draw.first);
DFBRectangle *verts = (DFBRectangle *) SDL_AllocateRenderVertices(renderer, 2 * sizeof(DFBRectangle), 0, &cmd->data.draw.first);
if (!verts) {
return -1;
@ -717,8 +697,7 @@ DirectFB_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture
return 0;
}
static int
DirectFB_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
static int DirectFB_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
{
/* !!! FIXME: there are probably some good optimization wins in here if someone wants to look it over. */
DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
@ -1025,8 +1004,7 @@ DirectFB_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *
}
static void
DirectFB_RenderPresent(SDL_Renderer * renderer)
static int DirectFB_RenderPresent(SDL_Renderer * renderer)
{
DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
SDL_Window *window = renderer->window;
@ -1056,10 +1034,10 @@ DirectFB_RenderPresent(SDL_Renderer * renderer)
/* Send the data to the display */
SDL_DFB_CHECK(windata->window_surface->Flip(windata->window_surface, NULL,
data->flipflags));
return 0;
}
static void
DirectFB_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
static void DirectFB_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
@ -1084,8 +1062,7 @@ DirectFB_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
texture->driverdata = NULL;
}
static void
DirectFB_DestroyRenderer(SDL_Renderer * renderer)
static void DirectFB_DestroyRenderer(SDL_Renderer * renderer)
{
DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
#if 0
@ -1099,8 +1076,7 @@ DirectFB_DestroyRenderer(SDL_Renderer * renderer)
SDL_free(renderer);
}
static int
DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
static int DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch)
{
Uint32 sdl_format;
@ -1127,8 +1103,7 @@ DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
}
#if 0
static int
DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
static int DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, const void * pixels, int pitch)
{
SDL_Window *window = renderer->window;
@ -1155,8 +1130,7 @@ DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
#endif
SDL_Renderer *
DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags)
SDL_Renderer *DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags)
{
IDirectFBSurface *winsurf = get_dfb_surface(window);
/*SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);*/

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -28,18 +28,27 @@
#include "../SDL_shape_internals.h"
SDL_WindowShaper*
DirectFB_CreateShaper(SDL_Window* window) {
SDL_WindowShaper *DirectFB_CreateShaper(SDL_Window* window)
{
SDL_WindowShaper* result = NULL;
SDL_ShapeData* data;
int resized_properly;
result = SDL_malloc(sizeof(SDL_WindowShaper));
if (!result) {
SDL_OutOfMemory();
return NULL;
}
result->window = window;
result->mode.mode = ShapeModeDefault;
result->mode.parameters.binarizationCutoff = 1;
result->userx = result->usery = 0;
data = SDL_malloc(sizeof(SDL_ShapeData));
if (!data) {
SDL_free(result);
SDL_OutOfMemory();
return NULL;
}
result->driverdata = data;
data->surface = NULL;
window->shaper = result;
@ -49,8 +58,8 @@ DirectFB_CreateShaper(SDL_Window* window) {
return result;
}
int
DirectFB_ResizeWindowShape(SDL_Window* window) {
int DirectFB_ResizeWindowShape(SDL_Window* window)
{
SDL_ShapeData* data = window->shaper->driverdata;
SDL_assert(data != NULL);
@ -64,8 +73,8 @@ DirectFB_ResizeWindowShape(SDL_Window* window) {
return 0;
}
int
DirectFB_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
int DirectFB_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode)
{
if(shaper == NULL || shape == NULL || shaper->driverdata == NULL)
return -1;
@ -94,10 +103,9 @@ DirectFB_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowSh
dsc.pixelformat = DSPF_ARGB;
SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, &data->surface));
SDL_DFB_CALLOC(bitmap, shape->w * shape->h, 1);
/* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */
SDL_DFB_ALLOC_CLEAR(bitmap, shape->w * shape->h);
SDL_CalculateShapeBitmap(shaper->mode,shape,bitmap,1);
SDL_CalculateShapeBitmap(shaper->mode, shape, bitmap, 1);
src = bitmap;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -61,7 +61,7 @@
static int DirectFB_VideoInit(_THIS);
static void DirectFB_VideoQuit(_THIS);
static SDL_VideoDevice *DirectFB_CreateDevice(int devindex);
static SDL_VideoDevice *DirectFB_CreateDevice(void);
VideoBootStrap DirectFB_bootstrap = {
"directfb", "DirectFB",
@ -74,16 +74,14 @@ static const DirectFBAccelerationMaskNames(acceleration_mask);
/* DirectFB driver bootstrap functions */
static void
DirectFB_DeleteDevice(SDL_VideoDevice * device)
static void DirectFB_DeleteDevice(SDL_VideoDevice * device)
{
SDL_DirectFB_UnLoadLibrary();
SDL_DFB_FREE(device->driverdata);
SDL_DFB_FREE(device);
}
static SDL_VideoDevice *
DirectFB_CreateDevice(int devindex)
static SDL_VideoDevice *DirectFB_CreateDevice(void)
{
SDL_VideoDevice *device;
@ -154,8 +152,7 @@ DirectFB_CreateDevice(int devindex)
return (0);
}
static void
DirectFB_DeviceInformation(IDirectFB * dfb)
static void DirectFB_DeviceInformation(IDirectFB * dfb)
{
DFBGraphicsDeviceDescription desc;
int n;
@ -206,8 +203,7 @@ static int readBoolEnv(const char *env_name, int def_val)
return def_val;
}
static int
DirectFB_VideoInit(_THIS)
static int DirectFB_VideoInit(_THIS)
{
IDirectFB *dfb = NULL;
DFB_DeviceData *devdata = NULL;
@ -282,8 +278,7 @@ DirectFB_VideoInit(_THIS)
return -1;
}
static void
DirectFB_VideoQuit(_THIS)
static void DirectFB_VideoQuit(_THIS)
{
DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
@ -379,8 +374,7 @@ static const struct {
{ DSPF_UNKNOWN, SDL_PIXELFORMAT_YVYU }, /**< Packed mode: Y0+V0+Y1+U0 (1 pla */
};
Uint32
DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat)
Uint32 DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat)
{
int i;
@ -392,8 +386,7 @@ DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat)
return SDL_PIXELFORMAT_UNKNOWN;
}
DFBSurfacePixelFormat
DirectFB_SDLToDFBPixelFormat(Uint32 format)
DFBSurfacePixelFormat DirectFB_SDLToDFBPixelFormat(Uint32 format)
{
int i;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

Some files were not shown because too many files have changed in this diff Show more