Panda3D
 All Classes Functions Variables Enumerations
subprocessWindow.h
1 // Filename: subprocessWindow.h
2 // Created by: drose (11Jul09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef SUBPROCESSWINDOW_H
16 #define SUBPROCESSWINDOW_H
17 
18 #include "pandabase.h"
19 
20 // For now, a simple trigger whether to enable the subprocess window
21 // support. We only build it on OSX, because this is (presently) the
22 // only case where it's useful.
23 #ifdef IS_OSX
24 #define SUPPORT_SUBPROCESS_WINDOW 1
25 #else
26 #undef SUPPORT_SUBPROCESS_WINDOW
27 #endif
28 
29 #ifdef SUPPORT_SUBPROCESS_WINDOW
30 
31 #include "graphicsWindow.h"
32 #include "graphicsBuffer.h"
33 #include "texture.h"
34 #include "subprocessWindowBuffer.h"
35 #include "filename.h"
36 
37 ////////////////////////////////////////////////////////////////////
38 // Class : SubprocessWindow
39 // Description : This is a special "window" that actually renders to
40 // an offscreen buffer, copies the pixels to RAM, and
41 // then ships them to a parent process via shared memory
42 // for rendering to the window.
43 //
44 // This whole nonsense is necessary because OSX doesn't
45 // allow child processes to draw to, or attach windows
46 // to, windows created in the parent process. There's a
47 // rumor that 10.6 fixes this nonsense; this will remain
48 // to be seen.
49 ////////////////////////////////////////////////////////////////////
50 class SubprocessWindow : public GraphicsWindow {
51 public:
52  SubprocessWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
53  const string &name,
54  const FrameBufferProperties &fb_prop,
55  const WindowProperties &win_prop,
56  int flags,
58  GraphicsOutput *host);
59  virtual ~SubprocessWindow();
60 
61  virtual void process_events();
62 
63  virtual bool begin_frame(FrameMode mode, Thread *current_thread);
64  virtual void end_frame(FrameMode mode, Thread *current_thread);
65  virtual void begin_flip();
66 
67  virtual void set_properties_now(WindowProperties &properties);
68 
69 protected:
70  virtual void close_window();
71  virtual bool open_window();
72 
73 private:
74  void internal_close_window();
75  bool internal_open_window();
76 
77  ButtonHandle translate_key(int &keycode, int os_code, unsigned int flags) const;
78  void transition_button(unsigned int flag, ButtonHandle button);
79 
80 private:
81  PT(GraphicsBuffer) _buffer;
82  PT(Texture) _texture;
83 
84  int _fd;
85  size_t _mmap_size;
86  Filename _filename;
87  SubprocessWindowBuffer *_swbuffer;
88 
89  unsigned int _last_event_flags;
90 
91 public:
92  static TypeHandle get_class_type() {
93  return _type_handle;
94  }
95  static void init_type() {
96  GraphicsWindow::init_type();
97  register_type(_type_handle, "SubprocessWindow",
98  GraphicsWindow::get_class_type());
99  }
100  virtual TypeHandle get_type() const {
101  return get_class_type();
102  }
103  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
104 
105 private:
106  static TypeHandle _type_handle;
107 };
108 
109 #include "subprocessWindow.I"
110 
111 #endif // SUPPORT_SUBPROCESS_WINDOW
112 
113 #endif
114 
virtual void process_events()
Do whatever processing is necessary to ensure that the window responds to user events.
virtual void set_properties_now(WindowProperties &properties)
Applies the requested set of properties to the window, if possible, for instance to request a change ...
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
virtual void end_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread after rendering is completed for a given frame...
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
A container for the various kinds of properties we might ask to have on a graphics window before we o...
An offscreen buffer for rendering into.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
This is a special class that is designed to faciliate SubprocessWindow.
This is a base class for the various different classes that represent the result of a frame of render...
A thread; that is, a lightweight process.
Definition: thread.h:51
virtual void begin_flip()
This function will be called within the draw thread after end_frame() has been called on all windows...
Encapsulates all the communication with a particular instance of a given rendering backend...
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
virtual bool begin_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread before beginning rendering for a given frame...