LibreOffice Module vcl (master)  1
xrender_peer.hxx
Go to the documentation of this file.
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_X11_XRENDER_PEER_HXX
21 #define INCLUDED_VCL_UNX_X11_XRENDER_PEER_HXX
22 
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
25 struct _XTrap; // on some older systems this is not declared within Xrender.h
26 #include <X11/extensions/Xrender.h>
27 
28 #include <tools/color.hxx>
29 
30 
32 {
33 public:
34  static XRenderPeer& GetInstance();
35 
36 private:
37  XRenderPeer();
38  void InitRenderLib();
39 
41  XRenderPictFormat* mpStandardFormatA8;
42 
43 public:
44  XRenderPictFormat* GetStandardFormatA8() const;
45  XRenderPictFormat* FindStandardFormat(int nFormat) const;
46 
47  // the methods below are thin wrappers for the XRENDER API
48  XRenderPictFormat* FindVisualFormat( Visual const * ) const;
49  Picture CreatePicture( Drawable, const XRenderPictFormat*,
50  unsigned long nDrawable, const XRenderPictureAttributes* ) const;
51  void ChangePicture( Picture, unsigned long nValueMask,
52  const XRenderPictureAttributes* ) const;
53  void SetPictureClipRegion( Picture, Region ) const;
54  void CompositePicture( int nOp, Picture aSrc, Picture aMask, Picture aDst,
55  int nXSrc, int nYSrc,
56  int nXDst, int nYDst, unsigned nWidth, unsigned nHeight ) const;
57  void FreePicture( Picture ) const;
58 
59  void FillRectangle( int nOp, Picture aDst, const XRenderColor*,
60  int nX, int nY, unsigned nW, unsigned nH ) const;
61  void CompositeTrapezoids( int nOp, Picture aSrc, Picture aDst,
62  const XRenderPictFormat*, int nXSrc, int nYSrc,
63  const XTrapezoid*, int nCount ) const;
64  void CompositeTriangles( int nOp, Picture aSrc, Picture aDst,
65  const XRenderPictFormat*, int nXSrc, int nYSrc,
66  const XTriangle*, int nCount ) const;
67 };
68 
69 inline XRenderPictFormat* XRenderPeer::GetStandardFormatA8() const
70 {
71  return mpStandardFormatA8;
72 }
73 
74 inline XRenderPictFormat* XRenderPeer::FindStandardFormat(int nFormat) const
75 {
76  return XRenderFindStandardFormat(mpDisplay, nFormat);
77 }
78 
79 inline XRenderPictFormat* XRenderPeer::FindVisualFormat( Visual const * pVisual ) const
80 {
81  return XRenderFindVisualFormat ( mpDisplay, pVisual );
82 }
83 
84 inline Picture XRenderPeer::CreatePicture( Drawable aDrawable,
85  const XRenderPictFormat* pVisFormat, unsigned long nValueMask,
86  const XRenderPictureAttributes* pRenderAttr ) const
87 {
88  return XRenderCreatePicture( mpDisplay, aDrawable, pVisFormat,
89  nValueMask, pRenderAttr );
90 }
91 
92 inline void XRenderPeer::ChangePicture( Picture aPicture,
93  unsigned long nValueMask, const XRenderPictureAttributes* pRenderAttr ) const
94 {
95  XRenderChangePicture( mpDisplay, aPicture, nValueMask, pRenderAttr );
96 }
97 
99  Region aXlibRegion ) const
100 {
101  XRenderSetPictureClipRegion( mpDisplay, aPicture, aXlibRegion );
102 }
103 
104 inline void XRenderPeer::CompositePicture( int nXRenderOp,
105  Picture aSrcPic, Picture aMaskPic, Picture aDstPic,
106  int nSrcX, int nSrcY, int nDstX, int nDstY,
107  unsigned nWidth, unsigned nHeight ) const
108 {
109  XRenderComposite( mpDisplay, nXRenderOp, aSrcPic, aMaskPic, aDstPic,
110  nSrcX, nSrcY, 0/*nMaskX*/, 0/*nMaskY*/, nDstX, nDstY, nWidth, nHeight );
111 }
112 
113 inline void XRenderPeer::FreePicture( Picture aPicture ) const
114 {
115  XRenderFreePicture( mpDisplay, aPicture );
116 }
117 
118 inline void XRenderPeer::FillRectangle( int a, Picture b, const XRenderColor* c,
119  int d, int e, unsigned int f, unsigned int g) const
120 {
121  XRenderFillRectangle( mpDisplay, a, b, c, d, e, f, g );
122 }
123 
124 inline void XRenderPeer::CompositeTrapezoids( int nOp,
125  Picture aSrc, Picture aDst, const XRenderPictFormat* pXRPF,
126  int nXSrc, int nYSrc, const XTrapezoid* pXT, int nCount ) const
127 {
128  XRenderCompositeTrapezoids( mpDisplay, nOp, aSrc, aDst, pXRPF,
129  nXSrc, nYSrc, pXT, nCount );
130 }
131 
132 inline void XRenderPeer::CompositeTriangles( int nOp,
133  Picture aSrc, Picture aDst, const XRenderPictFormat* pXRPF,
134  int nXSrc, int nYSrc, const XTriangle* pXT, int nCount ) const
135 {
136  XRenderCompositeTriangles( mpDisplay, nOp, aSrc, aDst, pXRPF,
137  nXSrc, nYSrc, pXT, nCount );
138 }
139 
140 inline XRenderColor GetXRenderColor( Color rColor, double fTransparency )
141 {
142  XRenderColor aRetVal;
143  // convert the Color
144  aRetVal.red = rColor.GetRed(); aRetVal.red |= (aRetVal.red << 8);
145  aRetVal.green = rColor.GetGreen(); aRetVal.green |= (aRetVal.green << 8);
146  aRetVal.blue = rColor.GetBlue(); aRetVal.blue |= (aRetVal.blue << 8);
147 
148  // handle transparency
149  aRetVal.alpha = 0xFFFF; // default to opaque
150  if( fTransparency != 0 )
151  {
152  const double fAlpha = 1.0 - fTransparency;
153  aRetVal.alpha = static_cast<sal_uInt16>(fAlpha * 0xFFFF + 0.5);
154  // xrender wants pre-multiplied colors
155  aRetVal.red = static_cast<sal_uInt16>(fAlpha * aRetVal.red + 0.5);
156  aRetVal.green = static_cast<sal_uInt16>(fAlpha * aRetVal.green + 0.5);
157  aRetVal.blue = static_cast<sal_uInt16>(fAlpha * aRetVal.blue + 0.5);
158  }
159 
160  return aRetVal;
161 }
162 
163 #endif // INCLUDED_VCL_UNX_X11_XRENDER_PEER_HXX
164 
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XRenderPictFormat * FindVisualFormat(Visual const *) const
sal_uInt8 GetRed() const
XRenderPictFormat * FindStandardFormat(int nFormat) const
void CompositeTrapezoids(int nOp, Picture aSrc, Picture aDst, const XRenderPictFormat *, int nXSrc, int nYSrc, const XTrapezoid *, int nCount) const
XRenderColor GetXRenderColor(Color rColor, double fTransparency)
void SetPictureClipRegion(Picture, Region) const
XRenderPictFormat * mpStandardFormatA8
sal_uInt8 GetBlue() const
XRenderPictFormat * GetStandardFormatA8() const
void ChangePicture(Picture, unsigned long nValueMask, const XRenderPictureAttributes *) const
Display
void FreePicture(Picture) const
sal_uInt8 GetGreen() const
static XRenderPeer & GetInstance()
void CompositeTriangles(int nOp, Picture aSrc, Picture aDst, const XRenderPictFormat *, int nXSrc, int nYSrc, const XTriangle *, int nCount) const
Picture CreatePicture(Drawable, const XRenderPictFormat *, unsigned long nDrawable, const XRenderPictureAttributes *) const
Display *const mpDisplay
void(* f)(TrueTypeTable *)
Definition: ttcr.cxx:466
void CompositePicture(int nOp, Picture aSrc, Picture aMask, Picture aDst, int nXSrc, int nYSrc, int nXDst, int nYDst, unsigned nWidth, unsigned nHeight) const
void InitRenderLib()
void FillRectangle(int nOp, Picture aDst, const XRenderColor *, int nX, int nY, unsigned nW, unsigned nH) const