Kaydet (Commit) b63b54e7 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Miklos Vajna

opengl: cache native widget textures also for Windows

Change-Id: I476f0ffaef383f3227c0c12b50fcdebf393190f6
Reviewed-on: https://gerrit.libreoffice.org/17487Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTor Lillqvist <tml@collabora.com>
Tested-by: 's avatarTor Lillqvist <tml@collabora.com>
(cherry picked from commit dea885f8)
Reviewed-on: https://gerrit.libreoffice.org/17561Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst b55e95ab
...@@ -23,6 +23,9 @@ class WinOpenGLSalGraphicsImpl : public OpenGLSalGraphicsImpl ...@@ -23,6 +23,9 @@ class WinOpenGLSalGraphicsImpl : public OpenGLSalGraphicsImpl
private: private:
WinSalGraphics& mrParent; WinSalGraphics& mrParent;
bool RenderCompatibleDC(OpenGLCompatibleDC& rWhite, OpenGLCompatibleDC& rBlack,
int nX, int nY, TextureCombo& rCombo);
public: public:
WinOpenGLSalGraphicsImpl(WinSalGraphics& rGraphics, WinOpenGLSalGraphicsImpl(WinSalGraphics& rGraphics,
SalGeometryProvider *mpProvider); SalGeometryProvider *mpProvider);
...@@ -34,6 +37,12 @@ protected: ...@@ -34,6 +37,12 @@ protected:
public: public:
virtual void copyBits( const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics ) SAL_OVERRIDE; 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 #endif
......
...@@ -40,6 +40,12 @@ namespace basegfx ...@@ -40,6 +40,12 @@ namespace basegfx
class B2DTrapezoid; class B2DTrapezoid;
}; };
struct TextureCombo
{
std::unique_ptr<OpenGLTexture> mpTexture;
std::unique_ptr<OpenGLTexture> mpMask;
};
class VCL_PLUGIN_PUBLIC OpenGLSalGraphicsImpl : public SalGraphicsImpl class VCL_PLUGIN_PUBLIC OpenGLSalGraphicsImpl : public SalGraphicsImpl
{ {
protected: protected:
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include <o3tl/lru_map.hxx>
#include "opengl/win/gdiimpl.hxx" #include "opengl/win/gdiimpl.hxx"
#include <win/wincomp.hxx> #include <win/wincomp.hxx>
...@@ -43,4 +46,86 @@ bool WinOpenGLSalGraphicsImpl::UseContext( OpenGLContext* pContext ) ...@@ -43,4 +46,86 @@ bool WinOpenGLSalGraphicsImpl::UseContext( OpenGLContext* pContext )
return ( pContext->getOpenGLWindow().hWnd == mrParent.mhWnd ); 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -113,12 +113,6 @@ bool X11OpenGLSalGraphicsImpl::FillPixmapFromScreen( X11Pixmap* pPixmap, int nX, ...@@ -113,12 +113,6 @@ bool X11OpenGLSalGraphicsImpl::FillPixmapFromScreen( X11Pixmap* pPixmap, int nX,
return true; 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 typename std::pair<ControlCacheKey, std::unique_ptr<TextureCombo>> ControlCachePair;
typedef o3tl::lru_map<ControlCacheKey, std::unique_ptr<TextureCombo>, ControlCacheHashFunction> ControlCacheType; typedef o3tl::lru_map<ControlCacheKey, std::unique_ptr<TextureCombo>, ControlCacheHashFunction> ControlCacheType;
......
...@@ -17,11 +17,12 @@ ...@@ -17,11 +17,12 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <svsys.h>
#include "gdiimpl.hxx" #include "gdiimpl.hxx"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <svsys.h>
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
#include <tools/debug.hxx> #include <tools/debug.hxx>
#include <tools/poly.hxx> #include <tools/poly.hxx>
...@@ -2377,4 +2378,15 @@ bool WinSalGraphicsImpl::drawGradient(const tools::PolyPolygon& /*rPolygon*/, ...@@ -2377,4 +2378,15 @@ bool WinSalGraphicsImpl::drawGradient(const tools::PolyPolygon& /*rPolygon*/,
return false; 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include "salgdiimpl.hxx" #include "salgdiimpl.hxx"
#include "win/salgdi.h"
#include <vcl/gradient.hxx> #include <vcl/gradient.hxx>
...@@ -226,6 +227,11 @@ public: ...@@ -226,6 +227,11 @@ public:
virtual void beginPaint() SAL_OVERRIDE { } virtual void beginPaint() SAL_OVERRIDE { }
virtual void endPaint() 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -1170,6 +1170,16 @@ bool WinSalGraphics::drawNativeControl( ControlType nType, ...@@ -1170,6 +1170,16 @@ bool WinSalGraphics::drawNativeControl( ControlType nType,
bool bOk = false; bool bOk = false;
HTHEME hTheme = NULL; 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 ) switch( nType )
{ {
case CTRL_PUSHBUTTON: case CTRL_PUSHBUTTON:
...@@ -1256,7 +1266,6 @@ bool WinSalGraphics::drawNativeControl( ControlType nType, ...@@ -1256,7 +1266,6 @@ bool WinSalGraphics::drawNativeControl( ControlType nType,
if( !hTheme ) if( !hTheme )
return false; return false;
Rectangle buttonRect = rControlRegion;
RECT rc; RECT rc;
rc.left = buttonRect.Left(); rc.left = buttonRect.Left();
rc.right = buttonRect.Right()+1; rc.right = buttonRect.Right()+1;
...@@ -1265,7 +1274,6 @@ bool WinSalGraphics::drawNativeControl( ControlType nType, ...@@ -1265,7 +1274,6 @@ bool WinSalGraphics::drawNativeControl( ControlType nType,
OUString aCaptionStr(aCaption.replace('~', '&')); // translate mnemonics OUString aCaptionStr(aCaption.replace('~', '&')); // translate mnemonics
WinOpenGLSalGraphicsImpl *pImpl = dynamic_cast<WinOpenGLSalGraphicsImpl*>(mpImpl.get());
if (pImpl == NULL) if (pImpl == NULL)
{ {
// set default text alignment // set default text alignment
...@@ -1290,18 +1298,7 @@ bool WinSalGraphics::drawNativeControl( ControlType nType, ...@@ -1290,18 +1298,7 @@ bool WinSalGraphics::drawNativeControl( ControlType nType,
if (ImplDrawNativeControl(aBlackDC.getCompatibleHDC(), hTheme, rc, nType, nPart, nState, aValue, aCaptionStr) && if (ImplDrawNativeControl(aBlackDC.getCompatibleHDC(), hTheme, rc, nType, nPart, nState, aValue, aCaptionStr) &&
ImplDrawNativeControl(aWhiteDC.getCompatibleHDC(), hTheme, rc, nType, nPart, nState, aValue, aCaptionStr)) ImplDrawNativeControl(aWhiteDC.getCompatibleHDC(), hTheme, rc, nType, nPart, nState, aValue, aCaptionStr))
{ {
pImpl->PreDraw(); bOk = pImpl->RenderAndCacheNativeControl(aWhiteDC, aBlackDC, buttonRect.Left(), buttonRect.Top(), aControlCacheKey);
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();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment