mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-19 19:28:28 +00:00
Renamed SDL_rand() to SDL_rand_bits() and updated tests
This commit is contained in:
parent
237bbfcb9d
commit
8f29f8cae5
12 changed files with 110 additions and 98 deletions
|
@ -26,9 +26,9 @@
|
|||
#include <libswscale/swscale.h>
|
||||
|
||||
#ifdef HAVE_EGL
|
||||
#include <SDL3/SDL_egl.h>
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
#include <SDL3/SDL_opengles2.h>
|
||||
#include <SDL3/SDL_egl.h>
|
||||
|
||||
#include <libavutil/hwcontext_drm.h>
|
||||
|
||||
|
@ -43,20 +43,20 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#define DRM_FORMAT_MOD_VENDOR_NONE 0
|
||||
#define DRM_FORMAT_RESERVED ((1ULL << 56) - 1)
|
||||
#define DRM_FORMAT_MOD_VENDOR_NONE 0
|
||||
#define DRM_FORMAT_RESERVED ((1ULL << 56) - 1)
|
||||
|
||||
#define fourcc_mod_get_vendor(modifier) \
|
||||
(((modifier) >> 56) & 0xff)
|
||||
|
||||
#define fourcc_mod_is_vendor(modifier, vendor) \
|
||||
(fourcc_mod_get_vendor(modifier) == DRM_FORMAT_MOD_VENDOR_## vendor)
|
||||
(fourcc_mod_get_vendor(modifier) == DRM_FORMAT_MOD_VENDOR_##vendor)
|
||||
|
||||
#define fourcc_mod_code(vendor, val) \
|
||||
((((Uint64)DRM_FORMAT_MOD_VENDOR_## vendor) << 56) | ((val) & 0x00ffffffffffffffULL))
|
||||
((((Uint64)DRM_FORMAT_MOD_VENDOR_##vendor) << 56) | ((val) & 0x00ffffffffffffffULL))
|
||||
|
||||
#define DRM_FORMAT_MOD_INVALID fourcc_mod_code(NONE, DRM_FORMAT_RESERVED)
|
||||
#define DRM_FORMAT_MOD_LINEAR fourcc_mod_code(NONE, 0)
|
||||
#define DRM_FORMAT_MOD_INVALID fourcc_mod_code(NONE, DRM_FORMAT_RESERVED)
|
||||
#define DRM_FORMAT_MOD_LINEAR fourcc_mod_code(NONE, 0)
|
||||
|
||||
#ifdef SDL_PLATFORM_APPLE
|
||||
#include <CoreVideo/CoreVideo.h>
|
||||
|
@ -71,7 +71,6 @@
|
|||
|
||||
#include "icon.h"
|
||||
|
||||
|
||||
static SDL_Texture *sprite;
|
||||
static SDL_FRect *positions;
|
||||
static SDL_FRect *velocities;
|
||||
|
@ -228,7 +227,8 @@ static SDL_bool CreateWindowAndRenderer(SDL_WindowFlags window_flags, const char
|
|||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static SDL_Texture *CreateTexture(SDL_Renderer *r, unsigned char *data, unsigned int len, int *w, int *h) {
|
||||
static SDL_Texture *CreateTexture(SDL_Renderer *r, unsigned char *data, unsigned int len, int *w, int *h)
|
||||
{
|
||||
SDL_Texture *texture = NULL;
|
||||
SDL_Surface *surface;
|
||||
SDL_IOStream *src = SDL_IOFromConstMem(data, len);
|
||||
|
@ -624,7 +624,7 @@ static SDL_bool GetTextureForMemoryFrame(AVFrame *frame, SDL_Texture **texture)
|
|||
uint8_t *pixels[4];
|
||||
int pitch[4];
|
||||
if (SDL_LockTexture(*texture, NULL, (void **)&pixels[0], &pitch[0]) == 0) {
|
||||
sws_scale(sws_container->context, (const uint8_t * const *)frame->data, frame->linesize, 0, frame->height, pixels, pitch);
|
||||
sws_scale(sws_container->context, (const uint8_t *const *)frame->data, frame->linesize, 0, frame->height, pixels, pitch);
|
||||
SDL_UnlockTexture(*texture);
|
||||
}
|
||||
} else {
|
||||
|
@ -636,12 +636,12 @@ static SDL_bool GetTextureForMemoryFrame(AVFrame *frame, SDL_Texture **texture)
|
|||
case SDL_PIXELFORMAT_IYUV:
|
||||
if (frame->linesize[0] > 0 && frame->linesize[1] > 0 && frame->linesize[2] > 0) {
|
||||
SDL_UpdateYUVTexture(*texture, NULL, frame->data[0], frame->linesize[0],
|
||||
frame->data[1], frame->linesize[1],
|
||||
frame->data[2], frame->linesize[2]);
|
||||
frame->data[1], frame->linesize[1],
|
||||
frame->data[2], frame->linesize[2]);
|
||||
} else if (frame->linesize[0] < 0 && frame->linesize[1] < 0 && frame->linesize[2] < 0) {
|
||||
SDL_UpdateYUVTexture(*texture, NULL, frame->data[0] + frame->linesize[0] * (frame->height - 1), -frame->linesize[0],
|
||||
frame->data[1] + frame->linesize[1] * (AV_CEIL_RSHIFT(frame->height, 1) - 1), -frame->linesize[1],
|
||||
frame->data[2] + frame->linesize[2] * (AV_CEIL_RSHIFT(frame->height, 1) - 1), -frame->linesize[2]);
|
||||
SDL_UpdateYUVTexture(*texture, NULL, frame->data[0] + frame->linesize[0] * (frame->height - 1), -frame->linesize[0],
|
||||
frame->data[1] + frame->linesize[1] * (AV_CEIL_RSHIFT(frame->height, 1) - 1), -frame->linesize[1],
|
||||
frame->data[2] + frame->linesize[2] * (AV_CEIL_RSHIFT(frame->height, 1) - 1), -frame->linesize[2]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -895,7 +895,7 @@ static SDL_bool GetTextureForDRMFrame(AVFrame *frame, SDL_Texture **texture)
|
|||
for (i = 0; i < desc->nb_layers; ++i) {
|
||||
const AVDRMLayerDescriptor *layer = &desc->layers[i];
|
||||
for (j = 0; j < layer->nb_planes; ++j) {
|
||||
static const uint32_t formats[ 2 ] = { DRM_FORMAT_R8, DRM_FORMAT_GR88 };
|
||||
static const uint32_t formats[2] = { DRM_FORMAT_R8, DRM_FORMAT_GR88 };
|
||||
const AVDRMPlaneDescriptor *plane = &layer->planes[j];
|
||||
const AVDRMObjectDescriptor *object = &desc->objects[plane->object_index];
|
||||
|
||||
|
@ -906,10 +906,10 @@ static SDL_bool GetTextureForDRMFrame(AVFrame *frame, SDL_Texture **texture)
|
|||
attr[k++] = formats[i];
|
||||
|
||||
attr[k++] = EGL_WIDTH;
|
||||
attr[k++] = frames->width / ( image_index + 1 ); /* half size for chroma */
|
||||
attr[k++] = frames->width / (image_index + 1); /* half size for chroma */
|
||||
|
||||
attr[k++] = EGL_HEIGHT;
|
||||
attr[k++] = frames->height / ( image_index + 1 );
|
||||
attr[k++] = frames->height / (image_index + 1);
|
||||
|
||||
attr[k++] = EGL_DMA_BUF_PLANE0_FD_EXT;
|
||||
attr[k++] = object->fd;
|
||||
|
@ -922,7 +922,7 @@ static SDL_bool GetTextureForDRMFrame(AVFrame *frame, SDL_Texture **texture)
|
|||
|
||||
if (has_EGL_EXT_image_dma_buf_import_modifiers) {
|
||||
attr[k++] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT;
|
||||
attr[k++] = (object->format_modifier >> 0) & 0xFFFFFFFF;
|
||||
attr[k++] = (object->format_modifier >> 0) & 0xFFFFFFFF;
|
||||
|
||||
attr[k++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
|
||||
attr[k++] = (object->format_modifier >> 32) & 0xFFFFFFFF;
|
||||
|
@ -1227,7 +1227,7 @@ static void InterleaveAudio(AVFrame *frame, const SDL_AudioSpec *spec)
|
|||
for (c = 0; c < spec->channels; ++c) {
|
||||
const Uint8 *src = frame->data[c];
|
||||
Uint8 *dst = data + c * samplesize;
|
||||
for (n = frame->nb_samples; n--; ) {
|
||||
for (n = frame->nb_samples; n--;) {
|
||||
SDL_memcpy(dst, src, samplesize);
|
||||
src += samplesize;
|
||||
dst += framesize;
|
||||
|
@ -1251,7 +1251,7 @@ static void HandleAudioFrame(AVFrame *frame)
|
|||
}
|
||||
}
|
||||
|
||||
static void av_log_callback(void* avcl, int level, const char *fmt, va_list vl)
|
||||
static void av_log_callback(void *avcl, int level, const char *fmt, va_list vl)
|
||||
{
|
||||
const char *pszCategory = NULL;
|
||||
char *message;
|
||||
|
@ -1290,7 +1290,8 @@ static void av_log_callback(void* avcl, int level, const char *fmt, va_list vl)
|
|||
SDL_free(message);
|
||||
}
|
||||
|
||||
static void print_usage(SDLTest_CommonState *state, const char *argv0) {
|
||||
static void print_usage(SDLTest_CommonState *state, const char *argv0)
|
||||
{
|
||||
static const char *options[] = { "[--verbose]", "[--sprites N]", "[--audio-codec codec]", "[--video-codec codec]", "[--software]", "video_file", NULL };
|
||||
SDLTest_CommonLogUsage(state, argv0, options);
|
||||
}
|
||||
|
@ -1325,7 +1326,7 @@ int main(int argc, char *argv[])
|
|||
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Log ffmpeg messages */
|
||||
av_log_set_callback( av_log_callback );
|
||||
av_log_set_callback(av_log_callback);
|
||||
|
||||
/* Parse commandline */
|
||||
for (i = 1; i < argc;) {
|
||||
|
@ -1336,14 +1337,14 @@ int main(int argc, char *argv[])
|
|||
if (SDL_strcmp(argv[i], "--verbose") == 0) {
|
||||
verbose = SDL_TRUE;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcmp(argv[i], "--sprites") == 0 && argv[i+1]) {
|
||||
num_sprites = SDL_atoi(argv[i+1]);
|
||||
} else if (SDL_strcmp(argv[i], "--sprites") == 0 && argv[i + 1]) {
|
||||
num_sprites = SDL_atoi(argv[i + 1]);
|
||||
consumed = 2;
|
||||
} else if (SDL_strcmp(argv[i], "--audio-codec") == 0 && argv[i+1]) {
|
||||
audio_codec_name = argv[i+1];
|
||||
} else if (SDL_strcmp(argv[i], "--audio-codec") == 0 && argv[i + 1]) {
|
||||
audio_codec_name = argv[i + 1];
|
||||
consumed = 2;
|
||||
} else if (SDL_strcmp(argv[i], "--video-codec") == 0 && argv[i+1]) {
|
||||
video_codec_name = argv[i+1];
|
||||
} else if (SDL_strcmp(argv[i], "--video-codec") == 0 && argv[i + 1]) {
|
||||
video_codec_name = argv[i + 1];
|
||||
consumed = 2;
|
||||
} else if (SDL_strcmp(argv[i], "--software") == 0) {
|
||||
software_only = SDL_TRUE;
|
||||
|
@ -1369,7 +1370,7 @@ int main(int argc, char *argv[])
|
|||
goto quit;
|
||||
}
|
||||
|
||||
if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0) {
|
||||
if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO) < 0) {
|
||||
return_code = 2;
|
||||
goto quit;
|
||||
}
|
||||
|
@ -1484,15 +1485,15 @@ int main(int argc, char *argv[])
|
|||
SDL_Rect viewport;
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
for (i = 0; i < num_sprites; ++i) {
|
||||
positions[i].x = (float)(SDL_rand() % (viewport.w - sprite_w));
|
||||
positions[i].y = (float)(SDL_rand() % (viewport.h - sprite_h));
|
||||
positions[i].x = (float)SDL_rand_n(viewport.w - sprite_w);
|
||||
positions[i].y = (float)SDL_rand_n(viewport.h - sprite_h);
|
||||
positions[i].w = (float)sprite_w;
|
||||
positions[i].h = (float)sprite_h;
|
||||
velocities[i].x = 0.0f;
|
||||
velocities[i].y = 0.0f;
|
||||
while (velocities[i].x == 0.f || velocities[i].y == 0.f) {
|
||||
velocities[i].x = (float)((SDL_rand() % (2 + 1)) - 1);
|
||||
velocities[i].y = (float)((SDL_rand() % (2 + 1)) - 1);
|
||||
velocities[i].x = (float)(SDL_rand_n(2 + 1) - 1);
|
||||
velocities[i].y = (float)(SDL_rand_n(2 + 1) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue