1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
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 ************************************************************************/
32 #include <rtl/ustring.hxx>
33 #include <osl/module.h>
34 //#include <osl/thread.h>
37 #include <xrender_peer.hxx>
40 #include <saldata.hxx>
41 #include <saldisp.hxx>
43 // ---------------------------------------------------------------------------
45 XRenderPeer::XRenderPeer()
46 : mpDisplay( GetX11SalData()->GetDisplay()->GetDisplay() ),
47 mpStandardFormatA8( NULL
),
51 , mpXRenderCompositeTrapezoids( NULL
)
52 , mpXRenderAddTraps( NULL
)
53 #endif // XRENDER_LINK
58 // ---------------------------------------------------------------------------
60 XRenderPeer::~XRenderPeer()
62 osl_unloadModule( mpRenderLib
);
65 // ---------------------------------------------------------------------------
67 XRenderPeer
& XRenderPeer::GetInstance()
69 static XRenderPeer aPeer
;
73 // ---------------------------------------------------------------------------
75 void XRenderPeer::InitRenderLib()
78 if( !XQueryExtension( mpDisplay
, "RENDER", &nDummy
, &nDummy
, &nDummy
) )
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
);
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() );
96 oslGenericFunction pFunc
;
97 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderQueryExtension" );
99 mpXRenderQueryExtension
= (Bool(*)(Display
*,int*,int*))pFunc
;
101 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderQueryVersion" );
103 mpXRenderQueryVersion
= (void(*)(Display
*,int*,int*))pFunc
;
105 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderFindVisualFormat" );
107 mpXRenderFindVisualFormat
= (XRenderPictFormat
*(*)(Display
*,Visual
*))pFunc
;
109 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderFindStandardFormat" );
111 mpXRenderFindStandardFormat
= (XRenderPictFormat
*(*)(Display
*,int))pFunc
;
113 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderFindFormat" );
115 mpXRenderFindFormat
= (XRenderPictFormat
*(*)(Display
*,unsigned long,
116 const XRenderPictFormat
*,int))pFunc
;
118 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderCreateGlyphSet" );
120 mpXRenderCreateGlyphSet
= (GlyphSet(*)(Display
*,const XRenderPictFormat
*))pFunc
;
122 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderFreeGlyphSet" );
124 mpXRenderFreeGlyphSet
= (void(*)(Display
*,GlyphSet
))pFunc
;
126 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderAddGlyphs" );
128 mpXRenderAddGlyphs
= (void(*)(Display
*,GlyphSet
,Glyph
*,const XGlyphInfo
*,
129 int,const char*,int))pFunc
;
131 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderFreeGlyphs" );
133 mpXRenderFreeGlyphs
= (void(*)(Display
*,GlyphSet
,Glyph
*,int))pFunc
;
135 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderCompositeString32" );
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" );
142 mpXRenderCreatePicture
= (Picture(*)(Display
*,Drawable
,const XRenderPictFormat
*,
143 unsigned long,const XRenderPictureAttributes
*))pFunc
;
145 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderSetPictureClipRegion" );
147 mpXRenderSetPictureClipRegion
= (void(*)(Display
*,Picture
,XLIB_Region
))pFunc
;
149 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderFreePicture" );
151 mpXRenderFreePicture
= (void(*)(Display
*,Picture
))pFunc
;
153 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderComposite" );
155 mpXRenderComposite
= (void(*)(Display
*,int,Picture
,Picture
,Picture
,
156 int,int,int,int,int,int,unsigned,unsigned))pFunc
;
158 pFunc
= osl_getAsciiFunctionSymbol( mpRenderLib
, "XRenderFillRectangle" );
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
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
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
180 XRenderQueryExtension( mpDisplay
, &nDummy
, &nDummy
);
182 (*mpXRenderQueryExtension
)( mpDisplay
, &nDummy
, &nDummy
);
187 XRenderQueryVersion( mpDisplay
, &nMajor
, &nMinor
);
189 (*mpXRenderQueryVersion
)( mpDisplay
, &nMajor
, &nMinor
);
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 )
202 // #93033# disable XRENDER for old RENDER versions if XINERAMA is present
204 if( XQueryExtension( mpDisplay
, "XINERAMA", &nDummy
, &nDummy
, &nDummy
) )
205 if( mnRenderVersion
< 0x02 )
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
)
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 )
235 // ---------------------------------------------------------------------------