[Libreoffice-commits] core.git: 7 commits - avmedia/source slideshow/source

Zolnai Tamás tamas.zolnai at collabora.com
Thu May 15 05:25:52 PDT 2014


 avmedia/source/opengl/oglplayer.cxx               |    1 
 avmedia/source/opengl/oglwindow.cxx               |   93 ++++++++++++++--------
 avmedia/source/opengl/oglwindow.hxx               |    1 
 slideshow/source/engine/shapes/viewmediashape.cxx |   33 +++++--
 slideshow/source/engine/shapes/viewmediashape.hxx |    5 -
 5 files changed, 91 insertions(+), 42 deletions(-)

New commits:
commit 3efddb093e72c100bc609ec691effb4563af2c20
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Thu May 15 12:54:57 2014 +0200

    OGLWindow: First try to rotate camera
    
    For now its too slow to render by mousemove so
    use mousebuttonup instead.
    It seems gltf_renderer_rotate_camera() method does not rotate
    the camera but set the new position of it.
    
    Change-Id: I0fe7895720dbf95acb0963a5ba6dd2a5840d8f6b

diff --git a/avmedia/source/opengl/oglwindow.cxx b/avmedia/source/opengl/oglwindow.cxx
index f32070a..ca2ffbf 100644
--- a/avmedia/source/opengl/oglwindow.cxx
+++ b/avmedia/source/opengl/oglwindow.cxx
@@ -20,6 +20,7 @@ OGLWindow::OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext, SystemChildW
     , m_pEventHandler( pChildWindow->GetParent() )
     , m_bVisible ( false )
     , meZoomLevel( media::ZoomLevel_ORIGINAL )
+    , m_aLastMousePos(Point())
 {
 }
 
@@ -276,12 +277,34 @@ IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent)
                     if(nCode == KEY_W)vMoveBy -= vMup*(0.1f*fModelSize);
                     if(nCode == KEY_S)vMoveBy += vMup*(0.1f*fModelSize);
                 }
-
                 gltf_renderer_move_camera(vMoveBy.x,vMoveBy.y,vMoveBy.z,10.0);
                 update();
             }
         }
     }
+    else if( pEvent->GetId() == VCLEVENT_WINDOW_MOUSEBUTTONDOWN )
+    {
+        MouseEvent* pMouseEvt = (MouseEvent*)pEvent->GetData();
+        if(pMouseEvt && pMouseEvt->IsLeft() && pMouseEvt->GetClicks() == 1)
+        {
+            m_aLastMousePos = pMouseEvt->GetPosPixel();
+        }
+    }
+    else if( pEvent->GetId() == VCLEVENT_WINDOW_MOUSEBUTTONUP )
+    {
+        MouseEvent* pMouseEvt = (MouseEvent*)pEvent->GetData();
+        if(pMouseEvt && pMouseEvt->IsLeft())
+        {
+            const Point& aCurPos = pMouseEvt->GetPosPixel();
+
+            long nDeltaX = m_aLastMousePos.X()-aCurPos.X();
+            long nDeltaY = aCurPos.Y()-m_aLastMousePos.Y();
+            static const float fSensitivity = 4.0;
+            // TODO: It seems this method just moves the camera but not rotate it.
+            gltf_renderer_rotate_camera((float)nDeltaX*fSensitivity,(float)nDeltaY*fSensitivity,0.0,10.0);
+            update();
+        }
+    }
     return 0;
 }
 
diff --git a/avmedia/source/opengl/oglwindow.hxx b/avmedia/source/opengl/oglwindow.hxx
index e7b0d3a..ba510e4 100644
--- a/avmedia/source/opengl/oglwindow.hxx
+++ b/avmedia/source/opengl/oglwindow.hxx
@@ -70,6 +70,7 @@ private:
     Window* m_pEventHandler;
     bool m_bVisible;
     com::sun::star::media::ZoomLevel meZoomLevel;
+    Point m_aLastMousePos;
 };
 
 } // namespace ogl
commit 882e1bb2db4d84d8349657153cfe14363d5d9da4
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Wed May 14 10:49:10 2014 +0200

    OGLWindow: use update function for redrawing.
    
    Change-Id: Icca39a44d6a4437f20d120b4032a39f7e74ac066

diff --git a/avmedia/source/opengl/oglwindow.cxx b/avmedia/source/opengl/oglwindow.cxx
index f798718..f32070a 100644
--- a/avmedia/source/opengl/oglwindow.cxx
+++ b/avmedia/source/opengl/oglwindow.cxx
@@ -250,8 +250,6 @@ IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent)
                 nCode == KEY_A || nCode == KEY_D ||
                 nCode == KEY_W || nCode == KEY_S )
             {
-                m_pContext->makeCurrent();
-
                 // Calculate movement
                 glm::vec3 vMoveBy;
                 {
@@ -280,10 +278,7 @@ IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent)
                 }
 
                 gltf_renderer_move_camera(vMoveBy.x,vMoveBy.y,vMoveBy.z,10.0);
-                gltf_prepare_renderer(m_pHandle);
-                gltf_renderer(m_pHandle);
-                gltf_complete_renderer();
-                m_pContext->swapBuffers();
+                update();
             }
         }
     }
commit 9ba99cbfcf793539f47f34fd637a48f97a249920
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Thu May 15 12:51:13 2014 +0200

    OGLWindow: move camera only when one of the key candidates is pressed
    
    Change-Id: I52b3d100512cad569a53d10c9dc819e4548ba928

diff --git a/avmedia/source/opengl/oglwindow.cxx b/avmedia/source/opengl/oglwindow.cxx
index 8f9eefa..f798718 100644
--- a/avmedia/source/opengl/oglwindow.cxx
+++ b/avmedia/source/opengl/oglwindow.cxx
@@ -246,40 +246,45 @@ IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent)
         if(pKeyEvt)
         {
             const sal_uInt16 nCode = pKeyEvt->GetKeyCode().GetCode();
-            m_pContext->makeCurrent();
-
-            // Calculate movement
-            glm::vec3 vMoveBy;
+            if (nCode == KEY_Q || nCode == KEY_E ||
+                nCode == KEY_A || nCode == KEY_D ||
+                nCode == KEY_W || nCode == KEY_S )
             {
-                glm::vec3 vEye;
-                glm::vec3 vView;
-                glm::vec3 vUp;
-                gltf_get_camera_pos(&vEye,&vView,&vUp);
-                float fModelSize =(float)gltf_get_model_size();
-
-                glm::vec3 vMove = vView-vEye;
-                vMove = glm::normalize(vMove);
-                vMove *= 25.0f;
-                glm::vec3 vStrafe = glm::cross(vView-vEye, vUp);
-                vStrafe = glm::normalize(vStrafe);
-                vStrafe *= 25.0f;
-                glm::vec3 vMup = glm::cross(vView-vEye,glm::vec3(1.f,0.f,0.f) );
-                vMup = glm::normalize(vMup);
-                vMup *= 25.0f;
-
-                if(nCode == KEY_Q)vMoveBy += vMove*(0.1f*fModelSize);
-                if(nCode == KEY_E)vMoveBy -= vMove*(0.1f*fModelSize);
-                if(nCode == KEY_A)vMoveBy -= vStrafe*(0.1f*fModelSize);
-                if(nCode == KEY_D)vMoveBy += vStrafe*(0.1f*fModelSize);
-                if(nCode == KEY_W)vMoveBy -= vMup*(0.1f*fModelSize);
-                if(nCode == KEY_S)vMoveBy += vMup*(0.1f*fModelSize);
-            }
+                m_pContext->makeCurrent();
+
+                // Calculate movement
+                glm::vec3 vMoveBy;
+                {
+                    glm::vec3 vEye;
+                    glm::vec3 vView;
+                    glm::vec3 vUp;
+                    gltf_get_camera_pos(&vEye,&vView,&vUp);
+                    float fModelSize =(float)gltf_get_model_size();
+
+                    glm::vec3 vMove = vView-vEye;
+                    vMove = glm::normalize(vMove);
+                    vMove *= 25.0f;
+                    glm::vec3 vStrafe = glm::cross(vView-vEye, vUp);
+                    vStrafe = glm::normalize(vStrafe);
+                    vStrafe *= 25.0f;
+                    glm::vec3 vMup = glm::cross(vView-vEye,glm::vec3(1.f,0.f,0.f) );
+                    vMup = glm::normalize(vMup);
+                    vMup *= 25.0f;
+
+                    if(nCode == KEY_Q)vMoveBy += vMove*(0.1f*fModelSize);
+                    if(nCode == KEY_E)vMoveBy -= vMove*(0.1f*fModelSize);
+                    if(nCode == KEY_A)vMoveBy -= vStrafe*(0.1f*fModelSize);
+                    if(nCode == KEY_D)vMoveBy += vStrafe*(0.1f*fModelSize);
+                    if(nCode == KEY_W)vMoveBy -= vMup*(0.1f*fModelSize);
+                    if(nCode == KEY_S)vMoveBy += vMup*(0.1f*fModelSize);
+                }
 
-            gltf_renderer_move_camera(vMoveBy.x,vMoveBy.y,vMoveBy.z,10.0);
-            gltf_prepare_renderer(m_pHandle);
-            gltf_renderer(m_pHandle);
-            gltf_complete_renderer();
-            m_pContext->swapBuffers();
+                gltf_renderer_move_camera(vMoveBy.x,vMoveBy.y,vMoveBy.z,10.0);
+                gltf_prepare_renderer(m_pHandle);
+                gltf_renderer(m_pHandle);
+                gltf_complete_renderer();
+                m_pContext->swapBuffers();
+            }
         }
     }
     return 0;
commit a48251956973525f338d297b07aad100e346ee9d
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Thu May 15 12:50:40 2014 +0200

    OGLWindow: remove event listeners also when window is disposed
    
    To avoid segmentation fault.
    Plus some comments.
    
    Change-Id: I7368b34a29b595f52975f41836d4fe1f63e4e859

diff --git a/avmedia/source/opengl/oglwindow.cxx b/avmedia/source/opengl/oglwindow.cxx
index 7bef3b4..8f9eefa 100644
--- a/avmedia/source/opengl/oglwindow.cxx
+++ b/avmedia/source/opengl/oglwindow.cxx
@@ -25,6 +25,7 @@ OGLWindow::OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext, SystemChildW
 
 OGLWindow::~OGLWindow()
 {
+    dispose();
 }
 
 void SAL_CALL OGLWindow::update() throw (css::uno::RuntimeException, std::exception)
@@ -81,6 +82,8 @@ uno::Sequence< OUString > SAL_CALL OGLWindow::getSupportedServiceNames() throw (
 
 void SAL_CALL OGLWindow::dispose() throw (uno::RuntimeException, std::exception)
 {
+    m_pEventHandler->GetParent()->RemoveEventListener( LINK(this, OGLWindow, FocusGrabber));
+    m_pEventHandler->RemoveEventListener( LINK(this, OGLWindow, CameraHandler));
 }
 
 void SAL_CALL OGLWindow::addEventListener( const uno::Reference< lang::XEventListener >& )
@@ -216,6 +219,7 @@ IMPL_LINK(OGLWindow, FocusGrabber, VclWindowEvent*, pEvent)
         {
             const Point& rMousePos = pMouseEvt->GetPosPixel();
             const Rectangle aWinRect(m_pEventHandler->GetPosPixel(),m_pEventHandler->GetSizePixel());
+            // Grab focus to the OpenGL window when mouse pointer is over it
             if( aWinRect.IsInside(rMousePos) )
             {
                 if ( !m_pEventHandler->HasFocus() )
@@ -223,6 +227,7 @@ IMPL_LINK(OGLWindow, FocusGrabber, VclWindowEvent*, pEvent)
                     m_pEventHandler->GrabFocus();
                 }
             }
+            // Move focus to the document when mouse is not over the OpenGL window
             else if ( m_pEventHandler->HasFocus() )
             {
                 m_pEventHandler->GrabFocusToDocument();
@@ -240,7 +245,7 @@ IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent)
         KeyEvent* pKeyEvt = (KeyEvent*)pEvent->GetData();
         if(pKeyEvt)
         {
-            sal_uInt16 nCode = pKeyEvt->GetKeyCode().GetCode();
+            const sal_uInt16 nCode = pKeyEvt->GetKeyCode().GetCode();
             m_pContext->makeCurrent();
 
             // Calculate movement
commit 21a2ce0d09a34ca63aebb3821ce120a8e00e0d68
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Thu May 15 12:49:57 2014 +0200

    slideshow\glTF: add a parent window to the OpenGL window
    
    OpenGL window is a SystemChildWindow which doesn't handle
    window events as a vcl Window does (call it's event
    handler functions and the given event listeners), so
    I added a new parent which will handle window events
    and capture them from the slideshow's main window.
    
    Change-Id: I06ac87fb85e663e52f2691c1311605b3fd7d3afa

diff --git a/slideshow/source/engine/shapes/viewmediashape.cxx b/slideshow/source/engine/shapes/viewmediashape.cxx
index d854151..ab97235 100644
--- a/slideshow/source/engine/shapes/viewmediashape.cxx
+++ b/slideshow/source/engine/shapes/viewmediashape.cxx
@@ -75,7 +75,8 @@ namespace slideshow
                                         const uno::Reference< drawing::XShape >&        rxShape,
                                         const uno::Reference< uno::XComponentContext >& rxContext ) :
             mpViewLayer( rViewLayer ),
-            mpMediaWindow(),
+            mpMediaWindow(0),
+            mpEventHandlerParent(0),
             maWindowOffset( 0, 0 ),
             maBounds(),
             mxShape( rxShape ),
@@ -149,6 +150,7 @@ namespace slideshow
             }
 
             mpMediaWindow.reset();
+            mpEventHandlerParent.reset();
 
             // shutdown player
             if( mxPlayer.is() )
@@ -277,7 +279,15 @@ namespace slideshow
 
             if( mpMediaWindow.get() )
             {
-                mpMediaWindow->SetPosSizePixel( aPosPixel, aSizePixel );
+                if( mpEventHandlerParent )
+                {
+                    mpEventHandlerParent->SetPosSizePixel( aPosPixel, aSizePixel );
+                    mpMediaWindow->SetPosSizePixel( Point(0,0), aSizePixel );
+                }
+                else
+                {
+                    mpMediaWindow->SetPosSizePixel( aPosPixel, aSizePixel );
+                }
                 mxPlayerWindow->setPosSize( 0, 0,
                                             aSizePixel.Width(), aSizePixel.Height(),
                                             0 );
@@ -463,16 +473,22 @@ namespace slideshow
                                                                     rRangePix.getMaxY() - rRangePix.getMinY() );
                             if( avmedia::IsModel(rMimeType) )
                             {
-                                SystemWindowData aWinData = OpenGLContext::generateWinData(pWindow);
-                                mpMediaWindow.reset(new SystemChildWindow(pWindow, 0, &aWinData));
+                                mpEventHandlerParent.reset(new Window(pWindow, WB_NOBORDER|WB_NODIALOGCONTROL));
+                                mpEventHandlerParent->SetPosSizePixel( Point( aAWTRect.X, aAWTRect.Y ),
+                                                           Size( aAWTRect.Width, aAWTRect.Height ) );
+                                mpEventHandlerParent->Show();
+                                SystemWindowData aWinData = OpenGLContext::generateWinData(mpEventHandlerParent.get());
+                                mpMediaWindow.reset(new SystemChildWindow(mpEventHandlerParent.get(), 0, &aWinData));
+                                mpMediaWindow->SetPosSizePixel( Point( 0, 0 ),
+                                                           Size( aAWTRect.Width, aAWTRect.Height ) );
                             }
                             else
                             {
                                 mpMediaWindow.reset( new SystemChildWindow( pWindow, WB_CLIPCHILDREN ) );
+                                mpMediaWindow->SetPosSizePixel( Point( aAWTRect.X, aAWTRect.Y ),
+                                                           Size( aAWTRect.Width, aAWTRect.Height ) );
                             }
                             mpMediaWindow->SetBackground( Color( COL_BLACK ) );
-                            mpMediaWindow->SetPosSizePixel( Point( aAWTRect.X, aAWTRect.Y ),
-                                                           Size( aAWTRect.Width, aAWTRect.Height ) );
                             mpMediaWindow->SetParentClipMode( PARENTCLIPMODE_NOCLIP );
                             mpMediaWindow->EnableEraseBackground( false );
                             mpMediaWindow->EnablePaint( false );
@@ -504,6 +520,7 @@ namespace slideshow
                                 //if there was no playerwindow, then clear the mpMediaWindow too
                                 //so that we can draw a placeholder instead in that space
                                 mpMediaWindow.reset();
+                                mpEventHandlerParent.reset();
                             }
                         }
                     }
diff --git a/slideshow/source/engine/shapes/viewmediashape.hxx b/slideshow/source/engine/shapes/viewmediashape.hxx
index 609c36e..dc726f6 100644
--- a/slideshow/source/engine/shapes/viewmediashape.hxx
+++ b/slideshow/source/engine/shapes/viewmediashape.hxx
@@ -25,10 +25,12 @@
 
 #include <boost/shared_ptr.hpp>
 #include <boost/utility.hpp>
+#include <boost/scoped_ptr.hpp>
 
 #include "viewlayer.hxx"
 
 class SystemChildWindow;
+class Window;
 
 namespace com { namespace sun { namespace star { namespace drawing {
     class XShape;
@@ -145,7 +147,8 @@ namespace slideshow
                                                      const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rVCLDeviceParams,
                                                      const OUString& rMimeType );
             ViewLayerSharedPtr                    mpViewLayer;
-            ::std::auto_ptr< SystemChildWindow >    mpMediaWindow;
+            ::std::auto_ptr< SystemChildWindow >  mpMediaWindow;
+            boost::scoped_ptr< Window >           mpEventHandlerParent;
             mutable ::com::sun::star::awt::Point  maWindowOffset;
             mutable ::basegfx::B2DRectangle       maBounds;
 
commit 8099056f50f4587cb03b76cf6bac7e876f6ff967
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Tue May 13 14:05:13 2014 +0200

    avmediaogl: call gltf_renderer_set_content() only once
    
    Change-Id: Ic4c4b886f5a60508e4f62eb3396850d09ae5d0a0

diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx
index 43b8a71..217fd88 100644
--- a/avmedia/source/opengl/oglplayer.cxx
+++ b/avmedia/source/opengl/oglplayer.cxx
@@ -211,6 +211,7 @@ uno::Reference< media::XPlayerWindow > SAL_CALL OGLPlayer::createPlayerWindow( c
     m_pHandle->viewport.y = 0;
     m_pHandle->viewport.width = aSize.Width();
     m_pHandle->viewport.height = aSize.Height();
+    gltf_renderer_set_content(m_pHandle);
     OGLWindow* pWindow = new OGLWindow(m_pHandle, &m_aContext, pChildWindow);
     return uno::Reference< media::XPlayerWindow >( pWindow );
 }
diff --git a/avmedia/source/opengl/oglwindow.cxx b/avmedia/source/opengl/oglwindow.cxx
index 35b1ab4..7bef3b4 100644
--- a/avmedia/source/opengl/oglwindow.cxx
+++ b/avmedia/source/opengl/oglwindow.cxx
@@ -30,7 +30,6 @@ OGLWindow::~OGLWindow()
 void SAL_CALL OGLWindow::update() throw (css::uno::RuntimeException, std::exception)
 {
     m_pContext->makeCurrent();
-    gltf_renderer_set_content(m_pHandle);
     gltf_prepare_renderer(m_pHandle);
     gltf_renderer(m_pHandle);
     gltf_complete_renderer();
commit 31095d231ad976a8ea36733c97a7b86288dc363f
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Tue May 13 13:02:47 2014 +0200

    slideshow: update log messages
    
    Change-Id: Ifcf9941707a8770931296750b674fbccc1571f6d

diff --git a/slideshow/source/engine/shapes/viewmediashape.cxx b/slideshow/source/engine/shapes/viewmediashape.cxx
index 77b6443..d854151 100644
--- a/slideshow/source/engine/shapes/viewmediashape.cxx
+++ b/slideshow/source/engine/shapes/viewmediashape.cxx
@@ -299,7 +299,7 @@ namespace slideshow
             if( !mxPlayer.is() && mxShape.is() )
             {
                 ENSURE_OR_RETURN_FALSE( mpViewLayer->getCanvas(),
-                                   "ViewMediaShape::update(): Invalid layer canvas" );
+                                   "ViewMediaShape::implInitialize(): Invalid layer canvas" );
 
                 uno::Reference< rendering::XCanvas > xCanvas( mpViewLayer->getCanvas()->getUNOCanvas() );
 
@@ -434,7 +434,7 @@ namespace slideshow
                                                                  const uno::Sequence< uno::Any >& rVCLDeviceParams,
                                                                  const OUString& rMimeType )
         {
-                    OSL_TRACE( "ViewMediaShape::implInitializeVCLBasedPlayerWindow" );
+            OSL_TRACE( "ViewMediaShape::implInitializePlayerWindow" );
             if( !mpMediaWindow.get() && !rBounds.isEmpty() )
             {
                 try


More information about the Libreoffice-commits mailing list