Panda3D
|
This is a special class that is designed to faciliate SubprocessWindow. More...
#include "subprocessWindowBuffer.h"
Classes | |
class | Event |
Public Types | |
enum | EventFlags { EF_has_mouse = 0x0001, EF_mouse_position = 0x0002, EF_shift_held = 0x0004, EF_control_held = 0x0008, EF_alt_held = 0x0010, EF_meta_held = 0x0020, EF_caps_lock = 0x0040 } |
enum | EventSource { ES_none, ES_mouse, ES_keyboard } |
enum | EventType { ET_none, ET_button_down, ET_button_up, ET_button_again } |
Public Member Functions | |
bool | add_event (const Event &event) |
Adds a new Event to the queue. | |
void | close_read_framebuffer () |
Releases the framebuffer after a previous call to open_read_framebuffer(). | |
void | close_write_framebuffer () |
Releases the framebuffer after a previous call to open_write_framebuffer(). | |
bool | get_event (Event &event) |
If the queue is nonempty, fills event with the first Event on the queue and returns true. | |
size_t | get_framebuffer_size () const |
Returns the total number of bytes in the framebuffer. | |
size_t | get_row_size () const |
Returns the length of a row of the framebuffer, in bytes. | |
int | get_x_size () const |
Returns the width of the framebuffer in pixels. | |
int | get_y_size () const |
Returns the height of the framebuffer in pixels. | |
bool | has_event () const |
Returns true if the queue has at least one Event to extract, false if it is empty. | |
const void * | open_read_framebuffer () |
Returns a read-only pointer to the framebuffer. | |
void * | open_write_framebuffer () |
Returns a writable pointer to the framebuffer. | |
bool | ready_for_read () const |
Returns true if the framebuffer data has been updated since open_read_framebuffer() was last called. | |
bool | ready_for_write () const |
Returns true if the framebuffer data has been read since open_write_framebuffer() was last called. | |
bool | verify_magic_number () const |
Returns true if the buffer's magic number matches, false otherwise. | |
Static Public Member Functions | |
static void | close_buffer (int fd, size_t mmap_size, const string &filename, SubprocessWindowBuffer *buffer) |
Closes a buffer object created via a previous call to open_buffer(). | |
static void | destroy_buffer (int fd, size_t mmap_size, const string &filename, SubprocessWindowBuffer *buffer) |
Destroys a buffer object created via a previous call to new_buffer(). | |
static SubprocessWindowBuffer * | new_buffer (int &fd, size_t &mmap_size, string &filename, int x_size, int y_size) |
Call this method to create a new buffer in shared memory space. | |
static SubprocessWindowBuffer * | open_buffer (int &fd, size_t &mmap_size, const string &filename) |
Call this method to open a reference to an existing buffer in shared memory space. |
This is a special class that is designed to faciliate SubprocessWindow.
It's intended to be allocated within a shared memory buffer, and it contains space for a framebuffer image to be stored for transferring between processes, as well as appropriate synchronization primitives.
It's designed to be compiled outside of Panda, so that code that doesn't link with Panda (in particular, the Panda3D plugin core API) may still link with this and use it.
At the moment, and maybe indefinitely, it is only compiled on OSX, and only when we are building support for the plugin; because it is only needed then.
Definition at line 42 of file subprocessWindowBuffer.h.
bool SubprocessWindowBuffer::add_event | ( | const Event & | event | ) | [inline] |
Adds a new Event to the queue.
Returns false if the queue was full.
Definition at line 140 of file subprocessWindowBuffer.I.
void SubprocessWindowBuffer::close_buffer | ( | int | fd, |
size_t | mmap_size, | ||
const string & | filename, | ||
SubprocessWindowBuffer * | buffer | ||
) | [static] |
Closes a buffer object created via a previous call to open_buffer().
This unmaps the shared memory and closes the file descriptor, but does not molest the shared buffer itself.
Definition at line 261 of file subprocessWindowBuffer.cxx.
Referenced by destroy_buffer().
void SubprocessWindowBuffer::close_read_framebuffer | ( | ) | [inline] |
Releases the framebuffer after a previous call to open_read_framebuffer().
Definition at line 102 of file subprocessWindowBuffer.I.
void SubprocessWindowBuffer::close_write_framebuffer | ( | ) | [inline] |
Releases the framebuffer after a previous call to open_write_framebuffer().
Definition at line 129 of file subprocessWindowBuffer.I.
void SubprocessWindowBuffer::destroy_buffer | ( | int | fd, |
size_t | mmap_size, | ||
const string & | filename, | ||
SubprocessWindowBuffer * | buffer | ||
) | [static] |
Destroys a buffer object created via a previous call to new_buffer().
This destructs objects within the buffer, unmaps the shared memory, and closes the file descriptor.
Definition at line 155 of file subprocessWindowBuffer.cxx.
References close_buffer().
bool SubprocessWindowBuffer::get_event | ( | SubprocessWindowBuffer::Event & | event | ) | [inline] |
If the queue is nonempty, fills event with the first Event on the queue and returns true.
If the queue is empty, returns false.
Definition at line 169 of file subprocessWindowBuffer.I.
size_t SubprocessWindowBuffer::get_framebuffer_size | ( | ) | const [inline] |
Returns the total number of bytes in the framebuffer.
Definition at line 53 of file subprocessWindowBuffer.I.
size_t SubprocessWindowBuffer::get_row_size | ( | ) | const [inline] |
Returns the length of a row of the framebuffer, in bytes.
Definition at line 43 of file subprocessWindowBuffer.I.
int SubprocessWindowBuffer::get_x_size | ( | ) | const [inline] |
Returns the width of the framebuffer in pixels.
Definition at line 22 of file subprocessWindowBuffer.I.
int SubprocessWindowBuffer::get_y_size | ( | ) | const [inline] |
Returns the height of the framebuffer in pixels.
Definition at line 32 of file subprocessWindowBuffer.I.
bool SubprocessWindowBuffer::has_event | ( | ) | const [inline] |
Returns true if the queue has at least one Event to extract, false if it is empty.
Definition at line 157 of file subprocessWindowBuffer.I.
SubprocessWindowBuffer * SubprocessWindowBuffer::new_buffer | ( | int & | fd, |
size_t & | mmap_size, | ||
string & | filename, | ||
int | x_size, | ||
int | y_size | ||
) | [static] |
Call this method to create a new buffer in shared memory space.
Supply the desired size of the window.
This method will create the required shared-memory buffer and return a SubprocessWindowBuffer allocated within that shared memory, or NULL if there is a failure allocating sufficient shared memory.
It also creates a temporary file on disk and returns fd, mmap_size, and filename, which the caller must retain and eventually pass to destroy_buffer(). The filename should be passed to the child process to open with open_buffer().
Definition at line 107 of file subprocessWindowBuffer.cxx.
SubprocessWindowBuffer * SubprocessWindowBuffer::open_buffer | ( | int & | fd, |
size_t & | mmap_size, | ||
const string & | filename | ||
) | [static] |
Call this method to open a reference to an existing buffer in shared memory space.
Supply the temporary filename returned by new_buffer(), above (presumably from the parent process).
This method will mmap the required shared-memory buffer and return a SubprocessWindowBuffer allocated within that shared memory, or NULL if there is some failure. The caller must retain fd, mmap_size, and filename and eventually pass all three to close_buffer().
Definition at line 180 of file subprocessWindowBuffer.cxx.
References verify_magic_number().
const void * SubprocessWindowBuffer::open_read_framebuffer | ( | ) | [inline] |
Returns a read-only pointer to the framebuffer.
It is only valid to call this if ready_for_read() has returned true.
You must call close_read_framebuffer() to indicate you have finished reading.
Definition at line 90 of file subprocessWindowBuffer.I.
References ready_for_read().
void * SubprocessWindowBuffer::open_write_framebuffer | ( | ) | [inline] |
Returns a writable pointer to the framebuffer.
It is only valid to call this if ready_for_write() has returned true.
You must call close_write_framebuffer() to indicate you have finished writing.
Definition at line 117 of file subprocessWindowBuffer.I.
References ready_for_write().
bool SubprocessWindowBuffer::ready_for_read | ( | ) | const [inline] |
Returns true if the framebuffer data has been updated since open_read_framebuffer() was last called.
Definition at line 64 of file subprocessWindowBuffer.I.
Referenced by open_read_framebuffer().
bool SubprocessWindowBuffer::ready_for_write | ( | ) | const [inline] |
Returns true if the framebuffer data has been read since open_write_framebuffer() was last called.
Definition at line 75 of file subprocessWindowBuffer.I.
Referenced by open_write_framebuffer().
bool SubprocessWindowBuffer::verify_magic_number | ( | ) | const |
Returns true if the buffer's magic number matches, false otherwise.
Definition at line 274 of file subprocessWindowBuffer.cxx.
Referenced by open_buffer().