From da7c3b688f5d8cf9cd1c916b280553a2d939dfac Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 30 May 2023 21:26:10 +0200 Subject: [PATCH] [client,sdl] use unique_ptr for SDL_Surface et al --- client/SDL/sdl_freerdp.cpp | 32 ++++++++++++++++---------------- client/SDL/sdl_freerdp.hpp | 7 +++++-- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/client/SDL/sdl_freerdp.cpp b/client/SDL/sdl_freerdp.cpp index 54fe116ac..cf36a865e 100644 --- a/client/SDL/sdl_freerdp.cpp +++ b/client/SDL/sdl_freerdp.cpp @@ -376,9 +376,9 @@ static BOOL sdl_end_paint_process(rdpContext* context) const SDL_Rect srcRect = { rgn->x, rgn->y, rgn->w, rgn->h }; SDL_Rect dstRect = { window->offset_x + rgn->x, window->offset_y + rgn->y, rgn->w, rgn->h }; - SDL_SetClipRect(sdl->primary, &srcRect); + SDL_SetClipRect(sdl->primary.get(), &srcRect); SDL_SetClipRect(screen, &dstRect); - SDL_BlitSurface(sdl->primary, &srcRect, screen, &dstRect); + SDL_BlitSurface(sdl->primary.get(), &srcRect, screen, &dstRect); } } else @@ -391,9 +391,9 @@ static BOOL sdl_end_paint_process(rdpContext* context) SDL_Rect dstRect = srcRect; sdl_scale_coordinates(sdl, id, &dstRect.x, &dstRect.y, FALSE, TRUE); sdl_scale_coordinates(sdl, id, &dstRect.w, &dstRect.h, FALSE, TRUE); - SDL_SetClipRect(sdl->primary, &srcRect); + SDL_SetClipRect(sdl->primary.get(), &srcRect); SDL_SetClipRect(screen, &dstRect); - SDL_BlitScaled(sdl->primary, &srcRect, screen, &dstRect); + SDL_BlitScaled(sdl->primary.get(), &srcRect, screen, &dstRect); } } SDL_UpdateWindowSurface(window->window); @@ -421,11 +421,8 @@ static void sdl_destroy_primary(sdlContext* sdl) { if (!sdl) return; - - SDL_FreeFormat(sdl->primary_format); - SDL_FreeSurface(sdl->primary); - sdl->primary = nullptr; - sdl->primary_format = nullptr; + sdl->primary.reset(); + sdl->primary_format.reset(); } /* Create a SDL surface from the GDI buffer */ @@ -439,17 +436,20 @@ static BOOL sdl_create_primary(sdlContext* sdl) WINPR_ASSERT(gdi); sdl_destroy_primary(sdl); - sdl->primary = SDL_CreateRGBSurfaceWithFormatFrom( - gdi->primary_buffer, static_cast(gdi->width), static_cast(gdi->height), - static_cast(FreeRDPGetBitsPerPixel(gdi->dstFormat)), static_cast(gdi->stride), - sdl->sdl_pixel_format); - sdl->primary_format = SDL_AllocFormat(sdl->sdl_pixel_format); + sdl->primary = SDLSurfacePtr( + SDL_CreateRGBSurfaceWithFormatFrom(gdi->primary_buffer, static_cast(gdi->width), + static_cast(gdi->height), + static_cast(FreeRDPGetBitsPerPixel(gdi->dstFormat)), + static_cast(gdi->stride), sdl->sdl_pixel_format), + SDL_FreeSurface); + sdl->primary_format = SDLPixelFormatPtr(SDL_AllocFormat(sdl->sdl_pixel_format), SDL_FreeFormat); if (!sdl->primary || !sdl->primary_format) return FALSE; - SDL_SetSurfaceBlendMode(sdl->primary, SDL_BLENDMODE_NONE); - SDL_FillRect(sdl->primary, nullptr, SDL_MapRGBA(sdl->primary_format, 0, 0, 0, 0xff)); + SDL_SetSurfaceBlendMode(sdl->primary.get(), SDL_BLENDMODE_NONE); + SDL_FillRect(sdl->primary.get(), nullptr, + SDL_MapRGBA(sdl->primary_format.get(), 0, 0, 0, 0xff)); return TRUE; } diff --git a/client/SDL/sdl_freerdp.hpp b/client/SDL/sdl_freerdp.hpp index 88c7adf38..b7defa350 100644 --- a/client/SDL/sdl_freerdp.hpp +++ b/client/SDL/sdl_freerdp.hpp @@ -43,6 +43,9 @@ typedef struct int offset_y; } sdl_window_t; +using SDLSurfacePtr = std::unique_ptr; +using SDLPixelFormatPtr = std::unique_ptr; + struct sdl_context { rdpClientContext common; @@ -65,8 +68,8 @@ struct sdl_context std::unique_ptr windows_created; int exit_code; - SDL_Surface* primary; - SDL_PixelFormat* primary_format; + SDLSurfacePtr primary; + SDLPixelFormatPtr primary_format; std::unique_ptr disp; std::unique_ptr input;