Patch 17508: Blender Web Plugin - XEmbed. Enable XEmbed integration of blenderplayer...
authorBenoit Bolsee <benoit.bolsee@online.be>
Tue, 9 Sep 2008 21:15:30 +0000 (21:15 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Tue, 9 Sep 2008 21:15:30 +0000 (21:15 +0000)
15 files changed:
CMakeLists.txt
intern/ghost/GHOST_ISystem.h
intern/ghost/GHOST_Types.h
intern/ghost/intern/GHOST_SystemCarbon.cpp
intern/ghost/intern/GHOST_SystemCarbon.h
intern/ghost/intern/GHOST_SystemWin32.cpp
intern/ghost/intern/GHOST_SystemWin32.h
intern/ghost/intern/GHOST_SystemX11.cpp
intern/ghost/intern/GHOST_SystemX11.h
intern/ghost/intern/GHOST_WindowX11.cpp
intern/ghost/intern/GHOST_WindowX11.h
source/gameengine/GamePlayer/CMakeLists.txt
source/gameengine/GamePlayer/ghost/GPG_Application.cpp
source/gameengine/GamePlayer/ghost/GPG_Application.h
source/gameengine/GamePlayer/ghost/GPG_ghost.cpp

index 97113c22f980e61e050c5b2f3b0352d0788dd7a2..4c1b863178f444556c166295418d1729b7f610ce 100644 (file)
@@ -64,6 +64,7 @@ OPTION(WITH_OPENEXR           "Enable OpenEXR Support (http://www.openexr.com)"       ON)
 OPTION(WITH_FFMPEG             "Enable FFMPeg Support (http://ffmpeg.mplayerhq.hu/)"   OFF)
 OPTION(WITH_OPENAL             "Enable OpenAL Support (http://www.openal.org)"         ON)
 OPTION(WITH_OPENMP             "Enable OpenMP (has to be supported by the compiler)"   OFF)
+OPTION(WITH_WEBPLUGIN          "Enable Web Plugin (Mozilla-Unix only)"                 OFF)
 
 IF(NOT WITH_GAMEENGINE AND WITH_PLAYER)
   MESSAGE("WARNING: WITH_PLAYER needs WITH_GAMEENGINE")
@@ -456,6 +457,13 @@ SUBDIRS(
 # Blender Application
 SUBDIRS(source/creator)
 
+#-----------------------------------------------------------------------------
+# Blender WebPlugin
+IF(WITH_WEBPLUGIN) 
+  SET(MOZILLA_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
+  SET(WITH_PLAYER ON)
+ENDIF(WITH_WEBPLUGIN)
+
 #-----------------------------------------------------------------------------
 # Blender Player
 IF(WITH_PLAYER)
index 2ad2e9ddce71d1f36138823d535017b067c7096f..baf0cb813f84af7a40273a9b206d8be8f834d5b7 100644 (file)
@@ -224,13 +224,15 @@ public:
         * @param       state           The state of the window when opened.
         * @param       type            The type of drawing context installed in this window.
         * @param       stereoVisual    Create a stereo visual for quad buffered stereo.
+        * @param       parentWindow    Parent (embedder) window
         * @return      The new window (or 0 if creation failed).
         */
        virtual GHOST_IWindow* createWindow(
                const STR_String& title,
                GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
                GHOST_TWindowState state, GHOST_TDrawingContextType type,
-               const bool stereoVisual) = 0;
+               const bool stereoVisual,
+               const GHOST_TEmbedderWindowID parentWindow = 0) = 0;
 
        /**
         * Dispose a window.
index f81192f1887f8ee626f491b872ec2dc1f178db20..6b1295f649b32d24633cda2e0299d7d400318ca4 100644 (file)
@@ -100,6 +100,7 @@ typedef enum {
        GHOST_kWindowStateMaximized,
        GHOST_kWindowStateMinimized,
        GHOST_kWindowStateFullScreen,
+       GHOST_kWindowStateEmbedded,
        GHOST_kWindowState8Normal = 8,
        GHOST_kWindowState8Maximized,
        GHOST_kWindowState8Minimized,
@@ -392,6 +393,15 @@ typedef struct {
 } GHOST_DisplaySetting;
 
 
+#ifdef _WIN32
+typedef long GHOST_TEmbedderWindowID;
+#endif // _WIN32
+
+#ifndef _WIN32
+// I can't use "Window" from "<X11/Xlib.h>" because it conflits with Window defined in winlay.h
+typedef int GHOST_TEmbedderWindowID;
+#endif // _WIN32
+
 /**
  * A timer task callback routine.
  * @param task The timer task object.
index 78c25997806f12792f35635b7f2a0ded5f657a00..067c8deee32c391375b8a172d8f1b30fcd02599c 100644 (file)
@@ -402,7 +402,8 @@ GHOST_IWindow* GHOST_SystemCarbon::createWindow(
        GHOST_TUns32 height,
        GHOST_TWindowState state,
        GHOST_TDrawingContextType type,
-       bool stereoVisual
+       bool stereoVisual,
+       const GHOST_TEmbedderWindowID parentWindow
 )
 {
     GHOST_IWindow* window = 0;
index 2afc8e0885a3b50f4bba438fa2664950a3b312ff..2a1d63257843ba49d6135f2269faa35a58f13923 100644 (file)
@@ -103,6 +103,7 @@ public:
         * @param       height  The height the window.
         * @param       state   The state of the window when opened.
         * @param       type    The type of drawing context installed in this window.
+        * @param       parentWindow    Parent (embedder) window
         * @return      The new window (or 0 if creation failed).
         */
        virtual GHOST_IWindow* createWindow(
@@ -113,7 +114,8 @@ public:
                GHOST_TUns32 height,
                GHOST_TWindowState state,
                GHOST_TDrawingContextType type,
-               const bool stereoVisual
+               const bool stereoVisual,
+               const GHOST_TEmbedderWindowID parentWindow = 0 
        );
        
        /***************************************************************************************
index 7bc20d3873900efb007ec238ab3859a8bc8777dc..feb0fe39040eb8bebf567d558fb5d97b57da01e4 100644 (file)
@@ -169,7 +169,7 @@ GHOST_IWindow* GHOST_SystemWin32::createWindow(
        const STR_String& title, 
        GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
        GHOST_TWindowState state, GHOST_TDrawingContextType type,
-       bool stereoVisual)
+       bool stereoVisual, const GHOST_TEmbedderWindowID parentWindow )
 {
        GHOST_Window* window = 0;
        window = new GHOST_WindowWin32 (title, left, top, width, height, state, type, stereoVisual);
index c26ef25e366048d506e9709a810350cc8e6353cd..00f7af0016258c8c4086e7f85ddc945bb2f72cdc 100644 (file)
@@ -109,13 +109,14 @@ public:
         * @param       height  The height the window.
         * @param       state   The state of the window when opened.
         * @param       type    The type of drawing context installed in this window.
+        * @param       parentWindow    Parent (embedder) window
         * @return      The new window (or 0 if creation failed).
         */
        virtual GHOST_IWindow* createWindow(
                const STR_String& title,
                GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
                GHOST_TWindowState state, GHOST_TDrawingContextType type,
-               const bool stereoVisual);
+               const bool stereoVisual, const GHOST_TEmbedderWindowID parentWindow = 0 );
 
        /***************************************************************************************
         ** Event management functionality
index 3003e0b8b1431a75c8adacb9664d41b4578c0f2a..1b90831986d57d6634ab4c25ff99400a1e5a4312 100644 (file)
@@ -191,6 +191,7 @@ getMainDisplayDimensions(
         * @param       height  The height the window.
         * @param       state   The state of the window when opened.
         * @param       type    The type of drawing context installed in this window.
+        * @param       parentWindow    Parent (embedder) window
         * @return      The new window (or 0 if creation failed).
         */
        GHOST_IWindow* 
@@ -203,14 +204,18 @@ createWindow(
        GHOST_TUns32 height,
        GHOST_TWindowState state,
        GHOST_TDrawingContextType type,
-       bool stereoVisual
+       bool stereoVisual,
+       const GHOST_TEmbedderWindowID parentWindow
 ){
        GHOST_WindowX11 * window = 0;
        
        if (!m_display) return 0;
        
+
+       
+
        window = new GHOST_WindowX11 (
-               this,m_display,title, left, top, width, height, state, type, stereoVisual
+               this,m_display,title, left, top, width, height, state, parentWindow, type, stereoVisual
        );
 
        if (window) {
@@ -511,7 +516,9 @@ GHOST_SystemX11::processEvent(XEvent *xe)
                        }
                        break;
                }
-                       
+               
+               case DestroyNotify:
+                       ::exit(-1);     
                // We're not interested in the following things.(yet...)
                case NoExpose : 
                case GraphicsExpose :
index 726cdfb2fff03bb459579bb6966b322b45fa00e9..c67f7d81e6027f9fd2bac58d31bb482feb07e9dc 100644 (file)
@@ -108,6 +108,7 @@ public:
         * @param       state           The state of the window when opened.
         * @param       type            The type of drawing context installed in this window.
         * @param       stereoVisual    Create a stereo visual for quad buffered stereo.
+        * @param       parentWindow    Parent (embedder) window
         * @return      The new window (or 0 if creation failed).
         */
                GHOST_IWindow* 
@@ -119,9 +120,10 @@ public:
                GHOST_TUns32 height,
                GHOST_TWindowState state,
                GHOST_TDrawingContextType type,
-               const bool stereoVisual
+               const bool stereoVisual,
+               const GHOST_TEmbedderWindowID parentWindow = 0 
        );
-        
+
        /**
         * @section Interface Inherited from GHOST_ISystem 
         */
index a98a59377c703054b13f2e5bb511f8f7c5bbfce0..7b0606c40b7ce7dab306f8db1870f7ac72d4f18c 100644 (file)
@@ -138,6 +138,7 @@ GHOST_WindowX11(
        GHOST_TUns32 width,     
        GHOST_TUns32 height,
        GHOST_TWindowState state,
+       const GHOST_TEmbedderWindowID parentWindow,
        GHOST_TDrawingContextType type,
        const bool stereoVisual
 ) :
@@ -205,21 +206,57 @@ GHOST_WindowX11(
 
        // create the window!
 
-       m_window = 
-               XCreateWindow(
-                       m_display, 
-                       RootWindow(m_display, m_visual->screen), 
-                       left,
-                       top,
-                       width,
-                       height,
-                       0, // no border.
-                       m_visual->depth,
-                       InputOutput, 
-                       m_visual->visual,
-                       CWBorderPixel|CWColormap|CWEventMask, 
-                       &xattributes
-               );
+       ;
+       if (parentWindow == 0) {
+               m_window = 
+                       XCreateWindow(
+                               m_display, 
+                               RootWindow(m_display, m_visual->screen), 
+                               left,
+                               top,
+                               width,
+                               height,
+                               0, // no border.
+                               m_visual->depth,
+                               InputOutput, 
+                               m_visual->visual,
+                               CWBorderPixel|CWColormap|CWEventMask, 
+                               &xattributes
+                       );
+       } else {
+
+               Window root_return;
+               int x_return,y_return;
+               unsigned int w_return,h_return,border_w_return,depth_return;
+               GHOST_TInt32 screen_x, screen_y;
+               
+               XGetGeometry(m_display, parentWindow, &root_return, &x_return, &y_return,
+                       &w_return, &h_return, &border_w_return, &depth_return );
+
+               left = 0;
+               top = 0;
+               width = w_return;
+               height = h_return;
+
+
+               m_window = XCreateWindow(
+                               m_display, 
+                               parentWindow,  // reparent against embedder 
+                               left,
+                               top,
+                               width,
+                               height,
+                               0, // no border.
+                               m_visual->depth,
+                               InputOutput, 
+                               m_visual->visual,
+                               CWBorderPixel|CWColormap|CWEventMask, 
+                               &xattributes
+                       );
+
+               XSelectInput(m_display , parentWindow, SubstructureNotifyMask);
+               
+       }       
        
        
        // Are we in fullscreen mode - then include
index 1203dbde80dc1b39f4663830f09a457c0d5ba756..abb5c131cb74fa1cfac0483abfe95b7cae78d0e1 100644 (file)
@@ -64,6 +64,7 @@ public:
         * @param width         The width the window.
         * @param height        The height the window.
         * @param state         The state the window is initially opened with.
+        * @param parentWindow  Parent (embedder) window
         * @param type          The type of drawing context installed in this window.
         * @param stereoVisual  Stereo visual for quad buffered stereo.
         */
@@ -76,6 +77,7 @@ public:
                GHOST_TUns32 width,     
                GHOST_TUns32 height,
                GHOST_TWindowState state,
+               const GHOST_TEmbedderWindowID parentWindow,
                GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
                const bool stereoVisual = false
        );
index ff1040bfb401bae1781239ee76341b6a17359f1a..fc5912155cf0c0a626277e9941c1e8cf0994288b 100644 (file)
@@ -25,3 +25,7 @@
 # ***** END GPL LICENSE BLOCK *****
 
 SUBDIRS(common ghost)
+
+IF(WITH_WEBPLUGIN) 
+  SUBDIRS(xembed)
+ENDIF(WITH_WEBPLUGIN)
index 806216e05bb324ffe9ec7eb3871adab7876e5f61..3d9ae66c9ea3b0490899ccd5ddf4047635565e44 100644 (file)
@@ -129,7 +129,8 @@ GPG_Application::GPG_Application(GHOST_ISystem* system)
          m_blendermat(0),
          m_blenderglslmat(0),
          m_pyGlobalDictString(0),
-         m_pyGlobalDictString_Length(0)
+         m_pyGlobalDictString_Length(0),
+         m_isEmbedded(false)
 {
        fSystem = system;
 }
@@ -325,6 +326,26 @@ bool GPG_Application::startWindow(STR_String& title,
        return success;
 }
 
+bool GPG_Application::startEmbeddedWindow(STR_String& title,
+       const GHOST_TEmbedderWindowID parentWindow, 
+       const bool stereoVisual, 
+       const int stereoMode) {
+
+       m_mainWindow = fSystem->createWindow(title, 0, 0, 0, 0, GHOST_kWindowStateNormal,
+               GHOST_kDrawingContextTypeOpenGL, stereoVisual, parentWindow);
+
+       if (!m_mainWindow) {
+               printf("error: could not create main window\n");
+               exit(-1);
+       }
+       m_isEmbedded = true;
+
+       bool success = initEngine(m_mainWindow, stereoMode);
+       if (success) {
+               success = startEngine();
+       }
+       return success;
+}
 
 
 bool GPG_Application::startFullScreen(
@@ -887,7 +908,7 @@ bool GPG_Application::handleKey(GHOST_IEvent* event, bool isDown)
                GHOST_TEventKeyData* keyData = static_cast<GHOST_TEventKeyData*>(eventData);
                //no need for this test
                //if (fSystem->getFullScreen()) {
-                       if (keyData->key == GHOST_kKeyEsc && !m_keyboard->m_hookesc) {
+                       if (keyData->key == GHOST_kKeyEsc && !m_keyboard->m_hookesc && !m_isEmbedded) {
                                m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
                        }
                //}
index 5242a41980825b76c023fcd7699d19aad771abd0..7fc369fc0fd0ca93aa035ea76ead8a1745dddba5 100644 (file)
@@ -62,6 +62,7 @@ public:
                        bool startWindow(STR_String& title, int windowLeft, int windowTop, int windowWidth, int windowHeight,
                        const bool stereoVisual, const int stereoMode);
                        bool startFullScreen(int width, int height, int bpp, int frequency, const bool stereoVisual, const int stereoMode);
+                       bool startEmbeddedWindow(STR_String& title, const GHOST_TEmbedderWindowID parent_window, const bool stereoVisual, const int stereoMode);
 #ifdef WIN32
                        bool startScreenSaverFullScreen(int width, int height, int bpp, int frequency, const bool stereoVisual, const int stereoMode);
                        bool startScreenSaverPreview(HWND parentWindow, const bool stereoVisual, const int stereoMode);
@@ -143,6 +144,8 @@ protected:
        bool m_engineInitialized;
        /** Engine state. */
        bool m_engineRunning;
+       /** Running on embedded window */
+       bool m_isEmbedded;
 
        /** the gameengine itself */
        KX_KetsjiEngine* m_ketsjiengine;
index cc781a38bbb8ec267a073352fffbc62fd80974e1..d44e983af89b63167cbade75a1553c8e04e3c263 100644 (file)
@@ -178,6 +178,9 @@ void usage(char* program)
        printf("                   anaglyph         (Red-Blue glasses)\n");
        printf("                   vinterlace       (Vertical interlace for autostereo display)\n");
        printf("                             depending on the type of stereo you want\n");
+#ifndef _WIN32
+       printf("  -i: parent windows ID \n");
+#endif
 #ifdef _WIN32
        printf("  -c: keep console window open\n");
 #endif
@@ -297,6 +300,9 @@ int main(int argc, char** argv)
        int fullScreenFrequency = 60;
        char* pyGlobalDictString = NULL; /* store python dict data between blend file loading */
        int pyGlobalDictString_Length = 0;
+       GHOST_TEmbedderWindowID parentWindow = 0;
+
+
        
 #ifdef __linux__
 #ifdef __alpha__
@@ -457,6 +463,16 @@ int main(int argc, char** argv)
                                usage(argv[0]);
                                return 0;
                                break;
+#ifndef _WIN32
+                       case 'i':
+                               i++;
+                               if ( (i + 1) < argc )
+                                       parentWindow = atoi(argv[i++]);                                         
+#ifndef NDEBUG
+                               printf("XWindows ID = %d\n", parentWindow);
+#endif //NDEBUG
+
+#endif  // _WIN32                      
                        case 'c':
                                i++;
                                closeConsole = false;
@@ -729,7 +745,10 @@ int main(int argc, char** argv)
                                                                else
 #endif
                                                                {
-                                                                       app.startWindow(title, windowLeft, windowTop, windowWidth, windowHeight,
+                                                                                                                                                                                                               if (parentWindow != 0)
+                                                                               app.startEmbeddedWindow(title, parentWindow, stereoWindow, stereomode);
+                                                                       else
+                                                                               app.startWindow(title, windowLeft, windowTop, windowWidth, windowHeight,
                                                                                stereoWindow, stereomode);
                                                                }
                                                        }