]> git.sesse.net Git - nageru/blobdiff - nageru/image_input.h
Make the ImageInput cache store textures, not images.
[nageru] / nageru / image_input.h
index ac3c519147d6d4d6f66ad4e2baffaffaabdf7a69..f7289f3164e647358722ad5c021d75fa7f881c3e 100644 (file)
 #include <string>
 #include <thread>
 
+#include "ref_counted_texture.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 {
 public:
+       // NOTE: You will need to call start_update_thread() yourself, once per program.
        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();
+
+       static void start_update_thread(QSurface *surface);
+       static void end_update_thread();
        
 private:
        struct Image {
                unsigned width, height;
-               std::unique_ptr<uint8_t[]> pixels;
+               RefCountedTexture tex;
                timespec last_modified;
        };
 
@@ -36,15 +43,14 @@ private:
 
        static std::shared_ptr<const Image> load_image(const std::string &filename, const std::string &pathname);
        static std::shared_ptr<const Image> load_image_raw(const std::string &pathname);
-       static void update_thread_func();
+       static void update_thread_func(QSurface *surface);
        static std::mutex all_images_lock;
        static std::map<std::string, std::shared_ptr<const Image>> all_images;  // Under all_images_lock.
-       static bool update_thread_started;  // Under all_images_lock.
-       static std::thread update_thread;  // 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)