From 56d2cab4704f079ca173d65619432665bc1a1c92 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Fri, 20 May 2016 15:20:41 +0100 Subject: split GLWindow into platform dependent parts and move to respective backends MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I636d9bdac907000e4089aebdc5548ea89ec58083 Reviewed-on: https://gerrit.libreoffice.org/25252 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- include/vcl/opengl/OpenGLContext.hxx | 82 +++--------------------------------- vcl/headless/svpinst.cxx | 4 ++ vcl/inc/unx/saldisp.hxx | 19 +++++++++ vcl/inc/win/salgdi.h | 5 +++ vcl/opengl/win/gdiimpl.cxx | 42 +++++++++++++----- vcl/opengl/x11/gdiimpl.cxx | 29 +++++++++++-- vcl/osx/salobj.cxx | 3 ++ vcl/source/opengl/OpenGLContext.cxx | 28 ++++-------- vcl/unx/generic/window/salframe.cxx | 2 +- vcl/win/gdi/winlayout.cxx | 13 ------ 10 files changed, 105 insertions(+), 122 deletions(-) diff --git a/include/vcl/opengl/OpenGLContext.hxx b/include/vcl/opengl/OpenGLContext.hxx index 10024b3152e5..7b91620711a8 100644 --- a/include/vcl/opengl/OpenGLContext.hxx +++ b/include/vcl/opengl/OpenGLContext.hxx @@ -14,37 +14,6 @@ #include -#if defined( MACOSX ) -#elif defined( IOS ) -#elif defined( ANDROID ) -#elif defined( LIBO_HEADLESS ) -#elif defined( UNX ) -# include -# include -# include "GL/glxew.h" -#elif defined( _WIN32 ) -#ifndef INCLUDED_PRE_POST_WIN_H -#define INCLUDED_PRE_POST_WIN_H -# include "prewin.h" -# include "postwin.h" -#endif -#endif - -#if defined( _WIN32 ) -#include -#elif defined( MACOSX ) -#include -#ifdef __OBJC__ -@class NSOpenGLView; -#else -class NSOpenGLView; -#endif -#elif defined( IOS ) -#elif defined( ANDROID ) -#elif defined( LIBO_HEADLESS ) -#elif defined( UNX ) -#endif - #include #include #include @@ -67,57 +36,20 @@ class RenderState; /// Holds the information of our new child window struct VCL_DLLPUBLIC GLWindow { -#if defined( _WIN32 ) - HWND hWnd; - HDC hDC; - HGLRC hRC; -#elif defined( MACOSX ) -#elif defined( IOS ) -#elif defined( ANDROID ) -#elif defined( LIBO_HEADLESS ) -#elif defined( UNX ) - Display* dpy; - int screen; - Window win; - XVisualInfo* vi; - GLXContext ctx; - - bool HasGLXExtension( const char* name ) const; - const char* GLXExtensions; -#endif unsigned int Width; unsigned int Height; - const GLubyte* GLExtensions; bool bMultiSampleSupported; GLWindow() - : -#if defined( _WIN32 ) - hWnd(NULL), - hDC(NULL), - hRC(NULL), -#elif defined( MACOSX ) -#elif defined( IOS ) -#elif defined( ANDROID ) -#elif defined( LIBO_HEADLESS ) -#elif defined( UNX ) - dpy(nullptr), - screen(0), - win(0), - vi(nullptr), - ctx(nullptr), - GLXExtensions(nullptr), -#endif - Width(0), - Height(0), - GLExtensions(nullptr), - bMultiSampleSupported(false) + : Width(0) + , Height(0) + , bMultiSampleSupported(false) { } - bool Synchronize(bool bOnoff) const; + virtual bool Synchronize(bool bOnoff) const; - ~GLWindow(); + virtual ~GLWindow(); }; class VCL_DLLPUBLIC OpenGLContext @@ -189,7 +121,7 @@ public: void setWinPosAndSize(const Point &rPos, const Size& rSize); void setWinSize(const Size& rSize); - const GLWindow& getOpenGLWindow() const; + virtual const GLWindow& getOpenGLWindow() const = 0; SystemChildWindow* getChildWindow(); const SystemChildWindow* getChildWindow() const; @@ -212,11 +144,11 @@ private: virtual void destroyCurrentContext(); protected: - GLWindow m_aGLWin; bool InitGLEW(); void InitGLEWDebugging(); void InitChildWindow(SystemChildWindow *pChildWindow); void BuffersSwapped(); + virtual GLWindow& getModifiableOpenGLWindow() = 0; virtual bool ImplInit(); VclPtr m_xWindow; diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx index 2665bb509d70..c3aad0395345 100644 --- a/vcl/headless/svpinst.cxx +++ b/vcl/headless/svpinst.cxx @@ -447,6 +447,10 @@ void SvpSalInstance::AddToRecentDocumentList(const OUString&, const OUString&, c //obviously doesn't actually do anything, its just a nonfunctional stub class SvpOpenGLContext : public OpenGLContext { + GLWindow m_aGLWin; +private: + virtual const GLWindow& getOpenGLWindow() const { return m_aGLWin; } + virtual GLWindow& getModifiableOpenGLWindow() { return m_aGLWin; } }; OpenGLContext* SvpSalInstance::CreateOpenGLContext() diff --git a/vcl/inc/unx/saldisp.hxx b/vcl/inc/unx/saldisp.hxx index e191ebfa3ae5..426a0d028d7d 100644 --- a/vcl/inc/unx/saldisp.hxx +++ b/vcl/inc/unx/saldisp.hxx @@ -28,9 +28,11 @@ class SalXLib; #include #include #include +#include "GL/glxew.h" #include #include +#include #include #include #include @@ -184,6 +186,23 @@ extern "C" { typedef Bool(*X_if_predicate)(Display*,XEvent*,XPointer); } +class VCLPLUG_GEN_PUBLIC GLX11Window : public GLWindow +{ +public: + Display* dpy; + int screen; + Window win; + XVisualInfo* vi; + GLXContext ctx; + const char* GLXExtensions; + + bool HasGLXExtension(const char* name) const; + + GLX11Window(); + virtual bool Synchronize(bool bOnoff) const override; + ~GLX11Window(); +}; + class VCLPLUG_GEN_PUBLIC SalDisplay : public SalGenericDisplay { public: diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h index 182f666855f8..d2a81624cb4a 100644 --- a/vcl/inc/win/salgdi.h +++ b/vcl/inc/win/salgdi.h @@ -38,6 +38,11 @@ # include # include #endif +#ifndef INCLUDED_PRE_POST_WIN_H +#define INCLUDED_PRE_POST_WIN_H +# include "prewin.h" +# include "postwin.h" +#endif class FontSelectPattern; class WinFontInstance; diff --git a/vcl/opengl/win/gdiimpl.cxx b/vcl/opengl/win/gdiimpl.cxx index 50fb3928600e..1f6b044d9a64 100644 --- a/vcl/opengl/win/gdiimpl.cxx +++ b/vcl/opengl/win/gdiimpl.cxx @@ -13,15 +13,35 @@ #include #include #include +#include static std::vector g_vShareList; +class GLWinWindow : public GLWindow +{ +public: + HWND hWnd; + HDC hDC; + HGLRC hRC; + GLWinWindow(); +}; + +GLWinWindow::GLWinWindow() + : hWnd(NULL) + , hDC(NULL) + , hRC(NULL) +{ +} + class WinOpenGLContext : public OpenGLContext { public: bool init( HDC hDC, HWND hWnd ); virtual bool initWindow() override; private: + GLWinWindow m_aGLWin; + virtual const GLWindow& getOpenGLWindow() const { return m_aGLWin; } + virtual GLWindow& getModifiableOpenGLWindow() { return m_aGLWin; } virtual bool ImplInit() override; virtual void makeCurrent() override; virtual void destroyCurrentContext() override; @@ -150,7 +170,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM l } } -int InitTempWindow(HWND *hwnd, int width, int height, const PIXELFORMATDESCRIPTOR& inPfd, GLWindow& glWin) +int InitTempWindow(HWND *hwnd, int width, int height, const PIXELFORMATDESCRIPTOR& inPfd, GLWinWindow& glWin) { OpenGLZone aZone; @@ -239,7 +259,7 @@ bool InitMultisample(const PIXELFORMATDESCRIPTOR& pfd, int& rPixelFormat, OpenGLZone aZone; HWND hWnd = NULL; - GLWindow glWin; + GLWinWindow glWin; // Create a temp window to check whether support multi-sample, if support, get the format if (InitTempWindow(&hWnd, 1, 1, pfd, glWin) < 0) { @@ -507,15 +527,17 @@ rtl::Reference WinOpenGLSalGraphicsImpl::CreateWinContext() void WinOpenGLSalGraphicsImpl::Init() { - if ( !IsOffscreen() && mpContext.is() && mpContext->isInitialized() && - ( mpContext->getOpenGLWindow().hWnd != mrParent.mhWnd || - mpContext->getOpenGLWindow().hDC == mrParent.mhLocalDC ) ) + if (!IsOffscreen() && mpContext.is() && mpContext->isInitialized()) { - // This can legitimately happen, SalFrame keeps 2x - // SalGraphics which share the same hWnd and hDC. - // The shape 'Area' dialog does reparenting to trigger this. - SAL_WARN("vcl.opengl", "Unusual: Windows handle / DC changed without DeInit"); - DeInit(); + const GLWinWindow& rGLWindow = static_cast(mpContext->getOpenGLWindow()); + if (rGLWindow.hWnd != mrParent.mhWnd || rGLWindow.hDC == mrParent.mhLocalDC) + { + // This can legitimately happen, SalFrame keeps 2x + // SalGraphics which share the same hWnd and hDC. + // The shape 'Area' dialog does reparenting to trigger this. + SAL_WARN("vcl.opengl", "Unusual: Windows handle / DC changed without DeInit"); + DeInit(); + } } OpenGLSalGraphicsImpl::Init(); diff --git a/vcl/opengl/x11/gdiimpl.cxx b/vcl/opengl/x11/gdiimpl.cxx index f3626050f888..a4b2a8c9757f 100644 --- a/vcl/opengl/x11/gdiimpl.cxx +++ b/vcl/opengl/x11/gdiimpl.cxx @@ -39,6 +39,9 @@ public: bool init(Display* dpy, Window win, int screen); virtual bool initWindow() override; private: + GLX11Window m_aGLWin; + virtual const GLWindow& getOpenGLWindow() const { return m_aGLWin; } + virtual GLWindow& getModifiableOpenGLWindow() { return m_aGLWin; } virtual bool ImplInit() override; void initGLWindow(Visual* pVisual); virtual SystemWindowData generateWinData(vcl::Window* pParent, bool bRequestLegacyContext) override; @@ -362,8 +365,7 @@ bool X11OpenGLContext::ImplInit() nGLXVersion = glxMajor + 0.1*glxMinor; SAL_INFO("vcl.opengl", "available GLX version: " << nGLXVersion); - m_aGLWin.GLExtensions = glGetString( GL_EXTENSIONS ); - SAL_INFO("vcl.opengl", "available GL extensions: " << m_aGLWin.GLExtensions); + SAL_INFO("vcl.opengl", "available GL extensions: " << glGetString(GL_EXTENSIONS)); XWindowAttributes aWinAttr; if( !XGetWindowAttributes( m_aGLWin.dpy, m_aGLWin.win, &aWinAttr ) ) @@ -565,11 +567,32 @@ static GLboolean checkExtension(const GLubyte* extName, const GLubyte* extString return flag; } -bool GLWindow::HasGLXExtension( const char* name ) const +GLX11Window::GLX11Window() + : dpy(nullptr) + , screen(0) + , win(0) + , vi(nullptr) + , ctx(nullptr) + , GLXExtensions(nullptr) +{ +} + +bool GLX11Window::HasGLXExtension( const char* name ) const { return checkExtension( reinterpret_cast(name), reinterpret_cast(GLXExtensions) ); } +GLX11Window::~GLX11Window() +{ + XFree(vi); +} + +bool GLX11Window::Synchronize(bool bOnoff) const +{ + XSynchronize(dpy, bOnoff); + return true; +} + OpenGLContext* X11SalInstance::CreateOpenGLContext() { return new X11OpenGLContext; diff --git a/vcl/osx/salobj.cxx b/vcl/osx/salobj.cxx index 6bbb43aa51a8..e25c1a1d1694 100644 --- a/vcl/osx/salobj.cxx +++ b/vcl/osx/salobj.cxx @@ -236,6 +236,9 @@ class AquaOpenGLContext : public OpenGLContext public: virtual bool initWindow() override; private: + GLWindow m_aGLWin; + virtual const GLWindow& getOpenGLWindow() const { return m_aGLWin; } + virtual GLWindow& getModifiableOpenGLWindow() { return m_aGLWin; } NSOpenGLView* getOpenGLView(); virtual bool ImplInit() override; virtual SystemWindowData generateWinData(vcl::Window* pParent, bool bRequestLegacyContext) override; diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index b5e0a305d9f6..29e543611bf3 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -41,20 +41,11 @@ static sal_Int64 nBufferSwapCounter = 0; GLWindow::~GLWindow() { -#if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS) - XFree(vi); -#endif } -bool GLWindow::Synchronize(bool bOnoff) const +bool GLWindow::Synchronize(bool /*bOnoff*/) const { -#if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS) - XSynchronize(dpy, bOnoff); - return true; -#else - (void)bOnoff; return false; -#endif } OpenGLContext::OpenGLContext(): @@ -335,8 +326,9 @@ void OpenGLContext::setWinPosAndSize(const Point &rPos, const Size& rSize) if( m_pChildWindow ) m_pChildWindow->SetPosSizePixel(rPos, rSize); - m_aGLWin.Width = rSize.Width(); - m_aGLWin.Height = rSize.Height(); + GLWindow& rGLWin = getModifiableOpenGLWindow(); + rGLWin.Width = rSize.Width(); + rGLWin.Height = rSize.Height(); } void OpenGLContext::setWinSize(const Size& rSize) @@ -346,8 +338,9 @@ void OpenGLContext::setWinSize(const Size& rSize) if( m_pChildWindow ) m_pChildWindow->SetSizePixel(rSize); - m_aGLWin.Width = rSize.Width(); - m_aGLWin.Height = rSize.Height(); + GLWindow& rGLWin = getModifiableOpenGLWindow(); + rGLWin.Width = rSize.Width(); + rGLWin.Height = rSize.Height(); } void OpenGLContext::InitChildWindow(SystemChildWindow *pChildWindow) @@ -599,7 +592,7 @@ const SystemChildWindow* OpenGLContext::getChildWindow() const bool OpenGLContext::supportMultiSampling() const { - return m_aGLWin.bMultiSampleSupported; + return getOpenGLWindow().bMultiSampleSupported; } bool OpenGLContext::BindFramebuffer( OpenGLFramebuffer* pFramebuffer ) @@ -836,9 +829,4 @@ void OpenGLContext::UseNoProgram() CHECK_GL_ERROR(); } -const GLWindow& OpenGLContext::getOpenGLWindow() const -{ - return m_aGLWin; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/window/salframe.cxx b/vcl/unx/generic/window/salframe.cxx index 2197e3824e78..061abbf9dff7 100644 --- a/vcl/unx/generic/window/salframe.cxx +++ b/vcl/unx/generic/window/salframe.cxx @@ -891,7 +891,7 @@ X11SalFrame::~X11SalFrame() rtl::Reference pContext = ImplGetSVData()->maGDIData.mpLastContext; while( pContext.is() ) { - if( pContext->getOpenGLWindow().win == mhWindow ) + if (static_cast(pContext->getOpenGLWindow()).win == mhWindow) pContext->reset(); pContext = pContext->mpPrevContext; } diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx index 0e39c121c1c7..d00a49e59c71 100644 --- a/vcl/win/gdi/winlayout.cxx +++ b/vcl/win/gdi/winlayout.cxx @@ -2768,19 +2768,6 @@ bool UniscribeLayout::DrawCachedGlyphsUsingGLyphy(SalGraphics& rGraphics) const rGraphics.GetOpenGLContext()->UseNoProgram(); -#if 0 - HDC hDC = rGraphics.GetOpenGLContext()->getOpenGLWindow().hDC; - HBITMAP hbitmap = (HBITMAP)GetCurrentObject(hDC, OBJ_BITMAP); - - SAL_ DEBUG("hdc=" << hDC << " hbitmap=" << hbitmap); - if (hbitmap != NULL) { - BITMAP bm; - GetObjectW(hbitmap, sizeof(bm), &bm); - SAL_ DEBUG(" size=" << bm.bmWidth << "x" << bm.bmHeight << - " bpp=" << bm.bmBitsPixel); - } -#endif - glUseProgram( mrWinFontEntry.mnGLyphyProgram ); CHECK_GL_ERROR(); demo_atlas_set_uniforms( mrWinFontEntry.mpGLyphyAtlas ); -- cgit v1.2.3