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 @@
#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;
};
......
......@@ -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;
}
}
}
......
......@@ -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;
}
......
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