Bools to flags (#14486)

* (D3D11) Use flags instead of bools

* (RPNG) Use flags

* Simplify rpng_is_valid

* (rpng_is_valid) Prevent potential NULL pointer dereference
(D3D11) Some whitespacing changes/code nits

* (task_pl_thumbnail_download.c) Simplify some code
This commit is contained in:
LibretroAdmin 2022-10-06 19:26:38 +02:00 committed by GitHub
parent 714878783a
commit 951b98fe1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 160 additions and 135 deletions

View File

@ -169,6 +169,21 @@ typedef struct d3d11_shader_t
D3D11InputLayout layout;
} d3d11_shader_t;
enum d3d11_state_flags
{
D3D11_ST_FLAG_VSYNC = (1 << 0),
D3D11_ST_FLAG_WAITABLE_SWAPCHAINS = (1 << 1),
D3D11_ST_FLAG_WAIT_FOR_VBLANK = (1 << 2),
D3D11_ST_FLAG_RESIZE_CHAIN = (1 << 3),
D3D11_ST_FLAG_KEEP_ASPECT = (1 << 4),
D3D11_ST_FLAG_RESIZE_VIEWPORT = (1 << 5),
D3D11_ST_FLAG_RESIZE_RTS = (1 << 6), /* RT = Render Target */
D3D11_ST_FLAG_INIT_HISTORY = (1 << 7),
D3D11_ST_FLAG_HAS_FLIP_MODEL = (1 << 8),
D3D11_ST_FLAG_HAS_ALLOW_TEARING = (1 << 9),
D3D11_ST_FLAG_HW_IFACE_ENABLE = (1 << 10)
};
typedef struct
{
unsigned cur_mon_id;
@ -196,16 +211,7 @@ typedef struct
DXGI_FORMAT format;
float clearcolor[4];
unsigned swap_interval;
bool vsync;
bool waitable_swapchains;
bool wait_for_vblank;
bool resize_chain;
bool keep_aspect;
bool resize_viewport;
bool resize_render_targets;
bool init_history;
bool has_flip_model;
bool has_allow_tearing;
uint16_t flags;
d3d11_shader_t shaders[GFX_MAX_SHADERS];
#ifdef HAVE_DXGI_HDR
enum dxgi_swapchain_bit_depth
@ -220,11 +226,7 @@ typedef struct
#endif
DXGIAdapter adapter;
struct
{
bool enable;
struct retro_hw_render_interface_d3d11 iface;
} hw;
struct retro_hw_render_interface_d3d11 hw_iface;
#ifdef HAVE_DXGI_HDR
struct

View File

@ -463,7 +463,7 @@ static void d3d11_gfx_set_rotation(void* data, unsigned rotation)
static void d3d11_update_viewport(d3d11_video_t *d3d11, bool force_full)
{
video_driver_update_viewport(&d3d11->vp, force_full, d3d11->keep_aspect);
video_driver_update_viewport(&d3d11->vp, force_full, d3d11->flags & D3D11_ST_FLAG_KEEP_ASPECT);
d3d11->frame.viewport.TopLeftX = d3d11->vp.x;
d3d11->frame.viewport.TopLeftY = d3d11->vp.y;
@ -474,14 +474,14 @@ static void d3d11_update_viewport(d3d11_video_t *d3d11, bool force_full)
if (d3d11->shader_preset && (d3d11->frame.output_size.x != d3d11->vp.width ||
d3d11->frame.output_size.y != d3d11->vp.height))
d3d11->resize_render_targets = true;
d3d11->flags |= D3D11_ST_FLAG_RESIZE_RTS;
d3d11->frame.output_size.x = d3d11->vp.width;
d3d11->frame.output_size.y = d3d11->vp.height;
d3d11->frame.output_size.z = 1.0f / d3d11->vp.width;
d3d11->frame.output_size.w = 1.0f / d3d11->vp.height;
d3d11->resize_viewport = false;
d3d11->flags &= ~D3D11_ST_FLAG_RESIZE_VIEWPORT;
}
static void d3d11_free_shader_preset(d3d11_video_t* d3d11)
@ -529,8 +529,8 @@ static void d3d11_free_shader_preset(d3d11_video_t* d3d11)
free(d3d11->shader_preset);
d3d11->shader_preset = NULL;
d3d11->init_history = false;
d3d11->resize_render_targets = false;
d3d11->flags &= ~( D3D11_ST_FLAG_INIT_HISTORY
| D3D11_ST_FLAG_RESIZE_RTS);
}
static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const char* path)
@ -697,14 +697,14 @@ static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const
/* If the last shader pass uses a RGB10A2 back buffer and hdr has been enabled assume we want to skip the inverse tonemapper and hdr10 conversion */
d3d11_set_hdr_inverse_tonemap(d3d11, false);
d3d11_set_hdr10(d3d11, false);
d3d11->resize_chain = true;
d3d11->flags |= D3D11_ST_FLAG_RESIZE_CHAIN;
}
else if(d3d11->shader_preset && d3d11->shader_preset->passes && (d3d11->pass[d3d11->shader_preset->passes - 1].semantics.format == SLANG_FORMAT_R16G16B16A16_SFLOAT))
{
/* If the last shader pass uses a RGBA16 back buffer and hdr has been enabled assume we want to skip the inverse tonemapper */
d3d11_set_hdr_inverse_tonemap(d3d11, false);
d3d11_set_hdr10(d3d11, true);
d3d11->resize_chain = true;
d3d11->flags |= D3D11_ST_FLAG_RESIZE_CHAIN;
}
else
{
@ -739,8 +739,7 @@ static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const
image_texture_free(&image);
}
d3d11->resize_render_targets = true;
d3d11->init_history = true;
d3d11->flags|= D3D11_ST_FLAG_RESIZE_RTS | D3D11_ST_FLAG_INIT_HISTORY;
return true;
@ -882,11 +881,11 @@ static bool d3d11_init_swapchain(d3d11_video_t* d3d11,
hwnd = (HWND)corewindow;
#ifdef HAVE_DXGI_HDR
if (!(d3d11->hdr.support =
if (!(d3d11->hdr.support =
dxgi_check_display_hdr_support(d3d11->factory, hwnd)))
d3d11->hdr.enable = false;
d3d11->hdr.enable = false;
d3d11->chain_bit_depth = d3d11->hdr.enable
d3d11->chain_bit_depth = d3d11->hdr.enable
? DXGI_SWAPCHAIN_BIT_DEPTH_10
: DXGI_SWAPCHAIN_BIT_DEPTH_8;
#endif
@ -1010,7 +1009,7 @@ static bool d3d11_init_swapchain(d3d11_video_t* d3d11,
&desc, NULL, (IDXGISwapChain1**)&d3d11->swapChain)))
return false;
#else
if (d3d11->waitable_swapchains)
if (d3d11->flags & D3D11_ST_FLAG_WAITABLE_SWAPCHAINS)
desc.Flags |= DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;
desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
@ -1034,10 +1033,10 @@ static bool d3d11_init_swapchain(d3d11_video_t* d3d11,
&allow_tearing_supported, sizeof(allow_tearing_supported))) &&
allow_tearing_supported)
{
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
desc.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING;
d3d11->has_flip_model = true;
d3d11->has_allow_tearing = true;
d3d11->flags |= D3D11_ST_FLAG_HAS_FLIP_MODEL
| D3D11_ST_FLAG_HAS_ALLOW_TEARING;
RARCH_LOG("[D3D11]: Flip model and tear control supported and enabled.\n");
}
@ -1052,10 +1051,10 @@ static bool d3d11_init_swapchain(d3d11_video_t* d3d11,
RARCH_WARN("[D3D11]: Failed to create swapchain with flip model, try non-flip model.\n");
/* Failed to create swapchain, try non-flip model */
desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
desc.Flags &= ~DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING;
d3d11->has_flip_model = false;
d3d11->has_allow_tearing = false;
d3d11->flags &= ~( D3D11_ST_FLAG_HAS_FLIP_MODEL
| D3D11_ST_FLAG_HAS_ALLOW_TEARING);
if (FAILED(dxgiFactory->lpVtbl->CreateSwapChain(
dxgiFactory, (IUnknown*)d3d11->device,
@ -1076,20 +1075,20 @@ static bool d3d11_init_swapchain(d3d11_video_t* d3d11,
#endif /* __WINRT__ */
if (d3d11->waitable_swapchains &&
(d3d11->frameLatencyWaitableObject = DXGIGetFrameLatencyWaitableObject(d3d11->swapChain)))
if ( (d3d11->flags & D3D11_ST_FLAG_WAITABLE_SWAPCHAINS)
&& (d3d11->frameLatencyWaitableObject = DXGIGetFrameLatencyWaitableObject(d3d11->swapChain)))
{
settings_t* settings = config_get_ptr();
UINT max_latency = settings->uints.video_max_frame_latency;
UINT cur_latency = 0;
settings_t* settings = config_get_ptr();
UINT max_latency = settings->uints.video_max_frame_latency;
UINT cur_latency = 0;
if (max_latency == 0)
{
d3d11->wait_for_vblank = true;
max_latency = 1;
max_latency = 1;
d3d11->flags |= D3D11_ST_FLAG_WAIT_FOR_VBLANK;
}
else
d3d11->wait_for_vblank = false;
d3d11->flags &= ~D3D11_ST_FLAG_WAIT_FOR_VBLANK;
DXGISetMaximumFrameLatency(d3d11->swapChain, max_latency);
DXGIGetMaximumFrameLatency(d3d11->swapChain, &cur_latency);
@ -1203,7 +1202,8 @@ static void *d3d11_gfx_init(const video_info_t* video,
d3d11->hdr.max_fall = 0.0f;
#endif
d3d11->waitable_swapchains = settings->bools.video_waitable_swapchains;
if (settings->bools.video_waitable_swapchains)
d3d11->flags |= D3D11_ST_FLAG_WAITABLE_SWAPCHAINS;
#ifdef __WINRT__
if (!d3d11_init_swapchain(d3d11,
@ -1230,9 +1230,11 @@ static void *d3d11_gfx_init(const video_info_t* video,
d3d11->viewport.Height = d3d11->vp.full_height;
d3d11->scissor.right = d3d11->vp.full_width;
d3d11->scissor.bottom = d3d11->vp.full_height;
d3d11->resize_viewport = true;
d3d11->keep_aspect = video->force_aspect;
d3d11->vsync = video->vsync;
d3d11->flags |= D3D11_ST_FLAG_RESIZE_VIEWPORT;
if (video->force_aspect)
d3d11->flags |= D3D11_ST_FLAG_KEEP_ASPECT;
if (video->vsync)
d3d11->flags |= D3D11_ST_FLAG_VSYNC;
d3d11->format = video->rgb32 ?
DXGI_FORMAT_B8G8R8X8_UNORM : DXGI_FORMAT_B5G6R5_UNORM;
@ -1619,14 +1621,14 @@ static void *d3d11_gfx_init(const video_info_t* video,
if ( video_driver_get_hw_context()->context_type == RETRO_HW_CONTEXT_DIRECT3D
&& video_driver_get_hw_context()->version_major == 11)
{
d3d11->hw.enable = true;
d3d11->hw.iface.interface_type = RETRO_HW_RENDER_INTERFACE_D3D11;
d3d11->hw.iface.interface_version = RETRO_HW_RENDER_INTERFACE_D3D11_VERSION;
d3d11->hw.iface.handle = d3d11;
d3d11->hw.iface.device = d3d11->device;
d3d11->hw.iface.context = d3d11->context;
d3d11->hw.iface.featureLevel = d3d11->supportedFeatureLevel;
d3d11->hw.iface.D3DCompile = D3DCompile;
d3d11->flags |= D3D11_ST_FLAG_HW_IFACE_ENABLE;
d3d11->hw_iface.interface_type = RETRO_HW_RENDER_INTERFACE_D3D11;
d3d11->hw_iface.interface_version = RETRO_HW_RENDER_INTERFACE_D3D11_VERSION;
d3d11->hw_iface.handle = d3d11;
d3d11->hw_iface.device = d3d11->device;
d3d11->hw_iface.context = d3d11->context;
d3d11->hw_iface.featureLevel = d3d11->supportedFeatureLevel;
d3d11->hw_iface.D3DCompile = D3DCompile;
}
{
@ -1724,7 +1726,7 @@ static void d3d11_init_history(d3d11_video_t* d3d11, unsigned width, unsigned he
d3d11_init_texture(d3d11->device, &d3d11->frame.texture[i]);
/* TODO/FIXME: clear texture ? */
}
d3d11->init_history = false;
d3d11->flags &= ~D3D11_ST_FLAG_INIT_HISTORY;
}
static void d3d11_init_render_targets(d3d11_video_t* d3d11, unsigned width, unsigned height)
@ -1820,7 +1822,7 @@ static void d3d11_init_render_targets(d3d11_video_t* d3d11, unsigned width, unsi
}
}
d3d11->resize_render_targets = false;
d3d11->flags &= ~D3D11_ST_FLAG_RESIZE_RTS;
}
static bool d3d11_gfx_frame(
@ -1838,9 +1840,10 @@ static bool d3d11_gfx_frame(
D3D11RenderTargetView rtv = NULL;
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
D3D11DeviceContext context = d3d11->context;
bool vsync = d3d11->vsync;
bool wait_for_vblank = d3d11->wait_for_vblank;
unsigned present_flags = (vsync || !d3d11->has_allow_tearing) ? 0 : DXGI_PRESENT_ALLOW_TEARING;
bool vsync = d3d11->flags & D3D11_ST_FLAG_VSYNC;
bool wait_for_vblank = d3d11->flags & D3D11_ST_FLAG_WAIT_FOR_VBLANK;
unsigned present_flags = (vsync || !(d3d11->flags &
D3D11_ST_FLAG_HAS_ALLOW_TEARING)) ? 0 : DXGI_PRESENT_ALLOW_TEARING;
const char *stat_text = video_info->stat_text;
unsigned video_width = video_info->width;
unsigned video_height = video_info->height;
@ -1856,15 +1859,16 @@ static bool d3d11_gfx_frame(
DXGI_FORMAT back_buffer_format = d3d11->shader_preset && d3d11->shader_preset->passes ? glslang_format_to_dxgi(d3d11->pass[d3d11->shader_preset->passes - 1].semantics.format) : DXGI_FORMAT_R8G8B8A8_UNORM;
bool use_back_buffer = back_buffer_format != d3d11->chain_formats[d3d11->chain_bit_depth];
if ( d3d11->resize_chain ||
(d3d11->hdr.enable != video_hdr_enable))
if ( (d3d11->flags & D3D11_ST_FLAG_RESIZE_CHAIN)
|| (d3d11->hdr.enable != video_hdr_enable))
#else
if (d3d11->resize_chain)
#endif
{
UINT swapchain_flags = d3d11->has_allow_tearing
UINT swapchain_flags = (d3d11->flags &
D3D11_ST_FLAG_HAS_ALLOW_TEARING)
? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0;
if (d3d11->waitable_swapchains)
if (d3d11->flags & D3D11_ST_FLAG_WAITABLE_SWAPCHAINS)
swapchain_flags |= DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;
#ifdef HAVE_DXGI_HDR
d3d11->hdr.enable = video_hdr_enable;
@ -1888,8 +1892,8 @@ static bool d3d11_gfx_frame(
d3d11->ubo_values.OutputSize.width = d3d11->viewport.Width;
d3d11->ubo_values.OutputSize.height = d3d11->viewport.Height;
d3d11->resize_chain = false;
d3d11->resize_viewport = true;
d3d11->flags &= ~D3D11_ST_FLAG_RESIZE_CHAIN;
d3d11->flags |= D3D11_ST_FLAG_RESIZE_VIEWPORT;
video_driver_set_size(video_width, video_height);
#ifdef HAVE_DXGI_HDR
@ -1941,13 +1945,11 @@ static bool d3d11_gfx_frame(
d3d11->hdr.max_fall);
#endif
}
else if (d3d11->waitable_swapchains)
{
else if (d3d11->flags & D3D11_ST_FLAG_WAITABLE_SWAPCHAINS)
WaitForSingleObjectEx(
d3d11->frameLatencyWaitableObject,
1000,
true);
}
{
D3D11Texture2D back_buffer;
@ -1983,7 +1985,7 @@ static bool d3d11_gfx_frame(
d3d11_release_texture(&d3d11->frame.texture[0]);
d3d11_init_texture(d3d11->device, &d3d11->frame.texture[0]);
d3d11->init_history = true;
d3d11->flags |= D3D11_ST_FLAG_INIT_HISTORY;
}
Release(hw_view);
@ -1993,11 +1995,11 @@ static bool d3d11_gfx_frame(
{
if (d3d11->frame.texture[0].desc.Width != width ||
d3d11->frame.texture[0].desc.Height != height)
d3d11->resize_render_targets = true;
d3d11->flags |= D3D11_ST_FLAG_RESIZE_RTS;
if (d3d11->resize_render_targets)
if (d3d11->flags & D3D11_ST_FLAG_RESIZE_RTS)
{
/* release all render targets first to avoid memory fragmentation */
/* Release all Render Targets (RT) first to avoid memory fragmentation */
for (i = 0; i < d3d11->shader_preset->passes; i++)
{
d3d11_release_texture(&d3d11->pass[i].rt);
@ -2009,7 +2011,7 @@ static bool d3d11_gfx_frame(
if (d3d11->shader_preset->history_size)
{
if (d3d11->init_history)
if (d3d11->flags &D3D11_ST_FLAG_INIT_HISTORY)
d3d11_init_history(d3d11, width, height);
else
{
@ -2023,8 +2025,8 @@ static bool d3d11_gfx_frame(
}
/* either no history, or we moved a texture of a different size in the front slot */
if (d3d11->frame.texture[0].desc.Width != width ||
d3d11->frame.texture[0].desc.Height != height)
if ( d3d11->frame.texture[0].desc.Width != width
|| d3d11->frame.texture[0].desc.Height != height)
{
d3d11->frame.texture[0].desc.Width = width;
d3d11->frame.texture[0].desc.Height = height;
@ -2032,7 +2034,7 @@ static bool d3d11_gfx_frame(
d3d11_init_texture(d3d11->device, &d3d11->frame.texture[0]);
}
if (d3d11->resize_render_targets)
if (d3d11->flags & D3D11_ST_FLAG_RESIZE_RTS)
d3d11_init_render_targets(d3d11, width, height);
if (hw_texture)
@ -2422,24 +2424,33 @@ static void d3d11_gfx_set_nonblock_state(void* data,
if (!d3d11)
return;
d3d11->vsync = !toggle;
if (toggle)
d3d11->flags &= ~D3D11_ST_FLAG_VSYNC;
else
d3d11->flags |= D3D11_ST_FLAG_VSYNC;
d3d11->swap_interval = (!toggle) ? swap_interval : 0;
}
static bool d3d11_gfx_alive(void* data)
{
bool quit;
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
bool d3d11_resize_chain = false;
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
win32_check_window(NULL,
&quit,
&d3d11->resize_chain,
&d3d11_resize_chain,
&d3d11->vp.full_width,
&d3d11->vp.full_height);
if (d3d11_resize_chain)
d3d11->flags |= D3D11_ST_FLAG_RESIZE_CHAIN;
else
d3d11->flags &= ~D3D11_ST_FLAG_RESIZE_CHAIN;
if ( d3d11->resize_chain
&& d3d11->vp.full_width != 0
&& d3d11->vp.full_height != 0)
if ( (d3d11->flags & D3D11_ST_FLAG_RESIZE_CHAIN)
&& (d3d11->vp.full_width != 0)
&& (d3d11->vp.full_height != 0))
video_driver_set_size(d3d11->vp.full_width, d3d11->vp.full_height);
return !quit;
@ -2509,19 +2520,15 @@ static void d3d11_gfx_set_aspect_ratio(void* data, unsigned aspect_ratio_idx)
{
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
if (!d3d11)
return;
d3d11->keep_aspect = true;
d3d11->resize_viewport = true;
if (d3d11)
d3d11->flags |= D3D11_ST_FLAG_KEEP_ASPECT | D3D11_ST_FLAG_RESIZE_VIEWPORT;
}
static void d3d11_gfx_apply_state_changes(void* data)
{
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
if (d3d11)
d3d11->resize_viewport = true;
d3d11->flags |= D3D11_ST_FLAG_RESIZE_VIEWPORT;
}
static void d3d11_gfx_set_osd_msg(
@ -2607,8 +2614,8 @@ static bool d3d11_get_hw_render_interface(
{
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
*iface = (const struct retro_hw_render_interface*)
&d3d11->hw.iface;
return d3d11->hw.enable;
&d3d11->hw_iface;
return d3d11->flags & D3D11_ST_FLAG_HW_IFACE_ENABLE;
}
#ifndef __WINRT__

View File

@ -82,6 +82,13 @@ struct idat_buffer
size_t size;
};
enum rpng_process_flags
{
RPNG_PROCESS_FLAG_INFLATE_INITIALIZED = (1 << 0),
RPNG_PROCESS_FLAG_ADAM7_PASS_INITIALIZED = (1 << 1),
RPNG_PROCESS_FLAG_PASS_INITIALIZED = (1 << 2)
};
struct rpng_process
{
uint32_t *data;
@ -106,9 +113,16 @@ struct rpng_process
unsigned pass_width;
unsigned pass_height;
unsigned pass_pos;
bool inflate_initialized;
bool adam7_pass_initialized;
bool pass_initialized;
uint8_t flags;
};
enum rpng_flags
{
RPNG_FLAG_HAS_IHDR = (1 << 0),
RPNG_FLAG_HAS_IDAT = (1 << 1),
RPNG_FLAG_HAS_IEND = (1 << 2),
RPNG_FLAG_HAS_PLTE = (1 << 3),
RPNG_FLAG_HAS_TRNS = (1 << 4)
};
struct rpng
@ -119,11 +133,7 @@ struct rpng
struct idat_buffer idat_buf; /* ptr alignment */
struct png_ihdr ihdr; /* uint32 alignment */
uint32_t palette[256];
bool has_ihdr;
bool has_idat;
bool has_iend;
bool has_plte;
bool has_trns;
uint8_t flags;
};
static const struct adam7_pass rpng_passes[] = {
@ -485,7 +495,7 @@ static void rpng_reverse_filter_deinit(struct rpng_process *pngp)
free(pngp->prev_scanline);
pngp->prev_scanline = NULL;
pngp->pass_initialized = false;
pngp->flags &= ~RPNG_PROCESS_FLAG_PASS_INITIALIZED;
pngp->h = 0;
}
@ -494,7 +504,8 @@ static int rpng_reverse_filter_init(const struct png_ihdr *ihdr,
{
size_t pass_size;
if (!pngp->adam7_pass_initialized && ihdr->interlace)
if ( !(pngp->flags & RPNG_PROCESS_FLAG_ADAM7_PASS_INITIALIZED)
&& ihdr->interlace)
{
if ( ihdr->width <= rpng_passes[pngp->pass_pos].x
|| ihdr->height <= rpng_passes[pngp->pass_pos].y) /* Empty pass */
@ -524,12 +535,12 @@ static int rpng_reverse_filter_init(const struct png_ihdr *ihdr,
return -1;
}
pngp->adam7_pass_initialized = true;
pngp->flags |= RPNG_PROCESS_FLAG_ADAM7_PASS_INITIALIZED;
return 0;
}
if (pngp->pass_initialized)
if (pngp->flags & RPNG_PROCESS_FLAG_PASS_INITIALIZED)
return 0;
rpng_pass_geom(ihdr, ihdr->width, ihdr->height, &pngp->bpp, &pngp->pitch, &pass_size);
@ -545,8 +556,8 @@ static int rpng_reverse_filter_init(const struct png_ihdr *ihdr,
if (!pngp->prev_scanline || !pngp->decoded_scanline)
goto error;
pngp->h = 0;
pngp->pass_initialized = true;
pngp->h = 0;
pngp->flags |= RPNG_PROCESS_FLAG_PASS_INITIALIZED;
return 0;
@ -702,11 +713,11 @@ static int rpng_reverse_filter_adam7_iterate(uint32_t **data_,
free(pngp->data);
pngp->data = NULL;
pngp->pass_width = 0;
pngp->pass_height = 0;
pngp->pass_size = 0;
pngp->adam7_pass_initialized = false;
pngp->data = NULL;
pngp->pass_width = 0;
pngp->pass_height = 0;
pngp->pass_size = 0;
pngp->flags &= ~RPNG_PROCESS_FLAG_ADAM7_PASS_INITIALIZED;
return IMAGE_PROCESS_NEXT;
}
@ -790,12 +801,12 @@ end:
if (rpng_reverse_filter_init(&rpng->ihdr, process) == -1)
goto false_end;
process->inflate_initialized = true;
process->flags |= RPNG_PROCESS_FLAG_INFLATE_INITIALIZED;
return 1;
error:
false_end:
process->inflate_initialized = false;
process->flags &= ~RPNG_PROCESS_FLAG_INFLATE_INITIALIZED;
return -1;
}
@ -818,9 +829,7 @@ static struct rpng_process *rpng_process_init(rpng_t *rpng)
if (!process)
return NULL;
process->inflate_initialized = false;
process->adam7_pass_initialized = false;
process->pass_initialized = false;
process->flags = 0;
process->prev_scanline = NULL;
process->decoded_scanline = NULL;
process->inflate_buf = NULL;
@ -993,7 +1002,9 @@ bool rpng_iterate_image(rpng_t *rpng)
return false;
case PNG_CHUNK_IHDR:
if (rpng->has_ihdr || rpng->has_idat || rpng->has_iend)
if ( (rpng->flags & RPNG_FLAG_HAS_IHDR)
|| (rpng->flags & RPNG_FLAG_HAS_IDAT)
|| (rpng->flags & RPNG_FLAG_HAS_IEND))
return false;
if (chunk_size != 13)
@ -1026,7 +1037,7 @@ bool rpng_iterate_image(rpng_t *rpng)
return false;
}
rpng->has_ihdr = true;
rpng->flags |= RPNG_FLAG_HAS_IHDR;
break;
case PNG_CHUNK_PLTE:
@ -1039,11 +1050,11 @@ bool rpng_iterate_image(rpng_t *rpng)
if (chunk_size % 3)
return false;
if ( !rpng->has_ihdr
|| rpng->has_plte
|| rpng->has_iend
|| rpng->has_idat
|| rpng->has_trns)
if ( !(rpng->flags & RPNG_FLAG_HAS_IHDR)
|| (rpng->flags & RPNG_FLAG_HAS_PLTE)
|| (rpng->flags & RPNG_FLAG_HAS_IEND)
|| (rpng->flags & RPNG_FLAG_HAS_IDAT)
|| (rpng->flags & RPNG_FLAG_HAS_TRNS))
return false;
buf += 8;
@ -1056,12 +1067,12 @@ bool rpng_iterate_image(rpng_t *rpng)
rpng->palette[i] = (r << 16) | (g << 8) | (b << 0) | (0xffu << 24);
}
rpng->has_plte = true;
rpng->flags |= RPNG_FLAG_HAS_PLTE;
}
break;
case PNG_CHUNK_tRNS:
if (rpng->has_idat)
if (rpng->flags & RPNG_FLAG_HAS_IDAT)
return false;
if (rpng->ihdr.color_type == PNG_IHDR_COLOR_PLT)
@ -1080,11 +1091,15 @@ bool rpng_iterate_image(rpng_t *rpng)
}
/* TODO: support colorkey in grayscale and truecolor images */
rpng->has_trns = true;
rpng->flags |= RPNG_FLAG_HAS_TRNS;
break;
case PNG_CHUNK_IDAT:
if (!(rpng->has_ihdr) || rpng->has_iend || (rpng->ihdr.color_type == PNG_IHDR_COLOR_PLT && !(rpng->has_plte)))
if ( !(rpng->flags & RPNG_FLAG_HAS_IHDR)
|| (rpng->flags & RPNG_FLAG_HAS_IEND)
|| (rpng->ihdr.color_type == PNG_IHDR_COLOR_PLT
&&
!(rpng->flags & RPNG_FLAG_HAS_PLTE)))
return false;
if (!rpng_realloc_idat(&rpng->idat_buf, chunk_size))
@ -1097,14 +1112,15 @@ bool rpng_iterate_image(rpng_t *rpng)
rpng->idat_buf.size += chunk_size;
rpng->has_idat = true;
rpng->flags |= RPNG_FLAG_HAS_IDAT;
break;
case PNG_CHUNK_IEND:
if (!(rpng->has_ihdr) || !(rpng->has_idat))
if ( !(rpng->flags & RPNG_FLAG_HAS_IHDR)
|| !(rpng->flags & RPNG_FLAG_HAS_IDAT))
return false;
rpng->has_iend = true;
rpng->flags |= RPNG_FLAG_HAS_IEND;
return false;
}
@ -1132,7 +1148,7 @@ int rpng_process_image(rpng_t *rpng,
return IMAGE_PROCESS_NEXT;
}
if (!rpng->process->inflate_initialized)
if (!(rpng->process->flags & RPNG_PROCESS_FLAG_INFLATE_INITIALIZED))
{
if (rpng_load_image_argb_process_inflate_init(rpng, data) == -1)
goto error;
@ -1215,7 +1231,8 @@ bool rpng_start(rpng_t *rpng)
**/
bool rpng_is_valid(rpng_t *rpng)
{
return (rpng && rpng->has_ihdr && rpng->has_idat && rpng->has_iend);
return (rpng && ((rpng->flags & (RPNG_FLAG_HAS_IHDR | RPNG_FLAG_HAS_IDAT |
RPNG_FLAG_HAS_IEND)) > 0));
}
bool rpng_set_buf_ptr(rpng_t *rpng, void *data, size_t len)

View File

@ -706,13 +706,12 @@ static void task_pl_entry_thumbnail_download_handler(retro_task_t *task)
* current task is 'complete' */
if (!pl_thumb->http_task)
pl_thumb->flags |= PL_THUMB_FLAG_HTTP_TASK_COMPLETE;
/* > Wait for task_push_http_transfer_file()
* callback to trigger */
if (pl_thumb->flags & PL_THUMB_FLAG_HTTP_TASK_COMPLETE)
pl_thumb->http_task = NULL;
else
else if (!(pl_thumb->flags & PL_THUMB_FLAG_HTTP_TASK_COMPLETE))
break;
pl_thumb->http_task = NULL;
/* Check whether all thumbnail types have been processed */
if (pl_thumb->type_idx > 3)