filter-blur: Refactor onto obs::source_factory

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2019-12-03 20:37:57 +01:00
parent 4e1dcb533c
commit d9f43ec2e8
2 changed files with 506 additions and 651 deletions

File diff suppressed because it is too large Load diff

View file

@ -29,6 +29,7 @@
#include "obs/gs/gs-helper.hpp" #include "obs/gs/gs-helper.hpp"
#include "obs/gs/gs-rendertarget.hpp" #include "obs/gs/gs-rendertarget.hpp"
#include "obs/gs/gs-texture.hpp" #include "obs/gs/gs-texture.hpp"
#include "obs/obs-source-factory.hpp"
#include "plugin.hpp" #include "plugin.hpp"
// OBS // OBS
@ -43,62 +44,15 @@
namespace filter { namespace filter {
namespace blur { namespace blur {
class blur_instance;
enum mask_type : int64_t { enum mask_type : int64_t {
Region, Region,
Image, Image,
Source, Source,
}; };
class blur_factory { class blur_instance : public obs::source_instance {
obs_source_info _source_info; // Effects
std::list<blur_instance*> _sources; std::shared_ptr<gs::effect> _effect_mask;
std::shared_ptr<gs::effect> _color_converter_effect;
std::shared_ptr<gs::effect> _mask_effect;
std::map<std::string, std::string> _translation_map;
public: // Singleton
static void initialize();
static void finalize();
static std::shared_ptr<blur_factory> get();
public:
blur_factory();
~blur_factory();
void on_list_fill();
void on_list_empty();
std::string const& get_translation(std::string const key);
static void* create(obs_data_t* settings, obs_source_t* self);
static void destroy(void* source);
static void get_defaults(obs_data_t* settings);
static obs_properties_t* get_properties(void* source);
static void update(void* source, obs_data_t* settings);
static void load(void* source, obs_data_t* settings);
static const char* get_name(void* source);
static uint32_t get_width(void* source);
static uint32_t get_height(void* source);
static void activate(void* source);
static void deactivate(void* source);
static void video_tick(void* source, float delta);
static void video_render(void* source, gs_effect_t* effect);
public:
std::shared_ptr<gs::effect> get_color_converter_effect();
std::shared_ptr<gs::effect> get_mask_effect();
};
class blur_instance {
obs_source_t* _self;
// Input // Input
std::shared_ptr<gs::rendertarget> _source_rt; std::shared_ptr<gs::rendertarget> _source_rt;
@ -112,11 +66,11 @@ namespace filter {
// Blur // Blur
std::shared_ptr<::gfx::blur::base> _blur; std::shared_ptr<::gfx::blur::base> _blur;
double_t _blur_size; double_t _blur_size;
double_t _blur_angle; double_t _blur_angle;
std::pair<double_t, double_t> _blur_center; std::pair<double_t, double_t> _blur_center;
bool _blur_step_scaling; bool _blur_step_scaling;
std::pair<double_t, double_t> _blur_step_scale; std::pair<double_t, double_t> _blur_step_scale;
// Masking // Masking
struct { struct {
@ -156,28 +110,51 @@ namespace filter {
blur_instance(obs_data_t* settings, obs_source_t* self); blur_instance(obs_data_t* settings, obs_source_t* self);
~blur_instance(); ~blur_instance();
public:
virtual void update(obs_data_t* settings) override;
virtual void load(obs_data_t* settings) override;
virtual void video_tick(float time) override;
virtual void video_render(gs_effect_t* effect) override;
private: private:
bool apply_mask_parameters(std::shared_ptr<gs::effect> effect, gs_texture_t* original_texture, bool apply_mask_parameters(std::shared_ptr<gs::effect> effect, gs_texture_t* original_texture,
gs_texture_t* blurred_texture); gs_texture_t* blurred_texture);
};
static bool modified_properties(void* ptr, obs_properties_t* props, obs_property* prop, class blur_factory : public obs::source_factory<filter::blur::blur_factory, filter::blur::blur_instance> {
obs_data_t* settings) noexcept; static std::shared_ptr<filter::blur::blur_factory> factory_instance;
void translate_old_settings(obs_data_t*); public: // Singleton
static void initialize()
{
factory_instance = std::make_shared<filter::blur::blur_factory>();
}
static void finalize()
{
factory_instance.reset();
}
static std::shared_ptr<blur_factory> get()
{
return factory_instance;
}
private:
std::vector<std::string> _translation_cache;
public: public:
obs_properties_t* get_properties(); blur_factory();
void update(obs_data_t*); virtual ~blur_factory();
void load(obs_data_t*);
uint32_t get_width(); virtual const char* get_name() override;
uint32_t get_height();
void activate(); virtual void get_defaults2(obs_data_t* settings) override;
void deactivate();
void video_tick(float); virtual obs_properties_t* get_properties2(filter::blur::blur_instance* data) override;
void video_render(gs_effect_t*);
std::string translate_string(const char* format, ...);
}; };
} // namespace blur } // namespace blur
} // namespace filter } // namespace filter