2 This file is part of the KDE libraries
3 Copyright (C) 2008 Lubos Lunak (l.lunak@kde.org)
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
27 #include <kxerrorhandler.h>
32 #include <X11/extensions/Xrender.h>
38 // Create QPixmap from X pixmap. Take care of different depths if needed.
39 QPixmap
createPixmapFromHandle( WId pixmap
, WId pixmap_mask
)
41 Display
* dpy
= QX11Info::display();
42 KXErrorHandler handler
;
47 unsigned int border_w
, depth
;
48 if( XGetGeometry( dpy
, pixmap
, &root
, &x
, &y
, &w
, &h
, &border_w
, &depth
)
49 && !handler
.error( false ) && w
> 0 && h
> 0 )
52 // Always detach before doing something behind QPixmap's back.
55 if( int( depth
) != pm
.depth() && depth
!= 1 && pm
.x11PictureHandle() != None
)
57 XRenderPictFormat tmpl
;
58 tmpl
.type
= PictTypeDirect
;
60 XRenderPictFormat
* format
= XRenderFindFormat( dpy
, PictFormatType
| PictFormatDepth
, &tmpl
, 0 );
61 Picture pic
= XRenderCreatePicture( dpy
, pixmap
, format
, 0, NULL
);
62 XRenderComposite( dpy
, PictOpSrc
, pic
, None
, pm
.x11PictureHandle(), 0, 0, 0, 0, 0, 0, w
, h
);
63 XRenderFreePicture( dpy
, pic
);
67 { // the normal X11 way
68 GC gc
= XCreateGC( dpy
, pixmap
, 0, NULL
);
72 XCopyArea( dpy
, pixmap
, bm
.handle(), gc
, 0, 0, w
, h
, 0, 0 );
75 else // depth == pm.depth()
76 XCopyArea( dpy
, pixmap
, pm
.handle(), gc
, 0, 0, w
, h
, 0, 0 );
80 if( pixmap_mask
!= None
)
84 GC gc
= XCreateGC( dpy
, pixmap_mask
, 0, NULL
);
85 XCopyArea( dpy
, pixmap_mask
, bm
.handle(), gc
, 0, 0, w
, h
, 0, 0 );
89 if( !handler
.error( true )) // sync, check for error
95 // Functions for X timestamp comparing. For Time being 32bit they're fairly simple
96 // (the #if 0 part), but on 64bit architectures Time is 64bit unsigned long,
97 // so there special care needs to be taken to always use only the lower 32bits.
99 int timestampCompare( Time time1
, Time time2
) // like strcmp()
103 return ( time1
- time2
) < 0x7fffffffU
? 1 : -1; // time1 > time2 -> 1, handle wrapping
106 Time
timestampDiff( Time time1
, Time time2
) // returns time2 - time1
107 { // no need to handle wrapping?
108 return time2
- time1
;
111 int timestampCompare( unsigned long time1_
, unsigned long time2_
) // like strcmp()
113 quint32 time1
= time1_
;
114 quint32 time2
= time2_
;
117 return quint32( time1
- time2
) < 0x7fffffffU
? 1 : -1; // time1 > time2 -> 1, handle wrapping
120 int timestampDiff( unsigned long time1_
, unsigned long time2_
) // returns time2 - time1
121 { // no need to handle wrapping?
122 quint32 time1
= time1_
;
123 quint32 time2
= time2_
;
124 return quint32( time2
- time1
);