X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fjpeg_frame_view.h;h=693ea9b6d0a4c5f58fd3f4afafc7ca1ccf484847;hb=refs%2Fheads%2Fmaster;hp=38ffd412b61b5610cc68e8fa6e646e6901f68571;hpb=6e116a6bbeb2c047a3bfb084395ec601ce211e6c;p=nageru diff --git a/futatabi/jpeg_frame_view.h b/futatabi/jpeg_frame_view.h index 38ffd41..693ea9b 100644 --- a/futatabi/jpeg_frame_view.h +++ b/futatabi/jpeg_frame_view.h @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include enum CacheMissBehavior { @@ -20,14 +22,16 @@ enum CacheMissBehavior { RETURN_NULLPTR_IF_NOT_IN_CACHE }; -std::shared_ptr decode_jpeg(const std::string &filename); +std::shared_ptr decode_jpeg(const std::string &jpeg); std::shared_ptr decode_jpeg_with_cache(FrameOnDisk id, CacheMissBehavior cache_miss_behavior, FrameReader *frame_reader, bool *did_decode); +std::shared_ptr get_black_frame(); class JPEGFrameView : public QGLWidget { Q_OBJECT public: JPEGFrameView(QWidget *parent); + ~JPEGFrameView(); void setFrame(unsigned stream_idx, FrameOnDisk frame, FrameOnDisk secondary_frame = {}, float fade_alpha = 0.0f); void setFrame(std::shared_ptr frame); @@ -39,8 +43,6 @@ public: void setDecodedFrame(std::shared_ptr frame, std::shared_ptr secondary_frame, float fade_alpha); void set_overlay(const std::string &text); // Blank for none. - static void shutdown(); - signals: void clicked(); @@ -50,7 +52,7 @@ protected: void paintGL() override; private: - static void jpeg_decoder_thread_func(); + void jpeg_decoder_thread_func(); FrameReader frame_reader; @@ -60,10 +62,11 @@ private: std::unique_ptr ycbcr_converter; movit::EffectChain *current_chain = nullptr; // Owned by ycbcr_converter. - std::shared_ptr current_frame; // So that we hold on to the pixels. + bool displayed_this_frame = false; // Owned by the UI frame. + std::shared_ptr current_frame; // So that we hold on to the textures. std::shared_ptr current_secondary_frame; // Same. - static constexpr int overlay_base_width = 16, overlay_base_height = 16; + int overlay_base_width = 16, overlay_base_height = 16; int overlay_width = overlay_base_width, overlay_height = overlay_base_height; std::unique_ptr overlay_image; // If nullptr, no overlay. std::unique_ptr overlay_chain; // Just to get the overlay on screen in the easiest way possible. @@ -72,7 +75,22 @@ private: int gl_width, gl_height; - static std::thread jpeg_decoder_thread; + std::thread jpeg_decoder_thread; + movit::ResourcePool *resource_pool = nullptr; + + struct PendingDecode { + // For actual decodes (only if frame below is nullptr). + FrameOnDisk primary, secondary; + float fade_alpha; // Irrelevant if secondary.stream_idx == -1. + + // Already-decoded frames are also sent through PendingDecode, + // so that they get drawn in the right order. If frame is nullptr, + // it's a real decode. + std::shared_ptr frame; + }; + + std::condition_variable any_pending_decodes; + std::deque pending_decodes; // Under cache_mu. }; #endif // !defined(_JPEG_FRAME_VIEW_H)