]> git.sesse.net Git - mlt/blob - src/modules/opengl/filter_glsl_manager.h
35e81b13eb16efa35de1746664617af689c17abc
[mlt] / src / modules / opengl / filter_glsl_manager.h
1 /*
2  * filter_glsl_manager.h
3  * Copyright (C) 2013 Dan Dennedy <dan@dennedy.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef GLSL_MANAGER_H
21 #define GLSL_MANAGER_H
22
23 // Include a random Movit header file to get in GL.h, without including it
24 // ourselves (which might interfere with whatever OpenGL extension library
25 // Movit has chosen to use).
26 #include <movit/resource_pool.h>
27
28 #include <mlt++/MltFilter.h>
29 #include <mlt++/MltDeque.h>
30 #include <map>
31 #include <string>
32
33 #define MAXLISTCOUNT 1024
34 typedef struct glsl_list_s *glsl_list;
35 struct glsl_list_s
36 {
37         void *items[MAXLISTCOUNT];
38         int count;
39
40         int ( *add )( glsl_list, void* );
41         void* ( *at )( glsl_list, int );
42         void* ( *take_at )( glsl_list, int );
43         void* ( *take )( glsl_list, void* );
44 };
45
46 struct glsl_texture_s
47 {
48         int used;
49         GLuint texture;
50         int width;
51         int height;
52         GLint internal_format;
53 };
54 typedef struct glsl_texture_s *glsl_texture;
55
56 struct glsl_pbo_s
57 {
58         int size;
59         GLuint pbo;
60 };
61 typedef struct glsl_pbo_s *glsl_pbo;
62
63 namespace movit {
64
65 class Effect;
66 class EffectChain;
67 class ResourcePool;
68
69 }  // namespace movit
70
71 class MltInput;
72
73 struct GlslChain
74 {
75         movit::EffectChain *effect_chain;
76
77         // All MltInputs in the effect chain. These are not owned by the
78         // EffectChain (although the contained Input* is).
79         std::map<mlt_producer, MltInput*> inputs;
80
81         // All services owned by the effect chain and their associated Movit effect.
82         std::map<mlt_service, movit::Effect*> effects;
83
84         // For each effect in the Movit graph, a unique identifier for the service
85         // and whether it's disabled or not, using post-order traversal.
86         // We need to generate the chain if and only if this has changed.
87         std::string fingerprint;
88 };
89
90 class GlslManager : public Mlt::Filter
91 {
92 public:
93         GlslManager();
94         ~GlslManager();
95         void add_ref(mlt_properties properties);
96         static GlslManager* get_instance();
97
98         glsl_texture get_texture(int width, int height, GLint internal_format);
99         static void release_texture(glsl_texture);
100         static void delete_sync(GLsync sync);
101         glsl_pbo get_pbo(int size);
102         void cleanupContext();
103
104         movit::ResourcePool* get_resource_pool() { return resource_pool; }
105
106         static void set_chain(mlt_service, GlslChain*);
107         static GlslChain* get_chain(mlt_service);
108
109         static movit::Effect* get_effect(mlt_service, mlt_frame);
110         static movit::Effect* set_effect(mlt_service, mlt_frame, movit::Effect*);
111         static MltInput* get_input(mlt_producer, mlt_frame);
112         static MltInput* set_input(mlt_producer, mlt_frame, MltInput*);
113         static uint8_t* get_input_pixel_pointer(mlt_producer, mlt_frame);
114         static uint8_t* set_input_pixel_pointer(mlt_producer, mlt_frame, uint8_t*);
115
116         static mlt_service get_effect_input(mlt_service, mlt_frame);
117         static void set_effect_input(mlt_service, mlt_frame, mlt_service);
118         static void get_effect_secondary_input(mlt_service, mlt_frame, mlt_service*, mlt_frame*);
119         static void set_effect_secondary_input(mlt_service, mlt_frame, mlt_service, mlt_frame);
120
121         int render_frame_texture(movit::EffectChain*, mlt_frame, int width, int height, uint8_t **image);
122         int render_frame_rgba(movit::EffectChain*, mlt_frame, int width, int height, uint8_t **image);
123         static void lock_service(mlt_frame frame);
124         static void unlock_service(mlt_frame frame);
125
126 private:
127         static void* get_frame_specific_data( mlt_service service, mlt_frame frame, const char *key, int *length );
128         static int set_frame_specific_data( mlt_service service, mlt_frame frame, const char *key, void *value, int length, mlt_destructor destroy, mlt_serialiser serialise );
129
130         static void onInit( mlt_properties owner, GlslManager* filter );
131         static void onClose( mlt_properties owner, GlslManager* filter );
132         static void onServiceChanged( mlt_properties owner, mlt_service service );
133         static void onPropertyChanged( mlt_properties owner, mlt_service service, const char* property );
134         movit::ResourcePool* resource_pool;
135         Mlt::Deque texture_list;
136         Mlt::Deque syncs_to_delete;
137         glsl_pbo  pbo;
138         Mlt::Event* initEvent;
139         Mlt::Event* closeEvent;
140         GLsync prev_sync;
141 };
142
143 #endif // GLSL_MANAGER_H