00001 #ifndef BCSYNCHRONOUS_H
00002 #define BCSYNCHRONOUS_H
00003
00004 #include "arraylist.h"
00005 #include "bcpbuffer.inc"
00006 #include "bcpixmap.inc"
00007 #include "bctexture.inc"
00008 #include "bcwindowbase.inc"
00009 #include "condition.inc"
00010 #include "mutex.inc"
00011 #include "thread.h"
00012 #include "vframe.inc"
00013
00014 #if defined(HAVE_CONFIG_H)
00015 #include "config.h"
00016 #endif
00017
00018
00019 #ifdef HAVE_GL
00020 #include <GL/gl.h>
00021 #include <GL/glx.h>
00022 #endif
00023
00024 #include <X11/Xlib.h>
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 class TextureID
00044 {
00045 public:
00046 TextureID(int window_id, int id, int w, int h, int components);
00047 int window_id;
00048 int id;
00049 int w;
00050 int h;
00051 int components;
00052 BC_WindowBase *window;
00053 int in_use;
00054 };
00055
00056 class ShaderID
00057 {
00058 public:
00059 ShaderID(int window_id, unsigned int handle, char *source);
00060 ~ShaderID();
00061
00062
00063 char *source;
00064 int window_id;
00065 unsigned int handle;
00066 };
00067
00068 class PBufferID
00069 {
00070 public:
00071 PBufferID() {};
00072 #ifdef HAVE_GL
00073 PBufferID(int window_id,
00074 GLXPbuffer pbuffer,
00075 GLXContext gl_context,
00076 int w,
00077 int h);
00078 GLXPbuffer pbuffer;
00079 GLXContext gl_context;
00080 int window_id;
00081 int w;
00082 int h;
00083 int in_use;
00084 #endif
00085 };
00086
00087 class BC_SynchronousCommand
00088 {
00089 public:
00090 BC_SynchronousCommand();
00091 ~BC_SynchronousCommand();
00092
00093 virtual void copy_from(BC_SynchronousCommand *command);
00094
00095 Condition *command_done;
00096 int result;
00097 int command;
00098
00099
00100 enum
00101 {
00102 NONE,
00103 QUIT,
00104
00105 DELETE_WINDOW,
00106 DELETE_PIXMAP,
00107
00108 LAST_COMMAND
00109 };
00110
00111 int colormodel;
00112 BC_WindowBase *window;
00113 VFrame *frame;
00114
00115 VFrame *frame_return;
00116
00117 int id;
00118 int w;
00119 int h;
00120
00121
00122 int window_id;
00123 Display *display;
00124 Window win;
00125 #ifdef HAVE_GL
00126 GLXContext gl_context;
00127 GLXPixmap gl_pixmap;
00128 #endif
00129 };
00130
00131
00132 class BC_Synchronous : public Thread
00133 {
00134 public:
00135 BC_Synchronous();
00136 virtual ~BC_Synchronous();
00137
00138 friend class BC_WindowBase;
00139 friend class VFrame;
00140 friend class BC_PBuffer;
00141 friend class BC_Pixmap;
00142 friend class BC_Texture;
00143
00144
00145
00146 void quit();
00147
00148 void create_objects();
00149 void start();
00150 void run();
00151
00152 virtual BC_SynchronousCommand* new_command();
00153
00154
00155 virtual void handle_command(BC_SynchronousCommand *command);
00156
00157
00158
00159
00160
00161
00162
00163 void put_texture(int id, int w, int h, int components);
00164
00165
00166
00167
00168
00169 int get_texture(int w, int h, int components);
00170
00171
00172 void release_texture(int window_id, int id);
00173
00174
00175
00176
00177 unsigned int get_shader(char *source, int *got_it);
00178
00179
00180 void put_shader(unsigned int handle, char *source);
00181 void dump_shader(unsigned int handle);
00182
00183
00184 #ifdef HAVE_GL
00185
00186
00187 void put_pbuffer(int w,
00188 int h,
00189 GLXPbuffer pbuffer,
00190 GLXContext gl_context);
00191
00192
00193 GLXPbuffer get_pbuffer(int w,
00194 int h,
00195 int *window_id,
00196 GLXContext *gl_context);
00197
00198 void release_pbuffer(int window_id, GLXPbuffer pbuffer);
00199
00200
00201
00202
00203 void delete_pixmap(BC_WindowBase *window,
00204 GLXPixmap pixmap,
00205 GLXContext context);
00206 #endif
00207
00208
00209
00210
00211
00212
00213 void delete_window(BC_WindowBase *window);
00214
00215
00216 int send_command(BC_SynchronousCommand *command);
00217 void send_garbage(BC_SynchronousCommand *command);
00218
00219
00220
00221 BC_WindowBase* get_window();
00222
00223 private:
00224 void handle_command_base(BC_SynchronousCommand *command);
00225
00226
00227 void handle_garbage();
00228
00229
00230
00231 void delete_window_sync(BC_SynchronousCommand *command);
00232 void delete_pixmap_sync(BC_SynchronousCommand *command);
00233
00234 Condition *next_command;
00235 Mutex *command_lock;
00236
00237
00238
00239 Mutex *table_lock;
00240
00241
00242 int done;
00243
00244 ArrayList<BC_SynchronousCommand*> commands;
00245 int is_running;
00246
00247
00248 BC_WindowBase *current_window;
00249
00250 ArrayList<ShaderID*> shader_ids;
00251 ArrayList<TextureID*> texture_ids;
00252 ArrayList<PBufferID*> pbuffer_ids;
00253
00254 ArrayList<BC_SynchronousCommand*> garbage;
00255
00256
00257
00258 int is_pbuffer;
00259 };
00260
00261
00262
00263
00264 #endif