From f2bd422e4e80478297da0fe550840a54546cd04f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 25 Oct 2023 06:08:31 +0300 Subject: [PATCH 16/20] sdl3: Stop using deprecated SDL_CreateRGBSurface() See osdn #48893 Signed-off-by: Marko Lindqvist --- client/gui-sdl3/graphics.c | 47 +++++++++--------------------------- client/gui-sdl3/graphics.h | 2 +- client/gui-sdl3/gui_string.c | 6 ++--- client/gui-sdl3/sprite.c | 10 +------- 4 files changed, 16 insertions(+), 49 deletions(-) diff --git a/client/gui-sdl3/graphics.c b/client/gui-sdl3/graphics.c index a762dd5523..a6438282fc 100644 --- a/client/gui-sdl3/graphics.c +++ b/client/gui-sdl3/graphics.c @@ -232,8 +232,7 @@ SDL_Surface *crop_rect_from_surface(SDL_Surface *psource, { SDL_Surface *new_surf = create_surf_with_format(psource->format, prect ? prect->w : psource->w, - prect ? prect->h : psource->h, - SDL_SWSURFACE); + prect ? prect->h : psource->h); if (alphablit(psource, prect, new_surf, NULL, 255) != 0) { FREESURFACE(new_surf); @@ -320,19 +319,15 @@ SDL_Surface *load_surf(const char *fname) MUST NOT BE USED IF NO SDLSCREEN IS SET **************************************************************************/ SDL_Surface *create_surf_with_format(SDL_PixelFormat *pf, - int width, int height, - Uint32 flags) + int width, int height) { - SDL_Surface *surf = SDL_CreateRGBSurface(flags, width, height, - pf->BitsPerPixel, - pf->Rmask, - pf->Gmask, - pf->Bmask, pf->Amask); + SDL_Surface *surf = SDL_CreateSurfaceFrom(NULL, width, height, + 0, pf->format); if (surf == NULL) { log_error(_("Unable to create Sprite (Surface) of size " - "%d x %d %d Bits in format %d"), - width, height, pf->BitsPerPixel, flags); + "%d x %d %d Bits"), + width, height, pf->BitsPerPixel); return NULL; } @@ -344,7 +339,7 @@ SDL_Surface *create_surf_with_format(SDL_PixelFormat *pf, **************************************************************************/ SDL_Surface *create_surf(int width, int height, Uint32 flags) { - return create_surf_with_format(main_surface->format, width, height, flags); + return create_surf_with_format(main_surface->format, width, height); } /**********************************************************************//** @@ -553,21 +548,8 @@ bool create_surfaces(int width, int height) free_surfaces(); - if (is_bigendian()) { - main_surface = SDL_CreateRGBSurface(0, width, height, 32, - 0x0000FF00, 0x00FF0000, - 0xFF000000, 0x000000FF); - main_data.map = SDL_CreateRGBSurface(0, width, height, 32, - 0x0000FF00, 0x00FF0000, - 0xFF000000, 0x000000FF); - } else { - main_surface = SDL_CreateRGBSurface(0, width, height, 32, - 0x00FF0000, 0x0000FF00, - 0x000000FF, 0xFF000000); - main_data.map = SDL_CreateRGBSurface(0, width, height, 32, - 0x00FF0000, 0x0000FF00, - 0x000000FF, 0xFF000000); - } + main_surface = SDL_CreateSurface(width, height, SDL_PIXELFORMAT_RGBA8888); + main_data.map = SDL_CreateSurface(width, height, SDL_PIXELFORMAT_RGBA8888); if (main_surface == NULL || main_data.map == NULL) { log_fatal(_("Failed to create RGB surface: %s"), SDL_GetError()); @@ -1302,15 +1284,8 @@ SDL_Surface *resize_surface_box(const SDL_Surface *psrc, **************************************************************************/ SDL_Surface *copy_surface(SDL_Surface *src) { - SDL_Surface *dst; - - dst = SDL_CreateRGBSurface(0, src->w, src->h, src->format->BitsPerPixel, - src->format->Rmask, src->format->Gmask, - src->format->Bmask, src->format->Amask); - - SDL_BlitSurface(src, NULL, dst, NULL); - - return dst; + return SDL_CreateSurfaceFrom(src->pixels, src->w, src->h, src->pitch, + src->format->format); } /* ============ Freeciv game graphics function =========== */ diff --git a/client/gui-sdl3/graphics.h b/client/gui-sdl3/graphics.h index 48046066cd..3e05fad023 100644 --- a/client/gui-sdl3/graphics.h +++ b/client/gui-sdl3/graphics.h @@ -247,7 +247,7 @@ int screen_blit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Rect *dstrect, SDL_Surface *load_surf(const char *fname); SDL_Surface *create_surf_with_format(SDL_PixelFormat *pf, - int width, int height, Uint32 flags); + int width, int height); SDL_Surface *create_surf(int width, int height, Uint32 flags); SDL_Surface *convert_surf(SDL_Surface *surf_in); diff --git a/client/gui-sdl3/gui_string.c b/client/gui-sdl3/gui_string.c index 226402de78..e0bc2f7f3f 100644 --- a/client/gui-sdl3/gui_string.c +++ b/client/gui-sdl3/gui_string.c @@ -376,9 +376,9 @@ static SDL_Surface *create_utf8_multi_surf(utf8_str *pstr) SDL_SetColorKey(text, SDL_TRUE, color); break; case 2: - text = create_surf_with_format(tmp[0]->format, - w, count * tmp[0]->h, tmp[0]->flags); - SDL_FillRect(text, NULL, color); + text = create_surf_with_format(tmp[0]->format, + w, count * tmp[0]->h); + SDL_FillRect(text, NULL, color); break; default: text = create_surf(w, count * tmp[0]->h, SDL_SWSURFACE); diff --git a/client/gui-sdl3/sprite.c b/client/gui-sdl3/sprite.c index 68ecd83a77..df52925c72 100644 --- a/client/gui-sdl3/sprite.c +++ b/client/gui-sdl3/sprite.c @@ -139,15 +139,7 @@ struct sprite *create_sprite(int width, int height, struct color *pcolor) fc_assert_ret_val(height > 0, NULL); fc_assert_ret_val(pcolor != NULL, NULL); - if (is_bigendian()) { - mypixbuf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, - 0x0000FF00, 0x00FF0000, - 0xFF000000, 0x000000FF); - } else { - mypixbuf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, - 0x00FF0000, 0x0000FF00, - 0x000000FF, 0xFF000000); - } + mypixbuf = SDL_CreateSurface(width, height, SDL_PIXELFORMAT_RGBA8888); SDL_FillRect(mypixbuf, NULL, SDL_MapRGBA(mypixbuf->format, -- 2.42.0