bracing style and attribute unused to void cast in libSDL display driver

pull/46/head
tarxvf 2021-08-25 02:02:31 -04:00 zatwierdzone przez Silvano Seva
rodzic 588265fa3d
commit 2ec8a3c264
1 zmienionych plików z 28 dodań i 15 usunięć

Wyświetl plik

@ -83,14 +83,16 @@ int screenshot_display(const char *filename)
/* Get information about texture we want to save */ /* Get information about texture we want to save */
st = SDL_QueryTexture(tex, NULL, NULL, &w, &h); st = SDL_QueryTexture(tex, NULL, NULL, &w, &h);
if (st != 0) { if (st != 0)
{
SDL_Log("Failed querying texture: %s\n", SDL_GetError()); SDL_Log("Failed querying texture: %s\n", SDL_GetError());
err++; err++;
goto cleanup; goto cleanup;
} }
ren_tex = SDL_CreateTexture(ren, format, SDL_TEXTUREACCESS_TARGET, w, h); ren_tex = SDL_CreateTexture(ren, format, SDL_TEXTUREACCESS_TARGET, w, h);
if (!ren_tex) { if (!ren_tex)
{
SDL_Log("Failed creating render texture: %s\n", SDL_GetError()); SDL_Log("Failed creating render texture: %s\n", SDL_GetError());
err++; err++;
goto cleanup; goto cleanup;
@ -101,7 +103,8 @@ int screenshot_display(const char *filename)
* can access * can access
*/ */
st = SDL_SetRenderTarget(ren, ren_tex); st = SDL_SetRenderTarget(ren, ren_tex);
if (st != 0) { if (st != 0)
{
SDL_Log("Failed setting render target: %s\n", SDL_GetError()); SDL_Log("Failed setting render target: %s\n", SDL_GetError());
err++; err++;
goto cleanup; goto cleanup;
@ -109,34 +112,39 @@ int screenshot_display(const char *filename)
SDL_SetRenderDrawColor(ren, 0x00, 0x00, 0x00, 0x00); SDL_SetRenderDrawColor(ren, 0x00, 0x00, 0x00, 0x00);
SDL_RenderClear(ren); SDL_RenderClear(ren);
st = SDL_RenderCopy(ren, tex, NULL, NULL); st = SDL_RenderCopy(ren, tex, NULL, NULL);
if (st != 0) { if (st != 0)
{
SDL_Log("Failed copying texture data: %s\n", SDL_GetError()); SDL_Log("Failed copying texture data: %s\n", SDL_GetError());
err++; err++;
goto cleanup; goto cleanup;
} }
/* Create buffer to hold texture data and load it */ /* Create buffer to hold texture data and load it */
pixels = malloc(w * h * SDL_BYTESPERPIXEL(format)); pixels = malloc(w * h * SDL_BYTESPERPIXEL(format));
if (!pixels) { if (!pixels)
{
SDL_Log("Failed allocating memory\n"); SDL_Log("Failed allocating memory\n");
err++; err++;
goto cleanup; goto cleanup;
} }
st = SDL_RenderReadPixels(ren, NULL, format, pixels, w * SDL_BYTESPERPIXEL(format)); st = SDL_RenderReadPixels(ren, NULL, format, pixels, w * SDL_BYTESPERPIXEL(format));
if (st != 0) { if (st != 0)
{
SDL_Log("Failed reading pixel data: %s\n", SDL_GetError()); SDL_Log("Failed reading pixel data: %s\n", SDL_GetError());
err++; err++;
goto cleanup; goto cleanup;
} }
/* Copy pixel data over to surface */ /* Copy pixel data over to surface */
surf = SDL_CreateRGBSurfaceWithFormatFrom(pixels, w, h, SDL_BITSPERPIXEL(format), w * SDL_BYTESPERPIXEL(format), format); surf = SDL_CreateRGBSurfaceWithFormatFrom(pixels, w, h, SDL_BITSPERPIXEL(format), w * SDL_BYTESPERPIXEL(format), format);
if (!surf) { if (!surf)
{
SDL_Log("Failed creating new surface: %s\n", SDL_GetError()); SDL_Log("Failed creating new surface: %s\n", SDL_GetError());
err++; err++;
goto cleanup; goto cleanup;
} }
/* Save result to an image */ /* Save result to an image */
st = SDL_SaveBMP(surf, filename); st = SDL_SaveBMP(surf, filename);
if (st != 0) { if (st != 0)
{
SDL_Log("Failed saving image: %s\n", SDL_GetError()); SDL_Log("Failed saving image: %s\n", SDL_GetError());
err++; err++;
goto cleanup; goto cleanup;
@ -156,9 +164,10 @@ cleanup:
* Internal helper function which fetches pixel at position (x, y) from framebuffer * Internal helper function which fetches pixel at position (x, y) from framebuffer
* and returns it in SDL-compatible format, which is ARGB8888. * and returns it in SDL-compatible format, which is ARGB8888.
*/ */
uint32_t fetchPixelFromFb(__attribute__((unused)) unsigned int x, uint32_t fetchPixelFromFb(unsigned int x, unsigned int y)
__attribute__((unused)) unsigned int y)
{ {
(void) x;
(void) y;
uint32_t pixel = 0; uint32_t pixel = 0;
#ifdef PIX_FMT_BW #ifdef PIX_FMT_BW
@ -192,7 +201,8 @@ void display_init()
{ {
printf("SDL video init error!!\n"); printf("SDL video init error!!\n");
} else }
else
{ {
window = SDL_CreateWindow("OpenRTX", window = SDL_CreateWindow("OpenRTX",
@ -253,9 +263,10 @@ void display_terminate()
SDL_Quit(); SDL_Quit();
} }
void display_renderRows(__attribute__((unused)) uint8_t startRow, void display_renderRows(uint8_t startRow, uint8_t endRow)
__attribute__((unused)) uint8_t endRow)
{ {
(void) startRow;
(void) endRow;
PIXEL_SIZE *pixels; PIXEL_SIZE *pixels;
int pitch = 0; int pitch = 0;
if (SDL_LockTexture(displayTexture, NULL, (void **) &pixels, &pitch) < 0) if (SDL_LockTexture(displayTexture, NULL, (void **) &pixels, &pitch) < 0)
@ -267,8 +278,10 @@ void display_renderRows(__attribute__((unused)) uint8_t startRow,
uint16_t *fb = (uint16_t *) (frameBuffer); uint16_t *fb = (uint16_t *) (frameBuffer);
memcpy(pixels, fb, sizeof(uint16_t) * SCREEN_HEIGHT * SCREEN_WIDTH); memcpy(pixels, fb, sizeof(uint16_t) * SCREEN_HEIGHT * SCREEN_WIDTH);
#else #else
for (unsigned int x = 0; x < SCREEN_WIDTH; x++) { for (unsigned int x = 0; x < SCREEN_WIDTH; x++)
for (unsigned int y = startRow; y < endRow; y++) { {
for (unsigned int y = startRow; y < endRow; y++)
{
pixels[x + y * SCREEN_WIDTH] = fetchPixelFromFb(x, y); pixels[x + y * SCREEN_WIDTH] = fetchPixelFromFb(x, y);
} }
} }