Merge CV, ver=5.1; ops/methods from HV, and interface from CV where possible
[goodguy/history.git] / cinelerra-5.1 / cinelerra / vdevicex11.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #ifndef VDEVICEX11_H
23 #define VDEVICEX11_H
24
25 #include "canvas.inc"
26 #include "edl.inc"
27 #include "guicast.h"
28 #include "maskauto.inc"
29 #include "maskautos.inc"
30 #include "pluginclient.inc"
31 #include "thread.h"
32 #include "vdevicebase.h"
33
34 // output_frame is the same one written to device
35 #define BITMAP_PRIMARY 0
36 // output_frame is a temporary converted to the device format
37 #define BITMAP_TEMP    1
38
39 class VDeviceX11 : public VDeviceBase
40 {
41 public:
42         VDeviceX11(VideoDevice *device, Canvas *output);
43         ~VDeviceX11();
44
45         int open_input();
46         int close_all();
47         int read_buffer(VFrame *frame);
48         int reset_parameters();
49 // User always gets the colormodel requested
50         void new_output_buffer(VFrame **output, int colormodel);
51
52         int open_output();
53         int start_playback();
54         int stop_playback();
55         int output_visible();
56 // After loading the bitmap with a picture, write it
57         int write_buffer(VFrame *result, EDL *edl);
58 // Get best colormodel for recording
59         int get_best_colormodel(Asset *asset);
60
61
62 //=========================== compositing stages ===============================
63 // For compositing with OpenGL, must clear the frame buffer
64 // before overlaying tracks.
65         void clear_output();
66
67 // Called by VModule::import_frame
68         void do_camera(VFrame *output,
69                 VFrame *input,
70                 float in_x1, 
71                 float in_y1, 
72                 float in_x2, 
73                 float in_y2, 
74                 float out_x1, 
75                 float out_y1, 
76                 float out_x2, 
77                 float out_y2);
78
79 // Called by VModule::import_frame for cases with no media.
80         void clear_input(VFrame *frame);
81
82         void do_fade(VFrame *output_temp, float fade);
83
84 // Hardware version of MaskEngine
85         void do_mask(VFrame *output_temp, 
86                 int64_t start_position_project,
87                 MaskAutos *keyframe_set, 
88                 MaskAuto *keyframe,
89                 MaskAuto *default_auto);
90         void convert_cmodel(VFrame *output, int dst_cmodel);
91
92 // The idea is to composite directly in the frame buffer if OpenGL.
93 // OpenGL can do all the blending using the frame buffer.
94 // Unfortunately if the output is lower resolution than the frame buffer, the
95 // rendered output is the resolution of the frame buffer, not the output.
96 // Also, the frame buffer has to be copied back to textures for nonstandard
97 // blending equations and blended at the framebuffer resolution.
98 // If the frame buffer is higher resolution than the
99 // output frame, like a 2560x1600 display, it could cause unnecessary slowness.
100 // Finally, there's the problem of updating the refresh frame.
101 // It requires recompositing the previous frame in software every time playback was
102 // stops, a complicated operation.
103         void overlay(VFrame *output_frame,
104                 VFrame *input, 
105                 float in_x1, 
106                 float in_y1, 
107                 float in_x2, 
108                 float in_y2, 
109                 float out_x1, 
110                 float out_y1, 
111                 float out_x2, 
112                 float out_y2, 
113                 float alpha,        // 0 - 1
114                 int mode,
115                 EDL *edl,
116                 int is_nested);
117
118 // For plugins, lock the canvas, enable opengl, and run a function in the
119 // plugin client in the synchronous thread.  The user must override the
120 // pluginclient function.
121         void run_plugin(PluginClient *client);
122
123 // For multichannel plugins, copy from the temporary pbuffer to 
124 // the plugin output texture.
125 // Set the output OpenGL state to TEXTURE.
126         void copy_frame(VFrame *dst, VFrame *src);
127
128 private:
129 // Closest colormodel the hardware can do for playback.
130 // Only used by VDeviceX11::new_output_buffer.  The value from File::get_best_colormodel
131 // is passed to this to create the VFrame to which the output is rendered.
132 // For OpenGL, it creates the array of row pointers used to upload the video
133 // frame to the texture, the texture, and the PBuffer.
134         int get_best_colormodel(int colormodel);
135
136 // Bitmap to be written to device
137         BC_Bitmap *bitmap;        
138 // Wrapper for bitmap or intermediate buffer for user to write to
139         VFrame *output_frame;     
140 // Type of output_frame
141         int bitmap_type;           
142 // dimensions of buffers written to window
143         int bitmap_w, bitmap_h;   
144         ArrayList<int> render_strategies;
145 // Canvas for output
146         Canvas *output;
147 // Parameters the output texture conforms to, for OpenGL
148 // window_id is probably not going to be used
149         int window_id;
150         int texture_w;
151         int texture_h;
152         int color_model;
153         int color_model_selected;
154 // Transfer coordinates from the output frame to the canvas 
155 // for last frame rendered.
156 // These stick the last frame to the display.
157 // Must be floats to support OpenGL
158         float output_x1, output_y1, output_x2, output_y2;
159         float canvas_x1, canvas_y1, canvas_x2, canvas_y2;
160 // Screen capture
161         BC_Capture *capture_bitmap;
162 // Set when OpenGL rendering has cleared the frame buffer before write_buffer
163         int is_cleared;
164 };
165
166 #endif