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 |
||||
|
||||
#include <SDL.h> |
||||
#ifdef USE_SDL1 |
||||
#include "utils/sdl2_to_1_2_backports.h" |
||||
#else |
||||
#include "utils/sdl2_backports.h" |
||||
#endif |
||||
|
||||
#include "appfat.h" |
||||
#include "utils/sdl_ptrs.h" |
||||
|
||||
#define NonNull(x) NullErrDlg(x, __FILE__, __LINE__) |
||||
|
||||
namespace devilution { |
||||
|
||||
namespace SDLWrap { |
||||
|
||||
template <typename T> |
||||
T NullErrDlg(T x, const char *file, int line) |
||||
{ |
||||
if (x == nullptr) |
||||
ErrDlg("SDL Error", SDL_GetError(), file, line); |
||||
return x; |
||||
} |
||||
|
||||
inline SDLSurfaceUniquePtr CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) |
||||
{ |
||||
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurface(flags, width, height, depth, Rmask, Gmask, Bmask, Amask)) }; |
||||
} |
||||
|
||||
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format) |
||||
{ |
||||
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format)) }; |
||||
} |
||||
|
||||
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 format) |
||||
{ |
||||
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurfaceWithFormatFrom(pixels, width, height, depth, pitch, format)) }; |
||||
} |
||||
|
||||
#ifndef USE_SDL1 |
||||
inline SDLSurfaceUniquePtr ConvertSurface(SDL_Surface *src, const SDL_PixelFormat *fmt, Uint32 flags) |
||||
#else |
||||
inline SDLSurfaceUniquePtr ConvertSurface(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags) |
||||
#endif |
||||
{ |
||||
return SDLSurfaceUniquePtr { NonNull(SDL_ConvertSurface(src, fmt, flags)) }; |
||||
} |
||||
|
||||
#ifndef USE_SDL1 |
||||
inline SDLSurfaceUniquePtr ConvertSurfaceFormat(SDL_Surface *src, Uint32 pixel_format, Uint32 flags) |
||||
{ |
||||
return SDLSurfaceUniquePtr { NonNull(SDL_ConvertSurfaceFormat(src, pixel_format, flags)) }; |
||||
} |
||||
#endif |
||||
|
||||
#ifndef USE_SDL1 |
||||
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 |
||||
|
||||
inline SDLPaletteUniquePtr AllocPalette(int ncolors = 256) |
||||
{ |
||||
return SDLPaletteUniquePtr { NonNull(SDL_AllocPalette(ncolors)) }; |
||||
} |
||||
|
||||
} // namespace SDLWrap
|
||||
|
||||
} // namespace devilution
|
||||
#pragma once |
||||
|
||||
#ifdef USE_SDL3 |
||||
#include <SDL3/SDL_error.h> |
||||
#include <SDL3/SDL_pixels.h> |
||||
#include <SDL3/SDL_render.h> |
||||
#include <SDL3/SDL_stdinc.h> |
||||
#include <SDL3/SDL_surface.h> |
||||
#else |
||||
#include <SDL.h> |
||||
#ifdef USE_SDL1 |
||||
#include "utils/sdl2_to_1_2_backports.h" |
||||
#else |
||||
#include "utils/sdl2_backports.h" |
||||
#endif |
||||
#endif |
||||
|
||||
#include "appfat.h" |
||||
#include "utils/sdl_ptrs.h" |
||||
|
||||
#define NonNull(x) NullErrDlg(x, __FILE__, __LINE__) |
||||
|
||||
namespace devilution { |
||||
|
||||
namespace SDLWrap { |
||||
|
||||
template <typename T> |
||||
T NullErrDlg(T x, const char *file, int line) |
||||
{ |
||||
if (x == nullptr) |
||||
ErrDlg("SDL Error", SDL_GetError(), file, line); |
||||
return x; |
||||
} |
||||
|
||||
inline SDLSurfaceUniquePtr CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) |
||||
{ |
||||
#ifdef USE_SDL3 |
||||
return SDLSurfaceUniquePtr { NonNull(SDL_CreateSurface(width, height, SDL_GetPixelFormatForMasks(depth, Rmask, Gmask, Bmask, Amask))) }; |
||||
#else |
||||
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurface(flags, width, height, depth, Rmask, Gmask, Bmask, Amask)) }; |
||||
#endif |
||||
} |
||||
|
||||
#ifdef USE_SDL3 |
||||
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, SDL_PixelFormat format) |
||||
{ |
||||
return SDLSurfaceUniquePtr { NonNull(SDL_CreateSurface(width, height, format)) }; |
||||
} |
||||
#else |
||||
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format) |
||||
{ |
||||
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format)) }; |
||||
} |
||||
#endif |
||||
|
||||
#ifdef USE_SDL3 |
||||
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, SDL_PixelFormat format) |
||||
{ |
||||
return SDLSurfaceUniquePtr { NonNull(SDL_CreateSurfaceFrom(width, height, format, pixels, pitch)) }; |
||||
} |
||||
#else |
||||
inline SDLSurfaceUniquePtr CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 format) |
||||
{ |
||||
return SDLSurfaceUniquePtr { NonNull(SDL_CreateRGBSurfaceWithFormatFrom(pixels, width, height, depth, pitch, format)) }; |
||||
} |
||||
#endif |
||||
|
||||
#ifndef USE_SDL1 |
||||
inline SDLSurfaceUniquePtr ConvertSurface(SDL_Surface *src, const SDL_PixelFormat *fmt, Uint32 flags) |
||||
#else |
||||
inline SDLSurfaceUniquePtr ConvertSurface(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags) |
||||
#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