]> git.sesse.net Git - nageru/blob - theme.h
Move NonBouncingYCbCrInput into its own header file.
[nageru] / theme.h
1 #ifndef _THEME_H
2 #define _THEME_H 1
3
4 #include <lua.hpp>
5 #include <movit/flat_input.h>
6 #include <movit/ycbcr_input.h>
7 #include <stdbool.h>
8 #include <functional>
9 #include <map>
10 #include <mutex>
11 #include <string>
12 #include <vector>
13
14 #include "bmusb/bmusb.h"
15 #include "ref_counted_frame.h"
16 #include "tweaked_inputs.h"
17
18 struct InputState;
19
20 namespace movit {
21 class Effect;
22 class EffectChain;
23 class ResourcePool;
24 }  // namespace movit
25
26 class Theme {
27 public:
28         Theme(const std::string &filename, const std::vector<std::string> &search_dirs, movit::ResourcePool *resource_pool, unsigned num_cards);
29         ~Theme();
30
31         struct Chain {
32                 movit::EffectChain *chain;
33                 std::function<void()> setup_chain;
34
35                 // May have duplicates.
36                 std::vector<RefCountedFrame> input_frames;
37         };
38
39         Chain get_chain(unsigned num, float t, unsigned width, unsigned height, InputState input_state);
40
41         int get_num_channels() const { return num_channels; }
42         int map_signal(int signal_num);
43         void set_signal_mapping(int signal_num, int card_num);
44         std::string get_channel_name(unsigned channel);
45         int get_channel_signal(unsigned channel);
46         bool get_supports_set_wb(unsigned channel);
47         void set_wb(unsigned channel, double r, double g, double b);
48         std::string get_channel_color(unsigned channel);
49
50         std::vector<std::string> get_transition_names(float t);
51
52         void transition_clicked(int transition_num, float t);
53         void channel_clicked(int preview_num);
54
55         movit::ResourcePool *get_resource_pool() const { return resource_pool; }
56
57 private:
58         void register_class(const char *class_name, const luaL_Reg *funcs);
59
60         std::mutex m;
61         lua_State *L;  // Protected by <m>.
62         const InputState *input_state;  // Protected by <m>. Only set temporarily, during chain setup.
63         movit::ResourcePool *resource_pool;
64         int num_channels;
65         unsigned num_cards;
66
67         std::mutex map_m;
68         std::map<int, int> signal_to_card_mapping;  // Protected by <map_m>.
69
70         friend class LiveInputWrapper;
71 };
72
73 // LiveInputWrapper is a facade on top of an YCbCrInput, exposed to
74 // the Lua code. It contains a function (connect_signal()) intended
75 // to be called during chain setup, that picks out the current frame
76 // (in the form of a set of textures) from the input state given by
77 // the mixer, and communicates that state over to the actual YCbCrInput.
78 class LiveInputWrapper {
79 public:
80         // Note: <override_bounce> is irrelevant for PixelFormat_8BitRGBA.
81         LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bmusb::PixelFormat pixel_format, bool override_bounce, bool deinterlace);
82
83         void connect_signal(int signal_num);
84         movit::Effect *get_effect() const
85         {
86                 if (deinterlace) {
87                         return deinterlace_effect;
88                 } else if (pixel_format == bmusb::PixelFormat_8BitRGBA) {
89                         return rgba_inputs[0];
90                 } else {
91                         return ycbcr_inputs[0];
92                 }
93         }
94
95 private:
96         Theme *theme;  // Not owned by us.
97         bmusb::PixelFormat pixel_format;
98         std::vector<movit::YCbCrInput *> ycbcr_inputs;  // Multiple ones if deinterlacing. Owned by the chain.
99         std::vector<movit::FlatInput *> rgba_inputs;  // Multiple ones if deinterlacing. Owned by the chain.
100         movit::Effect *deinterlace_effect = nullptr;  // Owned by the chain.
101         bool deinterlace;
102 };
103
104 #endif  // !defined(_THEME_H)