Panda3D
subprocessWindow.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file subprocessWindow.h
10  * @author drose
11  * @date 2009-07-11
12  */
13 
14 #ifndef SUBPROCESSWINDOW_H
15 #define SUBPROCESSWINDOW_H
16 
17 #include "pandabase.h"
18 
19 // For now, a simple trigger whether to enable the subprocess window support.
20 // We only build it on OSX, because this is (presently) the only case where
21 // it's useful.
22 #ifdef IS_OSX
23 #define SUPPORT_SUBPROCESS_WINDOW 1
24 #else
25 #undef SUPPORT_SUBPROCESS_WINDOW
26 #endif
27 
28 #ifdef SUPPORT_SUBPROCESS_WINDOW
29 
30 #include "graphicsWindow.h"
31 #include "graphicsBuffer.h"
32 #include "texture.h"
33 #include "subprocessWindowBuffer.h"
34 #include "filename.h"
35 
36 /**
37  * This is a special "window" that actually renders to an offscreen buffer,
38  * copies the pixels to RAM, and then ships them to a parent process via
39  * shared memory for rendering to the window.
40  *
41  * This whole nonsense is necessary because OSX doesn't allow child processes
42  * to draw to, or attach windows to, windows created in the parent process.
43  * There's a rumor that 10.6 fixes this nonsense; this will remain to be seen.
44  */
45 class SubprocessWindow : public GraphicsWindow {
46 public:
47  SubprocessWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
48  const std::string &name,
49  const FrameBufferProperties &fb_prop,
50  const WindowProperties &win_prop,
51  int flags,
53  GraphicsOutput *host);
54  virtual ~SubprocessWindow();
55 
56  virtual void process_events();
57 
58  virtual bool begin_frame(FrameMode mode, Thread *current_thread);
59  virtual void end_frame(FrameMode mode, Thread *current_thread);
60  virtual void begin_flip();
61 
62  virtual void set_properties_now(WindowProperties &properties);
63 
64 protected:
65  virtual void close_window();
66  virtual bool open_window();
67 
68 private:
69  void internal_close_window();
70  bool internal_open_window();
71 
72  ButtonHandle translate_key(int &keycode, int os_code, unsigned int flags) const;
73  void transition_button(unsigned int flag, ButtonHandle button);
74 
75 private:
76  PT(GraphicsBuffer) _buffer;
77  PT(Texture) _texture;
78  PT(GraphicsWindowInputDevice) _input;
79 
80  int _fd;
81  size_t _mmap_size;
82  Filename _filename;
83  SubprocessWindowBuffer *_swbuffer;
84 
85  unsigned int _last_event_flags;
86 
87 public:
88  static TypeHandle get_class_type() {
89  return _type_handle;
90  }
91  static void init_type() {
92  GraphicsWindow::init_type();
93  register_type(_type_handle, "SubprocessWindow",
94  GraphicsWindow::get_class_type());
95  }
96  virtual TypeHandle get_type() const {
97  return get_class_type();
98  }
99  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
100 
101 private:
102  static TypeHandle _type_handle;
103 };
104 
105 #include "subprocessWindow.I"
106 
107 #endif // SUPPORT_SUBPROCESS_WINDOW
108 
109 #endif
virtual void process_events()
Do whatever processing is necessary to ensure that the window responds to user events.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:71
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:26
A container for the various kinds of properties we might ask to have on a graphics window before we o...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An offscreen buffer for rendering into.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:52
This is a special class that is designed to faciliate SubprocessWindow.
This is a virtual input device that represents the keyboard and mouse pair that is associated with a ...
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:46
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:81
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.