Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_VCL_UNX_GENERIC_GDI_XRENDER_PEER_HXX
21 : #define INCLUDED_VCL_UNX_GENERIC_GDI_XRENDER_PEER_HXX
22 :
23 : #include <prex.h>
24 : struct _XTrap; // on some older systems this is not declared within Xrender.h
25 : #include <X11/extensions/Xrender.h>
26 : #include <postx.h>
27 :
28 : #include <vcl/salgtype.hxx>
29 : #include <osl/module.h>
30 :
31 : typedef Glyph XRenderGlyph;
32 :
33 : class XRenderPeer
34 : {
35 : public:
36 : static XRenderPeer& GetInstance();
37 :
38 : private:
39 : XRenderPeer();
40 : void InitRenderLib();
41 :
42 : Display* mpDisplay;
43 : XRenderPictFormat* mpStandardFormatA8;
44 :
45 : public:
46 : XRenderPictFormat* GetStandardFormatA8() const;
47 : XRenderPictFormat* FindStandardFormat(int nFormat) const;
48 :
49 : // the methods below are thin wrappers for the XRENDER API
50 : XRenderPictFormat* FindVisualFormat( Visual* ) const;
51 : XRenderPictFormat* FindPictureFormat( unsigned long nMask,
52 : const XRenderPictFormat& ) const;
53 : Picture CreatePicture( Drawable, const XRenderPictFormat*,
54 : unsigned long nDrawable, const XRenderPictureAttributes* ) const;
55 : void ChangePicture( Picture, unsigned long nValueMask,
56 : const XRenderPictureAttributes* ) const;
57 : void SetPictureClipRegion( Picture, XLIB_Region ) const;
58 : void CompositePicture( int nOp, Picture aSrc, Picture aMask, Picture aDst,
59 : int nXSrc, int nYSrc, int nXMask, int nYMask,
60 : int nXDst, int nYDst, unsigned nWidth, unsigned nHeight ) const;
61 : void FreePicture( Picture ) const;
62 :
63 : GlyphSet CreateGlyphSet() const;
64 : void FreeGlyphSet( GlyphSet ) const;
65 : void AddGlyph( GlyphSet, XRenderGlyph nXRGlyph, const XGlyphInfo&,
66 : const char* pBuffer, int nBufSize ) const;
67 : void FreeGlyph( GlyphSet, XRenderGlyph nXRGlyphId ) const;
68 : void CompositeString32( Picture aSrc, Picture aDst, GlyphSet,
69 : int nDstX, int nDstY, const unsigned* pText, int nTextLen ) const;
70 : void FillRectangle( int nOp, Picture aDst, const XRenderColor*,
71 : int nX, int nY, unsigned nW, unsigned nH ) const;
72 : void CompositeTrapezoids( int nOp, Picture aSrc, Picture aDst,
73 : const XRenderPictFormat*, int nXSrc, int nYSrc,
74 : const XTrapezoid*, int nCount ) const;
75 : void AddTraps( Picture aDst, int nXOfs, int nYOfs,
76 : const _XTrap*, int nCount ) const;
77 : };
78 :
79 0 : inline XRenderPictFormat* XRenderPeer::GetStandardFormatA8() const
80 : {
81 0 : return mpStandardFormatA8;
82 : }
83 :
84 0 : inline XRenderPictFormat* XRenderPeer::FindStandardFormat(int nFormat) const
85 : {
86 0 : return XRenderFindStandardFormat(mpDisplay, nFormat);
87 : }
88 :
89 0 : inline XRenderPictFormat* XRenderPeer::FindVisualFormat( Visual* pVisual ) const
90 : {
91 0 : return XRenderFindVisualFormat ( mpDisplay, pVisual );
92 : }
93 :
94 0 : inline XRenderPictFormat* XRenderPeer::FindPictureFormat( unsigned long nFormatMask,
95 : const XRenderPictFormat& rFormatAttr ) const
96 : {
97 0 : return XRenderFindFormat( mpDisplay, nFormatMask, &rFormatAttr, 0 );
98 : }
99 :
100 0 : inline Picture XRenderPeer::CreatePicture( Drawable aDrawable,
101 : const XRenderPictFormat* pVisFormat, unsigned long nValueMask,
102 : const XRenderPictureAttributes* pRenderAttr ) const
103 : {
104 : return XRenderCreatePicture( mpDisplay, aDrawable, pVisFormat,
105 0 : nValueMask, pRenderAttr );
106 : }
107 :
108 0 : inline void XRenderPeer::ChangePicture( Picture aPicture,
109 : unsigned long nValueMask, const XRenderPictureAttributes* pRenderAttr ) const
110 : {
111 0 : XRenderChangePicture( mpDisplay, aPicture, nValueMask, pRenderAttr );
112 0 : }
113 :
114 0 : inline void XRenderPeer::SetPictureClipRegion( Picture aPicture,
115 : XLIB_Region aXlibRegion ) const
116 : {
117 0 : XRenderSetPictureClipRegion( mpDisplay, aPicture, aXlibRegion );
118 0 : }
119 :
120 0 : inline void XRenderPeer::CompositePicture( int nXRenderOp,
121 : Picture aSrcPic, Picture aMaskPic, Picture aDstPic,
122 : int nSrcX, int nSrcY, int nMaskX, int nMaskY, int nDstX, int nDstY,
123 : unsigned nWidth, unsigned nHeight ) const
124 : {
125 : XRenderComposite( mpDisplay, nXRenderOp, aSrcPic, aMaskPic, aDstPic,
126 0 : nSrcX, nSrcY, nMaskX, nMaskY, nDstX, nDstY, nWidth, nHeight );
127 0 : }
128 :
129 0 : inline void XRenderPeer::FreePicture( Picture aPicture ) const
130 : {
131 0 : XRenderFreePicture( mpDisplay, aPicture );
132 0 : }
133 :
134 : inline GlyphSet XRenderPeer::CreateGlyphSet() const
135 : {
136 : return XRenderCreateGlyphSet( mpDisplay, mpStandardFormatA8 );
137 : }
138 :
139 : inline void XRenderPeer::FreeGlyphSet( GlyphSet aGS ) const
140 : {
141 : XRenderFreeGlyphSet( mpDisplay, aGS );
142 : }
143 :
144 : inline void XRenderPeer::AddGlyph( GlyphSet aGS, XRenderGlyph nXRGlyph,
145 : const XGlyphInfo& rGI, const char* pBuffer, int nBufSize ) const
146 : {
147 : XRenderAddGlyphs( mpDisplay, aGS, &nXRGlyph, &rGI, 1,
148 : const_cast<char*>(pBuffer), nBufSize );
149 : }
150 :
151 : inline void XRenderPeer::FreeGlyph( GlyphSet aGS, XRenderGlyph nXRGlyph ) const
152 : {
153 : (void)aGS; (void)nXRGlyph;
154 :
155 : // XRenderFreeGlyphs not implemented yet for version<=0.2
156 : // #108209# disabled because of crash potential,
157 : // the glyph leak is not too bad because they will
158 : // be cleaned up when the glyphset is released
159 : }
160 :
161 : inline void XRenderPeer::CompositeString32( Picture aSrc, Picture aDst,
162 : GlyphSet aGlyphSet, int nDstX, int nDstY,
163 : const unsigned* pText, int nTextLen ) const
164 : {
165 : XRenderCompositeString32( mpDisplay, PictOpOver, aSrc, aDst, NULL,
166 : aGlyphSet, 0, 0, nDstX, nDstY, pText, nTextLen );
167 : }
168 :
169 0 : inline void XRenderPeer::FillRectangle( int a, Picture b, const XRenderColor* c,
170 : int d, int e, unsigned int f, unsigned int g) const
171 : {
172 0 : XRenderFillRectangle( mpDisplay, a, b, c, d, e, f, g );
173 0 : }
174 :
175 0 : inline void XRenderPeer::CompositeTrapezoids( int nOp,
176 : Picture aSrc, Picture aDst, const XRenderPictFormat* pXRPF,
177 : int nXSrc, int nYSrc, const XTrapezoid* pXT, int nCount ) const
178 : {
179 : XRenderCompositeTrapezoids( mpDisplay, nOp, aSrc, aDst, pXRPF,
180 0 : nXSrc, nYSrc, pXT, nCount );
181 0 : }
182 :
183 : inline void XRenderPeer::AddTraps( Picture aDst, int nXOfs, int nYOfs,
184 : const _XTrap* pTraps, int nCount ) const
185 : {
186 : XRenderAddTraps( mpDisplay, aDst, nXOfs, nYOfs, pTraps, nCount );
187 : }
188 :
189 0 : inline XRenderColor GetXRenderColor( const SalColor& rSalColor, double fTransparency = 0.0 )
190 : {
191 : XRenderColor aRetVal;
192 : // convert the SalColor
193 0 : aRetVal.red = SALCOLOR_RED( rSalColor ); aRetVal.red |= (aRetVal.red << 8);
194 0 : aRetVal.green = SALCOLOR_GREEN( rSalColor ); aRetVal.green |= (aRetVal.green << 8);
195 0 : aRetVal.blue = SALCOLOR_BLUE( rSalColor ); aRetVal.blue |= (aRetVal.blue << 8);
196 :
197 : // handle transparency
198 0 : aRetVal.alpha = 0xFFFF; // default to opaque
199 0 : if( fTransparency != 0 )
200 : {
201 0 : const double fAlpha = 1.0 - fTransparency;
202 0 : aRetVal.alpha = static_cast<sal_uInt16>(fAlpha * 0xFFFF + 0.5);
203 : // xrender wants pre-multiplied colors
204 0 : aRetVal.red = static_cast<sal_uInt16>(fAlpha * aRetVal.red + 0.5);
205 0 : aRetVal.green = static_cast<sal_uInt16>(fAlpha * aRetVal.green + 0.5);
206 0 : aRetVal.blue = static_cast<sal_uInt16>(fAlpha * aRetVal.blue + 0.5);
207 : }
208 :
209 0 : return aRetVal;
210 : }
211 :
212 : #endif // INCLUDED_VCL_UNX_GENERIC_GDI_XRENDER_PEER_HXX
213 :
214 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|