From 450727fdffa4a0dc3b2d4e635a5c1bc0411b3c36 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Thu, 23 Jul 2015 19:15:20 +0900 Subject: tdf#92018 cache native controls for X11 OpenGL backend (for now) Change-Id: I85c7cc01113bc4ac810c450a6460059463cc8e03 --- vcl/opengl/x11/gdiimpl.cxx | 84 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 12 deletions(-) (limited to 'vcl/opengl/x11/gdiimpl.cxx') diff --git a/vcl/opengl/x11/gdiimpl.cxx b/vcl/opengl/x11/gdiimpl.cxx index 1d453dabf007..3890b6443de3 100644 --- a/vcl/opengl/x11/gdiimpl.cxx +++ b/vcl/opengl/x11/gdiimpl.cxx @@ -111,18 +111,28 @@ bool X11OpenGLSalGraphicsImpl::FillPixmapFromScreen( X11Pixmap* pPixmap, int nX, return true; } -bool X11OpenGLSalGraphicsImpl::RenderPixmapToScreen( X11Pixmap* pPixmap, X11Pixmap* pMask, int nX, int nY ) +struct TextureCombo +{ + std::unique_ptr mpTexture; + std::unique_ptr mpMask; +}; + +typedef std::unordered_map, ControlCacheHashFunction> ControlCacheType; + +ControlCacheType gTextureCache; + +bool X11OpenGLSalGraphicsImpl::RenderPixmap(X11Pixmap* pPixmap, X11Pixmap* pMask, int nX, int nY, TextureCombo& rCombo) { - const int aAttribs[] = { + const int aAttribs[] = + { GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT, None }; + Display* pDisplay = mrParent.GetXDisplay(); bool bInverted; - SAL_INFO( "vcl.opengl", "RenderPixmapToScreen (" << nX << " " << nY << ")" ); - const long nWidth = pPixmap->GetWidth(); const long nHeight = pPixmap->GetHeight(); SalTwoRect aPosAry(0, 0, nWidth, nHeight, nX, nY, nWidth, nHeight); @@ -145,27 +155,28 @@ bool X11OpenGLSalGraphicsImpl::RenderPixmapToScreen( X11Pixmap* pPixmap, X11Pixm //TODO: lfrb: glXGetProc to get the functions - OpenGLTexture aTexture( pPixmap->GetWidth(), pPixmap->GetHeight(), false ); + rCombo.mpTexture.reset(new OpenGLTexture(pPixmap->GetWidth(), pPixmap->GetHeight(), false)); + glActiveTexture( GL_TEXTURE0 ); - aTexture.Bind(); + rCombo.mpTexture->Bind(); glXBindTexImageEXT( pDisplay, pGlxPixmap, GLX_FRONT_LEFT_EXT, NULL ); - aTexture.Unbind(); + rCombo.mpTexture->Unbind(); if( pMask != NULL && pGlxMask ) { - OpenGLTexture aMaskTexture( pMask->GetWidth(), pMask->GetHeight(), false ); - aMaskTexture.Bind(); + rCombo.mpMask.reset(new OpenGLTexture(pPixmap->GetWidth(), pPixmap->GetHeight(), false)); + rCombo.mpMask->Bind(); glXBindTexImageEXT( pDisplay, pGlxMask, GLX_FRONT_LEFT_EXT, NULL ); - aMaskTexture.Unbind(); + rCombo.mpMask->Unbind(); - DrawTextureDiff( aTexture, aMaskTexture, aPosAry, bInverted ); + DrawTextureDiff(*rCombo.mpTexture, *rCombo.mpMask, aPosAry, bInverted); glXReleaseTexImageEXT( pDisplay, pGlxMask, GLX_FRONT_LEFT_EXT ); glXDestroyPixmap( pDisplay, pGlxMask ); } else { - DrawTexture( aTexture, aPosAry, bInverted ); + DrawTexture(*rCombo.mpTexture, aPosAry, bInverted); } CHECK_GL_ERROR(); @@ -176,7 +187,56 @@ bool X11OpenGLSalGraphicsImpl::RenderPixmapToScreen( X11Pixmap* pPixmap, X11Pixm PostDraw(); CHECK_GL_ERROR(); + return true; } +bool X11OpenGLSalGraphicsImpl::RenderPixmapToScreen( X11Pixmap* pPixmap, X11Pixmap* pMask, int nX, int nY ) +{ + SAL_INFO( "vcl.opengl", "RenderPixmapToScreen (" << nX << " " << nY << ")" ); + + TextureCombo aCombo; + return RenderPixmap(pPixmap, pMask, nX, nY, aCombo); +} + +bool X11OpenGLSalGraphicsImpl::TryRenderCachedNativeControl(ControlCacheKey& rControlCacheKey, int nX, int nY) +{ + static bool gbCacheEnabled = !getenv("SAL_WITHOUT_WIDGET_CACHE"); + + if (!gbCacheEnabled) + return false; + + ControlCacheType::const_iterator iterator = gTextureCache.find(rControlCacheKey); + + if (iterator == gTextureCache.end()) + return false; + + const std::unique_ptr& pCombo = iterator->second; + + PreDraw(); + + OpenGLTexture& rTexture = *pCombo->mpTexture; + + SalTwoRect aPosAry(0, 0, rTexture.GetWidth(), rTexture.GetHeight(), + nX, nY, rTexture.GetWidth(), rTexture.GetHeight()); + + if (pCombo->mpMask) + DrawTextureDiff(rTexture, *pCombo->mpMask, aPosAry, true); + else + DrawTexture(rTexture, aPosAry, true); + + PostDraw(); + + return true; +} + +bool X11OpenGLSalGraphicsImpl::RenderAndCacheNativeControl(X11Pixmap* pPixmap, X11Pixmap* pMask, int nX, int nY, + ControlCacheKey& aControlCacheKey) +{ + std::unique_ptr pCombo(new TextureCombo); + bool bResult = RenderPixmap(pPixmap, pMask, nX, nY, *pCombo); + gTextureCache[aControlCacheKey] = std::move(pCombo); + return bResult; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit