00001 // Filename: subprocessWindowBuffer.I 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 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: SubprocessWindowBuffer::get_x_size 00018 // Access: Public 00019 // Description: Returns the width of the framebuffer in pixels. 00020 //////////////////////////////////////////////////////////////////// 00021 inline int SubprocessWindowBuffer:: 00022 get_x_size() const { 00023 return _x_size; 00024 } 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: SubprocessWindowBuffer::get_y_size 00028 // Access: Public 00029 // Description: Returns the height of the framebuffer in pixels. 00030 //////////////////////////////////////////////////////////////////// 00031 inline int SubprocessWindowBuffer:: 00032 get_y_size() const { 00033 return _y_size; 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: SubprocessWindowBuffer::get_row_size 00038 // Access: Public 00039 // Description: Returns the length of a row of the framebuffer, in 00040 // bytes. 00041 //////////////////////////////////////////////////////////////////// 00042 inline size_t SubprocessWindowBuffer:: 00043 get_row_size() const { 00044 return _row_size; 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: SubprocessWindowBuffer::get_framebuffer_size 00049 // Access: Public 00050 // Description: Returns the total number of bytes in the framebuffer. 00051 //////////////////////////////////////////////////////////////////// 00052 inline size_t SubprocessWindowBuffer:: 00053 get_framebuffer_size() const { 00054 return _framebuffer_size; 00055 } 00056 00057 //////////////////////////////////////////////////////////////////// 00058 // Function: SubprocessWindowBuffer::ready_for_read 00059 // Access: Public 00060 // Description: Returns true if the framebuffer data has been updated 00061 // since open_read_framebuffer() was last called. 00062 //////////////////////////////////////////////////////////////////// 00063 inline bool SubprocessWindowBuffer:: 00064 ready_for_read() const { 00065 return (_last_written != _last_read); 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: SubprocessWindowBuffer::ready_for_write 00070 // Access: Public 00071 // Description: Returns true if the framebuffer data has been read 00072 // since open_write_framebuffer() was last called. 00073 //////////////////////////////////////////////////////////////////// 00074 inline bool SubprocessWindowBuffer:: 00075 ready_for_write() const { 00076 return (_last_written == _last_read); 00077 } 00078 00079 //////////////////////////////////////////////////////////////////// 00080 // Function: SubprocessWindowBuffer::open_read_framebuffer 00081 // Access: Public 00082 // Description: Returns a read-only pointer to the framebuffer. It 00083 // is only valid to call this if ready_for_read() has 00084 // returned true. 00085 // 00086 // You must call close_read_framebuffer() to indicate 00087 // you have finished reading. 00088 //////////////////////////////////////////////////////////////////// 00089 inline const void *SubprocessWindowBuffer:: 00090 open_read_framebuffer() { 00091 assert(ready_for_read()); 00092 return (void *)(this + 1); 00093 } 00094 00095 //////////////////////////////////////////////////////////////////// 00096 // Function: SubprocessWindowBuffer::close_read_framebuffer 00097 // Access: Public 00098 // Description: Releases the framebuffer after a previous call to 00099 // open_read_framebuffer(). 00100 //////////////////////////////////////////////////////////////////// 00101 inline void SubprocessWindowBuffer:: 00102 close_read_framebuffer() { 00103 _last_read = _last_written; 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function: SubprocessWindowBuffer::open_write_framebuffer 00108 // Access: Public 00109 // Description: Returns a writable pointer to the framebuffer. It 00110 // is only valid to call this if ready_for_write() has 00111 // returned true. 00112 // 00113 // You must call close_write_framebuffer() to indicate 00114 // you have finished writing. 00115 //////////////////////////////////////////////////////////////////// 00116 inline void *SubprocessWindowBuffer:: 00117 open_write_framebuffer() { 00118 assert(ready_for_write()); 00119 return (void *)(this + 1); 00120 } 00121 00122 //////////////////////////////////////////////////////////////////// 00123 // Function: SubprocessWindowBuffer::close_write_framebuffer 00124 // Access: Public 00125 // Description: Releases the framebuffer after a previous call to 00126 // open_write_framebuffer(). 00127 //////////////////////////////////////////////////////////////////// 00128 inline void SubprocessWindowBuffer:: 00129 close_write_framebuffer() { 00130 ++_last_written; 00131 } 00132 00133 //////////////////////////////////////////////////////////////////// 00134 // Function: SubprocessWindowBuffer::add_event 00135 // Access: Public 00136 // Description: Adds a new Event to the queue. Returns false 00137 // if the queue was full. 00138 //////////////////////////////////////////////////////////////////// 00139 inline bool SubprocessWindowBuffer:: 00140 add_event(const SubprocessWindowBuffer::Event &event) { 00141 if (((_event_in + 1) % max_events) == _event_out) { 00142 // The queue is full. 00143 return false; 00144 } 00145 _events[_event_in] = event; 00146 _event_in = (_event_in + 1) % max_events; 00147 return true; 00148 } 00149 00150 //////////////////////////////////////////////////////////////////// 00151 // Function: SubprocessWindowBuffer::has_event 00152 // Access: Public 00153 // Description: Returns true if the queue has at least one 00154 // Event to extract, false if it is empty. 00155 //////////////////////////////////////////////////////////////////// 00156 inline bool SubprocessWindowBuffer:: 00157 has_event() const { 00158 return (_event_in != _event_out); 00159 } 00160 00161 //////////////////////////////////////////////////////////////////// 00162 // Function: SubprocessWindowBuffer::get_event 00163 // Access: Public 00164 // Description: If the queue is nonempty, fills event with the first 00165 // Event on the queue and returns true. If the queue is 00166 // empty, returns false. 00167 //////////////////////////////////////////////////////////////////// 00168 inline bool SubprocessWindowBuffer:: 00169 get_event(SubprocessWindowBuffer::Event &event) { 00170 if (_event_in == _event_out) { 00171 return false; 00172 } 00173 event = _events[_event_out]; 00174 _event_out = (_event_out + 1) % max_events; 00175 return true; 00176 }