summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToma┼ż Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-08-03 15:06:55 +0900
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-08-07 09:35:28 +0000
commitb63b54e7453cdda92914dfe3d1ea2d9f0d1f0d29 (patch)
tree550d1a686a5f0288eea9d921d6b8806522e57283
parentb55e95ab39c684e226c667af456dea4f3d53b791 (diff)
opengl: cache native widget textures also for Windows
Change-Id: I476f0ffaef383f3227c0c12b50fcdebf393190f6 Reviewed-on: https://gerrit.libreoffice.org/17487 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tor Lillqvist <tml@collabora.com> Tested-by: Tor Lillqvist <tml@collabora.com> (cherry picked from commit dea885f80a80c6a5839ee5dbf8521487186a9522) Reviewed-on: https://gerrit.libreoffice.org/17561 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--vcl/inc/opengl/win/gdiimpl.hxx9
-rw-r--r--vcl/inc/openglgdiimpl.hxx6
-rw-r--r--vcl/opengl/win/gdiimpl.cxx85
-rw-r--r--vcl/opengl/x11/gdiimpl.cxx6
-rw-r--r--vcl/win/source/gdi/gdiimpl.cxx14
-rw-r--r--vcl/win/source/gdi/gdiimpl.hxx6
-rw-r--r--vcl/win/source/gdi/salnativewidgets-luna.cxx25
7 files changed, 130 insertions, 21 deletions
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 1ac1ec388dec..9e95f5ec113c 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -40,6 +40,12 @@ namespace basegfx
class B2DTrapezoid;
};
+struct TextureCombo
+{
+ std::unique_ptr<OpenGLTexture> mpTexture;
+ std::unique_ptr<OpenGLTexture> 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 <o3tl/lru_map.hxx>
+
+
#include "opengl/win/gdiimpl.hxx"
#include <win/wincomp.hxx>
@@ -43,4 +46,86 @@ bool WinOpenGLSalGraphicsImpl::UseContext( OpenGLContext* pContext )
return ( pContext->getOpenGLWindow().hWnd == mrParent.mhWnd );
}
+namespace
+{
+
+typedef std::pair<ControlCacheKey, std::unique_ptr<TextureCombo>> ControlCachePair;
+typedef o3tl::lru_map<ControlCacheKey, std::unique_ptr<TextureCombo>, 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<TextureCombo>& 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<TextureCombo> 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<OpenGLTexture> mpTexture;
- std::unique_ptr<OpenGLTexture> mpMask;
-};
-
typedef typename std::pair<ControlCacheKey, std::unique_ptr<TextureCombo>> ControlCachePair;
typedef o3tl::lru_map<ControlCacheKey, std::unique_ptr<TextureCombo>, ControlCacheHashFunction> ControlCacheType;
diff --git a/vcl/win/source/gdi/gdiimpl.cxx b/vcl/win/source/gdi/gdiimpl.cxx
index 16b7d4b1d576..e4823a2c6452 100644
--- a/vcl/win/source/gdi/gdiimpl.cxx
+++ b/vcl/win/source/gdi/gdiimpl.cxx
@@ -17,11 +17,12 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <svsys.h>
+
#include "gdiimpl.hxx"
#include <stdio.h>
#include <string.h>
-#include <svsys.h>
#include <rtl/strbuf.hxx>
#include <tools/debug.hxx>
#include <tools/poly.hxx>
@@ -2377,4 +2378,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 2890664406be..82a8333eb49f 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 <vcl/gradient.hxx>
@@ -226,6 +227,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<WinOpenGLSalGraphicsImpl*>(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<WinOpenGLSalGraphicsImpl*>(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<OpenGLTexture> xBlackTexture(aBlackDC.getTexture());
- std::unique_ptr<OpenGLTexture> 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);
}
}