LCOV - code coverage report
Current view: top level - vcl/opengl/x11 - gdiimpl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 83 1.2 %
Date: 2015-06-13 12:38:46 Functions: 2 11 18.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <vcl/salbtype.hxx>
      11             : 
      12             : #include <svdata.hxx>
      13             : 
      14             : #include <unx/pixmap.hxx>
      15             : #include <unx/saldisp.hxx>
      16             : #include <unx/salframe.h>
      17             : #include <unx/salgdi.h>
      18             : #include <unx/salvd.h>
      19             : #include <unx/x11/xlimits.hxx>
      20             : 
      21             : #include <opengl/texture.hxx>
      22             : #include <opengl/x11/gdiimpl.hxx>
      23             : #include <opengl/x11/salvd.hxx>
      24             : 
      25             : #include <vcl/opengl/OpenGLContext.hxx>
      26             : #include <vcl/opengl/OpenGLHelper.hxx>
      27             : 
      28           0 : X11OpenGLSalGraphicsImpl::X11OpenGLSalGraphicsImpl( X11SalGraphics& rParent ):
      29             :     OpenGLSalGraphicsImpl(rParent,rParent.GetGeometryProvider()),
      30           0 :     mrParent(rParent)
      31             : {
      32           0 : }
      33             : 
      34           0 : X11OpenGLSalGraphicsImpl::~X11OpenGLSalGraphicsImpl()
      35             : {
      36           0 : }
      37             : 
      38           0 : void X11OpenGLSalGraphicsImpl::Init()
      39             : {
      40             :     // The m_pFrame and m_pVDev pointers are updated late in X11
      41           0 :     mpProvider = mrParent.GetGeometryProvider();
      42           0 :     OpenGLSalGraphicsImpl::Init();
      43           0 : }
      44             : 
      45           0 : OpenGLContext* X11OpenGLSalGraphicsImpl::CreateWinContext()
      46             : {
      47           0 :     X11WindowProvider *pProvider = dynamic_cast<X11WindowProvider*>(mrParent.m_pFrame);
      48             : 
      49           0 :     if( !pProvider )
      50           0 :         return NULL;
      51             : 
      52           0 :     Window aWin = pProvider->GetX11Window();
      53           0 :     OpenGLContext* pContext = new OpenGLContext();
      54             :     pContext->init( mrParent.GetXDisplay(), aWin,
      55           0 :                     mrParent.m_nXScreen.getXScreen() );
      56           0 :     return pContext;
      57             : }
      58             : 
      59           0 : bool X11OpenGLSalGraphicsImpl::UseContext( OpenGLContext* pContext )
      60             : {
      61           0 :     X11WindowProvider *pProvider = dynamic_cast<X11WindowProvider*>(mrParent.m_pFrame);
      62             : 
      63           0 :     if( !pContext->isInitialized() )
      64           0 :         return false;
      65             : 
      66           0 :     if( !pProvider )
      67           0 :         return ( pContext->getOpenGLWindow().win != None );
      68             :     else
      69           0 :         return ( pContext->getOpenGLWindow().win == pProvider->GetX11Window() );
      70             : }
      71             : 
      72           0 : void X11OpenGLSalGraphicsImpl::copyBits( const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics )
      73             : {
      74           0 :     OpenGLSalGraphicsImpl *pImpl = pSrcGraphics ? static_cast< OpenGLSalGraphicsImpl* >(pSrcGraphics->GetImpl()) : static_cast< OpenGLSalGraphicsImpl *>(mrParent.GetImpl());
      75           0 :     OpenGLSalGraphicsImpl::DoCopyBits( rPosAry, *pImpl );
      76           0 : }
      77             : 
      78           0 : bool X11OpenGLSalGraphicsImpl::FillPixmapFromScreen( X11Pixmap* pPixmap, int nX, int nY )
      79             : {
      80           0 :     Display* pDisplay = mrParent.GetXDisplay();
      81           0 :     SalX11Screen nScreen = mrParent.GetScreenNumber();
      82             :     XVisualInfo aVisualInfo;
      83             :     XImage* pImage;
      84             :     char* pData;
      85             : 
      86             :     SAL_INFO( "vcl.opengl", "FillPixmapFromScreen" );
      87             : 
      88           0 :     if( !OpenGLHelper::GetVisualInfo( pDisplay, nScreen.getXScreen(), aVisualInfo ) )
      89           0 :         return false;
      90             : 
      91             :     // make sure everything is synced up before reading back
      92           0 :     mpContext->makeCurrent();
      93           0 :     glXWaitX();
      94             : 
      95             :     // TODO: lfrb: What if offscreen?
      96           0 :     pData = static_cast<char*>(malloc( pPixmap->GetWidth() * pPixmap->GetHeight() * 4 ));
      97           0 :     glPixelStorei( GL_PACK_ALIGNMENT, 1 );
      98           0 :     glReadPixels( nX, GetHeight() - nY, pPixmap->GetWidth(), pPixmap->GetHeight(),
      99           0 :                   GL_RGBA, GL_UNSIGNED_BYTE, pData );
     100             : 
     101             :     pImage = XCreateImage( pDisplay, aVisualInfo.visual, 24, ZPixmap, 0, pData,
     102           0 :                            pPixmap->GetWidth(), pPixmap->GetHeight(), 8, 0 );
     103           0 :     XInitImage( pImage );
     104           0 :     GC aGC = XCreateGC( pDisplay, pPixmap->GetPixmap(), 0, NULL );
     105             :     XPutImage( pDisplay, pPixmap->GetDrawable(), aGC, pImage,
     106           0 :                0, 0, 0, 0, pPixmap->GetWidth(), pPixmap->GetHeight() );
     107           0 :     XFreeGC( pDisplay, aGC );
     108           0 :     XDestroyImage( pImage );
     109             : 
     110           0 :     CHECK_GL_ERROR();
     111           0 :     return true;
     112             : }
     113             : 
     114           0 : bool X11OpenGLSalGraphicsImpl::RenderPixmapToScreen( X11Pixmap* pPixmap, X11Pixmap* pMask, int nX, int nY )
     115             : {
     116             :     const int aAttribs[] = {
     117             :         GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
     118             :         GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
     119             :         None
     120           0 :     };
     121           0 :     Display* pDisplay = mrParent.GetXDisplay();
     122             :     bool bInverted;
     123             : 
     124             :     SAL_INFO( "vcl.opengl", "RenderPixmapToScreen (" << nX << " " << nY << ")" );
     125             : 
     126           0 :     const long nWidth = pPixmap->GetWidth();
     127           0 :     const long nHeight = pPixmap->GetHeight();
     128           0 :     SalTwoRect aPosAry(0, 0, nWidth, nHeight, nX, nY, nWidth, nHeight);
     129             : 
     130           0 :     PreDraw();
     131             :     //glClear( GL_COLOR_BUFFER_BIT );
     132             : 
     133           0 :     XSync( pDisplay, 0 );
     134           0 :     GLXFBConfig pFbConfig = OpenGLHelper::GetPixmapFBConfig( pDisplay, bInverted );
     135           0 :     GLXPixmap pGlxPixmap = glXCreatePixmap( pDisplay, pFbConfig, pPixmap->GetPixmap(), aAttribs);
     136             :     GLXPixmap pGlxMask;
     137           0 :     if( pMask != NULL )
     138           0 :         pGlxMask = glXCreatePixmap( pDisplay, pFbConfig, pMask->GetPixmap(), aAttribs);
     139             :     else
     140           0 :         pGlxMask = 0;
     141           0 :     XSync( pDisplay, 0 );
     142             : 
     143           0 :     if( !pGlxPixmap )
     144             :         SAL_WARN( "vcl.opengl", "Couldn't create GLXPixmap" );
     145             : 
     146             :     //TODO: lfrb: glXGetProc to get the functions
     147             : 
     148           0 :     OpenGLTexture aTexture( pPixmap->GetWidth(), pPixmap->GetHeight(), false );
     149           0 :     glActiveTexture( GL_TEXTURE0 );
     150           0 :     aTexture.Bind();
     151           0 :     glXBindTexImageEXT( pDisplay, pGlxPixmap, GLX_FRONT_LEFT_EXT, NULL );
     152           0 :     aTexture.Unbind();
     153             : 
     154           0 :     if( pMask != NULL && pGlxMask )
     155             :     {
     156           0 :         OpenGLTexture aMaskTexture( pMask->GetWidth(), pMask->GetHeight(), false );
     157           0 :         aMaskTexture.Bind();
     158           0 :         glXBindTexImageEXT( pDisplay, pGlxMask, GLX_FRONT_LEFT_EXT, NULL );
     159           0 :         aMaskTexture.Unbind();
     160             : 
     161           0 :         DrawTextureDiff( aTexture, aMaskTexture, aPosAry, bInverted );
     162             : 
     163           0 :         glXReleaseTexImageEXT( pDisplay, pGlxMask, GLX_FRONT_LEFT_EXT );
     164           0 :         glXDestroyPixmap( pDisplay, pGlxMask );
     165             :     }
     166             :     else
     167             :     {
     168           0 :         DrawTexture( aTexture, aPosAry, bInverted );
     169             :     }
     170             : 
     171           0 :     CHECK_GL_ERROR();
     172             : 
     173           0 :     glXReleaseTexImageEXT( pDisplay, pGlxPixmap, GLX_FRONT_LEFT_EXT );
     174           0 :     glXDestroyPixmap( pDisplay, pGlxPixmap );
     175             : 
     176           0 :     PostDraw();
     177             : 
     178           0 :     CHECK_GL_ERROR();
     179           0 :     return true;
     180           9 : }
     181             : 
     182             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11