Panda3D
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
SubprocessWindowBuffer Class Reference

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. More...
 
void close_read_framebuffer ()
 Releases the framebuffer after a previous call to open_read_framebuffer(). More...
 
void close_write_framebuffer ()
 Releases the framebuffer after a previous call to open_write_framebuffer(). More...
 
bool get_event (Event &event)
 If the queue is nonempty, fills event with the first Event on the queue and returns true. More...
 
size_t get_framebuffer_size () const
 Returns the total number of bytes in the framebuffer. More...
 
size_t get_row_size () const
 Returns the length of a row of the framebuffer, in bytes. More...
 
int get_x_size () const
 Returns the width of the framebuffer in pixels. More...
 
int get_y_size () const
 Returns the height of the framebuffer in pixels. More...
 
bool has_event () const
 Returns true if the queue has at least one Event to extract, false if it is empty. More...
 
const void * open_read_framebuffer ()
 Returns a read-only pointer to the framebuffer. More...
 
void * open_write_framebuffer ()
 Returns a writable pointer to the framebuffer. More...
 
bool ready_for_read () const
 Returns true if the framebuffer data has been updated since open_read_framebuffer() was last called. More...
 
bool ready_for_write () const
 Returns true if the framebuffer data has been read since open_write_framebuffer() was last called. More...
 
bool verify_magic_number () const
 Returns true if the buffer's magic number matches, false otherwise. More...
 

Static Public Member Functions

static void close_buffer (int fd, size_t mmap_size, const std::string &filename, SubprocessWindowBuffer *buffer)
 Closes a buffer object created via a previous call to open_buffer(). More...
 
static void destroy_buffer (int fd, size_t mmap_size, const std::string &filename, SubprocessWindowBuffer *buffer)
 Destroys a buffer object created via a previous call to new_buffer(). More...
 
static SubprocessWindowBuffernew_buffer (int &fd, size_t &mmap_size, std::string &filename, int x_size, int y_size)
 Call this method to create a new buffer in shared memory space. More...
 
static SubprocessWindowBufferopen_buffer (int &fd, size_t &mmap_size, const std::string &filename)
 Call this method to open a reference to an existing buffer in shared memory space. More...
 

Detailed Description

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 35 of file subprocessWindowBuffer.h.

Member Function Documentation

◆ add_event()

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 110 of file subprocessWindowBuffer.I.

◆ close_buffer()

void SubprocessWindowBuffer::close_buffer ( int  fd,
size_t  mmap_size,
const std::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 237 of file subprocessWindowBuffer.cxx.

Referenced by destroy_buffer().

◆ close_read_framebuffer()

void SubprocessWindowBuffer::close_read_framebuffer ( )
inline

Releases the framebuffer after a previous call to open_read_framebuffer().

Definition at line 81 of file subprocessWindowBuffer.I.

◆ close_write_framebuffer()

void SubprocessWindowBuffer::close_write_framebuffer ( )
inline

Releases the framebuffer after a previous call to open_write_framebuffer().

Definition at line 102 of file subprocessWindowBuffer.I.

◆ destroy_buffer()

void SubprocessWindowBuffer::destroy_buffer ( int  fd,
size_t  mmap_size,
const std::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 140 of file subprocessWindowBuffer.cxx.

References close_buffer().

◆ get_event()

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 134 of file subprocessWindowBuffer.I.

◆ get_framebuffer_size()

size_t SubprocessWindowBuffer::get_framebuffer_size ( ) const
inline

Returns the total number of bytes in the framebuffer.

Definition at line 42 of file subprocessWindowBuffer.I.

◆ get_row_size()

size_t SubprocessWindowBuffer::get_row_size ( ) const
inline

Returns the length of a row of the framebuffer, in bytes.

Definition at line 34 of file subprocessWindowBuffer.I.

◆ get_x_size()

int SubprocessWindowBuffer::get_x_size ( ) const
inline

Returns the width of the framebuffer in pixels.

Definition at line 18 of file subprocessWindowBuffer.I.

◆ get_y_size()

int SubprocessWindowBuffer::get_y_size ( ) const
inline

Returns the height of the framebuffer in pixels.

Definition at line 26 of file subprocessWindowBuffer.I.

◆ has_event()

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 125 of file subprocessWindowBuffer.I.

◆ new_buffer()

SubprocessWindowBuffer * SubprocessWindowBuffer::new_buffer ( int &  fd,
size_t &  mmap_size,
std::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 95 of file subprocessWindowBuffer.cxx.

◆ open_buffer()

SubprocessWindowBuffer * SubprocessWindowBuffer::open_buffer ( int &  fd,
size_t &  mmap_size,
const std::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 160 of file subprocessWindowBuffer.cxx.

References verify_magic_number().

◆ open_read_framebuffer()

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 72 of file subprocessWindowBuffer.I.

References ready_for_read().

◆ open_write_framebuffer()

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 93 of file subprocessWindowBuffer.I.

References ready_for_write().

◆ ready_for_read()

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 51 of file subprocessWindowBuffer.I.

Referenced by open_read_framebuffer().

◆ ready_for_write()

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 60 of file subprocessWindowBuffer.I.

Referenced by open_write_framebuffer().

◆ verify_magic_number()

bool SubprocessWindowBuffer::verify_magic_number ( ) const

Returns true if the buffer's magic number matches, false otherwise.

Definition at line 247 of file subprocessWindowBuffer.cxx.

Referenced by open_buffer().


The documentation for this class was generated from the following files: