]> git.sesse.net Git - nageru/blob - theme.h
Clean up resources in the global ResourcePool on exit, in order to avoid some assert...
[nageru] / theme.h
1 #ifndef _THEME_H
2 #define _THEME_H 1
3
4 #include <epoxy/gl.h>
5 #include <lauxlib.h>
6 #include <lua.h>
7 #include <movit/effect_chain.h>
8 #include <movit/deinterlace_effect.h>
9 #include <movit/ycbcr_input.h>
10 #include <stdbool.h>
11 #include <stdio.h>
12 #include <functional>
13 #include <mutex>
14 #include <set>
15 #include <string>
16 #include <utility>
17 #include <vector>
18
19 #include "defs.h"
20 #include "input_state.h"
21 #include "ref_counted_frame.h"
22
23 namespace movit {
24 class ResourcePool;
25 struct ImageFormat;
26 struct YCbCrFormat;
27 }  // namespace movit
28
29 class NonBouncingYCbCrInput : public movit::YCbCrInput {
30 public:
31         NonBouncingYCbCrInput(const movit::ImageFormat &image_format,
32                               const movit::YCbCrFormat &ycbcr_format,
33                               unsigned width, unsigned height,
34                               movit::YCbCrInputSplitting ycbcr_input_splitting = movit::YCBCR_INPUT_PLANAR)
35             : movit::YCbCrInput(image_format, ycbcr_format, width, height, ycbcr_input_splitting) {}
36
37         bool override_disable_bounce() const override { return true; }
38 };
39
40 class Theme {
41 public:
42         Theme(const char *filename, movit::ResourcePool *resource_pool, unsigned num_cards);
43         ~Theme();
44
45         struct Chain {
46                 movit::EffectChain *chain;
47                 std::function<void()> setup_chain;
48
49                 // May have duplicates.
50                 std::vector<RefCountedFrame> input_frames;
51         };
52
53         Chain get_chain(unsigned num, float t, unsigned width, unsigned height, InputState input_state);
54
55         int get_num_channels() const { return num_channels; }
56         int map_signal(int signal_num);
57         std::string get_channel_name(unsigned channel);
58         bool get_supports_set_wb(unsigned channel);
59         void set_wb(unsigned channel, double r, double g, double b);
60
61         std::vector<std::string> get_transition_names(float t);
62
63         void connect_signal(movit::YCbCrInput *input, int signal_num);
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         std::set<int> signals_warned_about;
79
80         friend class LiveInputWrapper;
81 };
82
83 class LiveInputWrapper {
84 public:
85         LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bool override_bounce, bool deinterlace);
86
87         void connect_signal(int signal_num);
88         movit::Effect *get_effect() const
89         {
90                 if (deinterlace) {
91                         return deinterlace_effect;
92                 } else {
93                         return inputs[0];
94                 }
95         }
96
97 private:
98         Theme *theme;  // Not owned by us.
99         std::vector<movit::YCbCrInput *> 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)