X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fimage_input.h;h=1f6092e39618119e997bbbe970a45345e25a8070;hb=a0e57ec99e9dfdd7e79bcf21e8c996dc43b6cb49;hp=6a75df48c9f15ccdccfa26fe4a40b70bf49b05dd;hpb=f677a047d02e4d21491f2905bd220557472e1960;p=nageru diff --git a/nageru/image_input.h b/nageru/image_input.h index 6a75df4..1f6092e 100644 --- a/nageru/image_input.h +++ b/nageru/image_input.h @@ -2,48 +2,63 @@ #define _IMAGE_INPUT_H 1 #include -#include #include #include #include -#include #include #include #include #include #include +#include "shared/ref_counted_texture.h" +#include "tweaked_inputs.h" + +class QSurface; + // An output that takes its input from a static image, loaded with ffmpeg. // comes from a single 2D array with chunky pixels. The image is refreshed // from disk about every second. -class ImageInput : public movit::FlatInput { +class ImageInput : public sRGBSwitchingFlatInput { public: + // For loading images. + // NOTE: You will need to call start_update_thread() yourself, once per program. + struct Image { + unsigned width, height; + UniqueTexture tex; + timespec last_modified; + }; + static std::shared_ptr load_image(const std::string &filename, const std::string &pathname); + + // Actual members. + + ImageInput(); // Construct an empty input, which can't be used until you call switch_image(). ImageInput(const std::string &filename); std::string effect_type_id() const override { return "ImageInput"; } void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num) override; - static void shutdown_updaters(); + + // Switch to a different image. The image must be previously loaded using load_image(). + void switch_image(const std::string &pathname); + + std::string get_pathname() const { return pathname; } + + static void start_update_thread(QSurface *surface); + static void end_update_thread(); private: - struct Image { - unsigned width, height; - std::unique_ptr pixels; - timespec last_modified; - }; - std::string pathname; std::shared_ptr current_image; - static std::shared_ptr load_image(const std::string &filename, const std::string &pathname); static std::shared_ptr load_image_raw(const std::string &pathname); - static void update_thread_func(const std::string &filename, const std::string &pathname, const timespec &first_modified); + static void update_thread_func(QSurface *surface); static std::mutex all_images_lock; - static std::map> all_images; - static std::map update_threads; + static std::map> all_images; // Under all_images_lock. - static std::mutex threads_should_quit_mu; - static bool threads_should_quit; // Under threads_should_quit_mu. - static std::condition_variable threads_should_quit_modified; // Signals when threads_should_quit is set. + static std::thread update_thread; + static std::mutex update_thread_should_quit_mu; + static bool update_thread_should_quit; // Under thread_should_quit_mu. + static std::condition_variable update_thread_should_quit_modified; // Signals when threads_should_quit is set. }; #endif // !defined(_IMAGE_INPUT_H)