Very basic compositing with xrender.

svn path=/branches/work/kwin_composite/; revision=558481
This commit is contained in:
Luboš Luňák 2006-07-05 13:26:08 +00:00
parent 7d67cf42c4
commit 29111875e1
5 changed files with 88 additions and 3 deletions

View file

@ -16,7 +16,7 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR}/lib ${CMAKE_CURRENT_SOURCE_DIR}
########### next target ############### ########### next target ###############
set(kwin_KDEINIT_SRCS set(kwin_KDEINIT_SRCS
kwinadaptor.cpp kwinadaptor.cpp
workspace.cpp workspace.cpp
client.cpp client.cpp
placement.cpp placement.cpp
@ -60,6 +60,9 @@ endif (X11_Xcomposite_FOUND)
if (X11_Xdamage_FOUND) if (X11_Xdamage_FOUND)
target_link_libraries(kdeinit_kwin ${X11_Xdamage_LIB}) target_link_libraries(kdeinit_kwin ${X11_Xdamage_LIB})
endif (X11_Xdamage_FOUND) endif (X11_Xdamage_FOUND)
if (X11_Xrender_FOUND)
target_link_libraries(kdeinit_kwin ${X11_Xrender_LIB})
endif (X11_Xrender_FOUND)
install(TARGETS kdeinit_kwin DESTINATION ${LIB_INSTALL_DIR} ) install(TARGETS kdeinit_kwin DESTINATION ${LIB_INSTALL_DIR} )

View file

@ -14,6 +14,7 @@ License. See the file "COPYING" for the exact licensing terms.
#include "unmanaged.h" #include "unmanaged.h"
#include "scene.h" #include "scene.h"
#include "scene_basic.h" #include "scene_basic.h"
#include "scene_xrender.h"
namespace KWinInternal namespace KWinInternal
{ {
@ -33,7 +34,8 @@ void Workspace::setupCompositing()
compositeTimer.start( 20 ); compositeTimer.start( 20 );
XCompositeRedirectSubwindows( display(), rootWindow(), CompositeRedirectManual ); XCompositeRedirectSubwindows( display(), rootWindow(), CompositeRedirectManual );
setDamaged(); setDamaged();
scene = new SceneBasic( this ); // scene = new SceneBasic( this );
scene = new SceneXrender( this );
} }
void Workspace::finishCompositing() void Workspace::finishCompositing()

View file

@ -25,7 +25,6 @@ class SceneBasic
virtual void paint(); virtual void paint();
}; };
} // namespace } // namespace
#endif #endif

View file

@ -10,6 +10,10 @@ License. See the file "COPYING" for the exact licensing terms.
#include "scene_xrender.h" #include "scene_xrender.h"
#ifdef HAVE_XRENDER
#include "toplevel.h"
namespace KWinInternal namespace KWinInternal
{ {
@ -17,4 +21,58 @@ namespace KWinInternal
// SceneXrender // 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 } // namespace
#endif

View file

@ -11,9 +11,32 @@ License. See the file "COPYING" for the exact licensing terms.
#ifndef KWIN_SCENE_XRENDER_H #ifndef KWIN_SCENE_XRENDER_H
#define KWIN_SCENE_XRENDER_H #define KWIN_SCENE_XRENDER_H
#include "config.h"
#ifdef HAVE_XRENDER
#include <X11/extensions/Xrender.h>
#include "scene.h"
namespace KWinInternal namespace KWinInternal
{ {
class SceneXrender
: public Scene
{
public:
SceneXrender( Workspace* ws );
virtual ~SceneXrender();
virtual void paint();
private:
void createBuffer();
XRenderPictFormat* format;
Picture front;
Picture buffer;
};
} // namespace } // namespace
#endif #endif
#endif