[Libreoffice-commits] core.git: 2 commits - chart2/source

Markus Mohrhard markus.mohrhard at collabora.co.uk
Fri Mar 7 10:44:25 PST 2014


 chart2/source/view/inc/DummyXShape.hxx         |   35 ++++++++++++
 chart2/source/view/main/DummyXShape.cxx        |   69 +++++++++++++++++++------
 chart2/source/view/main/OpenglShapeFactory.cxx |    2 
 3 files changed, 88 insertions(+), 18 deletions(-)

New commits:
commit 4ba896806af7c92075c9dd82cda1749e2ad16295
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Fri Mar 7 19:41:02 2014 +0100

    cache text rendering for performance
    
    Change-Id: I644556ed6b74069d0e7d441d4056310a282f190e

diff --git a/chart2/source/view/inc/DummyXShape.hxx b/chart2/source/view/inc/DummyXShape.hxx
index 1d2eba6..6021139 100644
--- a/chart2/source/view/inc/DummyXShape.hxx
+++ b/chart2/source/view/inc/DummyXShape.hxx
@@ -60,6 +60,7 @@
 #include <vector>
 #include <map>
 #include <boost/scoped_ptr.hpp>
+#include <boost/unordered_map.hpp>
 
 #if defined( MACOSX )
 #include <OpenGL/gl.h>
@@ -97,6 +98,38 @@ class DummyChart;
 
 struct OpenglContext;
 
+
+class TextCache
+{
+public:
+    struct TextCacheKey
+    {
+        OUString maText;
+        std::map<OUString, com::sun::star::uno::Any> maProperties;
+
+        bool operator==(const TextCacheKey& rKey) const
+        {
+            return maText == rKey.maText && maProperties == rKey.maProperties;
+        }
+    };
+
+    struct TextCacheKeyHash
+    {
+        size_t operator()(const TextCacheKey& rKey) const
+        {
+            return rKey.maText.hashCode();
+        }
+    };
+
+    bool hasEntry(const TextCacheKey& rKey);
+    BitmapEx& getBitmap(const TextCacheKey& rKey);
+    void insertBitmap(const TextCacheKey& rKey, const BitmapEx& rBitmap);
+
+private:
+
+    boost::unordered_map<TextCacheKey, BitmapEx, TextCacheKeyHash> maCache;
+};
+
 class DummyXShape : public cppu::WeakAggImplHelper6<
                     ::com::sun::star::drawing::XShape,
                     com::sun::star::beans::XPropertySet,
@@ -392,6 +425,7 @@ public:
     virtual void render() SAL_OVERRIDE;
 
     void clear();
+    TextCache& getTextCache();
 
 private:
 
@@ -403,6 +437,7 @@ private:
     bool initOpengl();
     boost::scoped_ptr<Window> mpWindow;
     boost::scoped_ptr<SystemChildWindow> pWindow;
+    TextCache maTextCache;
 public:
     OpenGLRender m_GLRender;
 };
diff --git a/chart2/source/view/main/DummyXShape.cxx b/chart2/source/view/main/DummyXShape.cxx
index 5db0d4b..5a817a4 100644
--- a/chart2/source/view/main/DummyXShape.cxx
+++ b/chart2/source/view/main/DummyXShape.cxx
@@ -48,6 +48,21 @@ namespace chart {
 
 namespace dummy {
 
+bool TextCache::hasEntry(const TextCacheKey& rKey)
+{
+    return maCache.find(rKey) != maCache.end();
+}
+
+BitmapEx& TextCache::getBitmap(const TextCacheKey& rKey)
+{
+    return maCache.find(rKey)->second;
+}
+
+void TextCache::insertBitmap(const TextCacheKey& rKey, const BitmapEx& rBitmap)
+{
+    maCache.insert(std::pair<TextCacheKey, BitmapEx>(rKey, rBitmap));
+}
+
 class DummyPropertySetInfo : public cppu::WeakImplHelper1<
                                 com::sun::star::beans::XPropertySetInfo >
 {
@@ -791,22 +806,39 @@ DummyText::DummyText(const OUString& rText, const tNameSequence& rNames,
 {
     setProperties(rNames, rValues, maProperties);
 
-    Font aFont;
-    std::for_each(maProperties.begin(), maProperties.end(), FontAttribSetter(aFont));
-
-    VirtualDevice aDevice(*Application::GetDefaultDevice(), 0, 0);
-    aDevice.Erase();
-    Rectangle aRect;
-    aDevice.SetFont(aFont);
-    aDevice.GetTextBoundRect(aRect, rText);
-    int screenWidth = (aRect.BottomRight().X());
-    int screenHeight = (aRect.BottomRight().Y());
-    aDevice.SetOutputSizePixel(Size(screenWidth * 3, screenHeight));
-    aDevice.SetBackground(Wallpaper(COL_TRANSPARENT));
-    aDevice.DrawText(Point(0, 0), rText);
-    int bmpWidth = aRect.Right() - aRect.Left();
-    int bmpHeight = aRect.Bottom() - aRect.Top();
-    maBitmap = BitmapEx(aDevice.GetBitmapEx(aRect.TopLeft(), Size(bmpWidth, bmpHeight)));
+    xTarget->add(this);
+    DummyChart* pChart = getRootShape();
+    TextCache& rCache = pChart->getTextCache();
+    TextCache::TextCacheKey aKey;
+    aKey.maText = maText;
+    aKey.maProperties = maProperties;
+    int bmpWidth;
+    int bmpHeight;
+    if(rCache.hasEntry(aKey))
+    {
+        maBitmap = rCache.getBitmap(aKey);
+        bmpWidth = maBitmap.GetSizePixel().Width();
+        bmpHeight = maBitmap.GetSizePixel().Height();
+    }
+    else
+    {
+        Font aFont;
+        std::for_each(maProperties.begin(), maProperties.end(), FontAttribSetter(aFont));
+        VirtualDevice aDevice(*Application::GetDefaultDevice(), 0, 0);
+        aDevice.Erase();
+        Rectangle aRect;
+        aDevice.SetFont(aFont);
+        aDevice.GetTextBoundRect(aRect, rText);
+        int screenWidth = (aRect.BottomRight().X());
+        int screenHeight = (aRect.BottomRight().Y());
+        aDevice.SetOutputSizePixel(Size(screenWidth * 3, screenHeight));
+        aDevice.SetBackground(Wallpaper(COL_TRANSPARENT));
+        aDevice.DrawText(Point(0, 0), rText);
+        bmpWidth = aRect.Right() - aRect.Left();
+        bmpHeight = aRect.Bottom() - aRect.Top();
+        maBitmap = BitmapEx(aDevice.GetBitmapEx(aRect.TopLeft(), Size(bmpWidth, bmpHeight)));
+        rCache.insertBitmap(aKey, maBitmap);
+    }
 
     if(rTrans.hasValue())
     {
@@ -1541,6 +1573,11 @@ void DummyChart::clear()
     maShapes.clear();
 }
 
+TextCache& DummyChart::getTextCache()
+{
+    return maTextCache;
+}
+
 }
 
 }
diff --git a/chart2/source/view/main/OpenglShapeFactory.cxx b/chart2/source/view/main/OpenglShapeFactory.cxx
index 93e4084..efbceb9 100644
--- a/chart2/source/view/main/OpenglShapeFactory.cxx
+++ b/chart2/source/view/main/OpenglShapeFactory.cxx
@@ -404,7 +404,6 @@ uno::Reference< drawing::XShape >
 {
     dummy::DummyText* pText = new dummy::DummyText( rText, rPropNames, rPropValues,
             rATransformation, xTarget, 0 );
-    xTarget->add(pText);
     return pText;
 }
 
@@ -453,7 +452,6 @@ uno::Reference< drawing::XShape >
     dummy::DummyText* pText = new dummy::DummyText(aString, aPropNames, aPropValues,
             uno::makeAny(B2DHomMatrixToHomogenMatrix3(aM)), xTarget, nRotation);
     pText->setName(rName);
-    xTarget->add(pText);
     return pText;
 }
 
commit 20113d8f42a953e1834840e63f2fe914dacbabbc
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Fri Mar 7 13:50:16 2014 +0100

    no need to make it a multiple of 3
    
    Change-Id: If9f16461045b6a9f7b79579e84dc09e4475dbf3c

diff --git a/chart2/source/view/main/DummyXShape.cxx b/chart2/source/view/main/DummyXShape.cxx
index 02bafff..5db0d4b 100644
--- a/chart2/source/view/main/DummyXShape.cxx
+++ b/chart2/source/view/main/DummyXShape.cxx
@@ -799,13 +799,13 @@ DummyText::DummyText(const OUString& rText, const tNameSequence& rNames,
     Rectangle aRect;
     aDevice.SetFont(aFont);
     aDevice.GetTextBoundRect(aRect, rText);
-    int screenWidth = (aRect.BottomRight().X() + 3) & ~3;
-    int screenHeight = (aRect.BottomRight().Y() + 3) & ~3;
+    int screenWidth = (aRect.BottomRight().X());
+    int screenHeight = (aRect.BottomRight().Y());
     aDevice.SetOutputSizePixel(Size(screenWidth * 3, screenHeight));
     aDevice.SetBackground(Wallpaper(COL_TRANSPARENT));
     aDevice.DrawText(Point(0, 0), rText);
-    int bmpWidth = (aRect.Right() - aRect.Left() + 3) & ~3;
-    int bmpHeight = (aRect.Bottom() - aRect.Top() + 3) & ~3;
+    int bmpWidth = aRect.Right() - aRect.Left();
+    int bmpHeight = aRect.Bottom() - aRect.Top();
     maBitmap = BitmapEx(aDevice.GetBitmapEx(aRect.TopLeft(), Size(bmpWidth, bmpHeight)));
 
     if(rTrans.hasValue())


More information about the Libreoffice-commits mailing list