diff options
author | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-05-24 16:44:00 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-05-24 17:38:06 +0200 |
commit | 20e4e65b656e3c47d2a0115ed3f17dabcb8d30da (patch) | |
tree | d85ca9778909f306f1bbc1974ad35d2d1c0fe268 /chart2 | |
parent | 4f8d97753fb48da181c5e7aa277c1d26f092d2ae (diff) |
add a text cache to improve rendering performance
Change-Id: I5b3fbe9476f0eafed4524f57aa7bf65dfd029c1d
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/view/charttypes/GL3DBarChart.cxx | 12 | ||||
-rw-r--r-- | chart2/source/view/inc/3DChartObjects.hxx | 16 | ||||
-rw-r--r-- | chart2/source/view/inc/GL3DBarChart.hxx | 3 | ||||
-rw-r--r-- | chart2/source/view/main/3DChartObjects.cxx | 26 |
4 files changed, 43 insertions, 14 deletions
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index 7a3d3111bc97..dbf0310b15c3 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -30,7 +30,8 @@ GL3DBarChart::GL3DBarChart( mpRenderer(new opengl3D::OpenGL3DRenderer()), mrWindow(rWindow), mpCamera(NULL), - mbValidContext(true) + mbValidContext(true), + mpTextCache(new opengl3D::TextCache()) { Size aSize = mrWindow.GetSizePixel(); mpRenderer->SetSize(aSize); @@ -101,7 +102,8 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer if(!aSeriesName.isEmpty()) { - maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aSeriesName, nId++)); + maShapes.push_back(new opengl3D::Text(mpRenderer.get(), + *mpTextCache, aSeriesName, nId++)); opengl3D::Text* p = static_cast<opengl3D::Text*>(&maShapes.back()); glm::vec3 aTopLeft, aTopRight, aBottomRight; aTopLeft.x = -nBarDistanceY; @@ -181,7 +183,8 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer float nXPos = i * (nBarSizeX + nBarDistanceX); - maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aCats[i], nId++)); + maShapes.push_back(new opengl3D::Text(mpRenderer.get(), *mpTextCache, + aCats[i], nId++)); opengl3D::Text* p = static_cast<opengl3D::Text*>(&maShapes.back()); aTopLeft.x = nXPos + TEXT_HEIGHT; aTopLeft.y = nYPos + calculateTextWidth(aCats[i]) + 0.5 * nBarDistanceY; @@ -193,7 +196,8 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer // create shapes on other side as well - maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aCats[i], nId++)); + maShapes.push_back(new opengl3D::Text(mpRenderer.get(), *mpTextCache, + aCats[i], nId++)); p = static_cast<opengl3D::Text*>(&maShapes.back()); aTopLeft.x = nXPos + TEXT_HEIGHT; aTopLeft.y = - 0.5 * nBarDistanceY; diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index f8138aaa0f4a..c92a435d4797 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -14,10 +14,22 @@ #include <vcl/opengl/OpenGLContext.hxx> #include "GL3DRenderer.hxx" +#include <boost/ptr_container/ptr_map.hpp> + namespace chart { namespace opengl3D { +class TextCache +{ +public: + const BitmapEx& getText(OUString rText); +private: + typedef boost::ptr_map<OUString, BitmapEx> TextCacheType; + + TextCacheType maTextCache; +}; + class Renderable3DObject { public: @@ -65,7 +77,7 @@ private: class Text : public Renderable3DObject { public: - Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId); + Text(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const OUString& rStr, sal_uInt32 nId); virtual void render() SAL_OVERRIDE; Size getSize() const; @@ -73,7 +85,7 @@ public: void setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight); private: - BitmapEx maText; + const BitmapEx& mrText; glm::vec3 maTopLeft; glm::vec3 maTopRight; glm::vec3 maBottomRight; diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx index 674daf6e0d09..15fffde7c6fb 100644 --- a/chart2/source/view/inc/GL3DBarChart.hxx +++ b/chart2/source/view/inc/GL3DBarChart.hxx @@ -26,6 +26,7 @@ namespace opengl3D { class Renderable3DObject; class OpenGL3DRenderer; +class TextCache; class Camera; } @@ -58,6 +59,8 @@ private: opengl3D::Camera* mpCamera; bool mbValidContext; + + boost::scoped_ptr<opengl3D::TextCache> mpTextCache; }; } diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index bf8c10b57889..ea20774720c8 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -68,10 +68,12 @@ void Line::setLineColor(const Color& rColor) maLineColor = rColor; } -Text::Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId): - Renderable3DObject(pRenderer, nId) +const BitmapEx& TextCache::getText(OUString rText) { - // Convert OUString to BitmapEx. + TextCacheType::const_iterator itr = maTextCache.find(rText); + if(itr != maTextCache.end()) + return *itr->second; + VirtualDevice aDevice(*Application::GetDefaultDevice(), 0, 0); Font aFont = aDevice.GetFont(); aFont.SetSize(Size(0, 96)); @@ -79,27 +81,35 @@ Text::Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId): ::Rectangle aRect; aDevice.SetFont(aFont); aDevice.Erase(); - aDevice.GetTextBoundRect(aRect, rStr); + aDevice.GetTextBoundRect(aRect, rText); Size aSize = aRect.GetSize(); aSize.Width() += 5; aSize.Height() *= 1.6; aDevice.SetOutputSizePixel(aSize); aDevice.SetBackground(Wallpaper(COL_TRANSPARENT)); - aDevice.DrawText(Point(0,0), rStr); + aDevice.DrawText(Point(0,0), rText); - maText = BitmapEx(aDevice.GetBitmapEx(Point(0,0), aSize)); + BitmapEx* pText = new BitmapEx(aDevice.GetBitmapEx(Point(0,0), aSize)); + maTextCache.insert(rText, pText); + return *pText; +} + +Text::Text(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const OUString& rStr, sal_uInt32 nId): + Renderable3DObject(pRenderer, nId), + mrText(rTextCache.getText(rStr)) +{ } void Text::render() { glm::vec3 dir2 = maTopRight - maTopLeft; glm::vec3 bottomLeft = maBottomRight - dir2; - mpRenderer->CreateTextTexture(maText, maTopLeft, maTopRight, maBottomRight, bottomLeft, mnUniqueId); + mpRenderer->CreateTextTexture(mrText, maTopLeft, maTopRight, maBottomRight, bottomLeft, mnUniqueId); } Size Text::getSize() const { - return maText.GetSizePixel(); + return mrText.GetSizePixel(); } void Text::setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight) |