summaryrefslogtreecommitdiff
path: root/vcl/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'vcl/opengl')
-rw-r--r--vcl/opengl/framebuffer.cxx70
-rw-r--r--vcl/opengl/gdiimpl.cxx138
-rw-r--r--vcl/opengl/salbmp.cxx17
-rw-r--r--vcl/opengl/scale.cxx35
-rw-r--r--vcl/opengl/x11/gdiimpl.cxx64
-rw-r--r--vcl/opengl/x11/salvd.cxx102
6 files changed, 286 insertions, 140 deletions
diff --git a/vcl/opengl/framebuffer.cxx b/vcl/opengl/framebuffer.cxx
new file mode 100644
index 000000000000..29f9a781130a
--- /dev/null
+++ b/vcl/opengl/framebuffer.cxx
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/log.hxx>
+
+#include <opengl/framebuffer.hxx>
+
+#include <vcl/opengl/OpenGLHelper.hxx>
+
+OpenGLFramebuffer::OpenGLFramebuffer() :
+ mnId( 0 ),
+ mpPrevFramebuffer( NULL ),
+ mpNextFramebuffer( NULL )
+{
+ glGenFramebuffers( 1, &mnId );
+ SAL_INFO( "vcl.opengl", "Created framebuffer " << (int)mnId );
+}
+
+OpenGLFramebuffer::~OpenGLFramebuffer()
+{
+ glDeleteFramebuffers( 1, &mnId );
+}
+
+void OpenGLFramebuffer::Bind()
+{
+ glBindFramebuffer( GL_FRAMEBUFFER, mnId );
+ SAL_INFO( "vcl.opengl", "Binding framebuffer " << (int)mnId );
+ CHECK_GL_ERROR();
+}
+
+void OpenGLFramebuffer::Unbind()
+{
+ glBindFramebuffer( GL_FRAMEBUFFER, 0 );
+ SAL_INFO( "vcl.opengl", "Binding default framebuffer" );
+ CHECK_GL_ERROR();
+}
+
+bool OpenGLFramebuffer::IsFree() const
+{
+ return (!maAttachedTexture);
+}
+
+bool OpenGLFramebuffer::IsAttached( const OpenGLTexture& rTexture ) const
+{
+ return ( maAttachedTexture == rTexture );
+}
+
+void OpenGLFramebuffer::AttachTexture( const OpenGLTexture& rTexture )
+{
+ SAL_INFO( "vcl.opengl", "Attaching texture " << rTexture.Id() << " to framebuffer " << (int)mnId );
+ maAttachedTexture = rTexture;
+ glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
+ maAttachedTexture.Id(), 0 );
+ CHECK_GL_ERROR();
+}
+
+void OpenGLFramebuffer::DetachTexture()
+{
+ maAttachedTexture = OpenGLTexture();
+ glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0 );
+ CHECK_GL_ERROR();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 8f4c6c445f8e..28f7959567b1 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -65,10 +65,10 @@
OpenGLSalGraphicsImpl::OpenGLSalGraphicsImpl()
: mpContext(0)
+ , mpFramebuffer(NULL)
, mbUseScissor(false)
, mbUseStencil(false)
, mbOffscreen(false)
- , mnFramebufferId(0)
, mnLineColor(SALCOLOR_NONE)
, mnFillColor(SALCOLOR_NONE)
, mnSolidProgram(0)
@@ -112,24 +112,25 @@ OpenGLSalGraphicsImpl::~OpenGLSalGraphicsImpl()
ReleaseContext();
}
-bool OpenGLSalGraphicsImpl::AcquireContext( bool bOffscreen )
+OpenGLContext* OpenGLSalGraphicsImpl::GetOpenGLContext()
+{
+ if( !mpContext )
+ AcquireContext();
+ return mpContext;
+}
+
+bool OpenGLSalGraphicsImpl::AcquireContext( )
{
ImplSVData* pSVData = ImplGetSVData();
if( mpContext )
mpContext->DeRef();
- if( bOffscreen )
- {
- mpContext = CreatePixmapContext();
- return (mpContext != NULL);
- }
-
OpenGLContext* pContext = pSVData->maGDIData.mpLastContext;
while( pContext )
{
// check if this context can be used by this SalGraphicsImpl instance
- if( CompareWinContext( pContext ) )
+ if( UseContext( pContext ) )
break;
pContext = pContext->mpPrevContext;
}
@@ -137,7 +138,7 @@ bool OpenGLSalGraphicsImpl::AcquireContext( bool bOffscreen )
if( pContext )
pContext->AddRef();
else
- pContext = CreateWinContext();
+ pContext = mbOffscreen ? CreatePixmapContext() : CreateWinContext();
mpContext = pContext;
return (mpContext != NULL);
@@ -153,68 +154,41 @@ bool OpenGLSalGraphicsImpl::ReleaseContext()
void OpenGLSalGraphicsImpl::Init()
{
- const bool bOffscreen = IsOffscreen();
+ mbOffscreen = IsOffscreen();
// check if we can simply re-use the same context
if( mpContext )
{
- if( bOffscreen != mbOffscreen || ( !mbOffscreen && CompareWinContext( mpContext ) ) )
+ if( !UseContext( mpContext ) )
ReleaseContext();
}
- if( !mpContext && !AcquireContext( bOffscreen ) )
+ // reset the offscreen texture
+ if( !mbOffscreen ||
+ maOffscreenTex.GetWidth() != GetWidth() ||
+ maOffscreenTex.GetHeight() != GetHeight() )
{
- SAL_WARN( "vcl.opengl", "Couldn't acquire context for SalGraphics" );
- return;
- }
-
- mpContext->makeCurrent();
-
- if( mbOffscreen == bOffscreen )
- {
- // Nothing more to do for onscreen case
- if( !mbOffscreen )
- return;
-
- // Already enabled and same size
- if( maOffscreenTex.GetWidth() == GetWidth() &&
- maOffscreenTex.GetHeight() == GetHeight() )
- return;
- }
- else
- {
- mbOffscreen = bOffscreen;
- if( bOffscreen )
- glGenFramebuffers( 1, &mnFramebufferId );
- else
- glDeleteFramebuffers( 1, &mnFramebufferId );
- }
-
- // Create/update attached offscreen texture
- if( mbOffscreen )
- {
- glBindFramebuffer( GL_FRAMEBUFFER, mnFramebufferId );
- maOffscreenTex = OpenGLTexture( GetWidth(), GetHeight() );
- glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, maOffscreenTex.Id(), 0 );
- GLenum nStatus = glCheckFramebufferStatus( GL_FRAMEBUFFER );
- if( nStatus != GL_FRAMEBUFFER_COMPLETE )
- SAL_WARN( "vcl.opengl", "Incomplete framebuffer " << nStatus );
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- CHECK_GL_ERROR();
+ maOffscreenTex = OpenGLTexture();
}
}
void OpenGLSalGraphicsImpl::PreDraw()
{
- assert( mpContext && mpContext->isInitialized() );
+ if( !mpContext && !AcquireContext() )
+ {
+ SAL_WARN( "vcl.opengl", "Couldn't acquire context" );
+ return;
+ }
mpContext->makeCurrent();
- // TODO: lfrb: make sure the render target has the right size
- if( mbOffscreen )
- CheckOffscreenTexture();
+ CHECK_GL_ERROR();
+
+ if( !mbOffscreen )
+ mpContext->AcquireDefaultFramebuffer();
else
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
+ CheckOffscreenTexture();
CHECK_GL_ERROR();
+
glViewport( 0, 0, GetWidth(), GetHeight() );
ImplInitClipRegion();
@@ -223,15 +197,16 @@ void OpenGLSalGraphicsImpl::PreDraw()
void OpenGLSalGraphicsImpl::PostDraw()
{
- if( mbOffscreen )
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- else if( mpContext->mnPainting == 0 )
+ if( !mbOffscreen && mpContext->mnPainting == 0 )
glFlush();
if( mbUseScissor )
glDisable( GL_SCISSOR_TEST );
if( mbUseStencil )
glDisable( GL_STENCIL_TEST );
+ mpContext->ReleaseFramebuffer( mpFramebuffer );
+ mpFramebuffer = NULL;
+
CHECK_GL_ERROR();
}
@@ -287,6 +262,8 @@ void OpenGLSalGraphicsImpl::ImplInitClipRegion()
glStencilFunc( GL_EQUAL, 1, 0x1 );
glEnable( GL_STENCIL_TEST );
}
+
+ CHECK_GL_ERROR();
}
bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip )
@@ -379,28 +356,27 @@ void OpenGLSalGraphicsImpl::SetROPFillColor( SalROPColor /*nROPColor*/ )
bool OpenGLSalGraphicsImpl::CheckOffscreenTexture()
{
- glBindFramebuffer( GL_FRAMEBUFFER, mnFramebufferId );
+ if( !maOffscreenTex )
+ maOffscreenTex = OpenGLTexture( GetWidth(), GetHeight() );
- if( maOffscreenTex.IsUnique() )
+ if( !maOffscreenTex.IsUnique() )
{
- GLenum nStatus = glCheckFramebufferStatus( GL_FRAMEBUFFER );
- if( nStatus != GL_FRAMEBUFFER_COMPLETE )
- SAL_WARN( "vcl.opengl", "Incomplete framebuffer " << nStatus );
- return true;
- }
+ SalTwoRect aPosAry;
+ aPosAry.mnSrcX = aPosAry.mnDestX = 0;
+ aPosAry.mnSrcY = aPosAry.mnDestY = 0;
+ aPosAry.mnSrcWidth = aPosAry.mnDestWidth = GetWidth();
+ aPosAry.mnSrcHeight = aPosAry.mnDestHeight = GetHeight();
- SalTwoRect aPosAry;
- aPosAry.mnSrcX = aPosAry.mnDestX = 0;
- aPosAry.mnSrcY = aPosAry.mnDestY = 0;
- aPosAry.mnSrcWidth = aPosAry.mnDestWidth = GetWidth();
- aPosAry.mnSrcHeight = aPosAry.mnDestHeight = GetHeight();
-
- // TODO: lfrb: User GL_ARB_copy_image?
- OpenGLTexture aNewTex = OpenGLTexture( GetWidth(), GetHeight() );
- glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, aNewTex.Id(), 0 );
- glViewport( 0, 0, GetWidth(), GetHeight() );
- DrawTexture( maOffscreenTex, aPosAry );
- maOffscreenTex = aNewTex;
+ // TODO: lfrb: User GL_ARB_copy_image?
+ OpenGLTexture aNewTex = OpenGLTexture( GetWidth(), GetHeight() );
+ mpFramebuffer = mpContext->AcquireFramebuffer( aNewTex );
+ DrawTexture( maOffscreenTex, aPosAry );
+ maOffscreenTex = aNewTex;
+ }
+ else
+ {
+ mpFramebuffer = mpContext->AcquireFramebuffer( maOffscreenTex );
+ }
CHECK_GL_ERROR();
return true;
@@ -1916,13 +1892,17 @@ bool OpenGLSalGraphicsImpl::drawGradient(const tools::PolyPolygon& rPolyPoly,
void OpenGLSalGraphicsImpl::beginPaint()
{
- SAL_INFO( "vcl.opengl", "BEGIN PAINT " << this );
+ if( !mpContext && !AcquireContext() )
+ return;
+
mpContext->mnPainting++;
}
void OpenGLSalGraphicsImpl::endPaint()
{
- SAL_INFO( "vcl.opengl", "END PAINT " << this );
+ if( !mpContext && !AcquireContext() )
+ return;
+
mpContext->mnPainting--;
assert( mpContext->mnPainting >= 0 );
if( mpContext->mnPainting == 0 && !mbOffscreen )
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 8cd756176e74..ce566b061e70 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -35,7 +35,8 @@ static bool isValidBitCount( sal_uInt16 nBitCount )
}
OpenGLSalBitmap::OpenGLSalBitmap()
-: mbDirtyTexture(true)
+: mpContext(NULL)
+, mbDirtyTexture(true)
, mnBits(0)
, mnBytesPerRow(0)
, mnWidth(0)
@@ -472,10 +473,14 @@ OpenGLContext* OpenGLSalBitmap::GetBitmapContext() const
void OpenGLSalBitmap::makeCurrent()
{
- // Always use the default window's context for bitmap
- OpenGLContext* pContext = GetBitmapContext();
- assert(pContext && "Couldn't get default OpenGL context provider");
- pContext->makeCurrent();
+ ImplSVData* pSVData = ImplGetSVData();
+
+ // TODO: make sure we can really use the last used context
+ mpContext = pSVData->maGDIData.mpLastContext;
+ if( !mpContext )
+ mpContext = GetBitmapContext();
+ assert(mpContext && "Couldn't get an OpenGL context");
+ mpContext->makeCurrent();
}
BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( bool /*bReadOnly*/ )
@@ -490,8 +495,6 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( bool /*bReadOnly*/ )
if( !maPendingOps.empty() )
{
- makeCurrent();
-
SAL_INFO( "vcl.opengl", "** Creating texture and reading it back immediatly" );
if( !CreateTexture() || !AllocateUserData() || !ReadTexture() )
return NULL;
diff --git a/vcl/opengl/scale.cxx b/vcl/opengl/scale.cxx
index 9c52cc271f48..d3966521136f 100644
--- a/vcl/opengl/scale.cxx
+++ b/vcl/opengl/scale.cxx
@@ -86,8 +86,8 @@ bool OpenGLSalBitmap::ImplScaleFilter(
const double& rScaleY,
GLenum nFilter )
{
+ OpenGLFramebuffer* pFramebuffer;
GLuint nProgram;
- GLuint nFramebufferId;
GLenum nOldFilter;
int nNewWidth( mnWidth * rScaleX );
int nNewHeight( mnHeight * rScaleY );
@@ -96,15 +96,13 @@ bool OpenGLSalBitmap::ImplScaleFilter(
if( nProgram == 0 )
return false;
- glGenFramebuffers( 1, &nFramebufferId );
- glBindFramebuffer( GL_FRAMEBUFFER, nFramebufferId );
- glUseProgram( nProgram );
- glUniform1i( mnTexSamplerUniform, 0 );
-
OpenGLTexture aNewTex = OpenGLTexture( nNewWidth, nNewHeight );
- glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, aNewTex.Id(), 0 );
+ pFramebuffer = mpContext->AcquireFramebuffer( aNewTex );
- glViewport( 0, 0, nNewWidth, nNewHeight );
+ glUseProgram( nProgram );
+ glUniform1i( mnTexSamplerUniform, 0 );
+ glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
+ glClear( GL_COLOR_BUFFER_BIT );
maTexture.Bind();
nOldFilter = maTexture.GetFilter();
maTexture.SetFilter( nFilter );
@@ -113,8 +111,7 @@ bool OpenGLSalBitmap::ImplScaleFilter(
maTexture.Unbind();
glUseProgram( 0 );
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- glDeleteFramebuffers( 1, &nFramebufferId );
+ mpContext->ReleaseFramebuffer( pFramebuffer );
mnWidth = nNewWidth;
mnHeight = nNewHeight;
@@ -167,8 +164,8 @@ bool OpenGLSalBitmap::ImplScaleConvolution(
const double& rScaleY,
const Kernel& aKernel )
{
+ OpenGLFramebuffer* pFramebuffer;
GLfloat* pWeights( 0 );
- GLuint nFramebufferId;
GLuint nProgram;
sal_uInt32 nKernelSize;
GLfloat aOffsets[32];
@@ -181,8 +178,6 @@ bool OpenGLSalBitmap::ImplScaleConvolution(
if( nProgram == 0 )
return false;
- glGenFramebuffers( 1, &nFramebufferId );
- glBindFramebuffer( GL_FRAMEBUFFER, nFramebufferId );
glUseProgram( nProgram );
glUniform1i( mnConvSamplerUniform, 0 );
CHECK_GL_ERROR();
@@ -191,8 +186,7 @@ bool OpenGLSalBitmap::ImplScaleConvolution(
if( mnWidth != nNewWidth )
{
OpenGLTexture aScratchTex = OpenGLTexture( nNewWidth, mnHeight );
- glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, aScratchTex.Id(), 0 );
- CHECK_GL_ERROR();
+ pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex );
for( sal_uInt32 i = 0; i < 16; i++ )
{
@@ -205,19 +199,19 @@ bool OpenGLSalBitmap::ImplScaleConvolution(
glUniform2fv( mnConvOffsetsUniform, 16, aOffsets );
CHECK_GL_ERROR();
- glViewport( 0, 0, nNewWidth, mnHeight );
maTexture.Bind();
maTexture.Draw();
maTexture.Unbind();
maTexture = aScratchTex;
+ mpContext->ReleaseFramebuffer( pFramebuffer );
}
// vertical scaling in final texture
if( mnHeight != nNewHeight )
{
OpenGLTexture aScratchTex = OpenGLTexture( nNewWidth, nNewHeight );
- glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, aScratchTex.Id(), 0 );
+ pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex );
for( sal_uInt32 i = 0; i < 16; i++ )
{
@@ -229,17 +223,15 @@ bool OpenGLSalBitmap::ImplScaleConvolution(
glUniform2fv( mnConvOffsetsUniform, 16, aOffsets );
CHECK_GL_ERROR();
- glViewport( 0, 0, nNewWidth, nNewHeight );
maTexture.Bind();
maTexture.Draw();
maTexture.Unbind();
maTexture = aScratchTex;
+ mpContext->ReleaseFramebuffer( pFramebuffer );
}
glUseProgram( 0 );
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- glDeleteFramebuffers( 1, &nFramebufferId );
mnWidth = nNewWidth;
mnHeight = nNewHeight;
@@ -314,7 +306,8 @@ bool OpenGLSalBitmap::Scale( const double& rScaleX, const double& rScaleY, sal_u
nScaleFlag == BMP_SCALE_LANCZOS )
{
//TODO maUserBuffer.reset();
- if( GetBitmapContext() == NULL )
+ makeCurrent();
+ if( mpContext == NULL )
{
SAL_INFO( "vcl.opengl", "Add ScaleOp to pending operations" );
maPendingOps.push_back( new ScaleOp( this, rScaleX, rScaleY, nScaleFlag ) );
diff --git a/vcl/opengl/x11/gdiimpl.cxx b/vcl/opengl/x11/gdiimpl.cxx
index 605cbd55d760..b01e476ba8a1 100644
--- a/vcl/opengl/x11/gdiimpl.cxx
+++ b/vcl/opengl/x11/gdiimpl.cxx
@@ -7,16 +7,20 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include "vcl/salbtype.hxx"
+#include <vcl/salbtype.hxx>
-#include "unx/pixmap.hxx"
-#include "unx/saldisp.hxx"
-#include "unx/salframe.h"
-#include "unx/salgdi.h"
-#include "unx/salvd.h"
+#include <svdata.hxx>
-#include "opengl/texture.hxx"
-#include "opengl/x11/gdiimpl.hxx"
+#include <unx/pixmap.hxx>
+#include <unx/saldisp.hxx>
+#include <unx/salframe.h>
+#include <unx/salgdi.h>
+#include <unx/salvd.h>
+#include <unx/x11/xlimits.hxx>
+
+#include <opengl/texture.hxx>
+#include <opengl/x11/gdiimpl.hxx>
+#include <opengl/x11/salvd.hxx>
#include <vcl/opengl/OpenGLContext.hxx>
#include <vcl/opengl/OpenGLHelper.hxx>
@@ -36,12 +40,7 @@ GLfloat X11OpenGLSalGraphicsImpl::GetWidth() const
if( mrParent.m_pFrame )
return mrParent.m_pFrame->maGeometry.nWidth;
else if( mrParent.m_pVDev )
- {
- long nWidth = 0;
- long nHeight = 0;
- mrParent.m_pVDev->GetSize( nWidth, nHeight );
- return nWidth;
- }
+ return static_cast< X11OpenGLSalVirtualDevice* >(mrParent.m_pVDev)->GetWidth();
return 1;
}
@@ -50,12 +49,7 @@ GLfloat X11OpenGLSalGraphicsImpl::GetHeight() const
if( mrParent.m_pFrame )
return mrParent.m_pFrame->maGeometry.nHeight;
else if( mrParent.m_pVDev )
- {
- long nWidth = 0;
- long nHeight = 0;
- mrParent.m_pVDev->GetSize( nWidth, nHeight );
- return nHeight;
- }
+ return static_cast< X11OpenGLSalVirtualDevice* >(mrParent.m_pVDev)->GetHeight();
return 1;
}
@@ -79,6 +73,7 @@ OpenGLContext* X11OpenGLSalGraphicsImpl::CreateWinContext()
if( !pProvider )
return NULL;
+
Window aWin = pProvider->GetX11Window();
OpenGLContext* pContext = new OpenGLContext();
pContext->init( mrParent.GetXDisplay(), aWin,
@@ -86,24 +81,27 @@ OpenGLContext* X11OpenGLSalGraphicsImpl::CreateWinContext()
return pContext;
}
-bool X11OpenGLSalGraphicsImpl::CompareWinContext( OpenGLContext* pContext )
+OpenGLContext* X11OpenGLSalGraphicsImpl::CreatePixmapContext()
{
- X11WindowProvider *pProvider = dynamic_cast<X11WindowProvider*>(mrParent.m_pFrame);
+ X11OpenGLSalVirtualDevice* pVDev = dynamic_cast<X11OpenGLSalVirtualDevice*>(mrParent.m_pVDev);
- if( !pProvider || !pContext->isInitialized() )
- return false;
- return ( pContext->getOpenGLWindow().win == pProvider->GetX11Window() );
+ if( pVDev == NULL )
+ return NULL;
+
+ return ImplGetDefaultWindow()->GetGraphics()->GetOpenGLContext();
}
-OpenGLContext* X11OpenGLSalGraphicsImpl::CreatePixmapContext()
+bool X11OpenGLSalGraphicsImpl::UseContext( OpenGLContext* pContext )
{
- if( mrParent.m_pVDev == NULL )
- return NULL;
- OpenGLContext* pContext = new OpenGLContext();
- pContext->init( mrParent.GetXDisplay(), mrParent.m_pVDev->GetDrawable(),
- mrParent.m_pVDev->GetWidth(), mrParent.m_pVDev->GetHeight(),
- mrParent.m_nXScreen.getXScreen() );
- return pContext;
+ X11WindowProvider *pProvider = dynamic_cast<X11WindowProvider*>(mrParent.m_pFrame);
+
+ if( !pContext->isInitialized() )
+ return false;
+
+ if( !pProvider )
+ return ( pContext->getOpenGLWindow().win != None );
+ else
+ return ( pContext->getOpenGLWindow().win == pProvider->GetX11Window() );
}
void X11OpenGLSalGraphicsImpl::copyBits( const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics )
diff --git a/vcl/opengl/x11/salvd.cxx b/vcl/opengl/x11/salvd.cxx
new file mode 100644
index 000000000000..b0dbc0094dd6
--- /dev/null
+++ b/vcl/opengl/x11/salvd.cxx
@@ -0,0 +1,102 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <vcl/sysdata.hxx>
+
+#include <unx/salunx.h>
+#include <unx/saldata.hxx>
+#include <unx/saldisp.hxx>
+#include <unx/salgdi.h>
+#include <unx/salvd.h>
+
+#include <opengl/x11/salvd.hxx>
+
+void X11SalGraphics::Init( X11OpenGLSalVirtualDevice *pDevice )
+{
+ SalDisplay *pDisplay = pDevice->GetDisplay();
+
+ m_nXScreen = pDevice->GetXScreenNumber();
+ m_pColormap = &pDisplay->GetColormap( m_nXScreen );
+
+ m_pVDev = pDevice;
+ m_pFrame = NULL;
+
+ bWindow_ = pDisplay->IsDisplay();
+ bVirDev_ = true;
+
+ mpImpl->Init();
+}
+
+X11OpenGLSalVirtualDevice::X11OpenGLSalVirtualDevice( SalGraphics* pGraphics,
+ long nDX, long nDY,
+ sal_uInt16 nBitCount,
+ const SystemGraphicsData *pData ) :
+ mbGraphics( false ),
+ mnXScreen( 0 )
+{
+ // TODO Do we really need the requested bit count?
+ if( !nBitCount && pGraphics )
+ nBitCount = pGraphics->GetBitCount();
+
+ // TODO Check where a VirtualDevice is created from SystemGraphicsData
+ assert( pData == NULL );
+
+ mpDisplay = GetGenericData()->GetSalDisplay();
+ mnDepth = nBitCount;
+ mnXScreen = pGraphics ? static_cast<X11SalGraphics*>(pGraphics)->GetScreenNumber() :
+ GetGenericData()->GetSalDisplay()->GetDefaultXScreen();
+ mnWidth = nDX;
+ mnHeight = nDY;
+ mpGraphics = new X11SalGraphics();
+ mpGraphics->SetLayout( 0 );
+ mpGraphics->Init( this );
+}
+
+X11OpenGLSalVirtualDevice::~X11OpenGLSalVirtualDevice()
+{
+ if( mpGraphics )
+ delete mpGraphics;
+}
+
+SalGraphics* X11OpenGLSalVirtualDevice::AcquireGraphics()
+{
+ if( mbGraphics )
+ return NULL;
+
+ if( mpGraphics )
+ mbGraphics = true;
+
+ return mpGraphics;
+}
+
+void X11OpenGLSalVirtualDevice::ReleaseGraphics( SalGraphics* )
+{
+ mbGraphics = false;
+}
+
+bool X11OpenGLSalVirtualDevice::SetSize( long nDX, long nDY )
+{
+ if( !nDX ) nDX = 1;
+ if( !nDY ) nDY = 1;
+
+ mnWidth = nDX;
+ mnHeight = nDY;
+ if( mpGraphics )
+ mpGraphics->Init( this );
+
+ return true;
+}
+
+void X11OpenGLSalVirtualDevice::GetSize( long& rWidth, long& rHeight )
+{
+ rWidth = mnWidth;
+ rHeight = mnHeight;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */