193761b6763a61d11b0b85c8edbb4ec658df2b99
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / virtualvconsole.C
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 #include "bcsignals.h"
23 #include "bctimer.h"
24 #include "datatype.h"
25 #include "edl.h"
26 #include "edlsession.h"
27 #include "mwindow.h"
28 #include "playabletracks.h"
29 #include "preferences.h"
30 #include "renderengine.h"
31 #include "tracks.h"
32 #include "transportque.h"
33 #include "vdevicex11.h"
34 #include "vframe.h"
35 #include "videodevice.h"
36 #include "virtualvconsole.h"
37 #include "virtualvnode.h"
38 #include "vmodule.h"
39 #include "vrender.h"
40 #include "vtrack.h"
41
42 VirtualVConsole::VirtualVConsole(RenderEngine *renderengine, VRender *vrender)
43  : VirtualConsole(renderengine, vrender, TRACK_VIDEO)
44 {
45         this->vrender = vrender;
46         output_temp = 0;
47 }
48
49 VirtualVConsole::~VirtualVConsole()
50 {
51         delete output_temp;
52 }
53
54 VDeviceBase* VirtualVConsole::get_vdriver()
55 {
56         return renderengine->video->get_output_base();
57 }
58
59 void VirtualVConsole::get_playable_tracks()
60 {
61         if(!playable_tracks)
62                 playable_tracks = new PlayableTracks(renderengine->get_edl(),
63                         commonrender->current_position,
64                         renderengine->command->get_direction(),
65                         TRACK_VIDEO,
66                         1);
67 //printf("VirtualVConsole::get_playable_tracks %d %d\n", __LINE__, playable_tracks->size());
68 }
69
70 VirtualNode* VirtualVConsole::new_entry_node(Track *track,
71         Module *module,
72         int track_number)
73 {
74         return new VirtualVNode(renderengine,
75                 this,
76                 module,
77                 0,
78                 track,
79                 0);
80 }
81
82 // start of buffer in project if forward / end of buffer if reverse
83 int VirtualVConsole::process_buffer(int64_t input_position,
84         int use_opengl)
85 {
86         int result = 0;
87
88
89
90 // The use of single frame is determined in RenderEngine::arm_command
91 // printf("VirtualVConsole::process_buffer %d this=%p %d\n",
92 // __LINE__,
93 // this,
94 // use_opengl);
95
96         if(debug_tree)
97                 printf("VirtualVConsole::process_buffer %d exit_nodes=%d\n",
98                         __LINE__,
99                         exit_nodes.total);
100
101
102         if(use_opengl)
103         {
104 // clear hardware framebuffer
105
106                 ((VDeviceX11*)get_vdriver())->clear_output();
107
108 // que OpenGL driver that everything is overlaid in the framebuffer
109                 vrender->video_out->set_opengl_state(VFrame::SCREEN);
110
111         }
112         else
113         {
114 // clear device buffer
115 //printf("VirtualVConsole::process_buffer %d %p\n", __LINE__, vrender->video_out);
116 //vrender->video_out->dump();
117                 vrender->video_out->clear_frame();
118 //printf("VirtualVConsole::process_buffer %d\n", __LINE__);
119         }
120
121
122
123
124
125
126 // Reset plugin rendering status
127         reset_attachments();
128
129 //      Timer timer;
130 // Render exit nodes from bottom to top
131         for(current_exit_node = exit_nodes.total - 1; current_exit_node >= 0; current_exit_node--)
132         {
133                 VirtualVNode *node = (VirtualVNode*)exit_nodes.values[current_exit_node];
134                 Track *track = node->track;
135
136 // Create temporary output to match the track size, which is acceptable since
137 // most projects don't have variable track sizes.
138 // If the project has variable track sizes, this object is recreated for each track.
139
140
141
142
143
144                 if(output_temp &&
145                         (output_temp->get_w() != track->track_w ||
146                         output_temp->get_h() != track->track_h))
147                 {
148                         delete output_temp;
149                         output_temp = 0;
150                 }
151
152
153                 if(!output_temp)
154                 {
155 // Texture is created on demand
156                         EDL *edl = renderengine->get_edl();
157                         output_temp = new VFrame( track->track_w, track->track_h,
158                                 edl->session->color_model);
159                         int clr_color = edl->session->cwindow_clear_color;
160                         int clr_alpha = edl->session->cwindow_clear_alpha;
161                         output_temp->set_clear_color(clr_color, clr_alpha);
162                 }
163
164 // Reset OpenGL state
165                 if(use_opengl)
166                         output_temp->set_opengl_state(VFrame::RAM);
167
168
169 // Assume openGL is used for the final stage and let console
170 // disable.
171                 output_temp->clear_stacks();
172                 result |= node->render(output_temp,
173                         input_position + track->nudge,
174                         renderengine->get_edl()->session->frame_rate,
175                         use_opengl);
176
177         }
178 //printf("VirtualVConsole::process_buffer timer=%jd\n", timer.get_difference());
179
180         if(debug_tree) printf("VirtualVConsole::process_buffer %d\n", __LINE__);
181         return result;
182 }
183