generic: port to KPixmap

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-11-09 02:13:13 +02:00
parent 1c6377c040
commit a3834f4133
3 changed files with 15 additions and 38 deletions

View file

@ -35,6 +35,7 @@
#include <QtGui/QToolBar>
#include <QtCore/QTextStream>
#include <QtCore/QEvent>
#include <KPixmap>
#ifdef Q_WS_X11
#include <QtGui/qx11info_x11.h>
@ -324,20 +325,9 @@ namespace Oxygen
const int height( source.height() );
// create X11 pixmap
Pixmap pixmap = XCreatePixmap( QX11Info::display(), QX11Info::appRootWindow(), width, height, 32 );
// create explicitly shared QPixmap from it
QPixmap dest( QPixmap::fromX11Pixmap( pixmap, QPixmap::ExplicitlyShared ) );
// create surface for pixmap
{
QPainter painter( &dest );
painter.setCompositionMode( QPainter::CompositionMode_Source );
painter.drawPixmap( 0, 0, source );
}
return pixmap;
KPixmap pixmap(source);
// handle not released, safe to return
return pixmap.handle();
#else
return 0;
#endif

View file

@ -29,6 +29,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "scene_xrender.h"
#endif
#include <kpixmap.h>
namespace KWin
{
@ -95,8 +97,8 @@ QVector< long > Shadow::readX11ShadowProperty(WId id)
bool Shadow::init(const QVector< long > &data)
{
for (int i=0; i<ShadowElementsCount; ++i) {
QPixmap pix = QPixmap::fromX11Pixmap(data[i], QPixmap::ExplicitlyShared);
if (pix.isNull() || pix.depth() != 32) {
const KPixmap pix(Qt::HANDLE(data[i]));
if (pix.isNull()) {
return false;
}
m_shadowElements[i] = pix.toImage();

View file

@ -29,6 +29,7 @@
#endif
#include <KDebug>
#include <KPixmap>
class PanelShadows::Private
{
@ -57,7 +58,7 @@ public:
void windowDestroyed(QObject *deletedObject);
PanelShadows *q;
QList<QPixmap> m_shadowPixmaps;
QList<KPixmap> m_shadowPixmaps;
QVector<unsigned long> data;
QSet<const QWidget *> m_windows;
bool m_managePixmaps;
@ -120,20 +121,7 @@ void PanelShadows::Private::updateShadows()
void PanelShadows::Private::initPixmap(const QString &element)
{
#ifdef Q_WS_X11
QPixmap pix = q->pixmap(element);
if (!pix.isNull() && pix.handle() == 0) {
Pixmap xPix = XCreatePixmap(QX11Info::display(), QX11Info::appRootWindow(), pix.width(), pix.height(), 32);
QPixmap tempPix = QPixmap::fromX11Pixmap(xPix, QPixmap::ExplicitlyShared);
tempPix.fill(Qt::transparent);
QPainter p(&tempPix);
p.drawPixmap(QPoint(0, 0), pix);
m_shadowPixmaps << tempPix;
m_managePixmaps = true;
} else {
m_shadowPixmaps << pix;
}
#endif
m_shadowPixmaps << KPixmap(q->pixmap(element));
}
void PanelShadows::Private::setupPixmaps()
@ -148,11 +136,9 @@ void PanelShadows::Private::setupPixmaps()
initPixmap("shadow-left");
initPixmap("shadow-topleft");
#ifdef Q_WS_X11
foreach (const QPixmap &pixmap, m_shadowPixmaps) {
foreach (const KPixmap &pixmap, m_shadowPixmaps) {
data << pixmap.handle();
}
#endif
QSize marginHint = q->elementSize("shadow-hint-top-margin");
kDebug() << "top margin hint is:" << marginHint;
@ -197,14 +183,13 @@ void PanelShadows::getMargins(int &top, int &right, int &bottom, int &left)
void PanelShadows::Private::clearPixmaps()
{
#ifdef Q_WS_X11
#warning FIXME: pixmaps are leaked
if (m_managePixmaps) {
foreach (const QPixmap &pixmap, m_shadowPixmaps) {
XFreePixmap(QX11Info::display(), pixmap.handle());
foreach (KPixmap &pixmap, m_shadowPixmaps) {
pixmap.release();
}
m_managePixmaps = false;
}
#endif
m_shadowPixmaps.clear();
data.clear();
}