XRenderPicture, a wrapper around XRender's Picture, which

should act just like Picture, except for proper initialization
and resource freeing (i.e. it's sane and easy from C++ point of view).


svn path=/trunk/KDE/kdebase/workspace/; revision=805085
This commit is contained in:
Luboš Luňák 2008-05-07 14:43:13 +00:00
parent b840fa0792
commit 5efac21537
10 changed files with 175 additions and 54 deletions

View file

@ -344,25 +344,13 @@ void BoxSwitchEffect::setInactive()
if( w != selected_window )
w->addRepaintFull();
}
foreach( ItemInfo* i, windows )
{
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
if( effects->compositingType() == XRenderCompositing )
{
if( i->iconPicture != None )
XRenderFreePicture( display(), i->iconPicture );
i->iconPicture = None;
}
#endif
delete i;
}
qDeleteAll( windows );
windows.clear();
setSelectedWindow( 0 );
}
else
{ // DesktopMode
foreach( ItemInfo* i, desktops )
delete i;
qDeleteAll( windows );
desktops.clear();
}
effects->addRepaint( frame_area );
@ -601,8 +589,6 @@ void BoxSwitchEffect::paintWindowIcon( EffectWindow* w )
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
if( effects->compositingType() == XRenderCompositing )
{
if( windows[ w ]->iconPicture != None )
XRenderFreePicture( display(), windows[ w ]->iconPicture );
windows[ w ]->iconPicture = XRenderCreatePicture( display(),
windows[ w ]->icon.handle(), alphaFormat, 0, NULL );
}

View file

@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QFont>
#include <kwinglutils.h>
#include <kwinxrenderutils.h>
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
#include <X11/extensions/Xrender.h>
@ -112,7 +113,7 @@ class BoxSwitchEffect::ItemInfo
GLTexture iconTexture;
#endif
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
Picture iconPicture;
XRenderPicture iconPicture;
#endif
};

View file

@ -1046,8 +1046,6 @@ void PresentWindowsEffect::paintWindowIcon( EffectWindow* w, WindowPaintData& pa
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
if( effects->compositingType() == XRenderCompositing )
{
if( data.iconPicture != None )
XRenderFreePicture( display(), data.iconPicture );
data.iconPicture = XRenderCreatePicture( display(),
data.icon.handle(), alphaFormat, 0, NULL );
}

View file

@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Include with base class for effects.
#include <kwineffects.h>
#include <kwinglutils.h>
#include <kwinxrenderutils.h>
#include <QPixmap>
@ -121,7 +122,7 @@ class PresentWindowsEffect
KSharedPtr< GLTexture > iconTexture;
#endif
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
Picture iconPicture;
XRenderPicture iconPicture;
#endif
};
typedef QHash<EffectWindow*, WindowData> DataHash;

View file

@ -33,6 +33,7 @@ set(kwin_EFFECTSLIB_SRCS
kwinglutils.cpp
kwinglutils_funcs.cpp
kwinshadereffect.cpp
kwinxrenderutils.cpp
)
kde4_add_library(kwineffects SHARED ${kwin_EFFECTSLIB_SRCS})
@ -72,5 +73,6 @@ install( FILES
kwinglutils.h
kwinglutils_funcs.h
kwinshadereffect.h
kwinxrenderutils.h
${CMAKE_CURRENT_BINARY_DIR}/kwinconfig.h
DESTINATION ${INCLUDE_INSTALL_DIR})

View file

@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "kwineffects.h"
#include "kwinglutils.h"
#include "kwinxrenderutils.h"
#include <QtDBus/QtDBus>
#include <QVariant>
@ -979,27 +980,4 @@ void TimeLine::setCurveShape(CurveShape curveShape)
m_CurveShape = curveShape;
}
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
// Convert QRegion to XserverRegion. All code uses XserverRegion
// only when really necessary as the shared implementation uses
// QRegion.
XserverRegion toXserverRegion( QRegion region )
{
QVector< QRect > rects = region.rects();
XRectangle* xr = new XRectangle[ rects.count() ];
for( int i = 0;
i < rects.count();
++i )
{
xr[ i ].x = rects[ i ].x();
xr[ i ].y = rects[ i ].y();
xr[ i ].width = rects[ i ].width();
xr[ i ].height = rects[ i ].height();
}
XserverRegion ret = XFixesCreateRegion( display(), xr, rects.count());
delete[] xr;
return ret;
}
#endif
} // namespace

View file

@ -41,10 +41,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <assert.h>
#include <limits.h>
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
#include <X11/extensions/Xfixes.h>
#endif
class KLibrary;
class KConfigGroup;
class KActionCollection;
@ -179,13 +175,6 @@ QRect infiniteRegion()
return QRect( INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX );
}
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
/**
* Convert QRegion to XserverRegion.
*/
KWIN_EXPORT XserverRegion toXserverRegion( QRegion region );
#endif
/**
* @short Base class for all KWin effects
*

53
lib/kwinxrenderutils.cpp Normal file
View file

@ -0,0 +1,53 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2008 Lubos Lunak <l.lunak@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "kwinxrenderutils.h"
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
#include <qvector.h>
namespace KWin
{
// Convert QRegion to XserverRegion. All code uses XserverRegion
// only when really necessary as the shared implementation uses
// QRegion.
XserverRegion toXserverRegion( QRegion region )
{
QVector< QRect > rects = region.rects();
XRectangle* xr = new XRectangle[ rects.count() ];
for( int i = 0;
i < rects.count();
++i )
{
xr[ i ].x = rects[ i ].x();
xr[ i ].y = rects[ i ].y();
xr[ i ].width = rects[ i ].width();
xr[ i ].height = rects[ i ].height();
}
XserverRegion ret = XFixesCreateRegion( display(), xr, rects.count());
delete[] xr;
return ret;
}
} // namespace
#endif

112
lib/kwinxrenderutils.h Normal file
View file

@ -0,0 +1,112 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2008 Lubos Lunak <l.lunak@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_XRENDERUTILS_H
#define KWIN_XRENDERUTILS_H
#include <kwinconfig.h>
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
#include <QtCore/QSharedData>
#include <ksharedptr.h>
#include <kwinglobals.h>
#include <X11/extensions/Xfixes.h>
#include <X11/extensions/Xrender.h>
/** @addtogroup kwineffects */
/** @{ */
namespace KWin
{
/**
* Convert QRegion to XserverRegion.
*/
KWIN_EXPORT XserverRegion toXserverRegion( QRegion region );
/** @internal */
class KWIN_EXPORT XRenderPictureData
: public QSharedData
{
public:
XRenderPictureData( Picture pic = None );
~XRenderPictureData();
Picture value();
private:
Picture picture;
Q_DISABLE_COPY( XRenderPictureData )
};
/**
* @short Wrapper around XRender Picture.
*
* This class wraps XRender's Picture, providing proper initialization
* and freeing of resources. It should otherwise act exactly like the Picture type.
*/
class KWIN_EXPORT XRenderPicture
{
public:
XRenderPicture( Picture pic = None );
operator Picture();
private:
KSharedPtr< XRenderPictureData > d;
};
inline
XRenderPictureData::XRenderPictureData( Picture pic )
: picture( pic )
{
}
inline
XRenderPictureData::~XRenderPictureData()
{
if( picture != None )
XRenderFreePicture( display(), picture );
}
inline
Picture XRenderPictureData::value()
{
return picture;
}
inline
XRenderPicture::XRenderPicture( Picture pic )
: d( new XRenderPictureData( pic ))
{
}
inline
XRenderPicture::operator Picture()
{
return d->value();
}
} // namespace
#endif
/** @} */
#endif

View file

@ -45,6 +45,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "client.h"
#include "deleted.h"
#include "effects.h"
#include "kwinxrenderutils.h"
#include <kxerrorhandler.h>