diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-10-22 13:49:15 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-11-19 13:47:39 +0100 |
commit | 7070318e0f8dd1ef0c1168e1280ab7636da7332a (patch) | |
tree | 76d968676a9ac341e166d9c36e1d9ce4c8598c5b /chart2 | |
parent | e85751488d566622ddc5154095eac3e4215d14f4 (diff) |
it builds again
Change-Id: I969ff5ed6fd979e9fd126e8d0b79a518697e7915
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/Library_chartopengl.mk | 3 | ||||
-rw-r--r-- | chart2/source/view/inc/AbstractShapeFactory.hxx | 2 | ||||
-rw-r--r-- | chart2/source/view/inc/DummyXShape.hxx | 74 | ||||
-rw-r--r-- | chart2/source/view/inc/OpenglShapeFactory.hxx | 3 | ||||
-rw-r--r-- | chart2/source/view/inc/ShapeFactory.hxx | 2 | ||||
-rw-r--r-- | chart2/source/view/main/ChartView.cxx | 1 | ||||
-rw-r--r-- | chart2/source/view/main/DummyXShape.cxx | 359 | ||||
-rw-r--r-- | chart2/source/view/main/OpenglShapeFactory.cxx | 50 | ||||
-rw-r--r-- | chart2/source/view/main/ShapeFactory.cxx | 4 |
9 files changed, 496 insertions, 2 deletions
diff --git a/chart2/Library_chartopengl.mk b/chart2/Library_chartopengl.mk index 88c8e5f665ae..d1f2c4be434e 100644 --- a/chart2/Library_chartopengl.mk +++ b/chart2/Library_chartopengl.mk @@ -24,6 +24,7 @@ $(eval $(call gb_Library_use_libraries,chartopengl,\ cppu \ cppuhelper \ sal \ + vcl \ $(gb_UWINAPI) \ )) @@ -43,6 +44,8 @@ else ifeq ($(OS),LINUX) $(eval $(call gb_Library_add_libs,chartopengl,\ -ldl \ -lGL \ + -lGLU \ + -lX11 \ )) endif diff --git a/chart2/source/view/inc/AbstractShapeFactory.hxx b/chart2/source/view/inc/AbstractShapeFactory.hxx index 8dd8137acb8b..36b255457baa 100644 --- a/chart2/source/view/inc/AbstractShapeFactory.hxx +++ b/chart2/source/view/inc/AbstractShapeFactory.hxx @@ -227,6 +227,8 @@ public: getOrCreateChartRootShape( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage>& xPage ) = 0; + virtual void setPageSize( com::sun::star::uno::Reference < com::sun::star::drawing::XShapes > xChartShapes, const com::sun::star::awt::Size& rSize ) = 0; + virtual void createSeries( const com::sun::star::uno::Reference< com::sun::star::drawing::XShapes> & xTarget, diff --git a/chart2/source/view/inc/DummyXShape.hxx b/chart2/source/view/inc/DummyXShape.hxx index 924c43f98c8d..0d56924df1c6 100644 --- a/chart2/source/view/inc/DummyXShape.hxx +++ b/chart2/source/view/inc/DummyXShape.hxx @@ -56,6 +56,39 @@ #include <vector> #include <map> +#include <boost/scoped_ptr.hpp> + + +#include <GL/gl.h> +#include <GL/glu.h> +#include <vcl/window.hxx> +#include <vcl/syschild.hxx> +#include <vcl/sysdata.hxx> + +#if defined( _WIN32 ) + #include <GL/glu.h> + #include <GL/glext.h> + #include <GL/wglext.h> +#elif defined( MACOSX ) + #include "premac.h" + #include <Cocoa/Cocoa.h> + #include "postmac.h" +#elif defined( UNX ) + #include <GL/glu.h> + #include <GL/glext.h> + + namespace unx + { + #include <X11/keysym.h> + #include <X11/X.h> + #define GLX_GLXEXT_PROTOTYPES 1 + #include <GL/glx.h> + #include <GL/glxext.h> + } +#endif + +class SystemWindow; +class SystemChildWindow; using namespace com::sun::star; @@ -354,12 +387,53 @@ private: class DummyChart : public DummyXShapes { public: + DummyChart(); virtual DummyChart* getRootShape(); OpenglContext* getGlContext() { return mpContext; } + virtual void SAL_CALL setPosition( const ::com::sun::star::awt::Point& aPosition ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setSize( const ::com::sun::star::awt::Size& aSize ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException); + private: + + /// Holds the information of our new child window + struct GLWindow + { +#if defined( _WIN32 ) + HWND hWnd; + HDC hDC; + HGLRC hRC; +#elif defined( MACOSX ) +#elif defined( UNX ) + unx::Display* dpy; + int screen; + unx::Window win; +#if defined( GLX_VERSION_1_3 ) && defined( GLX_EXT_texture_from_pixmap ) + unx::GLXFBConfig fbc; +#endif + unx::XVisualInfo* vi; + unx::GLXContext ctx; + + bool HasGLXExtension( const char* name ) { return gluCheckExtension( (const GLubyte*) name, (const GLubyte*) GLXExtensions ); } + const char* GLXExtensions; +#endif + unsigned int bpp; + unsigned int Width; + unsigned int Height; + const GLubyte* GLExtensions; + + bool HasGLExtension( const char* name ) { return gluCheckExtension( (const GLubyte*) name, GLExtensions ); } + } GLWin; /// Holds the information of our new child window + + void createGLContext(); + + bool initWindow(); + bool initOpengl(); + OpenglContext* mpContext; + boost::scoped_ptr<Window> mpWindow; + boost::scoped_ptr<SystemChildWindow> pWindow; }; class DummyGroup2D : public DummyXShapes diff --git a/chart2/source/view/inc/OpenglShapeFactory.hxx b/chart2/source/view/inc/OpenglShapeFactory.hxx index 1dc444d6e8b6..7d8ebdc2b083 100644 --- a/chart2/source/view/inc/OpenglShapeFactory.hxx +++ b/chart2/source/view/inc/OpenglShapeFactory.hxx @@ -187,6 +187,9 @@ public: virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > getOrCreateChartRootShape( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage>& xPage ); + + virtual void setPageSize( com::sun::star::uno::Reference < com::sun::star::drawing::XShapes > xChartShapes, const com::sun::star::awt::Size& rSize ); + }; } diff --git a/chart2/source/view/inc/ShapeFactory.hxx b/chart2/source/view/inc/ShapeFactory.hxx index f2c662b044a3..78a441b36e36 100644 --- a/chart2/source/view/inc/ShapeFactory.hxx +++ b/chart2/source/view/inc/ShapeFactory.hxx @@ -203,6 +203,8 @@ public: getOrCreateChartRootShape( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage>& xPage ); + virtual void setPageSize( com::sun::star::uno::Reference < com::sun::star::drawing::XShapes > xChartShapes, const com::sun::star::awt::Size& rSize ); + private: ShapeFactory(); diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 387e840f0d82..8017109b5901 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -2398,6 +2398,7 @@ void ChartView::createShapes() { OSL_FAIL("could not set page size correctly"); } + pShapeFactory->setPageSize(xPageShapes, aPageSize); { SolarMutexGuard aSolarGuard; diff --git a/chart2/source/view/main/DummyXShape.cxx b/chart2/source/view/main/DummyXShape.cxx index 4d93079caf74..61860d01baed 100644 --- a/chart2/source/view/main/DummyXShape.cxx +++ b/chart2/source/view/main/DummyXShape.cxx @@ -11,6 +11,9 @@ #include "CommonConverters.hxx" #include <rtl/ustring.hxx> +#include <vcl/window.hxx> +#include <tools/gen.hxx> + #include <algorithm> using namespace com::sun::star; @@ -462,6 +465,362 @@ uno::Any DummyXShapes::getByIndex(sal_Int32 nIndex) return aShape; } +bool DummyChart::initWindow() +{ + const SystemEnvData* sysData(mpWindow->GetSystemData()); +#if defined( WNT ) + GLWin.hWnd = sysData->hWnd; +#elif defined( UNX ) + GLWin.dpy = reinterpret_cast<unx::Display*>(sysData->pDisplay); + + if( unx::glXQueryExtension( GLWin.dpy, NULL, NULL ) == false ) + return false; + + GLWin.win = sysData->aWindow; + + OSL_TRACE("parent window: %d", GLWin.win); + + unx::XWindowAttributes xattr; + unx::XGetWindowAttributes( GLWin.dpy, GLWin.win, &xattr ); + + GLWin.screen = XScreenNumberOfScreen( xattr.screen ); + + unx::XVisualInfo* vi( NULL ); +#if defined( GLX_VERSION_1_3 ) && defined( GLX_EXT_texture_from_pixmap ) + unx::XVisualInfo* visinfo; + unx::XVisualInfo* firstVisual( NULL ); +#endif + static int attrList3[] = + { + GLX_RGBA,//only TrueColor or DirectColor + //single buffered + GLX_RED_SIZE,4,//use the maximum red bits, with a minimum of 4 bits + GLX_GREEN_SIZE,4,//use the maximum green bits, with a minimum of 4 bits + GLX_BLUE_SIZE,4,//use the maximum blue bits, with a minimum of 4 bits + GLX_DEPTH_SIZE,0,//no depth buffer + None + }; + static int attrList2[] = + { + GLX_RGBA,//only TrueColor or DirectColor + /// single buffered + GLX_RED_SIZE,4,/// use the maximum red bits, with a minimum of 4 bits + GLX_GREEN_SIZE,4,/// use the maximum green bits, with a minimum of 4 bits + GLX_BLUE_SIZE,4,/// use the maximum blue bits, with a minimum of 4 bits + GLX_DEPTH_SIZE,1,/// use the maximum depth bits, making sure there is a depth buffer + None + }; + static int attrList1[] = + { + GLX_RGBA,//only TrueColor or DirectColor + GLX_DOUBLEBUFFER,/// only double buffer + GLX_RED_SIZE,4,/// use the maximum red bits, with a minimum of 4 bits + GLX_GREEN_SIZE,4,/// use the maximum green bits, with a minimum of 4 bits + GLX_BLUE_SIZE,4,/// use the maximum blue bits, with a minimum of 4 bits + GLX_DEPTH_SIZE,0,/// no depth buffer + None + }; + static int attrList0[] = + { + GLX_RGBA,//only TrueColor or DirectColor + GLX_DOUBLEBUFFER,/// only double buffer + GLX_RED_SIZE,4,/// use the maximum red bits, with a minimum of 4 bits + GLX_GREEN_SIZE,4,/// use the maximum green bits, with a minimum of 4 bits + GLX_BLUE_SIZE,4,/// use the maximum blue bits, with a minimum of 4 bits + GLX_DEPTH_SIZE,1,/// use the maximum depth bits, making sure there is a depth buffer + None + }; + static int* attrTable[] = + { + attrList0, + attrList1, + attrList2, + attrList3, + NULL + }; + int** pAttributeTable = attrTable; + const SystemEnvData* pChildSysData = NULL; + pWindow.reset(); + +#if defined( GLX_VERSION_1_3 ) && defined( GLX_EXT_texture_from_pixmap ) + unx::GLXFBConfig* fbconfigs = NULL; + int nfbconfigs, value, i = 0; +#endif + + while( *pAttributeTable ) + { + // try to find a visual for the current set of attributes + vi = unx::glXChooseVisual( GLWin.dpy, + GLWin.screen, + *pAttributeTable ); + +#if defined( GLX_VERSION_1_3 ) && defined( GLX_EXT_texture_from_pixmap ) + if( vi ) { + if( !firstVisual ) + firstVisual = vi; + OSL_TRACE("trying VisualID %08X", vi->visualid); + fbconfigs = glXGetFBConfigs (GLWin.dpy, GLWin.screen, &nfbconfigs); + + for ( ; i < nfbconfigs; i++) + { + visinfo = glXGetVisualFromFBConfig (GLWin.dpy, fbconfigs[i]); + if( !visinfo || visinfo->visualid != vi->visualid ) + continue; + + glXGetFBConfigAttrib (GLWin.dpy, fbconfigs[i], GLX_DRAWABLE_TYPE, &value); + if (!(value & GLX_PIXMAP_BIT)) + continue; + + glXGetFBConfigAttrib (GLWin.dpy, fbconfigs[i], + GLX_BIND_TO_TEXTURE_TARGETS_EXT, + &value); + if (!(value & GLX_TEXTURE_2D_BIT_EXT)) + continue; + + glXGetFBConfigAttrib (GLWin.dpy, fbconfigs[i], + GLX_BIND_TO_TEXTURE_RGB_EXT, + &value); + if (value == sal_False) + continue; + + glXGetFBConfigAttrib (GLWin.dpy, fbconfigs[i], + GLX_BIND_TO_MIPMAP_TEXTURE_EXT, + &value); + if (value == sal_False) + continue; + + // TODO: handle non Y inverted cases + break; + } + + if( i != nfbconfigs || ( firstVisual && pAttributeTable[1] == NULL ) ) { + if( i != nfbconfigs ) { + vi = glXGetVisualFromFBConfig( GLWin.dpy, fbconfigs[i] ); + // TODO:moggi + // mbHasTFPVisual = true; + OSL_TRACE("found visual suitable for texture_from_pixmap"); + } else { + vi = firstVisual; + // TODO:moggi + // mbHasTFPVisual = false; + OSL_TRACE("did not find visual suitable for texture_from_pixmap, using %08X", vi->visualid); + } +#else + if( vi ) { +#endif + SystemWindowData winData; + winData.nSize = sizeof(winData); + OSL_TRACE("using VisualID %08X", vi->visualid); + winData.pVisual = (void*)(vi->visual); + pWindow.reset(new SystemChildWindow(mpWindow.get(), 0, &winData, sal_False)); + pChildSysData = pWindow->GetSystemData(); + + if( pChildSysData ) { + break; + } else { + pWindow.reset(); + } + } +#if defined( GLX_VERSION_1_3 ) && defined( GLX_EXT_texture_from_pixmap ) + } +#endif + + ++pAttributeTable; + } +#endif + +#if defined( WNT ) + SystemWindowData winData; + winData.nSize = sizeof(winData); + pWindow.reset(new SystemChildWindow(mpWindow.get(), 0, &winData, sal_False)); +#endif + + if( pWindow ) + { + pWindow->SetMouseTransparent( sal_True ); + pWindow->SetParentClipMode( PARENTCLIPMODE_NOCLIP ); + pWindow->EnableEraseBackground( sal_False ); + pWindow->SetControlForeground(); + pWindow->SetControlBackground(); + pWindow->EnablePaint(sal_False); +#if defined( WNT ) + GLWin.hWnd = sysData->hWnd; +#elif defined( UNX ) + GLWin.dpy = reinterpret_cast<unx::Display*>(pChildSysData->pDisplay); + GLWin.win = pChildSysData->aWindow; +#if defined( GLX_VERSION_1_3 ) && defined( GLX_EXT_texture_from_pixmap ) + //TODO: moggi + /* + if( mbHasTFPVisual ) + GLWin.fbc = fbconfigs[i]; + */ +#endif + GLWin.vi = vi; + GLWin.GLXExtensions = unx::glXQueryExtensionsString( GLWin.dpy, GLWin.screen ); + OSL_TRACE("available GLX extensions: %s", GLWin.GLXExtensions); +#endif + + return false; + } + + return true; +} + +namespace { + +static bool errorTriggered; +int oglErrorHandler( unx::Display* /*dpy*/, unx::XErrorEvent* /*evnt*/ ) +{ + errorTriggered = true; + + return 0; +} + +} + +bool DummyChart::initOpengl() +{ + mpWindow->setPosSizePixel(0,0,0,0); + GLWin.Width = 0; + GLWin.Height = 0; + +#if defined( WNT ) + GLWin.hDC = GetDC(GLWin.hWnd); +#elif defined( UNX ) + GLWin.ctx = glXCreateContext(GLWin.dpy, + GLWin.vi, + 0, + GL_TRUE); + if( GLWin.ctx == NULL ) + { + OSL_TRACE("unable to create GLX context"); + return false; + } +#endif + +#if defined( WNT ) + PIXELFORMATDESCRIPTOR PixelFormatFront = // PixelFormat Tells Windows How We Want Things To Be + { + sizeof(PIXELFORMATDESCRIPTOR), + 1, // Version Number + PFD_DRAW_TO_WINDOW | + PFD_SUPPORT_OPENGL | + PFD_DOUBLEBUFFER, + PFD_TYPE_RGBA, // Request An RGBA Format + (BYTE)32, // Select Our Color Depth + 0, 0, 0, 0, 0, 0, // Color Bits Ignored + 0, // No Alpha Buffer + 0, // Shift Bit Ignored + 0, // No Accumulation Buffer + 0, 0, 0, 0, // Accumulation Bits Ignored + 64, // 32 bit Z-BUFFER + 0, // 0 bit stencil buffer + 0, // No Auxiliary Buffer + 0, // now ignored + 0, // Reserved + 0, 0, 0 // Layer Masks Ignored + }; + int WindowPix = ChoosePixelFormat(GLWin.hDC,&PixelFormatFront); + SetPixelFormat(GLWin.hDC,WindowPix,&PixelFormatFront); + GLWin.hRC = wglCreateContext(GLWin.hDC); + wglMakeCurrent(GLWin.hDC,GLWin.hRC); +#elif defined( UNX ) + if( !glXMakeCurrent( GLWin.dpy, GLWin.win, GLWin.ctx ) ) + { + OSL_TRACE("unable to select current GLX context"); + return false; + } + + int glxMinor, glxMajor; + double nGLXVersion = 0; + if( glXQueryVersion( GLWin.dpy, &glxMajor, &glxMinor ) ) + nGLXVersion = glxMajor + 0.1*glxMinor; + OSL_TRACE("available GLX version: %f", nGLXVersion); + + GLWin.GLExtensions = glGetString( GL_EXTENSIONS ); + OSL_TRACE("available GL extensions: %s", GLWin.GLExtensions); + + // TODO: moggi + // mbTextureFromPixmap = GLWin.HasGLXExtension( "GLX_EXT_texture_from_pixmap" ); + // mbGenerateMipmap = GLWin.HasGLExtension( "GL_SGIS_generate_mipmap" ); + + if( GLWin.HasGLXExtension("GLX_SGI_swap_control" ) ) + { + // enable vsync + typedef GLint (*glXSwapIntervalProc)(GLint); + glXSwapIntervalProc glXSwapInterval = (glXSwapIntervalProc) unx::glXGetProcAddress( (const GLubyte*) "glXSwapIntervalSGI" ); + if( glXSwapInterval ) { + int (*oldHandler)(unx::Display* /*dpy*/, unx::XErrorEvent* /*evnt*/); + + // replace error handler temporarily + oldHandler = unx::XSetErrorHandler( oglErrorHandler ); + + errorTriggered = false; + + glXSwapInterval( 1 ); + + // sync so that we possibly get an XError + unx::glXWaitGL(); + XSync(GLWin.dpy, false); + + if( errorTriggered ) + OSL_TRACE("error when trying to set swap interval, NVIDIA or Mesa bug?"); + else + OSL_TRACE("set swap interval to 1 (enable vsync)"); + + // restore the error handler + unx::XSetErrorHandler( oldHandler ); + } + } +#endif + + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + glClearColor (0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT); +#if defined( WNT ) + SwapBuffers(GLWin.hDC); +#elif defined( UNX ) + unx::glXSwapBuffers(GLWin.dpy, GLWin.win); +#endif + + glEnable(GL_LIGHTING); + GLfloat light_direction[] = { 0.0 , 0.0 , 1.0 }; + GLfloat materialDiffuse[] = { 1.0 , 1.0 , 1.0 , 1.0}; + glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_direction); + glMaterialfv(GL_FRONT,GL_DIFFUSE,materialDiffuse); + glEnable(GL_LIGHT0); + glEnable(GL_NORMALIZE); + + return true; +} + +DummyChart::DummyChart(): + mpWindow(new Window(0, WB_NOBORDER|WB_NODIALOGCONTROL)) +{ + setName("com.sun.star.chart2.shapes"); + createGLContext(); +} + +void DummyChart::createGLContext() +{ + +} + +void DummyChart::setPosition( const awt::Point& aPosition ) + throw( uno::RuntimeException ) +{ + DummyXShape::setPosition(aPosition); +} + +void DummyChart::setSize( const awt::Size& aSize ) + throw( beans::PropertyVetoException, uno::RuntimeException ) +{ + DummyXShape::setSize(aSize); + mpWindow->SetSizePixel(Size(aSize.Width, aSize.Height)); + pWindow->SetSizePixel(Size(aSize.Width, aSize.Height)); +} + } } diff --git a/chart2/source/view/main/OpenglShapeFactory.cxx b/chart2/source/view/main/OpenglShapeFactory.cxx index 4a45466d5810..e535a25c79b1 100644 --- a/chart2/source/view/main/OpenglShapeFactory.cxx +++ b/chart2/source/view/main/OpenglShapeFactory.cxx @@ -77,10 +77,56 @@ using dummy::DummyCone; namespace opengl { +namespace { + +uno::Reference< drawing::XShapes > getChartShape( + const uno::Reference< drawing::XDrawPage>& xDrawPage ) +{ + uno::Reference< drawing::XShapes > xRet; + uno::Reference< drawing::XShapes > xShapes( xDrawPage, uno::UNO_QUERY ); + if( xShapes.is() ) + { + sal_Int32 nCount = xShapes->getCount(); + uno::Reference< drawing::XShape > xShape; + for( sal_Int32 nN = nCount; nN--; ) + { + if( xShapes->getByIndex( nN ) >>= xShape ) + { + + OUString aRet; + + uno::Reference< beans::XPropertySet > xProp( xShape, uno::UNO_QUERY ); + xProp->getPropertyValue( UNO_NAME_MISC_OBJ_NAME ) >>= aRet; + if( aRet.equals("com.sun.star.chart2.shapes") ) + { + xRet = uno::Reference< drawing::XShapes >( xShape, uno::UNO_QUERY ); + break; + } + } + } + } + return xRet; +} + +} + uno::Reference< drawing::XShapes > OpenglShapeFactory::getOrCreateChartRootShape( - const uno::Reference< drawing::XDrawPage>& ) + const uno::Reference< drawing::XDrawPage>& xDrawPage ) +{ + uno::Reference< drawing::XShapes > xRet( getChartShape( xDrawPage ) ); + if( !xRet.is() ) + { + //create the root shape + xRet = new dummy::DummyChart(); + xDrawPage->add(uno::Reference< drawing::XShape >(xRet, uno::UNO_QUERY_THROW)); + } + return xRet; +} + +void OpenglShapeFactory::setPageSize( uno::Reference < drawing::XShapes > xChartShapes, const awt::Size& rSize ) { - return new dummy::DummyChart(); + uno::Reference< drawing::XShape > xShape(xChartShapes, uno::UNO_QUERY_THROW); + xShape->setSize(rSize); } // methods for 3D shape creation diff --git a/chart2/source/view/main/ShapeFactory.cxx b/chart2/source/view/main/ShapeFactory.cxx index 2bf11e4e1c39..17a89cb9cef5 100644 --- a/chart2/source/view/main/ShapeFactory.cxx +++ b/chart2/source/view/main/ShapeFactory.cxx @@ -74,6 +74,10 @@ uno::Reference< drawing::XShapes > ShapeFactory::getOrCreateChartRootShape( return xRet; } +void ShapeFactory::setPageSize(uno::Reference< drawing::XShapes >, const awt::Size& ) +{ +} + // diverse PolyPolygon create methods uno::Any createPolyPolygon_Cube( |