Browse Source
Adds support for just enough SDL3 to make `text_render_integration_test` work.pull/8212/head
43 changed files with 766 additions and 166 deletions
@ -0,0 +1,51 @@ |
|||||||
|
name: Linux x64 SDL3 Tests |
||||||
|
|
||||||
|
on: |
||||||
|
push: |
||||||
|
branches: |
||||||
|
- master |
||||||
|
paths-ignore: |
||||||
|
- '*.md' |
||||||
|
- 'docs/**' |
||||||
|
pull_request: |
||||||
|
types: [ opened, synchronize ] |
||||||
|
paths-ignore: |
||||||
|
- '*.md' |
||||||
|
- 'docs/**' |
||||||
|
workflow_dispatch: |
||||||
|
|
||||||
|
concurrency: |
||||||
|
group: ${{ github.workflow }}-${{ github.ref }} |
||||||
|
cancel-in-progress: true |
||||||
|
|
||||||
|
jobs: |
||||||
|
build: |
||||||
|
runs-on: ubuntu-22.04 |
||||||
|
|
||||||
|
steps: |
||||||
|
- uses: actions/checkout@v5 |
||||||
|
with: |
||||||
|
fetch-depth: 0 |
||||||
|
|
||||||
|
- name: Install dependencies |
||||||
|
run: | |
||||||
|
sudo apt-get update -y |
||||||
|
sudo apt-get install -y cmake curl g++ git libgtest-dev libgmock-dev libbenchmark-dev libfmt-dev libsodium-dev libpng-dev libbz2-dev wget |
||||||
|
|
||||||
|
- name: Cache CMake build folder |
||||||
|
uses: actions/cache@v4 |
||||||
|
with: |
||||||
|
path: build |
||||||
|
key: ${{ github.workflow }}-v2-${{ github.sha }} |
||||||
|
restore-keys: ${{ github.workflow }}-v2- |
||||||
|
|
||||||
|
# We specify `-DDEVILUTIONX_SYSTEM_BENCHMARK=OFF` to work around the following error: |
||||||
|
# lto1: fatal error: bytecode stream in file ‘/usr/lib/x86_64-linux-gnu/libbenchmark_main.a’ generated with LTO version 11.2 instead of the expected 11.3 |
||||||
|
- name: Build tests |
||||||
|
run: | |
||||||
|
cmake -S. -Bbuild -G Ninja -DUSE_SDL3=ON -DDEVILUTIONX_SYSTEM_SDL3=OFF -DDEVILUTIONX_STATIC_SDL3=ON -DDEVILUTIONX_SYSTEM_SDL_IMAGE=OFF -DNOSOUND=ON -DDEVILUTIONX_SYSTEM_BENCHMARK=OFF |
||||||
|
wget -qnc https://github.com/diasurgical/devilutionx-assets/releases/download/v2/spawn.mpq -P build |
||||||
|
cmake --build build -j $(nproc) --target text_render_integration_test |
||||||
|
|
||||||
|
- name: Run tests |
||||||
|
run: cd build && ctest -R 'TextRenderIntegrationTest' --output-on-failure |
||||||
@ -0,0 +1,31 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <cstdint> |
||||||
|
|
||||||
|
#ifdef USE_SDL3 |
||||||
|
#include <SDL3/SDL_endian.h> |
||||||
|
#else |
||||||
|
#include <SDL_endian.h> |
||||||
|
#endif |
||||||
|
|
||||||
|
namespace devilution { |
||||||
|
|
||||||
|
constexpr uint16_t Swap16LE(uint16_t val) |
||||||
|
{ |
||||||
|
#ifdef USE_SDL3 |
||||||
|
return SDL_Swap16LE(val); |
||||||
|
#else |
||||||
|
return SDL_SwapLE16(val); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
constexpr uint32_t Swap32LE(uint32_t val) |
||||||
|
{ |
||||||
|
#ifdef USE_SDL3 |
||||||
|
return SDL_Swap32LE(val); |
||||||
|
#else |
||||||
|
return SDL_SwapLE32(val); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace devilution
|
||||||
@ -1,72 +1,118 @@ |
|||||||
#pragma once |
#pragma once |
||||||
|
|
||||||
#include <SDL.h> |
#ifdef USE_SDL3 |
||||||
#ifdef USE_SDL1 |
#include <SDL3/SDL_error.h> |
||||||
#include "utils/sdl2_to_1_2_backports.h" |
#include <SDL3/SDL_pixels.h> |
||||||
#else |
#include <SDL3/SDL_render.h> |
||||||
#include "utils/sdl2_backports.h" |
#include <SDL3/SDL_stdinc.h> |
||||||
#endif |
#include <SDL3/SDL_surface.h> |
||||||
|
#else |
||||||
#include "appfat.h" |
#include <SDL.h> |
||||||
#include "utils/sdl_ptrs.h" |
#ifdef USE_SDL1 |
||||||
|
#include "utils/sdl2_to_1_2_backports.h" |
||||||
#define NonNull(x) NullErrDlg(x, __FILE__, __LINE__) |
#else |
||||||
|
#include "utils/sdl2_backports.h" |
||||||
namespace devilution { |
#endif |
||||||
|
#endif |
||||||
namespace SDLWrap { |
|
||||||
|
#include "appfat.h" |
||||||
template <typename T> |
#include "utils/sdl_ptrs.h" |
||||||
T NullErrDlg(T x, const char *file, int line) |
|
||||||
{ |
#define NonNull(x) NullErrDlg(x, __FILE__, __LINE__) |
||||||
if (x == nullptr) |
|
||||||
ErrDlg("SDL Error", SDL_GetError(), file, line); |
namespace devilution { |
||||||
return x; |
|
||||||
} |
namespace SDLWrap { |
||||||
|
|
||||||
inline SDLSurfaceUniquePtr CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) |
template <typename T> |
||||||
{ |
T NullErrDlg(T x, const char *file, int line) |
||||||
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurface(flags, width, height, depth, Rmask, Gmask, Bmask, Amask)) }; |
{ |
||||||
} |
if (x == nullptr) |
||||||
|
ErrDlg("SDL Error", SDL_GetError(), file, line); |
||||||
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format) |
return x; |
||||||
{ |
} |
||||||
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format)) }; |
|
||||||
} |
inline SDLSurfaceUniquePtr CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) |
||||||
|
{ |
||||||
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 format) |
#ifdef USE_SDL3 |
||||||
{ |
return SDLSurfaceUniquePtr { NonNull(SDL_CreateSurface(width, height, SDL_GetPixelFormatForMasks(depth, Rmask, Gmask, Bmask, Amask))) }; |
||||||
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurfaceWithFormatFrom(pixels, width, height, depth, pitch, format)) }; |
#else |
||||||
} |
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurface(flags, width, height, depth, Rmask, Gmask, Bmask, Amask)) }; |
||||||
|
#endif |
||||||
#ifndef USE_SDL1 |
} |
||||||
inline SDLSurfaceUniquePtr ConvertSurface(SDL_Surface *src, const SDL_PixelFormat *fmt, Uint32 flags) |
|
||||||
#else |
#ifdef USE_SDL3 |
||||||
inline SDLSurfaceUniquePtr ConvertSurface(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags) |
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, SDL_PixelFormat format) |
||||||
#endif |
{ |
||||||
{ |
return SDLSurfaceUniquePtr { NonNull(SDL_CreateSurface(width, height, format)) }; |
||||||
return SDLSurfaceUniquePtr { NonNull(SDL_ConvertSurface(src, fmt, flags)) }; |
} |
||||||
} |
#else |
||||||
|
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format) |
||||||
#ifndef USE_SDL1 |
{ |
||||||
inline SDLSurfaceUniquePtr ConvertSurfaceFormat(SDL_Surface *src, Uint32 pixel_format, Uint32 flags) |
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format)) }; |
||||||
{ |
} |
||||||
return SDLSurfaceUniquePtr { NonNull(SDL_ConvertSurfaceFormat(src, pixel_format, flags)) }; |
#endif |
||||||
} |
|
||||||
#endif |
#ifdef USE_SDL3 |
||||||
|
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, SDL_PixelFormat format) |
||||||
#ifndef USE_SDL1 |
{ |
||||||
inline SDLTextureUniquePtr CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int h) |
return SDLSurfaceUniquePtr { NonNull(SDL_CreateSurfaceFrom(width, height, format, pixels, pitch)) }; |
||||||
{ |
} |
||||||
return SDLTextureUniquePtr { NonNull(SDL_CreateTexture(renderer, format, access, w, h)) }; |
#else |
||||||
} |
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 format) |
||||||
#endif |
{ |
||||||
|
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurfaceWithFormatFrom(pixels, width, height, depth, pitch, format)) }; |
||||||
inline SDLPaletteUniquePtr AllocPalette(int ncolors = 256) |
} |
||||||
{ |
#endif |
||||||
return SDLPaletteUniquePtr { NonNull(SDL_AllocPalette(ncolors)) }; |
|
||||||
} |
#ifndef USE_SDL1 |
||||||
|
inline SDLSurfaceUniquePtr ConvertSurface(SDL_Surface *src, const SDL_PixelFormat *fmt, Uint32 flags) |
||||||
} // namespace SDLWrap
|
#else |
||||||
|
inline SDLSurfaceUniquePtr ConvertSurface(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags) |
||||||
} // namespace devilution
|
#endif |
||||||
|
{ |
||||||
|
#ifdef USE_SDL3 |
||||||
|
return SDLSurfaceUniquePtr { NonNull(SDL_ConvertSurface(src, *fmt)) }; |
||||||
|
#else |
||||||
|
return SDLSurfaceUniquePtr { NonNull(SDL_ConvertSurface(src, fmt, flags)) }; |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
#ifndef USE_SDL1 |
||||||
|
#ifdef USE_SDL3 |
||||||
|
inline SDLSurfaceUniquePtr ConvertSurfaceFormat(SDL_Surface *src, SDL_PixelFormat format, Uint32 flags) |
||||||
|
{ |
||||||
|
return SDLSurfaceUniquePtr { NonNull(SDL_ConvertSurface(src, format)) }; |
||||||
|
} |
||||||
|
#else |
||||||
|
inline SDLSurfaceUniquePtr ConvertSurfaceFormat(SDL_Surface *src, Uint32 format, Uint32 flags) |
||||||
|
{ |
||||||
|
return SDLSurfaceUniquePtr { NonNull(SDL_ConvertSurfaceFormat(src, format, flags)) }; |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifdef USE_SDL3 |
||||||
|
inline SDLTextureUniquePtr CreateTexture(SDL_Renderer *renderer, SDL_PixelFormat format, SDL_TextureAccess access, int w, int h) |
||||||
|
{ |
||||||
|
return SDLTextureUniquePtr { NonNull(SDL_CreateTexture(renderer, format, access, w, h)) }; |
||||||
|
} |
||||||
|
#else |
||||||
|
inline SDLTextureUniquePtr CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int h) |
||||||
|
{ |
||||||
|
return SDLTextureUniquePtr { NonNull(SDL_CreateTexture(renderer, format, access, w, h)) }; |
||||||
|
} |
||||||
|
#endif |
||||||
|
#endif |
||||||
|
|
||||||
|
inline SDLPaletteUniquePtr AllocPalette(int ncolors = 256) |
||||||
|
{ |
||||||
|
#ifdef USE_SDL3 |
||||||
|
return SDLPaletteUniquePtr { NonNull(SDL_CreatePalette(ncolors)) }; |
||||||
|
#else |
||||||
|
return SDLPaletteUniquePtr { NonNull(SDL_AllocPalette(ncolors)) }; |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace SDLWrap
|
||||||
|
|
||||||
|
} // namespace devilution
|
||||||
|
|||||||
Loading…
Reference in new issue