[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - vcl/inc vcl/opengl vcl/win

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Fri Aug 7 02:35:49 PDT 2015


 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(-)

New commits:
commit b63b54e7453cdda92914dfe3d1ea2d9f0d1f0d29
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Aug 3 15:06:55 2015 +0900

    opengl: cache native widget textures also for Windows
    
    Change-Id: I476f0ffaef383f3227c0c12b50fcdebf393190f6
    Reviewed-on: https://gerrit.libreoffice.org/17487
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tor Lillqvist <tml at collabora.com>
    Tested-by: Tor Lillqvist <tml at collabora.com>
    (cherry picked from commit dea885f80a80c6a5839ee5dbf8521487186a9522)
    Reviewed-on: https://gerrit.libreoffice.org/17561
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/vcl/inc/opengl/win/gdiimpl.hxx b/vcl/inc/opengl/win/gdiimpl.hxx
index 03007c9..e1fa195 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 1ac1ec3..9e95f5e 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 ee53c8a..cd7dc87 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 bf5e6f6..0663ce9 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 16b7d4b..e4823a2 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 2890664..82a8333 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 7d545b0..ec3d79f 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);
         }
     }
 


More information about the Libreoffice-commits mailing list