include/vcl/opengl/OpenGLContext.hxx |    9 +++
 vcl/source/opengl/OpenGLContext.cxx  |   94 +++++++++++++++++++++++------------
 2 files changed, 72 insertions(+), 31 deletions(-)

New commits:
commit bafc045bccffd2314d246f93d84dbaf80bf6eacc
Author: Markus Mohrhard <markus.mohrh...@collabora.co.uk>
Date:   Fri Oct 24 17:03:39 2014 +0200

    add a OpenGLContext::init for unix backend
    
    That one does not need the indirection through a Window instance to get
    to the X resources that are necessary for a GLX context.
    
    Change-Id: I3195a5f2b447172434881bd9b0b230c8992c1c87

diff --git a/include/vcl/opengl/OpenGLContext.hxx 
b/include/vcl/opengl/OpenGLContext.hxx
index 2c92103..a99e6c3 100644
--- a/include/vcl/opengl/OpenGLContext.hxx
+++ b/include/vcl/opengl/OpenGLContext.hxx
@@ -158,6 +158,12 @@ public:
     bool init(vcl::Window* pParent = 0);
     bool init(SystemChildWindow* pChildWindow);
 
+// these methods are for the deep platform layer, don't use them in normal code
+// only in vcl's platform code
+#if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
+    bool init(Display* dpy, Window win, int screen);
+#endif
+
     void makeCurrent();
     void resetCurrent();
     void swapBuffers();
diff --git a/vcl/source/opengl/OpenGLContext.cxx 
b/vcl/source/opengl/OpenGLContext.cxx
index e5b75c6..b29c7a1 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -428,6 +428,30 @@ GLXFBConfig* getFBConfig(Display* dpy, Window win, int& 
nBestFBC)
     return pFBC;
 }
 
+// we need them before glew can initialize them
+// glew needs an OpenGL context so we need to get the address manually
+void initOpenGLFunctionPointers()
+{
+    glXChooseFBConfig = (GLXFBConfig*(*)(Display *dpy, int screen, const int 
*attrib_list, int 
*nelements))glXGetProcAddressARB((GLubyte*)"glXChooseFBConfig");
+    glXGetVisualFromFBConfig = (XVisualInfo*(*)(Display *dpy, GLXFBConfig 
config))glXGetProcAddressARB((GLubyte*)"glXGetVisualFromFBConfig");    // try 
to find a visual for the current set of attributes
+    glXGetFBConfigAttrib = (int(*)(Display *dpy, GLXFBConfig config, int 
attribute, int* value))glXGetProcAddressARB((GLubyte*)"glXGetFBConfigAttrib");
+    glXCreateContextAttribsARB = (GLXContext(*) (Display*, GLXFBConfig, 
GLXContext, Bool, const int*)) glXGetProcAddressARB((const GLubyte *) 
"glXCreateContextAttribsARB");;
+}
+
+XVisualInfo* getVisualInfo(Display* dpy, Window win)
+{
+    initOpenGLFunctionPointers();
+
+    int best_fbc = -1;
+    GLXFBConfig* pFBC = getFBConfig(dpy, win, best_fbc);
+
+    XVisualInfo* vi = glXGetVisualFromFBConfig( dpy, pFBC[best_fbc] );
+
+    XFree(pFBC);
+
+    return vi;
+}
+
 }
 
 #endif
@@ -458,6 +482,33 @@ bool OpenGLContext::init(SystemChildWindow* pChildWindow)
     return ImplInit();
 }
 
+#if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
+bool OpenGLContext::init(Display* dpy, Window win, int screen)
+{
+    if(mbInitialized)
+        return true;
+
+    if (!dpy)
+        return false;
+
+    m_aGLWin.dpy = dpy;
+    m_aGLWin.win = win;
+    m_aGLWin.screen = screen;
+
+    XVisualInfo* vi = getVisualInfo(dpy, win);
+    Visual* pVisual = NULL;
+
+    if( vi )
+    {
+        SAL_INFO("vcl.opengl", "using VisualID " << vi->visualid);
+        pVisual = vi->visual;
+    }
+    initGLWindow(pVisual);
+
+    return ImplInit();
+}
+#endif
+
 bool OpenGLContext::ImplInit()
 {
     SAL_INFO("vcl.opengl", "OpenGLContext::ImplInit----start");
@@ -828,34 +879,6 @@ SystemWindowData 
OpenGLContext::generateWinData(vcl::Window* /*pParent*/, bool b
 
 #elif defined( UNX )
 
-namespace {
-
-// we need them before glew can initialize them
-// glew needs an OpenGL context so we need to get the address manually
-void initOpenGLFunctionPointers()
-{
-    glXChooseFBConfig = (GLXFBConfig*(*)(Display *dpy, int screen, const int 
*attrib_list, int 
*nelements))glXGetProcAddressARB((GLubyte*)"glXChooseFBConfig");
-    glXGetVisualFromFBConfig = (XVisualInfo*(*)(Display *dpy, GLXFBConfig 
config))glXGetProcAddressARB((GLubyte*)"glXGetVisualFromFBConfig");    // try 
to find a visual for the current set of attributes
-    glXGetFBConfigAttrib = (int(*)(Display *dpy, GLXFBConfig config, int 
attribute, int* value))glXGetProcAddressARB((GLubyte*)"glXGetFBConfigAttrib");
-    glXCreateContextAttribsARB = (GLXContext(*) (Display*, GLXFBConfig, 
GLXContext, Bool, const int*)) glXGetProcAddressARB((const GLubyte *) 
"glXCreateContextAttribsARB");;
-}
-
-}
-
-XVisualInfo* getVisualInfo(Display* dpy, Window win)
-{
-    initOpenGLFunctionPointers();
-
-    int best_fbc = -1;
-    GLXFBConfig* pFBC = getFBConfig(dpy, win, best_fbc);
-
-    XVisualInfo* vi = glXGetVisualFromFBConfig( dpy, pFBC[best_fbc] );
-
-    XFree(pFBC);
-
-    return vi;
-}
-
 SystemWindowData OpenGLContext::generateWinData(vcl::Window* pParent, bool)
 {
     SystemWindowData aWinData;
commit 2e24c7de8e185556fe7cb2bf013ff9019b08ca0c
Author: Markus Mohrhard <markus.mohrh...@collabora.co.uk>
Date:   Fri Oct 24 16:50:05 2014 +0200

    split method in part related to windows and other stuff
    
    Change-Id: Ie3851bfd558ffeabd374afdc2a4d4833e3866a6e

diff --git a/include/vcl/opengl/OpenGLContext.hxx 
b/include/vcl/opengl/OpenGLContext.hxx
index 4017923..2c92103 100644
--- a/include/vcl/opengl/OpenGLContext.hxx
+++ b/include/vcl/opengl/OpenGLContext.hxx
@@ -185,6 +185,9 @@ public:
 private:
     SAL_DLLPRIVATE bool initWindow();
     SAL_DLLPRIVATE bool ImplInit();
+#if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID
+    SAL_DLLPRIVATE void initGLWindow(Visual* pVisual);
+#endif
 
 #if defined(MACOSX)
     NSOpenGLView* getOpenGLView();
diff --git a/vcl/source/opengl/OpenGLContext.cxx 
b/vcl/source/opengl/OpenGLContext.cxx
index 0d7faff..e5b75c6 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -781,9 +781,16 @@ bool OpenGLContext::initWindow()
     m_aGLWin.win = pChildSysData->aWindow;
     m_aGLWin.screen = pChildSysData->nScreen;
 
+    Visual* pVisual = (Visual*)pChildSysData->pVisual;
+    initGLWindow(pVisual);
+
+    return true;
+}
+
+void OpenGLContext::initGLWindow(Visual* pVisual)
+{
     // Get visual info
     {
-        Visual* pVisual = (Visual*)pChildSysData->pVisual;
         XVisualInfo aTemplate;
         aTemplate.visualid = XVisualIDFromVisual( pVisual );
         int nVisuals = 0;
@@ -801,8 +808,6 @@ bool OpenGLContext::initWindow()
 
     m_aGLWin.GLXExtensions = glXQueryExtensionsString( m_aGLWin.dpy, 
m_aGLWin.screen );
     SAL_INFO("vcl.opengl", "available GLX extensions: " << 
m_aGLWin.GLXExtensions);
-
-    return true;
 }
 
 #endif
@@ -837,6 +842,20 @@ void initOpenGLFunctionPointers()
 
 }
 
+XVisualInfo* getVisualInfo(Display* dpy, Window win)
+{
+    initOpenGLFunctionPointers();
+
+    int best_fbc = -1;
+    GLXFBConfig* pFBC = getFBConfig(dpy, win, best_fbc);
+
+    XVisualInfo* vi = glXGetVisualFromFBConfig( dpy, pFBC[best_fbc] );
+
+    XFree(pFBC);
+
+    return vi;
+}
+
 SystemWindowData OpenGLContext::generateWinData(vcl::Window* pParent, bool)
 {
     SystemWindowData aWinData;
@@ -851,20 +870,14 @@ SystemWindowData 
OpenGLContext::generateWinData(vcl::Window* pParent, bool)
     if( dpy == 0 || !glXQueryExtension( dpy, NULL, NULL ) )
         return aWinData;
 
-    initOpenGLFunctionPointers();
+    XVisualInfo* vi = getVisualInfo(dpy, win);
 
-    int best_fbc = -1;
-    GLXFBConfig* pFBC = getFBConfig(dpy, win, best_fbc);
-
-    XVisualInfo* vi = glXGetVisualFromFBConfig( dpy, pFBC[best_fbc] );
     if( vi )
     {
         SAL_INFO("vcl.opengl", "using VisualID " << vi->visualid);
         aWinData.pVisual = (void*)(vi->visual);
     }
 
-    XFree(pFBC);
-
     return aWinData;
 }
 
commit de6e5170aa20eb17d174086b9784f0bf0a788305
Author: Markus Mohrhard <markus.mohrh...@collabora.co.uk>
Date:   Fri Oct 24 16:35:32 2014 +0200

    reduce one use of SystemWinData
    
    Change-Id: I777a8e324864ab9eab2a3df3e0645910dd1478a4

diff --git a/vcl/source/opengl/OpenGLContext.cxx 
b/vcl/source/opengl/OpenGLContext.cxx
index 79430ba..0d7faff 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -369,15 +369,11 @@ int oglErrorHandler( Display* /*dpy*/, XErrorEvent* 
/*evnt*/ )
     return 0;
 }
 
-GLXFBConfig* getFBConfig(const SystemEnvData* sysData, int& nBestFBC)
+GLXFBConfig* getFBConfig(Display* dpy, Window win, int& nBestFBC)
 {
-    Display *dpy = reinterpret_cast<Display*>(sysData->pDisplay);
-
     if( dpy == 0 || !glXQueryExtension( dpy, NULL, NULL ) )
         return NULL;
 
-    Window win = sysData->aWindow;
-
     SAL_INFO("vcl.opengl", "parent window: " << win);
 
     XWindowAttributes xattr;
@@ -490,8 +486,7 @@ bool OpenGLContext::ImplInit()
     if (glXCreateContextAttribsARB && !mbRequestLegacyContext)
     {
         int best_fbc = -1;
-        const SystemEnvData* sysData(m_pChildWindow->GetSystemData());
-        GLXFBConfig* pFBC = getFBConfig(sysData, best_fbc);
+        GLXFBConfig* pFBC = getFBConfig(m_aGLWin.dpy, m_aGLWin.win, best_fbc);
         if (!pFBC)
             return false;
 
@@ -851,6 +846,7 @@ SystemWindowData 
OpenGLContext::generateWinData(vcl::Window* pParent, bool)
     const SystemEnvData* sysData(pParent->GetSystemData());
 
     Display *dpy = reinterpret_cast<Display*>(sysData->pDisplay);
+    Window win = sysData->aWindow;
 
     if( dpy == 0 || !glXQueryExtension( dpy, NULL, NULL ) )
         return aWinData;
@@ -858,7 +854,7 @@ SystemWindowData 
OpenGLContext::generateWinData(vcl::Window* pParent, bool)
     initOpenGLFunctionPointers();
 
     int best_fbc = -1;
-    GLXFBConfig* pFBC = getFBConfig(sysData, best_fbc);
+    GLXFBConfig* pFBC = getFBConfig(dpy, win, best_fbc);
 
     XVisualInfo* vi = glXGetVisualFromFBConfig( dpy, pFBC[best_fbc] );
     if( vi )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to