summaryrefslogtreecommitdiff
path: root/vcl/opengl/x11
diff options
context:
space:
mode:
authorLouis-Francis Ratté-Boulianne <lfrb@collabora.com>2014-11-11 13:43:56 -0500
committerMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-11-12 04:07:21 +0100
commit74c3dbe87e7256f8f8b3eac3a34415780035f465 (patch)
tree1271e6355a0a47850435be794581c1bfc9a4c17f /vcl/opengl/x11
parentc7a5ce27e6d27af4d868dedcde1f650fa129e6f8 (diff)
vcl: Read back OpenGL FBO to create offscreen X11 pixmap
Change-Id: I330e7d62bf31b4a90b5866d9531f073f7c69c92a
Diffstat (limited to 'vcl/opengl/x11')
-rw-r--r--vcl/opengl/x11/gdiimpl.cxx33
1 files changed, 31 insertions, 2 deletions
diff --git a/vcl/opengl/x11/gdiimpl.cxx b/vcl/opengl/x11/gdiimpl.cxx
index 6e803bd21acd..13b70495341a 100644
--- a/vcl/opengl/x11/gdiimpl.cxx
+++ b/vcl/opengl/x11/gdiimpl.cxx
@@ -83,9 +83,38 @@ X11Pixmap* X11OpenGLSalGraphicsImpl::GetPixmapFromScreen( const Rectangle& rRect
{
Display* pDisplay = mrParent.GetXDisplay();
SalX11Screen nScreen = mrParent.GetScreenNumber();
+ XVisualInfo aVisualInfo;
+ X11Pixmap* pPixmap;
+ XImage* pImage;
+ sal_uInt8* pData;
SAL_INFO( "vcl.opengl", "GetPixmapFromScreen" );
- return new X11Pixmap( pDisplay, nScreen, rRect.GetWidth(), rRect.GetHeight(), 24 );
+ // TODO: lfrb: Use context depth
+ pPixmap = new X11Pixmap( pDisplay, nScreen, rRect.GetWidth(), rRect.GetHeight(), 24 );
+
+ if( !OpenGLHelper::GetVisualInfo( pDisplay, nScreen.getXScreen(), aVisualInfo ) )
+ return pPixmap;
+
+ // make sure everything is synced up before reading back
+ maContext.makeCurrent();
+ glXWaitX();
+
+ // TODO: lfrb: What if offscreen?
+ pData = new sal_uInt8[rRect.GetWidth() * rRect.GetHeight() * 4];
+ glPixelStorei( GL_PACK_ALIGNMENT, 1 );
+ glReadPixels( rRect.Left(), GetHeight() - rRect.Top(), rRect.GetWidth(), rRect.GetHeight(),
+ GL_RGBA, GL_UNSIGNED_BYTE, pData );
+
+ pImage = XCreateImage( pDisplay, aVisualInfo.visual, 24, ZPixmap, 0, (char*) pData,
+ rRect.GetWidth(), rRect.GetHeight(), 8, 0 );
+ XInitImage( pImage );
+ GC aGC = XCreateGC( pDisplay, pPixmap->GetPixmap(), 0, NULL );
+ XPutImage( pDisplay, pPixmap->GetDrawable(), aGC, pImage,
+ 0, 0, 0, 0, rRect.GetWidth(), rRect.GetHeight() );
+ XFreeGC( pDisplay, aGC );
+ XDestroyImage( pImage );
+
+ return pPixmap;
}
bool X11OpenGLSalGraphicsImpl::RenderPixmapToScreen( X11Pixmap* pPixmap, int nX, int nY )
@@ -128,7 +157,7 @@ bool X11OpenGLSalGraphicsImpl::RenderPixmapToScreen( X11Pixmap* pPixmap, int nX,
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- DrawTexture( nTexture, pPixmap->GetSize(), aPosAry );
+ DrawTexture( nTexture, pPixmap->GetSize(), aPosAry, !bInverted );
glXReleaseTexImageEXT( pDisplay, pGlxPixmap, GLX_FRONT_LEFT_EXT );
glDeleteTextures( 1, &nTexture );