[Libreoffice-commits] core.git: include/vcl vcl/source

Tamas Bunth tamas.bunth at collabora.co.uk
Mon Jun 12 09:59:20 UTC 2017


 include/vcl/outdev.hxx       |    6 ++--
 vcl/source/outdev/text.cxx   |   60 +++++++++++++++++--------------------------
 vcl/source/window/status.cxx |   32 ++++++++++------------
 3 files changed, 42 insertions(+), 56 deletions(-)

New commits:
commit 3b05c3b4b4b6c3891b4b7e88d91889cf327a34a8
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
Date:   Sun Jun 11 00:24:36 2017 +0200

    Refactor create layout cache in status bar
    
    Create SalLayout in StatusBar instead of getting cache through output
    parameter.
    
    Pass cache as a constant to the output device afterwards.
    
    Results in a more readable code, with more evident memory management.
    
    Change-Id: I4f949ea8f390b31379f661d611a183ceb3d91c25
    Reviewed-on: https://gerrit.libreoffice.org/38651
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tamás Bunth <btomi96 at gmail.com>

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index cf44ac9c3811..b4fb7f019081 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -972,7 +972,7 @@ public:
     void                        DrawText( const Point& rStartPt, const OUString& rStr,
                                           sal_Int32 nIndex = 0, sal_Int32 nLen = -1,
                                           MetricVector* pVector = nullptr, OUString* pDisplayText = nullptr,
-                                          SalLayout** pLayoutCache = nullptr );
+                                          SalLayout* pLayoutCache = nullptr );
 
     void                        DrawText( const tools::Rectangle& rRect,
                                           const OUString& rStr, DrawTextFlags nStyle = DrawTextFlags::NONE,
@@ -1134,7 +1134,7 @@ public:
     */
     long                        GetTextWidth( const OUString& rStr, sal_Int32 nIndex = 0, sal_Int32 nLen = -1,
                                   vcl::TextLayoutCache const* = nullptr,
-                                  SalLayout** pLayoutCache = nullptr) const;
+                                  SalLayout const*const pLayoutCache = nullptr) const;
 
     /** Height where any character of the current font fits; in logic coordinates.
 
@@ -1151,7 +1151,7 @@ public:
     long                        GetTextArray( const OUString& rStr, long* pDXAry,
                                               sal_Int32 nIndex = 0, sal_Int32 nLen = -1,
                                               vcl::TextLayoutCache const* = nullptr,
-                                              SalLayout** pLayoutCache = nullptr) const;
+                                              SalLayout const*const pLayoutCache = nullptr) const;
 
     bool                        GetCaretPositions( const OUString&, long* pCaretXArray,
                                               sal_Int32 nIndex, sal_Int32 nLen ) const;
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index 3937af3eb543..150fd828887d 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -803,7 +803,7 @@ void OutputDevice::SetTextAlign( TextAlign eAlign )
 void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr,
                              sal_Int32 nIndex, sal_Int32 nLen,
                              MetricVector* pVector, OUString* pDisplayText,
-                             SalLayout** pLayoutCache
+                             SalLayout* pLayoutCache
                              )
 {
     assert(!is_double_buffered_window());
@@ -875,10 +875,10 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr,
     if ( !IsDeviceOutputNecessary() || pVector )
         return;
 
-    if(mpFontInstance && pLayoutCache)
+    if(mpFontInstance)
         // do not use cache with modified string
-        if( mpFontInstance->mpConversion )
-            *pLayoutCache = nullptr;
+        if(mpFontInstance->mpConversion)
+            pLayoutCache = nullptr;
 
     // without cache
     if(!pLayoutCache)
@@ -893,29 +893,23 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr,
     }
     else
     {
-        // with cache, but there is no cache yet
-        if(!*pLayoutCache)
-            *pLayoutCache = ImplLayout(rStr, nIndex, nLen, rStartPt);
+        // initialize font if needed
+        if( mbNewFont )
+            if( !ImplNewFont() )
+                return;
+        if( mbInitFont )
+            InitFont();
 
-        if( *pLayoutCache )
-        {
-            // initialize font if needed
-            if( mbNewFont )
-                if( !ImplNewFont() )
-                    return;
-            if( mbInitFont )
-                InitFont();
-
-            OUString aStrModifiable = rStr;
-            ImplLayoutArgs aLayoutArgs = ImplPrepareLayoutArgs( aStrModifiable, nIndex, nLen,
-                    0, nullptr);
-
-             // position, justify, etc. the layout
-             (*pLayoutCache)->AdjustLayout( aLayoutArgs );
-             (*pLayoutCache)->DrawBase() = ImplLogicToDevicePixel( rStartPt );
-
-            ImplDrawText( **pLayoutCache );
-        }
+
+        OUString aStrModifiable = rStr;
+        ImplLayoutArgs aLayoutArgs = ImplPrepareLayoutArgs( aStrModifiable, nIndex, nLen,
+                0, nullptr);
+
+        // position, justify, etc. the layout
+        pLayoutCache->AdjustLayout( aLayoutArgs );
+        pLayoutCache->DrawBase() = ImplLogicToDevicePixel( rStartPt );
+
+        ImplDrawText( *pLayoutCache );
     }
 
     if( mpAlphaVDev )
@@ -924,7 +918,7 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr,
 
 long OutputDevice::GetTextWidth( const OUString& rStr, sal_Int32 nIndex, sal_Int32 nLen,
      vcl::TextLayoutCache const*const pLayoutCache,
-     SalLayout** pSalLayoutCache) const
+     SalLayout const*const pSalLayoutCache) const
 {
 
     long nWidth = GetTextArray( rStr, nullptr, nIndex,
@@ -992,7 +986,7 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr,
 long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
                                  sal_Int32 nIndex, sal_Int32 nLen,
                                  vcl::TextLayoutCache const*const pLayoutCache,
-                                 SalLayout** pSalLayoutCache) const
+                                 SalLayout const*const pSalLayoutCache) const
 {
     if( nIndex >= rStr.getLength() )
         return 0; // TODO: this looks like a buggy caller?
@@ -1002,9 +996,9 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
         nLen = rStr.getLength() - nIndex;
     }
 
-    SalLayout* pSalLayout = pSalLayoutCache ? *pSalLayoutCache : nullptr;
+    const SalLayout*  pSalLayout = pSalLayoutCache;
 
-    if(!pSalLayout)
+    if(!pSalLayoutCache)
     {
         // do layout
         pSalLayout = ImplLayout(rStr, nIndex, nLen,
@@ -1023,12 +1017,6 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
             }
             return 0;
         }
-
-        // update cache if used
-        if(pSalLayoutCache)
-        {
-            *pSalLayoutCache = pSalLayout;
-        }
     }
 
 #if VCL_FLOAT_DEVICE_PIXEL
diff --git a/vcl/source/window/status.cxx b/vcl/source/window/status.cxx
index c4f44d8e1a4b..099ac900d886 100644
--- a/vcl/source/window/status.cxx
+++ b/vcl/source/window/status.cxx
@@ -373,11 +373,17 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen
     }
 
     SalLayout* pLayoutCache = pItem->mxLayoutCache.get();
-    Size aTextSize(rRenderContext.GetTextWidth(pItem->maText,0,-1,nullptr,&pLayoutCache), rRenderContext.GetTextHeight());
 
-    // update cache if necessary
-    if(pLayoutCache != pItem->mxLayoutCache.get() )
-        pItem->mxLayoutCache.reset(pLayoutCache);
+    if(!pLayoutCache)
+    {
+        pLayoutCache = rRenderContext.ImplLayout(pItem->maText, 0, -1);
+
+        // update cache
+        if(pLayoutCache)
+            pItem->mxLayoutCache.reset(pLayoutCache);
+    }
+
+    Size aTextSize(rRenderContext.GetTextWidth(pItem->maText,0,-1,nullptr,pLayoutCache), rRenderContext.GetTextHeight());
 
     Point aTextPos = ImplGetItemTextPos(aTextRectSize, aTextSize, pItem->mnBits);
 
@@ -387,7 +393,7 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen
                     aTextPos,
                     pItem->maText,
                     0, -1, nullptr, nullptr,
-                    &pLayoutCache );
+                    pLayoutCache );
     }
     else
     {
@@ -397,13 +403,9 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen
                     aTextPos,
                     pItem->maText,
                     0, -1, nullptr, nullptr,
-                    &pLayoutCache );
+                    pLayoutCache );
     }
 
-    // update cache if necessary
-    if(pLayoutCache != pItem->mxLayoutCache.get() )
-        pItem->mxLayoutCache.reset(pLayoutCache);
-
     // call DrawItem if necessary
     if (pItem->mnBits & StatusBarItemBits::UserDraw)
     {
@@ -1163,20 +1165,16 @@ void StatusBar::SetItemText( sal_uInt16 nItemId, const OUString& rText )
 
         if ( pItem->maText != rText )
         {
-            // invalidate cache
-            pItem->mxLayoutCache.reset();
-
             pItem->maText = rText;
 
             // adjust item width - see also DataChanged()
             long nFudge = GetTextHeight()/4;
 
-            SalLayout* pLayoutCache = nullptr;
-
-            long nWidth = GetTextWidth( pItem->maText,0,-1,nullptr,&pLayoutCache ) + nFudge;
+            SalLayout* pSalLayout = ImplLayout(pItem->maText,0,-1);
+            long nWidth = GetTextWidth( pItem->maText,0,-1,nullptr,pSalLayout ) + nFudge;
 
             // update cache
-            pItem->mxLayoutCache.reset(pLayoutCache);
+            pItem->mxLayoutCache.reset(pSalLayout);
 
             if( (nWidth > pItem->mnWidth + STATUSBAR_OFFSET) ||
                 ((nWidth < pItem->mnWidth) && (mnDX - STATUSBAR_OFFSET) < mnItemsWidth  ))


More information about the Libreoffice-commits mailing list