mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-23 20:05:11 +00:00
code: Migrate source::shader to new dynamic loader
This commit is contained in:
parent
765e663180
commit
cfa2806e89
3 changed files with 20 additions and 32 deletions
|
@ -50,9 +50,6 @@
|
||||||
#ifdef ENABLE_SOURCE_MIRROR
|
#ifdef ENABLE_SOURCE_MIRROR
|
||||||
#include "sources/source-mirror.hpp"
|
#include "sources/source-mirror.hpp"
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_SOURCE_SHADER
|
|
||||||
#include "sources/source-shader.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ENABLE_FRONTEND
|
#ifdef ENABLE_FRONTEND
|
||||||
#include "ui/ui.hpp"
|
#include "ui/ui.hpp"
|
||||||
|
@ -189,9 +186,6 @@ MODULE_EXPORT bool obs_module_load(void)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_SOURCE_MIRROR
|
#ifdef ENABLE_SOURCE_MIRROR
|
||||||
streamfx::source::mirror::mirror_factory::initialize();
|
streamfx::source::mirror::mirror_factory::initialize();
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_SOURCE_SHADER
|
|
||||||
streamfx::source::shader::shader_factory::initialize();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,9 +209,6 @@ MODULE_EXPORT void obs_module_unload(void)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_SOURCE_MIRROR
|
#ifdef ENABLE_SOURCE_MIRROR
|
||||||
streamfx::source::mirror::mirror_factory::finalize();
|
streamfx::source::mirror::mirror_factory::finalize();
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_SOURCE_SHADER
|
|
||||||
streamfx::source::shader::shader_factory::finalize();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,26 +171,27 @@ bool shader_factory::on_manual_open(obs_properties_t* props, obs_property_t* pro
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::shared_ptr<shader_factory> _source_shader_factory_instance = nullptr;
|
std::shared_ptr<shader_factory> shader_factory::instance()
|
||||||
|
|
||||||
void streamfx::source::shader::shader_factory::initialize()
|
|
||||||
{
|
{
|
||||||
try {
|
static std::weak_ptr<shader_factory> winst;
|
||||||
if (!_source_shader_factory_instance)
|
static std::mutex mtx;
|
||||||
_source_shader_factory_instance = std::make_shared<shader_factory>();
|
|
||||||
} catch (const std::exception& ex) {
|
std::unique_lock<decltype(mtx)> lock(mtx);
|
||||||
D_LOG_ERROR("Failed to initialize due to error: %s", ex.what());
|
auto instance = winst.lock();
|
||||||
} catch (...) {
|
if (!instance) {
|
||||||
D_LOG_ERROR("Failed to initialize due to unknown error.", "");
|
instance = std::shared_ptr<shader_factory>(new shader_factory());
|
||||||
|
winst = instance;
|
||||||
}
|
}
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void streamfx::source::shader::shader_factory::finalize()
|
static std::shared_ptr<shader_factory> loader_instance;
|
||||||
{
|
|
||||||
_source_shader_factory_instance.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<shader_factory> streamfx::source::shader::shader_factory::get()
|
static auto loader = streamfx::loader(
|
||||||
{
|
[]() { // Initalizer
|
||||||
return _source_shader_factory_instance;
|
loader_instance = shader_factory::instance();
|
||||||
}
|
},
|
||||||
|
[]() { // Finalizer
|
||||||
|
loader_instance.reset();
|
||||||
|
},
|
||||||
|
streamfx::loader_priority::NORMAL);
|
||||||
|
|
|
@ -52,10 +52,6 @@ namespace streamfx::source::shader {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public: // Singleton
|
public: // Singleton
|
||||||
static void initialize();
|
static std::shared_ptr<shader_factory> instance();
|
||||||
|
|
||||||
static void finalize();
|
|
||||||
|
|
||||||
static std::shared_ptr<shader_factory> get();
|
|
||||||
};
|
};
|
||||||
} // namespace streamfx::source::shader
|
} // namespace streamfx::source::shader
|
||||||
|
|
Loading…
Reference in a new issue