From dea885f80a80c6a5839ee5dbf8521487186a9522 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 3 Aug 2015 15:06:55 +0900 Subject: opengl: cache native widget textures also for Windows Change-Id: I476f0ffaef383f3227c0c12b50fcdebf393190f6 Reviewed-on: https://gerrit.libreoffice.org/17487 Tested-by: Jenkins Reviewed-by: Tor Lillqvist Tested-by: Tor Lillqvist --- vcl/inc/opengl/win/gdiimpl.hxx | 9 +++ vcl/inc/openglgdiimpl.hxx | 6 ++ vcl/opengl/win/gdiimpl.cxx | 85 ++++++++++++++++++++++++++++ vcl/opengl/x11/gdiimpl.cxx | 6 -- vcl/win/source/gdi/gdiimpl.cxx | 14 ++++- vcl/win/source/gdi/gdiimpl.hxx | 6 ++ vcl/win/source/gdi/salnativewidgets-luna.cxx | 25 ++++---- 7 files changed, 130 insertions(+), 21 deletions(-) (limited to 'vcl') diff --git a/vcl/inc/opengl/win/gdiimpl.hxx b/vcl/inc/opengl/win/gdiimpl.hxx index 03007c9ad188..e1fa195286a6 100644 --- a/vcl/inc/opengl/win/gdiimpl.hxx +++ b/vcl/inc/opengl/win/gdiimpl.hxx @@ -23,6 +23,9 @@ class WinOpenGLSalGraphicsImpl : public OpenGLSalGraphicsImpl private: WinSalGraphics& mrParent; + bool RenderCompatibleDC(OpenGLCompatibleDC& rWhite, OpenGLCompatibleDC& rBlack, + int nX, int nY, TextureCombo& rCombo); + public: WinOpenGLSalGraphicsImpl(WinSalGraphics& rGraphics, SalGeometryProvider *mpProvider); @@ -34,6 +37,12 @@ protected: public: virtual void copyBits( const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics ) SAL_OVERRIDE; + + bool TryRenderCachedNativeControl(ControlCacheKey& rControlCacheKey, int nX, int nY); + + bool RenderAndCacheNativeControl(OpenGLCompatibleDC& rWhite, OpenGLCompatibleDC& rBlack, + int nX, int nY , ControlCacheKey& aControlCacheKey); + }; #endif diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx index caa883dca899..f0338b7b1d46 100644 --- a/vcl/inc/openglgdiimpl.hxx +++ b/vcl/inc/openglgdiimpl.hxx @@ -40,6 +40,12 @@ namespace basegfx class B2DTrapezoid; }; +struct TextureCombo +{ + std::unique_ptr mpTexture; + std::unique_ptr mpMask; +}; + class VCL_PLUGIN_PUBLIC OpenGLSalGraphicsImpl : public SalGraphicsImpl { protected: diff --git a/vcl/opengl/win/gdiimpl.cxx b/vcl/opengl/win/gdiimpl.cxx index ee53c8a7695b..cd7dc87b6e8c 100644 --- a/vcl/opengl/win/gdiimpl.cxx +++ b/vcl/opengl/win/gdiimpl.cxx @@ -7,6 +7,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include + + #include "opengl/win/gdiimpl.hxx" #include @@ -43,4 +46,86 @@ bool WinOpenGLSalGraphicsImpl::UseContext( OpenGLContext* pContext ) return ( pContext->getOpenGLWindow().hWnd == mrParent.mhWnd ); } +namespace +{ + +typedef std::pair> ControlCachePair; +typedef o3tl::lru_map, ControlCacheHashFunction> ControlCacheType; + +ControlCacheType gTextureCache(200); + +} + +bool WinOpenGLSalGraphicsImpl::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 WinOpenGLSalGraphicsImpl::RenderCompatibleDC(OpenGLCompatibleDC& rWhite, OpenGLCompatibleDC& rBlack, + int nX, int nY, TextureCombo& rCombo) +{ + PreDraw(); + + rCombo.mpTexture.reset(rWhite.getTexture()); + rCombo.mpMask.reset(rBlack.getTexture()); + + + if (rCombo.mpTexture && rCombo.mpMask) + { + OpenGLTexture& rTexture = *rCombo.mpTexture; + + SalTwoRect aPosAry(0, 0, rTexture.GetWidth(), rTexture.GetHeight(), + nX, nY, rTexture.GetWidth(), rTexture.GetHeight()); + + DrawTextureDiff(*rCombo.mpTexture, *rCombo.mpMask, aPosAry); + } + + PostDraw(); + return true; +} + +bool WinOpenGLSalGraphicsImpl::RenderAndCacheNativeControl(OpenGLCompatibleDC& rWhite, OpenGLCompatibleDC& rBlack, + int nX, int nY , ControlCacheKey& aControlCacheKey) +{ + std::unique_ptr pCombo(new TextureCombo); + + bool bResult = RenderCompatibleDC(rWhite, rBlack, nX, nY, *pCombo); + if (!bResult) + return false; + + if (aControlCacheKey.mnType == CTRL_CHECKBOX) + return true; + + ControlCachePair pair(aControlCacheKey, std::move(pCombo)); + gTextureCache.insert(std::move(pair)); + + return bResult; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/opengl/x11/gdiimpl.cxx b/vcl/opengl/x11/gdiimpl.cxx index bf5e6f600c44..0663ce933d24 100644 --- a/vcl/opengl/x11/gdiimpl.cxx +++ b/vcl/opengl/x11/gdiimpl.cxx @@ -113,12 +113,6 @@ bool X11OpenGLSalGraphicsImpl::FillPixmapFromScreen( X11Pixmap* pPixmap, int nX, return true; } -struct TextureCombo -{ - std::unique_ptr mpTexture; - std::unique_ptr mpMask; -}; - typedef typename std::pair> ControlCachePair; typedef o3tl::lru_map, ControlCacheHashFunction> ControlCacheType; diff --git a/vcl/win/source/gdi/gdiimpl.cxx b/vcl/win/source/gdi/gdiimpl.cxx index aea064d077cd..fbe386cf63ad 100644 --- a/vcl/win/source/gdi/gdiimpl.cxx +++ b/vcl/win/source/gdi/gdiimpl.cxx @@ -17,10 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include + #include "gdiimpl.hxx" #include -#include #include #include #include @@ -2320,4 +2321,15 @@ bool WinSalGraphicsImpl::drawGradient(const tools::PolyPolygon& /*rPolygon*/, return false; } +bool WinSalGraphicsImpl::TryRenderCachedNativeControl(ControlCacheKey& /*rControlCacheKey*/, int /*nX*/, int /*nY*/) +{ + return false; +} + +bool WinSalGraphicsImpl::RenderAndCacheNativeControl(OpenGLCompatibleDC& /*rWhite*/, OpenGLCompatibleDC& /*rBlack*/, + int /*nX*/, int /*nY*/ , ControlCacheKey& /*aControlCacheKey*/) +{ + return false; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/win/source/gdi/gdiimpl.hxx b/vcl/win/source/gdi/gdiimpl.hxx index bdcdda181370..c22d0bfce4a0 100644 --- a/vcl/win/source/gdi/gdiimpl.hxx +++ b/vcl/win/source/gdi/gdiimpl.hxx @@ -18,6 +18,7 @@ */ #include "salgdiimpl.hxx" +#include "win/salgdi.h" #include @@ -221,6 +222,11 @@ public: virtual void beginPaint() SAL_OVERRIDE { } virtual void endPaint() SAL_OVERRIDE { } + + virtual bool TryRenderCachedNativeControl(ControlCacheKey& rControlCacheKey, int nX, int nY); + + virtual bool RenderAndCacheNativeControl(OpenGLCompatibleDC& rWhite, OpenGLCompatibleDC& rBlack, + int nX, int nY , ControlCacheKey& aControlCacheKey); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/win/source/gdi/salnativewidgets-luna.cxx b/vcl/win/source/gdi/salnativewidgets-luna.cxx index 7d545b02c4d4..ec3d79f44972 100644 --- a/vcl/win/source/gdi/salnativewidgets-luna.cxx +++ b/vcl/win/source/gdi/salnativewidgets-luna.cxx @@ -1170,6 +1170,16 @@ bool WinSalGraphics::drawNativeControl( ControlType nType, bool bOk = false; HTHEME hTheme = NULL; + Rectangle buttonRect = rControlRegion; + + WinOpenGLSalGraphicsImpl* pImpl = dynamic_cast(mpImpl.get()); + + ControlCacheKey aControlCacheKey(nType, nPart, nState, buttonRect.GetSize()); + if (pImpl != NULL && pImpl->TryRenderCachedNativeControl(aControlCacheKey, buttonRect.Left(), buttonRect.Top())) + { + return true; + } + switch( nType ) { case CTRL_PUSHBUTTON: @@ -1256,7 +1266,6 @@ bool WinSalGraphics::drawNativeControl( ControlType nType, if( !hTheme ) return false; - Rectangle buttonRect = rControlRegion; RECT rc; rc.left = buttonRect.Left(); rc.right = buttonRect.Right()+1; @@ -1265,7 +1274,6 @@ bool WinSalGraphics::drawNativeControl( ControlType nType, OUString aCaptionStr(aCaption.replace('~', '&')); // translate mnemonics - WinOpenGLSalGraphicsImpl *pImpl = dynamic_cast(mpImpl.get()); if (pImpl == NULL) { // set default text alignment @@ -1290,18 +1298,7 @@ bool WinSalGraphics::drawNativeControl( ControlType nType, if (ImplDrawNativeControl(aBlackDC.getCompatibleHDC(), hTheme, rc, nType, nPart, nState, aValue, aCaptionStr) && ImplDrawNativeControl(aWhiteDC.getCompatibleHDC(), hTheme, rc, nType, nPart, nState, aValue, aCaptionStr)) { - pImpl->PreDraw(); - - std::unique_ptr xBlackTexture(aBlackDC.getTexture()); - std::unique_ptr xWhiteTexture(aWhiteDC.getTexture()); - - if (xBlackTexture && xWhiteTexture) - { - pImpl->DrawTextureDiff(*xWhiteTexture, *xBlackTexture, aBlackDC.getTwoRect()); - bOk = true; - } - - pImpl->PostDraw(); + bOk = pImpl->RenderAndCacheNativeControl(aWhiteDC, aBlackDC, buttonRect.Left(), buttonRect.Top(), aControlCacheKey); } } -- cgit