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