Kaydet (Commit) 4ba89680 authored tarafından Markus Mohrhard's avatar Markus Mohrhard Kaydeden (comit) Markus Mohrhard

cache text rendering for performance

Change-Id: I644556ed6b74069d0e7d441d4056310a282f190e
üst 20113d8f
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <boost/unordered_map.hpp>
#if defined( MACOSX ) #if defined( MACOSX )
#include <OpenGL/gl.h> #include <OpenGL/gl.h>
...@@ -97,6 +98,38 @@ class DummyChart; ...@@ -97,6 +98,38 @@ class DummyChart;
struct OpenglContext; 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< class DummyXShape : public cppu::WeakAggImplHelper6<
::com::sun::star::drawing::XShape, ::com::sun::star::drawing::XShape,
com::sun::star::beans::XPropertySet, com::sun::star::beans::XPropertySet,
...@@ -392,6 +425,7 @@ public: ...@@ -392,6 +425,7 @@ public:
virtual void render() SAL_OVERRIDE; virtual void render() SAL_OVERRIDE;
void clear(); void clear();
TextCache& getTextCache();
private: private:
...@@ -403,6 +437,7 @@ private: ...@@ -403,6 +437,7 @@ private:
bool initOpengl(); bool initOpengl();
boost::scoped_ptr<Window> mpWindow; boost::scoped_ptr<Window> mpWindow;
boost::scoped_ptr<SystemChildWindow> pWindow; boost::scoped_ptr<SystemChildWindow> pWindow;
TextCache maTextCache;
public: public:
OpenGLRender m_GLRender; OpenGLRender m_GLRender;
}; };
......
...@@ -48,6 +48,21 @@ namespace chart { ...@@ -48,6 +48,21 @@ namespace chart {
namespace dummy { 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< class DummyPropertySetInfo : public cppu::WeakImplHelper1<
com::sun::star::beans::XPropertySetInfo > com::sun::star::beans::XPropertySetInfo >
{ {
...@@ -791,9 +806,24 @@ DummyText::DummyText(const OUString& rText, const tNameSequence& rNames, ...@@ -791,9 +806,24 @@ DummyText::DummyText(const OUString& rText, const tNameSequence& rNames,
{ {
setProperties(rNames, rValues, maProperties); setProperties(rNames, rValues, maProperties);
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; Font aFont;
std::for_each(maProperties.begin(), maProperties.end(), FontAttribSetter(aFont)); std::for_each(maProperties.begin(), maProperties.end(), FontAttribSetter(aFont));
VirtualDevice aDevice(*Application::GetDefaultDevice(), 0, 0); VirtualDevice aDevice(*Application::GetDefaultDevice(), 0, 0);
aDevice.Erase(); aDevice.Erase();
Rectangle aRect; Rectangle aRect;
...@@ -804,9 +834,11 @@ DummyText::DummyText(const OUString& rText, const tNameSequence& rNames, ...@@ -804,9 +834,11 @@ DummyText::DummyText(const OUString& rText, const tNameSequence& rNames,
aDevice.SetOutputSizePixel(Size(screenWidth * 3, screenHeight)); aDevice.SetOutputSizePixel(Size(screenWidth * 3, screenHeight));
aDevice.SetBackground(Wallpaper(COL_TRANSPARENT)); aDevice.SetBackground(Wallpaper(COL_TRANSPARENT));
aDevice.DrawText(Point(0, 0), rText); aDevice.DrawText(Point(0, 0), rText);
int bmpWidth = aRect.Right() - aRect.Left(); bmpWidth = aRect.Right() - aRect.Left();
int bmpHeight = aRect.Bottom() - aRect.Top(); bmpHeight = aRect.Bottom() - aRect.Top();
maBitmap = BitmapEx(aDevice.GetBitmapEx(aRect.TopLeft(), Size(bmpWidth, bmpHeight))); maBitmap = BitmapEx(aDevice.GetBitmapEx(aRect.TopLeft(), Size(bmpWidth, bmpHeight)));
rCache.insertBitmap(aKey, maBitmap);
}
if(rTrans.hasValue()) if(rTrans.hasValue())
{ {
...@@ -1541,6 +1573,11 @@ void DummyChart::clear() ...@@ -1541,6 +1573,11 @@ void DummyChart::clear()
maShapes.clear(); maShapes.clear();
} }
TextCache& DummyChart::getTextCache()
{
return maTextCache;
}
} }
} }
......
...@@ -404,7 +404,6 @@ uno::Reference< drawing::XShape > ...@@ -404,7 +404,6 @@ uno::Reference< drawing::XShape >
{ {
dummy::DummyText* pText = new dummy::DummyText( rText, rPropNames, rPropValues, dummy::DummyText* pText = new dummy::DummyText( rText, rPropNames, rPropValues,
rATransformation, xTarget, 0 ); rATransformation, xTarget, 0 );
xTarget->add(pText);
return pText; return pText;
} }
...@@ -453,7 +452,6 @@ uno::Reference< drawing::XShape > ...@@ -453,7 +452,6 @@ uno::Reference< drawing::XShape >
dummy::DummyText* pText = new dummy::DummyText(aString, aPropNames, aPropValues, dummy::DummyText* pText = new dummy::DummyText(aString, aPropNames, aPropValues,
uno::makeAny(B2DHomMatrixToHomogenMatrix3(aM)), xTarget, nRotation); uno::makeAny(B2DHomMatrixToHomogenMatrix3(aM)), xTarget, nRotation);
pText->setName(rName); pText->setName(rName);
xTarget->add(pText);
return pText; return pText;
} }
......
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