Prechádzať zdrojové kódy

move subprocess_window into new WindowHandle structure

David Rose 16 rokov pred
rodič
commit
ee1f03abe7

+ 39 - 6
panda/src/display/subprocessWindow.cxx

@@ -18,6 +18,7 @@
 
 #include "graphicsEngine.h"
 #include "config_display.h"
+#include "nativeWindowHandle.h"
 
 TypeHandle SubprocessWindow::_type_handle;
 
@@ -244,10 +245,22 @@ begin_flip() {
 ////////////////////////////////////////////////////////////////////
 void SubprocessWindow::
 set_properties_now(WindowProperties &properties) {
-  if (properties.has_subprocess_window() && 
-      properties.get_subprocess_window() != _filename) {
+  Filename 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
     // might as well completely close and re-open the window.
+    display_cat.info() << "Re-opening SubprocessWindow\n";
     internal_close_window();
 
     _properties.add_properties(properties);
@@ -265,9 +278,9 @@ set_properties_now(WindowProperties &properties) {
     return;
   }
 
-  if (properties.has_subprocess_window()) {
-    // Redundant subprocess specification.
-    properties.clear_subprocess_window();
+  if (properties.has_parent_window()) {
+    // Redundant parent-window specification.
+    properties.clear_parent_window();
   }
 }
 
@@ -371,7 +384,24 @@ internal_open_window() {
   }
 
   _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
     (_fd, _mmap_size, _filename.to_os_specific());
@@ -387,6 +417,9 @@ internal_open_window() {
     return false;
   }
 
+  display_cat.error()
+    << "SubprocessWindow reading " << _filename << "\n";
+
   return true;
 }
 

+ 4 - 7
panda/src/display/windowHandle.h

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

+ 0 - 64
panda/src/display/windowProperties.I

@@ -855,70 +855,6 @@ clear_parent_window() {
   _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 &
 operator << (ostream &out, const WindowProperties &properties) {

+ 10 - 17
panda/src/display/windowProperties.cxx

@@ -47,7 +47,6 @@ operator = (const WindowProperties &copy) {
   _flags = copy._flags;
   _mouse_mode = copy._mouse_mode;
   _parent_window = copy._parent_window;
-  _subprocess_window = copy._subprocess_window;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -87,10 +86,9 @@ get_config_properties() {
   }
   props.set_title(window_title);
   if (parent_window_handle.get_value() != 0) {
-    props.set_parent_window(parent_window_handle);
-  }
-  if (!subprocess_window.empty()) {
-    props.set_subprocess_window(subprocess_window);
+    props.set_parent_window(NativeWindowHandle::make_int(parent_window_handle));
+  } else if (!subprocess_window.empty()) {
+    props.set_parent_window(NativeWindowHandle::make_subprocess(subprocess_window));
   }
   props.set_mouse_mode(M_absolute);
 
@@ -179,8 +177,7 @@ operator == (const WindowProperties &other) const {
           _icon_filename == other._icon_filename &&
           _cursor_filename == other._cursor_filename &&
           _mouse_mode == other._mouse_mode &&
-          _parent_window == other._parent_window &&
-          _subprocess_window == other._subprocess_window);
+          _parent_window == other._parent_window);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -203,8 +200,7 @@ clear() {
   _z_order = Z_normal;
   _flags = 0;
   _mouse_mode = M_absolute;
-  _parent_window = 0;
-  _subprocess_window = Filename();
+  _parent_window = NULL;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -290,9 +286,6 @@ add_properties(const WindowProperties &other) {
   if (other.has_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() << " ";
   }
   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 &

+ 0 - 7
panda/src/display/windowProperties.h

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

+ 12 - 6
panda/src/osxdisplay/osxGraphicsPipe.cxx

@@ -16,8 +16,7 @@
 #include "osxGraphicsStateGuardian.h"
 #include "pnmImage.h"
 #include "subprocessWindow.h"
-
-
+#include "nativeWindowHandle.h"
 
 TypeHandle osxGraphicsPipe::_type_handle;
   
@@ -234,12 +233,19 @@ make_output(const string &name,
         ((flags&BF_can_bind_every)!=0)) {
       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
-    if (win_prop.has_subprocess_window()) {
-      return new SubprocessWindow(engine, this, name, fb_prop, win_prop,
-                                  flags, gsg, host);
-    }
+      WindowHandle::OSHandle *os_handle = window_handle->get_os_handle();
+      if (os_handle != NULL && 
+          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
+    }
     return new osxGraphicsWindow(engine, this, name, fb_prop, win_prop,
                                  flags, gsg, host);
   }

+ 20 - 0
panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx

@@ -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;
   for (int y = 0; y < h; ++y) {
     ip -= w;
+#ifndef WORDS_BIGENDIAN
+    // On a little-endian machine, we can copy the whole row at a time.
     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;
   }
 

+ 12 - 4
panda/src/tinydisplay/tinyOsxGraphicsPipe.cxx

@@ -22,6 +22,7 @@
 #include "tinyGraphicsBuffer.h"
 #include "pnmImage.h"
 #include "subprocessWindow.h"
+#include "nativeWindowHandle.h"
 
 TypeHandle TinyOsxGraphicsPipe::_type_handle;
   
@@ -235,12 +236,19 @@ make_output(const string &name,
         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
-    if (win_prop.has_subprocess_window()) {
-      return new SubprocessWindow(engine, this, name, fb_prop, win_prop,
-                                  flags, gsg, host);
-    }
+      WindowHandle::OSHandle *os_handle = window_handle->get_os_handle();
+      if (os_handle != NULL && 
+          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
+    }
     return new TinyOsxGraphicsWindow(engine, this, name, fb_prop, win_prop,
                                      flags, gsg, host);
   }