1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <stdio.h> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <rtl/ustring.hxx> 34*cdf0e10cSrcweir #include <osl/module.h> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <unx/salunx.h> 37*cdf0e10cSrcweir #include <unx/saldata.hxx> 38*cdf0e10cSrcweir #include <unx/saldisp.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <xrender_peer.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir using namespace rtl; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir // --------------------------------------------------------------------------- 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir XRenderPeer::XRenderPeer() 47*cdf0e10cSrcweir : mpDisplay( GetX11SalData()->GetDisplay()->GetDisplay() ), 48*cdf0e10cSrcweir mpStandardFormatA8( NULL ), 49*cdf0e10cSrcweir mnRenderVersion( 0 ), 50*cdf0e10cSrcweir mpRenderLib( NULL ) 51*cdf0e10cSrcweir #ifndef XRENDER_LINK 52*cdf0e10cSrcweir , mpXRenderCompositeTrapezoids( NULL ) 53*cdf0e10cSrcweir , mpXRenderAddTraps( NULL ) 54*cdf0e10cSrcweir #endif // XRENDER_LINK 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir InitRenderLib(); 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir // --------------------------------------------------------------------------- 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir XRenderPeer::~XRenderPeer() 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir osl_unloadModule( mpRenderLib ); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir // --------------------------------------------------------------------------- 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir XRenderPeer& XRenderPeer::GetInstance() 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir static XRenderPeer aPeer; 71*cdf0e10cSrcweir return aPeer; 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir // --------------------------------------------------------------------------- 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir void XRenderPeer::InitRenderLib() 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir int nDummy; 79*cdf0e10cSrcweir if( !XQueryExtension( mpDisplay, "RENDER", &nDummy, &nDummy, &nDummy ) ) 80*cdf0e10cSrcweir return; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir #ifndef XRENDER_LINK 83*cdf0e10cSrcweir // we don't know if we are running on a system with xrender library 84*cdf0e10cSrcweir // we don't want to install system libraries ourselves 85*cdf0e10cSrcweir // => load them dynamically when they are there 86*cdf0e10cSrcweir const OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( "libXrender.so.1" )); 87*cdf0e10cSrcweir mpRenderLib = osl_loadModule( aLibName.pData, SAL_LOADMODULE_DEFAULT ); 88*cdf0e10cSrcweir if( !mpRenderLib ) { 89*cdf0e10cSrcweir #ifdef DEBUG 90*cdf0e10cSrcweir fprintf( stderr, "Display can do XRender, but no %s installed.\n" 91*cdf0e10cSrcweir "Please install for improved display performance\n", OUStringToOString( aLibName.getStr(), 92*cdf0e10cSrcweir osl_getThreadTextEncoding() ).getStr() ); 93*cdf0e10cSrcweir #endif 94*cdf0e10cSrcweir return; 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir oslGenericFunction pFunc; 98*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderQueryExtension" ); 99*cdf0e10cSrcweir if( !pFunc ) return; 100*cdf0e10cSrcweir mpXRenderQueryExtension = (Bool(*)(Display*,int*,int*))pFunc; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderQueryVersion" ); 103*cdf0e10cSrcweir if( !pFunc ) return; 104*cdf0e10cSrcweir mpXRenderQueryVersion = (void(*)(Display*,int*,int*))pFunc; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderFindVisualFormat" ); 107*cdf0e10cSrcweir if( !pFunc ) return; 108*cdf0e10cSrcweir mpXRenderFindVisualFormat = (XRenderPictFormat*(*)(Display*,Visual*))pFunc; 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderFindStandardFormat" ); 111*cdf0e10cSrcweir if( !pFunc ) return; 112*cdf0e10cSrcweir mpXRenderFindStandardFormat = (XRenderPictFormat*(*)(Display*,int))pFunc; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderFindFormat" ); 115*cdf0e10cSrcweir if( !pFunc ) return; 116*cdf0e10cSrcweir mpXRenderFindFormat = (XRenderPictFormat*(*)(Display*,unsigned long, 117*cdf0e10cSrcweir const XRenderPictFormat*,int))pFunc; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderCreateGlyphSet" ); 120*cdf0e10cSrcweir if( !pFunc ) return; 121*cdf0e10cSrcweir mpXRenderCreateGlyphSet = (GlyphSet(*)(Display*,const XRenderPictFormat*))pFunc; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderFreeGlyphSet" ); 124*cdf0e10cSrcweir if( !pFunc ) return; 125*cdf0e10cSrcweir mpXRenderFreeGlyphSet = (void(*)(Display*,GlyphSet))pFunc; 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderAddGlyphs" ); 128*cdf0e10cSrcweir if( !pFunc ) return; 129*cdf0e10cSrcweir mpXRenderAddGlyphs = (void(*)(Display*,GlyphSet,Glyph*,const XGlyphInfo*, 130*cdf0e10cSrcweir int,const char*,int))pFunc; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderFreeGlyphs" ); 133*cdf0e10cSrcweir if( !pFunc ) return; 134*cdf0e10cSrcweir mpXRenderFreeGlyphs = (void(*)(Display*,GlyphSet,Glyph*,int))pFunc; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderCompositeString32" ); 137*cdf0e10cSrcweir if( !pFunc ) return; 138*cdf0e10cSrcweir mpXRenderCompositeString32 = (void(*)(Display*,int,Picture,Picture, 139*cdf0e10cSrcweir const XRenderPictFormat*,GlyphSet,int,int,int,int,const unsigned*,int))pFunc; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderCreatePicture" ); 142*cdf0e10cSrcweir if( !pFunc ) return; 143*cdf0e10cSrcweir mpXRenderCreatePicture = (Picture(*)(Display*,Drawable,const XRenderPictFormat*, 144*cdf0e10cSrcweir unsigned long,const XRenderPictureAttributes*))pFunc; 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderChangePicture" ); 147*cdf0e10cSrcweir if( !pFunc ) return; 148*cdf0e10cSrcweir mpXRenderChangePicture = (void(*)(Display*,Picture,unsigned long,const XRenderPictureAttributes*))pFunc; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderSetPictureClipRegion" ); 151*cdf0e10cSrcweir if( !pFunc ) return; 152*cdf0e10cSrcweir mpXRenderSetPictureClipRegion = (void(*)(Display*,Picture,XLIB_Region))pFunc; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderFreePicture" ); 155*cdf0e10cSrcweir if( !pFunc ) return; 156*cdf0e10cSrcweir mpXRenderFreePicture = (void(*)(Display*,Picture))pFunc; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderComposite" ); 159*cdf0e10cSrcweir if( !pFunc ) return; 160*cdf0e10cSrcweir mpXRenderComposite = (void(*)(Display*,int,Picture,Picture,Picture, 161*cdf0e10cSrcweir int,int,int,int,int,int,unsigned,unsigned))pFunc; 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderFillRectangle" ); 164*cdf0e10cSrcweir if( !pFunc ) return; 165*cdf0e10cSrcweir mpXRenderFillRectangle = (void(*)(Display*,int,Picture,const XRenderColor*, 166*cdf0e10cSrcweir int,int,unsigned int,unsigned int))pFunc; 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderCompositeTrapezoids" ); 169*cdf0e10cSrcweir #if 0 // not having trapezoid support is supported 170*cdf0e10cSrcweir if( !pFunc ) return; 171*cdf0e10cSrcweir #endif 172*cdf0e10cSrcweir mpXRenderCompositeTrapezoids = (void(*)(Display*,int,Picture,Picture, 173*cdf0e10cSrcweir const XRenderPictFormat*,int,int,const XTrapezoid*,int))pFunc; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir pFunc = osl_getAsciiFunctionSymbol( mpRenderLib, "XRenderAddTraps" ); 176*cdf0e10cSrcweir #if 0 // not having trapezoid support is supported 177*cdf0e10cSrcweir if( !pFunc ) return; 178*cdf0e10cSrcweir #endif 179*cdf0e10cSrcweir mpXRenderAddTraps = (void(*)(Display*,Picture,int,int,const _XTrap*,int))pFunc; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir #endif // XRENDER_LINK 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir // needed to initialize libXrender internals, we already know its there 184*cdf0e10cSrcweir #ifdef XRENDER_LINK 185*cdf0e10cSrcweir XRenderQueryExtension( mpDisplay, &nDummy, &nDummy ); 186*cdf0e10cSrcweir #else 187*cdf0e10cSrcweir (*mpXRenderQueryExtension)( mpDisplay, &nDummy, &nDummy ); 188*cdf0e10cSrcweir #endif 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir int nMajor, nMinor; 191*cdf0e10cSrcweir #ifdef XRENDER_LINK 192*cdf0e10cSrcweir XRenderQueryVersion( mpDisplay, &nMajor, &nMinor ); 193*cdf0e10cSrcweir #else 194*cdf0e10cSrcweir (*mpXRenderQueryVersion)( mpDisplay, &nMajor, &nMinor ); 195*cdf0e10cSrcweir #endif 196*cdf0e10cSrcweir mnRenderVersion = 16*nMajor + nMinor; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir // the 8bit alpha mask format must be there 199*cdf0e10cSrcweir XRenderPictFormat aPictFormat={0,0,8,{0,0,0,0,0,0,0,0xFF},0}; 200*cdf0e10cSrcweir mpStandardFormatA8 = FindPictureFormat( PictFormatAlphaMask|PictFormatDepth, aPictFormat ); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir // --------------------------------------------------------------------------- 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir // return mask of screens capable of XRENDER text 206*cdf0e10cSrcweir sal_uInt32 XRenderPeer::InitRenderText() 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir if( mnRenderVersion < 0x01 ) 209*cdf0e10cSrcweir return 0; 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir // #93033# disable XRENDER for old RENDER versions if XINERAMA is present 212*cdf0e10cSrcweir int nDummy; 213*cdf0e10cSrcweir if( XQueryExtension( mpDisplay, "XINERAMA", &nDummy, &nDummy, &nDummy ) ) 214*cdf0e10cSrcweir if( mnRenderVersion < 0x02 ) 215*cdf0e10cSrcweir return 0; 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir if( !mpStandardFormatA8 ) 218*cdf0e10cSrcweir return 0; 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir // and the visual must be supported too on at least one screen 221*cdf0e10cSrcweir sal_uInt32 nRetMask = 0; 222*cdf0e10cSrcweir SalDisplay* pSalDisp = GetX11SalData()->GetDisplay(); 223*cdf0e10cSrcweir const int nScreenCount = pSalDisp->GetScreenCount(); 224*cdf0e10cSrcweir XRenderPictFormat* pVisualFormat = NULL; 225*cdf0e10cSrcweir int nMaxDepth = 0; 226*cdf0e10cSrcweir for( int nScreen = 0; nScreen < nScreenCount; ++nScreen ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir Visual* pXVisual = pSalDisp->GetVisual( nScreen ).GetVisual(); 229*cdf0e10cSrcweir pVisualFormat = FindVisualFormat( pXVisual ); 230*cdf0e10cSrcweir if( pVisualFormat != NULL ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir int nVDepth = pSalDisp->GetVisual( nScreen ).GetDepth(); 233*cdf0e10cSrcweir if( nVDepth > nMaxDepth ) 234*cdf0e10cSrcweir nMaxDepth = nVDepth; 235*cdf0e10cSrcweir nRetMask |= 1U << nScreen; 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir // #97763# disable XRENDER on <15bit displays for XFree<=4.2.0 240*cdf0e10cSrcweir if( mnRenderVersion <= 0x02 ) 241*cdf0e10cSrcweir if( nMaxDepth < 15 ) 242*cdf0e10cSrcweir nRetMask = 0; 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir return nRetMask; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir // --------------------------------------------------------------------------- 248