Panda3D
 All Classes Functions Variables Enumerations
subprocessWindowBuffer.I
1 // Filename: subprocessWindowBuffer.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: SubprocessWindowBuffer::get_x_size
18 // Access: Public
19 // Description: Returns the width of the framebuffer in pixels.
20 ////////////////////////////////////////////////////////////////////
21 inline int SubprocessWindowBuffer::
22 get_x_size() const {
23  return _x_size;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: SubprocessWindowBuffer::get_y_size
28 // Access: Public
29 // Description: Returns the height of the framebuffer in pixels.
30 ////////////////////////////////////////////////////////////////////
31 inline int SubprocessWindowBuffer::
32 get_y_size() const {
33  return _y_size;
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: SubprocessWindowBuffer::get_row_size
38 // Access: Public
39 // Description: Returns the length of a row of the framebuffer, in
40 // bytes.
41 ////////////////////////////////////////////////////////////////////
42 inline size_t SubprocessWindowBuffer::
43 get_row_size() const {
44  return _row_size;
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: SubprocessWindowBuffer::get_framebuffer_size
49 // Access: Public
50 // Description: Returns the total number of bytes in the framebuffer.
51 ////////////////////////////////////////////////////////////////////
52 inline size_t SubprocessWindowBuffer::
54  return _framebuffer_size;
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: SubprocessWindowBuffer::ready_for_read
59 // Access: Public
60 // Description: Returns true if the framebuffer data has been updated
61 // since open_read_framebuffer() was last called.
62 ////////////////////////////////////////////////////////////////////
63 inline bool SubprocessWindowBuffer::
64 ready_for_read() const {
65  return (_last_written != _last_read);
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: SubprocessWindowBuffer::ready_for_write
70 // Access: Public
71 // Description: Returns true if the framebuffer data has been read
72 // since open_write_framebuffer() was last called.
73 ////////////////////////////////////////////////////////////////////
74 inline bool SubprocessWindowBuffer::
75 ready_for_write() const {
76  return (_last_written == _last_read);
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: SubprocessWindowBuffer::open_read_framebuffer
81 // Access: Public
82 // Description: Returns a read-only pointer to the framebuffer. It
83 // is only valid to call this if ready_for_read() has
84 // returned true.
85 //
86 // You must call close_read_framebuffer() to indicate
87 // you have finished reading.
88 ////////////////////////////////////////////////////////////////////
89 inline const void *SubprocessWindowBuffer::
91  assert(ready_for_read());
92  return (void *)(this + 1);
93 }
94 
95 ////////////////////////////////////////////////////////////////////
96 // Function: SubprocessWindowBuffer::close_read_framebuffer
97 // Access: Public
98 // Description: Releases the framebuffer after a previous call to
99 // open_read_framebuffer().
100 ////////////////////////////////////////////////////////////////////
101 inline void SubprocessWindowBuffer::
103  _last_read = _last_written;
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: SubprocessWindowBuffer::open_write_framebuffer
108 // Access: Public
109 // Description: Returns a writable pointer to the framebuffer. It
110 // is only valid to call this if ready_for_write() has
111 // returned true.
112 //
113 // You must call close_write_framebuffer() to indicate
114 // you have finished writing.
115 ////////////////////////////////////////////////////////////////////
116 inline void *SubprocessWindowBuffer::
118  assert(ready_for_write());
119  return (void *)(this + 1);
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: SubprocessWindowBuffer::close_write_framebuffer
124 // Access: Public
125 // Description: Releases the framebuffer after a previous call to
126 // open_write_framebuffer().
127 ////////////////////////////////////////////////////////////////////
128 inline void SubprocessWindowBuffer::
130  ++_last_written;
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: SubprocessWindowBuffer::add_event
135 // Access: Public
136 // Description: Adds a new Event to the queue. Returns false
137 // if the queue was full.
138 ////////////////////////////////////////////////////////////////////
139 inline bool SubprocessWindowBuffer::
141  if (((_event_in + 1) % max_events) == _event_out) {
142  // The queue is full.
143  return false;
144  }
145  _events[_event_in] = event;
146  _event_in = (_event_in + 1) % max_events;
147  return true;
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function: SubprocessWindowBuffer::has_event
152 // Access: Public
153 // Description: Returns true if the queue has at least one
154 // Event to extract, false if it is empty.
155 ////////////////////////////////////////////////////////////////////
156 inline bool SubprocessWindowBuffer::
157 has_event() const {
158  return (_event_in != _event_out);
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: SubprocessWindowBuffer::get_event
163 // Access: Public
164 // Description: If the queue is nonempty, fills event with the first
165 // Event on the queue and returns true. If the queue is
166 // empty, returns false.
167 ////////////////////////////////////////////////////////////////////
168 inline bool SubprocessWindowBuffer::
170  if (_event_in == _event_out) {
171  return false;
172  }
173  event = _events[_event_out];
174  _event_out = (_event_out + 1) % max_events;
175  return true;
176 }
void close_write_framebuffer()
Releases the framebuffer after a previous call to open_write_framebuffer().
void close_read_framebuffer()
Releases the framebuffer after a previous call to open_read_framebuffer().
bool ready_for_read() const
Returns true if the framebuffer data has been updated since open_read_framebuffer() was last called...
size_t get_framebuffer_size() const
Returns the total number of bytes in the framebuffer.
int get_y_size() const
Returns the height of the framebuffer in pixels.
bool add_event(const Event &event)
Adds a new Event to the queue.
bool get_event(Event &event)
If the queue is nonempty, fills event with the first Event on the queue and returns true...
void * open_write_framebuffer()
Returns a writable pointer to the framebuffer.
int get_x_size() const
Returns the width of the framebuffer in pixels.
bool ready_for_write() const
Returns true if the framebuffer data has been read since open_write_framebuffer() was last called...
bool has_event() const
Returns true if the queue has at least one Event to extract, false if it is empty.
size_t get_row_size() const
Returns the length of a row of the framebuffer, in bytes.
const void * open_read_framebuffer()
Returns a read-only pointer to the framebuffer.