diff options
author | Zolnai Tamás <tamas.zolnai@collabora.com> | 2014-04-27 12:20:13 +0200 |
---|---|---|
committer | Zolnai Tamás <tamas.zolnai@collabora.com> | 2014-04-27 12:34:07 +0200 |
commit | e112ac81d1c3a91d46ea660ac4e01e6c94ee900e (patch) | |
tree | 284226e20c4c25d0b1d04fc0fc4056aa66ffff33 | |
parent | b5529c8c457f442bfc43305becc0c02d6a09ee80 (diff) |
First try to render OpenGL content in a window
Change-Id: Ibb7178330d356806cea2cfc972b361167d5a9340
-rw-r--r-- | avmedia/source/opengl/oglplayer.cxx | 22 | ||||
-rw-r--r-- | avmedia/source/opengl/oglplayer.hxx | 3 | ||||
-rw-r--r-- | avmedia/source/opengl/oglwindow.cxx | 32 | ||||
-rw-r--r-- | avmedia/source/opengl/oglwindow.hxx | 11 | ||||
-rw-r--r-- | avmedia/source/viewer/mediawindow_impl.cxx | 11 | ||||
-rw-r--r-- | include/vcl/opengl/OpenGLContext.hxx | 8 | ||||
-rw-r--r-- | vcl/source/opengl/OpenGLContext.cxx | 52 |
7 files changed, 103 insertions, 36 deletions
diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx index 720825ab151e..9d5f730cbc12 100644 --- a/avmedia/source/opengl/oglplayer.cxx +++ b/avmedia/source/opengl/oglplayer.cxx @@ -24,6 +24,7 @@ namespace avmedia { namespace ogl { OGLPlayer::OGLPlayer() : Player_BASE(m_aMutex) + , m_bIsPlaying(false) { } @@ -98,19 +99,21 @@ void SAL_CALL OGLPlayer::start() throw ( uno::RuntimeException, std::exception ) { osl::MutexGuard aGuard(m_aMutex); // TODO: Start playing of gltf model (see com::sun::star::media::XPlayer) + m_bIsPlaying = true; } void SAL_CALL OGLPlayer::stop() throw ( uno::RuntimeException, std::exception ) { osl::MutexGuard aGuard(m_aMutex); // TODO: Stop playing of gltf model (see com::sun::star::media::XPlayer) + m_bIsPlaying = false; } sal_Bool SAL_CALL OGLPlayer::isPlaying() throw ( uno::RuntimeException, std::exception ) { osl::MutexGuard aGuard(m_aMutex); // TODO: Check whether gltf model is played by now (see com::sun::star::media::XPlayer) - return false; + return m_bIsPlaying; } double SAL_CALL OGLPlayer::getDuration() throw ( uno::RuntimeException, std::exception ) @@ -184,11 +187,19 @@ awt::Size SAL_CALL OGLPlayer::getPreferredPlayerWindowSize() throw ( uno::Runtim return awt::Size( 480, 360 ); // TODO: It will be good for OpenGL too? } -uno::Reference< media::XPlayerWindow > SAL_CALL OGLPlayer::createPlayerWindow( const uno::Sequence< uno::Any >& /*aArguments*/ ) +uno::Reference< media::XPlayerWindow > SAL_CALL OGLPlayer::createPlayerWindow( const uno::Sequence< uno::Any >& rArguments ) throw ( uno::RuntimeException, std::exception ) { osl::MutexGuard aGuard( m_aMutex ); - OGLWindow* pWindow = new OGLWindow(*this); + + if( rArguments.getLength() > 2 ) + { + sal_IntPtr pIntPtr = 0; + rArguments[ 2 ] >>= pIntPtr; + SystemChildWindow *pChildWindow = reinterpret_cast< SystemChildWindow* >( pIntPtr ); + m_aContext.init(pChildWindow); + } + OGLWindow* pWindow = new OGLWindow(m_pHandle, &m_aContext); return uno::Reference< media::XPlayerWindow >( pWindow ); } @@ -197,11 +208,10 @@ uno::Reference< media::XFrameGrabber > SAL_CALL OGLPlayer::createFrameGrabber() { osl::MutexGuard aGuard(m_aMutex); m_aContext.init(); - //TODO: Use real values instead of constants. m_pHandle->viewport.x = 0; m_pHandle->viewport.y = 0; - m_pHandle->viewport.width = 800; - m_pHandle->viewport.height = 600; + m_pHandle->viewport.width = getPreferredPlayerWindowSize().Width; + m_pHandle->viewport.height = getPreferredPlayerWindowSize().Height; gltf_renderer_set_content(m_pHandle); OGLFrameGrabber *pFrameGrabber = new OGLFrameGrabber( m_pHandle ); return uno::Reference< media::XFrameGrabber >( pFrameGrabber );; diff --git a/avmedia/source/opengl/oglplayer.hxx b/avmedia/source/opengl/oglplayer.hxx index 2b9b4154b2a6..a40b43d808ac 100644 --- a/avmedia/source/opengl/oglplayer.hxx +++ b/avmedia/source/opengl/oglplayer.hxx @@ -47,7 +47,7 @@ public: virtual void SAL_CALL setMute( sal_Bool bSet ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual sal_Bool SAL_CALL isMute() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual com::sun::star::awt::Size SAL_CALL getPreferredPlayerWindowSize() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual com::sun::star::uno::Reference< com::sun::star::media::XPlayerWindow > SAL_CALL createPlayerWindow( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual com::sun::star::uno::Reference< com::sun::star::media::XPlayerWindow > SAL_CALL createPlayerWindow( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& rArguments ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual com::sun::star::uno::Reference< com::sun::star::media::XFrameGrabber > SAL_CALL createFrameGrabber() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; // XServiceInfo virtual OUString SAL_CALL getImplementationName() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; @@ -58,6 +58,7 @@ private: OUString m_sURL; glTFHandle* m_pHandle; OpenGLContext m_aContext; + bool m_bIsPlaying; }; } // namespace ogl diff --git a/avmedia/source/opengl/oglwindow.cxx b/avmedia/source/opengl/oglwindow.cxx index 3a024ef64aca..6d4788a7e675 100644 --- a/avmedia/source/opengl/oglwindow.cxx +++ b/avmedia/source/opengl/oglwindow.cxx @@ -14,11 +14,12 @@ using namespace com::sun::star; namespace avmedia { namespace ogl { -OGLWindow::OGLWindow( OGLPlayer& rPlayer ) - : m_rPlayer( rPlayer ) +OGLWindow::OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext ) + : m_pHandle( pHandle ) + , m_pContext( pContext ) + , m_bVisible ( false ) , meZoomLevel( media::ZoomLevel_ORIGINAL ) { - (void) m_rPlayer; } OGLWindow::~OGLWindow() @@ -86,22 +87,37 @@ void SAL_CALL OGLWindow::removeEventListener( const uno::Reference< lang::XEvent { } -void SAL_CALL OGLWindow::setPosSize( sal_Int32 /*X*/, sal_Int32 /*Y*/, sal_Int32 /*Width*/, sal_Int32 /*Height*/, sal_Int16 /* Flags */ ) +void SAL_CALL OGLWindow::setPosSize( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 /*nFlags*/ ) throw (uno::RuntimeException, std::exception) { - // TODO: store size + if( !m_bVisible ) + return; + + if( m_pHandle->viewport.x != nX || m_pHandle->viewport.x != nY || + m_pHandle->viewport.width != nWidth || m_pHandle->viewport.height != nHeight ) + { + m_pContext->setWinSize(Size(nWidth,nHeight)); + m_pHandle->viewport.x = nX; + m_pHandle->viewport.y = nY; + m_pHandle->viewport.width = nWidth; + m_pHandle->viewport.height = nHeight; + gltf_renderer_set_content(m_pHandle); + gltf_renderer(m_pHandle); + m_pContext->swapBuffers(); + } } awt::Rectangle SAL_CALL OGLWindow::getPosSize() throw (uno::RuntimeException, std::exception) { - // TODO: get size - return awt::Rectangle(); + return awt::Rectangle(m_pHandle->viewport.x, m_pHandle->viewport.y, + m_pHandle->viewport.width, m_pHandle->viewport.height); } -void SAL_CALL OGLWindow::setVisible( sal_Bool ) +void SAL_CALL OGLWindow::setVisible( sal_Bool bSet ) throw (uno::RuntimeException, std::exception) { + m_bVisible = bSet; } void SAL_CALL OGLWindow::setEnable( sal_Bool ) diff --git a/avmedia/source/opengl/oglwindow.hxx b/avmedia/source/opengl/oglwindow.hxx index d373dd1c8e5a..95767c04d52c 100644 --- a/avmedia/source/opengl/oglwindow.hxx +++ b/avmedia/source/opengl/oglwindow.hxx @@ -17,13 +17,16 @@ #include <com/sun/star/media/XPlayerWindow.hpp> #include <com/sun/star/media/ZoomLevel.hpp> +#include <libgltf.h> +#include <vcl/opengl/OpenGLContext.hxx> + namespace avmedia { namespace ogl { class OGLWindow : public ::cppu::WeakImplHelper2 < com::sun::star::media::XPlayerWindow, com::sun::star::lang::XServiceInfo > { public: - OGLWindow( OGLPlayer& rPlayer ); + OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext ); virtual ~OGLWindow(); virtual void SAL_CALL update() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; @@ -39,7 +42,7 @@ public: virtual void SAL_CALL addEventListener( const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& xListener ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual void SAL_CALL removeEventListener( const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& aListener ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual void SAL_CALL setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL setPosSize( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nFlags ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual com::sun::star::awt::Rectangle SAL_CALL getPosSize() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual void SAL_CALL setVisible( sal_Bool Visible ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual void SAL_CALL setEnable( sal_Bool Enable ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; @@ -58,7 +61,9 @@ public: virtual void SAL_CALL removePaintListener( const com::sun::star::uno::Reference< com::sun::star::awt::XPaintListener >& xListener ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; private: - OGLPlayer& m_rPlayer; + glTFHandle* m_pHandle; + OpenGLContext* m_pContext; + bool m_bVisible; com::sun::star::media::ZoomLevel meZoomLevel; }; diff --git a/avmedia/source/viewer/mediawindow_impl.cxx b/avmedia/source/viewer/mediawindow_impl.cxx index a84e42fe5f14..87d61cb3e736 100644 --- a/avmedia/source/viewer/mediawindow_impl.cxx +++ b/avmedia/source/viewer/mediawindow_impl.cxx @@ -86,11 +86,6 @@ MediaChildWindow::MediaChildWindow( Window* pParent ) : MediaChildWindow::MediaChildWindow( Window* pParent, SystemWindowData* pData ) : SystemChildWindow( pParent, 0, pData ) { - SetMouseTransparent( true ); - SetParentClipMode( PARENTCLIPMODE_NOCLIP ); - EnableEraseBackground( false ); - SetControlForeground(); - SetControlBackground(); } MediaChildWindow::~MediaChildWindow() @@ -515,7 +510,6 @@ void MediaWindowImpl::onURLChanged() mpChildWindow->SetHelpId( HID_AVMEDIA_PLAYERWINDOW ); mxEventsIf.set( static_cast< ::cppu::OWeakObject* >( mpEvents = new MediaEventListenersImpl( *mpChildWindow.get() ) ) ); - if( mxPlayer.is() ) { uno::Sequence< uno::Any > aArgs( 3 ); @@ -569,6 +563,8 @@ void MediaWindowImpl::onURLChanged() void MediaWindowImpl::setPosSize( const Rectangle& rRect ) { SetPosSizePixel( rRect.TopLeft(), rRect.GetSize() ); + if( mxPlayerWindow.is() ) + mxPlayerWindow->setPosSize( 0, 0, rRect.GetSize().Width(), rRect.GetSize().Height(), 0 ); } @@ -615,9 +611,6 @@ void MediaWindowImpl::Resize() mpMediaWindowControl->SetPosSizePixel( Point( nOffset, nControlY ), Size( aCurSize.Width() - ( nOffset << 1 ), nControlHeight ) ); } - if( mxPlayerWindow.is() ) - mxPlayerWindow->setPosSize( 0, 0, aPlayerWindowSize.Width(), aPlayerWindowSize.Height(), 0 ); - if( mpChildWindow ) mpChildWindow->SetPosSizePixel( Point( 0, 0 ), aPlayerWindowSize ); } diff --git a/include/vcl/opengl/OpenGLContext.hxx b/include/vcl/opengl/OpenGLContext.hxx index b01e8fd352a1..9d22ae6691ef 100644 --- a/include/vcl/opengl/OpenGLContext.hxx +++ b/include/vcl/opengl/OpenGLContext.hxx @@ -147,6 +147,10 @@ public: ~OpenGLContext(); bool init(Window* pParent = 0); + bool init(SystemChildWindow* pChildWindow); + + void swapBuffers(); + void setWinSize(const Size& rSize); GLWindow& getOpenGLWindow(); @@ -161,11 +165,13 @@ public: private: SAL_DLLPRIVATE bool initWindow(); + SAL_DLLPRIVATE bool ImplInit(); GLWindow m_aGLWin; boost::scoped_ptr<Window> m_pWindow; Window* mpWindow; //points to m_pWindow or the parent window, don't delete it - boost::scoped_ptr<SystemChildWindow> m_pChildWindow; + SystemChildWindow* m_pChildWindow; + boost::scoped_ptr<SystemChildWindow> m_pChildWindowGC; bool mbInitialized; }; diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index 2b3cba600db9..107bcf07a6ff 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -331,8 +331,28 @@ bool OpenGLContext::init( Window* pParent ) m_pWindow.reset(pParent ? NULL : new Window(0, WB_NOBORDER|WB_NODIALOGCONTROL)); mpWindow = pParent ? pParent : m_pWindow.get(); - SAL_INFO("vcl.opengl", "OpenGLContext::OpenGLContext----start"); + m_pChildWindow = 0; initWindow(); + return ImplInit(); +} + +bool OpenGLContext::init(SystemChildWindow* pChildWindow) +{ + if(mbInitialized) + return true; + + if( !pChildWindow ) + return false; + + mpWindow = pChildWindow->GetParent(); + m_pChildWindow = pChildWindow; + initWindow(); + return ImplInit(); +} + +bool OpenGLContext::ImplInit() +{ + SAL_INFO("vcl.opengl", "OpenGLContext::ImplInit----start"); if(m_pWindow) m_pWindow->setPosSizePixel(0,0,0,0); m_aGLWin.Width = 0; @@ -474,7 +494,7 @@ bool OpenGLContext::init( Window* pParent ) bGlewInit = true; } - SAL_INFO("vcl.opengl", "OpenGLContext::init----end"); + SAL_INFO("vcl.opengl", "OpenGLContext::ImplInit----end"); mbInitialized = true; return true; } @@ -483,7 +503,8 @@ void OpenGLContext::setWinSize(const Size& rSize) { if(m_pWindow) m_pWindow->SetSizePixel(rSize); - m_pChildWindow->SetSizePixel(rSize); + if( m_pChildWindow ) + m_pChildWindow->SetSizePixel(rSize); m_aGLWin.Width = rSize.Width(); m_aGLWin.Height = rSize.Height(); @@ -544,8 +565,12 @@ bool OpenGLContext::initWindow() { const SystemEnvData* sysData(mpWindow->GetSystemData()); m_aGLWin.hWnd = sysData->hWnd; - SystemWindowData winData = generateWinData(mpWindow); - m_pChildWindow.reset(new SystemChildWindow(mpWindow, 0, &winData, sal_False)); + if( !m_pChildWindow ) + { + SystemWindowData winData = generateWinData(mpWindow); + m_pChildWindow = new SystemChildWindow(mpWindow, 0, &winData, sal_False); + m_pChildWindowGC.reset(m_pChildWindow); + } if( m_pChildWindow ) { @@ -572,13 +597,15 @@ bool OpenGLContext::initWindow() bool OpenGLContext::initWindow() { - m_pChildWindow.reset(); - const SystemEnvData* pChildSysData = 0; SystemWindowData winData = generateWinData(mpWindow); if( winData.pVisual ) { - m_pChildWindow.reset(new SystemChildWindow(mpWindow, 0, &winData, false)); + if( !m_pChildWindow ) + { + m_pChildWindow = new SystemChildWindow(mpWindow, 0, &winData, sal_False); + m_pChildWindowGC.reset(m_pChildWindow); + } pChildSysData = m_pChildWindow->GetSystemData(); } @@ -723,4 +750,13 @@ SystemWindowData OpenGLContext::generateWinData(Window* pParent) #endif +void OpenGLContext::swapBuffers() +{ +#if defined( _WIN32 ) + SwapBuffers(m_aGLWin.hDC); +#elif defined( UNX ) + glXSwapBuffers(m_aGLWin.dpy, m_aGLWin.win); +#endif +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |