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