[client,sdl] use unique_ptr for SDL_Surface et al

This commit is contained in:
Armin Novak 2023-05-30 21:26:10 +02:00 committed by Martin Fleisz
parent 68995ddffb
commit da7c3b688f
2 changed files with 21 additions and 18 deletions

View File

@ -376,9 +376,9 @@ static BOOL sdl_end_paint_process(rdpContext* context)
const SDL_Rect srcRect = { rgn->x, rgn->y, rgn->w, rgn->h }; 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, SDL_Rect dstRect = { window->offset_x + rgn->x, window->offset_y + rgn->y, rgn->w,
rgn->h }; rgn->h };
SDL_SetClipRect(sdl->primary, &srcRect); SDL_SetClipRect(sdl->primary.get(), &srcRect);
SDL_SetClipRect(screen, &dstRect); SDL_SetClipRect(screen, &dstRect);
SDL_BlitSurface(sdl->primary, &srcRect, screen, &dstRect); SDL_BlitSurface(sdl->primary.get(), &srcRect, screen, &dstRect);
} }
} }
else else
@ -391,9 +391,9 @@ static BOOL sdl_end_paint_process(rdpContext* context)
SDL_Rect dstRect = srcRect; SDL_Rect dstRect = srcRect;
sdl_scale_coordinates(sdl, id, &dstRect.x, &dstRect.y, FALSE, TRUE); sdl_scale_coordinates(sdl, id, &dstRect.x, &dstRect.y, FALSE, TRUE);
sdl_scale_coordinates(sdl, id, &dstRect.w, &dstRect.h, 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_SetClipRect(screen, &dstRect);
SDL_BlitScaled(sdl->primary, &srcRect, screen, &dstRect); SDL_BlitScaled(sdl->primary.get(), &srcRect, screen, &dstRect);
} }
} }
SDL_UpdateWindowSurface(window->window); SDL_UpdateWindowSurface(window->window);
@ -421,11 +421,8 @@ static void sdl_destroy_primary(sdlContext* sdl)
{ {
if (!sdl) if (!sdl)
return; return;
sdl->primary.reset();
SDL_FreeFormat(sdl->primary_format); sdl->primary_format.reset();
SDL_FreeSurface(sdl->primary);
sdl->primary = nullptr;
sdl->primary_format = nullptr;
} }
/* Create a SDL surface from the GDI buffer */ /* Create a SDL surface from the GDI buffer */
@ -439,17 +436,20 @@ static BOOL sdl_create_primary(sdlContext* sdl)
WINPR_ASSERT(gdi); WINPR_ASSERT(gdi);
sdl_destroy_primary(sdl); sdl_destroy_primary(sdl);
sdl->primary = SDL_CreateRGBSurfaceWithFormatFrom( sdl->primary = SDLSurfacePtr(
gdi->primary_buffer, static_cast<int>(gdi->width), static_cast<int>(gdi->height), SDL_CreateRGBSurfaceWithFormatFrom(gdi->primary_buffer, static_cast<int>(gdi->width),
static_cast<int>(FreeRDPGetBitsPerPixel(gdi->dstFormat)), static_cast<int>(gdi->stride), static_cast<int>(gdi->height),
sdl->sdl_pixel_format); static_cast<int>(FreeRDPGetBitsPerPixel(gdi->dstFormat)),
sdl->primary_format = SDL_AllocFormat(sdl->sdl_pixel_format); static_cast<int>(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) if (!sdl->primary || !sdl->primary_format)
return FALSE; return FALSE;
SDL_SetSurfaceBlendMode(sdl->primary, SDL_BLENDMODE_NONE); SDL_SetSurfaceBlendMode(sdl->primary.get(), SDL_BLENDMODE_NONE);
SDL_FillRect(sdl->primary, nullptr, SDL_MapRGBA(sdl->primary_format, 0, 0, 0, 0xff)); SDL_FillRect(sdl->primary.get(), nullptr,
SDL_MapRGBA(sdl->primary_format.get(), 0, 0, 0, 0xff));
return TRUE; return TRUE;
} }

View File

@ -43,6 +43,9 @@ typedef struct
int offset_y; int offset_y;
} sdl_window_t; } sdl_window_t;
using SDLSurfacePtr = std::unique_ptr<SDL_Surface, decltype(&SDL_FreeSurface)>;
using SDLPixelFormatPtr = std::unique_ptr<SDL_PixelFormat, decltype(&SDL_FreeFormat)>;
struct sdl_context struct sdl_context
{ {
rdpClientContext common; rdpClientContext common;
@ -65,8 +68,8 @@ struct sdl_context
std::unique_ptr<WinPREvent> windows_created; std::unique_ptr<WinPREvent> windows_created;
int exit_code; int exit_code;
SDL_Surface* primary; SDLSurfacePtr primary;
SDL_PixelFormat* primary_format; SDLPixelFormatPtr primary_format;
std::unique_ptr<sdlDispContext> disp; std::unique_ptr<sdlDispContext> disp;
std::unique_ptr<sdlInput> input; std::unique_ptr<sdlInput> input;