diff options
Diffstat (limited to 'src/osd/modules/render/bgfx/targetmanager.cpp')
-rw-r--r-- | src/osd/modules/render/bgfx/targetmanager.cpp | 138 |
1 files changed, 74 insertions, 64 deletions
diff --git a/src/osd/modules/render/bgfx/targetmanager.cpp b/src/osd/modules/render/bgfx/targetmanager.cpp index dfc1678ee34..eae09c48008 100644 --- a/src/osd/modules/render/bgfx/targetmanager.cpp +++ b/src/osd/modules/render/bgfx/targetmanager.cpp @@ -9,15 +9,15 @@ // //============================================================ -#include <bgfx/bgfx.h> +#include "targetmanager.h" -#include <vector> +#include "bgfxutil.h" +#include "target.h" #include "modules/lib/osdobj_common.h" -#include "targetmanager.h" +#include <utility> -#include "target.h" const int32_t target_manager::MAX_SCREENS = 100; @@ -29,98 +29,106 @@ target_manager::target_manager(texture_manager& textures) target_manager::~target_manager() { - std::vector<bgfx_target*> to_delete; - for (std::pair<std::string, bgfx_target*> target : m_targets) - { - if (target.second != nullptr) - { - to_delete.push_back(target.second); - } - } - m_targets.clear(); - - for (uint32_t i = 0; i < to_delete.size(); i++) - { - delete to_delete[i]; - } + for (auto iter = m_targets.begin(); iter != m_targets.end(); iter = m_targets.erase(iter)) + m_textures.remove_provider(iter->first); } -bgfx_target* target_manager::create_target(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, uint32_t style, bool double_buffer, bool filter, uint16_t scale, uint32_t screen) +bgfx_target* target_manager::create_target( + std::string &&name, + bgfx::TextureFormat::Enum format, + uint16_t width, + uint16_t height, + uint16_t xprescale, + uint16_t yprescale, + uint32_t style, + bool double_buffer, + bool filter, + uint16_t scale, + uint32_t screen) { - bgfx_target* target = new bgfx_target(name, format, width, height, style, double_buffer, filter, scale, screen); - std::string full_name = name + std::to_string(screen); + const std::string full_name = name + std::to_string(screen); - m_targets[full_name] = target; + auto iter = m_targets.find(full_name); + if (iter != m_targets.end()) + { + iter->second.reset(); + m_textures.remove_provider(full_name); + } - m_textures.add_provider(full_name, target); + auto target = std::make_unique<bgfx_target>(std::move(name), format, width, height, xprescale, yprescale, style, double_buffer, filter, scale, screen); + if (iter != m_targets.end()) + iter->second = std::move(target); + else + iter = m_targets.emplace(full_name, std::move(target)).first; + m_textures.add_provider(full_name, *iter->second); - return target; + return iter->second.get(); } -void target_manager::destroy_target(std::string name, uint32_t screen) +void target_manager::destroy_target(const std::string &name, uint32_t screen) { - std::string full_name = (screen < 0) ? name : (name + std::to_string(screen)); - if (m_targets[full_name] != nullptr) + const std::string full_name = (screen < 0) ? name : (name + std::to_string(screen)); + const auto found = m_targets.find(full_name); + if (found != m_targets.end()) { - delete m_targets[full_name]; - m_targets[full_name] = nullptr; + m_targets.erase(found); m_textures.remove_provider(full_name); } } bgfx_target* target_manager::create_backbuffer(void *handle, uint16_t width, uint16_t height) { - bgfx_target* target = new bgfx_target(handle, width, height); - m_targets["backbuffer"] = target; - return target; + auto target = std::make_unique<bgfx_target>(handle, width, height); + return (m_targets["backbuffer"] = std::move(target)).get(); } -bgfx_target* target_manager::target(uint32_t screen, std::string name) +bgfx_target* target_manager::target(uint32_t screen, const std::string &name) { - std::string full_name = name + std::to_string(screen); - bgfx_target* target = m_targets[full_name]; - if (target == nullptr) + const std::string full_name = name + std::to_string(screen); + const auto found = m_targets.find(full_name); + if (found != m_targets.end()) { - osd_printf_verbose("Warning: Attempting to retrieve a nonexistent target '%s' for screen %d\n", name.c_str(), screen); + return found->second.get(); + } + else + { + osd_printf_verbose("Warning: Attempting to retrieve a nonexistent target '%s' for screen %d\n", name, screen); + return nullptr; } - return target; } -bool target_manager::update_target_sizes(uint32_t screen, uint16_t width, uint16_t height, uint32_t style) +bool target_manager::update_target_sizes(uint32_t screen, uint16_t width, uint16_t height, uint32_t style, uint16_t user_prescale, uint16_t max_prescale_size) { - if (style == TARGET_STYLE_CUSTOM) return false; + if (style == TARGET_STYLE_CUSTOM) + return false; - std::vector<osd_dim>& sizes = style == TARGET_STYLE_GUEST ? m_guest_dims : m_native_dims; + std::vector<osd_dim> &sizes = (style == TARGET_STYLE_GUEST) ? m_guest_dims : m_native_dims; // Ensure that there's an entry to fill while (sizes.size() <= screen) { - sizes.push_back(osd_dim(0, 0)); + sizes.emplace_back(0, 0); } if (width != sizes[screen].width() || height != sizes[screen].height()) { sizes[screen] = osd_dim(width, height); - rebuild_targets(screen, style); + rebuild_targets(screen, style, user_prescale, max_prescale_size); return true; } return false; } -void target_manager::rebuild_targets(uint32_t screen, uint32_t style) +void target_manager::rebuild_targets(uint32_t screen, uint32_t style, uint16_t user_prescale, uint16_t max_prescale_size) { if (style == TARGET_STYLE_CUSTOM) return; std::vector<bgfx_target*> to_resize; - for (std::pair<std::string, bgfx_target*> target_pair : m_targets) + for (const auto &[name, target] : m_targets) { - bgfx_target* target = target_pair.second; - if (target == nullptr || target->style() != style || target->screen_index() != screen) - { - continue; - } - to_resize.push_back(target); + if (target && (target->style() == style) && (target->screen_index() == screen)) + to_resize.push_back(target.get()); } std::vector<osd_dim>& sizes = style == TARGET_STYLE_GUEST ? m_guest_dims : m_native_dims; @@ -133,18 +141,20 @@ void target_manager::rebuild_targets(uint32_t screen, uint32_t style) const uint16_t scale = target->scale(); const uint16_t width(sizes[screen].width()); const uint16_t height(sizes[screen].height()); - delete target; + uint16_t xprescale = user_prescale; + uint16_t yprescale = user_prescale; + bgfx_util::find_prescale_factor(width, height, max_prescale_size, xprescale, yprescale); - create_target(name, format, width, height, style, double_buffered, filter, scale, screen); + create_target(std::move(name), format, width, height, xprescale, yprescale, style, double_buffered, filter, scale, screen); } } -void target_manager::update_screen_count(uint32_t count) +void target_manager::update_screen_count(uint32_t count, uint16_t user_prescale, uint16_t max_prescale_size) { // Ensure that there's an entry to fill while (count > m_native_dims.size()) { - m_native_dims.push_back(osd_dim(0, 0)); + m_native_dims.emplace_back(osd_dim(0, 0)); } if (count != m_screen_count) @@ -155,26 +165,26 @@ void target_manager::update_screen_count(uint32_t count) { for (uint32_t screen = old_count; screen < m_screen_count; screen++) { - create_target_if_nonexistent(screen, "output", false, false, TARGET_STYLE_NATIVE); + create_output_if_nonexistent(screen, user_prescale, max_prescale_size); } } } } -void target_manager::create_target_if_nonexistent(uint32_t screen, std::string name, bool double_buffered, bool filter, uint32_t style) +void target_manager::create_output_if_nonexistent(uint32_t screen, uint16_t user_prescale, uint16_t max_prescale_size) { - if (style == TARGET_STYLE_CUSTOM) return; - - if (m_targets[name + std::to_string(screen)] != nullptr) + if (m_targets.find("output" + std::to_string(screen)) != m_targets.end()) { return; } - std::vector<osd_dim>& sizes = style == TARGET_STYLE_GUEST ? m_guest_dims : m_native_dims; - uint16_t width(sizes[screen].width()); - uint16_t height(sizes[screen].height()); + uint16_t width(m_native_dims[screen].width()); + uint16_t height(m_native_dims[screen].height()); + uint16_t xprescale = user_prescale; + uint16_t yprescale = user_prescale; + bgfx_util::find_prescale_factor(width, height, max_prescale_size, xprescale, yprescale); - create_target(name, bgfx::TextureFormat::RGBA8, width, height, style, double_buffered, filter, 1, screen); + create_target("output", bgfx::TextureFormat::BGRA8, width, height, xprescale, yprescale, TARGET_STYLE_NATIVE, false, false, 1, screen); } uint16_t target_manager::width(uint32_t style, uint32_t screen) |