Kaydet (Commit) 19ad91f7 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

windows opengl: Proof-of-concept text rendering.

We don't have a method that would paint a texture with transparency yet.  We
also need to limit the size of the DIBSection exactly to what we are going to
paint, no point in creating a huge bitmap that is mostly empty (but the part
where is the text being drawn).

Change-Id: Ice0bf325743d08e19e636be73cef6aff3cde5704
üst 966fc1f2
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
class WinOpenGLSalGraphicsImpl : public OpenGLSalGraphicsImpl class WinOpenGLSalGraphicsImpl : public OpenGLSalGraphicsImpl
{ {
friend class WinLayout;
private: private:
WinSalGraphics& mrParent; WinSalGraphics& mrParent;
......
...@@ -146,6 +146,7 @@ class WinSalGraphics : public SalGraphics ...@@ -146,6 +146,7 @@ class WinSalGraphics : public SalGraphics
{ {
friend class WinSalGraphicsImpl; friend class WinSalGraphicsImpl;
friend class ScopedFont; friend class ScopedFont;
friend class WinLayout;
private: private:
boost::scoped_ptr<SalGraphicsImpl> mpImpl; boost::scoped_ptr<SalGraphicsImpl> mpImpl;
......
...@@ -51,8 +51,11 @@ public: ...@@ -51,8 +51,11 @@ public:
virtual void ReleaseGraphics( SalGraphics* pGraphics ); virtual void ReleaseGraphics( SalGraphics* pGraphics );
virtual bool SetSize( long nNewDX, long nNewDY ); virtual bool SetSize( long nNewDX, long nNewDY );
virtual void GetSize( long& rWidth, long& rHeight ); virtual void GetSize( long& rWidth, long& rHeight );
static HBITMAP ImplCreateVirDevBitmap(HDC hDC, long nDX, long nDY, sal_uInt16 nBitCount, void **ppDummy);
}; };
#endif // INCLUDED_VCL_INC_WIN_SALVD_H #endif // INCLUDED_VCL_INC_WIN_SALVD_H
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -27,14 +27,14 @@ ...@@ -27,14 +27,14 @@
#include <win/salgdi.h> #include <win/salgdi.h>
#include <win/salvd.h> #include <win/salvd.h>
static HBITMAP ImplCreateVirDevBitmap( HDC hDC, long nDX, long nDY, HBITMAP WinSalVirtualDevice::ImplCreateVirDevBitmap(HDC hDC, long nDX, long nDY, sal_uInt16 nBitCount, void **ppData)
sal_uInt16 nBitCount )
{ {
HBITMAP hBitmap; HBITMAP hBitmap;
if ( nBitCount == 1 ) if ( nBitCount == 1 )
{ {
hBitmap = CreateBitmap( (int)nDX, (int)nDY, 1, 1, NULL ); hBitmap = CreateBitmap( (int)nDX, (int)nDY, 1, 1, NULL );
ppData = NULL;
} }
else else
{ {
...@@ -55,9 +55,8 @@ static HBITMAP ImplCreateVirDevBitmap( HDC hDC, long nDX, long nDY, ...@@ -55,9 +55,8 @@ static HBITMAP ImplCreateVirDevBitmap( HDC hDC, long nDX, long nDY,
aBitmapInfo.bmiHeader.biClrUsed = 0; aBitmapInfo.bmiHeader.biClrUsed = 0;
aBitmapInfo.bmiHeader.biClrImportant = 0; aBitmapInfo.bmiHeader.biClrImportant = 0;
void* pDummy;
hBitmap = CreateDIBSection( hDC, &aBitmapInfo, hBitmap = CreateDIBSection( hDC, &aBitmapInfo,
DIB_RGB_COLORS, &pDummy, NULL, DIB_RGB_COLORS, ppData, NULL,
0 ); 0 );
} }
...@@ -87,8 +86,8 @@ SalVirtualDevice* WinSalInstance::CreateVirtualDevice( SalGraphics* pSGraphics, ...@@ -87,8 +86,8 @@ SalVirtualDevice* WinSalInstance::CreateVirtualDevice( SalGraphics* pSGraphics,
if( !hDC ) if( !hDC )
ImplWriteLastError( GetLastError(), "CreateCompatibleDC in CreateVirtualDevice" ); ImplWriteLastError( GetLastError(), "CreateCompatibleDC in CreateVirtualDevice" );
hBmp = ImplCreateVirDevBitmap( pGraphics->getHDC(), void *pDummy;
nDX, nDY, nBitCount ); hBmp = WinSalVirtualDevice::ImplCreateVirDevBitmap(pGraphics->getHDC(), nDX, nDY, nBitCount, &pDummy);
if( !hBmp ) if( !hBmp )
ImplWriteLastError( GetLastError(), "ImplCreateVirDevBitmap in CreateVirtualDevice" ); ImplWriteLastError( GetLastError(), "ImplCreateVirDevBitmap in CreateVirtualDevice" );
// #124826# continue even if hBmp could not be created // #124826# continue even if hBmp could not be created
...@@ -198,8 +197,8 @@ bool WinSalVirtualDevice::SetSize( long nDX, long nDY ) ...@@ -198,8 +197,8 @@ bool WinSalVirtualDevice::SetSize( long nDX, long nDY )
return TRUE; // ??? return TRUE; // ???
else else
{ {
HBITMAP hNewBmp = ImplCreateVirDevBitmap( getHDC(), nDX, nDY, void *pDummy;
mnBitCount ); HBITMAP hNewBmp = ImplCreateVirDevBitmap(getHDC(), nDX, nDY, mnBitCount, &pDummy);
if ( hNewBmp ) if ( hNewBmp )
{ {
SelectBitmap( getHDC(), hNewBmp ); SelectBitmap( getHDC(), hNewBmp );
......
...@@ -22,10 +22,12 @@ ...@@ -22,10 +22,12 @@
#include "osl/module.h" #include "osl/module.h"
#include "osl/file.h" #include "osl/file.h"
#include <opengl/texture.hxx>
#include <opengl/win/gdiimpl.hxx>
#include <vcl/opengl/OpenGLHelper.hxx> #include <vcl/opengl/OpenGLHelper.hxx>
#include <win/salgdi.h>
#include "win/salgdi.h" #include <win/saldata.hxx>
#include "win/saldata.hxx" #include <win/salvd.h>
#include "sft.hxx" #include "sft.hxx"
#include "sallayout.hxx" #include "sallayout.hxx"
...@@ -151,14 +153,62 @@ SCRIPT_CACHE& WinLayout::GetScriptCache() const ...@@ -151,14 +153,62 @@ SCRIPT_CACHE& WinLayout::GetScriptCache() const
void WinLayout::DrawText(SalGraphics& rGraphics) const void WinLayout::DrawText(SalGraphics& rGraphics) const
{ {
if (mbUseOpenGL) WinSalGraphics& rWinGraphics = static_cast<WinSalGraphics&>(rGraphics);
HDC hDC = rWinGraphics.getHDC();
if (!mbUseOpenGL)
{ {
// TODO draw to a texture instead // no OpenGL, just classic rendering
DrawTextImpl(static_cast<WinSalGraphics&>(rGraphics).getHDC()); DrawTextImpl(hDC);
} }
else else
{ {
DrawTextImpl(static_cast<WinSalGraphics&>(rGraphics).getHDC()); // we have to render the text to a hidden texture, and draw it
// FIXME so that we don't have to use enormous bitmap, move the text
// to 0,0, size the width / height accordingly, and move it back via
// SalTwoRects later
const int width = 1024;
const int height = 1024;
const int bpp = 32;
HDC compatibleDC = CreateCompatibleDC(hDC);
sal_uInt8 *data;
HBITMAP hBitmap = WinSalVirtualDevice::ImplCreateVirDevBitmap(compatibleDC, width, height, bpp, reinterpret_cast<void **>(&data));
// FIXME fill transparent instead of 128
memset(data, 128, width*height*4);
// draw the text to the hidden DC
HGDIOBJ hBitmapOld = SelectObject(compatibleDC, hBitmap);
SelectFont(compatibleDC, mhFont);
DrawTextImpl(compatibleDC);
SelectObject(compatibleDC, hBitmapOld);
// and turn it into a texture
OpenGLTexture aTexture(width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
CHECK_GL_ERROR();
WinOpenGLSalGraphicsImpl *pImpl = dynamic_cast<WinOpenGLSalGraphicsImpl*>(rWinGraphics.mpImpl.get());
if (pImpl)
{
SalTwoRect aRects;
aRects.mnSrcX = 0;
aRects.mnSrcY = 0;
aRects.mnSrcWidth = width;
aRects.mnSrcHeight = height;
aRects.mnDestX = 0;
aRects.mnDestY = 0;
aRects.mnDestWidth = width;
aRects.mnDestHeight = height;
// FIXME We don't have a method that could paint a texture with
// transparency yet, use it when we have it
pImpl->DrawTexture(aTexture.Id(), Size(width, height), aRects);
}
DeleteObject(hBitmap);
DeleteDC(compatibleDC);
} }
} }
......
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