00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kxutils.h"
00022
00023 #include <config.h>
00024
00025 #ifdef Q_WS_X11
00026
00027 #include <kxerrorhandler.h>
00028 #include <qbitmap.h>
00029 #include <qpixmap.h>
00030
00031 #ifdef HAVE_XRENDER
00032 #include <X11/extensions/Xrender.h>
00033 #endif
00034
00035 namespace KXUtils
00036 {
00037
00038
00039 QPixmap createPixmapFromHandle( WId pixmap, WId pixmap_mask )
00040 {
00041 Display* dpy = QX11Info::display();
00042 KXErrorHandler handler;
00043 Window root;
00044 int x, y;
00045 unsigned int w = 0;
00046 unsigned int h = 0;
00047 unsigned int border_w, depth;
00048 if( XGetGeometry( dpy, pixmap, &root, &x, &y, &w, &h, &border_w, &depth )
00049 && !handler.error( false ) && w > 0 && h > 0 )
00050 {
00051 QPixmap pm( w, h );
00052
00053 pm.detach();
00054 #ifdef HAVE_XRENDER
00055 if( int( depth ) != pm.depth() && depth != 1 && pm.x11PictureHandle() != None )
00056 {
00057 XRenderPictFormat tmpl;
00058 tmpl.type = PictTypeDirect;
00059 tmpl.depth = depth;
00060 XRenderPictFormat* format = XRenderFindFormat( dpy, PictFormatType | PictFormatDepth, &tmpl, 0 );
00061 Picture pic = XRenderCreatePicture( dpy, pixmap, format, 0, NULL );
00062 XRenderComposite( dpy, PictOpSrc, pic, None, pm.x11PictureHandle(), 0, 0, 0, 0, 0, 0, w, h );
00063 XRenderFreePicture( dpy, pic );
00064 }
00065 else
00066 #endif
00067 {
00068 GC gc = XCreateGC( dpy, pixmap, 0, NULL );
00069 if( depth == 1 )
00070 {
00071 QBitmap bm( w, h );
00072 XCopyArea( dpy, pixmap, bm.handle(), gc, 0, 0, w, h, 0, 0 );
00073 pm = bm;
00074 }
00075 else
00076 XCopyArea( dpy, pixmap, pm.handle(), gc, 0, 0, w, h, 0, 0 );
00077 XFreeGC( dpy, gc );
00078 }
00079
00080 if( pixmap_mask != None )
00081 {
00082 QBitmap bm( w, h );
00083 bm.detach();
00084 GC gc = XCreateGC( dpy, pixmap_mask, 0, NULL );
00085 XCopyArea( dpy, pixmap_mask, bm.handle(), gc, 0, 0, w, h, 0, 0 );
00086 pm.setMask( bm );
00087 XFreeGC( dpy, gc );
00088 }
00089 if( !handler.error( true ))
00090 return pm;
00091 }
00092 return QPixmap();
00093 }
00094
00095
00096
00097
00098 #if 0
00099 int timestampCompare( Time time1, Time time2 )
00100 {
00101 if( time1 == time2 )
00102 return 0;
00103 return ( time1 - time2 ) < 0x7fffffffU ? 1 : -1;
00104 }
00105
00106 Time timestampDiff( Time time1, Time time2 )
00107 {
00108 return time2 - time1;
00109 }
00110 #else
00111 int timestampCompare( unsigned long time1_, unsigned long time2_ )
00112 {
00113 quint32 time1 = time1_;
00114 quint32 time2 = time2_;
00115 if( time1 == time2 )
00116 return 0;
00117 return quint32( time1 - time2 ) < 0x7fffffffU ? 1 : -1;
00118 }
00119
00120 int timestampDiff( unsigned long time1_, unsigned long time2_ )
00121 {
00122 quint32 time1 = time1_;
00123 quint32 time2 = time2_;
00124 return quint32( time2 - time1 );
00125 }
00126 #endif
00127
00128
00129 }
00130
00131 #endif