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

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>
üst 4c57e8bb
......@@ -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
......
......@@ -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:
......
......@@ -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: */
......@@ -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;
......
......@@ -17,10 +17,11 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <svsys.h>
#include "gdiimpl.hxx"
#include <string.h>
#include <svsys.h>
#include <rtl/strbuf.hxx>
#include <tools/debug.hxx>
#include <tools/poly.hxx>
......@@ -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: */
......@@ -18,6 +18,7 @@
*/
#include "salgdiimpl.hxx"
#include "win/salgdi.h"
#include <vcl/gradient.hxx>
......@@ -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: */
......@@ -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);
}
}
......
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