Panda3D

subprocessWindow.h

00001 // Filename: subprocessWindow.h
00002 // Created by:  drose (11Jul09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef SUBPROCESSWINDOW_H
00016 #define SUBPROCESSWINDOW_H
00017 
00018 #include "pandabase.h"
00019 
00020 // For now, a simple trigger whether to enable the subprocess window
00021 // support.  We only build it on OSX, because this is (presently) the
00022 // only case where it's useful.
00023 #ifdef IS_OSX
00024 #define SUPPORT_SUBPROCESS_WINDOW 1
00025 #else
00026 #undef SUPPORT_SUBPROCESS_WINDOW
00027 #endif
00028 
00029 #ifdef SUPPORT_SUBPROCESS_WINDOW
00030 
00031 #include "graphicsWindow.h"
00032 #include "graphicsBuffer.h"
00033 #include "texture.h"
00034 #include "subprocessWindowBuffer.h"
00035 #include "filename.h"
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //       Class : SubprocessWindow
00039 // Description : This is a special "window" that actually renders to
00040 //               an offscreen buffer, copies the pixels to RAM, and
00041 //               then ships them to a parent process via shared memory
00042 //               for rendering to the window.
00043 //
00044 //               This whole nonsense is necessary because OSX doesn't
00045 //               allow child processes to draw to, or attach windows
00046 //               to, windows created in the parent process.  There's a
00047 //               rumor that 10.6 fixes this nonsense; this will remain
00048 //               to be seen.
00049 ////////////////////////////////////////////////////////////////////
00050 class SubprocessWindow : public GraphicsWindow {
00051 public:
00052   SubprocessWindow(GraphicsEngine *engine, GraphicsPipe *pipe, 
00053                    const string &name,
00054                    const FrameBufferProperties &fb_prop,
00055                    const WindowProperties &win_prop,
00056                    int flags,
00057                    GraphicsStateGuardian *gsg,
00058                    GraphicsOutput *host);
00059   virtual ~SubprocessWindow();
00060 
00061   virtual void process_events();
00062 
00063   virtual bool begin_frame(FrameMode mode, Thread *current_thread);
00064   virtual void end_frame(FrameMode mode, Thread *current_thread);
00065   virtual void begin_flip();
00066 
00067   virtual void set_properties_now(WindowProperties &properties);
00068 
00069 protected:
00070   virtual void close_window();
00071   virtual bool open_window();
00072 
00073 private:
00074   void internal_close_window();
00075   bool internal_open_window();
00076 
00077   ButtonHandle translate_key(int &keycode, int os_code, unsigned int flags) const;
00078   void transition_button(unsigned int flag, ButtonHandle button);
00079 
00080 private:
00081   PT(GraphicsBuffer) _buffer;
00082   PT(Texture) _texture;
00083 
00084   int _fd;
00085   size_t _mmap_size;
00086   Filename _filename;
00087   SubprocessWindowBuffer *_swbuffer;
00088 
00089   unsigned int _last_event_flags;
00090 
00091 public:
00092   static TypeHandle get_class_type() {
00093     return _type_handle;
00094   }
00095   static void init_type() {
00096     GraphicsWindow::init_type();
00097     register_type(_type_handle, "SubprocessWindow",
00098                   GraphicsWindow::get_class_type());
00099   }
00100   virtual TypeHandle get_type() const {
00101     return get_class_type();
00102   }
00103   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00104 
00105 private:
00106   static TypeHandle _type_handle;
00107 };
00108 
00109 #include "subprocessWindow.I"
00110 
00111 #endif  // SUPPORT_SUBPROCESS_WINDOW
00112 
00113 #endif
00114 
 All Classes Functions Variables Enumerations