Update to SDL2.0.10

This commit is contained in:
Areloch 2019-08-19 23:30:35 -05:00
parent 600859bd63
commit c932bda8dd
915 changed files with 116675 additions and 21754 deletions

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -1220,8 +1220,9 @@ RLEAlphaSurface(SDL_Surface * surface)
/* Now that we have it encoded, release the original pixels */
if (!(surface->flags & SDL_PREALLOC)) {
SDL_free(surface->pixels);
SDL_SIMDFree(surface->pixels);
surface->pixels = NULL;
surface->flags &= ~SDL_SIMD_ALIGNED;
}
/* realloc the buffer to release unused memory */
@ -1383,8 +1384,9 @@ RLEColorkeySurface(SDL_Surface * surface)
/* Now that we have it encoded, release the original pixels */
if (!(surface->flags & SDL_PREALLOC)) {
SDL_free(surface->pixels);
SDL_SIMDFree(surface->pixels);
surface->pixels = NULL;
surface->flags &= ~SDL_SIMD_ALIGNED;
}
/* realloc the buffer to release unused memory */
@ -1484,10 +1486,11 @@ UnRLEAlpha(SDL_Surface * surface)
uncopy_opaque = uncopy_transl = uncopy_32;
}
surface->pixels = SDL_malloc(surface->h * surface->pitch);
surface->pixels = SDL_SIMDAlloc(surface->h * surface->pitch);
if (!surface->pixels) {
return (SDL_FALSE);
}
surface->flags |= SDL_SIMD_ALIGNED;
/* fill background with transparent pixels */
SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
@ -1510,8 +1513,9 @@ UnRLEAlpha(SDL_Surface * surface)
if (run) {
srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
ofs += run;
} else if (!ofs)
return (SDL_TRUE);
} else if (!ofs) {
goto end_function;
}
} while (ofs < w);
/* skip padding if needed */
@ -1532,7 +1536,8 @@ UnRLEAlpha(SDL_Surface * surface)
} while (ofs < w);
dst += surface->pitch >> 2;
}
/* Make the compiler happy */
end_function:
return (SDL_TRUE);
}
@ -1547,12 +1552,13 @@ SDL_UnRLESurface(SDL_Surface * surface, int recode)
SDL_Rect full;
/* re-create the original surface */
surface->pixels = SDL_malloc(surface->h * surface->pitch);
surface->pixels = SDL_SIMDAlloc(surface->h * surface->pitch);
if (!surface->pixels) {
/* Oh crap... */
surface->flags |= SDL_RLEACCEL;
return;
}
surface->flags |= SDL_SIMD_ALIGNED;
/* fill it with the background color */
SDL_FillRect(surface, NULL, surface->map->info.colorkey);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -18,6 +18,10 @@
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 */
@ -28,4 +32,7 @@ extern int SDLCALL SDL_RLEBlit (SDL_Surface * src, SDL_Rect * srcrect,
extern int SDLCALL SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect);
extern void SDL_UnRLESurface(SDL_Surface * surface, int recode);
#endif /* SDL_RLEaccel_c_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -126,7 +126,7 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface * surface);
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)]; \
@ -262,18 +262,18 @@ do { \
{ \
switch (bpp) { \
case 1: { \
Uint8 Pixel; \
Uint8 _Pixel; \
\
PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \
*((Uint8 *)(buf)) = Pixel; \
PIXEL_FROM_RGB(_Pixel, fmt, r, g, b); \
*((Uint8 *)(buf)) = _Pixel; \
} \
break; \
\
case 2: { \
Uint16 Pixel; \
Uint16 _Pixel; \
\
PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \
*((Uint16 *)(buf)) = Pixel; \
PIXEL_FROM_RGB(_Pixel, fmt, r, g, b); \
*((Uint16 *)(buf)) = _Pixel; \
} \
break; \
\
@ -291,10 +291,10 @@ do { \
break; \
\
case 4: { \
Uint32 Pixel; \
Uint32 _Pixel; \
\
PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \
*((Uint32 *)(buf)) = Pixel; \
PIXEL_FROM_RGB(_Pixel, fmt, r, g, b); \
*((Uint32 *)(buf)) = _Pixel; \
} \
break; \
} \

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -49,13 +49,13 @@ Blit1to1(SDL_BlitInfo * info)
while (height--) {
#ifdef USE_DUFFS_LOOP
/* *INDENT-OFF* */
DUFFS_LOOP(
{
*dst = map[*src];
}
dst++;
src++;
, width);
DUFFS_LOOP(
{
*dst = map[*src];
}
dst++;
src++;
, width);
/* *INDENT-ON* */
#else
for (c = width; c; --c) {
@ -72,11 +72,11 @@ Blit1to1(SDL_BlitInfo * info)
/* This is now endian dependent */
#ifndef USE_DUFFS_LOOP
# if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )
# define HI 1
# define LO 0
# define HI 1
# define LO 0
# else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */
# define HI 0
# define LO 1
# define HI 0
# define LO 1
# endif
#endif
static void
@ -101,14 +101,14 @@ Blit1to2(SDL_BlitInfo * info)
#ifdef USE_DUFFS_LOOP
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
*(Uint16 *)dst = map[*src++];
dst += 2;
},
width);
/* *INDENT-ON* */
/* *INDENT-OFF* */
DUFFS_LOOP(
{
*(Uint16 *)dst = map[*src++];
dst += 2;
},
width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
@ -208,18 +208,18 @@ Blit1to3(SDL_BlitInfo * info)
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* */
/* *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;
@ -257,11 +257,11 @@ Blit1to4(SDL_BlitInfo * info)
while (height--) {
#ifdef USE_DUFFS_LOOP
/* *INDENT-OFF* */
DUFFS_LOOP(
*dst++ = map[*src++];
, width);
/* *INDENT-ON* */
/* *INDENT-OFF* */
DUFFS_LOOP(
*dst++ = map[*src++];
, width);
/* *INDENT-ON* */
#else
for (c = width / 4; c; --c) {
*dst++ = map[*src++];
@ -297,33 +297,33 @@ Blit1to1Key(SDL_BlitInfo * info)
if (palmap) {
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ( *src != ckey ) {
*dst = palmap[*src];
}
dst++;
src++;
},
width);
/* *INDENT-ON* */
/* *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* */
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ( *src != ckey ) {
*dst = *src;
}
dst++;
src++;
},
width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
@ -346,17 +346,17 @@ Blit1to2Key(SDL_BlitInfo * info)
dstskip /= 2;
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ( *src != ckey ) {
*dstp=palmap[*src];
}
src++;
dstp++;
},
width);
/* *INDENT-ON* */
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ( *src != ckey ) {
*dstp=palmap[*src];
}
src++;
dstp++;
},
width);
/* *INDENT-ON* */
src += srcskip;
dstp += dstskip;
}
@ -376,20 +376,20 @@ Blit1to3Key(SDL_BlitInfo * info)
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* */
/* *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;
}
@ -411,17 +411,17 @@ Blit1to4Key(SDL_BlitInfo * info)
dstskip /= 4;
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ( *src != ckey ) {
*dstp = palmap[*src];
}
src++;
dstp++;
},
width);
/* *INDENT-ON* */
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ( *src != ckey ) {
*dstp = palmap[*src];
}
src++;
dstp++;
},
width);
/* *INDENT-ON* */
src += srcskip;
dstp += dstskip;
}
@ -489,22 +489,22 @@ Blit1toNAlphaKey(SDL_BlitInfo * info)
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* */
/* *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;
}

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -27,6 +27,15 @@
#include "SDL_assert.h"
/* General optimized routines that write char by char */
#define HAVE_FAST_WRITE_INT8 1
/* On some CPU, it's slower than combining and write a word */
#if defined(__MIPS__)
# undef HAVE_FAST_WRITE_INT8
# define HAVE_FAST_WRITE_INT8 0
#endif
/* Functions to blit from N-bit surfaces to other surfaces */
#if SDL_ALTIVEC_BLITTERS
@ -2149,6 +2158,88 @@ Blit4to4CopyAlpha(SDL_BlitInfo * info)
}
}
/* permutation for mapping srcfmt to dstfmt, overloading or not the alpha channel */
static void
get_permutation(SDL_PixelFormat *srcfmt, SDL_PixelFormat *dstfmt,
int *_p0 , int *_p1, int *_p2, int *_p3, int *_alpha_channel)
{
int alpha_channel = 0, p0, p1, p2, p3;
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
int Pixel = 0x04030201; /* identity permutation */
#else
int Pixel = 0x01020304; /* identity permutation */
int srcbpp = srcfmt->BytesPerPixel;
int dstbpp = dstfmt->BytesPerPixel;
#endif
if (srcfmt->Amask) {
RGBA_FROM_PIXEL(Pixel, srcfmt, p0, p1, p2, p3);
} else {
RGB_FROM_PIXEL(Pixel, srcfmt, p0, p1, p2);
p3 = 0;
}
if (dstfmt->Amask) {
if (srcfmt->Amask) {
PIXEL_FROM_RGBA(Pixel, dstfmt, p0, p1, p2, p3);
} else {
PIXEL_FROM_RGBA(Pixel, dstfmt, p0, p1, p2, 0);
}
} else {
PIXEL_FROM_RGB(Pixel, dstfmt, p0, p1, p2);
}
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
p0 = Pixel & 0xFF;
p1 = (Pixel >> 8) & 0xFF;
p2 = (Pixel >> 16) & 0xFF;
p3 = (Pixel >> 24) & 0xFF;
#else
p3 = Pixel & 0xFF;
p2 = (Pixel >> 8) & 0xFF;
p1 = (Pixel >> 16) & 0xFF;
p0 = (Pixel >> 24) & 0xFF;
#endif
if (p0 == 0) {
p0 = 1;
alpha_channel = 0;
} else if (p1 == 0) {
p1 = 1;
alpha_channel = 1;
} else if (p2 == 0) {
p2 = 1;
alpha_channel = 2;
} else if (p3 == 0) {
p3 = 1;
alpha_channel = 3;
}
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#else
if (srcbpp == 3 && dstbpp == 4) {
if (p0 != 1) p0--;
if (p1 != 1) p1--;
if (p2 != 1) p2--;
if (p3 != 1) p3--;
} else if (srcbpp == 4 && dstbpp == 3) {
p0 = p1;
p1 = p2;
p2 = p3;
}
#endif
*_p0 = p0 - 1;
*_p1 = p1 - 1;
*_p2 = p2 - 1;
*_p3 = p3 - 1;
if (_alpha_channel) {
*_alpha_channel = alpha_channel;
}
return;
}
static void
BlitNtoN(SDL_BlitInfo * info)
{
@ -2164,6 +2255,90 @@ BlitNtoN(SDL_BlitInfo * info)
int dstbpp = dstfmt->BytesPerPixel;
unsigned alpha = dstfmt->Amask ? info->a : 0;
#if HAVE_FAST_WRITE_INT8
/* Blit with permutation: 4->4 */
if (srcbpp == 4 && dstbpp == 4 &&
srcfmt->format != SDL_PIXELFORMAT_ARGB2101010 &&
dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
/* Find the appropriate permutation */
int alpha_channel, p0, p1, p2, p3;
get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
dst[0] = src[p0];
dst[1] = src[p1];
dst[2] = src[p2];
dst[3] = src[p3];
dst[alpha_channel] = alpha;
src += 4;
dst += 4;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
return;
}
#endif
/* Blit with permutation: 4->3 */
if (srcbpp == 4 && dstbpp == 3 &&
srcfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
/* Find the appropriate permutation */
int p0, p1, p2, p3;
get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
dst[0] = src[p0];
dst[1] = src[p1];
dst[2] = src[p2];
src += 4;
dst += 3;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
return;
}
#if HAVE_FAST_WRITE_INT8
/* Blit with permutation: 3->4 */
if (srcbpp == 3 && dstbpp == 4 &&
dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
/* Find the appropriate permutation */
int alpha_channel, p0, p1, p2, p3;
get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
dst[0] = src[p0];
dst[1] = src[p1];
dst[2] = src[p2];
dst[3] = src[p3];
dst[alpha_channel] = alpha;
src += 3;
dst += 4;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
return;
}
#endif
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
@ -2199,6 +2374,35 @@ BlitNtoNCopyAlpha(SDL_BlitInfo * info)
int dstbpp = dstfmt->BytesPerPixel;
int c;
#if HAVE_FAST_WRITE_INT8
/* Blit with permutation: 4->4 */
if (srcbpp == 4 && dstbpp == 4 &&
srcfmt->format != SDL_PIXELFORMAT_ARGB2101010 &&
dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
/* Find the appropriate permutation */
int p0, p1, p2, p3;
get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
dst[0] = src[p0];
dst[1] = src[p1];
dst[2] = src[p2];
dst[3] = src[p3];
src += 4;
dst += 4;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
return;
}
#endif
while (height--) {
for (c = width; c; --c) {
Uint32 Pixel;
@ -2329,10 +2533,239 @@ BlitNtoNKey(SDL_BlitInfo * info)
int dstbpp = dstfmt->BytesPerPixel;
unsigned alpha = dstfmt->Amask ? info->a : 0;
Uint32 rgbmask = ~srcfmt->Amask;
int sfmt = srcfmt->format;
int dfmt = dstfmt->format;
/* Set up some basic variables */
ckey &= rgbmask;
/* BPP 4, same rgb */
if (srcbpp == 4 && dstbpp == 4 && srcfmt->Rmask == dstfmt->Rmask && srcfmt->Gmask == dstfmt->Gmask && srcfmt->Bmask == dstfmt->Bmask) {
Uint32 *src32 = (Uint32*)src;
Uint32 *dst32 = (Uint32*)dst;
if (dstfmt->Amask) {
/* RGB->RGBA, SET_ALPHA */
Uint32 mask = info->a << dstfmt->Ashift;
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ((*src32 & rgbmask) != ckey) {
*dst32 = *src32 | mask;
}
++dst32;
++src32;
}, width);
/* *INDENT-ON* */
src32 = (Uint32 *) ((Uint8 *) src32 + srcskip);
dst32 = (Uint32 *) ((Uint8 *) dst32 + dstskip);
}
return;
} else {
/* RGBA->RGB, NO_ALPHA */
Uint32 mask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ((*src32 & rgbmask) != ckey) {
*dst32 = *src32 & mask;
}
++dst32;
++src32;
}, width);
/* *INDENT-ON* */
src32 = (Uint32 *) ((Uint8 *) src32 + srcskip);
dst32 = (Uint32 *) ((Uint8 *) dst32 + dstskip);
}
return;
}
}
#if HAVE_FAST_WRITE_INT8
/* Blit with permutation: 4->4 */
if (srcbpp == 4 && dstbpp == 4 &&
srcfmt->format != SDL_PIXELFORMAT_ARGB2101010 &&
dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
/* Find the appropriate permutation */
int alpha_channel, p0, p1, p2, p3;
get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
Uint32 *src32 = (Uint32*)src;
if ((*src32 & rgbmask) != ckey) {
dst[0] = src[p0];
dst[1] = src[p1];
dst[2] = src[p2];
dst[3] = src[p3];
dst[alpha_channel] = alpha;
}
src += 4;
dst += 4;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
return;
}
#endif
/* BPP 3, same rgb triplet */
if ((sfmt == SDL_PIXELFORMAT_RGB24 && dfmt == SDL_PIXELFORMAT_RGB24) ||
(sfmt == SDL_PIXELFORMAT_BGR24 && dfmt == SDL_PIXELFORMAT_BGR24)) {
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
Uint8 k0 = ckey & 0xFF;
Uint8 k1 = (ckey >> 8) & 0xFF;
Uint8 k2 = (ckey >> 16) & 0xFF;
#else
Uint8 k0 = (ckey >> 16) & 0xFF;
Uint8 k1 = (ckey >> 8) & 0xFF;
Uint8 k2 = ckey & 0xFF;
#endif
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
Uint8 s0 = src[0];
Uint8 s1 = src[1];
Uint8 s2 = src[2];
if (k0 != s0 || k1 != s1 || k2 != s2) {
dst[0] = s0;
dst[1] = s1;
dst[2] = s2;
}
src += 3;
dst += 3;
},
width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
return;
}
/* BPP 3, inversed rgb triplet */
if ((sfmt == SDL_PIXELFORMAT_RGB24 && dfmt == SDL_PIXELFORMAT_BGR24) ||
(sfmt == SDL_PIXELFORMAT_BGR24 && dfmt == SDL_PIXELFORMAT_RGB24)) {
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
Uint8 k0 = ckey & 0xFF;
Uint8 k1 = (ckey >> 8) & 0xFF;
Uint8 k2 = (ckey >> 16) & 0xFF;
#else
Uint8 k0 = (ckey >> 16) & 0xFF;
Uint8 k1 = (ckey >> 8) & 0xFF;
Uint8 k2 = ckey & 0xFF;
#endif
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
Uint8 s0 = src[0];
Uint8 s1 = src[1];
Uint8 s2 = src[2];
if (k0 != s0 || k1 != s1 || k2 != s2) {
/* Inversed RGB */
dst[0] = s2;
dst[1] = s1;
dst[2] = s0;
}
src += 3;
dst += 3;
},
width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
return;
}
/* Blit with permutation: 4->3 */
if (srcbpp == 4 && dstbpp == 3 &&
srcfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
/* Find the appropriate permutation */
int p0, p1, p2, p3;
get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
Uint32 *src32 = (Uint32*)src;
if ((*src32 & rgbmask) != ckey) {
dst[0] = src[p0];
dst[1] = src[p1];
dst[2] = src[p2];
}
src += 4;
dst += 3;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
return;
}
#if HAVE_FAST_WRITE_INT8
/* Blit with permutation: 3->4 */
if (srcbpp == 3 && dstbpp == 4 &&
dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
Uint8 k0 = ckey & 0xFF;
Uint8 k1 = (ckey >> 8) & 0xFF;
Uint8 k2 = (ckey >> 16) & 0xFF;
#else
Uint8 k0 = (ckey >> 16) & 0xFF;
Uint8 k1 = (ckey >> 8) & 0xFF;
Uint8 k2 = ckey & 0xFF;
#endif
/* Find the appropriate permutation */
int alpha_channel, p0, p1, p2, p3;
get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
Uint8 s0 = src[0];
Uint8 s1 = src[1];
Uint8 s2 = src[2];
if (k0 != s0 || k1 != s1 || k2 != s2) {
dst[0] = src[p0];
dst[1] = src[p1];
dst[2] = src[p2];
dst[3] = src[p3];
dst[alpha_channel] = alpha;
}
src += 3;
dst += 4;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
return;
}
#endif
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
@ -2380,6 +2813,67 @@ BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info)
dstbpp = dstfmt->BytesPerPixel;
ckey &= rgbmask;
/* Fastpath: same source/destination format, with Amask, bpp 32, loop is vectorized. ~10x faster */
if (srcfmt->format == dstfmt->format) {
if (srcfmt->format == SDL_PIXELFORMAT_ARGB8888 ||
srcfmt->format == SDL_PIXELFORMAT_ABGR8888 ||
srcfmt->format == SDL_PIXELFORMAT_BGRA8888 ||
srcfmt->format == SDL_PIXELFORMAT_RGBA8888) {
Uint32 *src32 = (Uint32*)src;
Uint32 *dst32 = (Uint32*)dst;
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
if ((*src32 & rgbmask) != ckey) {
*dst32 = *src32;
}
++src32;
++dst32;
},
width);
/* *INDENT-ON* */
src32 = (Uint32 *)((Uint8 *)src32 + srcskip);
dst32 = (Uint32 *)((Uint8 *)dst32 + dstskip);
}
}
return;
}
#if HAVE_FAST_WRITE_INT8
/* Blit with permutation: 4->4 */
if (srcbpp == 4 && dstbpp == 4 &&
srcfmt->format != SDL_PIXELFORMAT_ARGB2101010 &&
dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
/* Find the appropriate permutation */
int p0, p1, p2, p3;
get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
Uint32 *src32 = (Uint32*)src;
if ((*src32 & rgbmask) != ckey) {
dst[0] = src[p0];
dst[1] = src[p1];
dst[2] = src[p2];
dst[3] = src[p3];
}
src += 4;
dst += 4;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
return;
}
#endif
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
@ -2462,6 +2956,186 @@ BlitNto2101010(SDL_BlitInfo * info)
}
}
/* Blit_3or4_to_3or4__same_rgb: 3 or 4 bpp, same RGB triplet */
static void
Blit_3or4_to_3or4__same_rgb(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 *srcfmt = info->src_fmt;
int srcbpp = srcfmt->BytesPerPixel;
SDL_PixelFormat *dstfmt = info->dst_fmt;
int dstbpp = dstfmt->BytesPerPixel;
if (dstfmt->Amask) {
/* SET_ALPHA */
Uint32 mask = info->a << dstfmt->Ashift;
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
int i0 = 0, i1 = 1, i2 = 2;
#else
int i0 = srcbpp - 1 - 0;
int i1 = srcbpp - 1 - 1;
int i2 = srcbpp - 1 - 2;
#endif
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
Uint32 *dst32 = (Uint32*)dst;
Uint8 s0 = src[i0];
Uint8 s1 = src[i1];
Uint8 s2 = src[i2];
*dst32 = (s0) | (s1 << 8) | (s2 << 16) | mask;
dst += 4;
src += srcbpp;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
} else {
/* NO_ALPHA */
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
int i0 = 0, i1 = 1, i2 = 2;
int j0 = 0, j1 = 1, j2 = 2;
#else
int i0 = srcbpp - 1 - 0;
int i1 = srcbpp - 1 - 1;
int i2 = srcbpp - 1 - 2;
int j0 = dstbpp - 1 - 0;
int j1 = dstbpp - 1 - 1;
int j2 = dstbpp - 1 - 2;
#endif
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
Uint8 s0 = src[i0];
Uint8 s1 = src[i1];
Uint8 s2 = src[i2];
dst[j0] = s0;
dst[j1] = s1;
dst[j2] = s2;
dst += dstbpp;
src += srcbpp;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
}
return;
}
/* Blit_3or4_to_3or4__inversed_rgb: 3 or 4 bpp, inversed RGB triplet */
static void
Blit_3or4_to_3or4__inversed_rgb(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 *srcfmt = info->src_fmt;
int srcbpp = srcfmt->BytesPerPixel;
SDL_PixelFormat *dstfmt = info->dst_fmt;
int dstbpp = dstfmt->BytesPerPixel;
if (dstfmt->Amask) {
if (srcfmt->Amask) {
/* COPY_ALPHA */
/* Only to switch ABGR8888 <-> ARGB8888 */
while (height--) {
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
int i0 = 0, i1 = 1, i2 = 2, i3 = 3;
#else
int i0 = 3, i1 = 2, i2 = 1, i3 = 0;
#endif
/* *INDENT-OFF* */
DUFFS_LOOP(
{
Uint32 *dst32 = (Uint32*)dst;
Uint8 s0 = src[i0];
Uint8 s1 = src[i1];
Uint8 s2 = src[i2];
Uint32 alphashift = src[i3] << dstfmt->Ashift;
/* inversed, compared to Blit_3or4_to_3or4__same_rgb */
*dst32 = (s0 << 16) | (s1 << 8) | (s2) | alphashift;
dst += 4;
src += 4;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
} else {
/* SET_ALPHA */
Uint32 mask = info->a << dstfmt->Ashift;
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
int i0 = 0, i1 = 1, i2 = 2;
#else
int i0 = srcbpp - 1 - 0;
int i1 = srcbpp - 1 - 1;
int i2 = srcbpp - 1 - 2;
#endif
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
Uint32 *dst32 = (Uint32*)dst;
Uint8 s0 = src[i0];
Uint8 s1 = src[i1];
Uint8 s2 = src[i2];
/* inversed, compared to Blit_3or4_to_3or4__same_rgb */
*dst32 = (s0 << 16) | (s1 << 8) | (s2) | mask;
dst += 4;
src += srcbpp;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
}
} else {
/* NO_ALPHA */
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
int i0 = 0, i1 = 1, i2 = 2;
int j0 = 2, j1 = 1, j2 = 0;
#else
int i0 = srcbpp - 1 - 0;
int i1 = srcbpp - 1 - 1;
int i2 = srcbpp - 1 - 2;
int j0 = dstbpp - 1 - 2;
int j1 = dstbpp - 1 - 1;
int j2 = dstbpp - 1 - 0;
#endif
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP(
{
Uint8 s0 = src[i0];
Uint8 s1 = src[i1];
Uint8 s2 = src[i2];
/* inversed, compared to Blit_3or4_to_3or4__same_rgb */
dst[j0] = s0;
dst[j1] = s1;
dst[j2] = s2;
dst += dstbpp;
src += srcbpp;
}, width);
/* *INDENT-ON* */
src += srcskip;
dst += dstskip;
}
}
return;
}
/* Normal N to N optimized blitters */
#define NO_ALPHA 1
#define SET_ALPHA 2
@ -2502,6 +3176,37 @@ static const struct blit_table normal_blit_2[] = {
};
static const struct blit_table normal_blit_3[] = {
/* 3->4 with same rgb triplet */
{0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
0, Blit_3or4_to_3or4__same_rgb,
#if HAVE_FAST_WRITE_INT8
NO_ALPHA |
#endif
SET_ALPHA},
{0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
0, Blit_3or4_to_3or4__same_rgb,
#if HAVE_FAST_WRITE_INT8
NO_ALPHA |
#endif
SET_ALPHA},
/* 3->4 with inversed rgb triplet */
{0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
0, Blit_3or4_to_3or4__inversed_rgb,
#if HAVE_FAST_WRITE_INT8
NO_ALPHA |
#endif
SET_ALPHA},
{0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
0, Blit_3or4_to_3or4__inversed_rgb,
#if HAVE_FAST_WRITE_INT8
NO_ALPHA |
#endif
SET_ALPHA},
/* 3->3 to switch RGB 24 <-> BGR 24 */
{0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x00FF0000, 0x0000FF00, 0x000000FF,
0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA },
{0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x000000FF, 0x0000FF00, 0x00FF0000,
0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA },
/* Default for 24-bit RGB source, never optimized */
{0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
};
@ -2518,6 +3223,30 @@ static const struct blit_table normal_blit_4[] = {
{0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0, 0x0000001F,
2, Blit_RGB888_RGB565Altivec, NO_ALPHA},
#endif
/* 4->3 with same rgb triplet */
{0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x000000FF, 0x0000FF00, 0x00FF0000,
0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA},
{0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x00FF0000, 0x0000FF00, 0x000000FF,
0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA},
/* 4->3 with inversed rgb triplet */
{0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x00FF0000, 0x0000FF00, 0x000000FF,
0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA},
{0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x000000FF, 0x0000FF00, 0x00FF0000,
0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA},
/* 4->4 with inversed rgb triplet, and COPY_ALPHA to switch ABGR8888 <-> ARGB8888 */
{0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
0, Blit_3or4_to_3or4__inversed_rgb,
#if HAVE_FAST_WRITE_INT8
NO_ALPHA |
#endif
SET_ALPHA | COPY_ALPHA},
{0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
0, Blit_3or4_to_3or4__inversed_rgb,
#if HAVE_FAST_WRITE_INT8
NO_ALPHA |
#endif
SET_ALPHA | COPY_ALPHA},
/* RGB 888 and RGB 565 */
{0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, 0x0000001F,
0, Blit_RGB888_RGB565, NO_ALPHA},
{0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, 0x0000001F,
@ -2570,7 +3299,7 @@ SDL_CalculateBlitN(SDL_Surface * surface)
}
} else {
/* Now the meat, choose the blitter we want */
int a_need = NO_ALPHA;
Uint32 a_need = NO_ALPHA;
if (dstfmt->Amask)
a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA;
table = normal_blit[srcfmt->BytesPerPixel - 1];

View file

@ -1,7 +1,7 @@
/* DO NOT EDIT! This file is generated by sdlgenblit.pl */
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

@ -1,7 +1,7 @@
/* DO NOT EDIT! This file is generated by sdlgenblit.pl */
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -19,6 +19,11 @@
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: */

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -18,8 +18,14 @@
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: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -246,6 +246,14 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
ExpandBMP = biBitCount;
biBitCount = 8;
break;
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;
@ -313,6 +321,10 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
SDL_assert(biBitCount <= 8);
if (biClrUsed == 0) {
biClrUsed = 1 << biBitCount;
} else if (biClrUsed > (Uint32)(1 << biBitCount)) {
SDL_SetError("BMP file has an invalid number of colors");
was_error = SDL_TRUE;
goto done;
}
if ((int) biClrUsed > palette->ncolors) {
SDL_Color *colors;
@ -394,19 +406,32 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
goto done;
}
}
*(bits + i) = (pixel >> shift);
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) {
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 < (Uint32)(1 << 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. */

View file

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

View file

@ -1,6 +1,6 @@
/*
* Simple DirectMedia Layer
* Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
* Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@ -27,6 +27,7 @@
#endif
#if SDL_VIDEO_DRIVER_ANDROID
#include <android/native_window.h>
#include "../core/android/SDL_android.h"
#endif
#include "SDL_sysvideo.h"
@ -278,16 +279,30 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
d3dcompiler = SDL_GetHint(SDL_HINT_VIDEO_WIN_D3DCOMPILER);
if (!d3dcompiler) {
if (WIN_IsWindowsVistaOrGreater()) {
d3dcompiler = "d3dcompiler_46.dll";
} else {
d3dcompiler = "d3dcompiler_43.dll";
if (d3dcompiler) {
if (SDL_strcasecmp(d3dcompiler, "none") != 0) {
if (SDL_LoadObject(d3dcompiler) == NULL) {
SDL_ClearError();
}
}
}
if (SDL_strcasecmp(d3dcompiler, "none") != 0) {
if (SDL_LoadObject(d3dcompiler) == NULL) {
SDL_ClearError();
} else {
if (WIN_IsWindowsVistaOrGreater()) {
/* Try the newer d3d compilers first */
const char *d3dcompiler_list[] = {
"d3dcompiler_47.dll", "d3dcompiler_46.dll",
};
int i;
for (i = 0; i < SDL_arraysize(d3dcompiler_list); ++i) {
if (SDL_LoadObject(d3dcompiler_list[i]) != NULL) {
break;
}
SDL_ClearError();
}
} else {
if (SDL_LoadObject("d3dcompiler_43.dll") == NULL) {
SDL_ClearError();
}
}
}
#endif
@ -406,6 +421,9 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
}
}
_this->egl_data->egl_version_major = egl_version_major;
_this->egl_data->egl_version_minor = egl_version_minor;
if (egl_version_major == 1 && egl_version_minor == 5) {
LOAD_FUNC(eglGetPlatformDisplay);
}
@ -446,20 +464,78 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
return 0;
}
void
SDL_EGL_SetRequiredVisualId(_THIS, int visual_id)
{
_this->egl_data->egl_required_visual_id=visual_id;
}
#ifdef DUMP_EGL_CONFIG
#define ATTRIBUTE(_attr) { _attr, #_attr }
typedef struct {
EGLint attribute;
char const* name;
} Attribute;
Attribute attributes[] = {
ATTRIBUTE( EGL_BUFFER_SIZE ),
ATTRIBUTE( EGL_ALPHA_SIZE ),
ATTRIBUTE( EGL_BLUE_SIZE ),
ATTRIBUTE( EGL_GREEN_SIZE ),
ATTRIBUTE( EGL_RED_SIZE ),
ATTRIBUTE( EGL_DEPTH_SIZE ),
ATTRIBUTE( EGL_STENCIL_SIZE ),
ATTRIBUTE( EGL_CONFIG_CAVEAT ),
ATTRIBUTE( EGL_CONFIG_ID ),
ATTRIBUTE( EGL_LEVEL ),
ATTRIBUTE( EGL_MAX_PBUFFER_HEIGHT ),
ATTRIBUTE( EGL_MAX_PBUFFER_WIDTH ),
ATTRIBUTE( EGL_MAX_PBUFFER_PIXELS ),
ATTRIBUTE( EGL_NATIVE_RENDERABLE ),
ATTRIBUTE( EGL_NATIVE_VISUAL_ID ),
ATTRIBUTE( EGL_NATIVE_VISUAL_TYPE ),
ATTRIBUTE( EGL_SAMPLES ),
ATTRIBUTE( EGL_SAMPLE_BUFFERS ),
ATTRIBUTE( EGL_SURFACE_TYPE ),
ATTRIBUTE( EGL_TRANSPARENT_TYPE ),
ATTRIBUTE( EGL_TRANSPARENT_BLUE_VALUE ),
ATTRIBUTE( EGL_TRANSPARENT_GREEN_VALUE ),
ATTRIBUTE( EGL_TRANSPARENT_RED_VALUE ),
ATTRIBUTE( EGL_BIND_TO_TEXTURE_RGB ),
ATTRIBUTE( EGL_BIND_TO_TEXTURE_RGBA ),
ATTRIBUTE( EGL_MIN_SWAP_INTERVAL ),
ATTRIBUTE( EGL_MAX_SWAP_INTERVAL ),
ATTRIBUTE( EGL_LUMINANCE_SIZE ),
ATTRIBUTE( EGL_ALPHA_MASK_SIZE ),
ATTRIBUTE( EGL_COLOR_BUFFER_TYPE ),
ATTRIBUTE( EGL_RENDERABLE_TYPE ),
ATTRIBUTE( EGL_MATCH_NATIVE_PIXMAP ),
ATTRIBUTE( EGL_CONFORMANT ),
};
static void dumpconfig(_THIS, EGLConfig config)
{
int attr;
for (attr = 0 ; attr<sizeof(attributes)/sizeof(Attribute) ; attr++) {
EGLint value;
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, config, attributes[attr].attribute, &value);
SDL_Log("\t%-32s: %10d (0x%08x)\n", attributes[attr].name, value, value);
}
}
#endif /* DUMP_EGL_CONFIG */
int
SDL_EGL_ChooseConfig(_THIS)
{
/* 64 seems nice. */
EGLint attribs[64];
EGLint found_configs = 0, value;
#ifdef SDL_VIDEO_DRIVER_KMSDRM
/* Intel EGL on KMS/DRM (al least) returns invalid configs that confuse the bitdiff search used */
/* later in this function, so we simply use the first one when using the KMSDRM driver for now. */
EGLConfig configs[1];
#else
/* 128 seems even nicer here */
EGLConfig configs[128];
#endif
int i, j, best_bitdiff = -1, bitdiff;
if (!_this->egl_data) {
@ -542,6 +618,16 @@ SDL_EGL_ChooseConfig(_THIS)
/* From those, we select the one that matches our requirements more closely via a makeshift algorithm */
for (i = 0; i < found_configs; i++ ) {
if (_this->egl_data->egl_required_visual_id)
{
EGLint format;
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
configs[i],
EGL_NATIVE_VISUAL_ID, &format);
if (_this->egl_data->egl_required_visual_id != format)
continue;
}
bitdiff = 0;
for (j = 0; j < SDL_arraysize(attribs) - 1; j += 2) {
if (attribs[j] == EGL_NONE) {
@ -570,6 +656,10 @@ SDL_EGL_ChooseConfig(_THIS)
break; /* we found an exact match! */
}
}
#ifdef DUMP_EGL_CONFIG
dumpconfig(_this, _this->egl_data->egl_config);
#endif
return 0;
}
@ -596,6 +686,24 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
share_context = (EGLContext)SDL_GL_GetCurrentContext();
}
#if SDL_VIDEO_DRIVER_ANDROID
if ((_this->gl_config.flags & SDL_GL_CONTEXT_DEBUG_FLAG) != 0) {
/* If SDL_GL_CONTEXT_DEBUG_FLAG is set but EGL_KHR_debug unsupported, unset.
* This is required because some Android devices like to complain about it
* by "silently" failing, logging a hint which could be easily overlooked:
* E/libEGL (26984): validate_display:255 error 3008 (EGL_BAD_DISPLAY)
* The following explicitly checks for EGL_KHR_debug before EGL 1.5
*/
int egl_version_major = _this->egl_data->egl_version_major;
int egl_version_minor = _this->egl_data->egl_version_minor;
if (((egl_version_major < 1) || (egl_version_major == 1 && egl_version_minor < 5)) &&
!SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_debug")) {
/* SDL profile bits match EGL profile bits. */
_this->gl_config.flags &= ~SDL_GL_CONTEXT_DEBUG_FLAG;
}
}
#endif
/* Set the context version and other attributes. */
if ((major_version < 3 || (minor_version == 0 && profile_es)) &&
_this->gl_config.flags == 0 &&
@ -763,7 +871,6 @@ SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
}
if (egl_context != NULL && egl_context != EGL_NO_CONTEXT) {
SDL_EGL_MakeCurrent(_this, NULL, NULL);
_this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context);
}
@ -775,7 +882,7 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
/* max 2 values plus terminator. */
EGLint attribs[3];
int attr = 0;
EGLSurface * surface;
if (SDL_EGL_ChooseConfig(_this) != 0) {
@ -793,6 +900,10 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry(nw, 0, 0, format);
/* Update SurfaceView holder format.
* May triggers a sequence surfaceDestroyed(), surfaceCreated(), surfaceChanged(). */
Android_JNI_SetSurfaceViewFormat(format);
}
#endif
if (_this->gl_config.framebuffer_srgb_capable) {
@ -807,7 +918,7 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
return EGL_NO_SURFACE;
}
}
attribs[attr++] = EGL_NONE;
surface = _this->egl_data->eglCreateWindowSurface(

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -36,6 +36,8 @@ typedef struct SDL_EGL_VideoData
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,
@ -101,6 +103,7 @@ extern int SDL_EGL_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
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);

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -326,7 +326,7 @@ SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
if (Rmask == 0) {
return SDL_PIXELFORMAT_RGB555;
}
/* fallthrough */
/* fallthrough */
case 16:
if (Rmask == 0) {
return SDL_PIXELFORMAT_RGB565;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -18,6 +18,10 @@
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 */
@ -37,4 +41,6 @@ extern void SDL_FreeBlitMap(SDL_BlitMap * map);
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: */

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -18,8 +18,14 @@
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: */

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -36,21 +36,21 @@ extern "C" {
#endif
typedef struct {
struct SDL_ShapeTree *upleft,*upright,*downleft,*downright;
struct SDL_ShapeTree *upleft,*upright,*downleft,*downright;
} SDL_QuadTreeChildren;
typedef union {
SDL_QuadTreeChildren children;
SDL_Rect shape;
SDL_QuadTreeChildren children;
SDL_Rect shape;
} SDL_ShapeUnion;
typedef enum { QuadShape,TransparentShape,OpaqueShape } SDL_ShapeKind;
typedef struct {
SDL_ShapeKind kind;
SDL_ShapeUnion data;
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);

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -37,7 +37,7 @@ SDL_COMPILE_TIME_ASSERT(surface_size_assumptions,
/*
* Calculate the pad-aligned scanline width of a surface
*/
int
static int
SDL_CalculatePitch(Uint32 format, int width)
{
int pitch;
@ -119,12 +119,13 @@ SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,
return NULL;
}
surface->pixels = SDL_malloc((size_t)size);
surface->pixels = SDL_SIMDAlloc((size_t)size);
if (!surface->pixels) {
SDL_FreeSurface(surface);
SDL_OutOfMemory();
return NULL;
}
surface->flags |= SDL_SIMD_ALIGNED;
/* This is important for bitmaps */
SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
}
@ -268,21 +269,7 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key)
if (flag) {
surface->map->info.flags |= SDL_COPY_COLORKEY;
surface->map->info.colorkey = key;
if (surface->format->palette) {
surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT;
++surface->format->palette->version;
if (!surface->format->palette->version) {
surface->format->palette->version = 1;
}
}
} else {
if (surface->format->palette) {
surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_OPAQUE;
++surface->format->palette->version;
if (!surface->format->palette->version) {
surface->format->palette->version = 1;
}
}
surface->map->info.flags &= ~SDL_COPY_COLORKEY;
}
if (surface->map->info.flags != flags) {
@ -292,6 +279,20 @@ SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key)
return 0;
}
SDL_bool
SDL_HasColorKey(SDL_Surface * surface)
{
if (!surface) {
return SDL_FALSE;
}
if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
return SDL_FALSE;
}
return SDL_TRUE;
}
int
SDL_GetColorKey(SDL_Surface * surface, Uint32 * key)
{
@ -311,7 +312,7 @@ SDL_GetColorKey(SDL_Surface * surface, Uint32 * key)
/* This is a fairly slow function to switch from colorkey to alpha */
static void
SDL_ConvertColorkeyToAlpha(SDL_Surface * surface)
SDL_ConvertColorkeyToAlpha(SDL_Surface * surface, SDL_bool ignore_alpha)
{
int x, y;
@ -333,18 +334,32 @@ SDL_ConvertColorkeyToAlpha(SDL_Surface * surface)
Uint16 ckey = (Uint16) surface->map->info.colorkey;
Uint16 mask = (Uint16) (~surface->format->Amask);
/* Ignore alpha in colorkey comparison */
ckey &= mask;
row = (Uint16 *) surface->pixels;
for (y = surface->h; y--;) {
spot = row;
for (x = surface->w; x--;) {
if ((*spot & mask) == ckey) {
*spot &= mask;
/* Ignore, or not, alpha in colorkey comparison */
if (ignore_alpha) {
ckey &= mask;
row = (Uint16 *) surface->pixels;
for (y = surface->h; y--;) {
spot = row;
for (x = surface->w; x--;) {
if ((*spot & mask) == ckey) {
*spot &= mask;
}
++spot;
}
++spot;
row += surface->pitch / 2;
}
} else {
row = (Uint16 *) surface->pixels;
for (y = surface->h; y--;) {
spot = row;
for (x = surface->w; x--;) {
if (*spot == ckey) {
*spot &= mask;
}
++spot;
}
row += surface->pitch / 2;
}
row += surface->pitch / 2;
}
}
break;
@ -357,18 +372,32 @@ SDL_ConvertColorkeyToAlpha(SDL_Surface * surface)
Uint32 ckey = surface->map->info.colorkey;
Uint32 mask = ~surface->format->Amask;
/* Ignore alpha in colorkey comparison */
ckey &= mask;
row = (Uint32 *) surface->pixels;
for (y = surface->h; y--;) {
spot = row;
for (x = surface->w; x--;) {
if ((*spot & mask) == ckey) {
*spot &= mask;
/* Ignore, or not, alpha in colorkey comparison */
if (ignore_alpha) {
ckey &= mask;
row = (Uint32 *) surface->pixels;
for (y = surface->h; y--;) {
spot = row;
for (x = surface->w; x--;) {
if ((*spot & mask) == ckey) {
*spot &= mask;
}
++spot;
}
++spot;
row += surface->pitch / 4;
}
} else {
row = (Uint32 *) surface->pixels;
for (y = surface->h; y--;) {
spot = row;
for (x = surface->w; x--;) {
if (*spot == ckey) {
*spot &= mask;
}
++spot;
}
row += surface->pitch / 4;
}
row += surface->pitch / 4;
}
}
break;
@ -929,6 +958,7 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
Uint32 copy_flags;
SDL_Color copy_color;
SDL_Rect bounds;
int ret;
if (!surface) {
SDL_InvalidParamError("surface");
@ -989,7 +1019,7 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
bounds.y = 0;
bounds.w = surface->w;
bounds.h = surface->h;
SDL_LowerBlit(surface, &bounds, convert, &bounds);
ret = SDL_LowerBlit(surface, &bounds, convert, &bounds);
/* Clean up the original surface, and update converted surface */
convert->map->info.r = copy_color.r;
@ -1007,8 +1037,16 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
surface->map->info.a = copy_color.a;
surface->map->info.flags = copy_flags;
SDL_InvalidateMap(surface->map);
/* SDL_LowerBlit failed, and so the conversion */
if (ret < 0) {
SDL_FreeSurface(convert);
return NULL;
}
if (copy_flags & SDL_COPY_COLORKEY) {
SDL_bool set_colorkey_by_color = SDL_FALSE;
SDL_bool ignore_alpha = SDL_TRUE; /* Ignore, or not, alpha in colorkey comparison */
if (surface->format->palette) {
if (format->palette &&
@ -1018,7 +1056,8 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
/* The palette is identical, just set the same colorkey */
SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
} else if (format->Amask) {
/* The alpha was set in the destination from the palette */
set_colorkey_by_color = SDL_TRUE;
ignore_alpha = SDL_FALSE;
} else {
set_colorkey_by_color = SDL_TRUE;
}
@ -1041,7 +1080,7 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
if (surface->format->palette) {
SDL_SetSurfacePalette(tmp, surface->format->palette);
}
SDL_FillRect(tmp, NULL, surface->map->info.colorkey);
tmp->map->info.flags &= ~SDL_COPY_COLORKEY;
@ -1059,7 +1098,7 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
SDL_SetColorKey(convert, 1, converted_colorkey);
/* This is needed when converting for 3D texture upload */
SDL_ConvertColorkeyToAlpha(convert);
SDL_ConvertColorkeyToAlpha(convert, ignore_alpha);
}
}
SDL_SetClipRect(convert, &surface->clip_rect);
@ -1220,7 +1259,13 @@ SDL_FreeSurface(SDL_Surface * surface)
SDL_FreeFormat(surface->format);
surface->format = NULL;
}
if (!(surface->flags & SDL_PREALLOC)) {
if (surface->flags & SDL_PREALLOC) {
/* Don't free */
} else if (surface->flags & SDL_SIMD_ALIGNED) {
/* Free aligned */
SDL_SIMDFree(surface->pixels);
} else {
/* Normal */
SDL_free(surface->pixels);
}
if (surface->map) {

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -119,8 +119,8 @@ struct SDL_Window
!((W)->flags & SDL_WINDOW_MINIMIZED))
/*
* Define the SDL display structure This corresponds to physical monitors
* attached to the system.
* Define the SDL display structure.
* This corresponds to physical monitors attached to the system.
*/
struct SDL_VideoDisplay
{
@ -130,6 +130,7 @@ struct SDL_VideoDisplay
SDL_DisplayMode *display_modes;
SDL_DisplayMode desktop_mode;
SDL_DisplayMode current_mode;
SDL_DisplayOrientation orientation;
SDL_Window *fullscreen_window;
@ -180,16 +181,16 @@ struct SDL_VideoDevice
*/
int (*GetDisplayBounds) (_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 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.
*/
@ -304,6 +305,9 @@ struct SDL_VideoDevice
/* 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;
@ -401,7 +405,6 @@ typedef struct VideoBootStrap
/* Not all of these are available in a given build. Use #ifdefs, etc. */
extern VideoBootStrap COCOA_bootstrap;
extern VideoBootStrap X11_bootstrap;
extern VideoBootStrap MIR_bootstrap;
extern VideoBootStrap DirectFB_bootstrap;
extern VideoBootStrap WINDOWS_bootstrap;
extern VideoBootStrap WINRT_bootstrap;
@ -423,6 +426,8 @@ 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 );
@ -454,6 +459,8 @@ extern void SDL_OnApplicationDidEnterBackground(void);
extern void SDL_OnApplicationWillEnterForeground(void);
extern void SDL_OnApplicationDidBecomeActive(void);
extern void SDL_ToggleDragAndDropSupport(void);
#endif /* SDL_sysvideo_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -64,9 +64,6 @@ static VideoBootStrap *bootstrap[] = {
#if SDL_VIDEO_DRIVER_X11
&X11_bootstrap,
#endif
#if SDL_VIDEO_DRIVER_MIR
&MIR_bootstrap,
#endif
#if SDL_VIDEO_DRIVER_WAYLAND
&Wayland_bootstrap,
#endif
@ -641,7 +638,7 @@ SDL_GetNumVideoDisplays(void)
return _this->num_displays;
}
static int
int
SDL_GetIndexOfDisplay(SDL_VideoDisplay *display)
{
int displayIndex;
@ -739,6 +736,17 @@ SDL_GetDisplayDPI(int displayIndex, float * ddpi, float * hdpi, float * vdpi)
return -1;
}
SDL_DisplayOrientation
SDL_GetDisplayOrientation(int displayIndex)
{
SDL_VideoDisplay *display;
CHECK_DISPLAY_INDEX(displayIndex, SDL_ORIENTATION_UNKNOWN);
display = &_this->displays[displayIndex];
return display->orientation;
}
SDL_bool
SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
{
@ -1000,7 +1008,7 @@ SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode *
/* Actually change the display mode */
if (!_this->SetDisplayMode) {
return SDL_SetError("Video driver doesn't support changing display mode");
return SDL_SetError("SDL video driver doesn't support changing display mode");
}
if (_this->SetDisplayMode(_this, display, &display_mode) < 0) {
return -1;
@ -1009,6 +1017,14 @@ SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode *
return 0;
}
SDL_VideoDisplay *
SDL_GetDisplay(int displayIndex)
{
CHECK_DISPLAY_INDEX(displayIndex, NULL);
return &_this->displays[displayIndex];
}
int
SDL_GetWindowDisplayIndex(SDL_Window * window)
{
@ -1289,8 +1305,15 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
/* Generate a mode change event here */
if (resized) {
#ifndef ANDROID
// Android may not resize the window to exactly what our fullscreen mode is, especially on
// windowed Android environments like the Chromebook or Samsung DeX. Given this, we shouldn't
// use fullscreen_mode.w and fullscreen_mode.h, but rather get our current native size. As such,
// Android's SetWindowFullscreen will generate the window event for us with the proper final size.
SDL_SendWindowEvent(other, SDL_WINDOWEVENT_RESIZED,
fullscreen_mode.w, fullscreen_mode.h);
#endif
} else {
SDL_OnWindowResized(other);
}
@ -1322,11 +1345,45 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
}
#define CREATE_FLAGS \
(SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_ALWAYS_ON_TOP | SDL_WINDOW_SKIP_TASKBAR | SDL_WINDOW_POPUP_MENU | SDL_WINDOW_UTILITY | SDL_WINDOW_TOOLTIP | SDL_WINDOW_VULKAN)
(SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_ALWAYS_ON_TOP | SDL_WINDOW_SKIP_TASKBAR | SDL_WINDOW_POPUP_MENU | SDL_WINDOW_UTILITY | SDL_WINDOW_TOOLTIP | SDL_WINDOW_VULKAN | SDL_WINDOW_MINIMIZED)
static SDL_INLINE SDL_bool
IsAcceptingDragAndDrop(void)
{
if ((SDL_GetEventState(SDL_DROPFILE) == SDL_ENABLE) ||
(SDL_GetEventState(SDL_DROPTEXT) == SDL_ENABLE)) {
return SDL_TRUE;
}
return SDL_FALSE;
}
/* prepare a newly-created window */
static SDL_INLINE void
PrepareDragAndDropSupport(SDL_Window *window)
{
if (_this->AcceptDragAndDrop) {
_this->AcceptDragAndDrop(window, IsAcceptingDragAndDrop());
}
}
/* toggle d'n'd for all existing windows. */
void
SDL_ToggleDragAndDropSupport(void)
{
if (_this && _this->AcceptDragAndDrop) {
const SDL_bool enable = IsAcceptingDragAndDrop();
SDL_Window *window;
for (window = _this->windows; window; window = window->next) {
_this->AcceptDragAndDrop(window, enable);
}
}
}
static void
SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags)
{
PrepareDragAndDropSupport(window);
if (flags & SDL_WINDOW_MAXIMIZED) {
SDL_MaximizeWindow(window);
}
@ -1383,7 +1440,9 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
#endif
if (flags & SDL_WINDOW_OPENGL) {
if (!_this->GL_CreateContext) {
SDL_SetError("No OpenGL support in video driver");
SDL_SetError("OpenGL support is either not configured in SDL "
"or not available in current SDL video driver "
"(%s) or platform", _this->name);
return NULL;
}
if (SDL_GL_LoadLibrary(NULL) < 0) {
@ -1394,7 +1453,8 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
if (flags & SDL_WINDOW_VULKAN) {
if (!_this->Vulkan_CreateSurface) {
SDL_SetError("Vulkan support is either not configured in SDL "
"or not available in video driver");
"or not available in current SDL video driver "
"(%s) or platform", _this->name);
return NULL;
}
if (flags & SDL_WINDOW_OPENGL) {
@ -1477,6 +1537,15 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
return NULL;
}
/* Clear minimized if not on windows, only windows handles it at create rather than FinishWindowCreation,
* but it's important or window focus will get broken on windows!
*/
#if !defined(__WIN32__)
if (window->flags & SDL_WINDOW_MINIMIZED) {
window->flags &= ~SDL_WINDOW_MINIMIZED;
}
#endif
#if __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
/* HACK: WinRT 8.x apps can't choose whether or not they are fullscreen
or not. The user can choose this, via OS-provided UI, but this can't
@ -1535,6 +1604,9 @@ SDL_CreateWindowFrom(const void *data)
SDL_DestroyWindow(window);
return NULL;
}
PrepareDragAndDropSupport(window);
return window;
}
@ -1544,7 +1616,9 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
SDL_bool loaded_opengl = SDL_FALSE;
if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
return SDL_SetError("No OpenGL support in video driver");
return SDL_SetError("OpenGL support is either not configured in SDL "
"or not available in current SDL video driver "
"(%s) or platform", _this->name);
}
if (window->flags & SDL_WINDOW_FOREIGN) {
@ -1562,6 +1636,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
window->surface->flags &= ~SDL_DONTFREE;
SDL_FreeSurface(window->surface);
window->surface = NULL;
window->surface_valid = SDL_FALSE;
}
if (_this->DestroyWindowFramebuffer) {
_this->DestroyWindowFramebuffer(_this, window);
@ -1579,6 +1654,12 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
} else {
SDL_GL_UnloadLibrary();
}
} else if (window->flags & SDL_WINDOW_OPENGL) {
SDL_GL_UnloadLibrary();
if (SDL_GL_LoadLibrary(NULL) < 0) {
return -1;
}
loaded_opengl = SDL_TRUE;
}
if ((window->flags & SDL_WINDOW_VULKAN) != (flags & SDL_WINDOW_VULKAN)) {
@ -1820,7 +1901,6 @@ SDL_SetWindowPosition(SDL_Window * window, int x, int y)
if (_this->SetWindowPosition) {
_this->SetWindowPosition(_this, window);
}
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
}
}
@ -2132,6 +2212,15 @@ SDL_MaximizeWindow(SDL_Window * window)
}
}
static SDL_bool
CanMinimizeWindow(SDL_Window * window)
{
if (!_this->MinimizeWindow) {
return SDL_FALSE;
}
return SDL_TRUE;
}
void
SDL_MinimizeWindow(SDL_Window * window)
{
@ -2141,6 +2230,10 @@ SDL_MinimizeWindow(SDL_Window * window)
return;
}
if (!CanMinimizeWindow(window)) {
return;
}
SDL_UpdateFullscreenMode(window, SDL_FALSE);
if (_this->MinimizeWindow) {
@ -2571,6 +2664,15 @@ ShouldMinimizeOnFocusLoss(SDL_Window * window)
}
#endif
#ifdef __ANDROID__
{
extern SDL_bool Android_JNI_ShouldMinimizeOnFocusLoss(void);
if (! Android_JNI_ShouldMinimizeOnFocusLoss()) {
return SDL_FALSE;
}
}
#endif
return SDL_GetHintBoolean(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_TRUE);
}
@ -2787,7 +2889,7 @@ SDL_GL_LoadLibrary(const char *path)
retval = 0;
} else {
if (!_this->GL_LoadLibrary) {
return SDL_SetError("No dynamic GL support in video driver");
return SDL_SetError("No dynamic GL support in current SDL video driver (%s)", _this->name);
}
retval = _this->GL_LoadLibrary(_this, path);
}
@ -2818,7 +2920,7 @@ SDL_GL_GetProcAddress(const char *proc)
SDL_SetError("No GL driver has been loaded");
}
} else {
SDL_SetError("No dynamic GL support in video driver");
SDL_SetError("No dynamic GL support in current SDL video driver (%s)", _this->name);
}
return func;
}
@ -3774,6 +3876,8 @@ SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
if (!messageboxdata) {
return SDL_InvalidParamError("messageboxdata");
} else if (messageboxdata->numbuttons < 0) {
return SDL_SetError("Invalid number of buttons");
}
current_window = SDL_GetKeyboardFocus();
@ -3983,7 +4087,9 @@ int SDL_Vulkan_LoadLibrary(const char *path)
retval = 0;
} else {
if (!_this->Vulkan_LoadLibrary) {
return SDL_SetError("No Vulkan support in video driver");
return SDL_SetError("Vulkan support is either not configured in SDL "
"or not available in current SDL video driver "
"(%s) or platform", _this->name);
}
retval = _this->Vulkan_LoadLibrary(_this, path);
}
@ -4024,11 +4130,14 @@ void SDL_Vulkan_UnloadLibrary(void)
SDL_bool SDL_Vulkan_GetInstanceExtensions(SDL_Window *window, unsigned *count, const char **names)
{
CHECK_WINDOW_MAGIC(window, SDL_FALSE);
if (window) {
CHECK_WINDOW_MAGIC(window, SDL_FALSE);
if (!(window->flags & SDL_WINDOW_VULKAN)) {
SDL_SetError(NOT_A_VULKAN_WINDOW);
return SDL_FALSE;
if (!(window->flags & SDL_WINDOW_VULKAN))
{
SDL_SetError(NOT_A_VULKAN_WINDOW);
return SDL_FALSE;
}
}
if (!count) {

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -38,9 +38,6 @@
#if SDL_VIDEO_DRIVER_COCOA
#define VK_USE_PLATFORM_MACOS_MVK
#endif
#if SDL_VIDEO_DRIVER_MIR
#define VK_USE_PLATFORM_MIR_KHR
#endif
#if SDL_VIDEO_DRIVER_UIKIT
#define VK_USE_PLATFORM_IOS_MVK
#endif
@ -76,6 +73,13 @@ extern SDL_bool SDL_Vulkan_GetInstanceExtensions_Helper(unsigned *userCount,
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 */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,6 +22,9 @@
#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
@ -123,10 +126,10 @@ VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
{
retval = SDL_calloc(1, sizeof(VkExtensionProperties)); // so we can return non-null
}
else
{
retval = SDL_calloc(count, sizeof(VkExtensionProperties));
}
else
{
retval = SDL_calloc(count, sizeof(VkExtensionProperties));
}
if(!retval)
{
SDL_OutOfMemory();
@ -167,6 +170,346 @@ SDL_bool SDL_Vulkan_GetInstanceExtensions_Helper(unsigned *userCount,
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: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,6 +23,7 @@
#include "SDL_endian.h"
#include "SDL_video.h"
#include "SDL_pixels_c.h"
#include "SDL_yuv_c.h"
#include "yuv2rgb/yuv_rgb.h"
@ -89,10 +90,10 @@ static SDL_bool IsPacked4Format(Uint32 format)
}
static int GetYUVPlanes(int width, int height, Uint32 format, const void *yuv, int yuv_pitch,
const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride)
const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride)
{
const Uint8 *planes[3] = { NULL, NULL, NULL };
int pitches[3] = { 0, 0, 0 };
const Uint8 *planes[3] = { NULL, NULL, NULL };
int pitches[3] = { 0, 0, 0 };
switch (format) {
case SDL_PIXELFORMAT_YV12:
@ -180,10 +181,10 @@ static int GetYUVPlanes(int width, int height, Uint32 format, const void *yuv, i
static SDL_bool yuv_rgb_sse(
Uint32 src_format, Uint32 dst_format,
Uint32 width, Uint32 height,
const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride,
Uint8 *rgb, Uint32 rgb_stride,
YCbCrType yuv_type)
Uint32 width, Uint32 height,
const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride,
Uint8 *rgb, Uint32 rgb_stride,
YCbCrType yuv_type)
{
#ifdef __SSE2__
if (!SDL_HasSSE2()) {
@ -289,10 +290,10 @@ static SDL_bool yuv_rgb_sse(
static SDL_bool yuv_rgb_std(
Uint32 src_format, Uint32 dst_format,
Uint32 width, Uint32 height,
const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride,
Uint8 *rgb, Uint32 rgb_stride,
YCbCrType yuv_type)
Uint32 width, Uint32 height,
const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride,
Uint8 *rgb, Uint32 rgb_stride,
YCbCrType yuv_type)
{
if (src_format == SDL_PIXELFORMAT_YV12 ||
src_format == SDL_PIXELFORMAT_IYUV) {
@ -395,7 +396,7 @@ 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)
{
const Uint8 *y = NULL;
const Uint8 *y = NULL;
const Uint8 *u = NULL;
const Uint8 *v = NULL;
Uint32 y_stride = 0;
@ -553,7 +554,7 @@ SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int sr
Uint32 y_stride, uv_stride, y_skip, uv_skip;
GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
(const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v,
(const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v,
&y_stride, &uv_stride);
plane_interleaved_uv = (plane_y + height * y_stride);
y_skip = (y_stride - width);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -18,6 +18,10 @@
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"
@ -27,4 +31,6 @@ extern int SDL_ConvertPixels_YUV_to_RGB(int width, int height, Uint32 src_format
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

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

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,16 +22,15 @@
#if SDL_VIDEO_DRIVER_ANDROID
/* We're going to do this by default */
#define SDL_ANDROID_BLOCK_ON_PAUSE 1
#include "SDL_androidevents.h"
#include "SDL_events.h"
#include "SDL_androidkeyboard.h"
#include "SDL_androidwindow.h"
#if !SDL_AUDIO_DISABLED
/* 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
@ -39,82 +38,159 @@ static void ANDROIDAUDIO_ResumeDevices(void) {}
static void ANDROIDAUDIO_PauseDevices(void) {}
#endif
static void
android_egl_context_restore()
#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)
{
SDL_Event event;
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
if (SDL_GL_MakeCurrent(Android_Window, (SDL_GLContext) data->egl_context) < 0) {
/* The context is no longer valid, create a new one */
data->egl_context = (EGLContext) SDL_GL_CreateContext(Android_Window);
SDL_GL_MakeCurrent(Android_Window, (SDL_GLContext) data->egl_context);
event.type = SDL_RENDER_DEVICE_RESET;
SDL_PushEvent(&event);
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);
}
}
}
static void
android_egl_context_backup()
static void
android_egl_context_backup(SDL_Window *window)
{
/* Keep a copy of the EGL Context so we can try to restore it when we resume */
SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
data->egl_context = SDL_GL_GetCurrentContext();
/* We need to do this so the EGLSurface can be freed */
SDL_GL_MakeCurrent(Android_Window, NULL);
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);
}
}
/*
* 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) {
/* Make sure this is the last thing we do before pausing */
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;
ANDROIDAUDIO_ResumeDevices();
openslES_ResumeDevices();
/* Restore the GL Context from here, as this operation is thread dependent */
if (!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) {
/* 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(_THIS)
Android_PumpEvents_NonBlocking(_THIS)
{
static int isPaused = 0;
#if SDL_ANDROID_BLOCK_ON_PAUSE
static int isPausing = 0;
#endif
/* No polling necessary */
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
static int backup_context = 0;
/*
* 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 SDL_ANDROID_BLOCK_ON_PAUSE is defined the event loop will block until the resume signal is emitted.
*/
if (videodata->isPaused) {
if (backup_context) {
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;
#if SDL_ANDROID_BLOCK_ON_PAUSE
if (isPaused && !isPausing) {
/* Make sure this is the last thing we do before pausing */
android_egl_context_backup();
ANDROIDAUDIO_PauseDevices();
if(SDL_SemWait(Android_ResumeSem) == 0) {
#else
if (isPaused) {
if(SDL_SemTryWait(Android_ResumeSem) == 0) {
#endif
isPaused = 0;
ANDROIDAUDIO_ResumeDevices();
openslES_ResumeDevices();
/* Restore the GL Context from here, as this operation is thread dependent */
if (!SDL_HasEvent(SDL_QUIT)) {
android_egl_context_restore();
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 SDL_ANDROID_BLOCK_ON_PAUSE
if( isPausing || SDL_SemTryWait(Android_PauseSem) == 0 ) {
/* We've been signaled to pause, but before we block ourselves,
we need to make sure that certain key events have reached the app */
if (SDL_HasEvent(SDL_WINDOWEVENT) || SDL_HasEvent(SDL_APP_WILLENTERBACKGROUND) || SDL_HasEvent(SDL_APP_DIDENTERBACKGROUND) ) {
isPausing = 1;
}
else {
isPausing = 0;
isPaused = 1;
} else {
if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
/* 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;
}
}
#else
if(SDL_SemTryWait(Android_PauseSem) == 0) {
android_egl_context_backup();
ANDROIDAUDIO_PauseDevices();
isPaused = 1;
}
#endif
}
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,6 +22,7 @@
#include "SDL_androidvideo.h"
extern void Android_PumpEvents(_THIS);
extern void Android_PumpEvents_Blocking(_THIS);
extern void Android_PumpEvents_NonBlocking(_THIS);
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -36,20 +36,49 @@
#include <dlfcn.h>
SDL_EGL_CreateContext_impl(Android)
SDL_EGL_MakeCurrent_impl(Android)
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();*/
return SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
retval = SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
SDL_UnlockMutex(Android_ActivityMutex);
return retval;
}
int

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -42,15 +42,164 @@
#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)
@ -71,12 +220,12 @@ TranslateButton(int state)
}
void
Android_OnMouse(int state, int action, float x, float y)
Android_OnMouse(SDL_Window *window, int state, int action, float x, float y, SDL_bool relative)
{
int changes;
Uint8 button;
if (!Android_Window) {
if (!window) {
return;
}
@ -85,25 +234,25 @@ Android_OnMouse(int state, int action, float x, float y)
changes = state & ~last_state;
button = TranslateButton(changes);
last_state = state;
SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
SDL_SendMouseButton(Android_Window, 0, SDL_PRESSED, button);
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(Android_Window, 0, 0, x, y);
SDL_SendMouseButton(Android_Window, 0, SDL_RELEASED, button);
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(Android_Window, 0, 0, x, y);
SDL_SendMouseMotion(window, 0, relative, (int)x, (int)y);
break;
case ACTION_SCROLL:
SDL_SendMouseWheel(Android_Window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
SDL_SendMouseWheel(window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
break;
default:

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -25,7 +25,8 @@
#include "SDL_androidvideo.h"
extern void Android_InitMouse(void);
extern void Android_OnMouse( int button, int action, float x, float y);
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_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -40,104 +40,44 @@
#define ACTION_POINTER_DOWN 5
#define ACTION_POINTER_UP 6
static void Android_GetWindowCoordinates(float x, float y,
int *window_x, int *window_y)
{
int window_w, window_h;
SDL_GetWindowSize(Android_Window, &window_w, &window_h);
*window_x = (int)(x * window_w);
*window_y = (int)(y * window_h);
}
static SDL_bool separate_mouse_and_touch = SDL_FALSE;
static void SDLCALL
SeparateEventsHintWatcher(void *userdata, const char *name,
const char *oldValue, const char *newValue)
{
separate_mouse_and_touch = (newValue && (SDL_strcmp(newValue, "1") == 0));
Android_JNI_SetSeparateMouseAndTouch(separate_mouse_and_touch);
}
void Android_InitTouch(void)
{
int i;
int* ids;
const int number = Android_JNI_GetTouchDeviceIds(&ids);
SDL_AddHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
SeparateEventsHintWatcher, NULL);
if (0 < number) {
for (i = 0; i < number; ++i) {
SDL_AddTouch((SDL_TouchID) ids[i], ""); /* no error handling */
}
SDL_free(ids);
}
/* Add all touch devices */
Android_JNI_InitTouch();
}
void Android_QuitTouch(void)
{
SDL_DelHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
SeparateEventsHintWatcher, NULL);
separate_mouse_and_touch = SDL_FALSE;
return;
}
void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
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;
int window_x, window_y;
static SDL_FingerID pointerFingerID = 0;
if (!Android_Window) {
if (!window) {
return;
}
touchDeviceId = (SDL_TouchID)touch_device_id_in;
if (SDL_AddTouch(touchDeviceId, "") < 0) {
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:
/* Primary pointer down */
if (!separate_mouse_and_touch) {
Android_GetWindowCoordinates(x, y, &window_x, &window_y);
/* send moved event */
SDL_SendMouseMotion(Android_Window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
/* send mouse down event */
SDL_SendMouseButton(Android_Window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
}
pointerFingerID = fingerId;
case ACTION_POINTER_DOWN:
/* Non primary pointer down */
SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
break;
case ACTION_MOVE:
if (!pointerFingerID) {
if (!separate_mouse_and_touch) {
Android_GetWindowCoordinates(x, y, &window_x, &window_y);
/* send moved event */
SDL_SendMouseMotion(Android_Window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
}
}
SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
break;
case ACTION_UP:
/* Primary pointer up */
if (!separate_mouse_and_touch) {
/* send mouse up */
SDL_SendMouseButton(Android_Window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
}
pointerFingerID = (SDL_FingerID) 0;
case ACTION_POINTER_UP:
/* Non primary pointer up */
SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
break;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -24,6 +24,6 @@
extern void Android_InitTouch(void);
extern void Android_QuitTouch(void);
extern void Android_OnTouch( int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p);
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

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,11 +22,11 @@
#if SDL_VIDEO_DRIVER_ANDROID
/* Android SDL video driver implementation
*/
/* 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"
@ -47,7 +47,7 @@
/* 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);
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
@ -60,15 +60,15 @@ int Android_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float
/* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
int Android_ScreenWidth = 0;
int Android_ScreenHeight = 0;
Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
static int Android_ScreenRate = 0;
SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL;
/* Currently only one window */
SDL_Window *Android_Window = NULL;
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)
@ -83,7 +83,7 @@ Android_SuspendScreenSaver(_THIS)
}
static void
Android_DeleteDevice(SDL_VideoDevice * device)
Android_DeleteDevice(SDL_VideoDevice *device)
{
SDL_free(device->driverdata);
SDL_free(device);
@ -94,6 +94,7 @@ 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));
@ -102,7 +103,7 @@ Android_CreateDevice(int devindex)
return NULL;
}
data = (SDL_VideoData*) SDL_calloc(1, sizeof(SDL_VideoData));
data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
if (!data) {
SDL_OutOfMemory();
SDL_free(device);
@ -114,13 +115,19 @@ Android_CreateDevice(int devindex)
/* Set the function pointers */
device->VideoInit = Android_VideoInit;
device->VideoQuit = Android_VideoQuit;
device->PumpEvents = Android_PumpEvents;
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;
@ -173,16 +180,26 @@ VideoBootStrap Android_bootstrap = {
int
Android_VideoInit(_THIS)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
int display_index;
SDL_VideoDisplay *display;
SDL_DisplayMode mode;
mode.format = Android_ScreenFormat;
mode.w = Android_ScreenWidth;
mode.h = Android_ScreenHeight;
mode.refresh_rate = Android_ScreenRate;
mode.driverdata = NULL;
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
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);
@ -199,53 +216,56 @@ Android_VideoInit(_THIS)
void
Android_VideoQuit(_THIS)
{
Android_QuitMouse();
Android_QuitTouch();
}
int
Android_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
Android_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi)
{
return Android_JNI_GetDisplayDPI(ddpi, hdpi, vdpi);
}
void
Android_SetScreenResolution(int width, int height, Uint32 format, float rate)
Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate)
{
SDL_VideoDevice* device;
SDL_VideoDisplay *display;
Android_ScreenWidth = width;
Android_ScreenHeight = height;
Android_ScreenFormat = format;
Android_ScreenRate = 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().
*/
device = SDL_GetVideoDevice();
SDL_VideoDevice *device = SDL_GetVideoDevice();
if (device && device->num_displays > 0)
{
display = &device->displays[0];
display->desktop_mode.format = Android_ScreenFormat;
display->desktop_mode.w = Android_ScreenWidth;
display->desktop_mode.h = Android_ScreenHeight;
display->desktop_mode.refresh_rate = Android_ScreenRate;
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 (Android_Window) {
if (window) {
/* Force the current mode to match the resize otherwise the SDL_WINDOWEVENT_RESTORED event
* will fall back to the old mode */
display = SDL_GetDisplayForWindow(Android_Window);
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
display->display_modes[0].format = Android_ScreenFormat;
display->display_modes[0].w = Android_DeviceWidth;
display->display_modes[0].h = Android_DeviceHeight;
display->display_modes[0].refresh_rate = Android_ScreenRate;
display->current_mode = display->display_modes[0];
display->display_modes[0].format = format;
display->display_modes[0].w = width;
display->display_modes[0].h = height;
display->display_modes[0].refresh_rate = rate;
display->current_mode = display->display_modes[0];
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, Android_SurfaceWidth, Android_SurfaceHeight);
}
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -28,21 +28,22 @@
#include "../SDL_sysvideo.h"
/* Called by the JNI layer when the screen changes size or format */
extern void Android_SetScreenResolution(int width, int height, Uint32 format, float rate);
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;
SDL_Rect textRect;
int isPaused;
int isPausing;
} SDL_VideoData;
extern int Android_ScreenWidth;
extern int Android_ScreenHeight;
extern Uint32 Android_ScreenFormat;
extern int Android_SurfaceWidth;
extern int Android_SurfaceHeight;
extern SDL_sem *Android_PauseSem, *Android_ResumeSem;
extern SDL_Window *Android_Window;
extern SDL_mutex *Android_ActivityMutex;
#endif /* SDL_androidvideo_h_ */

View file

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

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,22 +26,28 @@
#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) {
return SDL_SetError("Android only supports one window");
retval = SDL_SetError("Android only supports one window");
goto endfunction;
}
Android_PauseSem = SDL_CreateSemaphore(0);
Android_ResumeSem = SDL_CreateSemaphore(0);
/* Set orientation */
Android_JNI_SetOrientation(window->w, window->h, window->flags & SDL_WINDOW_RESIZABLE, SDL_GetHint(SDL_HINT_ORIENTATIONS));
@ -49,28 +55,29 @@ Android_CreateWindow(_THIS, SDL_Window * window)
/* Adjust the window data to match the screen */
window->x = 0;
window->y = 0;
window->w = Android_ScreenWidth;
window->h = Android_ScreenHeight;
window->w = Android_SurfaceWidth;
window->h = Android_SurfaceHeight;
window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
window->flags &= ~SDL_WINDOW_HIDDEN;
window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */
window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
/* One window, it always has focus */
SDL_SetMouseFocus(window);
SDL_SetKeyboardFocus(window);
data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
if (!data) {
return SDL_OutOfMemory();
retval = SDL_OutOfMemory();
goto endfunction;
}
data->native_window = Android_JNI_GetNativeWindow();
if (!data->native_window) {
SDL_free(data);
return SDL_SetError("Could not fetch native window");
retval = SDL_SetError("Could not fetch native window");
goto endfunction;
}
/* Do not create EGLSurface for Vulkan window since it will then make the window
@ -81,42 +88,94 @@ Android_CreateWindow(_THIS, SDL_Window * window)
if (data->egl_surface == EGL_NO_SURFACE) {
ANativeWindow_release(data->native_window);
SDL_free(data);
return SDL_SetError("Could not create GLES window surface");
retval = -1;
goto endfunction;
}
}
window->driverdata = data;
Android_Window = window;
return 0;
endfunction:
SDL_UnlockMutex(Android_ActivityMutex);
return retval;
}
void
Android_SetWindowTitle(_THIS, SDL_Window * window)
Android_SetWindowTitle(_THIS, SDL_Window *window)
{
Android_JNI_SetActivityTitle(window->title);
}
void
Android_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
{
Android_JNI_SetWindowStyle(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_DestroyWindow(_THIS, SDL_Window * window)
Android_MinimizeWindow(_THIS, SDL_Window *window)
{
SDL_WindowData *data;
Android_JNI_MinizeWindow();
}
void
Android_DestroyWindow(_THIS, SDL_Window *window)
{
SDL_LockMutex(Android_ActivityMutex);
if (window == Android_Window) {
Android_Window = NULL;
if (Android_PauseSem) SDL_DestroySemaphore(Android_PauseSem);
if (Android_ResumeSem) SDL_DestroySemaphore(Android_ResumeSem);
Android_PauseSem = NULL;
Android_ResumeSem = NULL;
if(window->driverdata) {
data = (SDL_WindowData *) window->driverdata;
if (window->driverdata) {
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if (data->egl_surface != EGL_NO_SURFACE) {
SDL_EGL_DestroySurface(_this, data->egl_surface);
}
@ -127,10 +186,12 @@ Android_DestroyWindow(_THIS, SDL_Window * window)
window->driverdata = NULL;
}
}
SDL_UnlockMutex(Android_ActivityMutex);
}
SDL_bool
Android_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
Android_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,17 +26,20 @@
#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_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo * info);
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 */
ANativeWindow* native_window;
ANativeWindow *native_window;
} SDL_WindowData;

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -275,7 +275,6 @@ CreateApplicationMenus(void)
NSMenu *appleMenu;
NSMenu *serviceMenu;
NSMenu *windowMenu;
NSMenu *viewMenu;
NSMenuItem *menuItem;
NSMenu *mainMenu;
@ -342,9 +341,22 @@ CreateApplicationMenus(void)
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:@""];
@ -355,25 +367,6 @@ CreateApplicationMenus(void)
/* Tell the application object that this is now the window menu */
[NSApp setWindowsMenu:windowMenu];
[windowMenu release];
/* Add the fullscreen view toggle menu option, if supported */
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
/* Create the view menu */
viewMenu = [[NSMenu alloc] initWithTitle:@"View"];
/* Add menu items */
menuItem = [viewMenu addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
[menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""];
[menuItem setSubmenu:viewMenu];
[[NSApp mainMenu] addItem:menuItem];
[menuItem release];
[viewMenu release];
}
}
void
@ -390,8 +383,8 @@ Cocoa_RegisterApp(void)
if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
}
}
if ([NSApp mainMenu] == nil) {
CreateApplicationMenus();
}

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -29,7 +29,6 @@
#include "../../events/scancodes_darwin.h"
#include <Carbon/Carbon.h>
#include <IOKit/hid/IOHIDLib.h>
/*#define DEBUG_IME NSLog */
#define DEBUG_IME(...)
@ -187,115 +186,6 @@
@end
/*------------------------------------------------------------------------------
Set up a HID callback to properly detect Caps Lock up/down events.
Derived from:
http://stackoverflow.com/questions/7190852/using-iohidmanager-to-get-modifier-key-events
*/
static IOHIDManagerRef s_hidManager = NULL;
static void
HIDCallback(void *context, IOReturn result, void *sender, IOHIDValueRef value)
{
if (context != s_hidManager) {
/* An old callback, ignore it (related to bug 2157 below) */
return;
}
IOHIDElementRef elem = IOHIDValueGetElement(value);
if (IOHIDElementGetUsagePage(elem) != kHIDPage_KeyboardOrKeypad
|| IOHIDElementGetUsage(elem) != kHIDUsage_KeyboardCapsLock) {
return;
}
CFIndex pressed = IOHIDValueGetIntegerValue(value);
SDL_SendKeyboardKey(pressed ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
}
static CFDictionaryRef
CreateHIDDeviceMatchingDictionary(UInt32 usagePage, UInt32 usage)
{
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault,
0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if (dict) {
CFNumberRef number = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usagePage);
if (number) {
CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsagePageKey), number);
CFRelease(number);
number = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
if (number) {
CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsageKey), number);
CFRelease(number);
return dict;
}
}
CFRelease(dict);
}
return NULL;
}
static void
QuitHIDCallback()
{
if (!s_hidManager) {
return;
}
#if 0 /* Releasing here causes a crash on Mac OS X 10.10 and earlier,
* so just leak it for now. See bug 2157 for details.
*/
IOHIDManagerUnscheduleFromRunLoop(s_hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDManagerRegisterInputValueCallback(s_hidManager, NULL, NULL);
IOHIDManagerClose(s_hidManager, 0);
CFRelease(s_hidManager);
#endif
s_hidManager = NULL;
}
static void
InitHIDCallback()
{
s_hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!s_hidManager) {
return;
}
CFDictionaryRef keyboard = NULL, keypad = NULL;
CFArrayRef matches = NULL;
keyboard = CreateHIDDeviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard);
if (!keyboard) {
goto fail;
}
keypad = CreateHIDDeviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Keypad);
if (!keypad) {
goto fail;
}
CFDictionaryRef matchesList[] = { keyboard, keypad };
matches = CFArrayCreate(kCFAllocatorDefault, (const void **)matchesList, 2, NULL);
if (!matches) {
goto fail;
}
IOHIDManagerSetDeviceMatchingMultiple(s_hidManager, matches);
IOHIDManagerRegisterInputValueCallback(s_hidManager, HIDCallback, s_hidManager);
IOHIDManagerScheduleWithRunLoop(s_hidManager, CFRunLoopGetMain(), kCFRunLoopDefaultMode);
if (IOHIDManagerOpen(s_hidManager, kIOHIDOptionsTypeNone) == kIOReturnSuccess) {
goto cleanup;
}
fail:
QuitHIDCallback();
cleanup:
if (matches) {
CFRelease(matches);
}
if (keypad) {
CFRelease(keypad);
}
if (keyboard) {
CFRelease(keyboard);
}
}
/* This is a helper function for HandleModifierSide. This
* function reverts back to behavior before the distinction between
@ -585,8 +475,6 @@ Cocoa_InitKeyboard(_THIS)
data->modifierFlags = [NSEvent modifierFlags];
SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSEventModifierFlagCapsLock) != 0);
InitHIDCallback();
}
void
@ -712,7 +600,6 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
void
Cocoa_QuitKeyboard(_THIS)
{
QuitHIDCallback();
}
#endif /* SDL_VIDEO_DRIVER_COCOA */

View file

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

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -39,16 +39,16 @@
#define METALVIEW_TAG 255
@interface SDL_cocoametalview : NSView {
NSInteger _tag;
}
@interface SDL_cocoametalview : NSView
- (instancetype)initWithFrame:(NSRect)frame
scale:(CGFloat)scale;
highDPI:(BOOL)highDPI;
/* Override superclass tag so this class can set it. */
@property (assign, readonly) NSInteger tag;
@property (nonatomic) BOOL highDPI;
@end
SDL_cocoametalview* Cocoa_Mtl_AddMetalView(SDL_Window* window);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -33,13 +33,10 @@
@implementation SDL_cocoametalview
/* The synthesized getter should be called by super's viewWithTag. */
@synthesize tag = _tag;
/* Return a Metal-compatible layer. */
+ (Class)layerClass
{
return NSClassFromString(@"CAMetalLayer");
return NSClassFromString(@"CAMetalLayer");
}
/* Indicate the view wants to draw using a backing layer instead of drawRect. */
@ -57,28 +54,48 @@
}
- (instancetype)initWithFrame:(NSRect)frame
scale:(CGFloat)scale
highDPI:(BOOL)highDPI
{
if ((self = [super initWithFrame:frame])) {
_tag = METALVIEW_TAG;
if ((self = [super initWithFrame:frame])) {
self.highDPI = highDPI;
self.wantsLayer = YES;
/* Allow resize. */
self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
/* Set the desired scale. The default drawableSize of a CAMetalLayer
* is its bounds x its scale so nothing further needs to be done.
*/
self.layer.contentsScale = scale;
}
[self updateDrawableSize];
}
return self;
return self;
}
- (NSInteger)tag
{
return METALVIEW_TAG;
}
- (void)updateDrawableSize
{
CAMetalLayer *metalLayer = (CAMetalLayer *)self.layer;
CGSize size = self.bounds.size;
CGSize 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 = backingSize;
}
/* Set the size of the metal drawables when the view is resized. */
- (void)resizeWithOldSuperviewSize:(NSSize)oldSize
{
[super resizeWithOldSuperviewSize:oldSize];
[self updateDrawableSize];
}
@end
@ -88,24 +105,10 @@ Cocoa_Mtl_AddMetalView(SDL_Window* window)
{
SDL_WindowData* data = (__bridge SDL_WindowData *)window->driverdata;
NSView *view = data->nswindow.contentView;
CGFloat scale = 1.0;
BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
SDL_cocoametalview *metalview;
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
/* Set the scale to the natural scale factor of the screen - then
* the backing dimensions of the Metal view will match the pixel
* dimensions of the screen rather than the dimensions in points
* yielding high resolution on retine displays.
*
* N.B. In order for backingScaleFactor to be > 1,
* NSHighResolutionCapable must be set to true in the app's Info.plist.
*/
NSWindow* nswindow = data->nswindow;
if ([nswindow.screen respondsToSelector:@selector(backingScaleFactor)])
scale = data->nswindow.screen.backingScaleFactor;
}
SDL_cocoametalview *metalview
= [[SDL_cocoametalview alloc] initWithFrame:view.frame scale:scale];
metalview = [[SDL_cocoametalview alloc] initWithFrame:view.frame highDPI:highDPI];
[view addSubview:metalview];
return metalview;
}
@ -118,7 +121,7 @@ Cocoa_Mtl_GetDrawableSize(SDL_Window * window, int * w, int * h)
SDL_cocoametalview* metalview = [view viewWithTag:METALVIEW_TAG];
if (metalview) {
CAMetalLayer *layer = (CAMetalLayer*)metalview.layer;
assert(layer != NULL);
SDL_assert(layer != NULL);
if (w) {
*w = layer.drawableSize.width;
}

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -187,6 +187,7 @@ Cocoa_InitModes(_THIS)
CGDisplayErr result;
CGDirectDisplayID *displays;
CGDisplayCount numDisplays;
SDL_bool isstack;
int pass, i;
result = CGGetOnlineDisplayList(0, NULL, &numDisplays);
@ -194,11 +195,11 @@ Cocoa_InitModes(_THIS)
CG_SetError("CGGetOnlineDisplayList()", result);
return;
}
displays = SDL_stack_alloc(CGDirectDisplayID, numDisplays);
displays = SDL_small_alloc(CGDirectDisplayID, numDisplays, &isstack);
result = CGGetOnlineDisplayList(numDisplays, displays, &numDisplays);
if (result != kCGErrorSuccess) {
CG_SetError("CGGetOnlineDisplayList()", result);
SDL_stack_free(displays);
SDL_small_free(displays, isstack);
return;
}
@ -260,7 +261,7 @@ Cocoa_InitModes(_THIS)
SDL_free(display.name);
}
}
SDL_stack_free(displays);
SDL_small_free(displays, isstack);
}}
int
@ -299,13 +300,9 @@ Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
return -1;
}
const CGRect cgrect = CGDisplayBounds(cgdisplay);
const NSRect frame = [screen visibleFrame];
// !!! FIXME: I assume -[NSScreen visibleFrame] is relative to the origin of the screen in question and not the whole desktop.
// !!! FIXME: The math vs CGDisplayBounds might be incorrect if that's not the case, though. Check this.
rect->x = (int)(cgrect.origin.x + frame.origin.x);
rect->y = (int)(cgrect.origin.y + frame.origin.y);
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;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -25,7 +25,7 @@
#include "SDL_cocoavideo.h"
extern void Cocoa_InitMouse(_THIS);
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);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -315,14 +315,8 @@ Cocoa_GetGlobalMouseState(int *x, int *y)
const NSPoint cocoaLocation = [NSEvent mouseLocation];
Uint32 retval = 0;
for (NSScreen *screen in [NSScreen screens]) {
NSRect frame = [screen frame];
if (NSMouseInRect(cocoaLocation, frame, NO)) {
*x = (int) cocoaLocation.x;
*y = (int) ((frame.origin.y + frame.size.height) - cocoaLocation.y);
break;
}
}
*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;
@ -333,13 +327,16 @@ Cocoa_GetGlobalMouseState(int *x, int *y)
return retval;
}
void
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 = SDL_calloc(1, sizeof(SDL_MouseData));
mouse->driverdata = driverdata;
mouse->CreateCursor = Cocoa_CreateCursor;
mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
mouse->ShowCursor = Cocoa_ShowCursor;
@ -352,12 +349,12 @@ Cocoa_InitMouse(_THIS)
SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
Cocoa_InitMouseEventTap(mouse->driverdata);
Cocoa_InitMouseEventTap(driverdata);
SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
const NSPoint location = [NSEvent mouseLocation];
driverdata->lastMoveX = location.x;
driverdata->lastMoveY = location.y;
return 0;
}
void
@ -381,6 +378,7 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
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;
@ -414,14 +412,18 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
DLog("Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY);
}
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)deltaX, (int)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;
@ -432,7 +434,18 @@ Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
}
}
SDL_SendMouseWheel(window, mouse->mouseID, x, y, direction);
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
@ -456,9 +469,10 @@ Cocoa_QuitMouse(_THIS)
if (mouse) {
if (mouse->driverdata) {
Cocoa_QuitMouseEventTap(((SDL_MouseData*)mouse->driverdata));
}
SDL_free(mouse->driverdata);
SDL_free(mouse->driverdata);
mouse->driverdata = NULL;
}
}
}

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -211,7 +211,7 @@ Cocoa_InitMouseEventTap(SDL_MouseData* driverdata)
tapdata->thread = SDL_CreateThreadInternal(&Cocoa_MouseTapThread, "Event Tap Loop", 512 * 1024, tapdata);
if (tapdata->thread) {
/* Success - early out. Ownership transferred to thread. */
return;
return;
}
CFRelease(tapdata->tap);
}
@ -237,6 +237,13 @@ 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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -28,6 +28,12 @@
#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;
@ -46,7 +52,6 @@ struct SDL_GLDriverData
@end
/* OpenGL functions */
extern int Cocoa_GL_LoadLibrary(_THIS, const char *path);
extern void *Cocoa_GL_GetProcAddress(_THIS, const char *proc);
@ -61,6 +66,10 @@ 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_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -36,6 +36,12 @@
#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
@ -89,6 +95,18 @@
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;
@ -96,8 +114,8 @@
[contexts addObject:self];
}
if ([self view] != [windowdata->nswindow contentView]) {
[self setView:[windowdata->nswindow contentView]];
if ([self view] != contentview) {
[self setView:contentview];
if (self == [NSOpenGLContext currentContext]) {
[self update];
} else {
@ -347,10 +365,12 @@ Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
NSView *contentView = [windata->nswindow contentView];
NSRect viewport = [contentView bounds];
/* 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 (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) {
@ -408,8 +428,14 @@ 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;
}}
@ -423,6 +449,11 @@ Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
[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

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -107,12 +107,18 @@ typedef struct SDL_VideoData
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.10 SDK */
#if MAC_OS_X_VERSION_MAX_ALLOWED < 101100
#define NSEventSubtypeTouch NSTouchEventSubtype
#define NSEventSubtypeMouseEvent NSMouseEventSubtype
#endif
#endif /* SDL_cocoavideo_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -105,6 +105,7 @@ Cocoa_CreateDevice(int devindex)
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;
@ -167,22 +168,32 @@ Cocoa_VideoInit(_THIS)
Cocoa_InitModes(_this);
Cocoa_InitKeyboard(_this);
Cocoa_InitMouse(_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 */
@ -241,6 +252,9 @@ Cocoa_CreateImage(SDL_Surface * surface)
*
* 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)

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -19,7 +19,7 @@
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.
*/
@ -42,6 +42,7 @@
const char* defaultPaths[] = {
"vulkan.framework/vulkan",
"libvulkan.1.dylib",
"libvulkan.dylib",
"MoltenVK.framework/MoltenVK",
"libMoltenVK.dylib"
};
@ -58,8 +59,7 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
if (_this->vulkan_config.loader_handle) {
SDL_SetError("Vulkan/MoltenVK already loaded");
return -1;
return SDL_SetError("Vulkan Portability library is already loaded.");
}
/* Load the Vulkan loader library */
@ -68,9 +68,7 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
}
if (!path) {
/* MoltenVK framework, currently, v0.17.0, has a static library and is
* the recommended way to use the package. There is likely no object to
* load. */
/* Handle the case where Vulkan Portability is linked statically. */
vkGetInstanceProcAddr =
(PFN_vkGetInstanceProcAddr)dlsym(DEFAULT_HANDLE,
"vkGetInstanceProcAddr");
@ -80,6 +78,7 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
_this->vulkan_config.loader_handle = DEFAULT_HANDLE;
} else {
const char** paths;
const char *foundPath = NULL;
int numPaths;
int i;
@ -92,18 +91,17 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
paths = defaultPaths;
numPaths = SDL_arraysize(defaultPaths);
}
for (i=0; i < numPaths; i++) {
_this->vulkan_config.loader_handle = SDL_LoadObject(paths[i]);
if (_this->vulkan_config.loader_handle)
break;
else
continue;
}
if (i == numPaths)
return -1;
SDL_strlcpy(_this->vulkan_config.loader_path, paths[i],
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");
@ -140,11 +138,11 @@ int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
}
SDL_free(extensions);
if (!hasSurfaceExtension) {
SDL_SetError("Installed MoltenVK/Vulkan doesn't implement the "
SDL_SetError("Installed Vulkan Portability library doesn't implement the "
VK_KHR_SURFACE_EXTENSION_NAME " extension");
goto fail;
} else if (!hasMacOSSurfaceExtension) {
SDL_SetError("Installed MoltenVK/Vulkan doesn't implement the "
SDL_SetError("Installed Vulkan Portability library doesn't implement the "
VK_MVK_MACOS_SURFACE_EXTENSION_NAME "extension");
goto fail;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -113,6 +113,7 @@ struct SDL_WindowData
{
SDL_Window *window;
NSWindow *nswindow;
NSView *sdlContentView; /* nil if window is created via CreateWindowFrom */
NSMutableArray *nscontexts;
SDL_bool created;
SDL_bool inWindowMove;
@ -148,6 +149,7 @@ 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_ */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -54,6 +54,9 @@
#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
#ifndef MAC_OS_X_VERSION_10_12
#define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask
#endif
@interface SDLWindow : NSWindow <NSDraggingDestination>
/* These are needed for borderless/fullscreen windows */
@ -224,6 +227,16 @@ static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
static void
ScheduleContextUpdates(SDL_WindowData *data)
{
if (!data || !data->nscontexts) {
return;
}
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
NSMutableArray *contexts = data->nscontexts;
@synchronized (contexts) {
@ -235,13 +248,17 @@ ScheduleContextUpdates(SDL_WindowData *data)
}
}
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}
/* !!! FIXME: this should use a hint callback. */
static int
GetHintCtrlClickEmulateRightClick()
{
return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, SDL_FALSE);
return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, SDL_FALSE);
}
static NSUInteger
@ -618,7 +635,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
y = (int)(window->h - point.y);
if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
SDL_SendMouseMotion(window, 0, 0, x, y);
SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
}
}
@ -835,14 +852,31 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
}
}
/* We'll respond to key events by doing nothing so we don't beep.
/* We'll respond to key events by mostly doing nothing so we don't beep.
* We could handle key messages here, but we lose some in the NSApp dispatch,
* where they get converted to action messages, etc.
*/
- (void)flagsChanged:(NSEvent *)theEvent
{
/*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
/* Catch capslock in here as a special case:
https://developer.apple.com/library/archive/qa/qa1519/_index.html
Note that technote's check of keyCode doesn't work. At least on the
10.15 beta, capslock comes through here as keycode 255, but it's safe
to send duplicate key events; SDL filters them out quickly in
SDL_SendKeyboardKey(). */
/* Also note that SDL_SendKeyboardKey expects all capslock events to be
keypresses; it won't toggle the mod state if you send a keyrelease. */
const SDL_bool osenabled = ([theEvent modifierFlags] & NSEventModifierFlagCapsLock) ? SDL_TRUE : SDL_FALSE;
const SDL_bool sdlenabled = (SDL_GetModState() & KMOD_CAPS) ? SDL_TRUE : SDL_FALSE;
if (!osenabled && sdlenabled) {
SDL_ToggleModState(KMOD_CAPS, SDL_FALSE);
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
} else if (osenabled && !sdlenabled) {
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
}
}
- (void)keyDown:(NSEvent *)theEvent
{
@ -889,6 +923,12 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
- (void)mouseDown:(NSEvent *)theEvent
{
const SDL_Mouse *mouse = SDL_GetMouse();
if (!mouse) {
return;
}
const SDL_MouseID mouseID = mouse->mouseID;
int button;
int clicks;
@ -908,7 +948,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
switch ([theEvent buttonNumber]) {
case 0:
if (([theEvent modifierFlags] & NSEventModifierFlagControl) &&
GetHintCtrlClickEmulateRightClick()) {
GetHintCtrlClickEmulateRightClick()) {
wasCtrlLeft = YES;
button = SDL_BUTTON_RIGHT;
} else {
@ -928,7 +968,8 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
}
clicks = (int) [theEvent clickCount];
SDL_SendMouseButtonClicks(_data->window, 0, SDL_PRESSED, button, clicks);
SDL_SendMouseButtonClicks(_data->window, mouseID, SDL_PRESSED, button, clicks);
}
- (void)rightMouseDown:(NSEvent *)theEvent
@ -943,6 +984,12 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
- (void)mouseUp:(NSEvent *)theEvent
{
const SDL_Mouse *mouse = SDL_GetMouse();
if (!mouse) {
return;
}
const SDL_MouseID mouseID = mouse->mouseID;
int button;
int clicks;
@ -972,7 +1019,8 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
}
clicks = (int) [theEvent clickCount];
SDL_SendMouseButtonClicks(_data->window, 0, SDL_RELEASED, button, clicks);
SDL_SendMouseButtonClicks(_data->window, mouseID, SDL_RELEASED, button, clicks);
}
- (void)rightMouseUp:(NSEvent *)theEvent
@ -988,6 +1036,11 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
- (void)mouseMoved:(NSEvent *)theEvent
{
SDL_Mouse *mouse = SDL_GetMouse();
if (!mouse) {
return;
}
const SDL_MouseID mouseID = mouse->mouseID;
SDL_Window *window = _data->window;
NSPoint point;
int x, y;
@ -1035,7 +1088,8 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
#endif
}
}
SDL_SendMouseMotion(window, 0, 0, x, y);
SDL_SendMouseMotion(window, mouseID, 0, x, y);
}
- (void)mouseDragged:(NSEvent *)theEvent
@ -1060,7 +1114,12 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
{
/* probably a MacBook trackpad; make this look like a synthesized event.
This is backwards from reality, but better matches user expectations. */
const BOOL istrackpad = ([theEvent subtype] == NSEventSubtypeMouseEvent);
NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
const SDL_TouchID touchID = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[[touches anyObject] device];
int existingTouchCount = 0;
for (NSTouch* touch in touches) {
@ -1069,7 +1128,6 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
}
}
if (existingTouchCount == 0) {
SDL_TouchID touchID = (SDL_TouchID)(intptr_t)[[touches anyObject] device];
int numFingers = SDL_GetNumTouchFingers(touchID);
DLog("Reset Lost Fingers: %d", numFingers);
for (--numFingers; numFingers >= 0; --numFingers) {
@ -1101,9 +1159,23 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
{
NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
/* probably a MacBook trackpad; make this look like a synthesized event.
This is backwards from reality, but better matches user expectations. */
const BOOL istrackpad = ([theEvent subtype] == NSEventSubtypeMouseEvent);
for (NSTouch *touch in touches) {
const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
if (SDL_AddTouch(touchId, "") < 0) {
const SDL_TouchID touchId = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[touch device];
SDL_TouchDeviceType devtype = SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101202 /* Added in the 10.12.2 SDK. */
if ([touch respondsToSelector:@selector(type)]) {
if ([touch type] == NSTouchTypeDirect) {
devtype = SDL_TOUCH_DEVICE_DIRECT;
}
}
#endif
if (SDL_AddTouch(touchId, devtype, "") < 0) {
return;
}
@ -1143,14 +1215,18 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
- (BOOL)mouseDownCanMoveWindow;
- (void)drawRect:(NSRect)dirtyRect;
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
- (BOOL)wantsUpdateLayer;
- (void)updateLayer;
@end
@implementation SDLView
- (void)setSDLWindow:(SDL_Window*)window
{
_sdlWindow = window;
}
/* this is used on older macOS revisions. 10.8 and later use updateLayer. */
- (void)drawRect:(NSRect)dirtyRect
{
/* Force the graphics context to clear to black so we don't get a flash of
@ -1161,6 +1237,21 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
}
-(BOOL) wantsUpdateLayer
{
return YES;
}
-(void) updateLayer
{
/* Force the graphics context to clear to black so we don't get a flash of
white until the app is ready to draw. In practice on modern macOS, this
only gets called for window creation and other extraordinary events. */
self.layer.backgroundColor = CGColorGetConstantColor(kCGColorBlack);
ScheduleContextUpdates((SDL_WindowData *) _sdlWindow->driverdata);
SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
}
- (void)rightMouseDown:(NSEvent *)theEvent
{
[[self nextResponder] rightMouseDown:theEvent];
@ -1216,6 +1307,11 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
data->videodata = videodata;
data->nscontexts = [[NSMutableArray alloc] init];
/* Only store this for windows created by us since the content view might
* get replaced from under us otherwise, and we only need it when the
* window is guaranteed to be created by us (OpenGL contexts). */
data->sdlContentView = created ? [nswindow contentView] : nil;
/* Create an event listener for the window */
data->listener = [[Cocoa_WindowListener alloc] init];
@ -1323,6 +1419,13 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
return SDL_SetError("%s", [[e reason] UTF8String]);
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 /* Added in the 10.12.0 SDK. */
/* By default, don't allow users to make our window tabbed in 10.12 or later */
if ([nswindow respondsToSelector:@selector(setTabbingMode:)]) {
[nswindow setTabbingMode:NSWindowTabbingModeDisallowed];
}
#endif
if (videodata->allow_spaces) {
SDL_assert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6);
SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
@ -1338,11 +1441,20 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
[contentView setSDLWindow:window];
/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
[contentView setWantsBestResolutionOpenGLSurface:YES];
}
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#if SDL_VIDEO_OPENGL_ES2
#if SDL_VIDEO_OPENGL_EGL
if ((window->flags & SDL_WINDOW_OPENGL) &&
@ -1354,9 +1466,6 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
[nswindow setContentView:contentView];
[contentView release];
/* Allow files and folders to be dragged onto the window by users */
[nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
[nswindow release];
return -1;
@ -1778,6 +1887,8 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window)
[data->listener close];
[data->listener release];
if (data->created) {
/* Release the content view to avoid further updateLayer callbacks */
[data->nswindow setContentView:nil];
[data->nswindow close];
}
@ -1864,6 +1975,17 @@ Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)
return 0; /* just succeed, the real work is done elsewhere. */
}
void
Cocoa_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if (accept) {
[data->nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
} else {
[data->nswindow unregisterDraggedTypes];
}
}
int
Cocoa_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
{

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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

File diff suppressed because it is too large Load diff

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2019 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
@ -324,6 +324,7 @@ static const struct {
{ DSPF_YUY2, SDL_PIXELFORMAT_YUY2 }, /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains CbYCrY [31:0]) */
{ DSPF_UYVY, SDL_PIXELFORMAT_UYVY }, /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains YCbYCr [31:0]) */
{ DSPF_RGB555, SDL_PIXELFORMAT_RGB555 }, /* 16 bit RGB (2 byte, nothing @15, red 5@10, green 5@5, blue 5@0) */
{ DSPF_ABGR, SDL_PIXELFORMAT_ABGR8888 }, /* 32 bit ABGR (4 byte, alpha 8@24, blue 8@16, green 8@8, red 8@0) */
#if (ENABLE_LUT8)
{ DSPF_LUT8, SDL_PIXELFORMAT_INDEX8 }, /* 8 bit LUT (8 bit color and alpha lookup from palette) */
#endif
@ -370,7 +371,6 @@ static const struct {
{ DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR24 },
{ DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR888 },
{ DSPF_UNKNOWN, SDL_PIXELFORMAT_RGBA8888 },
{ DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR8888 },
{ DSPF_UNKNOWN, SDL_PIXELFORMAT_BGRA8888 },
{ DSPF_UNKNOWN, SDL_PIXELFORMAT_ARGB2101010 },
{ DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR4444 },

View file

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

View file

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

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