[Libreoffice-commits] core.git: 2 commits - avmedia/source external/libgltf include/avmedia slideshow/source svx/source

Zolnai Tamás tamas.zolnai at collabora.com
Sun Apr 20 09:01:58 PDT 2014


 avmedia/source/opengl/oglframegrabber.cxx                        |   30 ++-
 avmedia/source/opengl/oglframegrabber.hxx                        |    7 
 avmedia/source/opengl/oglplayer.cxx                              |    5 
 avmedia/source/opengl/oglplayer.hxx                              |    2 
 avmedia/source/viewer/mediawindow.cxx                            |   12 -
 avmedia/source/viewer/mediawindow_impl.cxx                       |    2 
 avmedia/source/viewer/mediawindow_impl.hxx                       |    2 
 external/libgltf/UnpackedTarball_libgltf.mk                      |    3 
 external/libgltf/patches/charbuffer_used_as_cstring.patch        |   12 -
 external/libgltf/patches/json_charbuffer_used_as_cstring.patch   |   12 +
 external/libgltf/patches/shader_charbuffer_used_as_cstring.patch |   94 ++++++++++
 include/avmedia/mediawindow.hxx                                  |    5 
 slideshow/source/engine/shapes/viewmediashape.cxx                |    6 
 svx/source/svdraw/svdomedia.cxx                                  |    2 
 14 files changed, 161 insertions(+), 33 deletions(-)

New commits:
commit d8920e6d1de0698f7c132d74cc34e2f1021c6fb3
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Sun Apr 20 18:00:33 2014 +0200

    Make OGLFrameGrabber work
    
    Steps of grabFrame
    - Init opengl context
    - Call libgltf to render
    - Get a RGB buffer from libgltf
    - Create a Bitmap from this RGB buffer
    
    Additionally:
    - Using mimetype is neccessary to decide which player to create.
    - bAllowToCreateReplacementGraphic is unneeded.
    
    Change-Id: I7fef043a3341771389144a4f4cac71b0862ef8a7

diff --git a/avmedia/source/opengl/oglframegrabber.cxx b/avmedia/source/opengl/oglframegrabber.cxx
index 2aeda97..81be9c1 100644
--- a/avmedia/source/opengl/oglframegrabber.cxx
+++ b/avmedia/source/opengl/oglframegrabber.cxx
@@ -12,13 +12,16 @@
 #include <cppuhelper/supportsservice.hxx>
 #include <vcl/bitmapex.hxx>
 #include <vcl/graph.hxx>
+#include <vcl/salbtype.hxx>
+#include <vcl/bmpacc.hxx>
 
 using namespace com::sun::star;
 
 namespace avmedia { namespace ogl {
 
-OGLFrameGrabber::OGLFrameGrabber( const OUString& /*rUrl*/ )
+OGLFrameGrabber::OGLFrameGrabber(  glTFHandle* pHandle )
     : FrameGrabber_BASE()
+    , m_pHandle( pHandle )
 {
 }
 
@@ -26,12 +29,29 @@ OGLFrameGrabber::~OGLFrameGrabber()
 {
 }
 
-uno::Reference< css::graphic::XGraphic > SAL_CALL OGLFrameGrabber::grabFrame( double /*fMediaTime*/ )
+uno::Reference< css::graphic::XGraphic > SAL_CALL OGLFrameGrabber::grabFrame( double fMediaTime )
         throw ( uno::RuntimeException, std::exception )
 {
-    // TODO: Here we need a bitmap of the model at the point specified by fMediaTime
-    // See com::sun::star::media::XFrameGrabber
-    BitmapEx aBitmap;
+    // TODO: libgltf should provide an RGBA buffer, not just an RGB one. See: OpenGLRender::GetAsBitmap().
+    char* pBuffer = new char[m_pHandle->viewport.width * m_pHandle->viewport.height * 3];
+    gltf_renderer_get_bitmap(m_pHandle, fMediaTime, pBuffer, 800, 600);
+    Bitmap aBitmap( Size(m_pHandle->viewport.width, m_pHandle->viewport.height), 24 );
+    {
+        Bitmap::ScopedWriteAccess pWriteAccess( aBitmap );
+        size_t nCurPos = 0;
+        for( int y = 0; y < m_pHandle->viewport.height; ++y)
+        {
+            Scanline pScan = pWriteAccess->GetScanline(y);
+            for( int x = 0; x < m_pHandle->viewport.width; ++x )
+            {
+                *pScan++ = pBuffer[nCurPos];
+                *pScan++ = pBuffer[nCurPos+1];
+                *pScan++ = pBuffer[nCurPos+2];
+                nCurPos += 3;
+            }
+        }
+    }
+    delete [] pBuffer;
     return Graphic( aBitmap ).GetXGraphic();
 }
 
diff --git a/avmedia/source/opengl/oglframegrabber.hxx b/avmedia/source/opengl/oglframegrabber.hxx
index fd3d9fb..b4b1dae 100644
--- a/avmedia/source/opengl/oglframegrabber.hxx
+++ b/avmedia/source/opengl/oglframegrabber.hxx
@@ -14,6 +14,8 @@
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/media/XFrameGrabber.hpp>
 
+#include <libgltf.h>
+
 namespace avmedia { namespace ogl {
 
 typedef ::cppu::WeakImplHelper2< com::sun::star::media::XFrameGrabber,
@@ -23,7 +25,7 @@ class OGLFrameGrabber : public FrameGrabber_BASE
 {
 public:
 
-    OGLFrameGrabber( const OUString& rURL );
+    OGLFrameGrabber( glTFHandle* pHandle );
     virtual ~OGLFrameGrabber();
 
     // XFrameGrabber
@@ -33,6 +35,9 @@ public:
     virtual OUString SAL_CALL getImplementationName() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     virtual com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+
+private:
+    glTFHandle* m_pHandle;
 };
 
 } // namespace ogl
diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx
index d0ffde3..f1d514a 100644
--- a/avmedia/source/opengl/oglplayer.cxx
+++ b/avmedia/source/opengl/oglplayer.cxx
@@ -196,7 +196,10 @@ uno::Reference< media::XFrameGrabber > SAL_CALL OGLPlayer::createFrameGrabber()
      throw ( uno::RuntimeException, std::exception )
 {
     osl::MutexGuard aGuard(m_aMutex);
-    OGLFrameGrabber *pFrameGrabber = new OGLFrameGrabber( m_sURL );
+    m_aContext.init();
+    m_pHandle->viewport = glTFViewport({0,0,800,600}); //TODO: Use real values instead of constants.
+    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 cf8ac2c..2b9b415 100644
--- a/avmedia/source/opengl/oglplayer.hxx
+++ b/avmedia/source/opengl/oglplayer.hxx
@@ -15,6 +15,7 @@
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/media/XPlayer.hpp>
 #include <libgltf.h>
+#include <vcl/opengl/OpenGLContext.hxx>
 
 namespace avmedia { namespace ogl {
 
@@ -56,6 +57,7 @@ public:
 private:
     OUString m_sURL;
     glTFHandle* m_pHandle;
+    OpenGLContext m_aContext;
 };
 
 } // namespace ogl
diff --git a/avmedia/source/viewer/mediawindow.cxx b/avmedia/source/viewer/mediawindow.cxx
index 992bb40..e586a58 100644
--- a/avmedia/source/viewer/mediawindow.cxx
+++ b/avmedia/source/viewer/mediawindow.cxx
@@ -385,19 +385,19 @@ bool MediaWindow::isMediaURL( const OUString& rURL, const OUString& rReferer, bo
 
 
 
-uno::Reference< media::XPlayer > MediaWindow::createPlayer( const OUString& rURL, const OUString& rReferer )
+uno::Reference< media::XPlayer > MediaWindow::createPlayer( const OUString& rURL, const OUString& rReferer, const OUString* pMimeType )
 {
-    return priv::MediaWindowImpl::createPlayer( rURL, rReferer );
+    return priv::MediaWindowImpl::createPlayer( rURL, rReferer, pMimeType );
 }
 
 
 
 uno::Reference< graphic::XGraphic > MediaWindow::grabFrame( const OUString& rURL,
                                                             const OUString& rReferer,
-                                                            bool bAllowToCreateReplacementGraphic,
+                                                            const OUString& sMimeType,
                                                             double fMediaTime )
 {
-    uno::Reference< media::XPlayer >    xPlayer( createPlayer( rURL, rReferer ) );
+    uno::Reference< media::XPlayer >    xPlayer( createPlayer( rURL, rReferer, &sMimeType ) );
     uno::Reference< graphic::XGraphic > xRet;
     boost::scoped_ptr< Graphic > apGraphic;
 
@@ -416,7 +416,7 @@ uno::Reference< graphic::XGraphic > MediaWindow::grabFrame( const OUString& rURL
             xRet = xGrabber->grabFrame( fMediaTime );
         }
 
-        if( !xRet.is() && bAllowToCreateReplacementGraphic  )
+        if( !xRet.is() )
         {
             awt::Size aPrefSize( xPlayer->getPreferredPlayerWindowSize() );
 
@@ -428,7 +428,7 @@ uno::Reference< graphic::XGraphic > MediaWindow::grabFrame( const OUString& rURL
         }
     }
 
-    if( !xRet.is() && !apGraphic.get() && bAllowToCreateReplacementGraphic )
+    if( !xRet.is() && !apGraphic.get() )
     {
         const BitmapEx aBmpEx( getEmptyLogo() );
         apGraphic.reset( new Graphic( aBmpEx ) );
diff --git a/avmedia/source/viewer/mediawindow_impl.cxx b/avmedia/source/viewer/mediawindow_impl.cxx
index f24c6e1..515580c 100644
--- a/avmedia/source/viewer/mediawindow_impl.cxx
+++ b/avmedia/source/viewer/mediawindow_impl.cxx
@@ -205,7 +205,7 @@ MediaWindowImpl::~MediaWindowImpl()
     delete mpMediaWindowControl;
 }
 
-uno::Reference< media::XPlayer > MediaWindowImpl::createPlayer( const OUString& rURL, const OUString& rReferer, OUString* pMimeType )
+uno::Reference< media::XPlayer > MediaWindowImpl::createPlayer( const OUString& rURL, const OUString& rReferer, const OUString* pMimeType )
 {
 
     uno::Reference< media::XPlayer > xPlayer;
diff --git a/avmedia/source/viewer/mediawindow_impl.hxx b/avmedia/source/viewer/mediawindow_impl.hxx
index e001863..317cea8 100644
--- a/avmedia/source/viewer/mediawindow_impl.hxx
+++ b/avmedia/source/viewer/mediawindow_impl.hxx
@@ -94,7 +94,7 @@ namespace avmedia
                             MediaWindowImpl( Window* parent, MediaWindow* pMediaWindow, bool bInternalMediaControl );
             virtual         ~MediaWindowImpl();
 
-            static ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > createPlayer( const OUString& rURL, const OUString& rReferer, OUString* pMimeType = 0 );
+            static ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > createPlayer( const OUString& rURL, const OUString& rReferer, const OUString* pMimeType = 0 );
 
             void    setURL( const OUString& rURL, OUString const& rTempURL, OUString const& rReferer );
 
diff --git a/include/avmedia/mediawindow.hxx b/include/avmedia/mediawindow.hxx
index 9357595..a42e95e 100644
--- a/include/avmedia/mediawindow.hxx
+++ b/include/avmedia/mediawindow.hxx
@@ -102,11 +102,10 @@ namespace avmedia
         static void         executeFormatErrorBox( Window* pParent );
         static bool         isMediaURL( const OUString& rURL, const OUString& rReferer, bool bDeep = false, Size* pPreferredSizePixel = NULL );
 
-        static ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > createPlayer( const OUString& rURL, const OUString& rReferer );
+        static ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > createPlayer( const OUString& rURL, const OUString& rReferer, const OUString* pMimeType = 0 );
 
         static ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > grabFrame( const OUString& rURL, const OUString& rReferer,
-                                                                                                  bool bAllowToCreateReplacementGraphic = false,
-                                                                                                  double fMediaTime = AVMEDIA_FRAMEGRABBER_DEFAULTFRAME );
+            const OUString& sMimeType, double fMediaTime = AVMEDIA_FRAMEGRABBER_DEFAULTFRAME );
 
         static BitmapEx getAudioLogo();
         static BitmapEx getEmptyLogo();
diff --git a/slideshow/source/engine/shapes/viewmediashape.cxx b/slideshow/source/engine/shapes/viewmediashape.cxx
index 135a372..22fa24e 100644
--- a/slideshow/source/engine/shapes/viewmediashape.cxx
+++ b/slideshow/source/engine/shapes/viewmediashape.cxx
@@ -191,11 +191,15 @@ namespace slideshow
             if( !mpMediaWindow.get() && !mxPlayerWindow.is() )
             {
                 OUString sURL;
+                OUString sMimeType;
                 uno::Reference< beans::XPropertySet > xPropSet( mxShape, uno::UNO_QUERY );
                 if (xPropSet.is())
+                {
                     xPropSet->getPropertyValue("PrivateTempFileURL") >>= sURL;
+                    xPropSet->getPropertyValue("MediaMimeType") >>= sMimeType;
+                }
 
-                const Graphic aGraphic(avmedia::MediaWindow::grabFrame(sURL,"", true));
+                const Graphic aGraphic(avmedia::MediaWindow::grabFrame(sURL,"",sMimeType));
                 const BitmapEx aBmp = aGraphic.GetBitmapEx();
 
                 uno::Reference< rendering::XBitmap > xBitmap(vcl::unotools::xBitmapFromBitmapEx(
diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx
index b7f5956..9ac85bb 100644
--- a/svx/source/svdraw/svdomedia.cxx
+++ b/svx/source/svdraw/svdomedia.cxx
@@ -171,7 +171,7 @@ uno::Reference< graphic::XGraphic > SdrMediaObj::getSnapshot()
         OUString aRealURL = m_pImpl->m_MediaProperties.getTempURL();
         if( aRealURL.isEmpty() )
             aRealURL = m_pImpl->m_MediaProperties.getURL();
-        m_pImpl->m_xCachedSnapshot = avmedia::MediaWindow::grabFrame( aRealURL, m_pImpl->m_MediaProperties.getReferer(), true );
+        m_pImpl->m_xCachedSnapshot = avmedia::MediaWindow::grabFrame( aRealURL, m_pImpl->m_MediaProperties.getReferer(), m_pImpl->m_MediaProperties.getMimeType());
     }
     return m_pImpl->m_xCachedSnapshot;
 }
commit 78609b36e0d61bd5535cfdc1ab2f1e0e59505042
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date:   Sun Apr 20 12:27:33 2014 +0200

    Patching libgltf: shader character buffers are used as c strings
    
    Change-Id: Ic0c2bd47ffd5bf2d12e2201063ca688712a5f9b3

diff --git a/external/libgltf/UnpackedTarball_libgltf.mk b/external/libgltf/UnpackedTarball_libgltf.mk
index e83486d..dd28b67 100644
--- a/external/libgltf/UnpackedTarball_libgltf.mk
+++ b/external/libgltf/UnpackedTarball_libgltf.mk
@@ -24,7 +24,8 @@ $(eval $(call gb_UnpackedTarball_add_patches,libgltf,\
 	external/libgltf/patches/include_typo_texture.patch \
 	external/libgltf/patches/adress_of_temporary.patch \
 	external/libgltf/patches/avoid_c++11.patch \
-	external/libgltf/patches/charbuffer_used_as_cstring.patch \
+	external/libgltf/patches/json_charbuffer_used_as_cstring.patch \
+	external/libgltf/patches/shader_charbuffer_used_as_cstring.patch \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/external/libgltf/patches/charbuffer_used_as_cstring.patch b/external/libgltf/patches/json_charbuffer_used_as_cstring.patch
similarity index 100%
rename from external/libgltf/patches/charbuffer_used_as_cstring.patch
rename to external/libgltf/patches/json_charbuffer_used_as_cstring.patch
diff --git a/external/libgltf/patches/shader_charbuffer_used_as_cstring.patch b/external/libgltf/patches/shader_charbuffer_used_as_cstring.patch
new file mode 100644
index 0000000..000796c
--- /dev/null
+++ b/external/libgltf/patches/shader_charbuffer_used_as_cstring.patch
@@ -0,0 +1,94 @@
+diff -ur libgltf.org/src/Common.cpp libgltf/src/Common.cpp
+--- libgltf.org/src/Common.cpp	2014-04-20 10:46:20.065036606 +0200
++++ libgltf/src/Common.cpp	2014-04-20 12:12:26.940821223 +0200
+@@ -521,8 +521,10 @@
+         if(vShaderIdx >= 0 && fShaderIdx >= 0)
+         {
+             const char* pvShader = pGltfHandle->files[vShaderIdx]->buffer;
++            size_t ivShaderSize = pGltfHandle->files[vShaderIdx]->size;
+             const char* pfShader = pGltfHandle->files[fShaderIdx]->buffer;
+-            mProgramId = mShaderProg.createProgram(pvShader, pfShader);
++            size_t ifShaderSize = pGltfHandle->files[fShaderIdx]->size;
++            mProgramId = mShaderProg.createProgram(pvShader, ivShaderSize, pfShader, ifShaderSize);
+         }
+         if (0 != mProgramId)
+         {
+diff -ur libgltf.org/src/Shaders.cpp libgltf/src/Shaders.cpp
+--- libgltf.org/src/Shaders.cpp	2014-04-20 10:46:20.065036606 +0200
++++ libgltf/src/Shaders.cpp	2014-04-20 12:15:42.683813064 +0200
+@@ -110,12 +110,12 @@
+ 	return programId;
+ }
+ 
+-unsigned int ShaderProgram::createProgram(const char* pvShader, const char* pfShader)
++unsigned int ShaderProgram::createProgram(const char* pvShader, size_t ivShaderSize, const char* pfShader, size_t ifShaderSize)
+ {
+     unsigned int programId = glCreateProgram();
+-    if (!loadShader(programId, pvShader, GL_VERTEX_SHADER))
++    if (!loadShader(programId, pvShader, ivShaderSize, GL_VERTEX_SHADER))
+         return 0;
+-    if (!loadShader(programId, pfShader, GL_FRAGMENT_SHADER))
++    if (!loadShader(programId, pfShader, ifShaderSize, GL_FRAGMENT_SHADER))
+         return 0;
+ 
+     return programId;
+@@ -142,7 +142,7 @@
+ 		return false;
+ 	}
+ 
+-	if (!compileShader(shaderCode.c_str(), shaderId))
++	if (!compileShader(shaderCode.c_str(), shader.length(), shaderId))
+ 	{
+ 		std::cout << "compileShader : compileShader failed." << std::endl;
+ 		return false;
+@@ -158,11 +158,11 @@
+ 	return true;
+ }
+ 
+-bool ShaderProgram::loadShader(unsigned int programId, const char* pShader, int type)
++bool ShaderProgram::loadShader(unsigned int programId, const char* pShader, size_t iSize, int type)
+ {
+     unsigned int shaderId = glCreateShader(type);
+ 
+-    if (!compileShader(pShader, shaderId))
++    if (!compileShader(pShader, iSize, shaderId))
+     {
+         std::cout << "compileShader : compileShader failed." << std::endl;
+         return false;
+@@ -178,9 +178,10 @@
+     return true;
+ }
+ 
+-bool ShaderProgram::compileShader(const char* pShader, unsigned int shaderId)
++bool ShaderProgram::compileShader(const char* pShader, size_t iSize, unsigned int shaderId)
+ {
+-	glShaderSource(shaderId, 1, &pShader, NULL);
++	GLint iGLSize = iSize;
++	glShaderSource(shaderId, 1, &pShader, &iGLSize);
+ 	glCompileShader(shaderId);
+ 	int iStatus = 0;
+ 	glGetShaderiv(shaderId, GL_COMPILE_STATUS, &iStatus);
+diff -ur libgltf.org/src/Shaders.h libgltf/src/Shaders.h
+--- libgltf.org/src/Shaders.h	2014-04-20 10:46:20.065036606 +0200
++++ libgltf/src/Shaders.h	2014-04-20 12:11:36.816823313 +0200
+@@ -39,17 +39,17 @@
+     void setUniform(unsigned int uProgId, const char* name, const glm::mat4 mMatrix);
+ 
+ 	unsigned int createProgram(const std::string& vName, const std::string& fName);
+-    unsigned int createProgram(const char* pvShader, const char* pfShader);
++    unsigned int createProgram(const char* pvShader, size_t ivShaderSize, const char* pfShader, size_t ifShaderSize);
+ 
+ 	void deleteProgram(unsigned int programId);
+ 
+ 	void useProgram(unsigned int programId);
+ 
+     bool loadShader(unsigned int programId, const std::string& shaderName, int type);
+-    bool loadShader(unsigned int programId, const char* pShader, int type);
++    bool loadShader(unsigned int programId, const char* pShader, size_t iSize, int type);
+ private:
+ 
+-	bool compileShader(const char* pShader, unsigned int shaderId);
++	bool compileShader(const char* pShader, size_t iSize, unsigned int shaderId);
+ 
+ 	bool linkProgram(unsigned int programId, unsigned int shaderId);
+ 


More information about the Libreoffice-commits mailing list