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