...(for now, from LIBO_INTERNAL_CODE only). See the mail thread starting at <https://lists.freedesktop.org/archives/libreoffice/2017-January/076665.html> "Dynamic Exception Specifications" for details. Most changes have been done automatically by the rewriting loplugin:dynexcspec (after enabling the rewriting mode, to be committed shortly). The way it only removes exception specs from declarations if it also sees a definition, it identified some dead declarations-w/o-definitions (that have been removed manually) and some cases where a definition appeared in multiple include files (which have also been cleaned up manually). There's also been cases of macro paramters (that were used to abstract over exception specs) that have become unused now (and been removed). Furthermore, some code needed to be cleaned up manually (avmedia/source/quicktime/ and connectivity/source/drivers/kab/), as I had no configurations available that would actually build that code. Missing @throws documentation has not been applied in such manual clean-up. Change-Id: I3408691256c9b0c12bc5332de976743626e13960 Reviewed-on: https://gerrit.libreoffice.org/33574 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
372 lines
12 KiB
C++
372 lines
12 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "oglwindow.hxx"
|
|
#include <cppuhelper/supportsservice.hxx>
|
|
|
|
using namespace com::sun::star;
|
|
using namespace libgltf;
|
|
|
|
namespace avmedia { namespace ogl {
|
|
|
|
OGLWindow::OGLWindow( glTFHandle& rHandle, const rtl::Reference<OpenGLContext> &rContext, vcl::Window& rEventHandlerParent )
|
|
: m_rHandle( rHandle )
|
|
, m_xContext( rContext )
|
|
, m_rEventHandler( rEventHandlerParent )
|
|
, m_bVisible ( false )
|
|
, m_aLastMousePos(Point(0,0))
|
|
, m_bIsOrbitMode( false )
|
|
{
|
|
}
|
|
|
|
OGLWindow::~OGLWindow()
|
|
{
|
|
dispose();
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::update()
|
|
{
|
|
m_xContext->makeCurrent();
|
|
int nRet = gltf_prepare_renderer(&m_rHandle);
|
|
if( nRet != 0 )
|
|
{
|
|
SAL_WARN("avmedia.opengl", "Error occurred while preparing for rendering! Error code: " << nRet);
|
|
return;
|
|
}
|
|
gltf_renderer(&m_rHandle);
|
|
gltf_complete_renderer(&m_rHandle);
|
|
m_xContext->swapBuffers();
|
|
}
|
|
|
|
sal_Bool SAL_CALL OGLWindow::setZoomLevel( css::media::ZoomLevel /*eZoomLevel*/ )
|
|
{
|
|
return false;
|
|
}
|
|
|
|
css::media::ZoomLevel SAL_CALL OGLWindow::getZoomLevel()
|
|
{
|
|
return media::ZoomLevel_ORIGINAL;
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::setPointerType( sal_Int32 )
|
|
{
|
|
}
|
|
|
|
OUString SAL_CALL OGLWindow::getImplementationName()
|
|
{
|
|
return OUString("com.sun.star.comp.avmedia.Window_OpenGL");
|
|
}
|
|
|
|
sal_Bool SAL_CALL OGLWindow::supportsService( const OUString& rServiceName )
|
|
{
|
|
return cppu::supportsService(this, rServiceName);
|
|
}
|
|
|
|
uno::Sequence< OUString > SAL_CALL OGLWindow::getSupportedServiceNames()
|
|
{
|
|
return { "com.sun.star.media.Window_OpenGL" };
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::dispose()
|
|
{
|
|
assert(m_rEventHandler.GetParent());
|
|
m_rEventHandler.GetParent()->RemoveEventListener( LINK(this, OGLWindow, FocusGrabber));
|
|
m_rEventHandler.RemoveEventListener( LINK(this, OGLWindow, CameraHandler));
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::addEventListener( const uno::Reference< lang::XEventListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::removeEventListener( const uno::Reference< lang::XEventListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::setPosSize( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 /*nFlags*/ )
|
|
{
|
|
if( m_rHandle.viewport.x != nX || m_rHandle.viewport.x != nY ||
|
|
m_rHandle.viewport.width != nWidth || m_rHandle.viewport.height != nHeight )
|
|
{
|
|
m_xContext->setWinSize(Size(nWidth,nHeight));
|
|
m_rHandle.viewport.x = nX;
|
|
m_rHandle.viewport.y = nY;
|
|
m_rHandle.viewport.width = nWidth;
|
|
m_rHandle.viewport.height = nHeight;
|
|
}
|
|
}
|
|
|
|
awt::Rectangle SAL_CALL OGLWindow::getPosSize()
|
|
{
|
|
return awt::Rectangle(m_rHandle.viewport.x, m_rHandle.viewport.y,
|
|
m_rHandle.viewport.width, m_rHandle.viewport.height);
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::setVisible( sal_Bool bSet )
|
|
{
|
|
assert(m_rEventHandler.GetParent());
|
|
if( bSet && !m_bVisible )
|
|
{
|
|
m_rEventHandler.GetParent()->AddEventListener( LINK(this, OGLWindow, FocusGrabber));
|
|
m_rEventHandler.AddEventListener( LINK(this, OGLWindow, CameraHandler));
|
|
m_rEventHandler.GrabFocus();
|
|
}
|
|
else if( !bSet )
|
|
{
|
|
m_rEventHandler.GetParent()->RemoveEventListener( LINK(this, OGLWindow, FocusGrabber));
|
|
m_rEventHandler.RemoveEventListener( LINK(this, OGLWindow, CameraHandler));
|
|
}
|
|
m_bVisible = bSet;
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::setEnable( sal_Bool )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::setFocus()
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::addWindowListener( const uno::Reference< awt::XWindowListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::removeWindowListener( const uno::Reference< awt::XWindowListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::addFocusListener( const uno::Reference< awt::XFocusListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::removeFocusListener( const uno::Reference< awt::XFocusListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::addKeyListener( const uno::Reference< awt::XKeyListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::removeKeyListener( const uno::Reference< awt::XKeyListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::addMouseListener( const uno::Reference< awt::XMouseListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::removeMouseListener( const uno::Reference< awt::XMouseListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::addPaintListener( const uno::Reference< awt::XPaintListener >& )
|
|
{
|
|
}
|
|
|
|
void SAL_CALL OGLWindow::removePaintListener( const uno::Reference< awt::XPaintListener >& )
|
|
{
|
|
}
|
|
|
|
IMPL_LINK(OGLWindow, FocusGrabber, VclWindowEvent&, rEvent, void)
|
|
{
|
|
if( rEvent.GetId() == VclEventId::WindowMouseMove )
|
|
{
|
|
MouseEvent* pMouseEvt = static_cast<MouseEvent*>(rEvent.GetData());
|
|
if(pMouseEvt)
|
|
{
|
|
const Point& rMousePos = pMouseEvt->GetPosPixel();
|
|
const Rectangle aWinRect(m_rEventHandler.GetPosPixel(),m_rEventHandler.GetSizePixel());
|
|
// Grab focus to the OpenGL window when mouse pointer is over it
|
|
if( aWinRect.IsInside(rMousePos) )
|
|
{
|
|
if ( !m_rEventHandler.HasFocus() )
|
|
{
|
|
m_rEventHandler.GrabFocus();
|
|
}
|
|
}
|
|
// Move focus to the document when mouse is not over the OpenGL window
|
|
else if ( m_rEventHandler.HasFocus() )
|
|
{
|
|
m_rEventHandler.GrabFocusToDocument();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent&, rEvent, void)
|
|
{
|
|
if( rEvent.GetId() == VclEventId::WindowKeyInput )
|
|
{
|
|
KeyEvent* pKeyEvt = static_cast<KeyEvent*>(rEvent.GetData());
|
|
if(pKeyEvt)
|
|
{
|
|
const sal_uInt16 nCode = pKeyEvt->GetKeyCode().GetCode();
|
|
if (nCode == KEY_Q || nCode == KEY_E ||
|
|
nCode == KEY_A || nCode == KEY_D ||
|
|
nCode == KEY_W || nCode == KEY_S )
|
|
{
|
|
// Calculate movement
|
|
glm::vec3 vMoveBy;
|
|
{
|
|
glm::vec3 vEye;
|
|
glm::vec3 vView;
|
|
glm::vec3 vUp;
|
|
gltf_get_camera_pos(&m_rHandle, &vEye,&vView,&vUp);
|
|
float fModelSize =(float)gltf_get_model_size(&m_rHandle);
|
|
|
|
glm::vec3 vMove = vView-vEye;
|
|
vMove = glm::normalize(vMove);
|
|
vMove *= 25.0f;
|
|
glm::vec3 vStrafe = glm::cross(vMove, vUp);
|
|
vStrafe = glm::normalize(vStrafe);
|
|
vStrafe *= 25.0f;
|
|
glm::vec3 vMup = vUp * 25.0f;
|
|
|
|
if( !m_bIsOrbitMode )
|
|
{
|
|
if(nCode == KEY_E)vMoveBy += vMup*(0.0005f*fModelSize);
|
|
if(nCode == KEY_Q)vMoveBy -= vMup*(0.0005f*fModelSize);
|
|
if(nCode == KEY_W)vMoveBy += vMove*(0.0005f*fModelSize);
|
|
if(nCode == KEY_S)vMoveBy -= vMove*(0.0005f*fModelSize);
|
|
if(nCode == KEY_A)vMoveBy -= vStrafe*(0.0005f*fModelSize);
|
|
if(nCode == KEY_D)vMoveBy += vStrafe*(0.0005f*fModelSize);
|
|
}
|
|
else
|
|
{
|
|
bool bZoomIn = false;
|
|
bool bZoomOut = false;
|
|
if(nCode == KEY_E)
|
|
{
|
|
vMoveBy += vMove*(0.0005f*fModelSize);
|
|
bZoomIn = true;
|
|
}
|
|
if(nCode == KEY_Q)
|
|
{
|
|
vMoveBy -= vMove*(0.0005f*fModelSize);
|
|
bZoomOut = true;
|
|
}
|
|
|
|
// Limit zooming in orbit mode
|
|
float fCameraDistFromModelGlobe = glm::length(vEye + vMoveBy - vView) - fModelSize / 2.0f;
|
|
if ((fCameraDistFromModelGlobe < 0.5 * fModelSize && bZoomIn ) ||
|
|
(fCameraDistFromModelGlobe > 2 * fModelSize && bZoomOut ))
|
|
{
|
|
vMoveBy = glm::vec3(0.0);
|
|
}
|
|
}
|
|
}
|
|
gltf_renderer_move_camera(&m_rHandle, vMoveBy.x, vMoveBy.y, vMoveBy.z, 0.0001);
|
|
|
|
if( m_bIsOrbitMode )
|
|
{
|
|
long nDeltaX = 0;
|
|
long nDeltaY = 0;
|
|
if (nCode == KEY_W)
|
|
{
|
|
nDeltaY -= 1;
|
|
}
|
|
if (nCode == KEY_S)
|
|
{
|
|
nDeltaY += 1;
|
|
}
|
|
if (nCode == KEY_A)
|
|
{
|
|
nDeltaX -= 1;
|
|
}
|
|
if (nCode == KEY_D)
|
|
{
|
|
nDeltaX += 1;
|
|
}
|
|
float fSensitivity = 50.0;
|
|
gltf_renderer_rotate_model(&m_rHandle, nDeltaX*fSensitivity, nDeltaY*fSensitivity, 0.0);
|
|
}
|
|
}
|
|
else if(nCode == KEY_M)
|
|
{
|
|
if(m_bIsOrbitMode)
|
|
{
|
|
gltf_orbit_mode_stop(&m_rHandle);
|
|
m_bIsOrbitMode = false;
|
|
}
|
|
else
|
|
{
|
|
gltf_orbit_mode_start(&m_rHandle);
|
|
m_bIsOrbitMode = true;
|
|
}
|
|
}
|
|
else if(nCode == KEY_F)
|
|
{
|
|
gltf_render_FPS_enable(&m_rHandle);
|
|
}
|
|
}
|
|
}
|
|
else if( rEvent.GetId() == VclEventId::WindowMouseButtonDown )
|
|
{
|
|
MouseEvent* pMouseEvt = static_cast<MouseEvent*>(rEvent.GetData());
|
|
if(pMouseEvt && pMouseEvt->IsLeft() && pMouseEvt->GetClicks() == 1)
|
|
{
|
|
m_aLastMousePos = pMouseEvt->GetPosPixel();
|
|
}
|
|
}
|
|
else if( rEvent.GetId() == VclEventId::WindowMouseMove )
|
|
{
|
|
if ( !m_rEventHandler.HasFocus() )
|
|
{
|
|
m_rEventHandler.GrabFocus();
|
|
}
|
|
MouseEvent* pMouseEvt = static_cast<MouseEvent*>(rEvent.GetData());
|
|
if(pMouseEvt && pMouseEvt->IsLeft() && m_aLastMousePos != Point(0,0))
|
|
{
|
|
const Point& aCurPos = pMouseEvt->GetPosPixel();
|
|
float fSensitivity = std::min(m_rHandle.viewport.width, m_rHandle.viewport.height);
|
|
if (fSensitivity == 0.0)
|
|
fSensitivity = 1.0;
|
|
else
|
|
fSensitivity = 540.0 / fSensitivity;
|
|
|
|
|
|
long nDeltaX = m_aLastMousePos.X()-aCurPos.X();
|
|
long nDeltaY = m_aLastMousePos.Y()-aCurPos.Y();
|
|
if( m_bIsOrbitMode )
|
|
{
|
|
fSensitivity *= 5;
|
|
gltf_renderer_rotate_model(&m_rHandle, (float)nDeltaX*fSensitivity, (float)nDeltaY*fSensitivity, 0.0);
|
|
}
|
|
else
|
|
{
|
|
// Filter out too small deltas to avoid rewrite rotation parameter with 0
|
|
// before rotation is done
|
|
if( nDeltaX != 0 || nDeltaY != 0 )
|
|
gltf_renderer_rotate_camera(&m_rHandle, (float)nDeltaX*fSensitivity, (float)nDeltaY*fSensitivity, 0.0);
|
|
}
|
|
m_aLastMousePos = aCurPos;
|
|
}
|
|
}
|
|
else if( rEvent.GetId() == VclEventId::WindowMouseButtonUp )
|
|
{
|
|
MouseEvent* pMouseEvt = static_cast<MouseEvent*>(rEvent.GetData());
|
|
if(pMouseEvt && pMouseEvt->IsLeft() && pMouseEvt->GetClicks() == 1)
|
|
{
|
|
m_aLastMousePos = Point(0,0);
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace ogl
|
|
} // namespace avmedia
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|