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