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