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