kwin/scene_xrender.cpp

79 lines
2.6 KiB
C++
Raw Normal View History

/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#include "scene_xrender.h"
#ifdef HAVE_XRENDER
#include "toplevel.h"
namespace KWinInternal
{
//****************************************
// SceneXrender
//****************************************
SceneXrender::SceneXrender( Workspace* ws )
: Scene( ws )
{
format = XRenderFindVisualFormat( display(), DefaultVisual( display(), DefaultScreen( display())));
XRenderPictureAttributes pa;
pa.subwindow_mode = IncludeInferiors;
front = XRenderCreatePicture( display(), rootWindow(), format, CPSubwindowMode, &pa );
createBuffer();
}
SceneXrender::~SceneXrender()
{
XRenderFreePicture( display(), front );
XRenderFreePicture( display(), buffer );
}
// TODO handle xrandr changes
void SceneXrender::createBuffer()
{
if( buffer != None )
XRenderFreePicture( display(), buffer );
Pixmap pixmap = XCreatePixmap( display(), rootWindow(), displayWidth(), displayHeight(), QX11Info::appDepth());
buffer = XRenderCreatePicture( display(), pixmap, format, 0, 0 );
XFreePixmap( display(), pixmap ); // The picture owns the pixmap now
}
void SceneXrender::paint()
{
XRenderColor col = { 0xffff, 0xffff, 0xffff, 0xffff };
XRenderFillRectangle( display(), PictOpSrc, buffer, &col, 0, 0, displayWidth(), displayHeight());
for( ToplevelList::ConstIterator it = windows.begin();
it != windows.end();
++it )
{
QRect r = (*it)->geometry().intersect( QRect( 0, 0, displayWidth(), displayHeight()));
if( !r.isEmpty())
{
XWindowAttributes attrs;
if( !XGetWindowAttributes( display(), (*it)->handle(), &attrs ))
continue;
if( XRenderPictFormat* clientFormat = XRenderFindVisualFormat( display(), attrs.visual ))
{
Picture picture = XRenderCreatePicture( display(), (*it)->windowPixmap(), clientFormat, 0, 0 );
XRenderComposite( display(), PictOpSrc, picture, None, buffer, 0, 0, 0, 0,
(*it)->x(), (*it)->y(), (*it)->width(), (*it)->height());
}
}
}
XRenderComposite( display(), PictOpSrc, buffer, None, front, 0, 0, 0, 0, 0, 0, displayWidth(), displayHeight());
XFlush( display());
}
} // namespace
#endif