Kaydet (Commit) 80d0b291 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

opengl: use packed texture atlas for glyph cache in win. backend

Change-Id: I6a627699d49bad47213788877fa3947ad2ef83f4
üst 40e9ed91
......@@ -11,6 +11,8 @@
#ifndef INCLUDED_VCL_INC_OPENGL_ACCUMULATEDTEXTURES_H
#define INCLUDED_VCL_INC_OPENGL_ACCUMULATEDTEXTURES_H
#include <vcl/opengl/OpenGLHelper.hxx>
#include <o3tl/make_unique.hxx>
#include "opengl/texture.hxx"
#include <memory>
......@@ -34,10 +36,10 @@ struct AccumulatedTexturesEntry
: maTexture(rTexture)
{}
void insert(const SalColor& aColor, const SalTwoRect& r2Rect)
void insert(const OpenGLTexture& rTexture, const SalColor& aColor, const SalTwoRect& r2Rect)
{
TextureDrawParameters& aDrawParameters = maColorTextureDrawParametersMap[aColor];
maTexture.FillCoords<GL_TRIANGLES>(aDrawParameters.maTextureCoords, r2Rect, false);
rTexture.FillCoords<GL_TRIANGLES>(aDrawParameters.maTextureCoords, r2Rect, false);
GLfloat nX1 = r2Rect.mnDestX;
GLfloat nY1 = r2Rect.mnDestY;
......@@ -86,19 +88,18 @@ public:
maEntries.clear();
}
void insert(const OpenGLTexture& rTexture, const SalColor& aColor, const SalTwoRect& r2Rect)
void insert(OpenGLTexture& rTexture, const SalColor& aColor, const SalTwoRect& r2Rect)
{
GLuint nTextureId = rTexture.Id();
auto iterator = maEntries.find(nTextureId);
if (iterator == maEntries.end())
if (maEntries.find(nTextureId) == maEntries.end())
{
maEntries[nTextureId] = o3tl::make_unique<AccumulatedTexturesEntry>(rTexture);
OpenGLTexture aWholeTexture(rTexture.GetWholeTexture());
maEntries[nTextureId] = o3tl::make_unique<AccumulatedTexturesEntry>(aWholeTexture);
}
std::unique_ptr<AccumulatedTexturesEntry>& rEntry = maEntries[nTextureId];
rEntry->insert(aColor, r2Rect);
rEntry->insert(rTexture, aColor, r2Rect);
}
AccumulatedTexturesMap& getAccumulatedTexturesMap()
......
......@@ -96,7 +96,7 @@ private:
public:
OpenGLTexture();
OpenGLTexture(ImplOpenGLTexture* pImpl, Rectangle aRectangle, int nSlotNumber = 0);
OpenGLTexture(ImplOpenGLTexture* pImpl, Rectangle aRectangle, int nSlotNumber);
OpenGLTexture( int nWidth, int nHeight, bool bAllocate = true );
OpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, void const * pData );
......@@ -113,13 +113,15 @@ public:
void GetCoord( GLfloat* pCoord, const SalTwoRect& rPosAry, bool bInverted=false ) const;
void GetWholeCoord( GLfloat* pCoord ) const;
OpenGLTexture GetWholeTexture();
void Bind();
void Unbind();
void Read( GLenum nFormat, GLenum nType, sal_uInt8* pData );
GLuint AddStencil();
GLuint StencilId() const;
bool CopyData(int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData);
void SaveToFile(const OUString& rFileName);
GLenum GetFilter() const;
......
......@@ -147,7 +147,7 @@ public:
void DrawLinearGradient( const Gradient& rGradient, const Rectangle& rRect );
void DrawAxialGradient( const Gradient& rGradient, const Rectangle& rRect );
void DrawRadialGradient( const Gradient& rGradient, const Rectangle& rRect );
void DeferredTextDraw(const OpenGLTexture& rTexture, const SalColor nMaskColor, const SalTwoRect& rPosAry);
void DeferredTextDraw(OpenGLTexture& rTexture, const SalColor nMaskColor, const SalTwoRect& rPosAry);
void FlushDeferredDrawing(bool bInDraw = false);
public:
......
......@@ -172,11 +172,16 @@ public:
SalTwoRect getTwoRect() { return maRects; }
Size getBitmapSize() { return Size(maRects.mnSrcWidth, maRects.mnSrcHeight); }
/// Reset the DC with the defined color.
void fill(sal_uInt32 color);
/// Obtain the texture; the caller must delete it after use.
OpenGLTexture* getTexture();
/// Copy bitmap data to the texture. Texutre must be initialized and the correct size to hold the bitmap.
bool copyToTexture(OpenGLTexture& aTexture);
};
class WinSalGraphics : public SalGraphics
......
......@@ -1669,7 +1669,7 @@ void OpenGLSalGraphicsImpl::DrawMask( OpenGLTexture& rMask, SalColor nMaskColor,
mpProgram->Clean();
}
void OpenGLSalGraphicsImpl::DeferredTextDraw(const OpenGLTexture& rTexture, SalColor aMaskColor, const SalTwoRect& rPosAry)
void OpenGLSalGraphicsImpl::DeferredTextDraw(OpenGLTexture& rTexture, SalColor aMaskColor, const SalTwoRect& rPosAry)
{
mpAccumulatedTextures->insert(rTexture, aMaskColor, rPosAry);
}
......@@ -1682,6 +1682,8 @@ void OpenGLSalGraphicsImpl::FlushDeferredDrawing(bool bIsInDraw)
if (!bIsInDraw)
PreDraw();
VCL_GL_INFO("FlushDeferredDrawing");
OpenGLZone aZone;
#if 0 // Draw a background rect under text for debugging - same color shows text from the same texture
......
......@@ -373,26 +373,31 @@ template <>
void OpenGLTexture::FillCoords<GL_TRIANGLES>(std::vector<GLfloat>& aCoord, const SalTwoRect& rPosAry, bool bInverted) const
{
VCL_GL_INFO("Add coord " << Id() << " [" << maRect.Left() << "," << maRect.Top() << "] " << GetWidth() << "x" << GetHeight() );
VCL_GL_INFO(" With 2Rect Src [" << rPosAry.mnSrcX << ", " << rPosAry.mnSrcY << "] wh (" << rPosAry.mnSrcWidth << ", " << rPosAry.mnSrcHeight << ")");
VCL_GL_INFO(" With 2Rect Dest [" << rPosAry.mnDestX << ", " << rPosAry.mnDestY << "] wh (" << rPosAry.mnDestWidth << ", " << rPosAry.mnDestHeight << ")");
GLfloat x1 = 0.0f;
GLfloat x2 = 0.0f;
GLfloat y1 = 0.0f;
GLfloat y2 = 0.0f;
double fTextureWidth(mpImpl->mnWidth);
double fTextureHeight(mpImpl->mnHeight);
if (mpImpl)
{
x1 = (maRect.Left() + rPosAry.mnSrcX) / (double) mpImpl->mnWidth;
x2 = (maRect.Left() + rPosAry.mnSrcX + rPosAry.mnSrcWidth) / (double) mpImpl->mnWidth;
x1 = (maRect.Left() + rPosAry.mnSrcX) / fTextureWidth;
x2 = (maRect.Left() + rPosAry.mnSrcX + rPosAry.mnSrcWidth) / fTextureWidth;
if (bInverted)
{
y2 = 1.0f - (maRect.Top() + rPosAry.mnSrcY) / (double) mpImpl->mnHeight;
y1 = 1.0f - (maRect.Top() + rPosAry.mnSrcY + rPosAry.mnSrcHeight) / (double) mpImpl->mnHeight;
y2 = 1.0f - (maRect.Top() + rPosAry.mnSrcY) / fTextureHeight;
y1 = 1.0f - (maRect.Top() + rPosAry.mnSrcY + rPosAry.mnSrcHeight) / fTextureHeight;
}
else
{
y1 = 1.0f - (maRect.Top() + rPosAry.mnSrcY) / (double) mpImpl->mnHeight;
y2 = 1.0f - (maRect.Top() + rPosAry.mnSrcY + rPosAry.mnSrcHeight) / (double) mpImpl->mnHeight;
y1 = 1.0f - (maRect.Top() + rPosAry.mnSrcY) / fTextureHeight;
y2 = 1.0f - (maRect.Top() + rPosAry.mnSrcY + rPosAry.mnSrcHeight) / fTextureHeight;
}
}
......@@ -433,6 +438,11 @@ void OpenGLTexture::GetWholeCoord( GLfloat* pCoord ) const
}
}
OpenGLTexture OpenGLTexture::GetWholeTexture()
{
return OpenGLTexture(mpImpl, Rectangle(Point(0, 0), Size(mpImpl->mnWidth, mpImpl->mnHeight)), -1);
}
GLenum OpenGLTexture::GetFilter() const
{
if( mpImpl )
......@@ -440,6 +450,17 @@ GLenum OpenGLTexture::GetFilter() const
return GL_NEAREST;
}
bool OpenGLTexture::CopyData(int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData)
{
if (!pData || mpImpl == nullptr)
return false;
int nX = maRect.Left();
int nY = maRect.Top();
return mpImpl->InsertBuffer(nX, nY, nWidth, nHeight, nFormat, nType, pData);
}
void OpenGLTexture::SetFilter( GLenum nFilter )
{
if( mpImpl )
......
......@@ -591,6 +591,14 @@ OpenGLTexture* OpenGLCompatibleDC::getTexture()
return new OpenGLTexture(maRects.mnSrcWidth, maRects.mnSrcHeight, GL_BGRA, GL_UNSIGNED_BYTE, reinterpret_cast<sal_uInt8*>(mpData));
}
bool OpenGLCompatibleDC::copyToTexture(OpenGLTexture& aTexture)
{
if (!mpImpl)
return false;
return aTexture.CopyData(maRects.mnSrcWidth, maRects.mnSrcHeight, GL_BGRA, GL_UNSIGNED_BYTE, reinterpret_cast<sal_uInt8*>(mpData));
}
WinSalGraphics::WinSalGraphics(WinSalGraphics::Type eType, bool bScreen, HWND hWnd, SalGeometryProvider *pProvider):
mhLocalDC(0),
mbPrinter(eType == WinSalGraphics::PRINTER),
......
This diff is collapsed.
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