Kaydet (Commit) 8c9b3cdc authored tarafından Michael Meeks's avatar Michael Meeks Kaydeden (comit) Markus Mohrhard

cache the bitmap converted to flat RGBA pixels.

Conflicts:
	chart2/source/view/inc/3DChartObjects.hxx
	chart2/source/view/main/3DChartObjects.cxx

Change-Id: Ied38d4457fbc04ded42fe4fb55a8ec654cefa259
üst f46d9c7d
...@@ -15,17 +15,28 @@ ...@@ -15,17 +15,28 @@
#include "GL3DRenderer.hxx" #include "GL3DRenderer.hxx"
#include <boost/ptr_container/ptr_map.hpp> #include <boost/ptr_container/ptr_map.hpp>
#include <boost/shared_array.hpp>
namespace chart { namespace chart {
namespace opengl3D { namespace opengl3D {
struct TextCacheItem
{
TextCacheItem(sal_uInt8 *pPixels, ::Size aSize)
: maSize(aSize), maPixels(pPixels)
{
}
::Size maSize;
boost::shared_array<sal_uInt8> maPixels;
};
class TextCache class TextCache
{ {
public: public:
const BitmapEx& getText(OUString const & rText); const TextCacheItem &getText(OUString const & rText);
private: private:
typedef boost::ptr_map<OUString const, BitmapEx> TextCacheType; typedef boost::ptr_map<OUString const, TextCacheItem> TextCacheType;
TextCacheType maTextCache; TextCacheType maTextCache;
}; };
...@@ -85,7 +96,7 @@ public: ...@@ -85,7 +96,7 @@ public:
void setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight); void setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight);
private: private:
const BitmapEx& mrText; TextCacheItem maText;
glm::vec3 maTopLeft; glm::vec3 maTopLeft;
glm::vec3 maTopRight; glm::vec3 maTopRight;
glm::vec3 maBottomRight; glm::vec3 maBottomRight;
...@@ -100,7 +111,7 @@ public: ...@@ -100,7 +111,7 @@ public:
void setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottomRight); void setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottomRight);
private: private:
const BitmapEx& mrText; TextCacheItem maText;
glm::vec2 maTopLeft; glm::vec2 maTopLeft;
glm::vec2 maBottomRight; glm::vec2 maBottomRight;
}; };
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "glm/gtx/quaternion.hpp" #include "glm/gtx/quaternion.hpp"
#include <com/sun/star/awt/Point.hpp> #include <com/sun/star/awt/Point.hpp>
#include <boost/shared_array.hpp>
#include <tools/gen.hxx> #include <tools/gen.hxx>
#include <vcl/bitmapex.hxx> #include <vcl/bitmapex.hxx>
...@@ -161,8 +162,16 @@ public: ...@@ -161,8 +162,16 @@ public:
void EndAddShape3DExtrudeObject(); void EndAddShape3DExtrudeObject();
void SetSize(const Size& rSize); void SetSize(const Size& rSize);
void SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up); void SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up);
void CreateTextTexture(const BitmapEx& rBitmapEx, glm::vec3 vTopLeft,glm::vec3 vTopRight, glm::vec3 vBottomRight, glm::vec3 vBottomLeft, sal_uInt32 nUniqueId); void CreateTextTexture(const boost::shared_array<sal_uInt8> &bitmapBuf,
void CreateScreenTextTexture(const BitmapEx& rBitmapEx, glm::vec2 vTopLeft, glm::vec2 vBottomRight, sal_uInt32 nUniqueId); ::Size maSizePixels,
glm::vec3 vTopLeft,glm::vec3 vTopRight,
glm::vec3 vBottomRight, glm::vec3 vBottomLeft,
sal_uInt32 nUniqueId);
void CreateScreenTextTexture(const boost::shared_array<sal_uInt8> &bitmapBuf,
::Size maSizePixels,
glm::vec2 vTopLeft, glm::vec2 vBottomRight,
sal_uInt32 nUniqueId);
void ProcessUnrenderedShape(); void ProcessUnrenderedShape();
void SetPickingMode(bool bPickingMode); void SetPickingMode(bool bPickingMode);
......
...@@ -68,7 +68,7 @@ void Line::setLineColor(const Color& rColor) ...@@ -68,7 +68,7 @@ void Line::setLineColor(const Color& rColor)
maLineColor = rColor; maLineColor = rColor;
} }
const BitmapEx& TextCache::getText(OUString const & rText) const TextCacheItem& TextCache::getText(OUString const & rText)
{ {
TextCacheType::const_iterator itr = maTextCache.find(rText); TextCacheType::const_iterator itr = maTextCache.find(rText);
if(itr != maTextCache.end()) if(itr != maTextCache.end())
...@@ -85,14 +85,16 @@ const BitmapEx& TextCache::getText(OUString const & rText) ...@@ -85,14 +85,16 @@ const BitmapEx& TextCache::getText(OUString const & rText)
aDevice.SetBackground(Wallpaper(COL_TRANSPARENT)); aDevice.SetBackground(Wallpaper(COL_TRANSPARENT));
aDevice.DrawText(Point(0,0), rText); aDevice.DrawText(Point(0,0), rText);
BitmapEx* pText = new BitmapEx(aDevice.GetBitmapEx(Point(0,0), aDevice.GetOutputSize())); BitmapEx aText(aDevice.GetBitmapEx(Point(0,0), aDevice.GetOutputSize()));
maTextCache.insert(rText, pText); TextCacheItem *pItem = new TextCacheItem(OpenGLHelper::ConvertBitmapExToRGBABuffer(aText), aText.GetSizePixel());
return *pText; maTextCache.insert(rText, pItem);
return *maTextCache.find(rText)->second;
} }
Text::Text(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const OUString& rStr, sal_uInt32 nId): Text::Text(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const OUString& rStr, sal_uInt32 nId):
Renderable3DObject(pRenderer, nId), Renderable3DObject(pRenderer, nId),
mrText(rTextCache.getText(rStr)) maText(rTextCache.getText(rStr))
{ {
} }
...@@ -100,12 +102,14 @@ void Text::render() ...@@ -100,12 +102,14 @@ void Text::render()
{ {
glm::vec3 dir2 = maTopRight - maTopLeft; glm::vec3 dir2 = maTopRight - maTopLeft;
glm::vec3 bottomLeft = maBottomRight - dir2; glm::vec3 bottomLeft = maBottomRight - dir2;
mpRenderer->CreateTextTexture(mrText, maTopLeft, maTopRight, maBottomRight, bottomLeft, mnUniqueId); mpRenderer->CreateTextTexture(maText.maPixels, maText.maSize,
maTopLeft, maTopRight, maBottomRight, bottomLeft,
mnUniqueId);
} }
Size Text::getSize() const Size Text::getSize() const
{ {
return mrText.GetSizePixel(); return maText.maSize;
} }
void Text::setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight) void Text::setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight)
...@@ -117,7 +121,7 @@ void Text::setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, co ...@@ -117,7 +121,7 @@ void Text::setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, co
ScreenText::ScreenText(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const OUString& rStr, sal_uInt32 nId): ScreenText::ScreenText(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const OUString& rStr, sal_uInt32 nId):
Renderable3DObject(pRenderer, nId), Renderable3DObject(pRenderer, nId),
mrText(rTextCache.getText(rStr)) maText(rTextCache.getText(rStr))
{ {
} }
...@@ -129,7 +133,9 @@ void ScreenText::setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottom ...@@ -129,7 +133,9 @@ void ScreenText::setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottom
void ScreenText::render() void ScreenText::render()
{ {
mpRenderer->CreateScreenTextTexture(mrText, maTopLeft, maBottomRight, mnUniqueId); mpRenderer->CreateScreenTextTexture(maText.maPixels, maText.maSize,
maTopLeft, maBottomRight,
mnUniqueId);
} }
Rectangle::Rectangle(OpenGL3DRenderer* pRenderer, sal_uInt32 nId): Rectangle::Rectangle(OpenGL3DRenderer* pRenderer, sal_uInt32 nId):
......
...@@ -1378,11 +1378,13 @@ void OpenGL3DRenderer::RenderExtrude3DObject() ...@@ -1378,11 +1378,13 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
} }
void OpenGL3DRenderer::CreateScreenTextTexture(const BitmapEx& rBitmapEx, glm::vec2 vTopLeft, glm::vec2 vBottomRight, sal_uInt32 nUniqueId) void OpenGL3DRenderer::CreateScreenTextTexture(
const boost::shared_array<sal_uInt8> &bitmapBuf,
::Size maSizePixels,
glm::vec2 vTopLeft, glm::vec2 vBottomRight, sal_uInt32 nUniqueId)
{ {
long bmpWidth = rBitmapEx.GetSizePixel().Width(); long bmpWidth = maSizePixels.Width();
long bmpHeight = rBitmapEx.GetSizePixel().Height(); long bmpHeight = maSizePixels.Height();
boost::scoped_array<sal_uInt8> bitmapBuf(OpenGLHelper::ConvertBitmapExToRGBABuffer(rBitmapEx));
TextInfo aTextInfo; TextInfo aTextInfo;
aTextInfo.id = getColorAsVector(nUniqueId); aTextInfo.id = getColorAsVector(nUniqueId);
...@@ -1422,11 +1424,14 @@ void OpenGL3DRenderer::CreateScreenTextTexture(const BitmapEx& rBitmapEx, glm::v ...@@ -1422,11 +1424,14 @@ void OpenGL3DRenderer::CreateScreenTextTexture(const BitmapEx& rBitmapEx, glm::v
m_ScreenTextInfoList.push_back(aTextInfo); m_ScreenTextInfoList.push_back(aTextInfo);
} }
void OpenGL3DRenderer::CreateTextTexture(const BitmapEx& rBitmapEx, glm::vec3 vTopLeft,glm::vec3 vTopRight, glm::vec3 vBottomRight, glm::vec3 vBottomLeft, sal_uInt32 nUniqueId) void OpenGL3DRenderer::CreateTextTexture(const boost::shared_array<sal_uInt8> &bitmapBuf,
::Size maSizePixels,
glm::vec3 vTopLeft,glm::vec3 vTopRight,
glm::vec3 vBottomRight, glm::vec3 vBottomLeft,
sal_uInt32 nUniqueId)
{ {
long bmpWidth = rBitmapEx.GetSizePixel().Width(); long bmpWidth = maSizePixels.Width();
long bmpHeight = rBitmapEx.GetSizePixel().Height(); long bmpHeight = maSizePixels.Height();
boost::scoped_array<sal_uInt8> bitmapBuf(OpenGLHelper::ConvertBitmapExToRGBABuffer(rBitmapEx));
TextInfo aTextInfo; TextInfo aTextInfo;
aTextInfo.id = getColorAsVector(nUniqueId); aTextInfo.id = getColorAsVector(nUniqueId);
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include <vcl/opengl/OpenGLHelper.hxx> #include <vcl/opengl/OpenGLHelper.hxx>
#include <boost/scoped_array.hpp>
#include "CommonConverters.hxx" #include "CommonConverters.hxx"
using namespace com::sun::star; using namespace com::sun::star;
...@@ -946,9 +945,21 @@ int OpenGLRender::CreateTextTexture(const BitmapEx& rBitmapEx, const awt::Point& ...@@ -946,9 +945,21 @@ int OpenGLRender::CreateTextTexture(const BitmapEx& rBitmapEx, const awt::Point&
} }
#endif #endif
long bmpWidth = rBitmapEx.GetSizePixel().Width(); boost::shared_array<sal_uInt8> bitmapBuf(OpenGLHelper::ConvertBitmapExToRGBABuffer(rBitmapEx));
long bmpHeight = rBitmapEx.GetSizePixel().Height();
boost::scoped_array<sal_uInt8> bitmapBuf(OpenGLHelper::ConvertBitmapExToRGBABuffer(rBitmapEx)); return CreateTextTexture(bitmapBuf, rBitmapEx.GetSizePixel(),
awt::Point(), aSize, rotation, rTrans);
}
int OpenGLRender::CreateTextTexture(const boost::shared_array<sal_uInt8> &rPixels,
const ::Size &aPixelSize,
const awt::Point&,
const awt::Size& aSize,
long rotation,
const drawing::HomogenMatrix3& rTrans)
{
long bmpWidth = aPixelSize.Width();
long bmpHeight = aPixelSize.Height();
TextInfo aTextInfo; TextInfo aTextInfo;
aTextInfo.rotation = -(double)rotation / 360.0 * 2* GL_PI; aTextInfo.rotation = -(double)rotation / 360.0 * 2* GL_PI;
...@@ -983,7 +994,7 @@ int OpenGLRender::CreateTextTexture(const BitmapEx& rBitmapEx, const awt::Point& ...@@ -983,7 +994,7 @@ int OpenGLRender::CreateTextTexture(const BitmapEx& rBitmapEx, const awt::Point&
CHECK_GL_ERROR(); CHECK_GL_ERROR();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
CHECK_GL_ERROR(); CHECK_GL_ERROR();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmpWidth, bmpHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmapBuf.get()); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmpWidth, bmpHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, rPixels.get());
CHECK_GL_ERROR(); CHECK_GL_ERROR();
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
CHECK_GL_ERROR(); CHECK_GL_ERROR();
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <com/sun/star/drawing/XDrawPage.hpp> #include <com/sun/star/drawing/XDrawPage.hpp>
#include <vcl/font.hxx> #include <vcl/font.hxx>
#include <vcl/opengl/OpenGLContext.hxx> #include <vcl/opengl/OpenGLContext.hxx>
#include <boost/shared_array.hpp>
// Include GLM // Include GLM
#include <list> #include <list>
...@@ -96,9 +97,15 @@ public: ...@@ -96,9 +97,15 @@ public:
int RenderRectangleShape(bool bBorder, bool bFill); int RenderRectangleShape(bool bBorder, bool bFill);
int RectangleShapePoint(float x, float y, float directionX, float directionY); int RectangleShapePoint(float x, float y, float directionX, float directionY);
int CreateTextTexture(const boost::shared_array<sal_uInt8> &rPixels,
const ::Size &aPixelSize,
const ::css::awt::Point&,
const ::css::awt::Size& aSize,
long rotation,
const ::css::drawing::HomogenMatrix3& rTrans);
int CreateTextTexture(const BitmapEx& rBitmapEx, int CreateTextTexture(const BitmapEx& rBitmapEx,
const com::sun::star::awt::Point& aPos, const com::sun::star::awt::Size& aSize, const ::css::awt::Point& aPos, const css::awt::Size& aSize,
long rotation, const com::sun::star::drawing::HomogenMatrix3& rTrans); long rotation, const ::css::drawing::HomogenMatrix3& rTrans);
int CreateTextTexture(::rtl::OUString const &textValue, Font aFont, long fontColor, awt::Point aPos, awt::Size aSize, long rotation); int CreateTextTexture(::rtl::OUString const &textValue, Font aFont, long fontColor, awt::Point aPos, awt::Size aSize, long rotation);
int RenderTextShape(); int RenderTextShape();
......
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