]> git.sesse.net Git - mlt/blob - src/modules/opengl/filter_glsl_manager.h
Use the new ResourcePool Movit functionality.
[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 <glew.h>
24 #include <mlt++/MltFilter.h>
25 #include <mlt++/MltDeque.h>
26 #include <map>
27 #include <string>
28
29 #define MAXLISTCOUNT 1024
30 typedef struct glsl_list_s *glsl_list;
31 struct glsl_list_s
32 {
33         void *items[MAXLISTCOUNT];
34         int count;
35
36         int ( *add )( glsl_list, void* );
37         void* ( *at )( glsl_list, int );
38         void* ( *take_at )( glsl_list, int );
39         void* ( *take )( glsl_list, void* );
40 };
41
42 struct glsl_texture_s
43 {
44         int used;
45         GLuint texture;
46         int width;
47         int height;
48         GLint internal_format;
49 };
50 typedef struct glsl_texture_s *glsl_texture;
51
52 struct glsl_fbo_s
53 {
54         int used;
55         int width;
56         int height;
57         GLuint fbo;
58         void* context;
59 };
60 typedef struct glsl_fbo_s *glsl_fbo;
61
62 struct glsl_pbo_s
63 {
64         int size;
65         GLuint pbo;
66 };
67 typedef struct glsl_pbo_s *glsl_pbo;
68
69 class Effect;
70 class EffectChain;
71 class MltInput;
72 class ResourcePool;
73
74 struct GlslChain
75 {
76         EffectChain *effect_chain;
77
78         // All services owned by the effect chain and their associated Movit effect.
79         std::map<mlt_service, Effect*> effects;
80
81         // For each effect in the Movit graph, a unique identifier for the service
82         // and whether it's disabled or not, using post-order traversal.
83         // We need to generate the chain if and only if this has changed.
84         std::string fingerprint;
85 };
86
87 class GlslManager : public Mlt::Filter
88 {
89 public:
90         GlslManager();
91         ~GlslManager();
92         void add_ref(mlt_properties properties);
93         static GlslManager* get_instance();
94
95         glsl_fbo get_fbo(int width, int height);
96         static void release_fbo(glsl_fbo);
97         glsl_texture get_texture(int width, int height, GLint internal_format);
98         static void release_texture(glsl_texture);
99         static void delete_sync(GLsync sync);
100         glsl_pbo get_pbo(int size);
101         void cleanupContext();
102
103         ResourcePool* get_resource_pool() { return resource_pool; }
104
105         static void set_chain(mlt_service, GlslChain*);
106         static GlslChain* get_chain(mlt_service);
107
108         static Effect* get_effect(mlt_service, mlt_frame);
109         static Effect* set_effect(mlt_service, mlt_frame, Effect*);
110         static MltInput* get_input(mlt_producer, mlt_frame);
111         static MltInput* set_input(mlt_producer, mlt_frame, MltInput*);
112         static uint8_t* get_input_pixel_pointer(mlt_producer, mlt_frame);
113         static uint8_t* set_input_pixel_pointer(mlt_producer, mlt_frame, uint8_t*);
114
115         static mlt_service get_effect_input(mlt_service, mlt_frame);
116         static void set_effect_input(mlt_service, mlt_frame, mlt_service);
117         static void get_effect_secondary_input(mlt_service, mlt_frame, mlt_service*, mlt_frame*);
118         static void set_effect_secondary_input(mlt_service, mlt_frame, mlt_service, mlt_frame);
119
120         int render_frame_texture(EffectChain*, mlt_frame, int width, int height, uint8_t **image);
121         int render_frame_rgba(EffectChain*, mlt_frame, int width, int height, uint8_t **image);
122         static void lock_service(mlt_frame frame);
123         static void unlock_service(mlt_frame frame);
124
125 private:
126         static void* get_frame_specific_data( mlt_service service, mlt_frame frame, const char *key, int *length );
127         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 );
128
129         static void onInit( mlt_properties owner, GlslManager* filter );
130         static void onClose( mlt_properties owner, GlslManager* filter );
131         static void onServiceChanged( mlt_properties owner, mlt_service service );
132         static void onPropertyChanged( mlt_properties owner, mlt_service service, const char* property );
133         ResourcePool* resource_pool;
134         Mlt::Deque fbo_list;
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