early-access version 1611

This commit is contained in:
pineappleEA
2021-04-18 05:35:25 +02:00
parent 16f54e367d
commit 18db69f039
1409 changed files with 545335 additions and 10 deletions

1591
externals/SDL/src/video/SDL_RLEaccel.c vendored Executable file

File diff suppressed because it is too large Load Diff

34
externals/SDL/src/video/SDL_RLEaccel_c.h vendored Executable file
View File

@@ -0,0 +1,34 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_RLEaccel_c_h_
#define SDL_RLEaccel_c_h_
#include "../SDL_internal.h"
/* Useful functions and variables from SDL_RLEaccel.c */
extern int SDL_RLESurface(SDL_Surface * surface);
extern void SDL_UnRLESurface(SDL_Surface * surface, int recode);
#endif /* SDL_RLEaccel_c_h_ */
/* vi: set ts=4 sw=4 expandtab: */

296
externals/SDL/src/video/SDL_blit.c vendored Executable file
View File

@@ -0,0 +1,296 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#include "SDL_video.h"
#include "SDL_sysvideo.h"
#include "SDL_blit.h"
#include "SDL_blit_auto.h"
#include "SDL_blit_copy.h"
#include "SDL_blit_slow.h"
#include "SDL_RLEaccel_c.h"
#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)
{
int okay;
int src_locked;
int dst_locked;
/* Everything is okay at the beginning... */
okay = 1;
/* Lock the destination if it's in hardware */
dst_locked = 0;
if (SDL_MUSTLOCK(dst)) {
if (SDL_LockSurface(dst) < 0) {
okay = 0;
} else {
dst_locked = 1;
}
}
/* Lock the source if it's in hardware */
src_locked = 0;
if (SDL_MUSTLOCK(src)) {
if (SDL_LockSurface(src) < 0) {
okay = 0;
} else {
src_locked = 1;
}
}
/* Set up source and destination buffer pointers, and BLIT! */
if (okay && !SDL_RectEmpty(srcrect)) {
SDL_BlitFunc RunBlit;
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_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;
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;
/* Run the actual software blit */
RunBlit(info);
}
/* We need to unlock the surfaces if they're locked */
if (dst_locked) {
SDL_UnlockSurface(dst);
}
if (src_locked) {
SDL_UnlockSurface(src);
}
/* Blit is done! */
return (okay ? 0 : -1);
}
#if SDL_HAVE_BLIT_AUTO
#ifdef __MACOSX__
#include <sys/sysctl.h>
static SDL_bool
SDL_UseAltivecPrefetch()
{
const char key[] = "hw.l3cachesize";
u_int64_t result = 0;
size_t typeSize = sizeof(result);
if (sysctlbyname(key, &result, &typeSize, NULL, 0) == 0 && result > 0) {
return SDL_TRUE;
} else {
return SDL_FALSE;
}
}
#else
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)
{
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;
/* Get the available CPU features */
if (features == 0x7fffffff) {
const char *override = SDL_getenv("SDL_BLIT_CPU_FEATURES");
features = SDL_CPU_ANY;
/* Allow an override for testing .. */
if (override) {
SDL_sscanf(override, "%u", &features);
} else {
if (SDL_HasMMX()) {
features |= SDL_CPU_MMX;
}
if (SDL_Has3DNow()) {
features |= SDL_CPU_3DNOW;
}
if (SDL_HasSSE()) {
features |= SDL_CPU_SSE;
}
if (SDL_HasSSE2()) {
features |= SDL_CPU_SSE2;
}
if (SDL_HasAltiVec()) {
if (SDL_UseAltivecPrefetch()) {
features |= SDL_CPU_ALTIVEC_PREFETCH;
} else {
features |= SDL_CPU_ALTIVEC_NOPREFETCH;
}
}
}
}
for (i = 0; entries[i].func; ++i) {
/* Check for matching pixel formats */
if (src_format != entries[i].src_format) {
continue;
}
if (dst_format != entries[i].dst_format) {
continue;
}
/* Check flags */
if ((flagcheck & entries[i].flags) != flagcheck) {
continue;
}
/* Check CPU features */
if ((entries[i].cpu & features) != entries[i].cpu) {
continue;
}
/* We found the best one! */
return entries[i].func;
}
return NULL;
}
#endif /* SDL_HAVE_BLIT_AUTO */
/* Figure out which of many blit routines to set up on a surface */
int
SDL_CalculateBlit(SDL_Surface * surface)
{
SDL_BlitFunc blit = NULL;
SDL_BlitMap *map = surface->map;
SDL_Surface *dst = map->dst;
/* We don't currently support blitting to < 8 bpp surfaces */
if (dst->format->BitsPerPixel < 8) {
SDL_InvalidateMap(map);
return SDL_SetError("Blit combination not supported");
}
#if SDL_HAVE_RLE
/* Clean everything out to start */
if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
SDL_UnRLESurface(surface, 1);
}
#endif
map->blit = SDL_SoftBlit;
map->info.src_fmt = surface->format;
map->info.src_pitch = surface->pitch;
map->info.dst_fmt = dst->format;
map->info.dst_pitch = dst->pitch;
#if SDL_HAVE_RLE
/* See if we can do RLE acceleration */
if (map->info.flags & SDL_COPY_RLE_DESIRED) {
if (SDL_RLESurface(surface) == 0) {
return 0;
}
}
#endif
/* Choose a standard blit function */
if (map->identity && !(map->info.flags & ~SDL_COPY_RLE_DESIRED)) {
blit = SDL_BlitCopy;
} else if (surface->format->Rloss > 8 || dst->format->Rloss > 8) {
/* Greater than 8 bits per channel not supported yet */
SDL_InvalidateMap(map);
return SDL_SetError("Blit combination not supported");
}
#if SDL_HAVE_BLIT_0
else if (surface->format->BitsPerPixel < 8 &&
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)) {
blit = SDL_CalculateBlit1(surface);
}
#endif
#if SDL_HAVE_BLIT_A
else if (map->info.flags & SDL_COPY_BLEND) {
blit = SDL_CalculateBlitA(surface);
}
#endif
#if SDL_HAVE_BLIT_N
else {
blit = SDL_CalculateBlitN(surface);
}
#endif
#if SDL_HAVE_BLIT_AUTO
if (blit == NULL) {
Uint32 src_format = surface->format->format;
Uint32 dst_format = dst->format->format;
blit =
SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags,
SDL_GeneratedBlitFuncTable);
}
#endif
#ifndef TEST_SLOW_BLIT
if (blit == NULL)
#endif
{
Uint32 src_format = surface->format->format;
Uint32 dst_format = dst->format->format;
if (!SDL_ISPIXELFORMAT_INDEXED(src_format) &&
!SDL_ISPIXELFORMAT_FOURCC(src_format) &&
!SDL_ISPIXELFORMAT_INDEXED(dst_format) &&
!SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
blit = SDL_Blit_Slow;
}
}
map->data = blit;
/* Make sure we have a blit function */
if (blit == NULL) {
SDL_InvalidateMap(map);
return SDL_SetError("Blit combination not supported");
}
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */

554
externals/SDL/src/video/SDL_blit.h vendored Executable file
View File

@@ -0,0 +1,554 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#ifndef SDL_blit_h_
#define SDL_blit_h_
#include "SDL_cpuinfo.h"
#include "SDL_endian.h"
#include "SDL_surface.h"
/* Table to do pixel byte expansion */
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)
/* 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
typedef struct
{
Uint8 *src;
int src_w, src_h;
int src_pitch;
int src_skip;
Uint8 *dst;
int dst_w, dst_h;
int dst_pitch;
int dst_skip;
SDL_PixelFormat *src_fmt;
SDL_PixelFormat *dst_fmt;
Uint8 *table;
int flags;
Uint32 colorkey;
Uint8 r, g, b, a;
} SDL_BlitInfo;
typedef void (*SDL_BlitFunc) (SDL_BlitInfo *info);
typedef struct
{
Uint32 src_format;
Uint32 dst_format;
int flags;
int cpu;
SDL_BlitFunc func;
} SDL_BlitFuncEntry;
/* Blit mapping definition */
typedef struct SDL_BlitMap
{
SDL_Surface *dst;
int identity;
SDL_blit blit;
void *data;
SDL_BlitInfo info;
/* the version count matches the destination; mismatch indicates
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);
/* 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);
/*
* Useful macros for blitting routines
*/
#if defined(__GNUC__)
#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
#else
#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 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; \
} \
}
/* 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)
/* 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; \
} \
}
/* 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)
/* 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)
/* This is a very useful loop for optimizing blitters */
#if defined(_MSC_VER) && (_MSC_VER == 1300)
/* There's a bug in the Visual C++ 7 optimizer when compiling this code */
#else
#define USE_DUFFS_LOOP
#endif
#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; /* fallthrough */ \
case 7: pixel_copy_increment; /* fallthrough */ \
case 6: pixel_copy_increment; /* fallthrough */ \
case 5: pixel_copy_increment; /* fallthrough */ \
case 4: pixel_copy_increment; /* fallthrough */ \
case 3: pixel_copy_increment; /* fallthrough */ \
case 2: pixel_copy_increment; /* fallthrough */ \
case 1: pixel_copy_increment; /* fallthrough */ \
} 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; /* fallthrough */ \
case 3: pixel_copy_increment; /* fallthrough */ \
case 2: pixel_copy_increment; /* fallthrough */ \
case 1: pixel_copy_increment; /* fallthrough */ \
} while (--n > 0); \
} \
}
/* Use the 8-times version of the loop by default */
#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); \
} \
}
#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) \
DUFFS_LOOP(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) \
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)
#endif
#endif /* SDL_blit_h_ */
/* vi: set ts=4 sw=4 expandtab: */

487
externals/SDL/src/video/SDL_blit_0.c vendored Executable file
View File

@@ -0,0 +1,487 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#if SDL_HAVE_BLIT_0
#include "SDL_video.h"
#include "SDL_blit.h"
/* Functions to blit from bitmaps to other surfaces */
static void
BlitBto1(SDL_BlitInfo * info)
{
int c;
int width, height;
Uint8 *src, *map, *dst;
int srcskip, dstskip;
/* Set up some basic variables */
width = info->dst_w;
height = info->dst_h;
src = info->src;
srcskip = info->src_skip;
dst = info->dst;
dstskip = info->dst_skip;
map = info->table;
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++;
}
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) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = bit;
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
}
}
static void
BlitBto2(SDL_BlitInfo * info)
{
int c;
int width, height;
Uint8 *src;
Uint16 *map, *dst;
int srcskip, dstskip;
/* Set up some basic variables */
width = info->dst_w;
height = info->dst_h;
src = info->src;
srcskip = info->src_skip;
dst = (Uint16 *) info->dst;
dstskip = info->dst_skip / 2;
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++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
byte <<= 1;
dst++;
}
src += srcskip;
dst += dstskip;
}
}
static void
BlitBto3(SDL_BlitInfo * info)
{
int c, o;
int width, height;
Uint8 *src, *map, *dst;
int srcskip, dstskip;
/* Set up some basic variables */
width = info->dst_w;
height = info->dst_h;
src = info->src;
srcskip = info->src_skip;
dst = info->dst;
dstskip = info->dst_skip;
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++;
}
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;
}
}
static void
BlitBto4(SDL_BlitInfo * info)
{
int width, height;
Uint8 *src;
Uint32 *map, *dst;
int srcskip, dstskip;
int c;
/* Set up some basic variables */
width = info->dst_w;
height = info->dst_h;
src = info->src;
srcskip = info->src_skip;
dst = (Uint32 *) info->dst;
dstskip = info->dst_skip / 4;
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++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
byte <<= 1;
dst++;
}
src += srcskip;
dst += dstskip;
}
}
static void
BlitBto1Key(SDL_BlitInfo * info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint8 *dst = info->dst;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
Uint8 *palmap = info->table;
int c;
/* Set up some basic variables */
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++;
}
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) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dst = bit;
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
}
}
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;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
Uint8 *palmap = info->table;
int c;
/* Set up some basic variables */
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++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dstp = ((Uint16 *) palmap)[bit];
}
byte <<= 1;
dstp++;
}
src += srcskip;
dstp += dstskip;
}
}
static void
BlitBto3Key(SDL_BlitInfo * info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint8 *dst = info->dst;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
Uint8 *palmap = info->table;
int c;
/* 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++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
SDL_memcpy(dst, &palmap[bit * 4], 3);
}
byte <<= 1;
dst += 3;
}
src += srcskip;
dst += dstskip;
}
}
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;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
Uint8 *palmap = info->table;
int c;
/* Set up some basic variables */
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++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dstp = ((Uint32 *) palmap)[bit];
}
byte <<= 1;
dstp++;
}
src += srcskip;
dstp += dstskip;
}
}
static void
BlitBtoNAlpha(SDL_BlitInfo * info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint8 *dst = info->dst;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
const SDL_Color *srcpal = info->src_fmt->palette->colors;
SDL_PixelFormat *dstfmt = info->dst_fmt;
int dstbpp;
int c;
Uint32 pixel;
unsigned sR, sG, sB;
unsigned dR, dG, dB, dA;
const unsigned A = info->a;
/* Set up some basic variables */
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++;
}
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;
}
}
static void
BlitBtoNAlphaKey(SDL_BlitInfo * info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint8 *dst = info->dst;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
SDL_PixelFormat *srcfmt = info->src_fmt;
SDL_PixelFormat *dstfmt = info->dst_fmt;
const SDL_Color *srcpal = srcfmt->palette->colors;
int dstbpp;
int c;
Uint32 pixel;
unsigned sR, sG, sB;
unsigned dR, dG, dB, dA;
const unsigned A = info->a;
Uint32 ckey = info->colorkey;
/* Set up some basic variables */
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++;
}
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;
}
}
static const SDL_BlitFunc bitmap_blit[] = {
(SDL_BlitFunc) NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4
};
static const SDL_BlitFunc colorkey_blit[] = {
(SDL_BlitFunc) NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key
};
SDL_BlitFunc
SDL_CalculateBlit0(SDL_Surface * surface)
{
int which;
if (surface->format->BitsPerPixel != 1) {
/* We don't support sub 8-bit packed pixel modes */
return (SDL_BlitFunc) NULL;
}
if (surface->map->dst->format->BitsPerPixel < 8) {
which = 0;
} else {
which = surface->map->dst->format->BytesPerPixel;
}
switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
case 0:
return bitmap_blit[which];
case SDL_COPY_COLORKEY:
return colorkey_blit[which];
case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc) NULL;
case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc) NULL;
}
return (SDL_BlitFunc) NULL;
}
#endif /* SDL_HAVE_BLIT_0 */
/* vi: set ts=4 sw=4 expandtab: */

556
externals/SDL/src/video/SDL_blit_1.c vendored Executable file
View File

@@ -0,0 +1,556 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#if SDL_HAVE_BLIT_1
#include "SDL_video.h"
#include "SDL_blit.h"
#include "SDL_sysvideo.h"
#include "SDL_endian.h"
/* Functions to blit from 8-bit surfaces to other surfaces */
static void
Blit1to1(SDL_BlitInfo * info)
{
#ifndef USE_DUFFS_LOOP
int c;
#endif
int width, height;
Uint8 *src, *map, *dst;
int srcskip, dstskip;
/* Set up some basic variables */
width = info->dst_w;
height = info->dst_h;
src = info->src;
srcskip = info->src_skip;
dst = info->dst;
dstskip = info->dst_skip;
map = info->table;
while (height--) {
#ifdef USE_DUFFS_LOOP
/* *INDENT-OFF* */
DUFFS_LOOP(
{
*dst = map[*src];
}
dst++;
src++;
, width);
/* *INDENT-ON* */
#else
for (c = width; c; --c) {
*dst = map[*src];
dst++;
src++;
}
#endif
src += srcskip;
dst += dstskip;
}
}
/* 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
#endif
static void
Blit1to2(SDL_BlitInfo * info)
{
#ifndef USE_DUFFS_LOOP
int c;
#endif
int width, height;
Uint8 *src, *dst;
Uint16 *map;
int srcskip, dstskip;
/* Set up some basic variables */
width = info->dst_w;
height = info->dst_h;
src = info->src;
srcskip = info->src_skip;
dst = info->dst;
dstskip = info->dst_skip;
map = (Uint16 *) info->table;
#ifdef USE_DUFFS_LOOP
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
*(Uint16 *)dst = map[*src++];
dst += 2;
},
width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
#else
/* Memory align at 4-byte boundary, if necessary */
if ((long) dst & 0x03) {
/* Don't do anything if width is 0 */
if (width == 0) {
return;
}
--width;
while (height--) {
/* Perform copy alignment */
*(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]]);
src += 2;
dst += 4;
*(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++];
dst += 2;
case 2:
*(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
src += 2;
dst += 4;
break;
case 1:
*(Uint16 *) dst = map[*src++];
dst += 2;
break;
}
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
/* Copy in 4 pixel chunks */
for (c = width / 4; c; --c) {
*(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
src += 2;
dst += 4;
*(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++];
dst += 2;
case 2:
*(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
src += 2;
dst += 4;
break;
case 1:
*(Uint16 *) dst = map[*src++];
dst += 2;
break;
}
src += srcskip;
dst += dstskip;
}
}
#endif /* USE_DUFFS_LOOP */
}
static void
Blit1to3(SDL_BlitInfo * info)
{
#ifndef USE_DUFFS_LOOP
int c;
#endif
int o;
int width, height;
Uint8 *src, *map, *dst;
int srcskip, dstskip;
/* Set up some basic variables */
width = info->dst_w;
height = info->dst_h;
src = info->src;
srcskip = info->src_skip;
dst = info->dst;
dstskip = info->dst_skip;
map = info->table;
while (height--) {
#ifdef USE_DUFFS_LOOP
/* *INDENT-OFF* */
DUFFS_LOOP(
{
o = *src * 4;
dst[0] = map[o++];
dst[1] = map[o++];
dst[2] = map[o++];
}
src++;
dst += 3;
, width);
/* *INDENT-ON* */
#else
for (c = width; c; --c) {
o = *src * 4;
dst[0] = map[o++];
dst[1] = map[o++];
dst[2] = map[o++];
src++;
dst += 3;
}
#endif /* USE_DUFFS_LOOP */
src += srcskip;
dst += dstskip;
}
}
static void
Blit1to4(SDL_BlitInfo * info)
{
#ifndef USE_DUFFS_LOOP
int c;
#endif
int width, height;
Uint8 *src;
Uint32 *map, *dst;
int srcskip, dstskip;
/* Set up some basic variables */
width = info->dst_w;
height = info->dst_h;
src = info->src;
srcskip = info->src_skip;
dst = (Uint32 *) info->dst;
dstskip = info->dst_skip / 4;
map = (Uint32 *) info->table;
while (height--) {
#ifdef USE_DUFFS_LOOP
/* *INDENT-OFF* */
DUFFS_LOOP(
*dst++ = map[*src++];
, width);
/* *INDENT-ON* */
#else
for (c = width / 4; c; --c) {
*dst++ = map[*src++];
*dst++ = map[*src++];
*dst++ = map[*src++];
*dst++ = map[*src++];
}
switch (width & 3) {
case 3:
*dst++ = map[*src++];
case 2:
*dst++ = map[*src++];
case 1:
*dst++ = map[*src++];
}
#endif /* USE_DUFFS_LOOP */
src += srcskip;
dst += dstskip;
}
}
static void
Blit1to1Key(SDL_BlitInfo * info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
Uint8 *palmap = info->table;
Uint32 ckey = info->colorkey;
if (palmap) {
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ( *src != ckey ) {
*dst = palmap[*src];
}
dst++;
src++;
},
width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ( *src != ckey ) {
*dst = *src;
}
dst++;
src++;
},
width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
}
}
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;
int dstskip = info->dst_skip;
Uint16 *palmap = (Uint16 *) info->table;
Uint32 ckey = info->colorkey;
/* Set up some basic variables */
dstskip /= 2;
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ( *src != ckey ) {
*dstp=palmap[*src];
}
src++;
dstp++;
},
width);
/* *INDENT-ON* */
src += srcskip;
dstp += dstskip;
}
}
static void
Blit1to3Key(SDL_BlitInfo * info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
Uint8 *palmap = info->table;
Uint32 ckey = info->colorkey;
int o;
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ( *src != ckey ) {
o = *src * 4;
dst[0] = palmap[o++];
dst[1] = palmap[o++];
dst[2] = palmap[o++];
}
src++;
dst += 3;
},
width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
}
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;
int dstskip = info->dst_skip;
Uint32 *palmap = (Uint32 *) info->table;
Uint32 ckey = info->colorkey;
/* Set up some basic variables */
dstskip /= 4;
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ( *src != ckey ) {
*dstp = palmap[*src];
}
src++;
dstp++;
},
width);
/* *INDENT-ON* */
src += srcskip;
dstp += dstskip;
}
}
static void
Blit1toNAlpha(SDL_BlitInfo * info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
SDL_PixelFormat *dstfmt = info->dst_fmt;
const SDL_Color *srcpal = info->src_fmt->palette->colors;
int dstbpp;
Uint32 pixel;
unsigned sR, sG, sB;
unsigned dR, dG, dB, dA;
const unsigned A = info->a;
/* Set up some basic variables */
dstbpp = dstfmt->BytesPerPixel;
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP4(
{
sR = srcpal[*src].r;
sG = srcpal[*src].g;
sB = srcpal[*src].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);
src++;
dst += dstbpp;
},
width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
}
static void
Blit1toNAlphaKey(SDL_BlitInfo * info)
{
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
SDL_PixelFormat *dstfmt = info->dst_fmt;
const SDL_Color *srcpal = info->src_fmt->palette->colors;
Uint32 ckey = info->colorkey;
int dstbpp;
Uint32 pixel;
unsigned sR, sG, sB;
unsigned dR, dG, dB, dA;
const unsigned A = info->a;
/* Set up some basic variables */
dstbpp = dstfmt->BytesPerPixel;
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ( *src != ckey ) {
sR = srcpal[*src].r;
sG = srcpal[*src].g;
sB = srcpal[*src].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);
}
src++;
dst += dstbpp;
},
width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
}
static const SDL_BlitFunc one_blit[] = {
(SDL_BlitFunc) NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4
};
static const SDL_BlitFunc one_blitkey[] = {
(SDL_BlitFunc) NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key
};
SDL_BlitFunc
SDL_CalculateBlit1(SDL_Surface * surface)
{
int which;
SDL_PixelFormat *dstfmt;
dstfmt = surface->map->dst->format;
if (dstfmt->BitsPerPixel < 8) {
which = 0;
} else {
which = dstfmt->BytesPerPixel;
}
switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
case 0:
return one_blit[which];
case SDL_COPY_COLORKEY:
return one_blitkey[which];
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;
case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? Blit1toNAlphaKey : (SDL_BlitFunc) NULL;
}
return (SDL_BlitFunc) NULL;
}
#endif /* SDL_HAVE_BLIT_1 */
/* vi: set ts=4 sw=4 expandtab: */

1496
externals/SDL/src/video/SDL_blit_A.c vendored Executable file

File diff suppressed because it is too large Load Diff

3472
externals/SDL/src/video/SDL_blit_N.c vendored Executable file

File diff suppressed because it is too large Load Diff

7681
externals/SDL/src/video/SDL_blit_auto.c vendored Executable file

File diff suppressed because it is too large Load Diff

34
externals/SDL/src/video/SDL_blit_auto.h vendored Executable file
View File

@@ -0,0 +1,34 @@
/* DO NOT EDIT! This file is generated by sdlgenblit.pl */
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#if SDL_HAVE_BLIT_AUTO
/* *INDENT-OFF* */
extern SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[];
/* *INDENT-ON* */
#endif /* SDL_HAVE_BLIT_AUTO */
/* vi: set ts=4 sw=4 expandtab: */

162
externals/SDL/src/video/SDL_blit_copy.c vendored Executable file
View File

@@ -0,0 +1,162 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#include "SDL_video.h"
#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)
{
int i;
__m128 values[4];
for (i = len / 64; i--;) {
_mm_prefetch(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]);
src += 64;
dst += 64;
}
if (len & 63)
SDL_memcpy(dst, src, len & 63);
}
#endif /* __SSE__ */
#ifdef __MMX__
#ifdef _MSC_VER
#pragma warning(disable:4799)
#endif
static SDL_INLINE void
SDL_memcpyMMX(Uint8 * dst, const Uint8 * src, int len)
{
const int remain = (len & 63);
int i;
__m64* d64 = (__m64*)dst;
__m64* s64 = (__m64*)src;
for(i= len / 64; i--;) {
d64[0] = s64[0];
d64[1] = s64[1];
d64[2] = s64[2];
d64[3] = s64[3];
d64[4] = s64[4];
d64[5] = s64[5];
d64[6] = s64[6];
d64[7] = s64[7];
d64 += 8;
s64 += 8;
}
if (remain)
{
const int skip = len - remain;
SDL_memcpy(dst + skip, src + skip, remain);
}
}
#endif /* __MMX__ */
void
SDL_BlitCopy(SDL_BlitInfo * info)
{
SDL_bool overlap;
Uint8 *src, *dst;
int w, h;
int srcskip, dstskip;
w = info->dst_w * info->dst_fmt->BytesPerPixel;
h = info->dst_h;
src = info->src;
dst = info->dst;
srcskip = info->src_pitch;
dstskip = info->dst_pitch;
/* Properly handle overlapping blits */
if (src < dst) {
overlap = (dst < (src + h*srcskip));
} else {
overlap = (src < (dst + h*dstskip));
}
if (overlap) {
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;
}
}
return;
}
#ifdef __SSE__
if (SDL_HasSSE() &&
!((uintptr_t) src & 15) && !(srcskip & 15) &&
!((uintptr_t) dst & 15) && !(dstskip & 15)) {
while (h--) {
SDL_memcpySSE(dst, src, w);
src += srcskip;
dst += dstskip;
}
return;
}
#endif
#ifdef __MMX__
if (SDL_HasMMX() && !(srcskip & 7) && !(dstskip & 7)) {
while (h--) {
SDL_memcpyMMX(dst, src, w);
src += srcskip;
dst += dstskip;
}
_mm_empty();
return;
}
#endif
while (h--) {
SDL_memcpy(dst, src, w);
src += srcskip;
dst += dstskip;
}
}
/* vi: set ts=4 sw=4 expandtab: */

29
externals/SDL/src/video/SDL_blit_copy.h vendored Executable file
View File

@@ -0,0 +1,29 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_blit_copy_h_
#define SDL_blit_copy_h_
void SDL_BlitCopy(SDL_BlitInfo * info);
#endif /* SDL_blit_copy_h_ */
/* vi: set ts=4 sw=4 expandtab: */

178
externals/SDL/src/video/SDL_blit_slow.c vendored Executable file
View File

@@ -0,0 +1,178 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#include "SDL_video.h"
#include "SDL_blit.h"
#include "SDL_blit_slow.h"
/* The ONE TRUE BLITTER
* This puppy has to handle all the unoptimized cases - yes, it's slow.
*/
void
SDL_Blit_Slow(SDL_BlitInfo * info)
{
const int flags = info->flags;
const Uint32 modulateR = info->r;
const Uint32 modulateG = info->g;
const Uint32 modulateB = info->b;
const Uint32 modulateA = info->a;
Uint32 srcpixel;
Uint32 srcR, srcG, srcB, srcA;
Uint32 dstpixel;
Uint32 dstR, dstG, dstB, dstA;
int srcy, srcx;
int posy, posx;
int incy, incx;
SDL_PixelFormat *src_fmt = info->src_fmt;
SDL_PixelFormat *dst_fmt = info->dst_fmt;
int srcbpp = src_fmt->BytesPerPixel;
int dstbpp = dst_fmt->BytesPerPixel;
Uint32 rgbmask = ~src_fmt->Amask;
Uint32 ckey = info->colorkey & rgbmask;
srcy = 0;
posy = 0;
incy = (info->src_h << 16) / info->dst_h;
incx = (info->src_w << 16) / info->dst_w;
while (info->dst_h--) {
Uint8 *src = 0;
Uint8 *dst = info->dst;
int n = info->dst_w;
srcx = -1;
posx = 0x10000L;
while (posy >= 0x10000L) {
++srcy;
posy -= 0x10000L;
}
while (n--) {
if (posx >= 0x10000L) {
while (posx >= 0x10000L) {
++srcx;
posx -= 0x10000L;
}
src =
(info->src + (srcy * info->src_pitch) + (srcx * srcbpp));
}
if (src_fmt->Amask) {
DISEMBLE_RGBA(src, srcbpp, src_fmt, srcpixel, srcR, srcG,
srcB, srcA);
} else {
DISEMBLE_RGB(src, srcbpp, src_fmt, srcpixel, srcR, srcG,
srcB);
srcA = 0xFF;
}
if (flags & SDL_COPY_COLORKEY) {
/* srcpixel isn't set for 24 bpp */
if (srcbpp == 3) {
srcpixel = (srcR << src_fmt->Rshift) |
(srcG << src_fmt->Gshift) | (srcB << src_fmt->Bshift);
}
if ((srcpixel & rgbmask) == ckey) {
posx += incx;
dst += dstbpp;
continue;
}
}
if (dst_fmt->Amask) {
DISEMBLE_RGBA(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG,
dstB, dstA);
} else {
DISEMBLE_RGB(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG,
dstB);
dstA = 0xFF;
}
if (flags & SDL_COPY_MODULATE_COLOR) {
srcR = (srcR * modulateR) / 255;
srcG = (srcG * modulateG) / 255;
srcB = (srcB * modulateB) / 255;
}
if (flags & SDL_COPY_MODULATE_ALPHA) {
srcA = (srcA * modulateA) / 255;
}
if (flags & (SDL_COPY_BLEND | SDL_COPY_ADD)) {
/* This goes away if we ever use premultiplied alpha */
if (srcA < 255) {
srcR = (srcR * srcA) / 255;
srcG = (srcG * srcA) / 255;
srcB = (srcB * srcA) / 255;
}
}
switch (flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL)) {
case 0:
dstR = srcR;
dstG = srcG;
dstB = srcB;
dstA = srcA;
break;
case SDL_COPY_BLEND:
dstR = srcR + ((255 - srcA) * dstR) / 255;
dstG = srcG + ((255 - srcA) * dstG) / 255;
dstB = srcB + ((255 - srcA) * dstB) / 255;
dstA = srcA + ((255 - srcA) * dstA) / 255;
break;
case SDL_COPY_ADD:
dstR = srcR + dstR;
if (dstR > 255)
dstR = 255;
dstG = srcG + dstG;
if (dstG > 255)
dstG = 255;
dstB = srcB + dstB;
if (dstB > 255)
dstB = 255;
break;
case SDL_COPY_MOD:
dstR = (srcR * dstR) / 255;
dstG = (srcG * dstG) / 255;
dstB = (srcB * dstB) / 255;
break;
case SDL_COPY_MUL:
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;
}
if (dst_fmt->Amask) {
ASSEMBLE_RGBA(dst, dstbpp, dst_fmt, dstR, dstG, dstB, dstA);
} else {
ASSEMBLE_RGB(dst, dstbpp, dst_fmt, dstR, dstG, dstB);
}
posx += incx;
dst += dstbpp;
}
posy += incy;
info->dst += info->dst_pitch;
}
}
/* vi: set ts=4 sw=4 expandtab: */

31
externals/SDL/src/video/SDL_blit_slow.h vendored Executable file
View File

@@ -0,0 +1,31 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_blit_slow_h_
#define SDL_blit_slow_h_
#include "../SDL_internal.h"
extern void SDL_Blit_Slow(SDL_BlitInfo * info);
#endif /* SDL_blit_slow_h_ */
/* vi: set ts=4 sw=4 expandtab: */

807
externals/SDL/src/video/SDL_bmp.c vendored Executable file
View File

@@ -0,0 +1,807 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
/*
Code to load and save surfaces in Windows BMP format.
Why support BMP format? Well, it's a native format for Windows, and
most image processing programs can read and write it. It would be nice
to be able to have at least one image format that we can natively load
and save, and since PNG is so complex that it would bloat the library,
BMP is a good alternative.
This code currently supports Win32 DIBs in uncompressed 8 and 24 bpp.
*/
#include "SDL_hints.h"
#include "SDL_video.h"
#include "SDL_assert.h"
#include "SDL_endian.h"
#include "SDL_pixels_c.h"
#define SAVE_32BIT_BMP
/* Compression encodings for BMP files */
#ifndef BI_RGB
#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
#endif
static int readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8)
{
/*
| Sets the surface pixels from src. A bmp image is upside down.
*/
int pitch = surface->pitch;
int height = surface->h;
Uint8 *start = (Uint8 *)surface->pixels;
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)
for (;;) {
if (!SDL_RWread(src, &ch, 1, 1)) return 1;
/*
| 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 1;
if (isRle8) { /* 256-color bitmap, compressed */
do {
COPY_PIXEL(pixel);
} while (--ch);
} else { /* 16-color bitmap, compressed */
Uint8 pixel0 = pixel >> 4;
Uint8 pixel1 = pixel & 0x0F;
for (;;) {
COPY_PIXEL(pixel0); /* even count, high nibble */
if (!--ch) break;
COPY_PIXEL(pixel1); /* odd count, low nibble */
if (!--ch) break;
}
}
} else {
/*
| A leading zero is an escape; it may signal the end of the bitmap,
| a cursor move, or some absolute data.
| zero tag may be absolute mode or an escape
*/
if (!SDL_RWread(src, &ch, 1, 1)) return 1;
switch (ch) {
case 0: /* end of line */
ofs = 0;
bits -= pitch; /* go to previous */
break;
case 1: /* end of bitmap */
return 0; /* success! */
case 2: /* delta */
if (!SDL_RWread(src, &ch, 1, 1)) return 1;
ofs += ch;
if (!SDL_RWread(src, &ch, 1, 1)) return 1;
bits -= (ch * pitch);
break;
default: /* no compression */
if (isRle8) {
needsPad = (ch & 1);
do {
Uint8 pixel;
if (!SDL_RWread(src, &pixel, 1, 1)) return 1;
COPY_PIXEL(pixel);
} while (--ch);
} else {
needsPad = (((ch+1)>>1) & 1); /* (ch+1)>>1: bytes size */
for (;;) {
Uint8 pixel;
if (!SDL_RWread(src, &pixel, 1, 1)) return 1;
COPY_PIXEL(pixel >> 4);
if (!--ch) break;
COPY_PIXEL(pixel & 0x0F);
if (!--ch) break;
}
}
/* pad at even boundary */
if (needsPad && !SDL_RWread(src, &ch, 1, 1)) return 1;
break;
}
}
}
}
static void CorrectAlphaChannel(SDL_Surface *surface)
{
/* Check to see if there is any alpha channel data */
SDL_bool hasAlpha = SDL_FALSE;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int alphaChannelOffset = 0;
#else
int alphaChannelOffset = 3;
#endif
Uint8 *alpha = ((Uint8*)surface->pixels) + alphaChannelOffset;
Uint8 *end = alpha + surface->h * surface->pitch;
while (alpha < end) {
if (*alpha != 0) {
hasAlpha = SDL_TRUE;
break;
}
alpha += 4;
}
if (!hasAlpha) {
alpha = ((Uint8*)surface->pixels) + alphaChannelOffset;
while (alpha < end) {
*alpha = SDL_ALPHA_OPAQUE;
alpha += 4;
}
}
}
SDL_Surface *
SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
{
SDL_bool was_error;
Sint64 fp_offset = 0;
int bmpPitch;
int i, pad;
SDL_Surface *surface;
Uint32 Rmask = 0;
Uint32 Gmask = 0;
Uint32 Bmask = 0;
Uint32 Amask = 0;
SDL_Palette *palette;
Uint8 *bits;
Uint8 *top, *end;
SDL_bool topDown;
int ExpandBMP;
SDL_bool haveRGBMasks = SDL_FALSE;
SDL_bool haveAlphaMask = SDL_FALSE;
SDL_bool correctAlpha = SDL_FALSE;
/* The Win32 BMP file header (14 bytes) */
char magic[2];
/* Uint32 bfSize; */
/* Uint16 bfReserved1; */
/* Uint16 bfReserved2; */
Uint32 bfOffBits;
/* The Win32 BITMAPINFOHEADER struct (40 bytes) */
Uint32 biSize;
Sint32 biWidth = 0;
Sint32 biHeight = 0;
/* Uint16 biPlanes; */
Uint16 biBitCount = 0;
Uint32 biCompression = 0;
/* Uint32 biSizeImage; */
/* Sint32 biXPelsPerMeter; */
/* Sint32 biYPelsPerMeter; */
Uint32 biClrUsed = 0;
/* Uint32 biClrImportant; */
/* Make sure we are passed a valid data source */
surface = NULL;
was_error = SDL_FALSE;
if (src == NULL) {
was_error = SDL_TRUE;
goto done;
}
/* Read in the BMP file header */
fp_offset = SDL_RWtell(src);
SDL_ClearError();
if (SDL_RWread(src, magic, 1, 2) != 2) {
SDL_Error(SDL_EFREAD);
was_error = SDL_TRUE;
goto done;
}
if (SDL_strncmp(magic, "BM", 2) != 0) {
SDL_SetError("File is not a Windows BMP file");
was_error = SDL_TRUE;
goto done;
}
/* bfSize = */ SDL_ReadLE32(src);
/* bfReserved1 = */ SDL_ReadLE16(src);
/* bfReserved2 = */ SDL_ReadLE16(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);
/* biPlanes = */ SDL_ReadLE16(src);
biBitCount = SDL_ReadLE16(src);
biCompression = BI_RGB;
/* biSizeImage = 0; */
/* biXPelsPerMeter = 0; */
/* biYPelsPerMeter = 0; */
biClrUsed = 0;
/* biClrImportant = 0; */
} else if (biSize >= 40) { /* some version of BITMAPINFOHEADER */
Uint32 headerSize;
biWidth = SDL_ReadLE32(src);
biHeight = SDL_ReadLE32(src);
/* biPlanes = */ SDL_ReadLE16(src);
biBitCount = SDL_ReadLE16(src);
biCompression = SDL_ReadLE32(src);
/* biSizeImage = */ SDL_ReadLE32(src);
/* biXPelsPerMeter = */ SDL_ReadLE32(src);
/* biYPelsPerMeter = */ SDL_ReadLE32(src);
biClrUsed = SDL_ReadLE32(src);
/* biClrImportant = */ SDL_ReadLE32(src);
/* 64 == BITMAPCOREHEADER2, an incompatible OS/2 2.x extension. Skip this stuff for now. */
if (biSize != 64) {
/* This is complicated. If compression is BI_BITFIELDS, then
we have 3 DWORDS that specify the RGB masks. This is either
stored here in an BITMAPV2INFOHEADER (which only differs in
that it adds these RGB masks) and biSize >= 52, or we've got
these masks stored in the exact same place, but strictly
speaking, this is the bmiColors field in BITMAPINFO immediately
following the legacy v1 info header, just past biSize. */
if (biCompression == BI_BITFIELDS) {
haveRGBMasks = SDL_TRUE;
Rmask = SDL_ReadLE32(src);
Gmask = SDL_ReadLE32(src);
Bmask = SDL_ReadLE32(src);
/* ...v3 adds an 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 */
/*Rmask = */ SDL_ReadLE32(src);
/*Gmask = */ SDL_ReadLE32(src);
/*Bmask = */ SDL_ReadLE32(src);
}
if (biSize >= 56) { /* BITMAPV3INFOHEADER; adds alpha mask */
/*Amask = */ SDL_ReadLE32(src);
}
}
/* Insert other fields here; Wikipedia and MSDN say we're up to
v5 of this header, but we ignore those for now (they add gamma,
color spaces, etc). Ignoring the weird OS/2 2.x format, we
currently parse up to v3 correctly (hopefully!). */
}
/* skip any header bytes we didn't handle... */
headerSize = (Uint32) (SDL_RWtell(src) - (fp_offset + 14));
if (biSize > headerSize) {
SDL_RWseek(src, (biSize - headerSize), RW_SEEK_CUR);
}
}
if (biWidth <= 0 || biHeight == 0) {
SDL_SetError("BMP file with bad dimensions (%dx%d)", biWidth, biHeight);
was_error = SDL_TRUE;
goto done;
}
if (biHeight < 0) {
topDown = SDL_TRUE;
biHeight = -biHeight;
} else {
topDown = SDL_FALSE;
}
/* Check for read error */
if (SDL_strcmp(SDL_GetError(), "") != 0) {
was_error = SDL_TRUE;
goto done;
}
/* Expand 1 and 4 bit bitmaps to 8 bits per pixel */
switch (biBitCount) {
case 1:
case 4:
ExpandBMP = biBitCount;
biBitCount = 8;
break;
case 0:
case 2:
case 3:
case 5:
case 6:
case 7:
SDL_SetError("%d-bpp BMP images are not supported", biBitCount);
was_error = SDL_TRUE;
goto done;
default:
ExpandBMP = 0;
break;
}
/* RLE4 and RLE8 BMP compression is supported */
switch (biCompression) {
case BI_RGB:
/* If there are no masks, use the defaults */
SDL_assert(!haveRGBMasks);
SDL_assert(!haveAlphaMask);
/* Default values for the BMP format */
switch (biBitCount) {
case 15:
case 16:
Rmask = 0x7C00;
Gmask = 0x03E0;
Bmask = 0x001F;
break;
case 24:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
Rmask = 0x000000FF;
Gmask = 0x0000FF00;
Bmask = 0x00FF0000;
#else
Rmask = 0x00FF0000;
Gmask = 0x0000FF00;
Bmask = 0x000000FF;
#endif
break;
case 32:
/* We don't know if this has alpha channel or not */
correctAlpha = SDL_TRUE;
Amask = 0xFF000000;
Rmask = 0x00FF0000;
Gmask = 0x0000FF00;
Bmask = 0x000000FF;
break;
default:
break;
}
break;
case BI_BITFIELDS:
break; /* we handled this in the info header. */
default:
break;
}
/* Create a compatible surface, note that the colors are RGB ordered */
surface =
SDL_CreateRGBSurface(0, biWidth, biHeight, biBitCount, Rmask, Gmask,
Bmask, Amask);
if (surface == NULL) {
was_error = SDL_TRUE;
goto done;
}
/* Load the palette, if any */
palette = (surface->format)->palette;
if (palette) {
if (SDL_RWseek(src, fp_offset+14+biSize, RW_SEEK_SET) < 0) {
SDL_Error(SDL_EFSEEK);
was_error = SDL_TRUE;
goto done;
}
/*
| guich: always use 1<<bpp b/c some bitmaps can bring wrong information
| for colorsUsed
*/
/* if (biClrUsed == 0) { */
biClrUsed = 1 << biBitCount;
/* } */
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) {
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);
SDL_RWread(src, &palette->colors[i].a, 1, 1);
/* According to Microsoft documentation, the fourth element
is reserved and must be zero, so we shouldn't treat it as
alpha.
*/
palette->colors[i].a = SDL_ALPHA_OPAQUE;
}
}
palette->ncolors = biClrUsed;
}
/* Read the surface pixels. Note that the bmp image is upside down */
if (SDL_RWseek(src, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
SDL_Error(SDL_EFSEEK);
was_error = SDL_TRUE;
goto done;
}
if ((biCompression == BI_RLE4) || (biCompression == BI_RLE8)) {
was_error = (SDL_bool)readRlePixels(surface, src, biCompression == BI_RLE8);
if (was_error) SDL_SetError("Error reading from BMP");
goto done;
}
top = (Uint8 *)surface->pixels;
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 4:
bmpPitch = (biWidth + 1) >> 1;
pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
break;
default:
pad = ((surface->pitch % 4) ? (4 - (surface->pitch % 4)) : 0);
break;
}
if (topDown) {
bits = top;
} else {
bits = end - surface->pitch;
}
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_SetError("Error reading from BMP");
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");
was_error = SDL_TRUE;
goto done;
}
pixel <<= ExpandBMP;
}
}
break;
default:
if (SDL_RWread(src, bits, 1, surface->pitch) != surface->pitch) {
SDL_Error(SDL_EFREAD);
was_error = SDL_TRUE;
goto done;
}
if (biBitCount == 8 && palette && biClrUsed < (1u << biBitCount)) {
for (i = 0; i < surface->w; ++i) {
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;
}
}
}
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
/* Byte-swap the pixels if needed. Note that the 24bpp
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 32:{
Uint32 *pix = (Uint32 *) bits;
for (i = 0; i < surface->w; i++)
pix[i] = SDL_Swap32(pix[i]);
break;
}
}
#endif
break;
}
/* Skip padding bytes, ugh */
if (pad) {
Uint8 padbyte;
for (i = 0; i < pad; ++i) {
SDL_RWread(src, &padbyte, 1, 1);
}
}
if (topDown) {
bits += surface->pitch;
} else {
bits -= surface->pitch;
}
}
if (correctAlpha) {
CorrectAlphaChannel(surface);
}
done:
if (was_error) {
if (src) {
SDL_RWseek(src, fp_offset, RW_SEEK_SET);
}
if (surface) {
SDL_FreeSurface(surface);
}
surface = NULL;
}
if (freesrc && src) {
SDL_RWclose(src);
}
return (surface);
}
int
SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
{
Sint64 fp_offset;
int i, pad;
SDL_Surface *surface;
Uint8 *bits;
SDL_bool save32bit = SDL_FALSE;
SDL_bool saveLegacyBMP = SDL_FALSE;
/* The Win32 BMP file header (14 bytes) */
char magic[2] = { 'B', 'M' };
Uint32 bfSize;
Uint16 bfReserved1;
Uint16 bfReserved2;
Uint32 bfOffBits;
/* The Win32 BITMAPINFOHEADER struct (40 bytes) */
Uint32 biSize;
Sint32 biWidth;
Sint32 biHeight;
Uint16 biPlanes;
Uint16 biBitCount;
Uint32 biCompression;
Uint32 biSizeImage;
Sint32 biXPelsPerMeter;
Sint32 biYPelsPerMeter;
Uint32 biClrUsed;
Uint32 biClrImportant;
/* The additional header members from the Win32 BITMAPV4HEADER struct (108 bytes in total) */
Uint32 bV4RedMask = 0;
Uint32 bV4GreenMask = 0;
Uint32 bV4BlueMask = 0;
Uint32 bV4AlphaMask = 0;
Uint32 bV4CSType = 0;
Sint32 bV4Endpoints[3 * 3] = {0};
Uint32 bV4GammaRed = 0;
Uint32 bV4GammaGreen = 0;
Uint32 bV4GammaBlue = 0;
/* Make sure we have somewhere to save */
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)) {
save32bit = SDL_TRUE;
}
#endif /* SAVE_32BIT_BMP */
if (saveme->format->palette && !save32bit) {
if (saveme->format->BitsPerPixel == 8) {
surface = saveme;
} else {
SDL_SetError("%d bpp BMP files not supported",
saveme->format->BitsPerPixel);
}
} else if ((saveme->format->BitsPerPixel == 24) && !save32bit &&
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
(saveme->format->Rmask == 0x00FF0000) &&
(saveme->format->Gmask == 0x0000FF00) &&
(saveme->format->Bmask == 0x000000FF)
#else
(saveme->format->Rmask == 0x000000FF) &&
(saveme->format->Gmask == 0x0000FF00) &&
(saveme->format->Bmask == 0x00FF0000)
#endif
) {
surface = saveme;
} else {
SDL_PixelFormat format;
/* If the surface has a colorkey or alpha channel we'll save a
32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */
if (save32bit) {
SDL_InitFormat(&format, SDL_PIXELFORMAT_BGRA32);
} else {
SDL_InitFormat(&format, SDL_PIXELFORMAT_BGR24);
}
surface = SDL_ConvertSurface(saveme, &format, 0);
if (!surface) {
SDL_SetError("Couldn't convert image to %d bpp",
format.BitsPerPixel);
}
}
} else {
/* Set no error here because it may overwrite a more useful message from
SDL_RWFromFile() if SDL_SaveBMP_RW() is called from SDL_SaveBMP(). */
return -1;
}
if (save32bit) {
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;
/* Set the BMP file header values */
bfSize = 0; /* We'll write this when we're done */
bfReserved1 = 0;
bfReserved2 = 0;
bfOffBits = 0; /* We'll write this when we're done */
/* Write the BMP file header values */
fp_offset = SDL_RWtell(dst);
SDL_ClearError();
SDL_RWwrite(dst, magic, 2, 1);
SDL_WriteLE32(dst, bfSize);
SDL_WriteLE16(dst, bfReserved1);
SDL_WriteLE16(dst, bfReserved2);
SDL_WriteLE32(dst, bfOffBits);
/* Set the BMP info values */
biSize = 40;
biWidth = surface->w;
biHeight = surface->h;
biPlanes = 1;
biBitCount = surface->format->BitsPerPixel;
biCompression = BI_RGB;
biSizeImage = surface->h * surface->pitch;
biXPelsPerMeter = 0;
biYPelsPerMeter = 0;
if (surface->format->palette) {
biClrUsed = surface->format->palette->ncolors;
} else {
biClrUsed = 0;
}
biClrImportant = 0;
/* Set the BMP info values for the version 4 header */
if (save32bit && !saveLegacyBMP) {
biSize = 108;
biCompression = BI_BITFIELDS;
/* The BMP format is always little endian, these masks stay the same */
bV4RedMask = 0x00ff0000;
bV4GreenMask = 0x0000ff00;
bV4BlueMask = 0x000000ff;
bV4AlphaMask = 0xff000000;
bV4CSType = LCS_WINDOWS_COLOR_SPACE;
bV4GammaRed = 0;
bV4GammaGreen = 0;
bV4GammaBlue = 0;
}
/* Write the BMP info values */
SDL_WriteLE32(dst, biSize);
SDL_WriteLE32(dst, biWidth);
SDL_WriteLE32(dst, biHeight);
SDL_WriteLE16(dst, biPlanes);
SDL_WriteLE16(dst, biBitCount);
SDL_WriteLE32(dst, biCompression);
SDL_WriteLE32(dst, biSizeImage);
SDL_WriteLE32(dst, biXPelsPerMeter);
SDL_WriteLE32(dst, biYPelsPerMeter);
SDL_WriteLE32(dst, biClrUsed);
SDL_WriteLE32(dst, biClrImportant);
/* Write the BMP info values for the version 4 header */
if (save32bit && !saveLegacyBMP) {
SDL_WriteLE32(dst, bV4RedMask);
SDL_WriteLE32(dst, bV4GreenMask);
SDL_WriteLE32(dst, bV4BlueMask);
SDL_WriteLE32(dst, bV4AlphaMask);
SDL_WriteLE32(dst, bV4CSType);
for (i = 0; i < 3 * 3; i++) {
SDL_WriteLE32(dst, bV4Endpoints[i]);
}
SDL_WriteLE32(dst, bV4GammaRed);
SDL_WriteLE32(dst, bV4GammaGreen);
SDL_WriteLE32(dst, bV4GammaBlue);
}
/* Write the palette (in BGR color order) */
if (surface->format->palette) {
SDL_Color *colors;
int ncolors;
colors = surface->format->palette->colors;
ncolors = 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);
SDL_RWwrite(dst, &colors[i].r, 1, 1);
SDL_RWwrite(dst, &colors[i].a, 1, 1);
}
}
/* Write the bitmap offset */
bfOffBits = (Uint32)(SDL_RWtell(dst) - fp_offset);
if (SDL_RWseek(dst, fp_offset + 10, RW_SEEK_SET) < 0) {
SDL_Error(SDL_EFSEEK);
}
SDL_WriteLE32(dst, bfOffBits);
if (SDL_RWseek(dst, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
SDL_Error(SDL_EFSEEK);
}
/* Write the bitmap image upside down */
bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch);
pad = ((bw % 4) ? (4 - (bw % 4)) : 0);
while (bits > (Uint8 *) surface->pixels) {
bits -= surface->pitch;
if (SDL_RWwrite(dst, bits, 1, bw) != bw) {
SDL_Error(SDL_EFWRITE);
break;
}
if (pad) {
const Uint8 padbyte = 0;
for (i = 0; i < pad; ++i) {
SDL_RWwrite(dst, &padbyte, 1, 1);
}
}
}
/* Write the BMP file size */
bfSize = (Uint32)(SDL_RWtell(dst) - fp_offset);
if (SDL_RWseek(dst, fp_offset + 2, RW_SEEK_SET) < 0) {
SDL_Error(SDL_EFSEEK);
}
SDL_WriteLE32(dst, bfSize);
if (SDL_RWseek(dst, fp_offset + bfSize, RW_SEEK_SET) < 0) {
SDL_Error(SDL_EFSEEK);
}
/* Close it up.. */
SDL_UnlockSurface(surface);
if (surface != saveme) {
SDL_FreeSurface(surface);
}
}
if (freedst && dst) {
SDL_RWclose(dst);
}
return ((SDL_strcmp(SDL_GetError(), "") == 0) ? 0 : -1);
}
/* vi: set ts=4 sw=4 expandtab: */

90
externals/SDL/src/video/SDL_clipboard.c vendored Executable file
View File

@@ -0,0 +1,90 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#include "SDL_clipboard.h"
#include "SDL_sysvideo.h"
int
SDL_SetClipboardText(const char *text)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (!_this) {
return SDL_SetError("Video subsystem must be initialized to set clipboard text");
}
if (!text) {
text = "";
}
if (_this->SetClipboardText) {
return _this->SetClipboardText(_this, text);
} else {
SDL_free(_this->clipboard_text);
_this->clipboard_text = SDL_strdup(text);
return 0;
}
}
char *
SDL_GetClipboardText(void)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (!_this) {
SDL_SetError("Video subsystem must be initialized to get clipboard text");
return SDL_strdup("");
}
if (_this->GetClipboardText) {
return _this->GetClipboardText(_this);
} else {
const char *text = _this->clipboard_text;
if (!text) {
text = "";
}
return SDL_strdup(text);
}
}
SDL_bool
SDL_HasClipboardText(void)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (!_this) {
SDL_SetError("Video subsystem must be initialized to check clipboard text");
return SDL_FALSE;
}
if (_this->HasClipboardText) {
return _this->HasClipboardText(_this);
} else {
if (_this->clipboard_text && _this->clipboard_text[0] != '\0') {
return SDL_TRUE;
} else {
return SDL_FALSE;
}
}
}
/* vi: set ts=4 sw=4 expandtab: */

1115
externals/SDL/src/video/SDL_egl.c vendored Executable file

File diff suppressed because it is too large Load Diff

168
externals/SDL/src/video/SDL_egl_c.h vendored Executable file
View File

@@ -0,0 +1,168 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#ifndef SDL_egl_h_
#define SDL_egl_h_
#if SDL_VIDEO_OPENGL_EGL
#include "SDL_egl.h"
#include "SDL_sysvideo.h"
#define SDL_EGL_MAX_DEVICES 8
typedef struct SDL_EGL_VideoData
{
void *egl_dll_handle, *dll_handle;
EGLDisplay egl_display;
EGLConfig egl_config;
int egl_swapinterval;
int egl_surfacetype;
int egl_version_major, egl_version_minor;
EGLint egl_required_visual_id;
EGLDisplay(EGLAPIENTRY *eglGetDisplay) (NativeDisplayType display);
EGLDisplay(EGLAPIENTRY *eglGetPlatformDisplay) (EGLenum platform,
void *native_display,
const EGLint *attrib_list);
EGLDisplay(EGLAPIENTRY *eglGetPlatformDisplayEXT) (EGLenum platform,
void *native_display,
const EGLint *attrib_list);
EGLBoolean(EGLAPIENTRY *eglInitialize) (EGLDisplay dpy, EGLint * major,
EGLint * minor);
EGLBoolean(EGLAPIENTRY *eglTerminate) (EGLDisplay dpy);
void *(EGLAPIENTRY *eglGetProcAddress) (const char * procName);
EGLBoolean(EGLAPIENTRY *eglChooseConfig) (EGLDisplay dpy,
const EGLint * attrib_list,
EGLConfig * configs,
EGLint config_size, EGLint * num_config);
EGLContext(EGLAPIENTRY *eglCreateContext) (EGLDisplay dpy,
EGLConfig config,
EGLContext share_list,
const EGLint * attrib_list);
EGLBoolean(EGLAPIENTRY *eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
EGLSurface(EGLAPIENTRY *eglCreatePbufferSurface)(EGLDisplay dpy, EGLConfig config,
EGLint const* attrib_list);
EGLSurface(EGLAPIENTRY *eglCreateWindowSurface) (EGLDisplay dpy,
EGLConfig config,
NativeWindowType window,
const EGLint * attrib_list);
EGLBoolean(EGLAPIENTRY *eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
EGLBoolean(EGLAPIENTRY *eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
EGLSurface read, EGLContext ctx);
EGLBoolean(EGLAPIENTRY *eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
EGLBoolean(EGLAPIENTRY *eglSwapInterval) (EGLDisplay dpy, EGLint interval);
const char *(EGLAPIENTRY *eglQueryString) (EGLDisplay dpy, EGLint name);
EGLenum(EGLAPIENTRY *eglQueryAPI)(void);
EGLBoolean(EGLAPIENTRY *eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
EGLint attribute, EGLint * value);
EGLBoolean(EGLAPIENTRY *eglWaitNative) (EGLint engine);
EGLBoolean(EGLAPIENTRY *eglWaitGL)(void);
EGLBoolean(EGLAPIENTRY *eglBindAPI)(EGLenum);
EGLint(EGLAPIENTRY *eglGetError)(void);
EGLBoolean(EGLAPIENTRY *eglQueryDevicesEXT)(EGLint max_devices,
void **devices,
EGLint *num_devices);
/* whether EGL display was offscreen */
int is_offscreen;
} SDL_EGL_VideoData;
/* OpenGLES functions */
extern int SDL_EGL_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
/* SDL_EGL_LoadLibrary can get a display for a specific platform (EGL_PLATFORM_*)
* or, if 0 is passed, let the implementation decide.
*/
extern int SDL_EGL_LoadLibraryOnly(_THIS, const char *path);
extern int SDL_EGL_LoadLibrary(_THIS, const char *path, NativeDisplayType native_display, EGLenum platform);
extern void *SDL_EGL_GetProcAddress(_THIS, const char *proc);
extern void SDL_EGL_UnloadLibrary(_THIS);
extern void SDL_EGL_SetRequiredVisualId(_THIS, int visual_id);
extern int SDL_EGL_ChooseConfig(_THIS);
extern int SDL_EGL_SetSwapInterval(_THIS, int interval);
extern int SDL_EGL_GetSwapInterval(_THIS);
extern void SDL_EGL_DeleteContext(_THIS, SDL_GLContext context);
extern EGLSurface *SDL_EGL_CreateSurface(_THIS, NativeWindowType nw);
extern void SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface);
extern EGLSurface SDL_EGL_CreateOffscreenSurface(_THIS, int width, int height);
/* Assumes that LoadLibraryOnly() has succeeded */
extern int SDL_EGL_InitializeOffscreen(_THIS, int device);
/* These need to be wrapped to get the surface for the window by the platform GLES implementation */
extern SDL_GLContext SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface);
extern int SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context);
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);
#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_MakeCurrent_impl(BACKEND) int \
BACKEND ## _GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) \
{\
if (window && context) { \
return SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context); \
}\
else {\
return SDL_EGL_MakeCurrent(_this, NULL, NULL);\
}\
}
#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 */
#endif /* SDL_egl_h_ */
/* vi: set ts=4 sw=4 expandtab: */

428
externals/SDL/src/video/SDL_fillrect.c vendored Executable file
View File

@@ -0,0 +1,428 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#include "SDL_video.h"
#include "SDL_blit.h"
#include "SDL_cpuinfo.h"
#ifdef __SSE__
/* *INDENT-OFF* */
#ifdef _MSC_VER
#define SSE_BEGIN \
__m128 c128; \
c128.m128_u32[0] = color; \
c128.m128_u32[1] = color; \
c128.m128_u32[2] = color; \
c128.m128_u32[3] = color;
#else
#define SSE_BEGIN \
__m128 c128; \
DECLARE_ALIGNED(Uint32, cccc[4], 16); \
cccc[0] = color; \
cccc[1] = color; \
cccc[2] = color; \
cccc[3] = color; \
c128 = *(__m128 *)cccc;
#endif
#define SSE_WORK \
for (i = n / 64; i--;) { \
_mm_stream_ps((float *)(p+0), c128); \
_mm_stream_ps((float *)(p+16), c128); \
_mm_stream_ps((float *)(p+32), c128); \
_mm_stream_ps((float *)(p+48), c128); \
p += 64; \
}
#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) \
{ \
int i, n; \
Uint8 *p = NULL; \
\
SSE_BEGIN; \
\
while (h--) { \
n = w * bpp; \
p = pixels; \
\
if (n > 63) { \
int adjust = 16 - ((uintptr_t)p & 15); \
if (adjust < 16) { \
n -= adjust; \
adjust /= bpp; \
while (adjust--) { \
*((type *)p) = (type)color; \
p += bpp; \
} \
} \
SSE_WORK; \
} \
if (n & 63) { \
int remainder = (n & 63); \
remainder /= bpp; \
while (remainder--) { \
*((type *)p) = (type)color; \
p += bpp; \
} \
} \
pixels += pitch; \
} \
\
SSE_END; \
}
static void
SDL_FillRect1SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
{
int i, n;
SSE_BEGIN;
while (h--) {
Uint8 *p = pixels;
n = w;
if (n > 63) {
int adjust = 16 - ((uintptr_t)p & 15);
if (adjust) {
n -= adjust;
SDL_memset(p, color, adjust);
p += adjust;
}
SSE_WORK;
}
if (n & 63) {
int remainder = (n & 63);
SDL_memset(p, color, remainder);
}
pixels += pitch;
}
SSE_END;
}
/* DEFINE_SSE_FILLRECT(1, Uint8) */
DEFINE_SSE_FILLRECT(2, Uint16)
DEFINE_SSE_FILLRECT(4, Uint32)
/* *INDENT-ON* */
#endif /* __SSE__ */
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) {
case 1:
*p++ = (Uint8) color;
--n; /* fallthrough */
case 2:
*p++ = (Uint8) color;
--n; /* fallthrough */
case 3:
*p++ = (Uint8) color;
--n; /* fallthrough */
}
SDL_memset4(p, color, (n >> 2));
}
if (n & 3) {
p += (n & ~3);
switch (n & 3) {
case 3:
*p++ = (Uint8) color; /* fallthrough */
case 2:
*p++ = (Uint8) color; /* fallthrough */
case 1:
*p++ = (Uint8) color; /* fallthrough */
}
}
pixels += pitch;
}
}
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;
if (n > 1) {
if ((uintptr_t) p & 2) {
*p++ = (Uint16) color;
--n;
}
SDL_memset4(p, color, (n >> 1));
}
if (n & 1) {
p[n - 1] = (Uint16) color;
}
pixels += pitch;
}
}
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);
#elif SDL_BYTEORDER == SDL_BIG_ENDIAN
Uint8 b1 = (Uint8) ((color >> 16) & 0xFF);
Uint8 b2 = (Uint8) ((color >> 8) & 0xFF);
Uint8 b3 = (Uint8) (color & 0xFF);
#endif
int n;
Uint8 *p = NULL;
while (h--) {
n = w;
p = pixels;
while (n--) {
*p++ = b1;
*p++ = b2;
*p++ = b3;
}
pixels += pitch;
}
}
static void
SDL_FillRect4(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
{
while (h--) {
SDL_memset4(pixels, color, w);
pixels += pitch;
}
}
/*
* This function performs a fast fill of the given rectangle with 'color'
*/
int
SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
{
if (!dst) {
return SDL_SetError("Passed NULL destination surface");
}
/* If 'rect' == NULL, then fill the whole surface */
if (!rect) {
rect = &dst->clip_rect;
/* Don't attempt to fill if the surface's clip_rect is empty */
if (SDL_RectEmpty(rect)) {
return 0;
}
}
return SDL_FillRects(dst, rect, 1, color);
}
#if SDL_ARM_NEON_BLITTERS
void FillRect8ARMNEONAsm(int32_t w, int32_t h, uint8_t *dst, int32_t dst_stride, uint8_t src);
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);
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);
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);
return;
}
#endif
#if SDL_ARM_SIMD_BLITTERS
void FillRect8ARMSIMDAsm(int32_t w, int32_t h, uint8_t *dst, int32_t dst_stride, uint8_t src);
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);
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);
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);
return;
}
#endif
int
SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
Uint32 color)
{
SDL_Rect clipped;
Uint8 *pixels;
const SDL_Rect* rect;
void (*fill_function)(Uint8 * pixels, int pitch, Uint32 color, int w, int h) = NULL;
int i;
if (!dst) {
return SDL_SetError("Passed NULL destination surface");
}
/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->BitsPerPixel < 8) {
return SDL_SetError("SDL_FillRect(): Unsupported surface format");
}
/* Perform software fill */
if (!dst->pixels) {
return SDL_SetError("SDL_FillRect(): You must lock the surface");
}
if (!rects) {
return SDL_SetError("SDL_FillRects() passed NULL rects");
}
#if SDL_ARM_NEON_BLITTERS
if (SDL_HasNEON() && dst->format->BytesPerPixel != 3 && fill_function == NULL) {
switch (dst->format->BytesPerPixel) {
case 1:
fill_function = fill_8_neon;
break;
case 2:
fill_function = fill_16_neon;
break;
case 4:
fill_function = fill_32_neon;
break;
}
}
#endif
#if SDL_ARM_SIMD_BLITTERS
if (SDL_HasARMSIMD() && dst->format->BytesPerPixel != 3 && fill_function == NULL) {
switch (dst->format->BytesPerPixel) {
case 1:
fill_function = fill_8_simd;
break;
case 2:
fill_function = fill_16_simd;
break;
case 4:
fill_function = fill_32_simd;
break;
}
}
#endif
if (fill_function == NULL) {
switch (dst->format->BytesPerPixel) {
case 1:
{
color |= (color << 8);
color |= (color << 16);
#ifdef __SSE__
if (SDL_HasSSE()) {
fill_function = SDL_FillRect1SSE;
break;
}
#endif
fill_function = SDL_FillRect1;
break;
}
case 2:
{
color |= (color << 16);
#ifdef __SSE__
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. */
{
fill_function = SDL_FillRect3;
break;
}
case 4:
{
#ifdef __SSE__
if (SDL_HasSSE()) {
fill_function = SDL_FillRect4SSE;
break;
}
#endif
fill_function = SDL_FillRect4;
break;
}
default:
return SDL_SetError("Unsupported pixel format");
}
}
for (i = 0; i < count; ++i) {
rect = &rects[i];
/* Perform clipping */
if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
continue;
}
rect = &clipped;
pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch +
rect->x * dst->format->BytesPerPixel;
fill_function(pixels, dst->pitch, color, rect->w, rect->h);
}
/* We're done! */
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */

1134
externals/SDL/src/video/SDL_pixels.c vendored Executable file

File diff suppressed because it is too large Load Diff

46
externals/SDL/src/video/SDL_pixels_c.h vendored Executable file
View File

@@ -0,0 +1,46 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_pixels_c_h_
#define SDL_pixels_c_h_
#include "../SDL_internal.h"
/* Useful functions and variables from SDL_pixel.c */
#include "SDL_blit.h"
/* Pixel format functions */
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);
/* 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);
#endif /* SDL_pixels_c_h_ */
/* vi: set ts=4 sw=4 expandtab: */

531
externals/SDL/src/video/SDL_rect.c vendored Executable file
View File

@@ -0,0 +1,531 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#include "SDL_rect.h"
#include "SDL_rect_c.h"
#include "SDL_assert.h"
SDL_bool
SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B)
{
int Amin, Amax, Bmin, Bmax;
if (!A) {
SDL_InvalidParamError("A");
return SDL_FALSE;
}
if (!B) {
SDL_InvalidParamError("B");
return SDL_FALSE;
}
/* Special cases for empty rects */
if (SDL_RectEmpty(A) || SDL_RectEmpty(B)) {
return SDL_FALSE;
}
/* Horizontal intersection */
Amin = A->x;
Amax = Amin + A->w;
Bmin = B->x;
Bmax = Bmin + B->w;
if (Bmin > Amin)
Amin = Bmin;
if (Bmax < Amax)
Amax = Bmax;
if (Amax <= Amin)
return SDL_FALSE;
/* Vertical intersection */
Amin = A->y;
Amax = Amin + A->h;
Bmin = B->y;
Bmax = Bmin + B->h;
if (Bmin > Amin)
Amin = Bmin;
if (Bmax < Amax)
Amax = Bmax;
if (Amax <= Amin)
return SDL_FALSE;
return SDL_TRUE;
}
SDL_bool
SDL_IntersectRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result)
{
int Amin, Amax, Bmin, Bmax;
if (!A) {
SDL_InvalidParamError("A");
return SDL_FALSE;
}
if (!B) {
SDL_InvalidParamError("B");
return SDL_FALSE;
}
if (!result) {
SDL_InvalidParamError("result");
return SDL_FALSE;
}
/* Special cases for empty rects */
if (SDL_RectEmpty(A) || SDL_RectEmpty(B)) {
result->w = 0;
result->h = 0;
return SDL_FALSE;
}
/* Horizontal intersection */
Amin = A->x;
Amax = Amin + A->w;
Bmin = B->x;
Bmax = Bmin + B->w;
if (Bmin > Amin)
Amin = Bmin;
result->x = Amin;
if (Bmax < Amax)
Amax = Bmax;
result->w = Amax - Amin;
/* Vertical intersection */
Amin = A->y;
Amax = Amin + A->h;
Bmin = B->y;
Bmax = Bmin + B->h;
if (Bmin > Amin)
Amin = Bmin;
result->y = Amin;
if (Bmax < Amax)
Amax = Bmax;
result->h = Amax - Amin;
return !SDL_RectEmpty(result);
}
void
SDL_UnionRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result)
{
int Amin, Amax, Bmin, Bmax;
if (!A) {
SDL_InvalidParamError("A");
return;
}
if (!B) {
SDL_InvalidParamError("B");
return;
}
if (!result) {
SDL_InvalidParamError("result");
return;
}
/* Special cases for empty Rects */
if (SDL_RectEmpty(A)) {
if (SDL_RectEmpty(B)) {
/* A and B empty */
return;
} else {
/* A empty, B not empty */
*result = *B;
return;
}
} else {
if (SDL_RectEmpty(B)) {
/* A not empty, B empty */
*result = *A;
return;
}
}
/* Horizontal union */
Amin = A->x;
Amax = Amin + A->w;
Bmin = B->x;
Bmax = Bmin + B->w;
if (Bmin < Amin)
Amin = Bmin;
result->x = Amin;
if (Bmax > Amax)
Amax = Bmax;
result->w = Amax - Amin;
/* Vertical union */
Amin = A->y;
Amax = Amin + A->h;
Bmin = B->y;
Bmax = Bmin + B->h;
if (Bmin < Amin)
Amin = Bmin;
result->y = Amin;
if (Bmax > Amax)
Amax = Bmax;
result->h = Amax - Amin;
}
SDL_bool
SDL_EnclosePoints(const SDL_Point * points, int count, const SDL_Rect * clip,
SDL_Rect * result)
{
int minx = 0;
int miny = 0;
int maxx = 0;
int maxy = 0;
int x, y, i;
if (!points) {
SDL_InvalidParamError("points");
return SDL_FALSE;
}
if (count < 1) {
SDL_InvalidParamError("count");
return SDL_FALSE;
}
if (clip) {
SDL_bool added = SDL_FALSE;
const int clip_minx = clip->x;
const int clip_miny = clip->y;
const int clip_maxx = clip->x+clip->w-1;
const int clip_maxy = clip->y+clip->h-1;
/* Special case for empty rectangle */
if (SDL_RectEmpty(clip)) {
return SDL_FALSE;
}
for (i = 0; i < count; ++i) {
x = points[i].x;
y = points[i].y;
if (x < clip_minx || x > clip_maxx ||
y < clip_miny || y > clip_maxy) {
continue;
}
if (!added) {
/* Special case: if no result was requested, we are done */
if (result == NULL) {
return SDL_TRUE;
}
/* First point added */
minx = maxx = x;
miny = maxy = y;
added = SDL_TRUE;
continue;
}
if (x < minx) {
minx = x;
} else if (x > maxx) {
maxx = x;
}
if (y < miny) {
miny = y;
} else if (y > maxy) {
maxy = y;
}
}
if (!added) {
return SDL_FALSE;
}
} else {
/* Special case: if no result was requested, we are done */
if (result == NULL) {
return SDL_TRUE;
}
/* No clipping, always add the first point */
minx = maxx = points[0].x;
miny = maxy = points[0].y;
for (i = 1; i < count; ++i) {
x = points[i].x;
y = points[i].y;
if (x < minx) {
minx = x;
} else if (x > maxx) {
maxx = x;
}
if (y < miny) {
miny = y;
} else if (y > maxy) {
maxy = y;
}
}
}
if (result) {
result->x = minx;
result->y = miny;
result->w = (maxx-minx)+1;
result->h = (maxy-miny)+1;
}
return SDL_TRUE;
}
/* Use the Cohen-Sutherland algorithm for line clipping */
#define CODE_BOTTOM 1
#define CODE_TOP 2
#define CODE_LEFT 4
#define CODE_RIGHT 8
static int
ComputeOutCode(const SDL_Rect * rect, int x, int y)
{
int code = 0;
if (y < rect->y) {
code |= CODE_TOP;
} else if (y >= rect->y + rect->h) {
code |= CODE_BOTTOM;
}
if (x < rect->x) {
code |= CODE_LEFT;
} else if (x >= rect->x + rect->w) {
code |= CODE_RIGHT;
}
return code;
}
SDL_bool
SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2,
int *Y2)
{
int x = 0;
int y = 0;
int x1, y1;
int x2, y2;
int rectx1;
int recty1;
int rectx2;
int recty2;
int outcode1, outcode2;
if (!rect) {
SDL_InvalidParamError("rect");
return SDL_FALSE;
}
if (!X1) {
SDL_InvalidParamError("X1");
return SDL_FALSE;
}
if (!Y1) {
SDL_InvalidParamError("Y1");
return SDL_FALSE;
}
if (!X2) {
SDL_InvalidParamError("X2");
return SDL_FALSE;
}
if (!Y2) {
SDL_InvalidParamError("Y2");
return SDL_FALSE;
}
/* Special case for empty rect */
if (SDL_RectEmpty(rect)) {
return SDL_FALSE;
}
x1 = *X1;
y1 = *Y1;
x2 = *X2;
y2 = *Y2;
rectx1 = rect->x;
recty1 = rect->y;
rectx2 = rect->x + rect->w - 1;
recty2 = rect->y + rect->h - 1;
/* Check to see if entire line is inside rect */
if (x1 >= rectx1 && x1 <= rectx2 && x2 >= rectx1 && x2 <= rectx2 &&
y1 >= recty1 && y1 <= recty2 && y2 >= recty1 && y2 <= recty2) {
return SDL_TRUE;
}
/* Check to see if entire line is to one side of rect */
if ((x1 < rectx1 && x2 < rectx1) || (x1 > rectx2 && x2 > rectx2) ||
(y1 < recty1 && y2 < recty1) || (y1 > recty2 && y2 > recty2)) {
return SDL_FALSE;
}
if (y1 == y2) {
/* Horizontal line, easy to clip */
if (x1 < rectx1) {
*X1 = rectx1;
} else if (x1 > rectx2) {
*X1 = rectx2;
}
if (x2 < rectx1) {
*X2 = rectx1;
} else if (x2 > rectx2) {
*X2 = rectx2;
}
return SDL_TRUE;
}
if (x1 == x2) {
/* Vertical line, easy to clip */
if (y1 < recty1) {
*Y1 = recty1;
} else if (y1 > recty2) {
*Y1 = recty2;
}
if (y2 < recty1) {
*Y2 = recty1;
} else if (y2 > recty2) {
*Y2 = recty2;
}
return SDL_TRUE;
}
/* More complicated Cohen-Sutherland algorithm */
outcode1 = ComputeOutCode(rect, x1, y1);
outcode2 = ComputeOutCode(rect, x2, y2);
while (outcode1 || outcode2) {
if (outcode1 & outcode2) {
return SDL_FALSE;
}
if (outcode1) {
if (outcode1 & CODE_TOP) {
y = recty1;
x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1);
} else if (outcode1 & CODE_BOTTOM) {
y = recty2;
x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1);
} else if (outcode1 & CODE_LEFT) {
x = rectx1;
y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);
} else if (outcode1 & CODE_RIGHT) {
x = rectx2;
y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);
}
x1 = x;
y1 = y;
outcode1 = ComputeOutCode(rect, x, y);
} else {
if (outcode2 & CODE_TOP) {
y = recty1;
x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1);
} else if (outcode2 & CODE_BOTTOM) {
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. */
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. */
x = rectx2;
y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);
}
x2 = x;
y2 = y;
outcode2 = ComputeOutCode(rect, x, y);
}
}
*X1 = x1;
*Y1 = y1;
*X2 = x2;
*Y2 = y2;
return SDL_TRUE;
}
SDL_bool
SDL_GetSpanEnclosingRect(int width, int height,
int numrects, const SDL_Rect * rects, SDL_Rect *span)
{
int i;
int span_y1, span_y2;
int rect_y1, rect_y2;
if (width < 1) {
SDL_InvalidParamError("width");
return SDL_FALSE;
}
if (height < 1) {
SDL_InvalidParamError("height");
return SDL_FALSE;
}
if (!rects) {
SDL_InvalidParamError("rects");
return SDL_FALSE;
}
if (!span) {
SDL_InvalidParamError("span");
return SDL_FALSE;
}
if (numrects < 1) {
SDL_InvalidParamError("numrects");
return SDL_FALSE;
}
/* Initialize to empty rect */
span_y1 = height;
span_y2 = 0;
for (i = 0; i < numrects; ++i) {
rect_y1 = rects[i].y;
rect_y2 = rect_y1 + rects[i].h;
/* Clip out of bounds rectangles, and expand span rect */
if (rect_y1 < 0) {
span_y1 = 0;
} else if (rect_y1 < span_y1) {
span_y1 = rect_y1;
}
if (rect_y2 > height) {
span_y2 = height;
} else if (rect_y2 > span_y2) {
span_y2 = rect_y2;
}
}
if (span_y2 > span_y1) {
span->x = 0;
span->y = span_y1;
span->w = width;
span->h = (span_y2 - span_y1);
return SDL_TRUE;
}
return SDL_FALSE;
}
/* vi: set ts=4 sw=4 expandtab: */

31
externals/SDL/src/video/SDL_rect_c.h vendored Executable file
View File

@@ -0,0 +1,31 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_rect_c_h_
#define SDL_rect_c_h_
#include "../SDL_internal.h"
extern SDL_bool SDL_GetSpanEnclosingRect(int width, int height, int numrects, const SDL_Rect * rects, SDL_Rect *span);
#endif /* SDL_rect_c_h_ */
/* vi: set ts=4 sw=4 expandtab: */

309
externals/SDL/src/video/SDL_shape.c vendored Executable file
View File

@@ -0,0 +1,309 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#include "SDL.h"
#include "SDL_assert.h"
#include "SDL_video.h"
#include "SDL_sysvideo.h"
#include "SDL_pixels.h"
#include "SDL_surface.h"
#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 *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) {
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 {
SDL_DestroyWindow(result);
return NULL;
}
}
else
return NULL;
}
SDL_bool
SDL_IsShapedWindow(const SDL_Window *window)
{
if(window == NULL)
return SDL_FALSE;
else
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)
{
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 *bitmap_scanline;
SDL_Color key;
if(SDL_MUSTLOCK(shape))
SDL_LockSurface(shape);
for(y = 0;y<shape->h;y++) {
bitmap_scanline = bitmap + y * bytes_per_scanline;
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;
}
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))
SDL_UnlockSurface(shape);
}
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;
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};
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;
}
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)
last_opaque = pixel_opaque;
if(last_opaque != pixel_opaque) {
const int halfwidth = dimensions.w / 2;
const int halfheight = dimensions.h / 2;
result->kind = QuadShape;
next.x = dimensions.x;
next.y = dimensions.y;
next.w = halfwidth;
next.h = halfheight;
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);
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);
next.x = dimensions.x + halfwidth;
next.w = dimensions.w - halfwidth;
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_Rect dimensions;
SDL_ShapeTree* result = NULL;
dimensions.x = 0;
dimensions.y = 0;
dimensions.w = shape->w;
dimensions.h = shape->h;
if(SDL_MUSTLOCK(shape))
SDL_LockSurface(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)
{
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);
}
else
function(tree,closure);
}
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);
}
SDL_free(*shape_tree);
*shape_tree = NULL;
}
int
SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode)
{
int result;
if(window == NULL || !SDL_IsShapedWindow(window))
/* The window given was not a shapeable window. */
return SDL_NONSHAPEABLE_WINDOW;
if(shape == NULL)
/* Invalid shape argument. */
return SDL_INVALID_SHAPE_ARGUMENT;
if(shape_mode != NULL)
window->shaper->mode = *shape_mode;
result = SDL_GetVideoDevice()->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);
window->shaper->userx = 0;
window->shaper->usery = 0;
}
return result;
}
static SDL_bool
SDL_WindowHasAShape(SDL_Window *window)
{
if (window == NULL || !SDL_IsShapedWindow(window))
return SDL_FALSE;
return window->shaper->hasshape;
}
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 {
*shape_mode = window->shaper->mode;
return 0;
}
}
else
/* The window given is not a valid shapeable window. */
return SDL_NONSHAPEABLE_WINDOW;
}

69
externals/SDL/src/video/SDL_shape_internals.h vendored Executable file
View File

@@ -0,0 +1,69 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#ifndef SDL_shape_internals_h_
#define SDL_shape_internals_h_
#include "SDL_rect.h"
#include "SDL_shape.h"
#include "SDL_surface.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
typedef struct {
struct SDL_ShapeTree *upleft,*upright,*downleft,*downright;
} SDL_QuadTreeChildren;
typedef union {
SDL_QuadTreeChildren children;
SDL_Rect shape;
} SDL_ShapeUnion;
typedef enum { QuadShape,TransparentShape,OpaqueShape } SDL_ShapeKind;
typedef struct {
SDL_ShapeKind kind;
SDL_ShapeUnion data;
} SDL_ShapeTree;
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);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif

353
externals/SDL/src/video/SDL_stretch.c vendored Executable file
View File

@@ -0,0 +1,353 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
/* This a stretch blit implementation based on ideas given to me by
Tomasz Cejner - thanks! :)
April 27, 2000 - Sam Lantinga
*/
#include "SDL_video.h"
#include "SDL_blit.h"
/* This isn't ready for general consumption yet - it should be folded
into the general blitting mechanism.
*/
#if ((defined(_MSC_VER) && defined(_M_IX86)) || \
(defined(__WATCOMC__) && defined(__386__)) || \
(defined(__GNUC__) && defined(__i386__))) && SDL_ASSEMBLY_ROUTINES
/* There's a bug with gcc 4.4.1 and -O2 where srcp doesn't get the correct
* value after the first scanline. FIXME? */
/* #define USE_ASM_STRETCH */
#endif
#ifdef USE_ASM_STRETCH
#ifdef HAVE_MPROTECT
#include <sys/types.h>
#include <sys/mman.h>
#endif
#ifdef __GNUC__
#define PAGE_ALIGNED __attribute__((__aligned__(4096)))
#else
#define PAGE_ALIGNED
#endif
#if defined(_M_IX86) || defined(__i386__) || defined(__386__)
#define PREFIX16 0x66
#define STORE_BYTE 0xAA
#define STORE_WORD 0xAB
#define LOAD_BYTE 0xAC
#define LOAD_WORD 0xAD
#define RETURN 0xC3
#else
#error Need assembly opcodes for this architecture
#endif
static unsigned char copy_row[4096] PAGE_ALIGNED;
static int
generate_rowbytes(int src_w, int dst_w, int bpp)
{
static struct
{
int bpp;
int src_w;
int dst_w;
int status;
} last;
int i;
int pos, inc;
unsigned char *eip, *fence;
unsigned char load, store;
/* See if we need to regenerate the copy buffer */
if ((src_w == last.src_w) && (dst_w == last.dst_w) && (bpp == last.bpp)) {
return (last.status);
}
last.bpp = bpp;
last.src_w = src_w;
last.dst_w = dst_w;
last.status = -1;
switch (bpp) {
case 1:
load = LOAD_BYTE;
store = STORE_BYTE;
break;
case 2:
case 4:
load = LOAD_WORD;
store = STORE_WORD;
break;
default:
return SDL_SetError("ASM stretch of %d bytes isn't supported", bpp);
}
#ifdef HAVE_MPROTECT
/* Make the code writeable */
if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_WRITE) < 0) {
return SDL_SetError("Couldn't make copy buffer writeable");
}
#endif
pos = 0x10000;
inc = (src_w << 16) / dst_w;
eip = copy_row;
fence = copy_row + sizeof(copy_row)-2;
for (i = 0; i < dst_w; ++i) {
while (pos >= 0x10000L) {
if (eip == fence) {
return -1;
}
if (bpp == 2) {
*eip++ = PREFIX16;
}
*eip++ = load;
pos -= 0x10000L;
}
if (eip == fence) {
return -1;
}
if (bpp == 2) {
*eip++ = PREFIX16;
}
*eip++ = store;
pos += inc;
}
*eip++ = RETURN;
#ifdef HAVE_MPROTECT
/* Make the code executable but not writeable */
if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_EXEC) < 0) {
return SDL_SetError("Couldn't make copy buffer executable");
}
#endif
last.status = 0;
return (0);
}
#endif /* USE_ASM_STRETCH */
#define DEFINE_COPY_ROW(name, type) \
static void name(type *src, int src_w, type *dst, int dst_w) \
{ \
int i; \
int pos, inc; \
type pixel = 0; \
\
pos = 0x10000; \
inc = (src_w << 16) / dst_w; \
for ( i=dst_w; i>0; --i ) { \
while ( pos >= 0x10000L ) { \
pixel = *src++; \
pos -= 0x10000L; \
} \
*dst++ = pixel; \
pos += inc; \
} \
}
/* *INDENT-OFF* */
DEFINE_COPY_ROW(copy_row1, Uint8)
DEFINE_COPY_ROW(copy_row2, Uint16)
DEFINE_COPY_ROW(copy_row4, Uint32)
/* *INDENT-ON* */
/* The ASM code doesn't handle 24-bpp stretch blits */
static void
copy_row3(Uint8 * src, int src_w, Uint8 * dst, int dst_w)
{
int i;
int pos, inc;
Uint8 pixel[3] = { 0, 0, 0 };
pos = 0x10000;
inc = (src_w << 16) / dst_w;
for (i = dst_w; i > 0; --i) {
while (pos >= 0x10000L) {
pixel[0] = *src++;
pixel[1] = *src++;
pixel[2] = *src++;
pos -= 0x10000L;
}
*dst++ = pixel[0];
*dst++ = pixel[1];
*dst++ = pixel[2];
pos += inc;
}
}
/* Perform a stretch blit between two surfaces of the same format.
NOTE: This function is not safe to call from multiple threads!
*/
int
SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect,
SDL_Surface * dst, const SDL_Rect * dstrect)
{
int src_locked;
int dst_locked;
int pos, inc;
int dst_maxrow;
int src_row, dst_row;
Uint8 *srcp = NULL;
Uint8 *dstp;
SDL_Rect full_src;
SDL_Rect full_dst;
#ifdef USE_ASM_STRETCH
SDL_bool use_asm = SDL_TRUE;
#ifdef __GNUC__
int u1, u2;
#endif
#endif /* USE_ASM_STRETCH */
const int bpp = dst->format->BytesPerPixel;
if (src->format->format != dst->format->format) {
return SDL_SetError("Only works with same format surfaces");
}
/* Verify the blit rectangles */
if (srcrect) {
if ((srcrect->x < 0) || (srcrect->y < 0) ||
((srcrect->x + srcrect->w) > src->w) ||
((srcrect->y + srcrect->h) > src->h)) {
return SDL_SetError("Invalid source blit rectangle");
}
} else {
full_src.x = 0;
full_src.y = 0;
full_src.w = src->w;
full_src.h = src->h;
srcrect = &full_src;
}
if (dstrect) {
if ((dstrect->x < 0) || (dstrect->y < 0) ||
((dstrect->x + dstrect->w) > dst->w) ||
((dstrect->y + dstrect->h) > dst->h)) {
return SDL_SetError("Invalid destination blit rectangle");
}
} else {
full_dst.x = 0;
full_dst.y = 0;
full_dst.w = dst->w;
full_dst.h = dst->h;
dstrect = &full_dst;
}
/* Lock the destination if it's in hardware */
dst_locked = 0;
if (SDL_MUSTLOCK(dst)) {
if (SDL_LockSurface(dst) < 0) {
return SDL_SetError("Unable to lock destination surface");
}
dst_locked = 1;
}
/* Lock the source if it's in hardware */
src_locked = 0;
if (SDL_MUSTLOCK(src)) {
if (SDL_LockSurface(src) < 0) {
if (dst_locked) {
SDL_UnlockSurface(dst);
}
return SDL_SetError("Unable to lock source surface");
}
src_locked = 1;
}
/* Set up the data... */
pos = 0x10000;
inc = (srcrect->h << 16) / dstrect->h;
src_row = srcrect->y;
dst_row = dstrect->y;
#ifdef USE_ASM_STRETCH
/* Write the opcodes for this stretch */
if ((bpp == 3) || (generate_rowbytes(srcrect->w, dstrect->w, bpp) < 0)) {
use_asm = SDL_FALSE;
}
#endif
/* Perform the stretch blit */
for (dst_maxrow = dst_row + dstrect->h; dst_row < dst_maxrow; ++dst_row) {
dstp = (Uint8 *) dst->pixels + (dst_row * dst->pitch)
+ (dstrect->x * bpp);
while (pos >= 0x10000L) {
srcp = (Uint8 *) src->pixels + (src_row * src->pitch)
+ (srcrect->x * bpp);
++src_row;
pos -= 0x10000L;
}
#ifdef USE_ASM_STRETCH
if (use_asm) {
#ifdef __GNUC__
__asm__ __volatile__("call *%4":"=&D"(u1), "=&S"(u2)
:"0"(dstp), "1"(srcp), "r"(copy_row)
:"memory");
#elif defined(_MSC_VER) || defined(__WATCOMC__)
/* *INDENT-OFF* */
{
void *code = copy_row;
__asm {
push edi
push esi
mov edi, dstp
mov esi, srcp
call dword ptr code
pop esi
pop edi
}
}
/* *INDENT-ON* */
#else
#error Need inline assembly for this compiler
#endif
} else
#endif
switch (bpp) {
case 1:
copy_row1(srcp, srcrect->w, dstp, dstrect->w);
break;
case 2:
copy_row2((Uint16 *) srcp, srcrect->w,
(Uint16 *) dstp, dstrect->w);
break;
case 3:
copy_row3(srcp, srcrect->w, dstp, dstrect->w);
break;
case 4:
copy_row4((Uint32 *) srcp, srcrect->w,
(Uint32 *) dstp, dstrect->w);
break;
}
pos += inc;
}
/* We need to unlock the surfaces if they're locked */
if (dst_locked) {
SDL_UnlockSurface(dst);
}
if (src_locked) {
SDL_UnlockSurface(src);
}
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

1351
externals/SDL/src/video/SDL_surface.c vendored Executable file

File diff suppressed because it is too large Load Diff

469
externals/SDL/src/video/SDL_sysvideo.h vendored Executable file
View File

@@ -0,0 +1,469 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#ifndef SDL_sysvideo_h_
#define SDL_sysvideo_h_
#include "SDL_messagebox.h"
#include "SDL_shape.h"
#include "SDL_thread.h"
#include "SDL_metal.h"
#include "SDL_vulkan_internal.h"
/* The SDL video driver */
typedef struct SDL_WindowShaper SDL_WindowShaper;
typedef struct SDL_ShapeDriver SDL_ShapeDriver;
typedef struct SDL_VideoDisplay SDL_VideoDisplay;
typedef struct SDL_VideoDevice SDL_VideoDevice;
/* Define the SDL window-shaper structure */
struct SDL_WindowShaper
{
/* The window associated with the shaper */
SDL_Window *window;
/* The user's specified coordinates for the window, for once we give it a shape. */
Uint32 userx,usery;
/* The parameters for shape calculation. */
SDL_WindowShapeMode mode;
/* Has this window been assigned a shape? */
SDL_bool hasshape;
void *driverdata;
};
/* 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);
int (*ResizeWindowShape)(SDL_Window *window);
};
typedef struct SDL_WindowUserData
{
char *name;
void *data;
struct SDL_WindowUserData *next;
} SDL_WindowUserData;
/* Define the SDL window structure, corresponding to toplevel windows */
struct SDL_Window
{
const void *magic;
Uint32 id;
char *title;
SDL_Surface *icon;
int x, y;
int w, h;
int min_w, min_h;
int max_w, max_h;
Uint32 flags;
Uint32 last_fullscreen_flags;
/* Stored position and size for windowed mode */
SDL_Rect windowed;
SDL_DisplayMode fullscreen_mode;
float opacity;
float brightness;
Uint16 *gamma;
Uint16 *saved_gamma; /* (just offset into gamma) */
SDL_Surface *surface;
SDL_bool surface_valid;
SDL_bool is_hiding;
SDL_bool is_destroying;
SDL_bool is_dropping; /* drag/drop in progress, expecting SDL_SendDropComplete(). */
SDL_WindowShaper *shaper;
SDL_HitTest hit_test;
void *hit_test_data;
SDL_WindowUserData *data;
void *driverdata;
SDL_Window *prev;
SDL_Window *next;
};
#define FULLSCREEN_VISIBLE(W) \
(((W)->flags & SDL_WINDOW_FULLSCREEN) && \
((W)->flags & SDL_WINDOW_SHOWN) && \
!((W)->flags & SDL_WINDOW_MINIMIZED))
/*
* Define the SDL display structure.
* This corresponds to physical monitors attached to the system.
*/
struct SDL_VideoDisplay
{
char *name;
int max_display_modes;
int num_display_modes;
SDL_DisplayMode *display_modes;
SDL_DisplayMode desktop_mode;
SDL_DisplayMode current_mode;
SDL_DisplayOrientation orientation;
SDL_Window *fullscreen_window;
SDL_VideoDevice *device;
void *driverdata;
};
/* Forward declaration */
struct SDL_SysWMinfo;
/* Define the SDL video driver structure */
#define _THIS SDL_VideoDevice *_this
struct SDL_VideoDevice
{
/* * * */
/* The name of this video driver */
const char *name;
/* * * */
/* Initialization/Query functions */
/*
* 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);
/*
* Reverse the effects VideoInit() -- called if VideoInit() fails or
* if the application is shutting down the video subsystem.
*/
void (*VideoQuit) (_THIS);
/*
* Reinitialize the touch devices -- called if an unknown touch ID occurs.
*/
void (*ResetTouch) (_THIS);
/* * * */
/*
* Display functions
*/
/*
* Get the bounds of a display
*/
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);
/*
* Get the dots/pixels-per-inch of a display
*/
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);
/*
* Setting the display mode is independent of creating windows, so
* when the display mode is changed, all existing windows should have
* their data updated accordingly, including the display surfaces
* associated with them.
*/
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 (*SetWindowOpacity) (_THIS, SDL_Window * window, float opacity);
int (*SetWindowModalFor) (_THIS, SDL_Window * modal_window, SDL_Window * parent_window);
int (*SetWindowInputFocus) (_THIS, SDL_Window * window);
void (*ShowWindow) (_THIS, SDL_Window * window);
void (*HideWindow) (_THIS, SDL_Window * window);
void (*RaiseWindow) (_THIS, SDL_Window * window);
void (*MaximizeWindow) (_THIS, SDL_Window * window);
void (*MinimizeWindow) (_THIS, SDL_Window * window);
void (*RestoreWindow) (_THIS, SDL_Window * window);
void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
void (*SetWindowResizable) (_THIS, SDL_Window * window, SDL_bool resizable);
void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
void (*DestroyWindow) (_THIS, SDL_Window * window);
int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
void (*OnWindowEnter) (_THIS, SDL_Window * window);
/* * * */
/*
* Shaped-window functions
*/
SDL_ShapeDriver shape_driver;
/* Get some platform dependent window information */
SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
struct SDL_SysWMinfo * info);
/* * * */
/*
* OpenGL support
*/
int (*GL_LoadLibrary) (_THIS, const char *path);
void *(*GL_GetProcAddress) (_THIS, const char *proc);
void (*GL_UnloadLibrary) (_THIS);
SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
int (*GL_SetSwapInterval) (_THIS, int interval);
int (*GL_GetSwapInterval) (_THIS);
int (*GL_SwapWindow) (_THIS, SDL_Window * window);
void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
void (*GL_DefaultProfileConfig) (_THIS, int *mask, int *major, int *minor);
/* * * */
/*
* 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);
/* * * */
/*
* Metal support
*/
SDL_MetalView (*Metal_CreateView) (_THIS, SDL_Window * window);
void (*Metal_DestroyView) (_THIS, SDL_MetalView view);
/* * * */
/*
* Event manager functions
*/
void (*PumpEvents) (_THIS);
/* Suspend the screensaver */
void (*SuspendScreenSaver) (_THIS);
/* Text input */
void (*StartTextInput) (_THIS);
void (*StopTextInput) (_THIS);
void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
/* 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);
/* Clipboard */
int (*SetClipboardText) (_THIS, const char *text);
char * (*GetClipboardText) (_THIS);
SDL_bool (*HasClipboardText) (_THIS);
/* MessageBox */
int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
/* Hit-testing */
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);
/* * * */
/* Data common to all drivers */
SDL_bool is_dummy;
SDL_bool suspend_screensaver;
int num_displays;
SDL_VideoDisplay *displays;
SDL_Window *windows;
SDL_Window *grabbed_window;
Uint8 window_magic;
Uint32 next_object_id;
char *clipboard_text;
/* * * */
/* Data used by the GL drivers */
struct
{
int red_size;
int green_size;
int blue_size;
int alpha_size;
int depth_size;
int buffer_size;
int stencil_size;
int double_buffer;
int accum_red_size;
int accum_green_size;
int accum_blue_size;
int accum_alpha_size;
int stereo;
int multisamplebuffers;
int multisamplesamples;
int accelerated;
int major_version;
int minor_version;
int flags;
int profile_mask;
int share_with_current_context;
int release_behavior;
int reset_notification;
int framebuffer_srgb_capable;
int no_error;
int retained_backing;
int driver_loaded;
char driver_path[256];
void *dll_handle;
} gl_config;
/* * * */
/* Cache current GL context; don't call the OS when it hasn't changed. */
/* We have the global pointers here so Cocoa continues to work the way
it always has, and the thread-local storage for the general case.
*/
SDL_Window *current_glwin;
SDL_GLContext current_glctx;
SDL_TLSID current_glwin_tls;
SDL_TLSID current_glctx_tls;
/* * * */
/* Data used by the Vulkan drivers */
struct
{
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties;
int loader_loaded;
char loader_path[256];
void *loader_handle;
} vulkan_config;
/* * * */
/* 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);
};
typedef struct VideoBootStrap
{
const char *name;
const char *desc;
int (*available) (void);
SDL_VideoDevice *(*create) (int devindex);
} VideoBootStrap;
/* Not all of these are available in a given build. Use #ifdefs, etc. */
extern VideoBootStrap COCOA_bootstrap;
extern VideoBootStrap X11_bootstrap;
extern VideoBootStrap DirectFB_bootstrap;
extern VideoBootStrap WINDOWS_bootstrap;
extern VideoBootStrap WINRT_bootstrap;
extern VideoBootStrap HAIKU_bootstrap;
extern VideoBootStrap PND_bootstrap;
extern VideoBootStrap UIKIT_bootstrap;
extern VideoBootStrap Android_bootstrap;
extern VideoBootStrap PSP_bootstrap;
extern VideoBootStrap RPI_bootstrap;
extern VideoBootStrap KMSDRM_bootstrap;
extern VideoBootStrap DUMMY_bootstrap;
extern VideoBootStrap Wayland_bootstrap;
extern VideoBootStrap NACL_bootstrap;
extern VideoBootStrap VIVANTE_bootstrap;
extern VideoBootStrap Emscripten_bootstrap;
extern VideoBootStrap QNX_bootstrap;
extern VideoBootStrap OFFSCREEN_bootstrap;
extern SDL_VideoDevice *SDL_GetVideoDevice(void);
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
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 SDL_bool SDL_IsVideoContextExternal(void);
extern void SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor);
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_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);
extern float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches);
extern void SDL_ToggleDragAndDropSupport(void);
#endif /* SDL_sysvideo_h_ */
/* vi: set ts=4 sw=4 expandtab: */

4238
externals/SDL/src/video/SDL_video.c vendored Executable file

File diff suppressed because it is too large Load Diff

95
externals/SDL/src/video/SDL_vulkan_internal.h vendored Executable file
View File

@@ -0,0 +1,95 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_vulkan_internal_h_
#define SDL_vulkan_internal_h_
#include "../SDL_internal.h"
#include "SDL_stdinc.h"
#if defined(SDL_LOADSO_DISABLED)
#undef SDL_VIDEO_VULKAN
#define SDL_VIDEO_VULKAN 0
#endif
#if SDL_VIDEO_VULKAN
#if SDL_VIDEO_DRIVER_ANDROID
#define VK_USE_PLATFORM_ANDROID_KHR
#endif
#if SDL_VIDEO_DRIVER_COCOA
#define VK_USE_PLATFORM_MACOS_MVK
#endif
#if SDL_VIDEO_DRIVER_UIKIT
#define VK_USE_PLATFORM_IOS_MVK
#endif
#if SDL_VIDEO_DRIVER_WAYLAND
#define VK_USE_PLATFORM_WAYLAND_KHR
#include "wayland/SDL_waylanddyn.h"
#endif
#if SDL_VIDEO_DRIVER_WINDOWS
#define VK_USE_PLATFORM_WIN32_KHR
#include "../core/windows/SDL_windows.h"
#endif
#if SDL_VIDEO_DRIVER_X11
#define VK_USE_PLATFORM_XLIB_KHR
#define VK_USE_PLATFORM_XCB_KHR
#endif
#define VK_NO_PROTOTYPES
#include "./khronos/vulkan/vulkan.h"
#include "SDL_vulkan.h"
extern const char *SDL_Vulkan_GetResultString(VkResult result);
extern VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties,
Uint32 *extensionCount); /* free returned list with SDL_free */
/* Implements functionality of SDL_Vulkan_GetInstanceExtensions for a list of
* names passed in nameCount and names. */
extern SDL_bool SDL_Vulkan_GetInstanceExtensions_Helper(unsigned *userCount,
const char **userNames,
unsigned nameCount,
const char *const *names);
/* Create a surface directly from a display connected to a physical device
* using the DisplayKHR extension.
* This needs to be passed an instance that was created with the VK_KHR_DISPLAY_EXTENSION_NAME
* exension. */
extern SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr,
VkInstance instance,
VkSurfaceKHR *surface);
#else
/* No SDL Vulkan support, just include the header for typedefs */
#include "SDL_vulkan.h"
typedef void (*PFN_vkGetInstanceProcAddr) (void);
typedef int (*PFN_vkEnumerateInstanceExtensionProperties) (void);
#endif /* SDL_VIDEO_VULKAN */
#endif /* SDL_vulkan_internal_h_ */
/* vi: set ts=4 sw=4 expandtab: */

515
externals/SDL/src/video/SDL_vulkan_utils.c vendored Executable file
View File

@@ -0,0 +1,515 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#include "SDL_vulkan_internal.h"
#include "SDL_error.h"
#include "SDL_log.h"
/* !!! FIXME: this file doesn't match coding standards for SDL (brace position, etc). */
#if SDL_VIDEO_VULKAN
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_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_OUT_OF_POOL_MEMORY_KHR:
return "VK_ERROR_OUT_OF_POOL_MEMORY_KHR";
case VK_ERROR_INVALID_SHADER_NV:
return "VK_ERROR_INVALID_SHADER_NV";
case VK_RESULT_MAX_ENUM:
case VK_RESULT_RANGE_SIZE:
break;
}
if(result < 0)
return "VK_ERROR_<Unknown>";
return "VK_<Unknown>";
}
VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties,
Uint32 *extensionCount)
{
Uint32 count = 0;
VkResult result = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL);
VkExtensionProperties *retval;
if(result == VK_ERROR_INCOMPATIBLE_DRIVER)
{
/* Avoid the ERR_MAX_STRLEN limit by passing part of the message
* as a string argument.
*/
SDL_SetError(
"You probably don't have a working Vulkan driver installed. %s %s %s(%d)",
"Getting Vulkan extensions failed:",
"vkEnumerateInstanceExtensionProperties returned",
SDL_Vulkan_GetResultString(result),
(int)result);
return NULL;
}
else if(result != VK_SUCCESS)
{
SDL_SetError(
"Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned "
"%s(%d)",
SDL_Vulkan_GetResultString(result),
(int)result);
return NULL;
}
if(count == 0)
{
retval = SDL_calloc(1, sizeof(VkExtensionProperties)); // so we can return non-null
}
else
{
retval = SDL_calloc(count, sizeof(VkExtensionProperties));
}
if(!retval)
{
SDL_OutOfMemory();
return NULL;
}
result = vkEnumerateInstanceExtensionProperties(NULL, &count, retval);
if(result != VK_SUCCESS)
{
SDL_SetError(
"Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned "
"%s(%d)",
SDL_Vulkan_GetResultString(result),
(int)result);
SDL_free(retval);
return NULL;
}
*extensionCount = count;
return retval;
}
SDL_bool SDL_Vulkan_GetInstanceExtensions_Helper(unsigned *userCount,
const char **userNames,
unsigned nameCount,
const char *const *names)
{
if (userNames) {
unsigned i;
if (*userCount < nameCount) {
SDL_SetError("Output array for SDL_Vulkan_GetInstanceExtensions needs to be at least %d big", nameCount);
return SDL_FALSE;
}
for (i = 0; i < nameCount; i++) {
userNames[i] = names[i];
}
}
*userCount = nameCount;
return SDL_TRUE;
}
/* Alpha modes, in order of preference */
static const VkDisplayPlaneAlphaFlagBitsKHR alphaModes[4] = {
VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR,
VK_DISPLAY_PLANE_ALPHA_GLOBAL_BIT_KHR,
VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_BIT_KHR,
VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_PREMULTIPLIED_BIT_KHR,
};
SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
VkInstance instance,
VkSurfaceKHR *surface)
{
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
(PFN_vkGetInstanceProcAddr)vkGetInstanceProcAddr_;
#define VULKAN_INSTANCE_FUNCTION(name) \
PFN_##name name = (PFN_##name)vkGetInstanceProcAddr((VkInstance)instance, #name)
VULKAN_INSTANCE_FUNCTION(vkEnumeratePhysicalDevices);
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayPropertiesKHR);
VULKAN_INSTANCE_FUNCTION(vkGetDisplayModePropertiesKHR);
VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayPlanePropertiesKHR);
VULKAN_INSTANCE_FUNCTION(vkGetDisplayPlaneCapabilitiesKHR);
VULKAN_INSTANCE_FUNCTION(vkGetDisplayPlaneSupportedDisplaysKHR);
VULKAN_INSTANCE_FUNCTION(vkCreateDisplayPlaneSurfaceKHR);
#undef VULKAN_INSTANCE_FUNCTION
VkDisplaySurfaceCreateInfoKHR createInfo;
VkResult result;
uint32_t physicalDeviceCount = 0;
VkPhysicalDevice *physicalDevices = NULL;
uint32_t physicalDeviceIndex;
const char *chosenDisplayId;
int displayId = 0; /* Counting from physical device 0, display 0 */
if(!vkEnumeratePhysicalDevices ||
!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)
{
displayId = SDL_atoi(chosenDisplayId);
}
/* Enumerate physical devices */
result =
vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, NULL);
if(result != VK_SUCCESS)
{
SDL_SetError("Could not enumerate Vulkan physical devices");
goto error;
}
if(physicalDeviceCount == 0)
{
SDL_SetError("No Vulkan physical devices");
goto error;
}
physicalDevices = SDL_malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount);
if(!physicalDevices)
{
SDL_OutOfMemory();
goto error;
}
result =
vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, physicalDevices);
if(result != VK_SUCCESS)
{
SDL_SetError("Error enumerating physical devices");
goto error;
}
for(physicalDeviceIndex = 0; physicalDeviceIndex < physicalDeviceCount;
physicalDeviceIndex++)
{
VkPhysicalDevice physicalDevice = physicalDevices[physicalDeviceIndex];
uint32_t displayPropertiesCount = 0;
VkDisplayPropertiesKHR *displayProperties = NULL;
uint32_t displayModePropertiesCount = 0;
VkDisplayModePropertiesKHR *displayModeProperties = NULL;
int bestMatchIndex = -1;
uint32_t refreshRate = 0;
uint32_t i;
uint32_t displayPlanePropertiesCount = 0;
int planeIndex = -1;
VkDisplayKHR display;
VkDisplayPlanePropertiesKHR *displayPlaneProperties = NULL;
VkExtent2D extent;
VkDisplayPlaneCapabilitiesKHR planeCaps;
/* Get information about the physical displays */
result =
vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, &displayPropertiesCount, NULL);
if (result != VK_SUCCESS || displayPropertiesCount == 0)
{
/* This device has no physical device display properties, move on to next. */
continue;
}
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Number of display properties for device %u: %u",
physicalDeviceIndex, 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)
{
SDL_OutOfMemory();
goto error;
}
result =
vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, &displayPropertiesCount, displayProperties);
if (result != VK_SUCCESS || displayPropertiesCount == 0) {
SDL_free(displayProperties);
SDL_SetError("Error enumerating physical device displays");
goto error;
}
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);
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)
{
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)
{
SDL_OutOfMemory();
goto error;
}
result =
vkGetDisplayModePropertiesKHR(physicalDevice, display, &displayModePropertiesCount, displayModeProperties);
if (result != VK_SUCCESS || displayModePropertiesCount == 0) {
SDL_SetError("Error enumerating display modes");
SDL_free(displayModeProperties);
goto error;
}
/* Try to find a display mode that matches the native resolution */
for (i = 0; i < displayModePropertiesCount; ++i)
{
if (displayModeProperties[i].parameters.visibleRegion.width == extent.width &&
displayModeProperties[i].parameters.visibleRegion.height == extent.height &&
displayModeProperties[i].parameters.refreshRate > refreshRate)
{
bestMatchIndex = i;
refreshRate = displayModeProperties[i].parameters.refreshRate;
}
}
if (bestMatchIndex < 0)
{
SDL_SetError("Found no matching display mode");
SDL_free(displayModeProperties);
goto error;
}
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);
SDL_free(displayModeProperties);
displayModeProperties = NULL;
/* Try to find a plane index that supports our display */
result =
vkGetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, &displayPlanePropertiesCount, NULL);
if (result != VK_SUCCESS || displayPlanePropertiesCount == 0)
{
SDL_SetError("Error enumerating display planes");
goto error;
}
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Number of display planes: %u", displayPlanePropertiesCount);
displayPlaneProperties = SDL_malloc(sizeof(VkDisplayPlanePropertiesKHR) * displayPlanePropertiesCount);
if(!displayPlaneProperties)
{
SDL_OutOfMemory();
goto error;
}
result =
vkGetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, &displayPlanePropertiesCount, displayPlaneProperties);
if (result != VK_SUCCESS || displayPlanePropertiesCount == 0)
{
SDL_SetError("Error enumerating display plane properties");
SDL_free(displayPlaneProperties);
goto error;
}
for (i = 0; i < displayPlanePropertiesCount; ++i)
{
uint32_t planeSupportedDisplaysCount = 0;
VkDisplayKHR *planeSupportedDisplays = NULL;
uint32_t j;
/* Check if plane is attached to a display, if not, continue. */
if (displayPlaneProperties[i].currentDisplay == VK_NULL_HANDLE)
continue;
/* 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. */
}
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)
{
SDL_free(displayPlaneProperties);
SDL_OutOfMemory();
goto error;
}
result =
vkGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, i, &planeSupportedDisplaysCount, planeSupportedDisplays);
if (result != VK_SUCCESS || planeSupportedDisplaysCount == 0)
{
SDL_SetError("Error enumerating supported displays, or no supported displays");
SDL_free(planeSupportedDisplays);
SDL_free(displayPlaneProperties);
goto error;
}
for (j = 0; j < planeSupportedDisplaysCount && planeSupportedDisplays[j] != display; ++j)
;
SDL_free(planeSupportedDisplays);
planeSupportedDisplays = NULL;
if (j == planeSupportedDisplaysCount)
{
/* This display is not supported for this plane, move on. */
continue;
}
result = vkGetDisplayPlaneCapabilitiesKHR(physicalDevice, createInfo.displayMode, i, &planeCaps);
if (result != VK_SUCCESS)
{
SDL_SetError("Error getting display plane capabilities");
SDL_free(displayPlaneProperties);
goto error;
}
/* Check if plane fulfills extent requirements. */
if (extent.width >= planeCaps.minDstExtent.width && extent.height >= planeCaps.minDstExtent.height &&
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);
planeIndex = i;
break;
}
}
if (planeIndex < 0)
{
SDL_SetError("No plane supports the selected resolution");
SDL_free(displayPlaneProperties);
goto error;
}
createInfo.planeIndex = planeIndex;
createInfo.planeStackIndex = displayPlaneProperties[planeIndex].currentStackIndex;
SDL_free(displayPlaneProperties);
displayPlaneProperties = NULL;
/* Find a supported alpha mode. Not all planes support OPAQUE */
createInfo.alphaMode = VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR;
for (i = 0; i < SDL_arraysize(alphaModes); i++) {
if (planeCaps.supportedAlpha & alphaModes[i]) {
createInfo.alphaMode = alphaModes[i];
break;
}
}
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Chose alpha mode 0x%x", createInfo.alphaMode);
/* Found a match, finally! Fill in extent, and break from loop */
createInfo.imageExtent = extent;
break;
}
SDL_free(physicalDevices);
physicalDevices = NULL;
if (physicalDeviceIndex == physicalDeviceCount)
{
SDL_SetError("No usable displays found or requested display out of range");
return SDL_FALSE;
}
createInfo.sType = VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR;
createInfo.transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
createInfo.globalAlpha = 1.0f;
result = vkCreateDisplayPlaneSurfaceKHR(instance, &createInfo,
NULL, surface);
if(result != VK_SUCCESS)
{
SDL_SetError("vkCreateDisplayPlaneSurfaceKHR failed: %s",
SDL_Vulkan_GetResultString(result));
return SDL_FALSE;
}
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Created surface");
return SDL_TRUE;
error:
SDL_free(physicalDevices);
return SDL_FALSE;
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

1846
externals/SDL/src/video/SDL_yuv.c vendored Executable file

File diff suppressed because it is too large Load Diff

36
externals/SDL/src/video/SDL_yuv_c.h vendored Executable file
View File

@@ -0,0 +1,36 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_yuv_c_h_
#define SDL_yuv_c_h_
#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);
#endif /* SDL_yuv_c_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,48 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_ANDROID
#include "SDL_androidvideo.h"
#include "SDL_androidclipboard.h"
#include "../../core/android/SDL_android.h"
int
Android_SetClipboardText(_THIS, const char *text)
{
return Android_JNI_SetClipboardText(text);
}
char *
Android_GetClipboardText(_THIS)
{
return Android_JNI_GetClipboardText();
}
SDL_bool Android_HasClipboardText(_THIS)
{
return Android_JNI_HasClipboardText();
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,32 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_androidclipboard_h_
#define SDL_androidclipboard_h_
extern int Android_SetClipboardText(_THIS, const char *text);
extern char *Android_GetClipboardText(_THIS);
extern SDL_bool Android_HasClipboardText(_THIS);
#endif /* SDL_androidclipboard_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,235 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_ANDROID
#include "SDL_androidevents.h"
#include "SDL_events.h"
#include "SDL_androidkeyboard.h"
#include "SDL_androidwindow.h"
#include "../SDL_sysvideo.h"
#include "../../events/SDL_events_c.h"
/* Can't include sysaudio "../../audio/android/SDL_androidaudio.h"
* because of THIS redefinition */
#if !SDL_AUDIO_DISABLED && SDL_AUDIO_DRIVER_ANDROID
extern void ANDROIDAUDIO_ResumeDevices(void);
extern void ANDROIDAUDIO_PauseDevices(void);
#else
static void ANDROIDAUDIO_ResumeDevices(void) {}
static void ANDROIDAUDIO_PauseDevices(void) {}
#endif
#if !SDL_AUDIO_DISABLED && SDL_AUDIO_DRIVER_OPENSLES
extern void openslES_ResumeDevices(void);
extern void openslES_PauseDevices(void);
#else
static void openslES_ResumeDevices(void) {}
static void openslES_PauseDevices(void) {}
#endif
/* Number of 'type' events in the event queue */
static int
SDL_NumberOfEvents(Uint32 type)
{
return SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type);
}
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) {
/* 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);
event.type = SDL_RENDER_DEVICE_RESET;
SDL_PushEvent(&event);
}
data->backup_done = 0;
}
}
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;
data->egl_context = SDL_GL_GetCurrentContext();
/* We need to do this so the EGLSurface can be freed */
SDL_GL_MakeCurrent(window, NULL);
data->backup_done = 1;
}
}
/*
* Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
* When the pause semaphore is signaled, if Android_PumpEvents_Blocking is used, the event loop will block until the resume signal is emitted.
*
* No polling necessary
*/
void
Android_PumpEvents_Blocking(_THIS)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
if (videodata->isPaused) {
SDL_bool isContextExternal = SDL_IsVideoContextExternal();
/* Make sure this is the last thing we do before pausing */
if (!isContextExternal) {
SDL_LockMutex(Android_ActivityMutex);
android_egl_context_backup(Android_Window);
SDL_UnlockMutex(Android_ActivityMutex);
}
ANDROIDAUDIO_PauseDevices();
openslES_PauseDevices();
if (SDL_SemWait(Android_ResumeSem) == 0) {
videodata->isPaused = 0;
/* Android_ResumeSem was signaled */
SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESTORED, 0, 0);
ANDROIDAUDIO_ResumeDevices();
openslES_ResumeDevices();
/* Restore the GL Context from here, as this operation is thread dependent */
if (!isContextExternal && !SDL_HasEvent(SDL_QUIT)) {
SDL_LockMutex(Android_ActivityMutex);
android_egl_context_restore(Android_Window);
SDL_UnlockMutex(Android_ActivityMutex);
}
/* Make sure SW Keyboard is restored when an app becomes foreground */
if (SDL_IsTextInputActive()) {
Android_StartTextInput(_this); /* Only showTextInput */
}
}
} else {
if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
/* Android_PauseSem was signaled */
if (videodata->isPausing == 0) {
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
}
/* We've been signaled to pause (potentially several times), but before we block ourselves,
* we need to make sure that the very last event (of the first pause sequence, if several)
* has reached the app */
if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) {
videodata->isPausing = 1;
} else {
videodata->isPausing = 0;
videodata->isPaused = 1;
}
}
}
}
void
Android_PumpEvents_NonBlocking(_THIS)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
static int backup_context = 0;
if (videodata->isPaused) {
SDL_bool isContextExternal = SDL_IsVideoContextExternal();
if (backup_context) {
if (!isContextExternal) {
SDL_LockMutex(Android_ActivityMutex);
android_egl_context_backup(Android_Window);
SDL_UnlockMutex(Android_ActivityMutex);
}
ANDROIDAUDIO_PauseDevices();
openslES_PauseDevices();
backup_context = 0;
}
if (SDL_SemTryWait(Android_ResumeSem) == 0) {
videodata->isPaused = 0;
/* Android_ResumeSem was signaled */
SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESTORED, 0, 0);
ANDROIDAUDIO_ResumeDevices();
openslES_ResumeDevices();
/* Restore the GL Context from here, as this operation is thread dependent */
if (!isContextExternal && !SDL_HasEvent(SDL_QUIT)) {
SDL_LockMutex(Android_ActivityMutex);
android_egl_context_restore(Android_Window);
SDL_UnlockMutex(Android_ActivityMutex);
}
/* Make sure SW Keyboard is restored when an app becomes foreground */
if (SDL_IsTextInputActive()) {
Android_StartTextInput(_this); /* Only showTextInput */
}
}
} else {
if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
/* Android_PauseSem was signaled */
if (videodata->isPausing == 0) {
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
}
/* We've been signaled to pause (potentially several times), but before we block ourselves,
* we need to make sure that the very last event (of the first pause sequence, if several)
* has reached the app */
if (SDL_NumberOfEvents(SDL_APP_DIDENTERBACKGROUND) > SDL_SemValue(Android_PauseSem)) {
videodata->isPausing = 1;
} else {
videodata->isPausing = 0;
videodata->isPaused = 1;
backup_context = 1;
}
}
}
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,28 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_androidvideo.h"
extern void Android_PumpEvents_Blocking(_THIS);
extern void Android_PumpEvents_NonBlocking(_THIS);
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,91 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_ANDROID
/* Android SDL video driver implementation */
#include "SDL_video.h"
#include "../SDL_egl_c.h"
#include "SDL_androidwindow.h"
#include "SDL_androidvideo.h"
#include "SDL_androidgl.h"
#include "../../core/android/SDL_android.h"
#include <android/log.h>
#include <dlfcn.h>
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);
} else {
return SDL_EGL_MakeCurrent(_this, NULL, NULL);
}
}
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);
SDL_UnlockMutex(Android_ActivityMutex);
return ret;
}
int
Android_GLES_SwapWindow(_THIS, SDL_Window * window)
{
int retval;
SDL_LockMutex(Android_ActivityMutex);
/* The following two calls existed in the original Java code
* If you happen to have a device that's affected by their removal,
* please report to Bugzilla. -- Gabriel
*/
/*_this->egl_data->eglWaitNative(EGL_CORE_NATIVE_ENGINE);
_this->egl_data->eglWaitGL();*/
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);
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,34 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#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);
int Android_GLES_LoadLibrary(_THIS, const char *path);
#endif /* SDL_androidgl_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,391 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_ANDROID
#include <android/log.h>
#include "../../events/SDL_events_c.h"
#include "SDL_androidkeyboard.h"
#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_UNKNOWN, /* AKEYCODE_SOFT_LEFT */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_RIGHT */
SDL_SCANCODE_AC_HOME, /* AKEYCODE_HOME */
SDL_SCANCODE_AC_BACK, /* AKEYCODE_BACK */
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CALL */
SDL_SCANCODE_UNKNOWN, /* 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 */
};
static SDL_Scancode
TranslateKeycode(int keycode)
{
SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
if (keycode < SDL_arraysize(Android_Keycodes)) {
scancode = Android_Keycodes[keycode];
}
if (scancode == SDL_SCANCODE_UNKNOWN) {
__android_log_print(ANDROID_LOG_INFO, "SDL", "Unknown keycode %d", keycode);
}
return scancode;
}
int
Android_OnKeyDown(int keycode)
{
return SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode(keycode));
}
int
Android_OnKeyUp(int keycode)
{
return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode));
}
SDL_bool
Android_HasScreenKeyboardSupport(_THIS)
{
return SDL_TRUE;
}
SDL_bool
Android_IsScreenKeyboardShown(_THIS, SDL_Window * window)
{
return Android_JNI_IsScreenKeyboardShown();
}
void
Android_StartTextInput(_THIS)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
Android_JNI_ShowTextInput(&videodata->textRect);
}
void
Android_StopTextInput(_THIS)
{
Android_JNI_HideTextInput();
}
void
Android_SetTextInputRect(_THIS, SDL_Rect *rect)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
if (!rect) {
SDL_InvalidParamError("rect");
return;
}
videodata->textRect = *rect;
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,36 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#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 void Android_StartTextInput(_THIS);
extern void Android_StopTextInput(_THIS);
extern void Android_SetTextInputRect(_THIS, SDL_Rect *rect);
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,37 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_ANDROID
#include "SDL_messagebox.h"
#include "SDL_androidmessagebox.h"
#include "../../core/android/SDL_android.h"
int
Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
{
return Android_JNI_ShowMessageBox(messageboxdata, buttonid);
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,29 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_ANDROID
extern int Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,266 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_ANDROID
#include "SDL_androidmouse.h"
#include "SDL_events.h"
#include "../../events/SDL_mouse_c.h"
#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_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
typedef struct
{
int custom_cursor;
int system_cursor;
} SDL_AndroidCursorData;
/* Last known Android mouse button state (includes all buttons) */
static int last_state;
/* Blank cursor */
static SDL_Cursor *empty_cursor;
static SDL_Cursor *
Android_WrapCursor(int custom_cursor, int system_cursor)
{
SDL_Cursor *cursor;
cursor = SDL_calloc(1, sizeof(*cursor));
if (cursor) {
SDL_AndroidCursorData *data = (SDL_AndroidCursorData *)SDL_calloc(1, sizeof(*data));
if (data) {
data->custom_cursor = custom_cursor;
data->system_cursor = system_cursor;
cursor->driverdata = data;
} else {
SDL_free(cursor);
cursor = NULL;
SDL_OutOfMemory();
}
} else {
SDL_OutOfMemory();
}
return cursor;
}
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)
{
int custom_cursor;
SDL_Surface *converted;
converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0);
if (!converted) {
return NULL;
}
custom_cursor = Android_JNI_CreateCustomCursor(converted, hot_x, hot_y);
SDL_FreeSurface(converted);
if (!custom_cursor) {
SDL_Unsupported();
return NULL;
}
return Android_WrapCursor(custom_cursor, 0);
}
static SDL_Cursor *
Android_CreateSystemCursor(SDL_SystemCursor id)
{
return Android_WrapCursor(0, id);
}
static void
Android_FreeCursor(SDL_Cursor * cursor)
{
SDL_free(cursor->driverdata);
SDL_free(cursor);
}
static SDL_Cursor *
Android_CreateEmptyCursor()
{
if (!empty_cursor) {
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);
empty_cursor = Android_CreateCursor(empty_surface, 0, 0);
SDL_FreeSurface(empty_surface);
}
}
return empty_cursor;
}
static void
Android_DestroyEmptyCursor()
{
if (empty_cursor) {
Android_FreeCursor(empty_cursor);
empty_cursor = NULL;
}
}
static int
Android_ShowCursor(SDL_Cursor *cursor)
{
if (!cursor) {
cursor = Android_CreateEmptyCursor();
}
if (cursor) {
SDL_AndroidCursorData *data = (SDL_AndroidCursorData *)cursor->driverdata;
if (data->custom_cursor) {
if (!Android_JNI_SetCustomCursor(data->custom_cursor)) {
return SDL_Unsupported();
}
} else {
if (!Android_JNI_SetSystemCursor(data->system_cursor)) {
return SDL_Unsupported();
}
}
return 0;
} else {
/* SDL error set inside Android_CreateEmptyCursor() */
return -1;
}
}
static int
Android_SetRelativeMouseMode(SDL_bool enabled)
{
if (!Android_JNI_SupportsRelativeMouse()) {
return SDL_Unsupported();
}
if (!Android_JNI_SetRelativeMouseEnabled(enabled)) {
return SDL_Unsupported();
}
return 0;
}
void
Android_InitMouse(void)
{
SDL_Mouse *mouse = SDL_GetMouse();
mouse->CreateCursor = Android_CreateCursor;
mouse->CreateSystemCursor = Android_CreateSystemCursor;
mouse->ShowCursor = Android_ShowCursor;
mouse->FreeCursor = Android_FreeCursor;
mouse->SetRelativeMouseMode = Android_SetRelativeMouseMode;
SDL_SetDefaultCursor(Android_CreateDefaultCursor());
last_state = 0;
}
void
Android_QuitMouse(void)
{
Android_DestroyEmptyCursor();
}
/* Translate Android mouse button state to SDL mouse button */
static Uint8
TranslateButton(int state)
{
if (state & BUTTON_PRIMARY) {
return SDL_BUTTON_LEFT;
} else if (state & BUTTON_SECONDARY) {
return SDL_BUTTON_RIGHT;
} else if (state & BUTTON_TERTIARY) {
return SDL_BUTTON_MIDDLE;
} else if (state & BUTTON_FORWARD) {
return SDL_BUTTON_X1;
} else if (state & BUTTON_BACK) {
return SDL_BUTTON_X2;
} else {
return 0;
}
}
void
Android_OnMouse(SDL_Window *window, int state, int action, float x, float y, SDL_bool relative)
{
int changes;
Uint8 button;
if (!window) {
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;
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_SCROLL:
SDL_SendMouseWheel(window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
break;
default:
break;
}
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,33 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_androidmouse_h_
#define SDL_androidmouse_h_
#include "SDL_androidvideo.h"
extern void Android_InitMouse(void);
extern void Android_OnMouse(SDL_Window *window, int button, int action, float x, float y, SDL_bool relative);
extern void Android_QuitMouse(void);
#endif /* SDL_androidmouse_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,90 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_ANDROID
#include <android/log.h>
#include "SDL_hints.h"
#include "SDL_events.h"
#include "SDL_log.h"
#include "SDL_androidtouch.h"
#include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_touch_c.h"
#include "../../core/android/SDL_android.h"
#define ACTION_DOWN 0
#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
void Android_InitTouch(void)
{
/* Add all touch devices */
Android_JNI_InitTouch();
}
void Android_QuitTouch(void)
{
}
void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
{
SDL_TouchID touchDeviceId = 0;
SDL_FingerID fingerId = 0;
if (!window) {
return;
}
touchDeviceId = (SDL_TouchID)touch_device_id_in;
if (SDL_AddTouch(touchDeviceId, SDL_TOUCH_DEVICE_DIRECT, "") < 0) {
SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
}
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_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;
default:
break;
}
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,29 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_androidvideo.h"
extern void Android_InitTouch(void);
extern void Android_QuitTouch(void);
extern void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p);
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,274 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_ANDROID
/* Android SDL video driver implementation */
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_hints.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
#include "../../events/SDL_windowevents_c.h"
#include "SDL_androidvideo.h"
#include "SDL_androidgl.h"
#include "SDL_androidclipboard.h"
#include "SDL_androidevents.h"
#include "SDL_androidkeyboard.h"
#include "SDL_androidmouse.h"
#include "SDL_androidtouch.h"
#include "SDL_androidwindow.h"
#include "SDL_androidvulkan.h"
#define ANDROID_VID_DRIVER_NAME "Android"
/* Initialization/Query functions */
static int Android_VideoInit(_THIS);
static void Android_VideoQuit(_THIS);
int Android_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
#include "../SDL_egl_c.h"
#define Android_GLES_GetProcAddress SDL_EGL_GetProcAddress
#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
/* 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;
static Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
static int Android_ScreenRate = 0;
SDL_sem *Android_PauseSem = NULL;
SDL_sem *Android_ResumeSem = NULL;
SDL_mutex *Android_ActivityMutex = NULL;
static int
Android_Available(void)
{
return 1;
}
static void
Android_SuspendScreenSaver(_THIS)
{
Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
}
static void
Android_DeleteDevice(SDL_VideoDevice *device)
{
SDL_free(device->driverdata);
SDL_free(device);
}
static SDL_VideoDevice *
Android_CreateDevice(int devindex)
{
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) {
SDL_OutOfMemory();
return NULL;
}
data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
if (!data) {
SDL_OutOfMemory();
SDL_free(device);
return NULL;
}
device->driverdata = data;
/* Set the function pointers */
device->VideoInit = Android_VideoInit;
device->VideoQuit = Android_VideoQuit;
block_on_pause = SDL_GetHintBoolean(SDL_HINT_ANDROID_BLOCK_ON_PAUSE, SDL_TRUE);
if (block_on_pause) {
device->PumpEvents = Android_PumpEvents_Blocking;
} else {
device->PumpEvents = Android_PumpEvents_NonBlocking;
}
device->GetDisplayDPI = Android_GetDisplayDPI;
device->CreateSDLWindow = Android_CreateWindow;
device->SetWindowTitle = Android_SetWindowTitle;
device->SetWindowFullscreen = Android_SetWindowFullscreen;
device->MinimizeWindow = Android_MinimizeWindow;
device->DestroyWindow = Android_DestroyWindow;
device->GetWindowWMInfo = Android_GetWindowWMInfo;
device->free = Android_DeleteDevice;
/* GL pointers */
device->GL_LoadLibrary = Android_GLES_LoadLibrary;
device->GL_GetProcAddress = Android_GLES_GetProcAddress;
device->GL_UnloadLibrary = Android_GLES_UnloadLibrary;
device->GL_CreateContext = Android_GLES_CreateContext;
device->GL_MakeCurrent = Android_GLES_MakeCurrent;
device->GL_SetSwapInterval = Android_GLES_SetSwapInterval;
device->GL_GetSwapInterval = Android_GLES_GetSwapInterval;
device->GL_SwapWindow = Android_GLES_SwapWindow;
device->GL_DeleteContext = Android_GLES_DeleteContext;
#if SDL_VIDEO_VULKAN
device->Vulkan_LoadLibrary = Android_Vulkan_LoadLibrary;
device->Vulkan_UnloadLibrary = Android_Vulkan_UnloadLibrary;
device->Vulkan_GetInstanceExtensions = Android_Vulkan_GetInstanceExtensions;
device->Vulkan_CreateSurface = Android_Vulkan_CreateSurface;
#endif
/* Screensaver */
device->SuspendScreenSaver = Android_SuspendScreenSaver;
/* Text input */
device->StartTextInput = Android_StartTextInput;
device->StopTextInput = Android_StopTextInput;
device->SetTextInputRect = Android_SetTextInputRect;
/* Screen keyboard */
device->HasScreenKeyboardSupport = Android_HasScreenKeyboardSupport;
device->IsScreenKeyboardShown = Android_IsScreenKeyboardShown;
/* Clipboard */
device->SetClipboardText = Android_SetClipboardText;
device->GetClipboardText = Android_GetClipboardText;
device->HasClipboardText = Android_HasClipboardText;
return device;
}
VideoBootStrap Android_bootstrap = {
ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
Android_Available, Android_CreateDevice
};
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->isPausing = SDL_FALSE;
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) {
return -1;
}
display = SDL_GetDisplay(display_index);
display->orientation = Android_JNI_GetDisplayOrientation();
SDL_AddDisplayMode(&_this->displays[0], &mode);
Android_InitKeyboard();
Android_InitTouch();
Android_InitMouse();
/* We're done! */
return 0;
}
void
Android_VideoQuit(_THIS)
{
Android_QuitMouse();
Android_QuitTouch();
}
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, Uint32 format, float rate)
{
Android_SurfaceWidth = surfaceWidth;
Android_SurfaceHeight = surfaceHeight;
Android_DeviceWidth = deviceWidth;
Android_DeviceHeight = deviceHeight;
Android_ScreenFormat = format;
Android_ScreenRate = (int)rate;
}
void Android_SendResize(SDL_Window *window)
{
/*
Update the resolution of the desktop mode, so that the window
can be properly resized. The screen resolution change can for
example happen when the Activity enters or exits immersive mode,
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;
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;
display->display_modes[0].refresh_rate = Android_ScreenRate;
display->current_mode = display->display_modes[0];
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, Android_SurfaceWidth, Android_SurfaceHeight);
}
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,50 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_androidvideo_h_
#define SDL_androidvideo_h_
#include "SDL_mutex.h"
#include "SDL_rect.h"
#include "../SDL_sysvideo.h"
/* Called by the JNI layer when the screen changes size or format */
extern void Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate);
extern void Android_SendResize(SDL_Window *window);
/* Private display data */
typedef struct SDL_VideoData
{
SDL_Rect textRect;
int isPaused;
int isPausing;
} SDL_VideoData;
extern int Android_SurfaceWidth;
extern int Android_SurfaceHeight;
extern SDL_sem *Android_PauseSem, *Android_ResumeSem;
extern SDL_mutex *Android_ActivityMutex;
#endif /* SDL_androidvideo_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,175 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
* @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
* SDL_x11vulkan.c.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_ANDROID
#include "SDL_androidvideo.h"
#include "SDL_androidwindow.h"
#include "SDL_assert.h"
#include "SDL_loadso.h"
#include "SDL_androidvulkan.h"
#include "SDL_syswm.h"
int Android_Vulkan_LoadLibrary(_THIS, const char *path)
{
VkExtensionProperties *extensions = NULL;
Uint32 i, extensionCount = 0;
SDL_bool hasSurfaceExtension = SDL_FALSE;
SDL_bool hasAndroidSurfaceExtension = SDL_FALSE;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
if(_this->vulkan_config.loader_handle)
return SDL_SetError("Vulkan already loaded");
/* Load the Vulkan loader library */
if(!path)
path = SDL_getenv("SDL_VULKAN_LIBRARY");
if(!path)
path = "libvulkan.so";
_this->vulkan_config.loader_handle = SDL_LoadObject(path);
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)
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)
goto fail;
extensions = SDL_Vulkan_CreateInstanceExtensionsList(
(PFN_vkEnumerateInstanceExtensionProperties)
_this->vulkan_config.vkEnumerateInstanceExtensionProperties,
&extensionCount);
if(!extensions)
goto fail;
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)
hasAndroidSurfaceExtension = SDL_TRUE;
}
SDL_free(extensions);
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");
goto fail;
}
return 0;
fail:
SDL_UnloadObject(_this->vulkan_config.loader_handle);
_this->vulkan_config.loader_handle = NULL;
return -1;
}
void Android_Vulkan_UnloadLibrary(_THIS)
{
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)
{
static const char *const extensionsForAndroid[] = {
VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_ANDROID_SURFACE_EXTENSION_NAME
};
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);
}
SDL_bool Android_Vulkan_CreateSurface(_THIS,
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");
VkAndroidSurfaceCreateInfoKHR createInfo;
VkResult result;
if(!_this->vulkan_config.loader_handle)
{
SDL_SetError("Vulkan is not loaded");
return SDL_FALSE;
}
if(!vkCreateAndroidSurfaceKHR)
{
SDL_SetError(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME
" extension is not enabled in the Vulkan instance.");
return SDL_FALSE;
}
SDL_zero(createInfo);
createInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.window = windowData->native_window;
result = vkCreateAndroidSurfaceKHR(instance, &createInfo,
NULL, surface);
if(result != VK_SUCCESS)
{
SDL_SetError("vkCreateAndroidSurfaceKHR failed: %s",
SDL_Vulkan_GetResultString(result));
return SDL_FALSE;
}
return SDL_TRUE;
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,52 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
* @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
* SDL_x11vulkan.h.
*/
#include "../../SDL_internal.h"
#ifndef SDL_androidvulkan_h_
#define SDL_androidvulkan_h_
#include "../SDL_vulkan_internal.h"
#include "../SDL_sysvideo.h"
#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_ANDROID
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_bool Android_Vulkan_CreateSurface(_THIS,
SDL_Window *window,
VkInstance instance,
VkSurfaceKHR *surface);
#endif
#endif /* SDL_androidvulkan_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,212 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_ANDROID
#include "SDL_syswm.h"
#include "../SDL_sysvideo.h"
#include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_windowevents_c.h"
#include "../../core/android/SDL_android.h"
#include "SDL_androidvideo.h"
#include "SDL_androidwindow.h"
#include "SDL_hints.h"
/* Currently only one window */
SDL_Window *Android_Window = NULL;
int
Android_CreateWindow(_THIS, SDL_Window * window)
{
SDL_WindowData *data;
int retval = 0;
Android_ActivityMutex_Lock_Running();
if (Android_Window) {
retval = SDL_SetError("Android only supports one window");
goto endfunction;
}
/* Set orientation */
Android_JNI_SetOrientation(window->w, window->h, window->flags & SDL_WINDOW_RESIZABLE, SDL_GetHint(SDL_HINT_ORIENTATIONS));
/* Adjust the window data to match the screen */
window->x = 0;
window->y = 0;
window->w = Android_SurfaceWidth;
window->h = Android_SurfaceHeight;
window->flags &= ~SDL_WINDOW_HIDDEN;
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) {
retval = SDL_OutOfMemory();
goto endfunction;
}
data->native_window = Android_JNI_GetNativeWindow();
if (!data->native_window) {
SDL_free(data);
retval = SDL_SetError("Could not fetch native window");
goto endfunction;
}
/* Do not create EGLSurface for Vulkan window since it will then make the window
incompatible with vkCreateAndroidSurfaceKHR */
if ((window->flags & SDL_WINDOW_OPENGL) != 0) {
data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
if (data->egl_surface == EGL_NO_SURFACE) {
ANativeWindow_release(data->native_window);
SDL_free(data);
retval = -1;
goto endfunction;
}
}
window->driverdata = data;
Android_Window = window;
endfunction:
SDL_UnlockMutex(Android_ActivityMutex);
return retval;
}
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)
{
SDL_LockMutex(Android_ActivityMutex);
if (window == Android_Window) {
/* If the window is being destroyed don't change visible state */
if (!window->is_destroying) {
Android_JNI_SetWindowStyle(fullscreen);
}
/* Ensure our size matches reality after we've executed the window style change.
*
* It is possible that we've set width and height to the full-size display, but on
* Samsung DeX or Chromebooks or other windowed Android environemtns, our window may
* still not be the full display size.
*/
if (!SDL_IsDeXMode() && !SDL_IsChromebook()) {
goto endfunction;
}
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
if (!data || !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;
int new_w = ANativeWindow_getWidth(data->native_window);
int new_h = ANativeWindow_getHeight(data->native_window);
if (new_w < 0 || new_h < 0) {
SDL_SetError("ANativeWindow_getWidth/Height() fails");
}
if (old_w != new_w || old_h != new_h) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, new_w, new_h);
}
}
endfunction:
SDL_UnlockMutex(Android_ActivityMutex);
}
void
Android_MinimizeWindow(_THIS, SDL_Window *window)
{
Android_JNI_MinizeWindow();
}
void
Android_DestroyWindow(_THIS, SDL_Window *window)
{
SDL_LockMutex(Android_ActivityMutex);
if (window == Android_Window) {
Android_Window = NULL;
if (window->driverdata) {
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if (data->egl_surface != EGL_NO_SURFACE) {
SDL_EGL_DestroySurface(_this, data->egl_surface);
}
if (data->native_window) {
ANativeWindow_release(data->native_window);
}
SDL_free(window->driverdata);
window->driverdata = NULL;
}
}
SDL_UnlockMutex(Android_ActivityMutex);
}
SDL_bool
Android_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if (info->version.major == SDL_MAJOR_VERSION &&
info->version.minor == SDL_MINOR_VERSION) {
info->subsystem = SDL_SYSWM_ANDROID;
info->info.android.window = data->native_window;
info->info.android.surface = data->egl_surface;
return SDL_TRUE;
} else {
SDL_SetError("Application not compiled with SDL %d.%d",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
return SDL_FALSE;
}
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,49 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_androidwindow_h_
#define SDL_androidwindow_h_
#include "../../core/android/SDL_android.h"
#include "../SDL_egl_c.h"
extern int Android_CreateWindow(_THIS, SDL_Window *window);
extern void Android_SetWindowTitle(_THIS, SDL_Window *window);
extern void Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen);
extern void Android_MinimizeWindow(_THIS, SDL_Window *window);
extern void Android_DestroyWindow(_THIS, SDL_Window *window);
extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info);
extern SDL_Window *Android_Window;
typedef struct
{
EGLSurface egl_surface;
EGLContext egl_context; /* We use this to preserve the context when losing focus */
SDL_bool backup_done;
ANativeWindow *native_window;
} SDL_WindowData;
#endif /* SDL_androidwindow_h_ */
/* vi: set ts=4 sw=4 expandtab: */

36
externals/SDL/src/video/arm/pixman-arm-asm.h vendored Executable file
View File

@@ -0,0 +1,36 @@
/*
* Copyright © 2010 Nokia Corporation
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Mozilla Corporation not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Mozilla Corporation makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*
* Author: Siarhei Siamashka (siarhei.siamashka@nokia.com)
*
*/
/* Supplementary macro for setting function attributes */
.macro pixman_asm_function fname
.func fname
.global fname
#ifdef __ELF__
.hidden fname
.type fname, %function
#endif
fname:
.endm

View File

@@ -0,0 +1,375 @@
/*
* Copyright © 2009 Nokia Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Author: Siarhei Siamashka (siarhei.siamashka@nokia.com)
*/
/*
* Copyright (c) 2018 RISC OS Open Ltd
*
* 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
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
/* Prevent the stack from becoming executable for no reason... */
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif
.text
.fpu neon
.arch armv7a
.object_arch armv4
.eabi_attribute 10, 0 /* suppress Tag_FP_arch */
.eabi_attribute 12, 0 /* suppress Tag_Advanced_SIMD_arch */
.arm
.altmacro
.p2align 2
#include "pixman-arm-asm.h"
#include "pixman-arm-neon-asm.h"
/* Global configuration options and preferences */
/*
* The code can optionally make use of unaligned memory accesses to improve
* performance of handling leading/trailing pixels for each scanline.
* Configuration variable RESPECT_STRICT_ALIGNMENT can be set to 0 for
* example in linux if unaligned memory accesses are not configured to
* generate.exceptions.
*/
.set RESPECT_STRICT_ALIGNMENT, 1
/*
* Set default prefetch type. There is a choice between the following options:
*
* PREFETCH_TYPE_NONE (may be useful for the ARM cores where PLD is set to work
* as NOP to workaround some HW bugs or for whatever other reason)
*
* PREFETCH_TYPE_SIMPLE (may be useful for simple single-issue ARM cores where
* advanced prefetch intruduces heavy overhead)
*
* PREFETCH_TYPE_ADVANCED (useful for superscalar cores such as ARM Cortex-A8
* which can run ARM and NEON instructions simultaneously so that extra ARM
* instructions do not add (many) extra cycles, but improve prefetch efficiency)
*
* Note: some types of function can't support advanced prefetch and fallback
* to simple one (those which handle 24bpp pixels)
*/
.set PREFETCH_TYPE_DEFAULT, PREFETCH_TYPE_ADVANCED
/* Prefetch distance in pixels for simple prefetch */
.set PREFETCH_DISTANCE_SIMPLE, 64
/******************************************************************************/
/* We can actually do significantly better than the Pixman macros, at least for
* the case of fills, by using a carefully scheduled inner loop. Cortex-A53
* shows an improvement of up to 78% in ideal cases (large fills to L1 cache).
*/
.macro generate_fillrect_function name, bpp, log2Bpp
/*
* void name(int32_t w, int32_t h, uint8_t *dst, int32_t dst_stride, uint8_t src);
* On entry:
* a1 = width, pixels
* a2 = height, rows
* a3 = pointer to top-left destination pixel
* a4 = stride, pixels
* [sp] = pixel value to fill with
* Within the function:
* v1 = width remaining
* v2 = vst offset
* v3 = alternate pointer
* ip = data ARM register
*/
pixman_asm_function name
vld1.\bpp {d0[],d1[]}, [sp]
sub a4, a1
vld1.\bpp {d2[],d3[]}, [sp]
cmp a1, #(15+64) >> \log2Bpp
push {v1-v3,lr}
vmov ip, s0
blo 51f
/* Long-row case */
mov v2, #64
1: mov v1, a1
ands v3, a3, #15
beq 2f
/* Leading pixels */
rsb v3, v3, #16 /* number of leading bytes until 16-byte aligned */
sub v1, v1, v3, lsr #\log2Bpp
rbit v3, v3
.if bpp <= 16
.if bpp == 8
tst a3, #1 /* bit 0 unaffected by rsb so can avoid register interlock */
strneb ip, [a3], #1
tst v3, #1<<30
.else
tst a3, #2 /* bit 1 unaffected by rsb (assuming halfword alignment) so can avoid register interlock */
.endif
strneh ip, [a3], #2
.endif
movs v3, v3, lsl #3
vstmcs a3!, {s0}
vstmmi a3!, {d0}
2: sub v1, v1, #64 >> \log2Bpp /* simplifies inner loop termination */
add v3, a3, #32
/* Inner loop */
3: vst1.\bpp {q0-q1}, [a3 :128], v2
subs v1, v1, #64 >> \log2Bpp
vst1.\bpp {q0-q1}, [v3 :128], v2
bhs 3b
/* Trailing pixels */
4: movs v1, v1, lsl #27 + \log2Bpp
bcc 5f
vst1.\bpp {q0-q1}, [a3 :128]!
5: bpl 6f
vst1.\bpp {q0}, [a3 :128]!
6: movs v1, v1, lsl #2
vstmcs a3!, {d0}
vstmmi a3!, {s0}
.if bpp <= 16
movs v1, v1, lsl #2
strcsh ip, [a3], #2
.if bpp == 8
strmib ip, [a3], #1
.endif
.endif
subs a2, a2, #1
add a3, a3, a4, lsl #\log2Bpp
bhi 1b
pop {v1-v3,pc}
/* Short-row case */
51: movs v1, a1
.if bpp == 8
tst a3, #3
beq 53f
52: subs v1, v1, #1
blo 57f
strb ip, [a3], #1
tst a3, #3
bne 52b
.elseif bpp == 16
tstne a3, #2
subne v1, v1, #1
strneh ip, [a3], #2
.endif
53: cmp v1, #32 >> \log2Bpp
bcc 54f
vst1.\bpp {q0-q1}, [a3]!
sub v1, v1, #32 >> \log2Bpp
/* Trailing pixels */
54: movs v1, v1, lsl #27 + \log2Bpp
bcc 55f
vst1.\bpp {q0-q1}, [a3]!
55: bpl 56f
vst1.\bpp {q0}, [a3]!
56: movs v1, v1, lsl #2
vstmcs a3!, {d0}
vstmmi a3!, {s0}
.if bpp <= 16
movs v1, v1, lsl #2
strcsh ip, [a3], #2
.if bpp == 8
strmib ip, [a3], #1
.endif
.endif
subs a2, a2, #1
add a3, a3, a4, lsl #\log2Bpp
bhi 51b
57: pop {v1-v3,pc}
.endfunc
.endm
generate_fillrect_function FillRect32ARMNEONAsm, 32, 2
generate_fillrect_function FillRect16ARMNEONAsm, 16, 1
generate_fillrect_function FillRect8ARMNEONAsm, 8, 0
/******************************************************************************/
.macro RGBtoRGBPixelAlpha_process_pixblock_head
vmvn d30, d3 /* get inverted source alpha */
vmov d31, d7 /* dest alpha is always unchanged */
vmull.u8 q14, d0, d3
vmlal.u8 q14, d4, d30
vmull.u8 q0, d1, d3
vmlal.u8 q0, d5, d30
vmull.u8 q1, d2, d3
vmlal.u8 q1, d6, d30
vrshr.u16 q2, q14, #8
vrshr.u16 q3, q0, #8
vraddhn.u16 d28, q14, q2
vrshr.u16 q2, q1, #8
vraddhn.u16 d29, q0, q3
vraddhn.u16 d30, q1, q2
.endm
.macro RGBtoRGBPixelAlpha_process_pixblock_tail
/* nothing */
.endm
.macro RGBtoRGBPixelAlpha_process_pixblock_tail_head
vld4.8 {d0-d3}, [SRC]!
PF add PF_X, PF_X, #8
vst4.8 {d28-d31}, [DST_W :128]!
PF tst PF_CTL, #0xF
vld4.8 {d4-d7}, [DST_R :128]!
PF addne PF_X, PF_X, #8
vmvn d30, d3 /* get inverted source alpha */
vmov d31, d7 /* dest alpha is always unchanged */
vmull.u8 q14, d0, d3
PF subne PF_CTL, PF_CTL, #1
vmlal.u8 q14, d4, d30
PF cmp PF_X, ORIG_W
vmull.u8 q0, d1, d3
PF pld, [PF_SRC, PF_X, lsl #src_bpp_shift]
vmlal.u8 q0, d5, d30
PF pld, [PF_DST, PF_X, lsl #dst_bpp_shift]
vmull.u8 q1, d2, d3
PF subge PF_X, PF_X, ORIG_W
vmlal.u8 q1, d6, d30
PF subges PF_CTL, PF_CTL, #0x10
vrshr.u16 q2, q14, #8
PF ldrgeb DUMMY, [PF_SRC, SRC_STRIDE, lsl #src_bpp_shift]!
vrshr.u16 q3, q0, #8
PF ldrgeb DUMMY, [PF_DST, DST_STRIDE, lsl #dst_bpp_shift]!
vraddhn.u16 d28, q14, q2
vrshr.u16 q2, q1, #8
vraddhn.u16 d29, q0, q3
vraddhn.u16 d30, q1, q2
.endm
generate_composite_function \
BlitRGBtoRGBPixelAlphaARMNEONAsm, 32, 0, 32, \
FLAG_DST_READWRITE | FLAG_DEINTERLEAVE_32BPP, \
8, /* number of pixels, processed in a single block */ \
5, /* prefetch distance */ \
default_init, \
default_cleanup, \
RGBtoRGBPixelAlpha_process_pixblock_head, \
RGBtoRGBPixelAlpha_process_pixblock_tail, \
RGBtoRGBPixelAlpha_process_pixblock_tail_head
/******************************************************************************/
.macro ARGBto565PixelAlpha_process_pixblock_head
vmvn d6, d3
vshr.u8 d1, #2
vshr.u8 d3, #3
vshr.u8 d0, #3
vshrn.u16 d7, q2, #3
vshrn.u16 d25, q2, #8
vbic.i16 q2, #0xe0
vshr.u8 d6, #3
vshr.u8 d7, #2
vshr.u8 d2, #3
vmovn.u16 d24, q2
vshr.u8 d25, #3
vmull.u8 q13, d1, d3
vmlal.u8 q13, d7, d6
vmull.u8 q14, d0, d3
vmlal.u8 q14, d24, d6
vmull.u8 q15, d2, d3
vmlal.u8 q15, d25, d6
.endm
.macro ARGBto565PixelAlpha_process_pixblock_tail
vsra.u16 q13, #5
vsra.u16 q14, #5
vsra.u16 q15, #5
vrshr.u16 q13, #5
vrshr.u16 q14, #5
vrshr.u16 q15, #5
vsli.u16 q14, q13, #5
vsli.u16 q14, q15, #11
.endm
.macro ARGBto565PixelAlpha_process_pixblock_tail_head
vld4.8 {d0-d3}, [SRC]!
PF add PF_X, PF_X, #8
vsra.u16 q13, #5
PF tst PF_CTL, #0xF
vsra.u16 q14, #5
PF addne PF_X, PF_X, #8
vsra.u16 q15, #5
PF subne PF_CTL, PF_CTL, #1
vrshr.u16 q13, #5
PF cmp PF_X, ORIG_W
vrshr.u16 q14, #5
PF pld, [PF_SRC, PF_X, lsl #src_bpp_shift]
vrshr.u16 q15, #5
PF pld, [PF_DST, PF_X, lsl #dst_bpp_shift]
vld1.8 {d4-d5}, [DST_R]!
PF subge PF_X, PF_X, ORIG_W
vsli.u16 q14, q13, #5
PF subges PF_CTL, PF_CTL, #0x10
vsli.u16 q14, q15, #11
PF ldrgeb DUMMY, [PF_SRC, SRC_STRIDE, lsl #src_bpp_shift]!
vst1.8 {q14}, [DST_W :128]!
vmvn d6, d3
vshr.u8 d1, #2
vshr.u8 d3, #3
vshr.u8 d0, #3
vshrn.u16 d7, q2, #3
vshrn.u16 d25, q2, #8
vbic.i16 q2, #0xe0
PF ldrgeb DUMMY, [PF_DST, DST_STRIDE, lsl #dst_bpp_shift]!
vshr.u8 d6, #3
vshr.u8 d7, #2
vshr.u8 d2, #3
vmovn.u16 d24, q2
vshr.u8 d25, #3
vmull.u8 q13, d1, d3
vmlal.u8 q13, d7, d6
vmull.u8 q14, d0, d3
vmlal.u8 q14, d24, d6
vmull.u8 q15, d2, d3
vmlal.u8 q15, d25, d6
.endm
generate_composite_function \
BlitARGBto565PixelAlphaARMNEONAsm, 32, 0, 16, \
FLAG_DST_READWRITE | FLAG_DEINTERLEAVE_32BPP, \
8, /* number of pixels, processed in a single block */ \
6, /* prefetch distance */ \
default_init, \
default_cleanup, \
ARGBto565PixelAlpha_process_pixblock_head, \
ARGBto565PixelAlpha_process_pixblock_tail, \
ARGBto565PixelAlpha_process_pixblock_tail_head

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,532 @@
/*
* Copyright (c) 2016 RISC OS Open Ltd
*
* 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
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
/* Prevent the stack from becoming executable */
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif
.text
.arch armv6
.object_arch armv4
.arm
.altmacro
.p2align 2
#include "pixman-arm-asm.h"
#include "pixman-arm-simd-asm.h"
/* A head macro should do all processing which results in an output of up to
* 16 bytes, as far as the final load instruction. The corresponding tail macro
* should complete the processing of the up-to-16 bytes. The calling macro will
* sometimes choose to insert a preload or a decrement of X between them.
* cond ARM condition code for code block
* numbytes Number of output bytes that should be generated this time
* firstreg First WK register in which to place output
* unaligned_src Whether to use non-wordaligned loads of source image
* unaligned_mask Whether to use non-wordaligned loads of mask image
* preload If outputting 16 bytes causes 64 bytes to be read, whether an extra preload should be output
*/
/******************************************************************************/
.macro FillRect32_init
ldr SRC, [sp, #ARGS_STACK_OFFSET]
mov STRIDE_S, SRC
mov MASK, SRC
mov STRIDE_M, SRC
.endm
.macro FillRect16_init
ldrh SRC, [sp, #ARGS_STACK_OFFSET]
orr SRC, SRC, lsl #16
mov STRIDE_S, SRC
mov MASK, SRC
mov STRIDE_M, SRC
.endm
.macro FillRect8_init
ldrb SRC, [sp, #ARGS_STACK_OFFSET]
orr SRC, SRC, lsl #8
orr SRC, SRC, lsl #16
mov STRIDE_S, SRC
mov MASK, SRC
mov STRIDE_M, SRC
.endm
.macro FillRect_process_tail cond, numbytes, firstreg
WK4 .req SRC
WK5 .req STRIDE_S
WK6 .req MASK
WK7 .req STRIDE_M
pixst cond, numbytes, 4, DST
.unreq WK4
.unreq WK5
.unreq WK6
.unreq WK7
.endm
generate_composite_function \
FillRect32ARMSIMDAsm, 0, 0, 32, \
FLAG_DST_WRITEONLY | FLAG_COND_EXEC | FLAG_PROCESS_PRESERVES_PSR | FLAG_PROCESS_DOES_STORE | FLAG_PROCESS_PRESERVES_SCRATCH \
0, /* prefetch distance doesn't apply */ \
FillRect32_init \
nop_macro, /* newline */ \
nop_macro /* cleanup */ \
nop_macro /* process head */ \
FillRect_process_tail
generate_composite_function \
FillRect16ARMSIMDAsm, 0, 0, 16, \
FLAG_DST_WRITEONLY | FLAG_COND_EXEC | FLAG_PROCESS_PRESERVES_PSR | FLAG_PROCESS_DOES_STORE | FLAG_PROCESS_PRESERVES_SCRATCH \
0, /* prefetch distance doesn't apply */ \
FillRect16_init \
nop_macro, /* newline */ \
nop_macro /* cleanup */ \
nop_macro /* process head */ \
FillRect_process_tail
generate_composite_function \
FillRect8ARMSIMDAsm, 0, 0, 8, \
FLAG_DST_WRITEONLY | FLAG_COND_EXEC | FLAG_PROCESS_PRESERVES_PSR | FLAG_PROCESS_DOES_STORE | FLAG_PROCESS_PRESERVES_SCRATCH \
0, /* prefetch distance doesn't apply */ \
FillRect8_init \
nop_macro, /* newline */ \
nop_macro /* cleanup */ \
nop_macro /* process head */ \
FillRect_process_tail
/******************************************************************************/
/* This differs from the over_8888_8888 routine in Pixman in that the destination
* alpha component is always left unchanged, and RGB components are not
* premultiplied by alpha. It differs from BlitRGBtoRGBPixelAlpha in that
* renormalisation is done by multiplying by 257/256 (with rounding) rather than
* simply shifting right by 8 bits - removing the need to special-case alpha=0xff.
*/
.macro RGBtoRGBPixelAlpha_init
line_saved_regs STRIDE_S, ORIG_W
mov MASK, #0x80
.endm
.macro RGBtoRGBPixelAlpha_1pixel_translucent s, d, tmp0, tmp1, tmp2, tmp3, half
uxtb tmp3, s
uxtb tmp0, d
sub tmp0, tmp3, tmp0
uxtb tmp3, s, ror #16
uxtb tmp1, d, ror #16
sub tmp1, tmp3, tmp1
uxtb tmp3, s, ror #8
mov s, s, lsr #24
uxtb tmp2, d, ror #8
sub tmp2, tmp3, tmp2
smlabb tmp0, tmp0, s, half
smlabb tmp1, tmp1, s, half
smlabb tmp2, tmp2, s, half
add tmp0, tmp0, asr #8
add tmp1, tmp1, asr #8
add tmp2, tmp2, asr #8
pkhbt tmp0, tmp0, tmp1, lsl #16
and tmp2, tmp2, #0xff00
uxtb16 tmp0, tmp0, ror #8
orr tmp0, tmp0, tmp2
uadd8 d, d, tmp0
.endm
.macro RGBtoRGBPixelAlpha_1pixel_opaque s, d
and d, d, #0xff000000
bic s, s, #0xff000000
orr d, d, s
.endm
.macro RGBtoRGBPixelAlpha_process_head cond, numbytes, firstreg, unaligned_src, unaligned_mask, preload
.if numbytes == 16
ldm SRC!, {WK0, WK1}
ldm SRC!, {STRIDE_S, STRIDE_M}
ldrd WK2, WK3, [DST], #16
orr SCRATCH, WK0, WK1
and ORIG_W, WK0, WK1
orr SCRATCH, SCRATCH, STRIDE_S
and ORIG_W, ORIG_W, STRIDE_S
orr SCRATCH, SCRATCH, STRIDE_M
and ORIG_W, ORIG_W, STRIDE_M
tst SCRATCH, #0xff000000
.elseif numbytes == 8
ldm SRC!, {WK0, WK1}
ldm DST!, {WK2, WK3}
orr SCRATCH, WK0, WK1
and ORIG_W, WK0, WK1
tst SCRATCH, #0xff000000
.else // numbytes == 4
ldr WK0, [SRC], #4
ldr WK2, [DST], #4
tst WK0, #0xff000000
.endif
.endm
.macro RGBtoRGBPixelAlpha_process_tail cond, numbytes, firstreg
beq 20f @ all transparent
.if numbytes == 16
cmp ORIG_W, #0xff000000
bhs 10f @ all opaque
RGBtoRGBPixelAlpha_1pixel_translucent WK0, WK2, STRIDE_S, STRIDE_M, SCRATCH, ORIG_W, MASK
RGBtoRGBPixelAlpha_1pixel_translucent WK1, WK3, STRIDE_S, STRIDE_M, SCRATCH, ORIG_W, MASK
strd WK2, WK3, [DST, #-16]
ldrd WK0, WK1, [SRC, #-8]
ldrd WK2, WK3, [DST, #-8]
RGBtoRGBPixelAlpha_1pixel_translucent WK0, WK2, STRIDE_S, STRIDE_M, SCRATCH, ORIG_W, MASK
RGBtoRGBPixelAlpha_1pixel_translucent WK1, WK3, STRIDE_S, STRIDE_M, SCRATCH, ORIG_W, MASK
b 19f
10: RGBtoRGBPixelAlpha_1pixel_opaque WK0, WK2
RGBtoRGBPixelAlpha_1pixel_opaque WK1, WK3
strd WK2, WK3, [DST, #-16]
ldrd WK0, WK1, [SRC, #-8]
ldrd WK2, WK3, [DST, #-8]
RGBtoRGBPixelAlpha_1pixel_opaque WK0, WK2
RGBtoRGBPixelAlpha_1pixel_opaque WK1, WK3
19: strd WK2, WK3, [DST, #-8]
.elseif numbytes == 8
cmp ORIG_W, #0xff000000
bhs 10f @ all opaque
RGBtoRGBPixelAlpha_1pixel_translucent WK0, WK2, STRIDE_S, STRIDE_M, SCRATCH, ORIG_W, MASK
RGBtoRGBPixelAlpha_1pixel_translucent WK1, WK3, STRIDE_S, STRIDE_M, SCRATCH, ORIG_W, MASK
b 19f
10: RGBtoRGBPixelAlpha_1pixel_opaque WK0, WK2
RGBtoRGBPixelAlpha_1pixel_opaque WK1, WK3
19: strd WK2, WK3, [DST, #-8]
.else // numbytes == 4
cmp WK0, #0xff000000
bhs 10f @ opaque
RGBtoRGBPixelAlpha_1pixel_translucent WK0, WK2, STRIDE_S, STRIDE_M, SCRATCH, ORIG_W, MASK
b 19f
10: RGBtoRGBPixelAlpha_1pixel_opaque WK0, WK2
19: str WK2, [DST, #-4]
.endif
20:
.endm
generate_composite_function \
BlitRGBtoRGBPixelAlphaARMSIMDAsm, 32, 0, 32, \
FLAG_DST_READWRITE | FLAG_BRANCH_OVER | FLAG_PROCESS_CORRUPTS_PSR | FLAG_PROCESS_DOES_STORE | FLAG_SPILL_LINE_VARS | FLAG_PROCESS_CORRUPTS_WK0, \
2, /* prefetch distance */ \
RGBtoRGBPixelAlpha_init, \
nop_macro, /* newline */ \
nop_macro, /* cleanup */ \
RGBtoRGBPixelAlpha_process_head, \
RGBtoRGBPixelAlpha_process_tail
/******************************************************************************/
.macro ARGBto565PixelAlpha_init
line_saved_regs STRIDE_D, STRIDE_S, ORIG_W
mov MASK, #0x001f
mov STRIDE_M, #0x0010
orr MASK, MASK, MASK, lsl #16
orr STRIDE_M, STRIDE_M, STRIDE_M, lsl #16
.endm
.macro ARGBto565PixelAlpha_newline
mov STRIDE_S, #0x0200
.endm
/* On entry:
* s1 holds 1 32bpp source pixel
* d holds 1 16bpp destination pixel
* rbmask, rbhalf, ghalf hold 0x001f001f, 0x00100010, 0x00000200 respectively
* other registers are temporaries
* On exit:
* Constant registers preserved
*/
.macro ARGBto565PixelAlpha_1pixel_translucent s, d, rbmask, rbhalf, ghalf, alpha, rb, g, misc
mov alpha, s, lsr #27
and misc, s, #0xfc00
and g, d, #0x07e0
pkhbt rb, d, d, lsl #5
rsb misc, g, misc, lsr #5
and s, rbmask, s, lsr #3
and rb, rbmask, rb
sub s, s, rb
smlabb misc, misc, alpha, ghalf
mla s, s, alpha, rbhalf
add misc, misc, misc, lsl #5
add g, g, misc, asr #10
add s, s, s, lsl #5
and g, g, #0x07e0
add rb, rb, s, asr #10
and rb, rb, rbmask
pkhbt rb, rb, rb, lsl #11
orr d, rb, g
orr d, d, rb, lsr #16
.endm
/* On entry:
* s1 holds 1 32bpp source pixel
* d holds 1 16bpp destination pixel
* rbmask holds 0x001f001f
* On exit:
* Constant registers preserved
*/
.macro ARGBto565PixelAlpha_1pixel_opaque s, d, rbmask
and d, rbmask, s, lsr #3
and s, s, #0xfc00
orr d, d, d, lsr #5
orr d, d, s, lsr #5
.endm
/* On entry:
* s1, s2 hold 2 32bpp source pixels
* d holds 2 16bpp destination pixels
* rbmask, rbhalf, ghalf hold 0x001f001f, 0x00100010, 0x00000200 respectively
* other registers are temporaries
* On exit:
* Constant registers preserved
* Blended results have been written through destination pointer
*/
.macro ARGBto565PixelAlpha_2pixels_translucent s1, s2, d, rbmask, rbhalf, ghalf, alpha, rb, g, misc
mov alpha, s1, lsr #27
and misc, s1, #0xfc00
and g, d, #0x07e0
pkhbt rb, d, d, lsl #5
rsb misc, g, misc, lsr #5
and s1, rbmask, s1, lsr #3
and rb, rbmask, rb
sub s1, s1, rb
smlabb misc, misc, alpha, ghalf
mla s1, s1, alpha, rbhalf
uxth d, d, ror #16
add misc, misc, misc, lsl #5
mov alpha, s2, lsr #27
add g, g, misc, asr #10
add s1, s1, s1, lsl #5
and g, g, #0x07e0
add rb, rb, s1, asr #10
and rb, rb, rbmask
and misc, s2, #0xfc00
pkhbt rb, rb, rb, lsl #11
and s1, d, #0x07e0
pkhbt d, d, d, lsl #5
rsb misc, s1, misc, lsr #5
and s2, rbmask, s2, lsr #3
and d, rbmask, d
sub s2, s2, d
smlabb misc, misc, alpha, ghalf
mla s2, s2, alpha, rbhalf
orr alpha, rb, g
add misc, misc, misc, lsl #5
orr alpha, alpha, rb, lsr #16
add s1, s1, misc, asr #10
add s2, s2, s2, lsl #5
and s1, s1, #0x07e0
add d, d, s2, asr #10
and d, d, rbmask
strh alpha, [DST, #-4]
pkhbt d, d, d, lsl #11
orr alpha, d, s1
orr alpha, alpha, d, lsr #16
strh alpha, [DST, #-2]
.endm
/* On entry:
* s1, s2 hold 2 32bpp source pixels
* rbmask holds 0x001f001f
* other registers are temporaries
* On exit:
* Constant registers preserved
* Blended results have been written through destination pointer
*/
.macro ARGBto565PixelAlpha_2pixels_opaque s1, s2, d, rbmask, g
and g, s1, #0xfc00
and d, rbmask, s1, lsr #3
and s1, rbmask, s2, lsr #3
orr d, d, d, lsr #5
orr d, d, g, lsr #5
and g, s2, #0xfc00
strh d, [DST, #-4]
orr s1, s1, s1, lsr #5
orr s1, s1, g, lsr #5
strh s1, [DST, #-2]
.endm
.macro ARGBto565PixelAlpha_2pixels_head
ldrd WK0, WK1, [SRC], #8
ldr WK2, [DST], #4
orr SCRATCH, WK0, WK1
and ORIG_W, WK0, WK1
tst SCRATCH, #0xff000000
.endm
.macro ARGBto565PixelAlpha_2pixels_tail
beq 20f @ all transparent
cmp ORIG_W, #0xff000000
bhs 10f @ all opaque
ARGBto565PixelAlpha_2pixels_translucent WK0, WK1, WK2, MASK, STRIDE_M, STRIDE_S, STRIDE_D, WK3, SCRATCH, ORIG_W
b 20f
10: ARGBto565PixelAlpha_2pixels_opaque WK0, WK1, WK2, MASK, SCRATCH
20:
.endm
.macro ARGBto565PixelAlpha_process_head cond, numbytes, firstreg, unaligned_src, unaligned_mask, preload
.if numbytes == 16
ARGBto565PixelAlpha_2pixels_head
ARGBto565PixelAlpha_2pixels_tail
ARGBto565PixelAlpha_2pixels_head
ARGBto565PixelAlpha_2pixels_tail
.endif
.if numbytes >= 8
ARGBto565PixelAlpha_2pixels_head
ARGBto565PixelAlpha_2pixels_tail
.endif
.if numbytes >= 4
ARGBto565PixelAlpha_2pixels_head
.else // numbytes == 2
ldr WK0, [SRC], #4
ldrh WK2, [DST], #2
tst WK0, #0xff000000
.endif
.endm
.macro ARGBto565PixelAlpha_process_tail cond, numbytes, firstreg
.if numbytes >= 4
ARGBto565PixelAlpha_2pixels_tail
.else // numbytes == 2
beq 20f @ all transparent
cmp WK0, #0xff000000
bhs 10f @ opaque
ARGBto565PixelAlpha_1pixel_translucent WK0, WK2, MASK, STRIDE_M, STRIDE_S, STRIDE_D, WK3, SCRATCH, ORIG_W
b 19f
10: ARGBto565PixelAlpha_1pixel_opaque WK0, WK2, MASK
19: strh WK2, [DST, #-2]
20:
.endif
.endm
generate_composite_function \
BlitARGBto565PixelAlphaARMSIMDAsm, 32, 0, 16, \
FLAG_DST_READWRITE | FLAG_BRANCH_OVER | FLAG_PROCESS_CORRUPTS_PSR | FLAG_PROCESS_DOES_STORE | FLAG_SPILL_LINE_VARS | FLAG_PROCESS_CORRUPTS_WK0, \
2, /* prefetch distance */ \
ARGBto565PixelAlpha_init, \
ARGBto565PixelAlpha_newline, \
nop_macro, /* cleanup */ \
ARGBto565PixelAlpha_process_head, \
ARGBto565PixelAlpha_process_tail
/******************************************************************************/
.macro BGR888toRGB888_1pixel cond, reg, tmp
uxtb16&cond tmp, WK&reg, ror #8
uxtb16&cond WK&reg, WK&reg, ror #16
orr&cond WK&reg, WK&reg, tmp, lsl #8
.endm
.macro BGR888toRGB888_2pixels cond, reg1, reg2, tmp1, tmp2
uxtb16&cond tmp1, WK&reg1, ror #8
uxtb16&cond WK&reg1, WK&reg1, ror #16
uxtb16&cond tmp2, WK&reg2, ror #8
uxtb16&cond WK&reg2, WK&reg2, ror #16
orr&cond WK&reg1, WK&reg1, tmp1, lsl #8
orr&cond WK&reg2, WK&reg2, tmp2, lsl #8
.endm
.macro BGR888toRGB888_process_head cond, numbytes, firstreg, unaligned_src, unaligned_mask, preload
pixld cond, numbytes, firstreg, SRC, unaligned_src
.endm
.macro BGR888toRGB888_process_tail cond, numbytes, firstreg
.if numbytes >= 8
BGR888toRGB888_2pixels cond, %(firstreg+0), %(firstreg+1), MASK, STRIDE_M
.if numbytes == 16
BGR888toRGB888_2pixels cond, %(firstreg+2), %(firstreg+3), MASK, STRIDE_M
.endif
.else @ numbytes == 4
BGR888toRGB888_1pixel cond, %(firstreg+0), MASK
.endif
.endm
generate_composite_function \
Blit_BGR888_RGB888ARMSIMDAsm, 32, 0, 32, \
FLAG_DST_WRITEONLY | FLAG_COND_EXEC | FLAG_PROCESS_PRESERVES_SCRATCH, \
2, /* prefetch distance */ \
nop_macro, /* init */ \
nop_macro, /* newline */ \
nop_macro, /* cleanup */ \
BGR888toRGB888_process_head, \
BGR888toRGB888_process_tail
/******************************************************************************/
.macro RGB444toRGB888_init
ldr MASK, =0x0f0f0f0f
/* Set GE[3:0] to 0101 so SEL instructions do what we want */
msr CPSR_s, #0x50000
.endm
.macro RGB444toRGB888_1pixel reg, mask, tmp
pkhbt WK&reg, WK&reg, WK&reg, lsl #12 @ 0000aaaarrrrggggaaaarrrrggggbbbb
and WK&reg, mask, WK&reg @ 0000aaaa0000gggg0000rrrr0000bbbb
orr WK&reg, WK&reg, WK&reg, lsl #4 @ aaaaaaaaggggggggrrrrrrrrbbbbbbbb
pkhtb tmp, WK&reg, WK&reg, asr #8 @ aaaaaaaaggggggggggggggggrrrrrrrr
pkhbt WK&reg, WK&reg, WK&reg, lsl #8 @ ggggggggrrrrrrrrrrrrrrrrbbbbbbbb
sel WK&reg, WK&reg, tmp @ aaaaaaaarrrrrrrrggggggggbbbbbbbb
.endm
.macro RGB444toRGB888_2pixels in, out1, out2, mask, tmp1, tmp2
and tmp1, mask, WK&in @ 0000RRRR0000BBBB0000rrrr0000bbbb
and tmp2, mask, WK&in, lsr #4 @ 0000AAAA0000GGGG0000aaaa0000gggg
orr tmp1, tmp1, tmp1, lsl #4 @ RRRRRRRRBBBBBBBBrrrrrrrrbbbbbbbb
orr tmp2, tmp2, tmp2, lsl #4 @ AAAAAAAAGGGGGGGGaaaaaaaagggggggg
pkhtb WK&out2, tmp2, tmp1, asr #16 @ AAAAAAAAGGGGGGGGRRRRRRRRBBBBBBBB
pkhbt WK&out1, tmp1, tmp2, lsl #16 @ aaaaaaaaggggggggrrrrrrrrbbbbbbbb
pkhtb tmp2, WK&out2, WK&out2, asr #8 @ AAAAAAAAGGGGGGGGGGGGGGGGRRRRRRRR
pkhtb tmp1, WK&out1, WK&out1, asr #8 @ aaaaaaaaggggggggggggggggrrrrrrrr
pkhbt WK&out1, WK&out1, WK&out1, lsl #8 @ ggggggggrrrrrrrrrrrrrrrrbbbbbbbb
pkhbt WK&out2, WK&out2, WK&out2, lsl #8 @ GGGGGGGGRRRRRRRRRRRRRRRRBBBBBBBB
sel WK&out1, WK&out1, tmp1 @ aaaaaaaarrrrrrrrggggggggbbbbbbbb
sel WK&out2, WK&out2, tmp2 @ AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB
.endm
.macro RGB444toRGB888_process_head cond, numbytes, firstreg, unaligned_src, unaligned_mask, preload
pixld cond, numbytes/2, firstreg, SRC, unaligned_src
.endm
.macro RGB444toRGB888_process_tail cond, numbytes, firstreg
.if numbytes >= 8
.if numbytes == 16
RGB444toRGB888_2pixels %(firstreg+1), %(firstreg+2), %(firstreg+3), MASK, STRIDE_M, SCRATCH
.endif
RGB444toRGB888_2pixels %(firstreg+0), %(firstreg+0), %(firstreg+1), MASK, STRIDE_M, SCRATCH
.else @ numbytes == 4
RGB444toRGB888_1pixel %(firstreg+0), MASK, SCRATCH
.endif
.endm
generate_composite_function \
Blit_RGB444_RGB888ARMSIMDAsm, 16, 0, 32, \
FLAG_DST_WRITEONLY | FLAG_BRANCH_OVER, \
2, /* prefetch distance */ \
RGB444toRGB888_init, \
nop_macro, /* newline */ \
nop_macro, /* cleanup */ \
RGB444toRGB888_process_head, \
RGB444toRGB888_process_tail

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,36 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoaclipboard_h_
#define SDL_cocoaclipboard_h_
/* Forward declaration */
struct SDL_VideoData;
extern int Cocoa_SetClipboardText(_THIS, const char *text);
extern char *Cocoa_GetClipboardText(_THIS);
extern SDL_bool Cocoa_HasClipboardText(_THIS);
extern void Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data);
#endif /* SDL_cocoaclipboard_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,103 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_COCOA
#include "SDL_cocoavideo.h"
#include "../../events/SDL_clipboardevents_c.h"
int
Cocoa_SetClipboardText(_THIS, const char *text)
{ @autoreleasepool
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
NSPasteboard *pasteboard;
NSString *format = NSPasteboardTypeString;
pasteboard = [NSPasteboard generalPasteboard];
data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
[pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
return 0;
}}
char *
Cocoa_GetClipboardText(_THIS)
{ @autoreleasepool
{
NSPasteboard *pasteboard;
NSString *format = NSPasteboardTypeString;
NSString *available;
char *text;
pasteboard = [NSPasteboard generalPasteboard];
available = [pasteboard availableTypeFromArray:[NSArray arrayWithObject:format]];
if ([available isEqualToString:format]) {
NSString* string;
const char *utf8;
string = [pasteboard stringForType:format];
if (string == nil) {
utf8 = "";
} else {
utf8 = [string UTF8String];
}
text = SDL_strdup(utf8);
} else {
text = SDL_strdup("");
}
return text;
}}
SDL_bool
Cocoa_HasClipboardText(_THIS)
{
SDL_bool result = SDL_FALSE;
char *text = Cocoa_GetClipboardText(_this);
if (text) {
result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
SDL_free(text);
}
return result;
}
void
Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
{ @autoreleasepool
{
NSPasteboard *pasteboard;
NSInteger count;
pasteboard = [NSPasteboard generalPasteboard];
count = [pasteboard changeCount];
if (count != data->clipboard_count) {
if (data->clipboard_count) {
SDL_SendClipboardUpdate();
}
data->clipboard_count = count;
}
}}
#endif /* SDL_VIDEO_DRIVER_COCOA */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,32 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoaevents_h_
#define SDL_cocoaevents_h_
extern void Cocoa_RegisterApp(void);
extern void Cocoa_PumpEvents(_THIS);
extern void Cocoa_SuspendScreenSaver(_THIS);
#endif /* SDL_cocoaevents_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,511 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_COCOA
#include "SDL_timer.h"
#include "SDL_cocoavideo.h"
#include "../../events/SDL_events_c.h"
#include "SDL_assert.h"
#include "SDL_hints.h"
/* This define was added in the 10.9 SDK. */
#ifndef kIOPMAssertPreventUserIdleDisplaySleep
#define kIOPMAssertPreventUserIdleDisplaySleep kIOPMAssertionTypePreventUserIdleDisplaySleep
#endif
@interface SDLApplication : NSApplication
- (void)terminate:(id)sender;
- (void)sendEvent:(NSEvent *)theEvent;
+ (void)registerUserDefaults;
@end
@implementation SDLApplication
// Override terminate to handle Quit and System Shutdown smoothly.
- (void)terminate:(id)sender
{
SDL_SendQuit();
}
static SDL_bool s_bShouldHandleEventsInSDLApplication = SDL_FALSE;
static void Cocoa_DispatchEvent(NSEvent *theEvent)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
switch ([theEvent type]) {
case NSEventTypeLeftMouseDown:
case NSEventTypeOtherMouseDown:
case NSEventTypeRightMouseDown:
case NSEventTypeLeftMouseUp:
case NSEventTypeOtherMouseUp:
case NSEventTypeRightMouseUp:
case NSEventTypeLeftMouseDragged:
case NSEventTypeRightMouseDragged:
case NSEventTypeOtherMouseDragged: /* usually middle mouse dragged */
case NSEventTypeMouseMoved:
case NSEventTypeScrollWheel:
Cocoa_HandleMouseEvent(_this, theEvent);
break;
case NSEventTypeKeyDown:
case NSEventTypeKeyUp:
case NSEventTypeFlagsChanged:
Cocoa_HandleKeyEvent(_this, theEvent);
break;
default:
break;
}
}
// Dispatch events here so that we can handle events caught by
// nextEventMatchingMask in SDL, as well as events caught by other
// processes (such as CEF) that are passed down to NSApp.
- (void)sendEvent:(NSEvent *)theEvent
{
if (s_bShouldHandleEventsInSDLApplication) {
Cocoa_DispatchEvent(theEvent);
}
[super sendEvent:theEvent];
}
+ (void)registerUserDefaults
{
NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
[NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
[NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
[appDefaults release];
}
@end // SDLApplication
/* setAppleMenu disappeared from the headers in 10.4 */
@interface NSApplication(NSAppleMenu)
- (void)setAppleMenu:(NSMenu *)menu;
@end
@interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
@public
BOOL seenFirstActivate;
}
- (id)init;
@end
@implementation SDLAppDelegate : NSObject
- (id)init
{
self = [super init];
if (self) {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
seenFirstActivate = NO;
[center addObserver:self
selector:@selector(windowWillClose:)
name:NSWindowWillCloseNotification
object:nil];
[center addObserver:self
selector:@selector(focusSomeWindow:)
name:NSApplicationDidBecomeActiveNotification
object:nil];
}
return self;
}
- (void)dealloc
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center removeObserver:self name:NSWindowWillCloseNotification object:nil];
[center removeObserver:self name:NSApplicationDidBecomeActiveNotification object:nil];
[super dealloc];
}
- (void)windowWillClose:(NSNotification *)notification;
{
NSWindow *win = (NSWindow*)[notification object];
if (![win isKeyWindow]) {
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
* prevent the normal behavior: https://bugzilla.libsdl.org/show_bug.cgi?id=1825
*/
/* +[NSApp orderedWindows] never includes the 'About' window, but we still
* want to try its list first since the behavior in other apps is to only
* make the 'About' window key if no other windows are on-screen.
*/
for (NSWindow *window in [NSApp orderedWindows]) {
if (window != win && [window canBecomeKeyWindow]) {
if (![window isOnActiveSpace]) {
continue;
}
[window makeKeyAndOrderFront:self];
return;
}
}
/* If a window wasn't found above, iterate through all visible windows in
* the active Space in z-order (including the 'About' window, if it's shown)
* and make the first one key.
*/
for (NSNumber *num in [NSWindow windowNumbersWithOptions:0]) {
NSWindow *window = [NSApp windowWithWindowNumber:[num integerValue]];
if (window && window != win && [window canBecomeKeyWindow]) {
[window makeKeyAndOrderFront:self];
return;
}
}
}
- (void)focusSomeWindow:(NSNotification *)aNotification
{
/* 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
* SDL_WINDOW_MINIMIZED will ~immediately be restored.
*/
if (!seenFirstActivate) {
seenFirstActivate = YES;
return;
}
SDL_VideoDevice *device = SDL_GetVideoDevice();
if (device && device->windows) {
SDL_Window *window = device->windows;
int i;
for (i = 0; i < device->num_displays; ++i) {
SDL_Window *fullscreen_window = device->displays[i].fullscreen_window;
if (fullscreen_window) {
if (fullscreen_window->flags & SDL_WINDOW_MINIMIZED) {
SDL_RestoreWindow(fullscreen_window);
}
return;
}
}
if (window->flags & SDL_WINDOW_MINIMIZED) {
SDL_RestoreWindow(window);
} else {
SDL_RaiseWindow(window);
}
}
}
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
return (BOOL)SDL_SendDropFile(NULL, [filename UTF8String]) && SDL_SendDropComplete(NULL);
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
/* The menu bar of SDL apps which don't have the typical .app bundle
* structure fails to work the first time a window is created (until it's
* de-focused and re-focused), if this call is in Cocoa_RegisterApp instead
* of here. https://bugzilla.libsdl.org/show_bug.cgi?id=3051
*/
if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
/* Get more aggressive for Catalina: activate the Dock first so we definitely reset all activation state. */
for (NSRunningApplication *i in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"]) {
[i activateWithOptions:NSApplicationActivateIgnoringOtherApps];
break;
}
SDL_Delay(300); /* !!! FIXME: this isn't right. */
[NSApp activateIgnoringOtherApps:YES];
}
/* If we call this before NSApp activation, macOS might print a complaint
* about ApplePersistenceIgnoreState. */
[SDLApplication registerUserDefaults];
}
@end
static SDLAppDelegate *appDelegate = nil;
static NSString *
GetApplicationName(void)
{
NSString *appName;
/* Determine the application name */
appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
if (!appName) {
appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
}
if (![appName length]) {
appName = [[NSProcessInfo processInfo] processName];
}
return appName;
}
static bool
LoadMainMenuNibIfAvailable(void)
{
NSDictionary *infoDict;
NSString *mainNibFileName;
bool success = false;
infoDict = [[NSBundle mainBundle] infoDictionary];
if (infoDict) {
mainNibFileName = [infoDict valueForKey:@"NSMainNibFile"];
if (mainNibFileName) {
success = [[NSBundle mainBundle] loadNibNamed:mainNibFileName owner:[NSApplication sharedApplication] topLevelObjects:nil];
}
}
return success;
}
static void
CreateApplicationMenus(void)
{
NSString *appName;
NSString *title;
NSMenu *appleMenu;
NSMenu *serviceMenu;
NSMenu *windowMenu;
NSMenuItem *menuItem;
NSMenu *mainMenu;
if (NSApp == nil) {
return;
}
mainMenu = [[NSMenu alloc] init];
/* Create the main menu bar */
[NSApp setMainMenu:mainMenu];
[mainMenu release]; /* we're done with it, let NSApp own it. */
mainMenu = nil;
/* Create the application menu */
appName = GetApplicationName();
appleMenu = [[NSMenu alloc] initWithTitle:@""];
/* Add menu items */
title = [@"About " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
[appleMenu addItemWithTitle:@"Preferences…" action:nil keyEquivalent:@","];
[appleMenu addItem:[NSMenuItem separatorItem]];
serviceMenu = [[NSMenu alloc] initWithTitle:@""];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
[menuItem setSubmenu:serviceMenu];
[NSApp setServicesMenu:serviceMenu];
[serviceMenu release];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Hide " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
[menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)];
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Quit " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[menuItem setSubmenu:appleMenu];
[[NSApp mainMenu] addItem:menuItem];
[menuItem release];
/* Tell the application object that this is now the application menu */
[NSApp setAppleMenu:appleMenu];
[appleMenu release];
/* Create the window menu */
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
/* Add menu items */
[windowMenu addItemWithTitle:@"Close" action:@selector(performClose:) keyEquivalent:@"w"];
[windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
[windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
/* Add the fullscreen toggle menu option, if supported */
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
/* Cocoa should update the title to Enter or Exit Full Screen automatically.
* But if not, then just fallback to Toggle Full Screen.
*/
menuItem = [[NSMenuItem alloc] initWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
[menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
[windowMenu addItem:menuItem];
[menuItem release];
}
/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
[menuItem setSubmenu:windowMenu];
[[NSApp mainMenu] addItem:menuItem];
[menuItem release];
/* Tell the application object that this is now the window menu */
[NSApp setWindowsMenu:windowMenu];
[windowMenu release];
}
void
Cocoa_RegisterApp(void)
{ @autoreleasepool
{
/* This can get called more than once! Be careful what you initialize! */
if (NSApp == nil) {
[SDLApplication sharedApplication];
SDL_assert(NSApp != nil);
s_bShouldHandleEventsInSDLApplication = SDL_TRUE;
if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
}
/* If there aren't already menus in place, look to see if there's
* a nib we should use. If not, then manually create the basic
* menus we meed.
*/
if ([NSApp mainMenu] == nil) {
bool nibLoaded;
nibLoaded = LoadMainMenuNibIfAvailable();
if (!nibLoaded) {
CreateApplicationMenus();
}
}
[NSApp finishLaunching];
if ([NSApp delegate]) {
/* The SDL app delegate calls this in didFinishLaunching if it's
* attached to the NSApp, otherwise we need to call it manually.
*/
[SDLApplication registerUserDefaults];
}
}
if (NSApp && !appDelegate) {
appDelegate = [[SDLAppDelegate alloc] init];
/* If someone else has an app delegate, it means we can't turn a
* termination into SDL_Quit, and we can't handle application:openFile:
*/
if (![NSApp delegate]) {
[(NSApplication *)NSApp setDelegate:appDelegate];
} else {
appDelegate->seenFirstActivate = YES;
}
}
}}
void
Cocoa_PumpEvents(_THIS)
{ @autoreleasepool
{
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
/* Update activity every 30 seconds to prevent screensaver */
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
if (_this->suspend_screensaver && !data->screensaver_use_iopm) {
Uint32 now = SDL_GetTicks();
if (!data->screensaver_activity ||
SDL_TICKS_PASSED(now, data->screensaver_activity + 30000)) {
UpdateSystemActivity(UsrActivity);
data->screensaver_activity = now;
}
}
#endif
for ( ; ; ) {
NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
if ( event == nil ) {
break;
}
if (!s_bShouldHandleEventsInSDLApplication) {
Cocoa_DispatchEvent(event);
}
// Pass events down to SDLApplication to be handled in sendEvent:
[NSApp sendEvent:event];
}
}}
void
Cocoa_SuspendScreenSaver(_THIS)
{ @autoreleasepool
{
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
if (!data->screensaver_use_iopm) {
return;
}
if (data->screensaver_assertion) {
IOPMAssertionRelease(data->screensaver_assertion);
data->screensaver_assertion = 0;
}
if (_this->suspend_screensaver) {
/* FIXME: this should ideally describe the real reason why the game
* called SDL_DisableScreenSaver. Note that the name is only meant to be
* seen by OS X power users. there's an additional optional human-readable
* (localized) reason parameter which we don't set.
*/
NSString *name = [GetApplicationName() stringByAppendingString:@" using SDL_DisableScreenSaver"];
IOPMAssertionCreateWithDescription(kIOPMAssertPreventUserIdleDisplaySleep,
(CFStringRef) name,
NULL, NULL, NULL, 0, NULL,
&data->screensaver_assertion);
}
}}
#endif /* SDL_VIDEO_DRIVER_COCOA */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,36 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoakeyboard_h_
#define SDL_cocoakeyboard_h_
extern void Cocoa_InitKeyboard(_THIS);
extern void Cocoa_HandleKeyEvent(_THIS, NSEvent * event);
extern void Cocoa_QuitKeyboard(_THIS);
extern void Cocoa_StartTextInput(_THIS);
extern void Cocoa_StopTextInput(_THIS);
extern void Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect);
#endif /* SDL_cocoakeyboard_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,607 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_COCOA
#include "SDL_cocoavideo.h"
#include "../../events/SDL_events_c.h"
#include "../../events/SDL_keyboard_c.h"
#include "../../events/scancodes_darwin.h"
#include <Carbon/Carbon.h>
/*#define DEBUG_IME NSLog */
#define DEBUG_IME(...)
@interface SDLTranslatorResponder : NSView <NSTextInputClient> {
NSString *_markedText;
NSRange _markedRange;
NSRange _selectedRange;
SDL_Rect _inputRect;
}
- (void)doCommandBySelector:(SEL)myselector;
- (void)setInputRect:(SDL_Rect *)rect;
@end
@implementation SDLTranslatorResponder
- (void)setInputRect:(SDL_Rect *)rect
{
_inputRect = *rect;
}
- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange
{
/* TODO: Make use of replacementRange? */
const char *str;
DEBUG_IME(@"insertText: %@", aString);
/* Could be NSString or NSAttributedString, so we have
* to test and convert it before return as SDL event */
if ([aString isKindOfClass: [NSAttributedString class]]) {
str = [[aString string] UTF8String];
} else {
str = [aString UTF8String];
}
SDL_SendKeyboardText(str);
}
- (void)doCommandBySelector:(SEL)myselector
{
/* No need to do anything since we are not using Cocoa
selectors to handle special keys, instead we use SDL
key events to do the same job.
*/
}
- (BOOL)hasMarkedText
{
return _markedText != nil;
}
- (NSRange)markedRange
{
return _markedRange;
}
- (NSRange)selectedRange
{
return _selectedRange;
}
- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange
{
if ([aString isKindOfClass:[NSAttributedString class]]) {
aString = [aString string];
}
if ([aString length] == 0) {
[self unmarkText];
return;
}
if (_markedText != aString) {
[_markedText release];
_markedText = [aString retain];
}
_selectedRange = selectedRange;
_markedRange = NSMakeRange(0, [aString length]);
SDL_SendEditingText([aString UTF8String],
(int) selectedRange.location, (int) selectedRange.length);
DEBUG_IME(@"setMarkedText: %@, (%d, %d)", _markedText,
selRange.location, selRange.length);
}
- (void)unmarkText
{
[_markedText release];
_markedText = nil;
SDL_SendEditingText("", 0, 0);
}
- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange
{
NSWindow *window = [self window];
NSRect contentRect = [window contentRectForFrameRect:[window frame]];
float windowHeight = contentRect.size.height;
NSRect rect = NSMakeRect(_inputRect.x, windowHeight - _inputRect.y - _inputRect.h,
_inputRect.w, _inputRect.h);
if (actualRange) {
*actualRange = aRange;
}
DEBUG_IME(@"firstRectForCharacterRange: (%d, %d): windowHeight = %g, rect = %@",
aRange.location, aRange.length, windowHeight,
NSStringFromRect(rect));
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
if (![window respondsToSelector:@selector(convertRectToScreen:)]) {
rect.origin = [window convertBaseToScreen:rect.origin];
} else
#endif
{
rect = [window convertRectToScreen:rect];
}
return rect;
}
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange
{
DEBUG_IME(@"attributedSubstringFromRange: (%d, %d)", aRange.location, aRange.length);
return nil;
}
- (NSInteger)conversationIdentifier
{
return (NSInteger) self;
}
/* This method returns the index for character that is
* nearest to thePoint. thPoint is in screen coordinate system.
*/
- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint
{
DEBUG_IME(@"characterIndexForPoint: (%g, %g)", thePoint.x, thePoint.y);
return 0;
}
/* This method is the key to attribute extension.
* We could add new attributes through this method.
* NSInputServer examines the return value of this
* method & constructs appropriate attributed string.
*/
- (NSArray *)validAttributesForMarkedText
{
return [NSArray array];
}
@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)
{
unsigned int oldMask, newMask;
/* 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 (oldMask && oldMask != newMask) {
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
} else if (newMask && oldMask != newMask) {
SDL_SendKeyboardKey(SDL_PRESSED, scancode);
}
}
/* 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)
{
unsigned int old_dep_mask, new_dep_mask;
/* 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);
} 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);
}
}
}
/* 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 = (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)
{
TISInputSourceRef key_layout;
const void *chr_data;
int i;
SDL_Scancode scancode;
SDL_Keycode keymap[SDL_NUM_SCANCODES];
/* See if the keymap needs to be updated */
key_layout = TISCopyCurrentKeyboardLayoutInputSource();
if (key_layout == data->key_layout) {
return;
}
data->key_layout = key_layout;
SDL_GetDefaultKeymap(keymap);
/* Try Unicode data first */
CFDataRef uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData);
if (uchrDataRef) {
chr_data = CFDataGetBytePtr(uchrDataRef);
} else {
goto cleanup;
}
if (chr_data) {
UInt32 keyboard_type = LMGetKbdType();
OSStatus err;
for (i = 0; i < SDL_arraysize(darwin_scancode_table); i++) {
UniChar s[8];
UniCharCount len;
UInt32 dead_key_state;
/* Make sure this scancode is a valid character scancode */
scancode = darwin_scancode_table[i];
if (scancode == SDL_SCANCODE_UNKNOWN ||
(keymap[scancode] & SDLK_SCANCODE_MASK)) {
continue;
}
dead_key_state = 0;
err = UCKeyTranslate ((UCKeyboardLayout *) chr_data,
i, kUCKeyActionDown,
0, keyboard_type,
kUCKeyTranslateNoDeadKeysMask,
&dead_key_state, 8, &len, s);
if (err != noErr) {
continue;
}
if (len > 0 && s[0] != 0x10) {
keymap[scancode] = s[0];
}
}
SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
if (send_event) {
SDL_SendKeymapChangedEvent();
}
return;
}
cleanup:
CFRelease(key_layout);
}
void
Cocoa_InitKeyboard(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
UpdateKeymap(data, SDL_FALSE);
/* Set our own names for the platform-dependent but layout-independent keys */
/* This key is NumLock on the MacBook keyboard. :) */
/*SDL_SetScancodeName(SDL_SCANCODE_NUMLOCKCLEAR, "Clear");*/
SDL_SetScancodeName(SDL_SCANCODE_LALT, "Left Option");
SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Command");
SDL_SetScancodeName(SDL_SCANCODE_RALT, "Right Option");
SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");
data->modifierFlags = (unsigned int)[NSEvent modifierFlags];
SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSEventModifierFlagCapsLock) != 0);
}
void
Cocoa_StartTextInput(_THIS)
{ @autoreleasepool
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
SDL_Window *window = SDL_GetKeyboardFocus();
NSWindow *nswindow = nil;
if (window) {
nswindow = ((SDL_WindowData*)window->driverdata)->nswindow;
}
NSView *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
* than one copy. When we switched to another window and requesting for
* text input, simply remove the field editor from its superview then add
* it to the front most window's content view */
if (!data->fieldEdit) {
data->fieldEdit =
[[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
}
if (![[data->fieldEdit superview] isEqual:parentView]) {
/* DEBUG_IME(@"add fieldEdit to window contentView"); */
[data->fieldEdit removeFromSuperview];
[parentView addSubview: data->fieldEdit];
[nswindow makeFirstResponder: data->fieldEdit];
}
}}
void
Cocoa_StopTextInput(_THIS)
{ @autoreleasepool
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
if (data && data->fieldEdit) {
[data->fieldEdit removeFromSuperview];
[data->fieldEdit release];
data->fieldEdit = nil;
}
}}
void
Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
if (!rect) {
SDL_InvalidParamError("rect");
return;
}
[data->fieldEdit setInputRect:rect];
}
void
Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
{
SDL_VideoData *data = _this ? ((SDL_VideoData *) _this->driverdata) : NULL;
if (!data) {
return; /* can happen when returning from fullscreen Space on shutdown */
}
unsigned short scancode = [event keyCode];
SDL_Scancode code;
#if 0
const char *text;
#endif
if ((scancode == 10 || scancode == 50) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) {
/* see comments in SDL_cocoakeys.h */
scancode = 60 - scancode;
}
if (scancode < SDL_arraysize(darwin_scancode_table)) {
code = darwin_scancode_table[scancode];
} else {
/* Hmm, does this ever happen? If so, need to extend the keymap... */
code = SDL_SCANCODE_UNKNOWN;
}
switch ([event type]) {
case NSEventTypeKeyDown:
if (![event isARepeat]) {
/* See if we need to rebuild the keyboard layout */
UpdateKeymap(data, SDL_TRUE);
}
SDL_SendKeyboardKey(SDL_PRESSED, code);
#if 1
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);
}
#endif
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
/* FIXME CW 2007-08-16: only send those events to the field editor for which we actually want text events, not e.g. esc or function keys. Arrow keys in particular seem to produce crashes sometimes. */
[data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
#if 0
text = [[event characters] UTF8String];
if(text && *text) {
SDL_SendKeyboardText(text);
[data->fieldEdit setString:@""];
}
#endif
}
break;
case NSEventTypeKeyUp:
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]);
break;
default: /* just to avoid compiler warnings */
break;
}
}
void
Cocoa_QuitKeyboard(_THIS)
{
}
#endif /* SDL_VIDEO_DRIVER_COCOA */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,29 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_COCOA
extern int Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
#endif /* SDL_VIDEO_DRIVER_COCOA */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,157 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_COCOA
#include "SDL_events.h"
#include "SDL_timer.h"
#include "SDL_messagebox.h"
#include "SDL_cocoavideo.h"
@interface SDLMessageBoxPresenter : NSObject {
@public
NSInteger clicked;
NSWindow *nswindow;
}
- (id) initWithParentWindow:(SDL_Window *)window;
- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
@end
@implementation SDLMessageBoxPresenter
- (id) initWithParentWindow:(SDL_Window *)window
{
self = [super init];
if (self) {
clicked = -1;
/* Retain the NSWindow because we'll show the alert later on the main thread */
if (window) {
nswindow = [((SDL_WindowData *) window->driverdata)->nswindow retain];
} else {
nswindow = NULL;
}
}
return self;
}
- (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) {
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);
}
[nswindow release];
} else {
clicked = [alert runModal];
}
}
- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
clicked = returnCode;
}
@end
/* Display a Cocoa message box */
int
Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
{ @autoreleasepool
{
Cocoa_RegisterApp();
NSAlert* alert = [[[NSAlert alloc] init] autorelease];
if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
[alert setAlertStyle:NSAlertStyleCritical];
} else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
[alert setAlertStyle:NSAlertStyleWarning];
} else {
[alert setAlertStyle:NSAlertStyleInformational];
}
[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;
if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT) {
sdlButton = &messageboxdata->buttons[messageboxdata->numbuttons - 1 - i];
} else {
sdlButton = &messageboxdata->buttons[i];
}
button = [alert addButtonWithTitle:[NSString stringWithUTF8String:sdlButton->text]];
if (sdlButton->flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
[button setKeyEquivalent:@"\r"];
} else if (sdlButton->flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
[button setKeyEquivalent:@"\033"];
} else {
[button setKeyEquivalent:@""];
}
}
SDLMessageBoxPresenter* presenter = [[[SDLMessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window] autorelease];
[presenter performSelectorOnMainThread:@selector(showAlert:)
withObject:alert
waitUntilDone:YES];
int returnValue = 0;
NSInteger clicked = presenter->clicked;
if (clicked >= NSAlertFirstButtonReturn) {
clicked -= NSAlertFirstButtonReturn;
if (messageboxdata->flags & SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT) {
clicked = messageboxdata->numbuttons - 1 - clicked;
}
*buttonid = buttons[clicked].buttonid;
} else {
returnValue = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked);
}
return returnValue;
}}
#endif /* SDL_VIDEO_DRIVER_COCOA */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,70 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
* @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.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoametalview_h_
#define SDL_cocoametalview_h_
#if SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_METAL)
#import "../SDL_sysvideo.h"
#import "SDL_cocoawindow.h"
#import <Cocoa/Cocoa.h>
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
#define METALVIEW_TAG 255
@interface SDL_cocoametalview : NSView
- (instancetype)initWithFrame:(NSRect)frame
highDPI:(BOOL)highDPI
windowID:(Uint32)windowID;
- (void)updateDrawableSize;
/* Override superclass tag so this class can set it. */
@property (assign, readonly) NSInteger tag;
@property (nonatomic) BOOL highDPI;
@property (nonatomic) Uint32 sdlWindowID;
@end
SDL_MetalView Cocoa_Metal_CreateView(_THIS, SDL_Window * window);
void Cocoa_Metal_DestroyView(_THIS, SDL_MetalView view);
void Cocoa_Metal_GetDrawableSize(SDL_Window * window, int * w, int * h);
#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_METAL) */
#endif /* SDL_cocoametalview_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,182 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
* @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.
*/
#import "SDL_cocoametalview.h"
#if SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_METAL)
#include "SDL_assert.h"
#include "SDL_events.h"
static int SDLCALL
SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
{
/* Update the drawable size when SDL receives a size changed event for
* the window that contains the metal view. It would be nice to use
* - (void)resizeWithOldSuperviewSize:(NSSize)oldSize and
* - (void)viewDidChangeBackingProperties instead, but SDL's size change
* events don't always happen in the same frame (for example when a
* resizable window exits a fullscreen Space via the user pressing the OS
* exit-space button). */
if (event->type == SDL_WINDOWEVENT && event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
@autoreleasepool {
SDL_cocoametalview *view = (__bridge SDL_cocoametalview *)userdata;
if (view.sdlWindowID == event->window.windowID) {
[view updateDrawableSize];
}
}
}
return 0;
}
@implementation SDL_cocoametalview
/* Return a Metal-compatible layer. */
+ (Class)layerClass
{
return NSClassFromString(@"CAMetalLayer");
}
/* Indicate the view wants to draw using a backing layer instead of drawRect. */
- (BOOL)wantsUpdateLayer
{
return YES;
}
/* When the wantsLayer property is set to YES, this method will be invoked to
* return a layer instance.
*/
- (CALayer*)makeBackingLayer
{
return [self.class.layerClass layer];
}
- (instancetype)initWithFrame:(NSRect)frame
highDPI:(BOOL)highDPI
windowID:(Uint32)windowID;
{
if ((self = [super initWithFrame:frame])) {
self.highDPI = highDPI;
self.sdlWindowID = windowID;
self.wantsLayer = YES;
/* Allow resize. */
self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
SDL_AddEventWatch(SDL_MetalViewEventWatch, self);
[self updateDrawableSize];
}
return self;
}
- (void)dealloc
{
SDL_DelEventWatch(SDL_MetalViewEventWatch, self);
[super dealloc];
}
- (NSInteger)tag
{
return METALVIEW_TAG;
}
- (void)updateDrawableSize
{
CAMetalLayer *metalLayer = (CAMetalLayer *)self.layer;
NSSize size = self.bounds.size;
NSSize backingSize = size;
if (self.highDPI) {
/* Note: NSHighResolutionCapable must be set to true in the app's
* Info.plist in order for the backing size to be high res.
*/
backingSize = [self convertSizeToBacking:size];
}
metalLayer.contentsScale = backingSize.height / size.height;
metalLayer.drawableSize = NSSizeToCGSize(backingSize);
}
@end
SDL_MetalView
Cocoa_Metal_CreateView(_THIS, SDL_Window * window)
{ @autoreleasepool {
SDL_WindowData* data = (__bridge SDL_WindowData *)window->driverdata;
NSView *view = data->nswindow.contentView;
BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
Uint32 windowID = SDL_GetWindowID(window);
SDL_cocoametalview *newview;
SDL_MetalView metalview;
newview = [[SDL_cocoametalview alloc] initWithFrame:view.frame
highDPI:highDPI
windowID:windowID];
if (newview == nil) {
return NULL;
}
[view addSubview:newview];
metalview = (SDL_MetalView)CFBridgingRetain(newview);
[newview release];
return metalview;
}}
void
Cocoa_Metal_DestroyView(_THIS, SDL_MetalView view)
{ @autoreleasepool {
SDL_cocoametalview *metalview = CFBridgingRelease(view);
[metalview removeFromSuperview];
}}
void
Cocoa_Metal_GetDrawableSize(SDL_Window * window, int * w, int * h)
{ @autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
NSView *view = data->nswindow.contentView;
SDL_cocoametalview* metalview = [view viewWithTag:METALVIEW_TAG];
if (metalview) {
CAMetalLayer *layer = (CAMetalLayer*)metalview.layer;
SDL_assert(layer != NULL);
if (w) {
*w = layer.drawableSize.width;
}
if (h) {
*h = layer.drawableSize.height;
}
} else {
SDL_GetWindowSize(window, w, h);
}
}}
#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_METAL) */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,46 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoamodes_h_
#define SDL_cocoamodes_h_
typedef struct
{
CGDirectDisplayID display;
} SDL_DisplayData;
typedef struct
{
CFMutableArrayRef modes;
} SDL_DisplayModeData;
extern void Cocoa_InitModes(_THIS);
extern int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
extern int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
extern void Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
extern int Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hpdi, float * vdpi);
extern int Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
extern void Cocoa_QuitModes(_THIS);
#endif /* SDL_cocoamodes_h_ */
/* vi: set ts=4 sw=4 expandtab: */

683
externals/SDL/src/video/cocoa/SDL_cocoamodes.m vendored Executable file
View File

@@ -0,0 +1,683 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_assert.h"
#if SDL_VIDEO_DRIVER_COCOA
#include "SDL_cocoavideo.h"
/* We need this for IODisplayCreateInfoDictionary and kIODisplayOnlyPreferredName */
#include <IOKit/graphics/IOGraphicsLib.h>
/* We need this for CVDisplayLinkGetNominalOutputVideoRefreshPeriod */
#include <CoreVideo/CVBase.h>
#include <CoreVideo/CVDisplayLink.h>
/* we need this for ShowMenuBar() and HideMenuBar(). */
#include <Carbon/Carbon.h>
/* This gets us MAC_OS_X_VERSION_MIN_REQUIRED... */
#include <AvailabilityMacros.h>
#ifndef MAC_OS_X_VERSION_10_13
#define NSAppKitVersionNumber10_12 1504
#endif
static void
Cocoa_ToggleMenuBar(const BOOL show)
{
/* !!! FIXME: keep an eye on this.
* ShowMenuBar/HideMenuBar is officially unavailable for 64-bit binaries.
* It happens to work, as of 10.7, but we're going to see if
* we can just simply do without it on newer OSes...
*/
#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070) && !defined(__LP64__)
if (show) {
ShowMenuBar();
} else {
HideMenuBar();
}
#endif
}
static int
CG_SetError(const char *prefix, CGDisplayErr result)
{
const char *error;
switch (result) {
case kCGErrorFailure:
error = "kCGErrorFailure";
break;
case kCGErrorIllegalArgument:
error = "kCGErrorIllegalArgument";
break;
case kCGErrorInvalidConnection:
error = "kCGErrorInvalidConnection";
break;
case kCGErrorInvalidContext:
error = "kCGErrorInvalidContext";
break;
case kCGErrorCannotComplete:
error = "kCGErrorCannotComplete";
break;
case kCGErrorNotImplemented:
error = "kCGErrorNotImplemented";
break;
case kCGErrorRangeCheck:
error = "kCGErrorRangeCheck";
break;
case kCGErrorTypeCheck:
error = "kCGErrorTypeCheck";
break;
case kCGErrorInvalidOperation:
error = "kCGErrorInvalidOperation";
break;
case kCGErrorNoneAvailable:
error = "kCGErrorNoneAvailable";
break;
default:
error = "Unknown Error";
break;
}
return SDL_SetError("%s: %s", prefix, error);
}
static int
GetDisplayModeRefreshRate(CGDisplayModeRef vidmode, CVDisplayLinkRef link)
{
int refreshRate = (int) (CGDisplayModeGetRefreshRate(vidmode) + 0.5);
/* CGDisplayModeGetRefreshRate can return 0 (eg for built-in displays). */
if (refreshRate == 0 && link != NULL) {
CVTime time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
if ((time.flags & kCVTimeIsIndefinite) == 0 && time.timeValue != 0) {
refreshRate = (int) ((time.timeScale / (double) time.timeValue) + 0.5);
}
}
return refreshRate;
}
static SDL_bool
HasValidDisplayModeFlags(CGDisplayModeRef vidmode)
{
uint32_t ioflags = CGDisplayModeGetIOFlags(vidmode);
/* Filter out modes which have flags that we don't want. */
if (ioflags & (kDisplayModeNeverShowFlag | kDisplayModeNotGraphicsQualityFlag)) {
return SDL_FALSE;
}
/* Filter out modes which don't have flags that we want. */
if (!(ioflags & kDisplayModeValidFlag) || !(ioflags & kDisplayModeSafeFlag)) {
return SDL_FALSE;
}
return SDL_TRUE;
}
static Uint32
GetDisplayModePixelFormat(CGDisplayModeRef vidmode)
{
/* This API is deprecated in 10.11 with no good replacement (as of 10.15). */
CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
Uint32 pixelformat = SDL_PIXELFORMAT_UNKNOWN;
if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels),
kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
pixelformat = SDL_PIXELFORMAT_ARGB8888;
} else if (CFStringCompare(fmt, CFSTR(IO16BitDirectPixels),
kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
pixelformat = SDL_PIXELFORMAT_ARGB1555;
} else if (CFStringCompare(fmt, CFSTR(kIO30BitDirectPixels),
kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
pixelformat = SDL_PIXELFORMAT_ARGB2101010;
} else {
/* ignore 8-bit and such for now. */
}
CFRelease(fmt);
return pixelformat;
}
static SDL_bool
GetDisplayMode(_THIS, CGDisplayModeRef vidmode, CFArrayRef modelist, CVDisplayLinkRef link, SDL_DisplayMode *mode)
{
SDL_DisplayModeData *data;
bool usableForGUI = CGDisplayModeIsUsableForDesktopGUI(vidmode);
int width = (int) CGDisplayModeGetWidth(vidmode);
int height = (int) CGDisplayModeGetHeight(vidmode);
uint32_t ioflags = CGDisplayModeGetIOFlags(vidmode);
int refreshrate = GetDisplayModeRefreshRate(vidmode, link);
Uint32 format = GetDisplayModePixelFormat(vidmode);
bool interlaced = (ioflags & kDisplayModeInterlacedFlag) != 0;
CFMutableArrayRef modes;
if (format == SDL_PIXELFORMAT_UNKNOWN) {
return SDL_FALSE;
}
if (!HasValidDisplayModeFlags(vidmode)) {
return SDL_FALSE;
}
modes = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
CFArrayAppendValue(modes, vidmode);
/* If a list of possible diplay modes is passed in, use it to filter out
* modes that have duplicate sizes. We don't just rely on SDL's higher level
* duplicate filtering because this code can choose what properties are
* prefered, and it can add CGDisplayModes to the DisplayModeData's list of
* modes to try (see comment below for why that's necessary).
* CGDisplayModeGetPixelWidth and friends are only available in 10.8+. */
#ifdef MAC_OS_X_VERSION_10_8
if (modelist != NULL && floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_7) {
int pixelW = (int) CGDisplayModeGetPixelWidth(vidmode);
int pixelH = (int) CGDisplayModeGetPixelHeight(vidmode);
CFIndex modescount = CFArrayGetCount(modelist);
for (int i = 0; i < modescount; i++) {
CGDisplayModeRef othermode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modelist, i);
uint32_t otherioflags = CGDisplayModeGetIOFlags(othermode);
if (CFEqual(vidmode, othermode)) {
continue;
}
if (!HasValidDisplayModeFlags(othermode)) {
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);
/* 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.
*/
if (width == pixelW && height == pixelH
&& width == otherW && height == otherH
&& refreshrate == otherrefresh && format == otherformat
&& (otherpixelW != otherW || otherpixelH != otherH)) {
CFRelease(modes);
return SDL_FALSE;
}
/* Ignore this mode if it's interlaced and there's a non-interlaced
* mode in the list with the same properties.
*/
if (interlaced && ((otherioflags & kDisplayModeInterlacedFlag) == 0)
&& width == otherW && height == otherH && pixelW == otherpixelW
&& pixelH == otherpixelH && refreshrate == otherrefresh
&& format == otherformat && usableForGUI == otherGUI) {
CFRelease(modes);
return SDL_FALSE;
}
/* Ignore this mode if it's not usable for desktop UI and its
* properties are equal to another GUI-capable mode in the list.
*/
if (width == otherW && height == otherH && pixelW == otherpixelW
&& pixelH == otherpixelH && !usableForGUI && otherGUI
&& refreshrate == otherrefresh && format == otherformat) {
CFRelease(modes);
return SDL_FALSE;
}
/* If multiple modes have the exact same properties, they'll all
* go in the list of modes to try when SetDisplayMode is called.
* This is needed because kCGDisplayShowDuplicateLowResolutionModes
* (which is used to expose highdpi display modes) can make the
* list of modes contain duplicates (according to their properties
* obtained via public APIs) which don't work with SetDisplayMode.
* Those duplicate non-functional modes *do* have different pixel
* formats according to their internal data structure viewed with
* NSLog, but currently no public API can detect that.
* https://bugzilla.libsdl.org/show_bug.cgi?id=4822
*
* As of macOS 10.15.0, those duplicates have the exact same
* properties via public APIs in every way (even their IO flags and
* CGDisplayModeGetIODisplayModeID is the same), so we could test
* those for equality here too, but I'm intentionally not doing that
* in case there are duplicate modes with different IO flags or IO
* display mode IDs in the future. In that case I think it's better
* to try them all in SetDisplayMode than to risk one of them being
* correct but it being filtered out by SDL_AddDisplayMode as being
* a duplicate.
*/
if (width == otherW && height == otherH && pixelW == otherpixelW
&& pixelH == otherpixelH && usableForGUI == otherGUI
&& refreshrate == otherrefresh && format == otherformat) {
CFArrayAppendValue(modes, othermode);
}
}
}
#endif
data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
if (!data) {
CFRelease(modes);
return SDL_FALSE;
}
data->modes = modes;
mode->format = format;
mode->w = width;
mode->h = height;
mode->refresh_rate = refreshrate;
mode->driverdata = data;
return SDL_TRUE;
}
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);
CFDictionaryRef deviceInfo = IODisplayCreateInfoDictionary(servicePort, kIODisplayOnlyPreferredName);
NSDictionary *localizedNames = [(NSDictionary *)deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
const char* displayName = NULL;
if ([localizedNames count] > 0) {
displayName = SDL_strdup([[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] UTF8String]);
}
CFRelease(deviceInfo);
return displayName;
}
void
Cocoa_InitModes(_THIS)
{ @autoreleasepool
{
CGDisplayErr result;
CGDirectDisplayID *displays;
CGDisplayCount numDisplays;
SDL_bool isstack;
int pass, i;
result = CGGetOnlineDisplayList(0, NULL, &numDisplays);
if (result != kCGErrorSuccess) {
CG_SetError("CGGetOnlineDisplayList()", result);
return;
}
displays = SDL_small_alloc(CGDirectDisplayID, numDisplays, &isstack);
result = CGGetOnlineDisplayList(numDisplays, displays, &numDisplays);
if (result != kCGErrorSuccess) {
CG_SetError("CGGetOnlineDisplayList()", result);
SDL_small_free(displays, isstack);
return;
}
/* Pick up the primary display in the first pass, then get the rest */
for (pass = 0; pass < 2; ++pass) {
for (i = 0; i < numDisplays; ++i) {
SDL_VideoDisplay display;
SDL_DisplayData *displaydata;
SDL_DisplayMode mode;
CGDisplayModeRef moderef = NULL;
CVDisplayLinkRef link = NULL;
if (pass == 0) {
if (!CGDisplayIsMain(displays[i])) {
continue;
}
} else {
if (CGDisplayIsMain(displays[i])) {
continue;
}
}
if (CGDisplayMirrorsDisplay(displays[i]) != kCGNullDirectDisplay) {
continue;
}
moderef = CGDisplayCopyDisplayMode(displays[i]);
if (!moderef) {
continue;
}
displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
if (!displaydata) {
CGDisplayModeRelease(moderef);
continue;
}
displaydata->display = displays[i];
CVDisplayLinkCreateWithCGDisplay(displays[i], &link);
SDL_zero(display);
/* this returns a stddup'ed string */
display.name = (char *)Cocoa_GetDisplayName(displays[i]);
if (!GetDisplayMode(_this, moderef, NULL, link, &mode)) {
CVDisplayLinkRelease(link);
CGDisplayModeRelease(moderef);
SDL_free(display.name);
SDL_free(displaydata);
continue;
}
CVDisplayLinkRelease(link);
CGDisplayModeRelease(moderef);
display.desktop_mode = mode;
display.current_mode = mode;
display.driverdata = displaydata;
SDL_AddVideoDisplay(&display);
SDL_free(display.name);
}
}
SDL_small_free(displays, isstack);
}}
int
Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
{
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
CGRect cgrect;
cgrect = CGDisplayBounds(displaydata->display);
rect->x = (int)cgrect.origin.x;
rect->y = (int)cgrect.origin.y;
rect->w = (int)cgrect.size.width;
rect->h = (int)cgrect.size.height;
return 0;
}
int
Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
{
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
const CGDirectDisplayID cgdisplay = displaydata->display;
NSArray *screens = [NSScreen screens];
NSScreen *screen = nil;
/* !!! FIXME: maybe track the NSScreen in SDL_DisplayData? */
for (NSScreen *i in screens) {
const CGDirectDisplayID thisDisplay = (CGDirectDisplayID) [[[i deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
if (thisDisplay == cgdisplay) {
screen = i;
break;
}
}
SDL_assert(screen != nil); /* didn't find it?! */
if (screen == nil) {
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;
return 0;
}
int
Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
{ @autoreleasepool
{
const float MM_IN_INCH = 25.4f;
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
/* we need the backingScaleFactor for Retina displays, which is only exposed through NSScreen, not CGDisplay, afaik, so find our screen... */
CGFloat scaleFactor = 1.0f;
NSArray *screens = [NSScreen screens];
for (NSScreen *screen in screens) {
const CGDirectDisplayID dpyid = (const CGDirectDisplayID ) [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
if (dpyid == data->display) {
if ([screen respondsToSelector:@selector(backingScaleFactor)]) { // Mac OS X 10.7 and later
scaleFactor = [screen backingScaleFactor];
break;
}
}
}
const CGSize displaySize = CGDisplayScreenSize(data->display);
const int pixelWidth = (int) CGDisplayPixelsWide(data->display);
const int pixelHeight = (int) CGDisplayPixelsHigh(data->display);
if (ddpi) {
*ddpi = (SDL_ComputeDiagonalDPI(pixelWidth, pixelHeight, displaySize.width / MM_IN_INCH, displaySize.height / MM_IN_INCH)) * scaleFactor;
}
if (hdpi) {
*hdpi = (pixelWidth * MM_IN_INCH / displaySize.width) * scaleFactor;
}
if (vdpi) {
*vdpi = (pixelHeight * MM_IN_INCH / displaySize.height) * scaleFactor;
}
return 0;
}}
void
Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{
SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
CVDisplayLinkRef link = NULL;
CGDisplayModeRef desktopmoderef;
SDL_DisplayMode desktopmode;
CFArrayRef modes;
CFDictionaryRef dict = NULL;
CVDisplayLinkCreateWithCGDisplay(data->display, &link);
desktopmoderef = CGDisplayCopyDisplayMode(data->display);
/* CopyAllDisplayModes won't always contain the desktop display mode (if
* NULL is passed in) - for example on a retina 15" MBP, System Preferences
* allows choosing 1920x1200 but it's not in the list. AddDisplayMode makes
* sure there are no duplicates so it's safe to always add the desktop mode
* even in cases where it is in the CopyAllDisplayModes list.
*/
if (desktopmoderef && GetDisplayMode(_this, desktopmoderef, NULL, link, &desktopmode)) {
if (!SDL_AddDisplayMode(display, &desktopmode)) {
CFRelease(((SDL_DisplayModeData*)desktopmode.driverdata)->modes);
SDL_free(desktopmode.driverdata);
}
}
CGDisplayModeRelease(desktopmoderef);
/* By default, CGDisplayCopyAllDisplayModes will only get a subset of the
* system's available modes. For example on a 15" 2016 MBP, users can
* choose 1920x1080@2x in System Preferences but it won't show up here,
* unless we specify the option below.
* The display modes returned by CGDisplayCopyAllDisplayModes are also not
* high dpi-capable unless this option is set.
* macOS 10.15 also seems to have a bug where entering, exiting, and
* re-entering exclusive fullscreen with a low dpi display mode can cause
* the content of the screen to move up, which this setting avoids:
* https://bugzilla.libsdl.org/show_bug.cgi?id=4822
*/
#ifdef MAC_OS_X_VERSION_10_8
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_7) {
const CFStringRef dictkeys[] = {kCGDisplayShowDuplicateLowResolutionModes};
const CFBooleanRef dictvalues[] = {kCFBooleanTrue};
dict = CFDictionaryCreate(NULL,
(const void **)dictkeys,
(const void **)dictvalues,
1,
&kCFCopyStringDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
}
#endif
modes = CGDisplayCopyAllDisplayModes(data->display, dict);
if (dict) {
CFRelease(dict);
}
if (modes) {
CFIndex i;
const CFIndex count = CFArrayGetCount(modes);
for (i = 0; i < count; i++) {
CGDisplayModeRef moderef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
SDL_DisplayMode mode;
if (GetDisplayMode(_this, moderef, modes, link, &mode)) {
if (!SDL_AddDisplayMode(display, &mode)) {
CFRelease(((SDL_DisplayModeData*)mode.driverdata)->modes);
SDL_free(mode.driverdata);
}
}
}
CFRelease(modes);
}
CVDisplayLinkRelease(link);
}
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.
*/
CGError result = kCGErrorFailure;
for (CFIndex i = 0; i < CFArrayGetCount(data->modes); i++) {
CGDisplayModeRef moderef = (CGDisplayModeRef)CFArrayGetValueAtIndex(data->modes, i);
result = CGDisplaySetDisplayMode(display, moderef, NULL);
if (result == kCGErrorSuccess) {
/* If this mode works, try it first next time. */
CFArrayExchangeValuesAtIndices(data->modes, i, 0);
break;
}
}
return result;
}
int
Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
CGError result;
/* Fade to black to hide resolution-switching flicker */
if (CGAcquireDisplayFadeReservation(5, &fade_token) == kCGErrorSuccess) {
CGDisplayFade(fade_token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
}
if (data == display->desktop_mode.driverdata) {
/* Restoring desktop mode */
SetDisplayModeForDisplay(displaydata->display, data);
if (CGDisplayIsMain(displaydata->display)) {
CGReleaseAllDisplays();
} else {
CGDisplayRelease(displaydata->display);
}
if (CGDisplayIsMain(displaydata->display)) {
Cocoa_ToggleMenuBar(YES);
}
} else {
/* Put up the blanking window (a window above all other windows) */
if (CGDisplayIsMain(displaydata->display)) {
/* If we don't capture all displays, Cocoa tries to rearrange windows... *sigh* */
result = CGCaptureAllDisplays();
} else {
result = CGDisplayCapture(displaydata->display);
}
if (result != kCGErrorSuccess) {
CG_SetError("CGDisplayCapture()", result);
goto ERR_NO_CAPTURE;
}
/* Do the physical switch */
result = SetDisplayModeForDisplay(displaydata->display, data);
if (result != kCGErrorSuccess) {
CG_SetError("CGDisplaySwitchToMode()", result);
goto ERR_NO_SWITCH;
}
/* Hide the menu bar so it doesn't intercept events */
if (CGDisplayIsMain(displaydata->display)) {
Cocoa_ToggleMenuBar(NO);
}
}
/* Fade in again (asynchronously) */
if (fade_token != kCGDisplayFadeReservationInvalidToken) {
CGDisplayFade(fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
CGReleaseDisplayFadeReservation(fade_token);
}
return 0;
/* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
ERR_NO_SWITCH:
if (CGDisplayIsMain(displaydata->display)) {
CGReleaseAllDisplays();
} else {
CGDisplayRelease(displaydata->display);
}
ERR_NO_CAPTURE:
if (fade_token != kCGDisplayFadeReservationInvalidToken) {
CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
CGReleaseDisplayFadeReservation(fade_token);
}
return -1;
}
void
Cocoa_QuitModes(_THIS)
{
int i, j;
for (i = 0; i < _this->num_displays; ++i) {
SDL_VideoDisplay *display = &_this->displays[i];
SDL_DisplayModeData *mode;
if (display->current_mode.driverdata != display->desktop_mode.driverdata) {
Cocoa_SetDisplayMode(_this, display, &display->desktop_mode);
}
mode = (SDL_DisplayModeData *) display->desktop_mode.driverdata;
CFRelease(mode->modes);
for (j = 0; j < display->num_display_modes; j++) {
mode = (SDL_DisplayModeData*) display->display_modes[j].driverdata;
CFRelease(mode->modes);
}
}
Cocoa_ToggleMenuBar(YES);
}
#endif /* SDL_VIDEO_DRIVER_COCOA */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,52 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoamouse_h_
#define SDL_cocoamouse_h_
#include "SDL_cocoavideo.h"
extern int Cocoa_InitMouse(_THIS);
extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent * event);
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. */
SDL_bool seenWarp;
/* What location our last cursor warp was to. */
CGFloat lastWarpX;
CGFloat lastWarpY;
/* What location we last saw the cursor move to. */
CGFloat lastMoveX;
CGFloat lastMoveY;
void *tapdata;
} SDL_MouseData;
@interface NSCursor (InvisibleCursor)
+ (NSCursor *)invisibleCursor;
@end
#endif /* SDL_cocoamouse_h_ */
/* vi: set ts=4 sw=4 expandtab: */

481
externals/SDL/src/video/cocoa/SDL_cocoamouse.m vendored Executable file
View File

@@ -0,0 +1,481 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_COCOA
#include "SDL_assert.h"
#include "SDL_events.h"
#include "SDL_cocoamouse.h"
#include "SDL_cocoamousetap.h"
#include "SDL_cocoavideo.h"
#include "../../events/SDL_mouse_c.h"
/* #define DEBUG_COCOAMOUSE */
#ifdef DEBUG_COCOAMOUSE
#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
#else
#define DLog(...) do { } while (0)
#endif
@implementation NSCursor (InvisibleCursor)
+ (NSCursor *)invisibleCursor
{
static NSCursor *invisibleCursor = NULL;
if (!invisibleCursor) {
/* RAW 16x16 transparent GIF */
static unsigned char cursorBytes[] = {
0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04,
0x01, 0x00, 0x00, 0x01, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x10,
0x00, 0x10, 0x00, 0x00, 0x02, 0x0E, 0x8C, 0x8F, 0xA9, 0xCB, 0xED,
0x0F, 0xA3, 0x9C, 0xB4, 0xDA, 0x8B, 0xB3, 0x3E, 0x05, 0x00, 0x3B
};
NSData *cursorData = [NSData dataWithBytesNoCopy:&cursorBytes[0]
length:sizeof(cursorBytes)
freeWhenDone:NO];
NSImage *cursorImage = [[[NSImage alloc] initWithData:cursorData] autorelease];
invisibleCursor = [[NSCursor alloc] initWithImage:cursorImage
hotSpot:NSZeroPoint];
}
return invisibleCursor;
}
@end
static SDL_Cursor *
Cocoa_CreateDefaultCursor()
{ @autoreleasepool
{
NSCursor *nscursor;
SDL_Cursor *cursor = NULL;
nscursor = [NSCursor arrowCursor];
if (nscursor) {
cursor = SDL_calloc(1, sizeof(*cursor));
if (cursor) {
cursor->driverdata = nscursor;
[nscursor retain];
}
}
return cursor;
}}
static SDL_Cursor *
Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
{ @autoreleasepool
{
NSImage *nsimage;
NSCursor *nscursor = NULL;
SDL_Cursor *cursor = NULL;
nsimage = Cocoa_CreateImage(surface);
if (nsimage) {
nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
}
if (nscursor) {
cursor = SDL_calloc(1, sizeof(*cursor));
if (cursor) {
cursor->driverdata = nscursor;
} else {
[nscursor release];
}
}
return cursor;
}}
static SDL_Cursor *
Cocoa_CreateSystemCursor(SDL_SystemCursor id)
{ @autoreleasepool
{
NSCursor *nscursor = NULL;
SDL_Cursor *cursor = NULL;
switch(id) {
case SDL_SYSTEM_CURSOR_ARROW:
nscursor = [NSCursor arrowCursor];
break;
case SDL_SYSTEM_CURSOR_IBEAM:
nscursor = [NSCursor IBeamCursor];
break;
case SDL_SYSTEM_CURSOR_WAIT:
nscursor = [NSCursor arrowCursor];
break;
case SDL_SYSTEM_CURSOR_CROSSHAIR:
nscursor = [NSCursor crosshairCursor];
break;
case SDL_SYSTEM_CURSOR_WAITARROW:
nscursor = [NSCursor arrowCursor];
break;
case SDL_SYSTEM_CURSOR_SIZENWSE:
case SDL_SYSTEM_CURSOR_SIZENESW:
nscursor = [NSCursor closedHandCursor];
break;
case SDL_SYSTEM_CURSOR_SIZEWE:
nscursor = [NSCursor resizeLeftRightCursor];
break;
case SDL_SYSTEM_CURSOR_SIZENS:
nscursor = [NSCursor resizeUpDownCursor];
break;
case SDL_SYSTEM_CURSOR_SIZEALL:
nscursor = [NSCursor closedHandCursor];
break;
case SDL_SYSTEM_CURSOR_NO:
nscursor = [NSCursor operationNotAllowedCursor];
break;
case SDL_SYSTEM_CURSOR_HAND:
nscursor = [NSCursor pointingHandCursor];
break;
default:
SDL_assert(!"Unknown system cursor");
return NULL;
}
if (nscursor) {
cursor = SDL_calloc(1, sizeof(*cursor));
if (cursor) {
/* We'll free it later, so retain it here */
[nscursor retain];
cursor->driverdata = nscursor;
}
}
return cursor;
}}
static void
Cocoa_FreeCursor(SDL_Cursor * cursor)
{ @autoreleasepool
{
NSCursor *nscursor = (NSCursor *)cursor->driverdata;
[nscursor release];
SDL_free(cursor);
}}
static int
Cocoa_ShowCursor(SDL_Cursor * cursor)
{ @autoreleasepool
{
SDL_VideoDevice *device = SDL_GetVideoDevice();
SDL_Window *window = (device ? device->windows : NULL);
for (; window != NULL; window = window->next) {
SDL_WindowData *driverdata = (SDL_WindowData *)window->driverdata;
if (driverdata) {
[driverdata->nswindow performSelectorOnMainThread:@selector(invalidateCursorRectsForView:)
withObject:[driverdata->nswindow contentView]
waitUntilDone:NO];
}
}
return 0;
}}
static SDL_Window *
SDL_FindWindowAtPoint(const int x, const int y)
{
const SDL_Point pt = { x, y };
SDL_Window *i;
for (i = SDL_GetVideoDevice()->windows; i; i = i->next) {
const SDL_Rect r = { i->x, i->y, i->w, i->h };
if (SDL_PointInRect(&pt, &r)) {
return i;
}
}
return NULL;
}
static int
Cocoa_WarpMouseGlobal(int x, int y)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse->focus) {
SDL_WindowData *data = (SDL_WindowData *) mouse->focus->driverdata;
if ([data->listener isMoving]) {
DLog("Postponing warp, window being moved.");
[data->listener setPendingMoveX:x Y:y];
return 0;
}
}
const CGPoint point = CGPointMake((float)x, (float)y);
Cocoa_HandleMouseWarp(point.x, point.y);
CGWarpMouseCursorPosition(point);
/* CGWarpMouse causes a short delay by default, which is preventable by
* Calling this directly after. CGSetLocalEventsSuppressionInterval can also
* prevent it, but it's deprecated as of OS X 10.6.
*/
if (!mouse->relative_mode) {
CGAssociateMouseAndMouseCursorPosition(YES);
}
/* CGWarpMouseCursorPosition doesn't generate a window event, unlike our
* other implementations' APIs. Send what's appropriate.
*/
if (!mouse->relative_mode) {
SDL_Window *win = SDL_FindWindowAtPoint(x, y);
SDL_SetMouseFocus(win);
if (win) {
SDL_assert(win == mouse->focus);
SDL_SendMouseMotion(win, mouse->mouseID, 0, x - win->x, y - win->y);
}
}
return 0;
}
static void
Cocoa_WarpMouse(SDL_Window * window, int x, int y)
{
Cocoa_WarpMouseGlobal(x + window->x, y + window->y);
}
static int
Cocoa_SetRelativeMouseMode(SDL_bool enabled)
{
/* We will re-apply the relative mode when the window gets focus, if it
* doesn't have focus right now.
*/
SDL_Window *window = SDL_GetMouseFocus();
if (!window) {
return 0;
}
/* We will re-apply the relative mode when the window finishes being moved,
* if it is being moved right now.
*/
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if ([data->listener isMoving]) {
return 0;
}
CGError result;
if (enabled) {
DLog("Turning on.");
result = CGAssociateMouseAndMouseCursorPosition(NO);
} else {
DLog("Turning off.");
result = CGAssociateMouseAndMouseCursorPosition(YES);
}
if (result != kCGErrorSuccess) {
return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed");
}
/* The hide/unhide calls are redundant most of the time, but they fix
* https://bugzilla.libsdl.org/show_bug.cgi?id=2550
*/
if (enabled) {
[NSCursor hide];
} else {
[NSCursor unhide];
}
return 0;
}
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)
{
const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
const NSPoint cocoaLocation = [NSEvent mouseLocation];
Uint32 retval = 0;
*x = (int) cocoaLocation.x;
*y = (int) (CGDisplayPixelsHigh(kCGDirectMainDisplay) - cocoaLocation.y);
retval |= (cocoaButtons & (1 << 0)) ? SDL_BUTTON_LMASK : 0;
retval |= (cocoaButtons & (1 << 1)) ? SDL_BUTTON_RMASK : 0;
retval |= (cocoaButtons & (1 << 2)) ? SDL_BUTTON_MMASK : 0;
retval |= (cocoaButtons & (1 << 3)) ? SDL_BUTTON_X1MASK : 0;
retval |= (cocoaButtons & (1 << 4)) ? SDL_BUTTON_X2MASK : 0;
return retval;
}
int
Cocoa_InitMouse(_THIS)
{
SDL_Mouse *mouse = SDL_GetMouse();
SDL_MouseData *driverdata = (SDL_MouseData*) SDL_calloc(1, sizeof(SDL_MouseData));
if (driverdata == NULL) {
return SDL_OutOfMemory();
}
mouse->driverdata = driverdata;
mouse->CreateCursor = Cocoa_CreateCursor;
mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
mouse->ShowCursor = Cocoa_ShowCursor;
mouse->FreeCursor = Cocoa_FreeCursor;
mouse->WarpMouse = Cocoa_WarpMouse;
mouse->WarpMouseGlobal = Cocoa_WarpMouseGlobal;
mouse->SetRelativeMouseMode = Cocoa_SetRelativeMouseMode;
mouse->CaptureMouse = Cocoa_CaptureMouse;
mouse->GetGlobalMouseState = Cocoa_GetGlobalMouseState;
SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
Cocoa_InitMouseEventTap(driverdata);
const NSPoint location = [NSEvent mouseLocation];
driverdata->lastMoveX = location.x;
driverdata->lastMoveY = location.y;
return 0;
}
void
Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
{
switch ([event type]) {
case NSEventTypeMouseMoved:
case NSEventTypeLeftMouseDragged:
case NSEventTypeRightMouseDragged:
case NSEventTypeOtherMouseDragged:
break;
default:
/* Ignore any other events. */
return;
}
SDL_Mouse *mouse = SDL_GetMouse();
SDL_MouseData *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;
driverdata->seenWarp = NO;
const NSPoint location = [NSEvent mouseLocation];
const CGFloat lastMoveX = driverdata->lastMoveX;
const CGFloat lastMoveY = driverdata->lastMoveY;
driverdata->lastMoveX = location.x;
driverdata->lastMoveY = location.y;
DLog("Last seen mouse: (%g, %g)", location.x, location.y);
/* Non-relative movement is handled in -[Cocoa_WindowListener mouseMoved:] */
if (!mouse->relative_mode) {
return;
}
/* Ignore events that aren't inside the client area (i.e. title bar.) */
if ([event window]) {
NSRect windowRect = [[[event window] contentView] frame];
if (!NSMouseInRect([event locationInWindow], windowRect, NO)) {
return;
}
}
float deltaX = [event deltaX];
float deltaY = [event deltaY];
if (seenWarp) {
deltaX += (lastMoveX - driverdata->lastWarpX);
deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY);
DLog("Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY);
}
SDL_SendMouseMotion(mouse->focus, mouseID, 1, (int)deltaX, (int)deltaY);
}
void
Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
{
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;
if ([event respondsToSelector:@selector(isDirectionInvertedFromDevice)]) {
if ([event isDirectionInvertedFromDevice] == YES) {
direction = SDL_MOUSEWHEEL_FLIPPED;
}
}
if (x > 0) {
x = SDL_ceil(x);
} else if (x < 0) {
x = SDL_floor(x);
}
if (y > 0) {
y = SDL_ceil(y);
} else if (y < 0) {
y = SDL_floor(y);
}
SDL_SendMouseWheel(window, mouseID, x, y, direction);
}
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.
*/
SDL_MouseData *driverdata = (SDL_MouseData*)SDL_GetMouse()->driverdata;
driverdata->lastWarpX = x;
driverdata->lastWarpY = y;
driverdata->seenWarp = SDL_TRUE;
DLog("(%g, %g)", x, y);
}
void
Cocoa_QuitMouse(_THIS)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse) {
if (mouse->driverdata) {
Cocoa_QuitMouseEventTap(((SDL_MouseData*)mouse->driverdata));
SDL_free(mouse->driverdata);
mouse->driverdata = NULL;
}
}
}
#endif /* SDL_VIDEO_DRIVER_COCOA */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,34 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoamousetap_h_
#define SDL_cocoamousetap_h_
#include "SDL_cocoamouse.h"
extern void Cocoa_InitMouseEventTap(SDL_MouseData *driverdata);
extern void Cocoa_EnableMouseEventTap(SDL_MouseData *driverdata, SDL_bool enabled);
extern void Cocoa_QuitMouseEventTap(SDL_MouseData *driverdata);
#endif /* SDL_cocoamousetap_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,286 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_COCOA
#include "SDL_cocoamousetap.h"
/* Event taps are forbidden in the Mac App Store, so we can only enable this
* code if your app doesn't need to ship through the app store.
* This code makes it so that a grabbed cursor cannot "leak" a mouse click
* past the edge of the window if moving the cursor too fast.
*/
#if SDL_MAC_NO_SANDBOX
#include "SDL_keyboard.h"
#include "SDL_cocoavideo.h"
#include "../../thread/SDL_systhread.h"
#include "../../events/SDL_mouse_c.h"
typedef struct {
CFMachPortRef tap;
CFRunLoopRef runloop;
CFRunLoopSourceRef runloopSource;
SDL_Thread *thread;
SDL_sem *runloopStartedSemaphore;
} SDL_MouseEventTapData;
static const CGEventMask movementEventsMask =
CGEventMaskBit(kCGEventLeftMouseDragged)
| CGEventMaskBit(kCGEventRightMouseDragged)
| CGEventMaskBit(kCGEventMouseMoved);
static const CGEventMask allGrabbedEventsMask =
CGEventMaskBit(kCGEventLeftMouseDown) | CGEventMaskBit(kCGEventLeftMouseUp)
| CGEventMaskBit(kCGEventRightMouseDown) | CGEventMaskBit(kCGEventRightMouseUp)
| CGEventMaskBit(kCGEventOtherMouseDown) | CGEventMaskBit(kCGEventOtherMouseUp)
| CGEventMaskBit(kCGEventLeftMouseDragged) | CGEventMaskBit(kCGEventRightMouseDragged)
| CGEventMaskBit(kCGEventMouseMoved);
static CGEventRef
Cocoa_MouseTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
{
SDL_MouseEventTapData *tapdata = (SDL_MouseEventTapData*)refcon;
SDL_Mouse *mouse = SDL_GetMouse();
SDL_Window *window = SDL_GetKeyboardFocus();
NSWindow *nswindow;
NSRect windowRect;
CGPoint eventLocation;
switch (type) {
case kCGEventTapDisabledByTimeout:
{
CGEventTapEnable(tapdata->tap, true);
return NULL;
}
case kCGEventTapDisabledByUserInput:
{
return NULL;
}
default:
break;
}
if (!window || !mouse) {
return event;
}
if (mouse->relative_mode) {
return event;
}
if (!(window->flags & SDL_WINDOW_INPUT_GRABBED)) {
return event;
}
/* This is the same coordinate system as Cocoa uses. */
nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
eventLocation = CGEventGetUnflippedLocation(event);
windowRect = [nswindow contentRectForFrameRect:[nswindow frame]];
if (!NSMouseInRect(NSPointFromCGPoint(eventLocation), windowRect, NO)) {
/* This is in CGs global screenspace coordinate system, which has a
* flipped Y.
*/
CGPoint newLocation = CGEventGetLocation(event);
if (eventLocation.x < NSMinX(windowRect)) {
newLocation.x = NSMinX(windowRect);
} else if (eventLocation.x >= NSMaxX(windowRect)) {
newLocation.x = NSMaxX(windowRect) - 1.0;
}
if (eventLocation.y <= NSMinY(windowRect)) {
newLocation.y -= (NSMinY(windowRect) - eventLocation.y + 1);
} else if (eventLocation.y > NSMaxY(windowRect)) {
newLocation.y += (eventLocation.y - NSMaxY(windowRect));
}
CGWarpMouseCursorPosition(newLocation);
CGAssociateMouseAndMouseCursorPosition(YES);
if ((CGEventMaskBit(type) & movementEventsMask) == 0) {
/* For click events, we just constrain the event to the window, so
* no other app receives the click event. We can't due the same to
* movement events, since they mean that our warp cursor above
* behaves strangely.
*/
CGEventSetLocation(event, newLocation);
}
}
return event;
}
static void
SemaphorePostCallback(CFRunLoopTimerRef timer, void *info)
{
SDL_SemPost((SDL_sem*)info);
}
static int
Cocoa_MouseTapThread(void *data)
{
SDL_MouseEventTapData *tapdata = (SDL_MouseEventTapData*)data;
/* Tap was created on main thread but we own it now. */
CFMachPortRef eventTap = tapdata->tap;
if (eventTap) {
/* Try to create a runloop source we can schedule. */
CFRunLoopSourceRef runloopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
if (runloopSource) {
tapdata->runloopSource = runloopSource;
} else {
CFRelease(eventTap);
SDL_SemPost(tapdata->runloopStartedSemaphore);
/* TODO: Both here and in the return below, set some state in
* tapdata to indicate that initialization failed, which we should
* check in InitMouseEventTap, after we move the semaphore check
* from Quit to Init.
*/
return 1;
}
} else {
SDL_SemPost(tapdata->runloopStartedSemaphore);
return 1;
}
tapdata->runloop = CFRunLoopGetCurrent();
CFRunLoopAddSource(tapdata->runloop, tapdata->runloopSource, kCFRunLoopCommonModes);
CFRunLoopTimerContext context = {.info = tapdata->runloopStartedSemaphore};
/* We signal the runloop started semaphore *after* the run loop has started, indicating it's safe to CFRunLoopStop it. */
CFRunLoopTimerRef timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent(), 0, 0, 0, &SemaphorePostCallback, &context);
CFRunLoopAddTimer(tapdata->runloop, timer, kCFRunLoopCommonModes);
CFRelease(timer);
/* Run the event loop to handle events in the event tap. */
CFRunLoopRun();
/* Make sure this is signaled so that SDL_QuitMouseEventTap knows it can safely SDL_WaitThread for us. */
if (SDL_SemValue(tapdata->runloopStartedSemaphore) < 1) {
SDL_SemPost(tapdata->runloopStartedSemaphore);
}
CFRunLoopRemoveSource(tapdata->runloop, tapdata->runloopSource, kCFRunLoopCommonModes);
/* Clean up. */
CGEventTapEnable(tapdata->tap, false);
CFRelease(tapdata->runloopSource);
CFRelease(tapdata->tap);
tapdata->runloopSource = NULL;
tapdata->tap = NULL;
return 0;
}
void
Cocoa_InitMouseEventTap(SDL_MouseData* driverdata)
{
SDL_MouseEventTapData *tapdata;
driverdata->tapdata = SDL_calloc(1, sizeof(SDL_MouseEventTapData));
tapdata = (SDL_MouseEventTapData*)driverdata->tapdata;
tapdata->runloopStartedSemaphore = SDL_CreateSemaphore(0);
if (tapdata->runloopStartedSemaphore) {
tapdata->tap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap,
kCGEventTapOptionDefault, allGrabbedEventsMask,
&Cocoa_MouseTapCallback, tapdata);
if (tapdata->tap) {
/* Tap starts disabled, until app requests mouse grab */
CGEventTapEnable(tapdata->tap, false);
tapdata->thread = SDL_CreateThreadInternal(&Cocoa_MouseTapThread, "Event Tap Loop", 512 * 1024, tapdata);
if (tapdata->thread) {
/* Success - early out. Ownership transferred to thread. */
return;
}
CFRelease(tapdata->tap);
}
SDL_DestroySemaphore(tapdata->runloopStartedSemaphore);
}
SDL_free(driverdata->tapdata);
driverdata->tapdata = NULL;
}
void
Cocoa_EnableMouseEventTap(SDL_MouseData *driverdata, SDL_bool enabled)
{
SDL_MouseEventTapData *tapdata = (SDL_MouseEventTapData*)driverdata->tapdata;
if (tapdata && tapdata->tap)
{
CGEventTapEnable(tapdata->tap, !!enabled);
}
}
void
Cocoa_QuitMouseEventTap(SDL_MouseData *driverdata)
{
SDL_MouseEventTapData *tapdata = (SDL_MouseEventTapData*)driverdata->tapdata;
int status;
if (tapdata == NULL) {
/* event tap was already cleaned up (possibly due to CGEventTapCreate
* returning null.)
*/
return;
}
/* Ensure that the runloop has been started first.
* TODO: Move this to InitMouseEventTap, check for error conditions that can
* happen in Cocoa_MouseTapThread, and fall back to the non-EventTap way of
* grabbing the mouse if it fails to Init.
*/
status = SDL_SemWaitTimeout(tapdata->runloopStartedSemaphore, 5000);
if (status > -1) {
/* Then stop it, which will cause Cocoa_MouseTapThread to return. */
CFRunLoopStop(tapdata->runloop);
/* And then wait for Cocoa_MouseTapThread to finish cleaning up. It
* releases some of the pointers in tapdata. */
SDL_WaitThread(tapdata->thread, &status);
}
SDL_free(driverdata->tapdata);
driverdata->tapdata = NULL;
}
#else /* SDL_MAC_NO_SANDBOX */
void
Cocoa_InitMouseEventTap(SDL_MouseData *unused)
{
}
void
Cocoa_EnableMouseEventTap(SDL_MouseData *driverdata, SDL_bool enabled)
{
}
void
Cocoa_QuitMouseEventTap(SDL_MouseData *driverdata)
{
}
#endif /* !SDL_MAC_NO_SANDBOX */
#endif /* SDL_VIDEO_DRIVER_COCOA */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,77 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoaopengl_h_
#define SDL_cocoaopengl_h_
#if SDL_VIDEO_OPENGL_CGL
#include "SDL_atomic.h"
#import <Cocoa/Cocoa.h>
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
struct SDL_GLDriverData
{
int initialized;
};
@interface SDLOpenGLContext : NSOpenGLContext {
SDL_atomic_t dirty;
SDL_Window *window;
}
- (id)initWithFormat:(NSOpenGLPixelFormat *)format
shareContext:(NSOpenGLContext *)share;
- (void)scheduleUpdate;
- (void)updateIfNeeded;
- (void)setWindow:(SDL_Window *)window;
@end
/* OpenGL functions */
extern int Cocoa_GL_LoadLibrary(_THIS, const char *path);
extern void *Cocoa_GL_GetProcAddress(_THIS, const char *proc);
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);
extern void Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif /* SDL_VIDEO_OPENGL_CGL */
#endif /* SDL_cocoaopengl_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,459 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
/* NSOpenGL implementation of SDL OpenGL support */
#if SDL_VIDEO_OPENGL_CGL
#include "SDL_cocoavideo.h"
#include "SDL_cocoaopengl.h"
#include "SDL_cocoaopengles.h"
#include <OpenGL/CGLTypes.h>
#include <OpenGL/OpenGL.h>
#include <OpenGL/CGLRenderers.h>
#include "SDL_loadso.h"
#include "SDL_opengl.h"
#define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
@implementation SDLOpenGLContext : NSOpenGLContext
- (id)initWithFormat:(NSOpenGLPixelFormat *)format
shareContext:(NSOpenGLContext *)share
{
self = [super initWithFormat:format shareContext:share];
if (self) {
SDL_AtomicSet(&self->dirty, 0);
self->window = NULL;
}
return self;
}
- (void)scheduleUpdate
{
SDL_AtomicAdd(&self->dirty, 1);
}
/* This should only be called on the thread on which a user is using the context. */
- (void)updateIfNeeded
{
int value = SDL_AtomicSet(&self->dirty, 0);
if (value > 0) {
/* We call the real underlying update here, since -[SDLOpenGLContext update] just calls us. */
[super update];
}
}
/* This should only be called on the thread on which a user is using the context. */
- (void)update
{
/* This ensures that regular 'update' calls clear the atomic dirty flag. */
[self scheduleUpdate];
[self updateIfNeeded];
}
/* Updates the drawable for the contexts and manages related state. */
- (void)setWindow:(SDL_Window *)newWindow
{
if (self->window) {
SDL_WindowData *oldwindowdata = (SDL_WindowData *)self->window->driverdata;
/* Make sure to remove us from the old window's context list, or we'll get scheduled updates from it too. */
NSMutableArray *contexts = oldwindowdata->nscontexts;
@synchronized (contexts) {
[contexts removeObject:self];
}
}
self->window = newWindow;
if (newWindow) {
SDL_WindowData *windowdata = (SDL_WindowData *)newWindow->driverdata;
NSView *contentview = windowdata->sdlContentView;
/* This should never be nil since sdlContentView is only nil if the
window was created via SDL_CreateWindowFrom, and SDL doesn't allow
OpenGL contexts to be created in that case. However, it doesn't hurt
to check. */
if (contentview == nil) {
/* Prefer to access the cached content view above instead of this,
since as of Xcode 11 + SDK 10.15, [window contentView] causes
Apple's Main Thread Checker to output a warning. */
contentview = [windowdata->nswindow contentView];
}
/* Now sign up for scheduled updates for the new window. */
NSMutableArray *contexts = windowdata->nscontexts;
@synchronized (contexts) {
[contexts addObject:self];
}
if ([self view] != contentview) {
[self setView:contentview];
if (self == [NSOpenGLContext currentContext]) {
[self update];
} else {
[self scheduleUpdate];
}
}
} else {
[self clearDrawable];
if (self == [NSOpenGLContext currentContext]) {
[self update];
} else {
[self scheduleUpdate];
}
}
}
@end
int
Cocoa_GL_LoadLibrary(_THIS, const char *path)
{
/* Load the OpenGL library */
if (path == NULL) {
path = SDL_getenv("SDL_OPENGL_LIBRARY");
}
if (path == NULL) {
path = DEFAULT_OPENGL;
}
_this->gl_config.dll_handle = SDL_LoadObject(path);
if (!_this->gl_config.dll_handle) {
return -1;
}
SDL_strlcpy(_this->gl_config.driver_path, path,
SDL_arraysize(_this->gl_config.driver_path));
return 0;
}
void *
Cocoa_GL_GetProcAddress(_THIS, const char *proc)
{
return SDL_LoadFunction(_this->gl_config.dll_handle, proc);
}
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)
{ @autoreleasepool
{
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
SDL_bool lion_or_later = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
NSOpenGLPixelFormatAttribute attr[32];
NSOpenGLPixelFormat *fmt;
SDLOpenGLContext *context;
NSOpenGLContext *share_context = nil;
int i = 0;
const char *glversion;
int glversion_major;
int glversion_minor;
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
#if SDL_VIDEO_OPENGL_EGL
/* Switch to EGL based functions */
Cocoa_GL_UnloadLibrary(_this);
_this->GL_LoadLibrary = Cocoa_GLES_LoadLibrary;
_this->GL_GetProcAddress = Cocoa_GLES_GetProcAddress;
_this->GL_UnloadLibrary = Cocoa_GLES_UnloadLibrary;
_this->GL_CreateContext = Cocoa_GLES_CreateContext;
_this->GL_MakeCurrent = Cocoa_GLES_MakeCurrent;
_this->GL_SetSwapInterval = Cocoa_GLES_SetSwapInterval;
_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;
}
return Cocoa_GLES_CreateContext(_this, window);
#else
SDL_SetError("SDL not configured with EGL support");
return NULL;
#endif
}
if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) && !lion_or_later) {
SDL_SetError ("OpenGL Core Profile is not supported on this platform version");
return NULL;
}
attr[i++] = NSOpenGLPFAAllowOfflineRenderers;
/* specify a profile if we're on Lion (10.7) or later. */
if (lion_or_later) {
NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
profile = NSOpenGLProfileVersion3_2Core;
}
attr[i++] = NSOpenGLPFAOpenGLProfile;
attr[i++] = profile;
}
attr[i++] = NSOpenGLPFAColorSize;
attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
attr[i++] = NSOpenGLPFADepthSize;
attr[i++] = _this->gl_config.depth_size;
if (_this->gl_config.double_buffer) {
attr[i++] = NSOpenGLPFADoubleBuffer;
}
if (_this->gl_config.stereo) {
attr[i++] = NSOpenGLPFAStereo;
}
if (_this->gl_config.stencil_size) {
attr[i++] = NSOpenGLPFAStencilSize;
attr[i++] = _this->gl_config.stencil_size;
}
if ((_this->gl_config.accum_red_size +
_this->gl_config.accum_green_size +
_this->gl_config.accum_blue_size +
_this->gl_config.accum_alpha_size) > 0) {
attr[i++] = NSOpenGLPFAAccumSize;
attr[i++] = _this->gl_config.accum_red_size + _this->gl_config.accum_green_size + _this->gl_config.accum_blue_size + _this->gl_config.accum_alpha_size;
}
if (_this->gl_config.multisamplebuffers) {
attr[i++] = NSOpenGLPFASampleBuffers;
attr[i++] = _this->gl_config.multisamplebuffers;
}
if (_this->gl_config.multisamplesamples) {
attr[i++] = NSOpenGLPFASamples;
attr[i++] = _this->gl_config.multisamplesamples;
attr[i++] = NSOpenGLPFANoRecovery;
}
if (_this->gl_config.accelerated >= 0) {
if (_this->gl_config.accelerated) {
attr[i++] = NSOpenGLPFAAccelerated;
} else {
attr[i++] = NSOpenGLPFARendererID;
attr[i++] = kCGLRendererGenericFloatID;
}
}
attr[i++] = NSOpenGLPFAScreenMask;
attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
attr[i] = 0;
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
if (fmt == nil) {
SDL_SetError("Failed creating OpenGL pixel format");
return NULL;
}
if (_this->gl_config.share_with_current_context) {
share_context = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
}
context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context];
[fmt release];
if (context == nil) {
SDL_SetError("Failed creating OpenGL context");
return NULL;
}
if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
Cocoa_GL_DeleteContext(_this, context);
SDL_SetError("Failed making OpenGL context current");
return NULL;
}
if (_this->gl_config.major_version < 3 &&
_this->gl_config.profile_mask == 0 &&
_this->gl_config.flags == 0) {
/* This is a legacy profile, so to match other backends, we're done. */
} else {
const GLubyte *(APIENTRY * glGetStringFunc)(GLenum);
glGetStringFunc = (const GLubyte *(APIENTRY *)(GLenum)) SDL_GL_GetProcAddress("glGetString");
if (!glGetStringFunc) {
Cocoa_GL_DeleteContext(_this, context);
SDL_SetError ("Failed getting OpenGL glGetString entry point");
return NULL;
}
glversion = (const char *)glGetStringFunc(GL_VERSION);
if (glversion == NULL) {
Cocoa_GL_DeleteContext(_this, context);
SDL_SetError ("Failed getting OpenGL context version");
return NULL;
}
if (SDL_sscanf(glversion, "%d.%d", &glversion_major, &glversion_minor) != 2) {
Cocoa_GL_DeleteContext(_this, context);
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, context);
SDL_SetError ("Failed creating OpenGL context at version requested");
return NULL;
}
/* In the future we'll want to do this, but to match other platforms
we'll leave the OpenGL version the way it is for now
*/
/*_this->gl_config.major_version = glversion_major;*/
/*_this->gl_config.minor_version = glversion_minor;*/
}
return context;
}}
int
Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{ @autoreleasepool
{
if (context) {
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
[nscontext setWindow:window];
[nscontext updateIfNeeded];
[nscontext makeCurrentContext];
} else {
[NSOpenGLContext clearCurrentContext];
}
return 0;
}}
void
Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
{
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
NSView *contentView = [windata->nswindow contentView];
NSRect viewport = [contentView bounds];
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
/* This gives us the correct viewport for a Retina-enabled view, only
* supported on 10.7+. */
if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) {
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;
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 = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
if (nscontext != nil) {
value = interval;
[nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
status = 0;
} else {
status = SDL_SetError("No current OpenGL context");
}
return status;
}}
int
Cocoa_GL_GetSwapInterval(_THIS)
{ @autoreleasepool
{
NSOpenGLContext *nscontext;
GLint value;
int status = 0;
nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
if (nscontext != nil) {
[nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
status = (int)value;
}
return status;
}}
int
Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
{ @autoreleasepool
{
SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext();
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
/* 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. */
SDL_LockMutex(videodata->swaplock);
[nscontext flushBuffer];
[nscontext updateIfNeeded];
SDL_UnlockMutex(videodata->swaplock);
return 0;
}}
void
Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
{ @autoreleasepool
{
SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
[nscontext setWindow:NULL];
[nscontext release];
}}
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif /* SDL_VIDEO_OPENGL_CGL */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,49 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoaopengles_h_
#define SDL_cocoaopengles_h_
#if SDL_VIDEO_OPENGL_EGL
#include "../SDL_sysvideo.h"
#include "../SDL_egl_c.h"
/* OpenGLES functions */
#define Cocoa_GLES_GetAttribute SDL_EGL_GetAttribute
#define Cocoa_GLES_GetProcAddress SDL_EGL_GetProcAddress
#define Cocoa_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
#define Cocoa_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
#define Cocoa_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
extern int Cocoa_GLES_LoadLibrary(_THIS, const char *path);
extern SDL_GLContext Cocoa_GLES_CreateContext(_THIS, SDL_Window * window);
extern int Cocoa_GLES_SwapWindow(_THIS, SDL_Window * window);
extern int Cocoa_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
extern void Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context);
extern int Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window);
#endif /* SDL_VIDEO_OPENGL_EGL */
#endif /* SDL_cocoaopengles_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,132 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_COCOA && SDL_VIDEO_OPENGL_EGL
#include "SDL_cocoavideo.h"
#include "SDL_cocoaopengles.h"
#include "SDL_cocoaopengl.h"
#include "SDL_log.h"
/* EGL implementation of SDL OpenGL support */
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) {
#if SDL_VIDEO_OPENGL_CGL
Cocoa_GLES_UnloadLibrary(_this);
_this->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
_this->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
_this->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary;
_this->GL_CreateContext = Cocoa_GL_CreateContext;
_this->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
_this->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
_this->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
_this->GL_SwapWindow = Cocoa_GL_SwapWindow;
_this->GL_DeleteContext = Cocoa_GL_DeleteContext;
return Cocoa_GL_LoadLibrary(_this, path);
#else
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);
}
return 0;
}
SDL_GLContext
Cocoa_GLES_CreateContext(_THIS, SDL_Window * window)
{
SDL_GLContext context;
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
#if SDL_VIDEO_OPENGL_CGL
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
/* Switch to CGL based functions */
Cocoa_GLES_UnloadLibrary(_this);
_this->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
_this->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
_this->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary;
_this->GL_CreateContext = Cocoa_GL_CreateContext;
_this->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
_this->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
_this->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
_this->GL_SwapWindow = Cocoa_GL_SwapWindow;
_this->GL_DeleteContext = Cocoa_GL_DeleteContext;
if (Cocoa_GL_LoadLibrary(_this, NULL) != 0) {
return NULL;
}
return Cocoa_GL_CreateContext(_this, window);
}
#endif
context = SDL_EGL_CreateContext(_this, data->egl_surface);
return context;
}
void
Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context)
{
SDL_EGL_DeleteContext(_this, context);
Cocoa_GLES_UnloadLibrary(_this);
}
SDL_EGL_SwapWindow_impl(Cocoa)
SDL_EGL_MakeCurrent_impl(Cocoa)
int
Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
{
/* The current context is lost in here; save it and reset it. */
SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
SDL_Window *current_win = SDL_GL_GetCurrentWindow();
SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
if (_this->egl_data == NULL) {
if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0) < 0) {
SDL_EGL_UnloadLibrary(_this);
return -1;
}
}
/* Create the GLES window surface */
NSView* v = windowdata->nswindow.contentView;
windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)[v layer]);
if (windowdata->egl_surface == EGL_NO_SURFACE) {
return SDL_SetError("Could not create GLES window surface");
}
return Cocoa_GLES_MakeCurrent(_this, current_win, current_ctx);
}
#endif /* SDL_VIDEO_DRIVER_COCOA && SDL_VIDEO_OPENGL_EGL */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,45 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoashape_h_
#define SDL_cocoashape_h_
#include "SDL_stdinc.h"
#include "SDL_video.h"
#include "SDL_shape.h"
#include "../SDL_shape_internals.h"
typedef struct {
NSGraphicsContext* context;
SDL_bool saved;
SDL_ShapeTree* shape;
} SDL_ShapeData;
extern SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window);
extern int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
extern int Cocoa_ResizeWindowShape(SDL_Window *window);
#endif /* SDL_cocoashape_h_ */
/* vi: set ts=4 sw=4 expandtab: */

113
externals/SDL/src/video/cocoa/SDL_cocoashape.m vendored Executable file
View File

@@ -0,0 +1,113 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_COCOA
#include "SDL_cocoavideo.h"
#include "SDL_shape.h"
#include "SDL_cocoashape.h"
#include "../SDL_sysvideo.h"
#include "SDL_assert.h"
SDL_WindowShaper*
Cocoa_CreateShaper(SDL_Window* window)
{
SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
[windata->nswindow setOpaque:NO];
[windata->nswindow setStyleMask:NSWindowStyleMaskBorderless];
SDL_WindowShaper* result = result = 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 = malloc(sizeof(SDL_ShapeData));
result->driverdata = data;
data->context = [windata->nswindow graphicsContext];
data->saved = SDL_FALSE;
data->shape = NULL;
int 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)
{
SDL_CocoaClosure* data = (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]];
}
}
int
Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
{ @autoreleasepool
{
SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
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];
[[NSColor clearColor] set];
NSRectFill([[windata->nswindow contentView] frame]);
data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
closure.view = [windata->nswindow contentView];
closure.path = [NSBezierPath bezierPath];
closure.window = shaper->window;
SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
[closure.path addClip];
return 0;
}}
int
Cocoa_ResizeWindowShape(SDL_Window *window)
{
SDL_ShapeData* data = window->shaper->driverdata;
SDL_assert(data != NULL);
return 0;
}
#endif /* SDL_VIDEO_DRIVER_COCOA */
/* vi: set ts=4 sw=4 expandtab: */

123
externals/SDL/src/video/cocoa/SDL_cocoavideo.h vendored Executable file
View File

@@ -0,0 +1,123 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoavideo_h_
#define SDL_cocoavideo_h_
#include "SDL_opengl.h"
#include <ApplicationServices/ApplicationServices.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <Cocoa/Cocoa.h>
#include "SDL_keycode.h"
#include "../SDL_sysvideo.h"
#include "SDL_cocoaclipboard.h"
#include "SDL_cocoaevents.h"
#include "SDL_cocoakeyboard.h"
#include "SDL_cocoamodes.h"
#include "SDL_cocoamouse.h"
#include "SDL_cocoaopengl.h"
#include "SDL_cocoawindow.h"
#ifndef MAC_OS_X_VERSION_10_12
#define DECLARE_EVENT(name) static const NSEventType NSEventType##name = NS##name
DECLARE_EVENT(LeftMouseDown);
DECLARE_EVENT(LeftMouseUp);
DECLARE_EVENT(RightMouseDown);
DECLARE_EVENT(RightMouseUp);
DECLARE_EVENT(OtherMouseDown);
DECLARE_EVENT(OtherMouseUp);
DECLARE_EVENT(MouseMoved);
DECLARE_EVENT(LeftMouseDragged);
DECLARE_EVENT(RightMouseDragged);
DECLARE_EVENT(OtherMouseDragged);
DECLARE_EVENT(ScrollWheel);
DECLARE_EVENT(KeyDown);
DECLARE_EVENT(KeyUp);
DECLARE_EVENT(FlagsChanged);
#undef DECLARE_EVENT
static const NSEventMask NSEventMaskAny = NSAnyEventMask;
#define DECLARE_MODIFIER_FLAG(name) static const NSUInteger NSEventModifierFlag##name = NS##name##KeyMask
DECLARE_MODIFIER_FLAG(Shift);
DECLARE_MODIFIER_FLAG(Control);
DECLARE_MODIFIER_FLAG(Command);
DECLARE_MODIFIER_FLAG(NumericPad);
DECLARE_MODIFIER_FLAG(Help);
DECLARE_MODIFIER_FLAG(Function);
#undef DECLARE_MODIFIER_FLAG
static const NSUInteger NSEventModifierFlagCapsLock = NSAlphaShiftKeyMask;
static const NSUInteger NSEventModifierFlagOption = NSAlternateKeyMask;
#define DECLARE_WINDOW_MASK(name) static const unsigned int NSWindowStyleMask##name = NS##name##WindowMask
DECLARE_WINDOW_MASK(Borderless);
DECLARE_WINDOW_MASK(Titled);
DECLARE_WINDOW_MASK(Closable);
DECLARE_WINDOW_MASK(Miniaturizable);
DECLARE_WINDOW_MASK(Resizable);
DECLARE_WINDOW_MASK(TexturedBackground);
DECLARE_WINDOW_MASK(UnifiedTitleAndToolbar);
DECLARE_WINDOW_MASK(FullScreen);
/*DECLARE_WINDOW_MASK(FullSizeContentView);*/ /* Not used, fails compile on older SDKs */
static const unsigned int NSWindowStyleMaskUtilityWindow = NSUtilityWindowMask;
static const unsigned int NSWindowStyleMaskDocModalWindow = NSDocModalWindowMask;
static const unsigned int NSWindowStyleMaskHUDWindow = NSHUDWindowMask;
#undef DECLARE_WINDOW_MASK
#define DECLARE_ALERT_STYLE(name) static const NSUInteger NSAlertStyle##name = NS##name##AlertStyle
DECLARE_ALERT_STYLE(Warning);
DECLARE_ALERT_STYLE(Informational);
DECLARE_ALERT_STYLE(Critical);
#undef DECLARE_ALERT_STYLE
#endif
/* Private display data */
@class SDLTranslatorResponder;
typedef struct SDL_VideoData
{
int allow_spaces;
unsigned int modifierFlags;
void *key_layout;
SDLTranslatorResponder *fieldEdit;
NSInteger clipboard_count;
Uint32 screensaver_activity;
BOOL screensaver_use_iopm;
IOPMAssertionID screensaver_assertion;
SDL_mutex *swaplock;
} SDL_VideoData;
/* Utility functions */
extern NSImage * Cocoa_CreateImage(SDL_Surface * surface);
/* Fix build with the 10.11 SDK */
#if MAC_OS_X_VERSION_MAX_ALLOWED < 101200
#define NSEventSubtypeMouseEvent NSMouseEventSubtype
#endif
#endif /* SDL_cocoavideo_h_ */
/* vi: set ts=4 sw=4 expandtab: */

273
externals/SDL/src/video/cocoa/SDL_cocoavideo.m vendored Executable file
View File

@@ -0,0 +1,273 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_COCOA
#include "SDL.h"
#include "SDL_endian.h"
#include "SDL_cocoavideo.h"
#include "SDL_cocoashape.h"
#include "SDL_cocoavulkan.h"
#include "SDL_cocoametalview.h"
#include "SDL_assert.h"
/* Initialization/Query functions */
static int Cocoa_VideoInit(_THIS);
static void Cocoa_VideoQuit(_THIS);
/* Cocoa driver bootstrap functions */
static int
Cocoa_Available(void)
{
return (1);
}
static void
Cocoa_DeleteDevice(SDL_VideoDevice * device)
{
SDL_free(device->driverdata);
SDL_free(device);
}
static SDL_VideoDevice *
Cocoa_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
SDL_VideoData *data;
Cocoa_RegisterApp();
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (device) {
data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
} else {
data = NULL;
}
if (!data) {
SDL_OutOfMemory();
SDL_free(device);
return NULL;
}
device->driverdata = data;
/* Set the function pointers */
device->VideoInit = Cocoa_VideoInit;
device->VideoQuit = Cocoa_VideoQuit;
device->GetDisplayBounds = Cocoa_GetDisplayBounds;
device->GetDisplayUsableBounds = Cocoa_GetDisplayUsableBounds;
device->GetDisplayDPI = Cocoa_GetDisplayDPI;
device->GetDisplayModes = Cocoa_GetDisplayModes;
device->SetDisplayMode = Cocoa_SetDisplayMode;
device->PumpEvents = Cocoa_PumpEvents;
device->SuspendScreenSaver = Cocoa_SuspendScreenSaver;
device->CreateSDLWindow = Cocoa_CreateWindow;
device->CreateSDLWindowFrom = Cocoa_CreateWindowFrom;
device->SetWindowTitle = Cocoa_SetWindowTitle;
device->SetWindowIcon = Cocoa_SetWindowIcon;
device->SetWindowPosition = Cocoa_SetWindowPosition;
device->SetWindowSize = Cocoa_SetWindowSize;
device->SetWindowMinimumSize = Cocoa_SetWindowMinimumSize;
device->SetWindowMaximumSize = Cocoa_SetWindowMaximumSize;
device->SetWindowOpacity = Cocoa_SetWindowOpacity;
device->ShowWindow = Cocoa_ShowWindow;
device->HideWindow = Cocoa_HideWindow;
device->RaiseWindow = Cocoa_RaiseWindow;
device->MaximizeWindow = Cocoa_MaximizeWindow;
device->MinimizeWindow = Cocoa_MinimizeWindow;
device->RestoreWindow = Cocoa_RestoreWindow;
device->SetWindowBordered = Cocoa_SetWindowBordered;
device->SetWindowResizable = Cocoa_SetWindowResizable;
device->SetWindowFullscreen = Cocoa_SetWindowFullscreen;
device->SetWindowGammaRamp = Cocoa_SetWindowGammaRamp;
device->GetWindowGammaRamp = Cocoa_GetWindowGammaRamp;
device->SetWindowGrab = Cocoa_SetWindowGrab;
device->DestroyWindow = Cocoa_DestroyWindow;
device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
device->SetWindowHitTest = Cocoa_SetWindowHitTest;
device->AcceptDragAndDrop = Cocoa_AcceptDragAndDrop;
device->shape_driver.CreateShaper = Cocoa_CreateShaper;
device->shape_driver.SetWindowShape = Cocoa_SetWindowShape;
device->shape_driver.ResizeWindowShape = Cocoa_ResizeWindowShape;
#if SDL_VIDEO_OPENGL_CGL
device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
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;
device->GL_DeleteContext = Cocoa_GL_DeleteContext;
#elif SDL_VIDEO_OPENGL_EGL
device->GL_LoadLibrary = Cocoa_GLES_LoadLibrary;
device->GL_GetProcAddress = Cocoa_GLES_GetProcAddress;
device->GL_UnloadLibrary = Cocoa_GLES_UnloadLibrary;
device->GL_CreateContext = Cocoa_GLES_CreateContext;
device->GL_MakeCurrent = Cocoa_GLES_MakeCurrent;
device->GL_SetSwapInterval = Cocoa_GLES_SetSwapInterval;
device->GL_GetSwapInterval = Cocoa_GLES_GetSwapInterval;
device->GL_SwapWindow = Cocoa_GLES_SwapWindow;
device->GL_DeleteContext = Cocoa_GLES_DeleteContext;
#endif
#if SDL_VIDEO_VULKAN
device->Vulkan_LoadLibrary = Cocoa_Vulkan_LoadLibrary;
device->Vulkan_UnloadLibrary = Cocoa_Vulkan_UnloadLibrary;
device->Vulkan_GetInstanceExtensions = Cocoa_Vulkan_GetInstanceExtensions;
device->Vulkan_CreateSurface = Cocoa_Vulkan_CreateSurface;
device->Vulkan_GetDrawableSize = Cocoa_Vulkan_GetDrawableSize;
#endif
#if SDL_VIDEO_METAL
device->Metal_CreateView = Cocoa_Metal_CreateView;
device->Metal_DestroyView = Cocoa_Metal_DestroyView;
#endif
device->StartTextInput = Cocoa_StartTextInput;
device->StopTextInput = Cocoa_StopTextInput;
device->SetTextInputRect = Cocoa_SetTextInputRect;
device->SetClipboardText = Cocoa_SetClipboardText;
device->GetClipboardText = Cocoa_GetClipboardText;
device->HasClipboardText = Cocoa_HasClipboardText;
device->free = Cocoa_DeleteDevice;
return device;
}
VideoBootStrap COCOA_bootstrap = {
"cocoa", "SDL Cocoa video driver",
Cocoa_Available, Cocoa_CreateDevice
};
int
Cocoa_VideoInit(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
Cocoa_InitModes(_this);
Cocoa_InitKeyboard(_this);
if (Cocoa_InitMouse(_this) < 0) {
return -1;
}
data->allow_spaces = ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE));
/* The IOPM assertion API can disable the screensaver as of 10.7. */
data->screensaver_use_iopm = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
data->swaplock = SDL_CreateMutex();
if (!data->swaplock) {
return -1;
}
return 0;
}
void
Cocoa_VideoQuit(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
Cocoa_QuitModes(_this);
Cocoa_QuitKeyboard(_this);
Cocoa_QuitMouse(_this);
SDL_DestroyMutex(data->swaplock);
data->swaplock = NULL;
}
/* This function assumes that it's called from within an autorelease pool */
NSImage *
Cocoa_CreateImage(SDL_Surface * surface)
{
SDL_Surface *converted;
NSBitmapImageRep *imgrep;
Uint8 *pixels;
int i;
NSImage *img;
converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32, 0);
if (!converted) {
return nil;
}
imgrep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL
pixelsWide: converted->w
pixelsHigh: converted->h
bitsPerSample: 8
samplesPerPixel: 4
hasAlpha: YES
isPlanar: NO
colorSpaceName: NSDeviceRGBColorSpace
bytesPerRow: converted->pitch
bitsPerPixel: converted->format->BitsPerPixel] autorelease];
if (imgrep == nil) {
SDL_FreeSurface(converted);
return nil;
}
/* Copy the pixels */
pixels = [imgrep bitmapData];
SDL_memcpy(pixels, converted->pixels, converted->h * converted->pitch);
SDL_FreeSurface(converted);
/* Premultiply the alpha channel */
for (i = (surface->h * surface->w); i--; ) {
Uint8 alpha = pixels[3];
pixels[0] = (Uint8)(((Uint16)pixels[0] * alpha) / 255);
pixels[1] = (Uint8)(((Uint16)pixels[1] * alpha) / 255);
pixels[2] = (Uint8)(((Uint16)pixels[2] * alpha) / 255);
pixels += 4;
}
img = [[[NSImage alloc] initWithSize: NSMakeSize(surface->w, surface->h)] autorelease];
if (img != nil) {
[img addRepresentation: imgrep];
}
return img;
}
/*
* Mac OS X log support.
*
* This doesn't really have aything to do with the interfaces of the SDL video
* subsystem, but we need to stuff this into an Objective-C source code file.
*
* NOTE: This is copypasted in src/video/uikit/SDL_uikitvideo.m! Be sure both
* versions remain identical!
*/
void SDL_NSLog(const char *text)
{
NSLog(@"%s", text);
}
#endif /* SDL_VIDEO_DRIVER_COCOA */
/* vim: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,55 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
* @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
* SDL_x11vulkan.h.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoavulkan_h_
#define SDL_cocoavulkan_h_
#include "../SDL_vulkan_internal.h"
#include "../SDL_sysvideo.h"
#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_COCOA
int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path);
void Cocoa_Vulkan_UnloadLibrary(_THIS);
SDL_bool Cocoa_Vulkan_GetInstanceExtensions(_THIS,
SDL_Window *window,
unsigned *count,
const char **names);
SDL_bool Cocoa_Vulkan_CreateSurface(_THIS,
SDL_Window *window,
VkInstance instance,
VkSurfaceKHR *surface);
void Cocoa_Vulkan_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h);
#endif
#endif /* SDL_cocoavulkan_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,244 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
* @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
* SDL_x11vulkan.c.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_COCOA
#include "SDL_cocoavideo.h"
#include "SDL_cocoawindow.h"
#include "SDL_assert.h"
#include "SDL_loadso.h"
#include "SDL_cocoametalview.h"
#include "SDL_cocoavulkan.h"
#include "SDL_syswm.h"
#include <dlfcn.h>
const char* defaultPaths[] = {
"vulkan.framework/vulkan",
"libvulkan.1.dylib",
"libvulkan.dylib",
"MoltenVK.framework/MoltenVK",
"libMoltenVK.dylib"
};
/* Since libSDL is most likely a .dylib, need RTLD_DEFAULT not RTLD_SELF. */
#define DEFAULT_HANDLE RTLD_DEFAULT
int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
{
VkExtensionProperties *extensions = NULL;
Uint32 extensionCount = 0;
SDL_bool hasSurfaceExtension = SDL_FALSE;
SDL_bool hasMacOSSurfaceExtension = SDL_FALSE;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
if (_this->vulkan_config.loader_handle) {
return SDL_SetError("Vulkan Portability library is already loaded.");
}
/* Load the Vulkan loader library */
if (!path) {
path = SDL_getenv("SDL_VULKAN_LIBRARY");
}
if (!path) {
/* Handle the case where Vulkan Portability is linked statically. */
vkGetInstanceProcAddr =
(PFN_vkGetInstanceProcAddr)dlsym(DEFAULT_HANDLE,
"vkGetInstanceProcAddr");
}
if (vkGetInstanceProcAddr) {
_this->vulkan_config.loader_handle = DEFAULT_HANDLE;
} else {
const char** paths;
const char *foundPath = NULL;
int numPaths;
int i;
if (path) {
paths = &path;
numPaths = 1;
} else {
/* Look for framework or .dylib packaged with the application
* instead. */
paths = defaultPaths;
numPaths = SDL_arraysize(defaultPaths);
}
for (i = 0; i < numPaths && _this->vulkan_config.loader_handle == NULL; i++) {
foundPath = paths[i];
_this->vulkan_config.loader_handle = SDL_LoadObject(foundPath);
}
if (_this->vulkan_config.loader_handle == NULL) {
return SDL_SetError("Failed to load Vulkan Portability library");
}
SDL_strlcpy(_this->vulkan_config.loader_path, foundPath,
SDL_arraysize(_this->vulkan_config.loader_path));
vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
_this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
}
if (!vkGetInstanceProcAddr) {
SDL_SetError("Failed to find %s in either executable or %s: %s",
"vkGetInstanceProcAddr",
_this->vulkan_config.loader_path,
(const char *) dlerror());
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) {
goto fail;
}
extensions = SDL_Vulkan_CreateInstanceExtensionsList(
(PFN_vkEnumerateInstanceExtensionProperties)
_this->vulkan_config.vkEnumerateInstanceExtensionProperties,
&extensionCount);
if (!extensions) {
goto fail;
}
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_MVK_MACOS_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
hasMacOSSurfaceExtension = SDL_TRUE;
}
}
SDL_free(extensions);
if (!hasSurfaceExtension) {
SDL_SetError("Installed Vulkan Portability library doesn't implement the "
VK_KHR_SURFACE_EXTENSION_NAME " extension");
goto fail;
} else if (!hasMacOSSurfaceExtension) {
SDL_SetError("Installed Vulkan Portability library doesn't implement the "
VK_MVK_MACOS_SURFACE_EXTENSION_NAME "extension");
goto fail;
}
return 0;
fail:
SDL_UnloadObject(_this->vulkan_config.loader_handle);
_this->vulkan_config.loader_handle = NULL;
return -1;
}
void Cocoa_Vulkan_UnloadLibrary(_THIS)
{
if (_this->vulkan_config.loader_handle) {
if (_this->vulkan_config.loader_handle != DEFAULT_HANDLE) {
SDL_UnloadObject(_this->vulkan_config.loader_handle);
}
_this->vulkan_config.loader_handle = NULL;
}
}
SDL_bool Cocoa_Vulkan_GetInstanceExtensions(_THIS,
SDL_Window *window,
unsigned *count,
const char **names)
{
static const char *const extensionsForCocoa[] = {
VK_KHR_SURFACE_EXTENSION_NAME, VK_MVK_MACOS_SURFACE_EXTENSION_NAME
};
if (!_this->vulkan_config.loader_handle) {
SDL_SetError("Vulkan is not loaded");
return SDL_FALSE;
}
return SDL_Vulkan_GetInstanceExtensions_Helper(
count, names, SDL_arraysize(extensionsForCocoa),
extensionsForCocoa);
}
SDL_bool Cocoa_Vulkan_CreateSurface(_THIS,
SDL_Window *window,
VkInstance instance,
VkSurfaceKHR *surface)
{
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
(PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr;
PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK =
(PFN_vkCreateMacOSSurfaceMVK)vkGetInstanceProcAddr(
(VkInstance)instance,
"vkCreateMacOSSurfaceMVK");
VkMacOSSurfaceCreateInfoMVK createInfo = {};
VkResult result;
SDL_MetalView metalview;
if (!_this->vulkan_config.loader_handle) {
SDL_SetError("Vulkan is not loaded");
return SDL_FALSE;
}
if (!vkCreateMacOSSurfaceMVK) {
SDL_SetError(VK_MVK_MACOS_SURFACE_EXTENSION_NAME
" extension is not enabled in the Vulkan instance.");
return SDL_FALSE;
}
metalview = Cocoa_Metal_CreateView(_this, window);
if (metalview == NULL) {
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;
}
/* Unfortunately there's no SDL_Vulkan_DestroySurface function we can call
* Metal_DestroyView from. Right now the metal view's ref count is +2 (one
* from returning a new view object in CreateView, and one because it's
* a subview of the window.) If we release the view here to make it +1, it
* will be destroyed when the window is destroyed. */
CFBridgingRelease(metalview);
return SDL_TRUE;
}
void Cocoa_Vulkan_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h)
{
Cocoa_Metal_GetDrawableSize(window, w, h);
}
#endif
/* vim: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,156 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_cocoawindow_h_
#define SDL_cocoawindow_h_
#import <Cocoa/Cocoa.h>
#if SDL_VIDEO_OPENGL_EGL
#include "../SDL_egl_c.h"
#endif
typedef struct SDL_WindowData SDL_WindowData;
typedef enum
{
PENDING_OPERATION_NONE,
PENDING_OPERATION_ENTER_FULLSCREEN,
PENDING_OPERATION_LEAVE_FULLSCREEN,
PENDING_OPERATION_MINIMIZE
} PendingWindowOperation;
@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
SDL_WindowData *_data;
BOOL observingVisible;
BOOL wasCtrlLeft;
BOOL wasVisible;
BOOL isFullscreenSpace;
BOOL inFullscreenTransition;
PendingWindowOperation pendingWindowOperation;
BOOL isMoving;
int pendingWindowWarpX, pendingWindowWarpY;
BOOL isDragAreaRunning;
}
-(void) listen:(SDL_WindowData *) data;
-(void) pauseVisibleObservation;
-(void) resumeVisibleObservation;
-(BOOL) setFullscreenSpace:(BOOL) state;
-(BOOL) isInFullscreenSpace;
-(BOOL) isInFullscreenSpaceTransition;
-(void) addPendingWindowOperation:(PendingWindowOperation) operation;
-(void) close;
-(BOOL) isMoving;
-(void) setPendingMoveX:(int)x Y:(int)y;
-(void) windowDidFinishMoving;
/* Window delegate functionality */
-(BOOL) windowShouldClose:(id) sender;
-(void) windowDidExpose:(NSNotification *) aNotification;
-(void) windowDidMove:(NSNotification *) aNotification;
-(void) windowDidResize:(NSNotification *) aNotification;
-(void) windowDidMiniaturize:(NSNotification *) aNotification;
-(void) windowDidDeminiaturize:(NSNotification *) aNotification;
-(void) windowDidBecomeKey:(NSNotification *) aNotification;
-(void) windowDidResignKey:(NSNotification *) aNotification;
-(void) windowDidChangeBackingProperties:(NSNotification *) aNotification;
-(void) windowWillEnterFullScreen:(NSNotification *) aNotification;
-(void) windowDidEnterFullScreen:(NSNotification *) aNotification;
-(void) windowWillExitFullScreen:(NSNotification *) aNotification;
-(void) windowDidExitFullScreen:(NSNotification *) aNotification;
-(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions;
/* See if event is in a drag area, toggle on window dragging. */
-(BOOL) processHitTest:(NSEvent *)theEvent;
/* Window event handling */
-(void) mouseDown:(NSEvent *) theEvent;
-(void) rightMouseDown:(NSEvent *) theEvent;
-(void) otherMouseDown:(NSEvent *) theEvent;
-(void) mouseUp:(NSEvent *) theEvent;
-(void) rightMouseUp:(NSEvent *) theEvent;
-(void) otherMouseUp:(NSEvent *) theEvent;
-(void) mouseMoved:(NSEvent *) theEvent;
-(void) mouseDragged:(NSEvent *) theEvent;
-(void) rightMouseDragged:(NSEvent *) theEvent;
-(void) otherMouseDragged:(NSEvent *) theEvent;
-(void) scrollWheel:(NSEvent *) theEvent;
-(void) touchesBeganWithEvent:(NSEvent *) theEvent;
-(void) touchesMovedWithEvent:(NSEvent *) theEvent;
-(void) touchesEndedWithEvent:(NSEvent *) theEvent;
-(void) touchesCancelledWithEvent:(NSEvent *) theEvent;
/* Touch event handling */
-(void) handleTouches:(NSTouchPhase) phase withEvent:(NSEvent*) theEvent;
@end
/* *INDENT-ON* */
@class SDLOpenGLContext;
struct SDL_WindowData
{
SDL_Window *window;
NSWindow *nswindow;
NSView *sdlContentView; /* nil if window is created via CreateWindowFrom */
NSMutableArray *nscontexts;
SDL_bool created;
SDL_bool inWindowFullscreenTransition;
Cocoa_WindowListener *listener;
struct SDL_VideoData *videodata;
#if SDL_VIDEO_OPENGL_EGL
EGLSurface egl_surface;
#endif
};
extern int Cocoa_CreateWindow(_THIS, SDL_Window * window);
extern int Cocoa_CreateWindowFrom(_THIS, SDL_Window * window,
const void *data);
extern void Cocoa_SetWindowTitle(_THIS, SDL_Window * window);
extern void Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
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 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);
extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
extern void Cocoa_MaximizeWindow(_THIS, SDL_Window * window);
extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window);
extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window);
extern void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
extern void Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
extern int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
extern int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
extern void Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info);
extern int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
extern void Cocoa_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept);
#endif /* SDL_cocoawindow_h_ */
/* vi: set ts=4 sw=4 expandtab: */

2096
externals/SDL/src/video/cocoa/SDL_cocoawindow.m vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,413 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_DIRECTFB
#include "SDL_DirectFB_video.h"
#include "SDL_DirectFB_window.h"
#include "../../events/SDL_windowevents_c.h"
#define COLOR_EXPAND(col) col.r, col.g, col.b, col.a
static DFB_Theme theme_std = {
4, 4, 8, 8,
{255, 200, 200, 200},
24,
{255, 0, 0, 255},
16,
{255, 255, 255, 255},
"/usr/share/fonts/truetype/freefont/FreeSans.ttf",
{255, 255, 0, 0},
{255, 255, 255, 0},
};
static DFB_Theme theme_none = {
0, 0, 0, 0,
{0, 0, 0, 0},
0,
{0, 0, 0, 0},
0,
{0, 0, 0, 0},
NULL
};
static void
DrawTriangle(IDirectFBSurface * s, int down, int x, int y, int w)
{
int x1, x2, x3;
int y1, y2, y3;
if (down) {
x1 = x + w / 2;
x2 = x;
x3 = x + w;
y1 = y + w;
y2 = y;
y3 = y;
} else {
x1 = x + w / 2;
x2 = x;
x3 = x + w;
y1 = y;
y2 = y + w;
y3 = y + w;
}
s->FillTriangle(s, x1, y1, x2, y2, x3, y3);
}
static void
LoadFont(_THIS, SDL_Window * window)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
if (windata->font != NULL) {
SDL_DFB_RELEASE(windata->font);
windata->font = NULL;
SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, windata->font));
}
if (windata->theme.font != NULL)
{
DFBFontDescription fdesc;
SDL_zero(fdesc);
fdesc.flags = DFDESC_HEIGHT;
fdesc.height = windata->theme.font_size;
SDL_DFB_CHECK(devdata->
dfb->CreateFont(devdata->dfb, windata->theme.font,
&fdesc, &windata->font));
SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, windata->font));
}
}
static void
DrawCraption(_THIS, IDirectFBSurface * s, int x, int y, char *text)
{
DFBSurfaceTextFlags flags;
flags = DSTF_CENTER | DSTF_TOP;
s->DrawString(s, text, -1, x, y, flags);
}
void
DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
IDirectFBSurface *s = windata->window_surface;
DFB_Theme *t = &windata->theme;
int i;
int d = (t->caption_size - t->font_size) / 2;
int x, y, w;
if (!windata->is_managed || (window->flags & SDL_WINDOW_FULLSCREEN))
return;
SDL_DFB_CHECK(s->SetSrcBlendFunction(s, DSBF_ONE));
SDL_DFB_CHECK(s->SetDstBlendFunction(s, DSBF_ZERO));
SDL_DFB_CHECK(s->SetDrawingFlags(s, DSDRAW_NOFX));
SDL_DFB_CHECK(s->SetBlittingFlags(s, DSBLIT_NOFX));
LoadFont(_this, window);
/* s->SetDrawingFlags(s, DSDRAW_BLEND); */
s->SetColor(s, COLOR_EXPAND(t->frame_color));
/* top */
for (i = 0; i < t->top_size; i++)
s->DrawLine(s, 0, i, windata->size.w, i);
/* bottom */
for (i = windata->size.h - t->bottom_size; i < windata->size.h; i++)
s->DrawLine(s, 0, i, windata->size.w, i);
/* left */
for (i = 0; i < t->left_size; i++)
s->DrawLine(s, i, 0, i, windata->size.h);
/* right */
for (i = windata->size.w - t->right_size; i < windata->size.w; i++)
s->DrawLine(s, i, 0, i, windata->size.h);
/* Caption */
s->SetColor(s, COLOR_EXPAND(t->caption_color));
s->FillRectangle(s, t->left_size, t->top_size, windata->client.w,
t->caption_size);
/* Close Button */
w = t->caption_size;
x = windata->size.w - t->right_size - w + d;
y = t->top_size + d;
s->SetColor(s, COLOR_EXPAND(t->close_color));
DrawTriangle(s, 1, x, y, w - 2 * d);
/* Max Button */
s->SetColor(s, COLOR_EXPAND(t->max_color));
DrawTriangle(s, window->flags & SDL_WINDOW_MAXIMIZED ? 1 : 0, x - w,
y, w - 2 * d);
/* Caption */
if (*window->title) {
s->SetColor(s, COLOR_EXPAND(t->font_color));
DrawCraption(_this, s, (x - w) / 2, t->top_size + d, window->title);
}
/* Icon */
if (windata->icon) {
DFBRectangle dr;
dr.x = t->left_size + d;
dr.y = t->top_size + d;
dr.w = w - 2 * d;
dr.h = w - 2 * d;
s->SetBlittingFlags(s, DSBLIT_BLEND_ALPHACHANNEL);
s->StretchBlit(s, windata->icon, NULL, &dr);
}
windata->wm_needs_redraw = 0;
}
DFBResult
DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch)
{
SDL_DFB_WINDOWDATA(window);
IDirectFBWindow *dfbwin = windata->dfbwin;
SDL_DFB_CHECK(dfbwin->GetSize(dfbwin, cw, ch));
dfbwin->GetSize(dfbwin, cw, ch);
*cw -= windata->theme.left_size + windata->theme.right_size;
*ch -=
windata->theme.top_size + windata->theme.caption_size +
windata->theme.bottom_size;
return DFB_OK;
}
void
DirectFB_WM_AdjustWindowLayout(SDL_Window * window, int flags, int w, int h)
{
SDL_DFB_WINDOWDATA(window);
if (!windata->is_managed)
windata->theme = theme_none;
else if (flags & SDL_WINDOW_BORDERLESS)
/* desc.caps |= DWCAPS_NODECORATION;) */
windata->theme = theme_none;
else if (flags & SDL_WINDOW_FULLSCREEN) {
windata->theme = theme_none;
} else if (flags & SDL_WINDOW_MAXIMIZED) {
windata->theme = theme_std;
windata->theme.left_size = 0;
windata->theme.right_size = 0;
windata->theme.top_size = 0;
windata->theme.bottom_size = 0;
} else {
windata->theme = theme_std;
}
windata->client.x = windata->theme.left_size;
windata->client.y = windata->theme.top_size + windata->theme.caption_size;
windata->client.w = w;
windata->client.h = h;
windata->size.w =
w + windata->theme.left_size + windata->theme.right_size;
windata->size.h =
h + windata->theme.top_size +
windata->theme.caption_size + windata->theme.bottom_size;
}
enum
{
WM_POS_NONE = 0x00,
WM_POS_CAPTION = 0x01,
WM_POS_CLOSE = 0x02,
WM_POS_MAX = 0x04,
WM_POS_LEFT = 0x08,
WM_POS_RIGHT = 0x10,
WM_POS_TOP = 0x20,
WM_POS_BOTTOM = 0x40,
};
static int
WMIsClient(DFB_WindowData * p, int x, int y)
{
x -= p->client.x;
y -= p->client.y;
if (x < 0 || y < 0)
return 0;
if (x >= p->client.w || y >= p->client.h)
return 0;
return 1;
}
static int
WMPos(DFB_WindowData * p, int x, int y)
{
int pos = WM_POS_NONE;
if (!WMIsClient(p, x, y)) {
if (y < p->theme.top_size) {
pos |= WM_POS_TOP;
} else if (y < p->client.y) {
if (x <
p->size.w - p->theme.right_size - 2 * p->theme.caption_size) {
pos |= WM_POS_CAPTION;
} else if (x <
p->size.w - p->theme.right_size -
p->theme.caption_size) {
pos |= WM_POS_MAX;
} else {
pos |= WM_POS_CLOSE;
}
} else if (y >= p->size.h - p->theme.bottom_size) {
pos |= WM_POS_BOTTOM;
}
if (x < p->theme.left_size) {
pos |= WM_POS_LEFT;
} else if (x >= p->size.w - p->theme.right_size) {
pos |= WM_POS_RIGHT;
}
}
return pos;
}
int
DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
IDirectFBWindow *dfbwin = windata->dfbwin;
DFBWindowOptions wopts;
if (!windata->is_managed)
return 0;
SDL_DFB_CHECK(dfbwin->GetOptions(dfbwin, &wopts));
switch (evt->type) {
case DWET_BUTTONDOWN:
if (evt->buttons & DIBM_LEFT) {
int pos = WMPos(windata, evt->x, evt->y);
switch (pos) {
case WM_POS_NONE:
return 0;
case WM_POS_CLOSE:
windata->wm_grab = WM_POS_NONE;
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_CLOSE, 0,
0);
return 1;
case WM_POS_MAX:
windata->wm_grab = WM_POS_NONE;
if (window->flags & SDL_WINDOW_MAXIMIZED) {
SDL_RestoreWindow(window);
} else {
SDL_MaximizeWindow(window);
}
return 1;
case WM_POS_CAPTION:
if (!(wopts & DWOP_KEEP_STACKING)) {
DirectFB_RaiseWindow(_this, window);
}
if (window->flags & SDL_WINDOW_MAXIMIZED)
return 1;
/* fall through */
default:
windata->wm_grab = pos;
if (gwindata != NULL)
SDL_DFB_CHECK(gwindata->dfbwin->UngrabPointer(gwindata->dfbwin));
SDL_DFB_CHECK(dfbwin->GrabPointer(dfbwin));
windata->wm_lastx = evt->cx;
windata->wm_lasty = evt->cy;
}
}
return 1;
case DWET_BUTTONUP:
if (!windata->wm_grab)
return 0;
if (!(evt->buttons & DIBM_LEFT)) {
if (windata->wm_grab & (WM_POS_RIGHT | WM_POS_BOTTOM)) {
int dx = evt->cx - windata->wm_lastx;
int dy = evt->cy - windata->wm_lasty;
if (!(wopts & DWOP_KEEP_SIZE)) {
int cw, ch;
if ((windata->wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_BOTTOM)
dx = 0;
else if ((windata->wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_RIGHT)
dy = 0;
SDL_DFB_CHECK(dfbwin->GetSize(dfbwin, &cw, &ch));
/* necessary to trigger an event - ugly */
SDL_DFB_CHECK(dfbwin->DisableEvents(dfbwin, DWET_ALL));
SDL_DFB_CHECK(dfbwin->Resize(dfbwin, cw + dx + 1, ch + dy));
SDL_DFB_CHECK(dfbwin->EnableEvents(dfbwin, DWET_ALL));
SDL_DFB_CHECK(dfbwin->Resize(dfbwin, cw + dx, ch + dy));
}
}
SDL_DFB_CHECK(dfbwin->UngrabPointer(dfbwin));
if (gwindata != NULL)
SDL_DFB_CHECK(gwindata->dfbwin->GrabPointer(gwindata->dfbwin));
windata->wm_grab = WM_POS_NONE;
return 1;
}
break;
case DWET_MOTION:
if (!windata->wm_grab)
return 0;
if (evt->buttons & DIBM_LEFT) {
int dx = evt->cx - windata->wm_lastx;
int dy = evt->cy - windata->wm_lasty;
if (windata->wm_grab & WM_POS_CAPTION) {
if (!(wopts & DWOP_KEEP_POSITION))
SDL_DFB_CHECK(dfbwin->Move(dfbwin, dx, dy));
}
if (windata->wm_grab & (WM_POS_RIGHT | WM_POS_BOTTOM)) {
if (!(wopts & DWOP_KEEP_SIZE)) {
int cw, ch;
/* Make sure all events are disabled for this operation ! */
SDL_DFB_CHECK(dfbwin->DisableEvents(dfbwin, DWET_ALL));
if ((windata->wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_BOTTOM)
dx = 0;
else if ((windata->wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_RIGHT)
dy = 0;
SDL_DFB_CHECK(dfbwin->GetSize(dfbwin, &cw, &ch));
SDL_DFB_CHECK(dfbwin->Resize(dfbwin, cw + dx, ch + dy));
SDL_DFB_CHECK(dfbwin->EnableEvents(dfbwin, DWET_ALL));
}
}
windata->wm_lastx = evt->cx;
windata->wm_lasty = evt->cy;
return 1;
}
break;
case DWET_KEYDOWN:
break;
case DWET_KEYUP:
break;
default:
;
}
return 0;
}
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */

View File

@@ -0,0 +1,56 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_directfb_wm_h_
#define SDL_directfb_wm_h_
#include "SDL_DirectFB_video.h"
typedef struct _DFB_Theme DFB_Theme;
struct _DFB_Theme
{
int left_size;
int right_size;
int top_size;
int bottom_size;
DFBColor frame_color;
int caption_size;
DFBColor caption_color;
int font_size;
DFBColor font_color;
char *font;
DFBColor close_color;
DFBColor max_color;
};
extern void DirectFB_WM_AdjustWindowLayout(SDL_Window * window, int flags, int w, int h);
extern void DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window);
extern int DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window,
DFBWindowEvent * evt);
extern DFBResult DirectFB_WM_GetClientSize(_THIS, SDL_Window * window,
int *cw, int *ch);
#endif /* SDL_directfb_wm_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,117 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_DIRECTFB
#include "SDL_DirectFB_video.h"
#include "SDL_DirectFB_dyn.h"
#ifdef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC
#include "SDL_name.h"
#include "SDL_loadso.h"
#define DFB_SYM(ret, name, args, al, func) ret (*name) args;
static struct _SDL_DirectFB_Symbols
{
DFB_SYMS
const unsigned int *directfb_major_version;
const unsigned int *directfb_minor_version;
const unsigned int *directfb_micro_version;
} SDL_DirectFB_Symbols;
#undef DFB_SYM
#define DFB_SYM(ret, name, args, al, func) ret name args { func SDL_DirectFB_Symbols.name al ; }
DFB_SYMS
#undef DFB_SYM
static void *handle = NULL;
int
SDL_DirectFB_LoadLibrary(void)
{
int retval = 0;
if (handle == NULL) {
handle = SDL_LoadObject(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC);
if (handle != NULL) {
retval = 1;
#define DFB_SYM(ret, name, args, al, func) if (!(SDL_DirectFB_Symbols.name = SDL_LoadFunction(handle, # name))) retval = 0;
DFB_SYMS
#undef DFB_SYM
if (!
(SDL_DirectFB_Symbols.directfb_major_version =
SDL_LoadFunction(handle, "directfb_major_version")))
retval = 0;
if (!
(SDL_DirectFB_Symbols.directfb_minor_version =
SDL_LoadFunction(handle, "directfb_minor_version")))
retval = 0;
if (!
(SDL_DirectFB_Symbols.directfb_micro_version =
SDL_LoadFunction(handle, "directfb_micro_version")))
retval = 0;
}
}
if (retval) {
const char *stemp = DirectFBCheckVersion(DIRECTFB_MAJOR_VERSION,
DIRECTFB_MINOR_VERSION,
DIRECTFB_MICRO_VERSION);
/* Version Check */
if (stemp != NULL) {
fprintf(stderr,
"DirectFB Lib: Version mismatch. Compiled: %d.%d.%d Library %d.%d.%d\n",
DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION,
DIRECTFB_MICRO_VERSION,
*SDL_DirectFB_Symbols.directfb_major_version,
*SDL_DirectFB_Symbols.directfb_minor_version,
*SDL_DirectFB_Symbols.directfb_micro_version);
retval = 0;
}
}
if (!retval)
SDL_DirectFB_UnLoadLibrary();
return retval;
}
void
SDL_DirectFB_UnLoadLibrary(void)
{
if (handle != NULL) {
SDL_UnloadObject(handle);
handle = NULL;
}
}
#else
int
SDL_DirectFB_LoadLibrary(void)
{
return 1;
}
void
SDL_DirectFB_UnLoadLibrary(void)
{
}
#endif
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */

View File

@@ -0,0 +1,41 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_DirectFB_dyn_h_
#define SDL_DirectFB_dyn_h_
#define DFB_SYMS \
DFB_SYM(DFBResult, DirectFBError, (const char *msg, DFBResult result), (msg, result), return) \
DFB_SYM(DFBResult, DirectFBErrorFatal, (const char *msg, DFBResult result), (msg, result), return) \
DFB_SYM(const char *, DirectFBErrorString, (DFBResult result), (result), return) \
DFB_SYM(const char *, DirectFBUsageString, ( void ), (), return) \
DFB_SYM(DFBResult, DirectFBInit, (int *argc, char *(*argv[]) ), (argc, argv), return) \
DFB_SYM(DFBResult, DirectFBSetOption, (const char *name, const char *value), (name, value), return) \
DFB_SYM(DFBResult, DirectFBCreate, (IDirectFB **interface), (interface), return) \
DFB_SYM(const char *, DirectFBCheckVersion, (unsigned int required_major, unsigned int required_minor, unsigned int required_micro), \
(required_major, required_minor, required_micro), return)
int SDL_DirectFB_LoadLibrary(void);
void SDL_DirectFB_UnLoadLibrary(void);
#endif /* SDL_DirectFB_dyn_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,748 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_DIRECTFB
/* Handle the event stream, converting DirectFB input events into SDL events */
#include "SDL_DirectFB_video.h"
#include "SDL_DirectFB_window.h"
#include "SDL_DirectFB_modes.h"
#include "SDL_syswm.h"
#include "../../events/SDL_mouse_c.h"
#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 "SDL_DirectFB_events.h"
#if USE_MULTI_API
#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y, p)
#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button)
#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(id, state, scancode)
#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(id, text)
#else
#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y)
#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button)
#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(state, scancode)
#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(text)
#endif
typedef struct _cb_data cb_data;
struct _cb_data
{
DFB_DeviceData *devdata;
int sys_ids;
int sys_kbd;
};
/* The translation tables from a DirectFB keycode to a SDL keysym */
static SDL_Scancode oskeymap[256];
static SDL_Keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt,
SDL_Keysym * keysym, Uint32 *unicode);
static SDL_Keysym *DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
SDL_Keysym * keysym, Uint32 *unicode);
static void DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keypmap, int numkeys);
static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
static void UnicodeToUtf8( Uint16 w , char *utf8buf)
{
unsigned char *utf8s = (unsigned char *) utf8buf;
if ( w < 0x0080 ) {
utf8s[0] = ( unsigned char ) w;
utf8s[1] = 0;
}
else if ( w < 0x0800 ) {
utf8s[0] = 0xc0 | (( w ) >> 6 );
utf8s[1] = 0x80 | (( w ) & 0x3f );
utf8s[2] = 0;
}
else {
utf8s[0] = 0xe0 | (( w ) >> 12 );
utf8s[1] = 0x80 | (( ( w ) >> 6 ) & 0x3f );
utf8s[2] = 0x80 | (( w ) & 0x3f );
utf8s[3] = 0;
}
}
static void
FocusAllMice(_THIS, SDL_Window *window)
{
#if USE_MULTI_API
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_mice; index++)
SDL_SetMouseFocus(devdata->mouse_id[index], id);
#else
SDL_SetMouseFocus(window);
#endif
}
static void
FocusAllKeyboards(_THIS, SDL_Window *window)
{
#if USE_MULTI_API
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_keyboard; index++)
SDL_SetKeyboardFocus(index, id);
#else
SDL_SetKeyboardFocus(window);
#endif
}
static void
MotionAllMice(_THIS, int x, int y)
{
#if USE_MULTI_API
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_mice; index++) {
SDL_Mouse *mouse = SDL_GetMouse(index);
mouse->x = mouse->last_x = x;
mouse->y = mouse->last_y = y;
/* SDL_SendMouseMotion(devdata->mouse_id[index], 0, x, y, 0); */
}
#endif
}
static int
KbdIndex(_THIS, int id)
{
SDL_DFB_DEVICEDATA(_this);
int index;
for (index = 0; index < devdata->num_keyboard; index++) {
if (devdata->keyboard[index].id == id)
return index;
}
return -1;
}
static int
ClientXY(DFB_WindowData * p, int *x, int *y)
{
int cx, cy;
cx = *x;
cy = *y;
cx -= p->client.x;
cy -= p->client.y;
if (cx < 0 || cy < 0)
return 0;
if (cx >= p->client.w || cy >= p->client.h)
return 0;
*x = cx;
*y = cy;
return 1;
}
static void
ProcessWindowEvent(_THIS, SDL_Window *sdlwin, DFBWindowEvent * evt)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(sdlwin);
SDL_Keysym keysym;
Uint32 unicode;
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
if (evt->clazz == DFEC_WINDOW) {
switch (evt->type) {
case DWET_BUTTONDOWN:
if (ClientXY(windata, &evt->x, &evt->y)) {
if (!devdata->use_linux_input) {
SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
evt->y, 0);
SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
SDL_PRESSED,
DirectFB_TranslateButton
(evt->button));
} else {
MotionAllMice(_this, evt->x, evt->y);
}
}
break;
case DWET_BUTTONUP:
if (ClientXY(windata, &evt->x, &evt->y)) {
if (!devdata->use_linux_input) {
SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
evt->y, 0);
SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
SDL_RELEASED,
DirectFB_TranslateButton
(evt->button));
} else {
MotionAllMice(_this, evt->x, evt->y);
}
}
break;
case DWET_MOTION:
if (ClientXY(windata, &evt->x, &evt->y)) {
if (!devdata->use_linux_input) {
if (!(sdlwin->flags & SDL_WINDOW_INPUT_GRABBED))
SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0,
evt->x, evt->y, 0);
} else {
/* relative movements are not exact!
* This code should limit the number of events sent.
* However it kills MAME axis recognition ... */
static int cnt = 0;
if (1 && ++cnt > 20) {
MotionAllMice(_this, evt->x, evt->y);
cnt = 0;
}
}
if (!(sdlwin->flags & SDL_WINDOW_MOUSE_FOCUS))
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0,
0);
}
break;
case DWET_KEYDOWN:
if (!devdata->use_linux_input) {
DirectFB_TranslateKey(_this, evt, &keysym, &unicode);
/* printf("Scancode %d %d %d\n", keysym.scancode, evt->key_code, evt->key_id); */
SDL_SendKeyboardKey_ex(0, SDL_PRESSED, keysym.scancode);
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
SDL_zeroa(text);
UnicodeToUtf8(unicode, text);
if (*text) {
SDL_SendKeyboardText_ex(0, text);
}
}
}
break;
case DWET_KEYUP:
if (!devdata->use_linux_input) {
DirectFB_TranslateKey(_this, evt, &keysym, &unicode);
SDL_SendKeyboardKey_ex(0, SDL_RELEASED, keysym.scancode);
}
break;
case DWET_POSITION:
if (ClientXY(windata, &evt->x, &evt->y)) {
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED,
evt->x, evt->y);
}
break;
case DWET_POSITION_SIZE:
if (ClientXY(windata, &evt->x, &evt->y)) {
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED,
evt->x, evt->y);
}
/* fall throught */
case DWET_SIZE:
/* FIXME: what about < 0 */
evt->w -= (windata->theme.right_size + windata->theme.left_size);
evt->h -=
(windata->theme.top_size + windata->theme.bottom_size +
windata->theme.caption_size);
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_RESIZED,
evt->w, evt->h);
break;
case DWET_CLOSE:
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_CLOSE, 0, 0);
break;
case DWET_GOTFOCUS:
DirectFB_SetContext(_this, sdlwin);
FocusAllKeyboards(_this, sdlwin);
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_GAINED,
0, 0);
break;
case DWET_LOSTFOCUS:
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
FocusAllKeyboards(_this, 0);
break;
case DWET_ENTER:
/* SDL_DirectFB_ReshowCursor(_this, 0); */
FocusAllMice(_this, sdlwin);
/* FIXME: when do we really enter ? */
if (ClientXY(windata, &evt->x, &evt->y))
MotionAllMice(_this, evt->x, evt->y);
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0, 0);
break;
case DWET_LEAVE:
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_LEAVE, 0, 0);
FocusAllMice(_this, 0);
/* SDL_DirectFB_ReshowCursor(_this, 1); */
break;
default:
;
}
} else
printf("Event Clazz %d\n", evt->clazz);
}
static void
ProcessInputEvent(_THIS, DFBInputEvent * ievt)
{
SDL_DFB_DEVICEDATA(_this);
SDL_Keysym keysym;
int kbd_idx;
Uint32 unicode;
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
if (!devdata->use_linux_input) {
if (ievt->type == DIET_AXISMOTION) {
if ((devdata->grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) {
if (ievt->axis == DIAI_X)
SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
ievt->axisrel, 0, 0);
else if (ievt->axis == DIAI_Y)
SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
ievt->axisrel, 0);
}
}
} else {
static int last_x, last_y;
switch (ievt->type) {
case DIET_AXISMOTION:
if (ievt->flags & DIEF_AXISABS) {
if (ievt->axis == DIAI_X)
last_x = ievt->axisabs;
else if (ievt->axis == DIAI_Y)
last_y = ievt->axisabs;
if (!(ievt->flags & DIEF_FOLLOW)) {
#if USE_MULTI_API
SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id);
SDL_Window *window = SDL_GetWindowFromID(mouse->focus);
#else
SDL_Window *window = devdata->grabbed_window;
#endif
if (window) {
DFB_WindowData *windata =
(DFB_WindowData *) window->driverdata;
int x, y;
windata->dfbwin->GetPosition(windata->dfbwin, &x, &y);
SDL_SendMouseMotion_ex(window, ievt->device_id, 0,
last_x - (x +
windata->client.x),
last_y - (y +
windata->client.y), 0);
} else {
SDL_SendMouseMotion_ex(window, ievt->device_id, 0, last_x,
last_y, 0);
}
}
} else if (ievt->flags & DIEF_AXISREL) {
if (ievt->axis == DIAI_X)
SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
ievt->axisrel, 0, 0);
else if (ievt->axis == DIAI_Y)
SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
ievt->axisrel, 0);
}
break;
case DIET_KEYPRESS:
kbd_idx = KbdIndex(_this, ievt->device_id);
DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym, &unicode);
/* printf("Scancode %d %d %d\n", keysym.scancode, evt->key_code, evt->key_id); */
SDL_SendKeyboardKey_ex(kbd_idx, SDL_PRESSED, keysym.scancode);
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
SDL_zeroa(text);
UnicodeToUtf8(unicode, text);
if (*text) {
SDL_SendKeyboardText_ex(kbd_idx, text);
}
}
break;
case DIET_KEYRELEASE:
kbd_idx = KbdIndex(_this, ievt->device_id);
DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym, &unicode);
SDL_SendKeyboardKey_ex(kbd_idx, SDL_RELEASED, keysym.scancode);
break;
case DIET_BUTTONPRESS:
if (ievt->buttons & DIBM_LEFT)
SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 1);
if (ievt->buttons & DIBM_MIDDLE)
SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 2);
if (ievt->buttons & DIBM_RIGHT)
SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 3);
break;
case DIET_BUTTONRELEASE:
if (!(ievt->buttons & DIBM_LEFT))
SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 1);
if (!(ievt->buttons & DIBM_MIDDLE))
SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 2);
if (!(ievt->buttons & DIBM_RIGHT))
SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 3);
break;
default:
break; /* please gcc */
}
}
}
void
DirectFB_PumpEventsWindow(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
DFBInputEvent ievt;
SDL_Window *w;
for (w = devdata->firstwin; w != NULL; w = w->next) {
SDL_DFB_WINDOWDATA(w);
DFBWindowEvent evt;
while (windata->eventbuffer->GetEvent(windata->eventbuffer,
DFB_EVENT(&evt)) == DFB_OK) {
if (!DirectFB_WM_ProcessEvent(_this, w, &evt)) {
/* Send a SDL_SYSWMEVENT if the application wants them */
if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
SDL_SysWMmsg wmmsg;
SDL_VERSION(&wmmsg.version);
wmmsg.subsystem = SDL_SYSWM_DIRECTFB;
wmmsg.msg.dfb.event.window = evt;
SDL_SendSysWMEvent(&wmmsg);
}
ProcessWindowEvent(_this, w, &evt);
}
}
}
/* Now get relative events in case we need them */
while (devdata->events->GetEvent(devdata->events,
DFB_EVENT(&ievt)) == DFB_OK) {
if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
SDL_SysWMmsg wmmsg;
SDL_VERSION(&wmmsg.version);
wmmsg.subsystem = SDL_SYSWM_DIRECTFB;
wmmsg.msg.dfb.event.input = ievt;
SDL_SendSysWMEvent(&wmmsg);
}
ProcessInputEvent(_this, &ievt);
}
}
void
DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keymap, int numkeys)
{
int i;
/* Initialize the DirectFB key translation table */
for (i = 0; i < numkeys; ++i)
keymap[i] = SDL_SCANCODE_UNKNOWN;
keymap[DIKI_A - DIKI_UNKNOWN] = SDL_SCANCODE_A;
keymap[DIKI_B - DIKI_UNKNOWN] = SDL_SCANCODE_B;
keymap[DIKI_C - DIKI_UNKNOWN] = SDL_SCANCODE_C;
keymap[DIKI_D - DIKI_UNKNOWN] = SDL_SCANCODE_D;
keymap[DIKI_E - DIKI_UNKNOWN] = SDL_SCANCODE_E;
keymap[DIKI_F - DIKI_UNKNOWN] = SDL_SCANCODE_F;
keymap[DIKI_G - DIKI_UNKNOWN] = SDL_SCANCODE_G;
keymap[DIKI_H - DIKI_UNKNOWN] = SDL_SCANCODE_H;
keymap[DIKI_I - DIKI_UNKNOWN] = SDL_SCANCODE_I;
keymap[DIKI_J - DIKI_UNKNOWN] = SDL_SCANCODE_J;
keymap[DIKI_K - DIKI_UNKNOWN] = SDL_SCANCODE_K;
keymap[DIKI_L - DIKI_UNKNOWN] = SDL_SCANCODE_L;
keymap[DIKI_M - DIKI_UNKNOWN] = SDL_SCANCODE_M;
keymap[DIKI_N - DIKI_UNKNOWN] = SDL_SCANCODE_N;
keymap[DIKI_O - DIKI_UNKNOWN] = SDL_SCANCODE_O;
keymap[DIKI_P - DIKI_UNKNOWN] = SDL_SCANCODE_P;
keymap[DIKI_Q - DIKI_UNKNOWN] = SDL_SCANCODE_Q;
keymap[DIKI_R - DIKI_UNKNOWN] = SDL_SCANCODE_R;
keymap[DIKI_S - DIKI_UNKNOWN] = SDL_SCANCODE_S;
keymap[DIKI_T - DIKI_UNKNOWN] = SDL_SCANCODE_T;
keymap[DIKI_U - DIKI_UNKNOWN] = SDL_SCANCODE_U;
keymap[DIKI_V - DIKI_UNKNOWN] = SDL_SCANCODE_V;
keymap[DIKI_W - DIKI_UNKNOWN] = SDL_SCANCODE_W;
keymap[DIKI_X - DIKI_UNKNOWN] = SDL_SCANCODE_X;
keymap[DIKI_Y - DIKI_UNKNOWN] = SDL_SCANCODE_Y;
keymap[DIKI_Z - DIKI_UNKNOWN] = SDL_SCANCODE_Z;
keymap[DIKI_0 - DIKI_UNKNOWN] = SDL_SCANCODE_0;
keymap[DIKI_1 - DIKI_UNKNOWN] = SDL_SCANCODE_1;
keymap[DIKI_2 - DIKI_UNKNOWN] = SDL_SCANCODE_2;
keymap[DIKI_3 - DIKI_UNKNOWN] = SDL_SCANCODE_3;
keymap[DIKI_4 - DIKI_UNKNOWN] = SDL_SCANCODE_4;
keymap[DIKI_5 - DIKI_UNKNOWN] = SDL_SCANCODE_5;
keymap[DIKI_6 - DIKI_UNKNOWN] = SDL_SCANCODE_6;
keymap[DIKI_7 - DIKI_UNKNOWN] = SDL_SCANCODE_7;
keymap[DIKI_8 - DIKI_UNKNOWN] = SDL_SCANCODE_8;
keymap[DIKI_9 - DIKI_UNKNOWN] = SDL_SCANCODE_9;
keymap[DIKI_F1 - DIKI_UNKNOWN] = SDL_SCANCODE_F1;
keymap[DIKI_F2 - DIKI_UNKNOWN] = SDL_SCANCODE_F2;
keymap[DIKI_F3 - DIKI_UNKNOWN] = SDL_SCANCODE_F3;
keymap[DIKI_F4 - DIKI_UNKNOWN] = SDL_SCANCODE_F4;
keymap[DIKI_F5 - DIKI_UNKNOWN] = SDL_SCANCODE_F5;
keymap[DIKI_F6 - DIKI_UNKNOWN] = SDL_SCANCODE_F6;
keymap[DIKI_F7 - DIKI_UNKNOWN] = SDL_SCANCODE_F7;
keymap[DIKI_F8 - DIKI_UNKNOWN] = SDL_SCANCODE_F8;
keymap[DIKI_F9 - DIKI_UNKNOWN] = SDL_SCANCODE_F9;
keymap[DIKI_F10 - DIKI_UNKNOWN] = SDL_SCANCODE_F10;
keymap[DIKI_F11 - DIKI_UNKNOWN] = SDL_SCANCODE_F11;
keymap[DIKI_F12 - DIKI_UNKNOWN] = SDL_SCANCODE_F12;
keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDL_SCANCODE_ESCAPE;
keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFT;
keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHT;
keymap[DIKI_UP - DIKI_UNKNOWN] = SDL_SCANCODE_UP;
keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_DOWN;
keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDL_SCANCODE_LCTRL;
keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDL_SCANCODE_RCTRL;
keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LSHIFT;
keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RSHIFT;
keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LALT;
keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RALT;
keymap[DIKI_META_L - DIKI_UNKNOWN] = SDL_SCANCODE_LGUI;
keymap[DIKI_META_R - DIKI_UNKNOWN] = SDL_SCANCODE_RGUI;
keymap[DIKI_SUPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
keymap[DIKI_SUPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
/* FIXME:Do we read hyper keys ?
* keymap[DIKI_HYPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
* keymap[DIKI_HYPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
*/
keymap[DIKI_TAB - DIKI_UNKNOWN] = SDL_SCANCODE_TAB;
keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_RETURN;
keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDL_SCANCODE_SPACE;
keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSPACE;
keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDL_SCANCODE_INSERT;
keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDL_SCANCODE_DELETE;
keymap[DIKI_HOME - DIKI_UNKNOWN] = SDL_SCANCODE_HOME;
keymap[DIKI_END - DIKI_UNKNOWN] = SDL_SCANCODE_END;
keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEUP;
keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEDOWN;
keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_CAPSLOCK;
keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_NUMLOCKCLEAR;
keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_SCROLLLOCK;
keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDL_SCANCODE_PRINTSCREEN;
keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDL_SCANCODE_PAUSE;
keymap[DIKI_KP_EQUAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_EQUALS;
keymap[DIKI_KP_DECIMAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PERIOD;
keymap[DIKI_KP_0 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_0;
keymap[DIKI_KP_1 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_1;
keymap[DIKI_KP_2 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_2;
keymap[DIKI_KP_3 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_3;
keymap[DIKI_KP_4 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_4;
keymap[DIKI_KP_5 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_5;
keymap[DIKI_KP_6 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_6;
keymap[DIKI_KP_7 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_7;
keymap[DIKI_KP_8 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_8;
keymap[DIKI_KP_9 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_9;
keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDL_SCANCODE_KP_DIVIDE;
keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MULTIPLY;
keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MINUS;
keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PLUS;
keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_KP_ENTER;
keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_GRAVE; /* TLDE */
keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_MINUS; /* AE11 */
keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_EQUALS; /* AE12 */
keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHTBRACKET; /* AD11 */
keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFTBRACKET; /* AD12 */
keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSLASH; /* BKSL */
keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = SDL_SCANCODE_SEMICOLON; /* AC10 */
keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_APOSTROPHE; /* AC11 */
keymap[DIKI_COMMA - DIKI_UNKNOWN] = SDL_SCANCODE_COMMA; /* AB08 */
keymap[DIKI_PERIOD - DIKI_UNKNOWN] = SDL_SCANCODE_PERIOD; /* AB09 */
keymap[DIKI_SLASH - DIKI_UNKNOWN] = SDL_SCANCODE_SLASH; /* AB10 */
keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_NONUSBACKSLASH; /* 103rd */
}
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); */
DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
keysym->scancode = SDL_SCANCODE_UNKNOWN;
if (kbd->map && evt->key_code >= kbd->map_adjust &&
evt->key_code < kbd->map_size + kbd->map_adjust)
keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust];
if (keysym->scancode == SDL_SCANCODE_UNKNOWN ||
devdata->keyboard[kbd_idx].is_generic) {
if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
else
keysym->scancode = SDL_SCANCODE_UNKNOWN;
}
*unicode =
(DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
if (*unicode == 0 &&
(evt->key_symbol > 0 && evt->key_symbol < 255))
*unicode = evt->key_symbol;
return keysym;
}
static SDL_Keysym *
DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
SDL_Keysym * keysym, Uint32 *unicode)
{
SDL_DFB_DEVICEDATA(_this);
int kbd_idx = KbdIndex(_this, evt->device_id);
DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
keysym->scancode = SDL_SCANCODE_UNKNOWN;
if (kbd->map && evt->key_code >= kbd->map_adjust &&
evt->key_code < kbd->map_size + kbd->map_adjust)
keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust];
if (keysym->scancode == SDL_SCANCODE_UNKNOWN || devdata->keyboard[kbd_idx].is_generic) {
if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
else
keysym->scancode = SDL_SCANCODE_UNKNOWN;
}
*unicode =
(DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
if (*unicode == 0 &&
(evt->key_symbol > 0 && evt->key_symbol < 255))
*unicode = evt->key_symbol;
return keysym;
}
static int
DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
{
switch (button) {
case DIBI_LEFT:
return 1;
case DIBI_MIDDLE:
return 2;
case DIBI_RIGHT:
return 3;
default:
return 0;
}
}
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) {
if (device_id >= 0x10)
return DFENUM_OK;
} else {
if (device_id < 0x10)
return DFENUM_OK;
}
} else {
if (device_id != DIDID_KEYBOARD)
return DFENUM_OK;
}
if ((desc.caps & DIDTF_KEYBOARD)) {
#if USE_MULTI_API
SDL_zero(keyboard);
SDL_AddKeyboard(&keyboard, devdata->num_keyboard);
#endif
devdata->keyboard[devdata->num_keyboard].id = device_id;
devdata->keyboard[devdata->num_keyboard].is_generic = 0;
if (!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_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_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)
return DFENUM_CANCEL;
}
return DFENUM_OK;
}
void
DirectFB_InitKeyboard(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
cb_data cb;
DirectFB_InitOSKeymap(_this, &oskeymap[0], SDL_arraysize(oskeymap));
devdata->num_keyboard = 0;
cb.devdata = devdata;
if (devdata->use_linux_input) {
cb.sys_kbd = 0;
cb.sys_ids = 0;
SDL_DFB_CHECK(devdata->dfb->
EnumInputDevices(devdata->dfb, EnumKeyboards, &cb));
if (devdata->num_keyboard == 0) {
cb.sys_ids = 1;
SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
EnumKeyboards,
&cb));
}
} else {
cb.sys_kbd = 1;
SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
EnumKeyboards,
&cb));
}
}
void
DirectFB_QuitKeyboard(_THIS)
{
/* SDL_DFB_DEVICEDATA(_this); */
}
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */

View File

@@ -0,0 +1,34 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_DirectFB_events_h_
#define SDL_DirectFB_events_h_
#include "../SDL_sysvideo.h"
/* Functions to be exported */
extern void DirectFB_InitKeyboard(_THIS);
extern void DirectFB_QuitKeyboard(_THIS);
extern void DirectFB_PumpEventsWindow(_THIS);
#endif /* SDL_DirectFB_events_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,414 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_DIRECTFB
#include "SDL_DirectFB_video.h"
#include "SDL_DirectFB_modes.h"
#define DFB_MAX_MODES 200
struct screen_callback_t
{
int numscreens;
DFBScreenID screenid[DFB_MAX_SCREENS];
DFBDisplayLayerID gralayer[DFB_MAX_SCREENS];
DFBDisplayLayerID vidlayer[DFB_MAX_SCREENS];
int aux; /* auxiliary integer for callbacks */
};
struct modes_callback_t
{
int nummodes;
SDL_DisplayMode *modelist;
};
static DFBEnumerationResult
EnumModesCallback(int width, int height, int bpp, void *data)
{
struct modes_callback_t *modedata = (struct modes_callback_t *) data;
SDL_DisplayMode mode;
mode.w = width;
mode.h = height;
mode.refresh_rate = 0;
mode.driverdata = NULL;
mode.format = SDL_PIXELFORMAT_UNKNOWN;
if (modedata->nummodes < DFB_MAX_MODES) {
modedata->modelist[modedata->nummodes++] = mode;
}
return DFENUM_OK;
}
static DFBEnumerationResult
EnumScreensCallback(DFBScreenID screen_id, DFBScreenDescription desc,
void *callbackdata)
{
struct screen_callback_t *devdata = (struct screen_callback_t *) callbackdata;
devdata->screenid[devdata->numscreens++] = screen_id;
return DFENUM_OK;
}
static DFBEnumerationResult
EnumLayersCallback(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
void *callbackdata)
{
struct screen_callback_t *devdata = (struct screen_callback_t *) callbackdata;
if (desc.caps & DLCAPS_SURFACE) {
if ((desc.type & DLTF_GRAPHICS) && (desc.type & DLTF_VIDEO)) {
if (devdata->vidlayer[devdata->aux] == -1)
devdata->vidlayer[devdata->aux] = layer_id;
} else if (desc.type & DLTF_GRAPHICS) {
if (devdata->gralayer[devdata->aux] == -1)
devdata->gralayer[devdata->aux] = layer_id;
}
}
return DFENUM_OK;
}
static void
CheckSetDisplayMode(_THIS, SDL_VideoDisplay * display, DFB_DisplayData * data, SDL_DisplayMode * mode)
{
SDL_DFB_DEVICEDATA(_this);
DFBDisplayLayerConfig config;
DFBDisplayLayerConfigFlags failed;
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_ADMINISTRATIVE));
config.width = mode->w;
config.height = mode->h;
config.pixelformat = DirectFB_SDLToDFBPixelFormat(mode->format);
config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
if (devdata->use_yuv_underlays) {
config.flags |= DLCONF_OPTIONS;
config.options = DLOP_ALPHACHANNEL;
}
failed = 0;
data->layer->TestConfiguration(data->layer, &config, &failed);
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_SHARED));
if (failed == 0)
{
SDL_AddDisplayMode(display, mode);
SDL_DFB_LOG("Mode %d x %d Added\n", mode->w, mode->h);
}
else
SDL_DFB_ERR("Mode %d x %d not available: %x\n", mode->w,
mode->h, failed);
return;
error:
return;
}
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
* the approach did work with the matrox driver
* This has simply no effect.
*/
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
/* FIXME: should we handle the error */
if (dispdata->vidIDinuse)
SDL_DFB_CHECK(dispdata->vidlayer->SwitchContext(dispdata->vidlayer,
DFB_TRUE));
#endif
}
void
DirectFB_InitModes(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
IDirectFBDisplayLayer *layer = NULL;
SDL_VideoDisplay display;
DFB_DisplayData *dispdata = NULL;
SDL_DisplayMode mode;
DFBGraphicsDeviceDescription caps;
DFBDisplayLayerConfig dlc;
struct screen_callback_t *screencbdata;
int tcw[DFB_MAX_SCREENS];
int tch[DFB_MAX_SCREENS];
int i;
DFBResult ret;
SDL_DFB_ALLOC_CLEAR(screencbdata, sizeof(*screencbdata));
screencbdata->numscreens = 0;
for (i = 0; i < DFB_MAX_SCREENS; i++) {
screencbdata->gralayer[i] = -1;
screencbdata->vidlayer[i] = -1;
}
SDL_DFB_CHECKERR(devdata->dfb->EnumScreens(devdata->dfb, &EnumScreensCallback,
screencbdata));
for (i = 0; i < screencbdata->numscreens; i++) {
IDirectFBScreen *screen;
SDL_DFB_CHECKERR(devdata->dfb->GetScreen(devdata->dfb,
screencbdata->screenid
[i], &screen));
screencbdata->aux = i;
SDL_DFB_CHECKERR(screen->EnumDisplayLayers(screen, &EnumLayersCallback,
screencbdata));
screen->GetSize(screen, &tcw[i], &tch[i]);
screen->Release(screen);
}
/* Query card capabilities */
devdata->dfb->GetDeviceDescription(devdata->dfb, &caps);
for (i = 0; i < screencbdata->numscreens; i++) {
SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb,
screencbdata->gralayer
[i], &layer));
SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer,
DLSCL_ADMINISTRATIVE));
layer->EnableCursor(layer, 1);
SDL_DFB_CHECKERR(layer->SetCursorOpacity(layer, 0xC0));
if (devdata->use_yuv_underlays) {
dlc.flags = DLCONF_PIXELFORMAT | DLCONF_OPTIONS;
dlc.pixelformat = DSPF_ARGB;
dlc.options = DLOP_ALPHACHANNEL;
ret = layer->SetConfiguration(layer, &dlc);
if (ret != DFB_OK) {
/* try AiRGB if the previous failed */
dlc.pixelformat = DSPF_AiRGB;
SDL_DFB_CHECKERR(layer->SetConfiguration(layer, &dlc));
}
}
/* Query layer configuration to determine the current mode and pixelformat */
dlc.flags = DLCONF_ALL;
SDL_DFB_CHECKERR(layer->GetConfiguration(layer, &dlc));
mode.format = DirectFB_DFBToSDLPixelFormat(dlc.pixelformat);
if (mode.format == SDL_PIXELFORMAT_UNKNOWN) {
SDL_DFB_ERR("Unknown dfb pixelformat %x !\n", dlc.pixelformat);
goto error;
}
mode.w = dlc.width;
mode.h = dlc.height;
mode.refresh_rate = 0;
mode.driverdata = NULL;
SDL_DFB_ALLOC_CLEAR(dispdata, sizeof(*dispdata));
dispdata->layer = layer;
dispdata->pixelformat = dlc.pixelformat;
dispdata->cw = tcw[i];
dispdata->ch = tch[i];
/* YUV - Video layer */
dispdata->vidID = screencbdata->vidlayer[i];
dispdata->vidIDinuse = 0;
SDL_zero(display);
display.desktop_mode = mode;
display.current_mode = mode;
display.driverdata = dispdata;
#if (DFB_VERSION_ATLEAST(1,2,0))
dlc.flags =
DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
DLCONF_OPTIONS;
ret = layer->SetConfiguration(layer, &dlc);
#endif
SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer, DLSCL_SHARED));
SDL_AddVideoDisplay(&display);
}
SDL_DFB_FREE(screencbdata);
return;
error:
/* FIXME: Cleanup not complete, Free existing displays */
SDL_DFB_FREE(dispdata);
SDL_DFB_RELEASE(layer);
return;
}
void
DirectFB_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{
SDL_DFB_DEVICEDATA(_this);
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
SDL_DisplayMode mode;
struct modes_callback_t data;
int i;
data.nummodes = 0;
/* Enumerate the available fullscreen modes */
SDL_DFB_CALLOC(data.modelist, DFB_MAX_MODES, sizeof(SDL_DisplayMode));
SDL_DFB_CHECKERR(devdata->dfb->EnumVideoModes(devdata->dfb,
EnumModesCallback, &data));
for (i = 0; i < data.nummodes; ++i) {
mode = data.modelist[i];
mode.format = SDL_PIXELFORMAT_ARGB8888;
CheckSetDisplayMode(_this, display, dispdata, &mode);
mode.format = SDL_PIXELFORMAT_RGB888;
CheckSetDisplayMode(_this, display, dispdata, &mode);
mode.format = SDL_PIXELFORMAT_RGB24;
CheckSetDisplayMode(_this, display, dispdata, &mode);
mode.format = SDL_PIXELFORMAT_RGB565;
CheckSetDisplayMode(_this, display, dispdata, &mode);
mode.format = SDL_PIXELFORMAT_INDEX8;
CheckSetDisplayMode(_this, display, dispdata, &mode);
}
SDL_DFB_FREE(data.modelist);
error:
return;
}
int
DirectFB_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
/*
* FIXME: video mode switch is currently broken for 1.2.0
*
*/
SDL_DFB_DEVICEDATA(_this);
DFB_DisplayData *data = (DFB_DisplayData *) display->driverdata;
DFBDisplayLayerConfig config, rconfig;
DFBDisplayLayerConfigFlags fail = 0;
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_ADMINISTRATIVE));
SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
config.flags = DLCONF_WIDTH | DLCONF_HEIGHT;
if (mode->format != SDL_PIXELFORMAT_UNKNOWN) {
config.flags |= DLCONF_PIXELFORMAT;
config.pixelformat = DirectFB_SDLToDFBPixelFormat(mode->format);
data->pixelformat = config.pixelformat;
}
config.width = mode->w;
config.height = mode->h;
if (devdata->use_yuv_underlays) {
config.flags |= DLCONF_OPTIONS;
config.options = DLOP_ALPHACHANNEL;
}
data->layer->TestConfiguration(data->layer, &config, &fail);
if (fail &
(DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
DLCONF_OPTIONS)) {
SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h,
mode->format);
return -1;
}
config.flags &= ~fail;
SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
#if (DFB_VERSION_ATLEAST(1,2,0))
/* Need to call this twice ! */
SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
#endif
/* Double check */
SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig));
SDL_DFB_CHECKERR(data->
layer->SetCooperativeLevel(data->layer, DLSCL_SHARED));
if ((config.width != rconfig.width) || (config.height != rconfig.height)
|| ((mode->format != SDL_PIXELFORMAT_UNKNOWN)
&& (config.pixelformat != rconfig.pixelformat))) {
SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h,
mode->format);
return -1;
}
data->pixelformat = rconfig.pixelformat;
data->cw = config.width;
data->ch = config.height;
display->current_mode = *mode;
return 0;
error:
return -1;
}
void
DirectFB_QuitModes(_THIS)
{
SDL_DisplayMode tmode;
int i;
for (i = 0; i < _this->num_displays; ++i) {
SDL_VideoDisplay *display = &_this->displays[i];
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
SDL_GetDesktopDisplayMode(i, &tmode);
tmode.format = SDL_PIXELFORMAT_UNKNOWN;
DirectFB_SetDisplayMode(_this, display, &tmode);
SDL_GetDesktopDisplayMode(i, &tmode);
DirectFB_SetDisplayMode(_this, display, &tmode);
if (dispdata->layer) {
SDL_DFB_CHECK(dispdata->
layer->SetCooperativeLevel(dispdata->layer,
DLSCL_ADMINISTRATIVE));
SDL_DFB_CHECK(dispdata->
layer->SetCursorOpacity(dispdata->layer, 0x00));
SDL_DFB_CHECK(dispdata->
layer->SetCooperativeLevel(dispdata->layer,
DLSCL_SHARED));
}
SDL_DFB_RELEASE(dispdata->layer);
SDL_DFB_RELEASE(dispdata->vidlayer);
}
}
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,59 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_directfb_modes_h_
#define SDL_directfb_modes_h_
#include <directfb.h>
#include "../SDL_sysvideo.h"
#define SDL_DFB_DISPLAYDATA(win) DFB_DisplayData *dispdata = ((win) ? (DFB_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata : NULL)
typedef struct _DFB_DisplayData DFB_DisplayData;
struct _DFB_DisplayData
{
IDirectFBDisplayLayer *layer;
DFBSurfacePixelFormat pixelformat;
/* FIXME: support for multiple video layer.
* However, I do not know any card supporting
* more than one
*/
DFBDisplayLayerID vidID;
IDirectFBDisplayLayer *vidlayer;
int vidIDinuse;
int cw;
int ch;
};
extern void DirectFB_InitModes(_THIS);
extern void DirectFB_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
extern int DirectFB_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
extern void DirectFB_QuitModes(_THIS);
extern void DirectFB_SetContext(_THIS, SDL_Window *window);
#endif /* SDL_directfb_modes_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,389 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_DIRECTFB
#include "SDL_assert.h"
#include "SDL_DirectFB_video.h"
#include "SDL_DirectFB_mouse.h"
#include "SDL_DirectFB_modes.h"
#include "SDL_DirectFB_window.h"
#include "../SDL_sysvideo.h"
#include "../../events/SDL_mouse_c.h"
static SDL_Cursor *DirectFB_CreateDefaultCursor(void);
static SDL_Cursor *DirectFB_CreateCursor(SDL_Surface * surface,
int hot_x, int hot_y);
static int DirectFB_ShowCursor(SDL_Cursor * cursor);
static void DirectFB_FreeCursor(SDL_Cursor * cursor);
static void DirectFB_WarpMouse(SDL_Window * window, int x, int y);
static const char *arrow[] = {
/* pixels */
"X ",
"XX ",
"X.X ",
"X..X ",
"X...X ",
"X....X ",
"X.....X ",
"X......X ",
"X.......X ",
"X........X ",
"X.....XXXXX ",
"X..X..X ",
"X.X X..X ",
"XX X..X ",
"X X..X ",
" X..X ",
" X..X ",
" X..X ",
" XX ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
};
static SDL_Cursor *
DirectFB_CreateDefaultCursor(void)
{
SDL_VideoDevice *dev = SDL_GetVideoDevice();
SDL_DFB_DEVICEDATA(dev);
DFB_CursorData *curdata;
DFBSurfaceDescription dsc;
SDL_Cursor *cursor;
Uint32 *dest;
int pitch, i, j;
SDL_DFB_ALLOC_CLEAR( cursor, sizeof(*cursor));
SDL_DFB_ALLOC_CLEAR(curdata, sizeof(*curdata));
dsc.flags =
DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
dsc.caps = DSCAPS_VIDEOONLY;
dsc.width = 32;
dsc.height = 32;
dsc.pixelformat = DSPF_ARGB;
SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
&curdata->surf));
curdata->hotx = 0;
curdata->hoty = 0;
cursor->driverdata = curdata;
SDL_DFB_CHECKERR(curdata->surf->Lock(curdata->surf, DSLF_WRITE,
(void *) &dest, &pitch));
/* Relies on the fact that this is only called with ARGB surface. */
for (i = 0; i < 32; i++)
{
for (j = 0; j < 32; j++)
{
switch (arrow[i][j])
{
case ' ': dest[j] = 0x00000000; break;
case '.': dest[j] = 0xffffffff; break;
case 'X': dest[j] = 0xff000000; break;
}
}
dest += (pitch >> 2);
}
curdata->surf->Unlock(curdata->surf);
return cursor;
error:
return NULL;
}
/* Create a cursor from a surface */
static SDL_Cursor *
DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
{
SDL_VideoDevice *dev = SDL_GetVideoDevice();
SDL_DFB_DEVICEDATA(dev);
DFB_CursorData *curdata;
DFBSurfaceDescription dsc;
SDL_Cursor *cursor;
Uint32 *dest;
Uint32 *p;
int pitch, i;
SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
SDL_assert(surface->pitch == surface->w * 4);
SDL_DFB_ALLOC_CLEAR( cursor, sizeof(*cursor));
SDL_DFB_ALLOC_CLEAR(curdata, sizeof(*curdata));
dsc.flags =
DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
dsc.caps = DSCAPS_VIDEOONLY;
dsc.width = surface->w;
dsc.height = surface->h;
dsc.pixelformat = DSPF_ARGB;
SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
&curdata->surf));
curdata->hotx = hot_x;
curdata->hoty = hot_y;
cursor->driverdata = curdata;
SDL_DFB_CHECKERR(curdata->surf->Lock(curdata->surf, DSLF_WRITE,
(void *) &dest, &pitch));
p = surface->pixels;
for (i = 0; i < surface->h; i++)
memcpy((char *) dest + i * pitch,
(char *) p + i * surface->pitch, 4 * surface->w);
curdata->surf->Unlock(curdata->surf);
return cursor;
error:
return NULL;
}
/* Show the specified cursor, or hide if cursor is NULL */
static int
DirectFB_ShowCursor(SDL_Cursor * cursor)
{
SDL_DFB_CURSORDATA(cursor);
SDL_Window *window;
window = SDL_GetFocusWindow();
if (!window)
return -1;
else {
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
if (display) {
DFB_DisplayData *dispdata =
(DFB_DisplayData *) display->driverdata;
DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
if (cursor)
SDL_DFB_CHECKERR(windata->dfbwin->
SetCursorShape(windata->dfbwin,
curdata->surf, curdata->hotx,
curdata->hoty));
SDL_DFB_CHECKERR(dispdata->layer->
SetCooperativeLevel(dispdata->layer,
DLSCL_ADMINISTRATIVE));
SDL_DFB_CHECKERR(dispdata->layer->
SetCursorOpacity(dispdata->layer,
cursor ? 0xC0 : 0x00));
SDL_DFB_CHECKERR(dispdata->layer->
SetCooperativeLevel(dispdata->layer,
DLSCL_SHARED));
}
}
return 0;
error:
return -1;
}
/* Free a window manager cursor */
static void
DirectFB_FreeCursor(SDL_Cursor * cursor)
{
SDL_DFB_CURSORDATA(cursor);
SDL_DFB_RELEASE(curdata->surf);
SDL_DFB_FREE(cursor->driverdata);
SDL_DFB_FREE(cursor);
}
/* Warp the mouse to (x,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;
DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
int cx, cy;
SDL_DFB_CHECKERR(windata->dfbwin->GetPosition(windata->dfbwin, &cx, &cy));
SDL_DFB_CHECKERR(dispdata->layer->WarpCursor(dispdata->layer,
cx + x + windata->client.x,
cy + y + windata->client.y));
error:
return;
}
#if USE_MULTI_API
static void DirectFB_MoveCursor(SDL_Cursor * cursor);
static void DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_Window * window,
int x, int y);
static void DirectFB_FreeMouse(SDL_Mouse * mouse);
static int id_mask;
static DFBEnumerationResult
EnumMice(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
void *callbackdata)
{
DFB_DeviceData *devdata = callbackdata;
if ((desc.type & DIDTF_MOUSE) && (device_id & id_mask)) {
SDL_Mouse mouse;
SDL_zero(mouse);
mouse.id = device_id;
mouse.CreateCursor = DirectFB_CreateCursor;
mouse.ShowCursor = DirectFB_ShowCursor;
mouse.MoveCursor = DirectFB_MoveCursor;
mouse.FreeCursor = DirectFB_FreeCursor;
mouse.WarpMouse = DirectFB_WarpMouse;
mouse.FreeMouse = DirectFB_FreeMouse;
mouse.cursor_shown = 1;
SDL_AddMouse(&mouse, desc.name, 0, 0, 1);
devdata->mouse_id[devdata->num_mice++] = device_id;
}
return DFENUM_OK;
}
void
DirectFB_InitMouse(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
devdata->num_mice = 0;
if (devdata->use_linux_input) {
/* try non-core devices first */
id_mask = 0xF0;
devdata->dfb->EnumInputDevices(devdata->dfb, EnumMice, devdata);
if (devdata->num_mice == 0) {
/* try core devices */
id_mask = 0x0F;
devdata->dfb->EnumInputDevices(devdata->dfb, EnumMice, devdata);
}
}
if (devdata->num_mice == 0) {
SDL_Mouse mouse;
SDL_zero(mouse);
mouse.CreateCursor = DirectFB_CreateCursor;
mouse.ShowCursor = DirectFB_ShowCursor;
mouse.MoveCursor = DirectFB_MoveCursor;
mouse.FreeCursor = DirectFB_FreeCursor;
mouse.WarpMouse = DirectFB_WarpMouse;
mouse.FreeMouse = DirectFB_FreeMouse;
mouse.cursor_shown = 1;
SDL_AddMouse(&mouse, "Mouse", 0, 0, 1);
devdata->num_mice = 1;
}
}
void
DirectFB_QuitMouse(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
if (devdata->use_linux_input) {
SDL_MouseQuit();
} else {
SDL_DelMouse(0);
}
}
/* This is called when a mouse motion event occurs */
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)
{
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
DFBResult ret;
int cx, cy;
SDL_DFB_CHECKERR(windata->dfbwin->GetPosition(windata->dfbwin, &cx, &cy));
SDL_DFB_CHECKERR(dispdata->layer->WarpCursor(dispdata->layer,
cx + x + windata->client.x,
cy + y + windata->client.y));
error:
return;
}
/* Free the mouse when it's time */
static void
DirectFB_FreeMouse(SDL_Mouse * mouse)
{
/* nothing yet */
}
#else /* USE_MULTI_API */
void
DirectFB_InitMouse(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
SDL_Mouse *mouse = SDL_GetMouse();
mouse->CreateCursor = DirectFB_CreateCursor;
mouse->ShowCursor = DirectFB_ShowCursor;
mouse->WarpMouse = DirectFB_WarpMouse;
mouse->FreeCursor = DirectFB_FreeCursor;
SDL_SetDefaultCursor(DirectFB_CreateDefaultCursor());
devdata->num_mice = 1;
}
void
DirectFB_QuitMouse(_THIS)
{
}
#endif
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,44 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_DirectFB_mouse_h_
#define SDL_DirectFB_mouse_h_
#include <directfb.h>
#include "../SDL_sysvideo.h"
typedef struct _DFB_CursorData DFB_CursorData;
struct _DFB_CursorData
{
IDirectFBSurface *surf;
int hotx;
int hoty;
};
#define SDL_DFB_CURSORDATA(curs) DFB_CursorData *curdata = (DFB_CursorData *) ((curs) ? (curs)->driverdata : NULL)
extern void DirectFB_InitMouse(_THIS);
extern void DirectFB_QuitMouse(_THIS);
#endif /* SDL_DirectFB_mouse_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,332 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_DIRECTFB
#include "SDL_DirectFB_video.h"
#if SDL_DIRECTFB_OPENGL
#include "SDL_DirectFB_opengl.h"
#include "SDL_DirectFB_window.h"
#include <directfbgl.h>
#include "SDL_loadso.h"
#endif
#if SDL_DIRECTFB_OPENGL
struct SDL_GLDriverData
{
int gl_active; /* to stop switching drivers while we have a valid context */
int initialized;
DirectFB_GLContext *firstgl; /* linked list */
/* OpenGL */
void (*glFinish) (void);
void (*glFlush) (void);
};
#define OPENGL_REQUIRS_DLOPEN
#if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
#include <dlfcn.h>
#define GL_LoadObject(X) dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
#define GL_LoadFunction dlsym
#define GL_UnloadObject dlclose
#else
#define GL_LoadObject SDL_LoadObject
#define GL_LoadFunction SDL_LoadFunction
#define GL_UnloadObject SDL_UnloadObject
#endif
static void DirectFB_GL_UnloadLibrary(_THIS);
int
DirectFB_GL_Initialize(_THIS)
{
if (_this->gl_data) {
return 0;
}
_this->gl_data =
(struct SDL_GLDriverData *) SDL_calloc(1,
sizeof(struct
SDL_GLDriverData));
if (!_this->gl_data) {
return SDL_OutOfMemory();
}
_this->gl_data->initialized = 0;
++_this->gl_data->initialized;
_this->gl_data->firstgl = NULL;
if (DirectFB_GL_LoadLibrary(_this, NULL) < 0) {
return -1;
}
/* Initialize extensions */
/* FIXME needed?
* X11_GL_InitExtensions(_this);
*/
return 0;
}
void
DirectFB_GL_Shutdown(_THIS)
{
if (!_this->gl_data || (--_this->gl_data->initialized > 0)) {
return;
}
DirectFB_GL_UnloadLibrary(_this);
SDL_free(_this->gl_data);
_this->gl_data = NULL;
}
int
DirectFB_GL_LoadLibrary(_THIS, const char *path)
{
void *handle = NULL;
SDL_DFB_DEBUG("Loadlibrary : %s\n", path);
if (_this->gl_data->gl_active) {
return SDL_SetError("OpenGL context already created");
}
if (path == NULL) {
path = SDL_getenv("SDL_OPENGL_LIBRARY");
if (path == NULL) {
path = "libGL.so.1";
}
}
handle = GL_LoadObject(path);
if (handle == NULL) {
SDL_DFB_ERR("Library not found: %s\n", path);
/* SDL_LoadObject() will call SDL_SetError() for us. */
return -1;
}
SDL_DFB_DEBUG("Loaded library: %s\n", path);
_this->gl_config.dll_handle = handle;
if (path) {
SDL_strlcpy(_this->gl_config.driver_path, path,
SDL_arraysize(_this->gl_config.driver_path));
} else {
*_this->gl_config.driver_path = '\0';
}
_this->gl_data->glFinish = DirectFB_GL_GetProcAddress(_this, "glFinish");
_this->gl_data->glFlush = DirectFB_GL_GetProcAddress(_this, "glFlush");
return 0;
}
static void
DirectFB_GL_UnloadLibrary(_THIS)
{
#if 0
int ret = GL_UnloadObject(_this->gl_config.dll_handle);
if (ret)
SDL_DFB_ERR("Error #%d trying to unload library.\n", ret);
_this->gl_config.dll_handle = NULL;
#endif
/* Free OpenGL memory */
SDL_free(_this->gl_data);
_this->gl_data = NULL;
}
void *
DirectFB_GL_GetProcAddress(_THIS, const char *proc)
{
void *handle;
handle = _this->gl_config.dll_handle;
return GL_LoadFunction(handle, proc);
}
SDL_GLContext
DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
DirectFB_GLContext *context;
SDL_DFB_ALLOC_CLEAR(context, sizeof(DirectFB_GLContext));
SDL_DFB_CHECKERR(windata->surface->GetGL(windata->surface,
&context->context));
if (!context->context)
return NULL;
context->is_locked = 0;
context->sdl_window = window;
context->next = _this->gl_data->firstgl;
_this->gl_data->firstgl = context;
SDL_DFB_CHECK(context->context->Unlock(context->context));
if (DirectFB_GL_MakeCurrent(_this, window, context) < 0) {
DirectFB_GL_DeleteContext(_this, context);
return NULL;
}
return context;
error:
return NULL;
}
int
DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{
DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
DirectFB_GLContext *p;
for (p = _this->gl_data->firstgl; p; p = p->next)
{
if (p->is_locked) {
SDL_DFB_CHECKERR(p->context->Unlock(p->context));
p->is_locked = 0;
}
}
if (ctx != NULL) {
SDL_DFB_CHECKERR(ctx->context->Lock(ctx->context));
ctx->is_locked = 1;
}
return 0;
error:
return -1;
}
int
DirectFB_GL_SetSwapInterval(_THIS, int interval)
{
return SDL_Unsupported();
}
int
DirectFB_GL_GetSwapInterval(_THIS)
{
return 0;
}
int
DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
{
SDL_DFB_WINDOWDATA(window);
DirectFB_GLContext *p;
#if 0
if (devdata->glFinish)
devdata->glFinish();
else if (devdata->glFlush)
devdata->glFlush();
#endif
for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
if (p->sdl_window == window && p->is_locked)
{
SDL_DFB_CHECKERR(p->context->Unlock(p->context));
p->is_locked = 0;
}
SDL_DFB_CHECKERR(windata->window_surface->Flip(windata->window_surface,NULL, DSFLIP_PIPELINE |DSFLIP_BLIT | DSFLIP_ONSYNC ));
return 0;
error:
return -1;
}
void
DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context)
{
DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
DirectFB_GLContext *p;
if (ctx->is_locked)
SDL_DFB_CHECK(ctx->context->Unlock(ctx->context));
SDL_DFB_RELEASE(ctx->context);
for (p = _this->gl_data->firstgl; p && p->next != ctx; p = p->next)
;
if (p)
p->next = ctx->next;
else
_this->gl_data->firstgl = ctx->next;
SDL_DFB_FREE(ctx);
}
void
DirectFB_GL_FreeWindowContexts(_THIS, SDL_Window * window)
{
DirectFB_GLContext *p;
for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
if (p->sdl_window == window)
{
if (p->is_locked)
SDL_DFB_CHECK(p->context->Unlock(p->context));
SDL_DFB_RELEASE(p->context);
}
}
void
DirectFB_GL_ReAllocWindowContexts(_THIS, SDL_Window * window)
{
DirectFB_GLContext *p;
for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
if (p->sdl_window == window)
{
SDL_DFB_WINDOWDATA(window);
SDL_DFB_CHECK(windata->surface->GetGL(windata->surface,
&p->context));
if (p->is_locked)
SDL_DFB_CHECK(p->context->Lock(p->context));
}
}
void
DirectFB_GL_DestroyWindowContexts(_THIS, SDL_Window * window)
{
DirectFB_GLContext *p;
for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
if (p->sdl_window == window)
DirectFB_GL_DeleteContext(_this, p);
}
#endif
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -0,0 +1,64 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_directfb_opengl_h_
#define SDL_directfb_opengl_h_
#include "SDL_DirectFB_video.h"
#if SDL_DIRECTFB_OPENGL
#include "SDL_opengl.h"
typedef struct _DirectFB_GLContext DirectFB_GLContext;
struct _DirectFB_GLContext
{
IDirectFBGL *context;
DirectFB_GLContext *next;
SDL_Window *sdl_window;
int is_locked;
};
/* OpenGL functions */
extern int DirectFB_GL_Initialize(_THIS);
extern void DirectFB_GL_Shutdown(_THIS);
extern int DirectFB_GL_LoadLibrary(_THIS, const char *path);
extern void *DirectFB_GL_GetProcAddress(_THIS, const char *proc);
extern SDL_GLContext DirectFB_GL_CreateContext(_THIS, SDL_Window * window);
extern int DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window,
SDL_GLContext context);
extern int DirectFB_GL_SetSwapInterval(_THIS, int interval);
extern int DirectFB_GL_GetSwapInterval(_THIS);
extern int DirectFB_GL_SwapWindow(_THIS, SDL_Window * window);
extern void DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context);
extern void DirectFB_GL_FreeWindowContexts(_THIS, SDL_Window * window);
extern void DirectFB_GL_ReAllocWindowContexts(_THIS, SDL_Window * window);
extern void DirectFB_GL_DestroyWindowContexts(_THIS, SDL_Window * window);
#endif /* SDL_DIRECTFB_OPENGL */
#endif /* SDL_directfb_opengl_h_ */
/* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 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
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* SDL surface based renderer implementation */
/* vi: set ts=4 sw=4 expandtab: */

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