diff --git a/driver.c b/driver.c index 46cfb88231..faa1591500 100644 --- a/driver.c +++ b/driver.c @@ -462,7 +462,7 @@ void drivers_init( bool menu_enable_widgets = settings->bools.menu_enable_widgets; /* By default, we want display widgets to persist through driver reinits. */ - dispwidget_get_ptr()->persisting = true; + dispwidget_get_ptr()->flags |= DISPGFX_WIDGET_FLAG_PERSISTING; #endif #ifdef HAVE_MENU @@ -704,14 +704,14 @@ void driver_uninit(int flags) core_info_deinit_list(); core_info_free_current_core(); -#if defined(HAVE_GFX_WIDGETS) - /* This absolutely has to be done before video_driver_free_internal() - * is called/completes, otherwise certain menu drivers - * (e.g. Vulkan) will segfault */ - if (dispwidget_get_ptr()->inited) +#if defined(HAVE_GFX_WIDGETS) + /* This absolutely has to be done before video_driver_free_internal() + * is called/completes, otherwise certain menu drivers + * (e.g. Vulkan) will segfault */ + if (dispwidget_get_ptr()->flags & DISPGFX_WIDGET_FLAG_INITED) { - gfx_widgets_deinit(dispwidget_get_ptr()->persisting); - dispwidget_get_ptr()->active = false; + gfx_widgets_deinit(dispwidget_get_ptr()->flags & DISPGFX_WIDGET_FLAG_PERSISTING); + dispwidget_get_ptr()->active = false; } #endif @@ -799,19 +799,19 @@ void retroarch_deinit_drivers(struct retro_callbacks *cbs) *location_st = location_state_get_ptr(); runloop_state_t *runloop_st = runloop_state_get_ptr(); -#if defined(HAVE_GFX_WIDGETS) - /* Tear down display widgets no matter what - * in case the handle is lost in the threaded - * video driver in the meantime - * (breaking video_driver_has_widgets) */ - if (dispwidget_get_ptr()->inited) - { - gfx_widgets_deinit( - dispwidget_get_ptr()->persisting); - dispwidget_get_ptr()->active = false; - } -#endif - +#if defined(HAVE_GFX_WIDGETS) + /* Tear down display widgets no matter what + * in case the handle is lost in the threaded + * video driver in the meantime + * (breaking video_driver_has_widgets) */ + if (dispwidget_get_ptr()->flags & DISPGFX_WIDGET_FLAG_INITED) + { + gfx_widgets_deinit( + dispwidget_get_ptr()->flags & DISPGFX_WIDGET_FLAG_PERSISTING); + dispwidget_get_ptr()->active = false; + } +#endif + #if defined(HAVE_CRTSWITCHRES) /* Switchres deinit */ if (video_st->crt_switching_active) diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c index 67e989320e..57add71bbb 100644 --- a/gfx/common/vulkan_common.c +++ b/gfx/common/vulkan_common.c @@ -104,7 +104,7 @@ static void vulkan_emulated_mailbox_deinit( if (mailbox->thread) { slock_lock(mailbox->lock); - mailbox->dead = true; + mailbox->flags |= VK_MAILBOX_FLAG_DEAD; scond_signal(mailbox->cond); slock_unlock(mailbox->lock); sthread_join(mailbox->thread); @@ -126,20 +126,20 @@ static VkResult vulkan_emulated_mailbox_acquire_next_image( slock_lock(mailbox->lock); - if (!mailbox->has_pending_request) + if (!(mailbox->flags & VK_MAILBOX_FLAG_HAS_PENDING_REQUEST)) { - mailbox->request_acquire = true; + mailbox->flags |= VK_MAILBOX_FLAG_REQUEST_ACQUIRE; scond_signal(mailbox->cond); } - mailbox->has_pending_request = true; + mailbox->flags |= VK_MAILBOX_FLAG_HAS_PENDING_REQUEST; - if (mailbox->acquired) + if (mailbox->flags & VK_MAILBOX_FLAG_ACQUIRED) { res = mailbox->result; *index = mailbox->index; - mailbox->has_pending_request = false; - mailbox->acquired = false; + mailbox->flags &= ~(VK_MAILBOX_FLAG_HAS_PENDING_REQUEST + | VK_MAILBOX_FLAG_ACQUIRED); } slock_unlock(mailbox->lock); @@ -154,21 +154,21 @@ static VkResult vulkan_emulated_mailbox_acquire_next_image_blocking( slock_lock(mailbox->lock); - if (!mailbox->has_pending_request) + if (!(mailbox->flags & VK_MAILBOX_FLAG_HAS_PENDING_REQUEST)) { - mailbox->request_acquire = true; + mailbox->flags |= VK_MAILBOX_FLAG_REQUEST_ACQUIRE; scond_signal(mailbox->cond); } - mailbox->has_pending_request = true; + mailbox->flags |= VK_MAILBOX_FLAG_HAS_PENDING_REQUEST; - while (!mailbox->acquired) + while (!(mailbox->flags & VK_MAILBOX_FLAG_ACQUIRED)) scond_wait(mailbox->cond, mailbox->lock); if ((res = mailbox->result) == VK_SUCCESS) *index = mailbox->index; - mailbox->has_pending_request = false; - mailbox->acquired = false; + mailbox->flags &= ~(VK_MAILBOX_FLAG_HAS_PENDING_REQUEST + | VK_MAILBOX_FLAG_ACQUIRED); slock_unlock(mailbox->lock); return res; @@ -193,16 +193,17 @@ static void vulkan_emulated_mailbox_loop(void *userdata) for (;;) { slock_lock(mailbox->lock); - while (!mailbox->dead && !mailbox->request_acquire) + while ( !(mailbox->flags & VK_MAILBOX_FLAG_DEAD) + && !(mailbox->flags & VK_MAILBOX_FLAG_REQUEST_ACQUIRE)) scond_wait(mailbox->cond, mailbox->lock); - if (mailbox->dead) + if (mailbox->flags & VK_MAILBOX_FLAG_DEAD) { slock_unlock(mailbox->lock); break; } - mailbox->request_acquire = false; + mailbox->flags &= ~VK_MAILBOX_FLAG_REQUEST_ACQUIRE; slock_unlock(mailbox->lock); @@ -228,7 +229,7 @@ static void vulkan_emulated_mailbox_loop(void *userdata) vkResetFences(mailbox->device, 1, &fence); slock_lock(mailbox->lock); - mailbox->acquired = true; + mailbox->flags |= VK_MAILBOX_FLAG_ACQUIRED; scond_signal(mailbox->cond); slock_unlock(mailbox->lock); } @@ -251,10 +252,7 @@ static bool vulkan_emulated_mailbox_init( mailbox->swapchain = swapchain; mailbox->index = 0; mailbox->result = VK_SUCCESS; - mailbox->acquired = false; - mailbox->request_acquire = false; - mailbox->dead = false; - mailbox->has_pending_request = false; + mailbox->flags = 0; if (!(mailbox->cond = scond_new())) return false; @@ -452,7 +450,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk, * static textures, samplers can be used to enable it dynamically. */ info.mipLevels = vulkan_num_miplevels(width, height); - tex.mipmap = true; + tex.flags |= VK_TEX_FLAG_MIPMAP; retro_assert(initial && "Static textures must have initial data.\n"); info.tiling = VK_IMAGE_TILING_OPTIMAL; info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | @@ -529,9 +527,10 @@ struct vk_texture vulkan_create_texture(vk_t *vk, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - tex.need_manual_cache_management = - (vk->context->memory_properties.memoryTypes[alloc.memoryTypeIndex].propertyFlags & - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == 0; + if ((vk->context->memory_properties.memoryTypes + [alloc.memoryTypeIndex].propertyFlags & + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == 0) + tex.flags |= VK_TEX_FLAG_NEED_MANUAL_CACHE_MANAGEMENT; /* If the texture is STREAMED and it's not DEVICE_LOCAL, we expect to hit a slower path, * so fallback to copy path. */ @@ -681,8 +680,8 @@ struct vk_texture vulkan_create_texture(vk_t *vk, for (y = 0; y < tex.height; y++, dst += tex.stride, src += stride) memcpy(dst, src, width * bpp); - if ( tex.need_manual_cache_management && - tex.memory != VK_NULL_HANDLE) + if ( (tex.flags & VK_TEX_FLAG_NEED_MANUAL_CACHE_MANAGEMENT) + && (tex.memory != VK_NULL_HANDLE)) VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, tex.memory); vkUnmapMemory(device, tex.memory); } @@ -692,7 +691,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk, VkBufferImageCopy region; VkCommandBuffer staging; enum VkImageLayout layout_fmt = - tex.mipmap + (tex.flags & VK_TEX_FLAG_MIPMAP) ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; struct vk_texture tmp = vulkan_create_texture(vk, NULL, @@ -734,7 +733,7 @@ struct vk_texture vulkan_create_texture(vk_t *vk, vkCmdCopyBufferToImage(staging, tmp.buffer, tex.image, layout_fmt, 1, ®ion); - if (tex.mipmap) + if (tex.flags & VK_TEX_FLAG_MIPMAP) { for (i = 1; i < info.mipLevels; i++) { @@ -848,9 +847,7 @@ void vulkan_destroy_texture( vulkan_track_dealloc(tex->image); #endif tex->type = VULKAN_TEXTURE_STREAMED; - tex->default_smooth = false; - tex->need_manual_cache_management = false; - tex->mipmap = false; + tex->flags = 0; tex->memory_type = 0; tex->width = 0; tex->height = 0; diff --git a/gfx/common/vulkan_common.h b/gfx/common/vulkan_common.h index d85263eff4..49913b4ff7 100644 --- a/gfx/common/vulkan_common.h +++ b/gfx/common/vulkan_common.h @@ -165,6 +165,14 @@ typedef struct vulkan_context } vulkan_context_t; +enum vulkan_emulated_mailbox_flags +{ + VK_MAILBOX_FLAG_ACQUIRED = (1 << 0), + VK_MAILBOX_FLAG_REQUEST_ACQUIRE = (1 << 1), + VK_MAILBOX_FLAG_DEAD = (1 << 2), + VK_MAILBOX_FLAG_HAS_PENDING_REQUEST = (1 << 3) +}; + struct vulkan_emulated_mailbox { sthread_t *thread; @@ -175,10 +183,7 @@ struct vulkan_emulated_mailbox unsigned index; VkResult result; /* enum alignment */ - bool acquired; - bool request_acquire; - bool dead; - bool has_pending_request; + uint8_t flags; }; typedef struct gfx_ctx_vulkan_data @@ -232,6 +237,13 @@ struct vk_image VkDeviceMemory memory; /* ptr alignment */ }; +enum vk_texture_flags +{ + VK_TEX_FLAG_DEFAULT_SMOOTH = (1 << 0), + VK_TEX_FLAG_NEED_MANUAL_CACHE_MANAGEMENT = (1 << 1), + VK_TEX_FLAG_MIPMAP = (1 << 2) +}; + struct vk_texture { VkDeviceSize memory_size; /* uint64_t alignment */ @@ -251,9 +263,7 @@ struct vk_texture VkImageLayout layout; /* enum alignment */ VkFormat format; /* enum alignment */ enum vk_texture_type type; - bool default_smooth; - bool need_manual_cache_management; - bool mipmap; + uint8_t flags; }; struct vk_buffer @@ -707,11 +717,11 @@ void vulkan_destroy_texture( * changes in resolution, so this seems like the sanest and * simplest solution. */ #define VULKAN_SYNC_TEXTURE_TO_GPU_COND_PTR(vk, tex) \ - if ((tex)->need_manual_cache_management && (tex)->memory != VK_NULL_HANDLE) \ + if (((tex)->flags & VK_TEX_FLAG_NEED_MANUAL_CACHE_MANAGEMENT) && (tex)->memory != VK_NULL_HANDLE) \ VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, (tex)->memory) \ #define VULKAN_SYNC_TEXTURE_TO_GPU_COND_OBJ(vk, tex) \ - if ((tex).need_manual_cache_management && (tex).memory != VK_NULL_HANDLE) \ + if (((tex).flags & VK_TEX_FLAG_NEED_MANUAL_CACHE_MANAGEMENT) && (tex).memory != VK_NULL_HANDLE) \ VULKAN_SYNC_TEXTURE_TO_GPU(vk->context->device, (tex).memory) \ /* VBO will be written to here. */ diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index 8b8bcb1ab2..e68a94647a 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -2394,21 +2394,17 @@ static bool vulkan_frame(void *data, const void *frame, quad.texture = optimal; if (menu_linear_filter) - { - quad.sampler = optimal->mipmap ? + quad.sampler = (optimal->flags & VK_TEX_FLAG_MIPMAP) ? vk->samplers.mipmap_linear : vk->samplers.linear; - } else - { - quad.sampler = optimal->mipmap ? + quad.sampler = (optimal->flags & VK_TEX_FLAG_MIPMAP) ? vk->samplers.mipmap_nearest : vk->samplers.nearest; - } - quad.mvp = &vk->mvp_no_rot; - quad.color.r = 1.0f; - quad.color.g = 1.0f; - quad.color.b = 1.0f; - quad.color.a = vk->menu.alpha; + quad.mvp = &vk->mvp_no_rot; + quad.color.r = 1.0f; + quad.color.g = 1.0f; + quad.color.b = 1.0f; + quad.color.a = vk->menu.alpha; vulkan_draw_quad(vk, &quad); } } @@ -3128,21 +3124,22 @@ static uintptr_t vulkan_load_texture(void *video_data, void *data, }; #undef T0 #undef T1 - *texture = vulkan_create_texture(vk, NULL, + *texture = vulkan_create_texture(vk, NULL, 8, 8, VK_FORMAT_B8G8R8A8_UNORM, checkerboard, NULL, VULKAN_TEXTURE_STATIC); - texture->default_smooth = false; - texture->mipmap = false; + texture->flags &= ~(VK_TEX_FLAG_DEFAULT_SMOOTH + | VK_TEX_FLAG_MIPMAP); } else { *texture = vulkan_create_texture(vk, NULL, image->width, image->height, VK_FORMAT_B8G8R8A8_UNORM, image->pixels, NULL, VULKAN_TEXTURE_STATIC); - - texture->default_smooth = - filter_type == TEXTURE_FILTER_MIPMAP_LINEAR || filter_type == TEXTURE_FILTER_LINEAR; - texture->mipmap = filter_type == TEXTURE_FILTER_MIPMAP_LINEAR; + if (filter_type == TEXTURE_FILTER_MIPMAP_LINEAR || filter_type == + TEXTURE_FILTER_LINEAR) + texture->flags |= VK_TEX_FLAG_DEFAULT_SMOOTH; + if (filter_type == TEXTURE_FILTER_MIPMAP_LINEAR) + texture->flags |= VK_TEX_FLAG_MIPMAP; } return (uintptr_t)texture; @@ -3320,8 +3317,8 @@ static bool vulkan_read_viewport(void *data, uint8_t *buffer, bool is_idle) vkMapMemory(vk->context->device, staging->memory, staging->offset, staging->size, 0, (void**)&src); - if (staging->need_manual_cache_management - && staging->memory != VK_NULL_HANDLE) + if ( (staging->flags & VK_TEX_FLAG_NEED_MANUAL_CACHE_MANAGEMENT) + && (staging->memory != VK_NULL_HANDLE)) VULKAN_SYNC_TEXTURE_TO_CPU(vk->context->device, staging->memory); ctx->in_stride = staging->stride; @@ -3362,8 +3359,8 @@ static bool vulkan_read_viewport(void *data, uint8_t *buffer, bool is_idle) VK_MAP_PERSISTENT_TEXTURE(vk->context->device, staging); } - if (staging->need_manual_cache_management - && staging->memory != VK_NULL_HANDLE) + if ( (staging->flags & VK_TEX_FLAG_NEED_MANUAL_CACHE_MANAGEMENT) + && (staging->memory != VK_NULL_HANDLE)) VULKAN_SYNC_TEXTURE_TO_CPU(vk->context->device, staging->memory); { @@ -3501,8 +3498,8 @@ static void vulkan_render_overlay(vk_t *vk, unsigned width, call.vbo = ⦥ call.texture = &vk->overlay.images[i]; call.pipeline = vk->display.pipelines[3]; /* Strip with blend */ - call.sampler = call.texture->mipmap ? - vk->samplers.mipmap_linear : vk->samplers.linear; + call.sampler = (call.texture->flags & VK_TEX_FLAG_MIPMAP) + ? vk->samplers.mipmap_linear : vk->samplers.linear; vulkan_draw_triangles(vk, &call); } diff --git a/gfx/drivers_display/gfx_display_vulkan.c b/gfx/drivers_display/gfx_display_vulkan.c index 5cd3902c5b..e9261a19af 100644 --- a/gfx/drivers_display/gfx_display_vulkan.c +++ b/gfx/drivers_display/gfx_display_vulkan.c @@ -254,9 +254,9 @@ static void gfx_display_vk_draw(gfx_display_ctx_draw_t *draw, (vk->display.blend << 0); call.pipeline = vk->display.pipelines[disp_pipeline]; call.texture = texture; - call.sampler = texture->mipmap ? + call.sampler = (texture->flags & VK_TEX_FLAG_MIPMAP) ? vk->samplers.mipmap_linear : - (texture->default_smooth ? vk->samplers.linear + ((texture->flags & VK_TEX_FLAG_DEFAULT_SMOOTH) ? vk->samplers.linear : vk->samplers.nearest); call.uniform = draw->matrix_data ? draw->matrix_data : &vk->mvp_no_rot; diff --git a/gfx/gfx_widgets.c b/gfx/gfx_widgets.c index d245a6eb6c..7f79f069e7 100644 --- a/gfx/gfx_widgets.c +++ b/gfx/gfx_widgets.c @@ -242,7 +242,7 @@ void gfx_widgets_msg_queue_push( msg_widget->hourglass_timer = 0.0f; msg_widget->flags = 0; - if (!p_dispwidget->msg_queue_has_icons) + if (!(p_dispwidget->flags & DISPGFX_WIDGET_FLAG_MSG_QUEUE_HAS_ICONS)) { msg_widget->flags |= DISPWIDG_FLAG_UNFOLDED; msg_widget->flags &= ~DISPWIDG_FLAG_UNFOLDING; @@ -402,7 +402,7 @@ static void gfx_widgets_unfold_end(void *userdata) dispgfx_widget_t *p_dispwidget = &dispwidget_st; unfold->flags &= ~DISPWIDG_FLAG_UNFOLDING; - p_dispwidget->moving = false; + p_dispwidget->flags &= ~DISPGFX_WIDGET_FLAG_MOVING; } static void gfx_widgets_move_end(void *userdata) @@ -428,7 +428,7 @@ static void gfx_widgets_move_end(void *userdata) unfold->flags |= DISPWIDG_FLAG_UNFOLDING; } else - p_dispwidget->moving = false; + p_dispwidget->flags &= ~DISPGFX_WIDGET_FLAG_MOVING; } static void gfx_widgets_msg_queue_expired(void *userdata) @@ -477,7 +477,7 @@ static void gfx_widgets_msg_queue_move(dispgfx_widget_t *p_dispwidget) gfx_animation_push(&entry); - p_dispwidget->moving = true; + p_dispwidget->flags |= DISPGFX_WIDGET_FLAG_MOVING; } } @@ -525,7 +525,7 @@ static void gfx_widgets_msg_queue_free( if (msg->msg_new) free(msg->msg_new); - p_dispwidget->moving = false; + p_dispwidget->flags &= ~DISPGFX_WIDGET_FLAG_MOVING; } static void gfx_widgets_msg_queue_kill_end(void *userdata) @@ -569,7 +569,7 @@ static void gfx_widgets_msg_queue_kill( if (!msg) return; - p_dispwidget->moving = true; + p_dispwidget->flags |= DISPGFX_WIDGET_FLAG_MOVING; msg->flags |= DISPWIDG_FLAG_DYING; p_dispwidget->msg_queue_kill = idx; @@ -847,7 +847,7 @@ static void gfx_widgets_layout( p_dispwidget->msg_queue_height = p_dispwidget->gfx_widget_fonts.msg_queue.line_height * 2.5f * (BASE_FONT_SIZE / MSG_QUEUE_FONT_SIZE); - if (p_dispwidget->msg_queue_has_icons) + if (p_dispwidget->flags & DISPGFX_WIDGET_FLAG_MSG_QUEUE_HAS_ICONS) { #if 0 p_dispwidget->msg_queue_icon_size_y = p_dispwidget->msg_queue_height @@ -871,7 +871,7 @@ static void gfx_widgets_layout( p_dispwidget->msg_queue_icon_offset_y = (p_dispwidget->msg_queue_icon_size_y - p_dispwidget->msg_queue_height) / 2; p_dispwidget->msg_queue_scissor_start_x = p_dispwidget->msg_queue_spacing + p_dispwidget->msg_queue_icon_size_x - (p_dispwidget->msg_queue_icon_size_x * 0.28928571428f); - if (p_dispwidget->msg_queue_has_icons) + if (p_dispwidget->flags & DISPGFX_WIDGET_FLAG_MSG_QUEUE_HAS_ICONS) p_dispwidget->msg_queue_regular_padding_x = p_dispwidget->simple_widget_padding / 2; else p_dispwidget->msg_queue_regular_padding_x = p_dispwidget->simple_widget_padding; @@ -971,7 +971,7 @@ void gfx_widgets_iterate( /* Consume one message if available */ if ((FIFO_READ_AVAIL_NONPTR(p_dispwidget->msg_queue) > 0) - && !p_dispwidget->moving + && !(p_dispwidget->flags & DISPGFX_WIDGET_FLAG_MOVING) && (p_dispwidget->current_msgs_size < ARRAY_SIZE(p_dispwidget->current_msgs))) { disp_widget_msg_t *msg_widget = NULL; @@ -1046,8 +1046,8 @@ void gfx_widgets_iterate( if (!(msg_widget->flags & DISPWIDG_FLAG_EXPIRATION_TIMER_STARTED)) gfx_widgets_start_msg_expiration_timer(msg_widget, TASK_FINISHED_DURATION); - if ( (msg_widget->flags & DISPWIDG_FLAG_EXPIRED) - && !p_dispwidget->moving) + if ( (msg_widget->flags & DISPWIDG_FLAG_EXPIRED) + && !(p_dispwidget->flags & DISPGFX_WIDGET_FLAG_MOVING)) { gfx_widgets_msg_queue_kill(p_dispwidget, (unsigned)i); @@ -1456,7 +1456,7 @@ static void gfx_widgets_draw_regular_msg( video_width, video_height); } - if (p_dispwidget->msg_queue_has_icons) + if (p_dispwidget->flags & DISPGFX_WIDGET_FLAG_MSG_QUEUE_HAS_ICONS) { if (dispctx && dispctx->blend_begin) dispctx->blend_begin(userdata); @@ -1802,7 +1802,7 @@ static void gfx_widgets_free(dispgfx_widget_t *p_dispwidget) { size_t i; - p_dispwidget->inited = false; + p_dispwidget->flags &= ~DISPGFX_WIDGET_FLAG_INITED; for (i = 0; i < ARRAY_SIZE(widgets); i++) { @@ -1930,10 +1930,12 @@ static void gfx_widgets_context_reset( NULL, NULL); - p_dispwidget->msg_queue_has_icons = - p_dispwidget->msg_queue_icon && - p_dispwidget->msg_queue_icon_outline && - p_dispwidget->msg_queue_icon_rect; + if ( p_dispwidget->msg_queue_icon + && p_dispwidget->msg_queue_icon_outline + && p_dispwidget->msg_queue_icon_rect) + p_dispwidget->flags |= DISPGFX_WIDGET_FLAG_MSG_QUEUE_HAS_ICONS; + else + p_dispwidget->flags &= ~DISPGFX_WIDGET_FLAG_MSG_QUEUE_HAS_ICONS; for (i = 0; i < ARRAY_SIZE(widgets); i++) { @@ -2009,7 +2011,7 @@ bool gfx_widgets_init( p_dispwidget->msg_queue_bg[14] = HEX_B(color); p_dispwidget->msg_queue_bg[15] = 1.0f; - if (!p_dispwidget->inited) + if (!(p_dispwidget->flags & DISPGFX_WIDGET_FLAG_INITED)) { char theme_path[PATH_MAX_LENGTH]; p_dispwidget->gfx_widgets_frame_count = 0; @@ -2072,7 +2074,7 @@ bool gfx_widgets_init( settings->paths.directory_assets, "pkg", sizeof(p_dispwidget->assets_pkg_dir)); - p_dispwidget->inited = true; + p_dispwidget->flags |= DISPGFX_WIDGET_FLAG_INITED; } gfx_widgets_context_reset( diff --git a/gfx/gfx_widgets.h b/gfx/gfx_widgets.h index dfaa8f640f..d173c537a6 100644 --- a/gfx/gfx_widgets.h +++ b/gfx/gfx_widgets.h @@ -151,6 +151,16 @@ typedef struct disp_widget_msg uint8_t task_count; } disp_widget_msg_t; +/* There can only be one message animation at a time to + * avoid confusing users */ +enum dispgfx_widget_flags +{ + DISPGFX_WIDGET_FLAG_MSG_QUEUE_HAS_ICONS = (1 << 0), + DISPGFX_WIDGET_FLAG_PERSISTING = (1 << 1), + DISPGFX_WIDGET_FLAG_MOVING = (1 << 2), + DISPGFX_WIDGET_FLAG_INITED = (1 << 3) +}; + typedef struct dispgfx_widget { uint64_t gfx_widgets_frame_count; @@ -217,6 +227,8 @@ typedef struct dispgfx_widget unsigned ai_service_overlay_height; #endif + uint8_t flags; + char assets_pkg_dir[PATH_MAX_LENGTH]; char xmb_path[PATH_MAX_LENGTH]; /* TODO/FIXME - decouple from XMB */ char ozone_path[PATH_MAX_LENGTH]; /* TODO/FIXME - decouple from Ozone */ @@ -227,18 +239,12 @@ typedef struct dispgfx_widget char gfx_widgets_path[PATH_MAX_LENGTH]; char gfx_widgets_status_text[255]; - /* There can only be one message animation at a time to - * avoid confusing users */ - bool moving; - bool inited; bool active; - bool persisting; - bool msg_queue_has_icons; } dispgfx_widget_t; /* A widget */ -/* TODO: cleanup all unused parameters */ +/* TODO/FIXME: cleanup all unused parameters */ struct gfx_widget { /* called when the widgets system is initialized diff --git a/retroarch.c b/retroarch.c index da99a97e35..f6528be2f0 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3686,7 +3686,7 @@ void main_exit(void *args) #if defined(HAVE_GFX_WIDGETS) /* Do not want display widgets to live any more. */ - dispwidget_get_ptr()->persisting = false; + dispwidget_get_ptr()->flags &= ~DISPGFX_WIDGET_FLAG_PERSISTING; #endif #ifdef HAVE_MENU /* Do not want menu context to live any more. */ diff --git a/tasks/task_autodetect.c b/tasks/task_autodetect.c index ca2fd862be..a137766850 100644 --- a/tasks/task_autodetect.c +++ b/tasks/task_autodetect.c @@ -37,6 +37,12 @@ #include "../input/include/blissbox.h" #endif +enum autoconfig_handle_flags +{ + AUTOCONF_FLAG_AUTOCONFIG_ENABLED = (1 << 0), + AUTOCONF_FLAG_SUPPRESS_NOTIFICATIONS = (1 << 1) +}; + typedef struct { char *dir_autoconfig; @@ -44,8 +50,7 @@ typedef struct config_file_t *autoconfig_file; unsigned port; input_device_info_t device_info; /* unsigned alignment */ - bool autoconfig_enabled; - bool suppress_notifcations; + uint8_t flags; } autoconfig_handle_t; /*********************/ @@ -442,9 +447,9 @@ static void input_autoconfigure_connect_handler(retro_task_t *task) autoconfig_handle = (autoconfig_handle_t*)task->state; - if (!autoconfig_handle || - string_is_empty(autoconfig_handle->device_info.name) || - !autoconfig_handle->autoconfig_enabled) + if ( !autoconfig_handle + || string_is_empty(autoconfig_handle->device_info.name) + || !(autoconfig_handle->flags & AUTOCONF_FLAG_AUTOCONFIG_ENABLED)) goto task_finished; /* Annoyingly, we have to scan all the autoconfig @@ -522,7 +527,7 @@ static void input_autoconfigure_connect_handler(retro_task_t *task) if (match_found) { /* A valid autoconfig was applied */ - if (!autoconfig_handle->suppress_notifcations) + if (!(autoconfig_handle->flags & AUTOCONF_FLAG_SUPPRESS_NOTIFICATIONS)) { size_t _len = strlcpy(task_title, device_display_name, sizeof(task_title)); @@ -632,7 +637,8 @@ bool input_autoconfigure_connect( goto error; /* Configure handle */ - if (!(autoconfig_handle = (autoconfig_handle_t*)malloc(sizeof(autoconfig_handle_t)))) + if (!(autoconfig_handle = (autoconfig_handle_t*) + malloc(sizeof(autoconfig_handle_t)))) goto error; autoconfig_handle->port = port; @@ -645,8 +651,10 @@ bool input_autoconfigure_connect( autoconfig_handle->device_info.joypad_driver[0] = '\0'; autoconfig_handle->device_info.autoconfigured = false; autoconfig_handle->device_info.name_index = 0; - autoconfig_handle->autoconfig_enabled = autoconfig_enabled; - autoconfig_handle->suppress_notifcations = !notification_show_autoconfig; + if (autoconfig_enabled) + autoconfig_handle->flags |= AUTOCONF_FLAG_AUTOCONFIG_ENABLED; + if (!notification_show_autoconfig) + autoconfig_handle->flags |= AUTOCONF_FLAG_SUPPRESS_NOTIFICATIONS; autoconfig_handle->dir_autoconfig = NULL; autoconfig_handle->dir_driver_autoconfig = NULL; autoconfig_handle->autoconfig_file = NULL; @@ -659,8 +667,7 @@ bool input_autoconfigure_connect( strlcpy(autoconfig_handle->device_info.display_name, display_name, sizeof(autoconfig_handle->device_info.display_name)); - driver_valid = !string_is_empty(driver); - if (driver_valid) + if ((driver_valid = !string_is_empty(driver))) strlcpy(autoconfig_handle->device_info.joypad_driver, driver, sizeof(autoconfig_handle->device_info.joypad_driver)); @@ -706,8 +713,8 @@ bool input_autoconfigure_connect( * task status messages * > Can skip this check if autoconfig notifications * have been disabled by the user */ - if (!autoconfig_handle->suppress_notifcations && - !string_is_empty(autoconfig_handle->device_info.name)) + if ( !(autoconfig_handle->flags & AUTOCONF_FLAG_SUPPRESS_NOTIFICATIONS) + && !string_is_empty(autoconfig_handle->device_info.name)) { const char *last_device_name = input_config_get_device_name(port); uint16_t last_vid = input_config_get_device_vid(port); @@ -720,7 +727,7 @@ bool input_autoconfigure_connect( (autoconfig_handle->device_info.vid == last_vid) && (autoconfig_handle->device_info.pid == last_pid) && last_autoconfigured) - autoconfig_handle->suppress_notifcations = true; + autoconfig_handle->flags |= AUTOCONF_FLAG_SUPPRESS_NOTIFICATIONS; } /* Configure task */ @@ -823,7 +830,7 @@ static void input_autoconfigure_disconnect_handler(retro_task_t *task) } task_free_title(task); - if (!autoconfig_handle->suppress_notifcations) + if (!(autoconfig_handle->flags & AUTOCONF_FLAG_SUPPRESS_NOTIFICATIONS)) task_set_title(task, strdup(task_title)); task_finished: @@ -885,17 +892,16 @@ bool input_autoconfigure_disconnect(unsigned port, const char *name) if (!autoconfig_handle) goto error; - autoconfig_handle->port = port; - autoconfig_handle->suppress_notifcations = !notification_show_autoconfig; + autoconfig_handle->port = port; + if (!notification_show_autoconfig) + autoconfig_handle->flags |= AUTOCONF_FLAG_SUPPRESS_NOTIFICATIONS; if (!string_is_empty(name)) strlcpy(autoconfig_handle->device_info.name, name, sizeof(autoconfig_handle->device_info.name)); /* Configure task */ - task = task_init(); - - if (!task) + if (!(task = task_init())) goto error; task->handler = input_autoconfigure_disconnect_handler;