move subprocess_window into new WindowHandle structure

This commit is contained in:
David Rose 2009-10-01 19:10:14 +00:00
parent 5d5a131026
commit ee1f03abe7
8 changed files with 97 additions and 111 deletions

View File

@ -18,6 +18,7 @@
#include "graphicsEngine.h" #include "graphicsEngine.h"
#include "config_display.h" #include "config_display.h"
#include "nativeWindowHandle.h"
TypeHandle SubprocessWindow::_type_handle; TypeHandle SubprocessWindow::_type_handle;
@ -244,10 +245,22 @@ begin_flip() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void SubprocessWindow:: void SubprocessWindow::
set_properties_now(WindowProperties &properties) { set_properties_now(WindowProperties &properties) {
if (properties.has_subprocess_window() && Filename filename;
properties.get_subprocess_window() != _filename) { WindowHandle *window_handle = properties.get_parent_window();
if (window_handle != NULL) {
WindowHandle::OSHandle *os_handle = window_handle->get_os_handle();
if (os_handle != NULL) {
if (os_handle->is_of_type(NativeWindowHandle::SubprocessHandle::get_class_type())) {
NativeWindowHandle::SubprocessHandle *subprocess_handle = DCAST(NativeWindowHandle::SubprocessHandle, os_handle);
filename = subprocess_handle->get_filename();
}
}
}
if (!filename.empty() && filename != _filename) {
// We're changing the subprocess buffer filename; that means we // We're changing the subprocess buffer filename; that means we
// might as well completely close and re-open the window. // might as well completely close and re-open the window.
display_cat.info() << "Re-opening SubprocessWindow\n";
internal_close_window(); internal_close_window();
_properties.add_properties(properties); _properties.add_properties(properties);
@ -265,9 +278,9 @@ set_properties_now(WindowProperties &properties) {
return; return;
} }
if (properties.has_subprocess_window()) { if (properties.has_parent_window()) {
// Redundant subprocess specification. // Redundant parent-window specification.
properties.clear_subprocess_window(); properties.clear_parent_window();
} }
} }
@ -371,7 +384,24 @@ internal_open_window() {
} }
_gsg = _buffer->get_gsg(); _gsg = _buffer->get_gsg();
_filename = _properties.get_subprocess_window();
WindowHandle *window_handle = _properties.get_parent_window();
if (window_handle != NULL) {
WindowHandle::OSHandle *os_handle = window_handle->get_os_handle();
if (os_handle != NULL) {
if (os_handle->is_of_type(NativeWindowHandle::SubprocessHandle::get_class_type())) {
NativeWindowHandle::SubprocessHandle *subprocess_handle = DCAST(NativeWindowHandle::SubprocessHandle, os_handle);
_filename = subprocess_handle->get_filename();
}
}
}
if (_filename.empty()) {
_is_valid = false;
display_cat.error()
<< "No filename given to SubprocessWindow.\n";
return false;
}
_swbuffer = SubprocessWindowBuffer::open_buffer _swbuffer = SubprocessWindowBuffer::open_buffer
(_fd, _mmap_size, _filename.to_os_specific()); (_fd, _mmap_size, _filename.to_os_specific());
@ -387,6 +417,9 @@ internal_open_window() {
return false; return false;
} }
display_cat.error()
<< "SubprocessWindow reading " << _filename << "\n";
return true; return true;
} }

View File

@ -32,13 +32,10 @@
// particularly important when running embedded in a // particularly important when running embedded in a
// browser. // browser.
// //
// To create a WindowHandle, you would typically call // To create a WindowHandle, you would usually call one
// GraphicsPipe::make_window_handle, for the particular // of the NativeWindowHandle::make_*() methods,
// GraphicsPipe that you have constructed. (Each // depending on the kind of native window handle object
// OS-specific GraphicsPipe has a make_window_handle() // you already have.
// method that receives an OS-specific window handle,
// whatever that means for a particular OS, and creates
// a WindowHandle object wrapping it.)
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_DISPLAY WindowHandle : public TypedReferenceCount { class EXPCL_PANDA_DISPLAY WindowHandle : public TypedReferenceCount {
PUBLISHED: PUBLISHED:

View File

@ -855,70 +855,6 @@ clear_parent_window() {
_parent_window = NULL; _parent_window = NULL;
} }
////////////////////////////////////////////////////////////////////
// Function: WindowProperties::set_subprocess_window
// Access: Published
// Description: Specifies that the window should be created as a
// "subprocess window", which is a special concept
// needed on OSX, to support windows that may run in a
// subprocess and communicate the output of their
// rendering to a parent process.
//
// To use it, create a SubprocessWindowBuffer in the
// parent process, pass the resulting temporary filename
// to the child process, and set that filename here
// before opening a window. Panda will open a
// SubprocessWindow instead of a normal window; and that
// class will take the output of the rendering and write
// it to the SubprocessWindowBuffer for the parent
// process to extract.
//
// This is particularly useful for implementing the web
// browser plugin on OSX, which requires exactly this
// sort of process isolation in order to render to the
// browser page.
//
// This feature is not currently available on other
// platforms (and they have no need of it).
////////////////////////////////////////////////////////////////////
INLINE void WindowProperties::
set_subprocess_window(const Filename &filename) {
_subprocess_window = filename;
_specified |= S_subprocess_window;
}
////////////////////////////////////////////////////////////////////
// Function: WindowProperties::get_subprocess_window
// Access: Published
// Description: Returns the filename specified to set_subprocess_window().
////////////////////////////////////////////////////////////////////
INLINE const Filename &WindowProperties::
get_subprocess_window() const {
return _subprocess_window;
}
////////////////////////////////////////////////////////////////////
// Function: WindowProperties::has_subprocess_window
// Access: Published
// Description: Returns true if set_subprocess_window() was set.
////////////////////////////////////////////////////////////////////
INLINE bool WindowProperties::
has_subprocess_window() const {
return ((_specified & S_subprocess_window) != 0);
}
////////////////////////////////////////////////////////////////////
// Function: WindowProperties::clear_subprocess_window
// Access: Published
// Description: Removes the subprocess_window specification from the
// properties.
////////////////////////////////////////////////////////////////////
INLINE void WindowProperties::
clear_subprocess_window() {
_specified &= ~S_subprocess_window;
_subprocess_window = Filename();
}
INLINE ostream & INLINE ostream &
operator << (ostream &out, const WindowProperties &properties) { operator << (ostream &out, const WindowProperties &properties) {

View File

@ -47,7 +47,6 @@ operator = (const WindowProperties &copy) {
_flags = copy._flags; _flags = copy._flags;
_mouse_mode = copy._mouse_mode; _mouse_mode = copy._mouse_mode;
_parent_window = copy._parent_window; _parent_window = copy._parent_window;
_subprocess_window = copy._subprocess_window;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -87,10 +86,9 @@ get_config_properties() {
} }
props.set_title(window_title); props.set_title(window_title);
if (parent_window_handle.get_value() != 0) { if (parent_window_handle.get_value() != 0) {
props.set_parent_window(parent_window_handle); props.set_parent_window(NativeWindowHandle::make_int(parent_window_handle));
} } else if (!subprocess_window.empty()) {
if (!subprocess_window.empty()) { props.set_parent_window(NativeWindowHandle::make_subprocess(subprocess_window));
props.set_subprocess_window(subprocess_window);
} }
props.set_mouse_mode(M_absolute); props.set_mouse_mode(M_absolute);
@ -179,8 +177,7 @@ operator == (const WindowProperties &other) const {
_icon_filename == other._icon_filename && _icon_filename == other._icon_filename &&
_cursor_filename == other._cursor_filename && _cursor_filename == other._cursor_filename &&
_mouse_mode == other._mouse_mode && _mouse_mode == other._mouse_mode &&
_parent_window == other._parent_window && _parent_window == other._parent_window);
_subprocess_window == other._subprocess_window);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -203,8 +200,7 @@ clear() {
_z_order = Z_normal; _z_order = Z_normal;
_flags = 0; _flags = 0;
_mouse_mode = M_absolute; _mouse_mode = M_absolute;
_parent_window = 0; _parent_window = NULL;
_subprocess_window = Filename();
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -290,9 +286,6 @@ add_properties(const WindowProperties &other) {
if (other.has_parent_window()) { if (other.has_parent_window()) {
set_parent_window(other.get_parent_window()); set_parent_window(other.get_parent_window());
} }
if (other.has_subprocess_window()) {
set_subprocess_window(other.get_subprocess_window());
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -350,12 +343,12 @@ output(ostream &out) const {
out << get_mouse_mode() << " "; out << get_mouse_mode() << " ";
} }
if (has_parent_window()) { if (has_parent_window()) {
out << "parent:" << get_parent_window() << " "; if (get_parent_window() == NULL) {
out << "parent:none ";
} else {
out << "parent:" << *get_parent_window() << " ";
}
} }
if (has_subprocess_window()) {
out << "subprocess_window:" << get_subprocess_window() << " ";
}
} }
ostream & ostream &

View File

@ -141,11 +141,6 @@ PUBLISHED:
INLINE bool has_parent_window() const; INLINE bool has_parent_window() const;
INLINE void clear_parent_window(); INLINE void clear_parent_window();
INLINE void set_subprocess_window(const Filename &filename);
INLINE const Filename &get_subprocess_window() const;
INLINE bool has_subprocess_window() const;
INLINE void clear_subprocess_window();
void add_properties(const WindowProperties &other); void add_properties(const WindowProperties &other);
void output(ostream &out) const; void output(ostream &out) const;
@ -171,7 +166,6 @@ private:
S_mouse_mode = 0x02000, S_mouse_mode = 0x02000,
S_parent_window = 0x04000, S_parent_window = 0x04000,
S_raw_mice = 0x08000, S_raw_mice = 0x08000,
S_subprocess_window = 0x10000,
}; };
// This bitmask represents the true/false settings for various // This bitmask represents the true/false settings for various
@ -200,7 +194,6 @@ private:
ZOrder _z_order; ZOrder _z_order;
unsigned int _flags; unsigned int _flags;
PT(WindowHandle) _parent_window; PT(WindowHandle) _parent_window;
Filename _subprocess_window;
static WindowProperties *_default_properties; static WindowProperties *_default_properties;
}; };

View File

@ -16,8 +16,7 @@
#include "osxGraphicsStateGuardian.h" #include "osxGraphicsStateGuardian.h"
#include "pnmImage.h" #include "pnmImage.h"
#include "subprocessWindow.h" #include "subprocessWindow.h"
#include "nativeWindowHandle.h"
TypeHandle osxGraphicsPipe::_type_handle; TypeHandle osxGraphicsPipe::_type_handle;
@ -234,12 +233,19 @@ make_output(const string &name,
((flags&BF_can_bind_every)!=0)) { ((flags&BF_can_bind_every)!=0)) {
return NULL; return NULL;
} }
WindowHandle *window_handle = win_prop.get_parent_window();
if (window_handle != NULL) {
osxdisplay_cat.info()
<< "Got parent_window " << *window_handle << "\n";
#ifdef SUPPORT_SUBPROCESS_WINDOW #ifdef SUPPORT_SUBPROCESS_WINDOW
if (win_prop.has_subprocess_window()) { WindowHandle::OSHandle *os_handle = window_handle->get_os_handle();
return new SubprocessWindow(engine, this, name, fb_prop, win_prop, if (os_handle != NULL &&
flags, gsg, host); os_handle->is_of_type(NativeWindowHandle::SubprocessHandle::get_class_type())) {
} return new SubprocessWindow(engine, this, name, fb_prop, win_prop,
flags, gsg, host);
}
#endif // SUPPORT_SUBPROCESS_WINDOW #endif // SUPPORT_SUBPROCESS_WINDOW
}
return new osxGraphicsWindow(engine, this, name, fb_prop, win_prop, return new osxGraphicsWindow(engine, this, name, fb_prop, win_prop,
flags, gsg, host); flags, gsg, host);
} }

View File

@ -1444,7 +1444,27 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr,
PIXEL *fo = _c->zb->pbuf + xo + yo * _c->zb->linesize / PSZB; PIXEL *fo = _c->zb->pbuf + xo + yo * _c->zb->linesize / PSZB;
for (int y = 0; y < h; ++y) { for (int y = 0; y < h; ++y) {
ip -= w; ip -= w;
#ifndef WORDS_BIGENDIAN
// On a little-endian machine, we can copy the whole row at a time.
memcpy(ip, fo, w * PSZB); memcpy(ip, fo, w * PSZB);
#else
// On a big-endian machine, we have to reverse the color-component order.
const char *source = (const char *)fo;
const char *stop = (const char *)fo + w * PSZB;
char *dest = (char *)ip;
while (source < stop) {
char b = source[0];
char g = source[1];
char r = source[2];
char a = source[3];
dest[0] = a;
dest[1] = r;
dest[2] = g;
dest[3] = b;
dest += 4;
source += 4;
}
#endif
fo += _c->zb->linesize / PSZB; fo += _c->zb->linesize / PSZB;
} }

View File

@ -22,6 +22,7 @@
#include "tinyGraphicsBuffer.h" #include "tinyGraphicsBuffer.h"
#include "pnmImage.h" #include "pnmImage.h"
#include "subprocessWindow.h" #include "subprocessWindow.h"
#include "nativeWindowHandle.h"
TypeHandle TinyOsxGraphicsPipe::_type_handle; TypeHandle TinyOsxGraphicsPipe::_type_handle;
@ -235,12 +236,19 @@ make_output(const string &name,
return NULL; return NULL;
} }
} }
WindowHandle *window_handle = win_prop.get_parent_window();
if (window_handle != NULL) {
tinydisplay_cat.info()
<< "Got parent_window " << *window_handle << "\n";
#ifdef SUPPORT_SUBPROCESS_WINDOW #ifdef SUPPORT_SUBPROCESS_WINDOW
if (win_prop.has_subprocess_window()) { WindowHandle::OSHandle *os_handle = window_handle->get_os_handle();
return new SubprocessWindow(engine, this, name, fb_prop, win_prop, if (os_handle != NULL &&
flags, gsg, host); os_handle->is_of_type(NativeWindowHandle::SubprocessHandle::get_class_type())) {
} return new SubprocessWindow(engine, this, name, fb_prop, win_prop,
flags, gsg, host);
}
#endif // SUPPORT_SUBPROCESS_WINDOW #endif // SUPPORT_SUBPROCESS_WINDOW
}
return new TinyOsxGraphicsWindow(engine, this, name, fb_prop, win_prop, return new TinyOsxGraphicsWindow(engine, this, name, fb_prop, win_prop,
flags, gsg, host); flags, gsg, host);
} }