Git commit 067e9bb5f767b4f64d9f0156c708ca29771b9648 by Marco Martin. Committed on 31/01/2017 at 20:42. Pushed by mart into branch 'mart/FrameSvgTransactions'. ditch the frames hash save locally only one frame, as all the others are in the static hash anyways Change-Id: If9d2338dd33c0a4b9771184bc852dd8ab0f19057 M +70 -94 src/plasma/framesvg.cpp M +2 -2 src/plasma/private/framesvg_p.h https://commits.kde.org/plasma-framework/067e9bb5f767b4f64d9f0156c708ca2977= 1b9648 diff --git a/src/plasma/framesvg.cpp b/src/plasma/framesvg.cpp index 11c3f09d4..9237ca5a5 100644 --- a/src/plasma/framesvg.cpp +++ b/src/plasma/framesvg.cpp @@ -51,7 +51,9 @@ FrameData::~FrameData() ++destcount; qWarning()<<"AAA"<d->frames.remove(prefix); + if (it.key()->d->frame =3D=3D this) { + it.key()->d->frame =3D nullptr; + } } } = @@ -61,7 +63,7 @@ FrameSvg::FrameSvg(QObject *parent) d(new FrameSvgPrivate(this)) { connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded())); - d->frames.insert(QString(), new FrameData(this, QString())); + d->frame =3D new FrameData(this, QString()); } = FrameSvg::~FrameSvg() @@ -78,7 +80,7 @@ void FrameSvg::setImagePath(const QString &path) bool updateNeeded =3D true; clearCache(); = - FrameData *fd =3D d->frames[d->prefix]; + FrameData *fd =3D d->frame; if (fd->refcount() =3D=3D 1) { // we're the only user of it, let's remove it from the shared keys // we don't want to deref it, however, as we'll still be using it @@ -94,7 +96,7 @@ void FrameSvg::setImagePath(const QString &path) = if (!fd) { // we need to replace our frame, start by looking in the frame cac= he - FrameData *oldFd =3D d->frames[d->prefix]; + FrameData *oldFd =3D d->frame; const QString key =3D d->cacheId(oldFd, d->prefix); fd =3D FrameSvgPrivate::s_sharedFrames[theme()->d].value(key); = @@ -110,7 +112,7 @@ void FrameSvg::setImagePath(const QString &path) fd =3D new FrameData(*oldFd, this); } = - d->frames.insert(d->prefix, fd); + d->frame =3D fd; } = setContainsMultipleImages(true); @@ -129,7 +131,7 @@ void FrameSvg::setImagePath(const QString &path) = void FrameSvg::setEnabledBorders(const EnabledBorders borders) { - if (borders =3D=3D d->frames[d->prefix]->enabledBorders) { + if (borders =3D=3D d->frame->enabledBorders) { return; } = @@ -142,16 +144,10 @@ void FrameSvg::setEnabledBorders(const EnabledBorders= borders) = FrameSvg::EnabledBorders FrameSvg::enabledBorders() const { - if (d->frames.isEmpty()) { + if (!d->frame) { return NoBorder; - } - - QHash::const_iterator it =3D d->frames.constFind= (d->prefix); - - if (it !=3D d->frames.constEnd()) { - return it.value()->enabledBorders; } else { - return NoBorder; + return d->frame->enabledBorders; } } = @@ -247,8 +243,7 @@ void FrameSvg::resizeFrame(const QSizeF &size) return; } = - FrameData *fd =3D d->frames[d->prefix]; - if (size.toSize() =3D=3D fd->frameSize) { + if (size.toSize() =3D=3D d->frame->frameSize) { return; } d->pendingFrameSize =3D size.toSize(); @@ -260,103 +255,96 @@ void FrameSvg::resizeFrame(const QSizeF &size) = QSizeF FrameSvg::frameSize() const { - QHash::const_iterator it =3D d->frames.constFind= (d->prefix); - - if (it =3D=3D d->frames.constEnd()) { + if (!d->frame) { return QSize(-1, -1); } else { - return d->frameSize(it.value()); + return d->frameSize(d->frame); } } = qreal FrameSvg::marginSize(const Plasma::Types::MarginEdge edge) const { - if (d->frames[d->prefix]->noBorderPadding) { + if (d->frame->noBorderPadding) { return .0; } = switch (edge) { case Plasma::Types::TopMargin: - return d->frames[d->prefix]->topMargin; + return d->frame->topMargin; break; = case Plasma::Types::LeftMargin: - return d->frames[d->prefix]->leftMargin; + return d->frame->leftMargin; break; = case Plasma::Types::RightMargin: - return d->frames[d->prefix]->rightMargin; + return d->frame->rightMargin; break; = //Plasma::BottomMargin default: - return d->frames[d->prefix]->bottomMargin; + return d->frame->bottomMargin; break; } } = qreal FrameSvg::fixedMarginSize(const Plasma::Types::MarginEdge edge) const { - if (d->frames[d->prefix]->noBorderPadding) { + if (d->frame->noBorderPadding) { return .0; } = switch (edge) { case Plasma::Types::TopMargin: - return d->frames[d->prefix]->fixedTopMargin; + return d->frame->fixedTopMargin; break; = case Plasma::Types::LeftMargin: - return d->frames[d->prefix]->fixedLeftMargin; + return d->frame->fixedLeftMargin; break; = case Plasma::Types::RightMargin: - return d->frames[d->prefix]->fixedRightMargin; + return d->frame->fixedRightMargin; break; = //Plasma::BottomMargin default: - return d->frames[d->prefix]->fixedBottomMargin; + return d->frame->fixedBottomMargin; break; } } = void FrameSvg::getMargins(qreal &left, qreal &top, qreal &right, qreal &bo= ttom) const { - FrameData *frame =3D d->frames[d->prefix]; - - if (frame->noBorderPadding) { + if (d->frame->noBorderPadding) { left =3D top =3D right =3D bottom =3D 0; return; } = - top =3D frame->topMargin; - left =3D frame->leftMargin; - right =3D frame->rightMargin; - bottom =3D frame->bottomMargin; + top =3D d->frame->topMargin; + left =3D d->frame->leftMargin; + right =3D d->frame->rightMargin; + bottom =3D d->frame->bottomMargin; } = void FrameSvg::getFixedMargins(qreal &left, qreal &top, qreal &right, qrea= l &bottom) const { - FrameData *frame =3D d->frames[d->prefix]; - - if (frame->noBorderPadding) { + if (d->frame->noBorderPadding) { left =3D top =3D right =3D bottom =3D 0; return; } = - top =3D frame->fixedTopMargin; - left =3D frame->fixedLeftMargin; - right =3D frame->fixedRightMargin; - bottom =3D frame->fixedBottomMargin; + top =3D d->frame->fixedTopMargin; + left =3D d->frame->fixedLeftMargin; + right =3D d->frame->fixedRightMargin; + bottom =3D d->frame->fixedBottomMargin; } = QRectF FrameSvg::contentsRect() const { - FrameData* frame =3D d->frames.value(d->prefix); - if (frame) { - QRectF rect(QPoint(0,0), frame->frameSize); - return rect.adjusted(frame->leftMargin, frame->topMargin, -frame->= rightMargin, -frame->bottomMargin); + if (d->frame) { + QRectF rect(QPoint(0,0), d->frame->frameSize); + return rect.adjusted(d->frame->leftMargin, d->frame->topMargin, -d= ->frame->rightMargin, -d->frame->bottomMargin); } else { return QRectF(); } @@ -370,16 +358,15 @@ QPixmap FrameSvg::alphaMask() const = QRegion FrameSvg::mask() const { - FrameData *frame =3D d->frames[d->prefix]; - QString id =3D d->cacheId(frame, QString()); + QString id =3D d->cacheId(d->frame, QString()); = - QRegion* obj =3D frame->cachedMasks.object(id); + QRegion* obj =3D d->frame->cachedMasks.object(id); QRegion result; = if (!obj) { obj =3D new QRegion(QBitmap(d->alphaMask().alphaChannel().createMa= skFromColor(Qt::black))); result =3D *obj; - frame->cachedMasks.insert(id, obj); + d->frame->cachedMasks.insert(id, obj); } else { result =3D *obj; @@ -403,7 +390,7 @@ bool FrameSvg::cacheAllRenderedFrames() const = void FrameSvg::clearCache() { - FrameData *frame =3D d->frames[d->prefix]; + /* FrameData *frame =3D d->frames[d->prefix]; = // delete all the frames that aren't this one QMutableHashIterator it(d->frames); @@ -419,43 +406,40 @@ void FrameSvg::clearCache() = it.remove(); } - } + }*/ } = QPixmap FrameSvg::framePixmap() { - FrameData *frame =3D d->frames[d->prefix]; - if (frame->cachedBackground.isNull()) { - d->generateBackground(frame); + if (d->frame->cachedBackground.isNull()) { + d->generateBackground(d->frame); } = - return frame->cachedBackground; + return d->frame->cachedBackground; } = void FrameSvg::paintFrame(QPainter *painter, const QRectF &target, const Q= RectF &source) { - FrameData *frame =3D d->frames[d->prefix]; - if (frame->cachedBackground.isNull()) { - d->generateBackground(frame); - if (frame->cachedBackground.isNull()) { + if (d->frame->cachedBackground.isNull()) { + d->generateBackground(d->frame); + if (d->frame->cachedBackground.isNull()) { return; } } = - painter->drawPixmap(target, frame->cachedBackground, source.isValid() = ? source : target); + painter->drawPixmap(target, d->frame->cachedBackground, source.isValid= () ? source : target); } = void FrameSvg::paintFrame(QPainter *painter, const QPointF &pos) { - FrameData *frame =3D d->frames[d->prefix]; - if (frame->cachedBackground.isNull()) { - d->generateBackground(frame); - if (frame->cachedBackground.isNull()) { + if (d->frame->cachedBackground.isNull()) { + d->generateBackground(d->frame); + if (d->frame->cachedBackground.isNull()) { return; } } = - painter->drawPixmap(pos, frame->cachedBackground); + painter->drawPixmap(pos, d->frame->cachedBackground); } = //#define DEBUG_FRAMESVG_CACHE @@ -467,26 +451,27 @@ FrameSvgPrivate::~FrameSvgPrivate() #endif #endif = - QHashIterator it(frames); + QList frames({frame, maskFrame}); + QListIterator it(frames); while (it.hasNext()) { - it.next(); - if (it.value()) { + FrameData *fd =3D it.next(); + if (fd) { // we remove all references from this widget to the frame, and= delete it if we're the // last user - if (it.value()->removeRefs(q)) { - const QString key =3D cacheId(it.value(), it.key()); + if (fd->removeRefs(q)) { + const QString key =3D cacheId(fd, fd->prefix); #ifdef DEBUG_FRAMESVG_CACHE #ifndef NDEBUG - // qCDebug(LOG_PLASMA) << "2. Removing it" << key << it.va= lue() << it.value()->refcount() << s_sharedFrames[theme()->d].contains(key); + // qCDebug(LOG_PLASMA) << "2. Removing it" << key << fd <<= fd->refcount() << s_sharedFrames[theme()->d].contains(key); #endif #endif - s_sharedFrames[it.value()->theme].remove(key); - delete it.value(); + s_sharedFrames[fd->theme].remove(key); + delete fd; } #ifdef DEBUG_FRAMESVG_CACHE else { #ifndef NDEBUG - // qCDebug(LOG_PLASMA) << "still shared:" << cacheId(it.va= lue(), it.key()) << it.value() << it.value()->refcount() << it.value()->isU= sed(); + // qCDebug(LOG_PLASMA) << "still shared:" << cacheId(*it, = it.key()) << fd << fd->refcount() << fd->isUsed(); #endif } } else { @@ -524,12 +509,12 @@ FrameSvgPrivate::~FrameSvgPrivate() #endif #endif = - frames.clear(); + frame =3D nullptr; + maskFrame =3D nullptr; } = QPixmap FrameSvgPrivate::alphaMask() { - FrameData *frame =3D frames[prefix]; QString maskPrefix; = if (q->hasElement(QLatin1String("mask-") % prefix % QLatin1String("cen= ter"))) { @@ -552,12 +537,12 @@ QPixmap FrameSvgPrivate::alphaMask() // the needed mask image prefix =3D maskPrefix % oldPrefix; = - if (!frames.contains(prefix)) { + if (!maskFrame) { const QString key =3D cacheId(frame, prefix); // see if we can find a suitable candidate in the shared frames // if successful, ref and insert, otherwise create a new one // and insert that into both the shared frames and our frames. - FrameData *maskFrame =3D s_sharedFrames[q->theme()->d].value(k= ey); + maskFrame =3D s_sharedFrames[q->theme()->d].value(key); = if (maskFrame) { maskFrame->ref(q); @@ -568,11 +553,10 @@ QPixmap FrameSvgPrivate::alphaMask() } maskFrame->enabledBorders =3D frame->enabledBorders; = - frames.insert(prefix, maskFrame); updateSizes(); } = - FrameData *maskFrame =3D frames[prefix]; + maskFrame =3D frame; maskFrame->enabledBorders =3D frame->enabledBorders; if (maskFrame->cachedBackground.isNull() || maskFrame->frameSize != =3D frameSize(frame)) { const QString oldKey =3D cacheId(maskFrame, prefix); @@ -733,7 +717,7 @@ QRect FrameSvgPrivate::contentGeometry(FrameData* frame= , const QSize& size) cons = void FrameSvgPrivate::updateFrameData() { - FrameData *fd =3D frames[prefix]; + FrameData *fd =3D frame; = const QString oldKey =3D cacheId(fd, fd->prefix); = @@ -756,7 +740,7 @@ void FrameSvgPrivate::updateFrameData() //qCDebug(LOG_PLASMA) << "FOUND IT!" << newFd->refcount; // we've found a math, so insert that new one and ref it .. newFd->ref(q); - frames.insert(pendingPrefix, newFd); + frame =3D newFd; = //.. then deref the old one and if it's no longer used, get rid of= it if (fd->deref(q)) { @@ -764,10 +748,6 @@ void FrameSvgPrivate::updateFrameData() //qCDebug(LOG_PLASMA) << "1. Removing it" << oldKey << fd->ref= count; FrameSvgPrivate::s_sharedFrames[fd->theme].remove(oldKey); = - if (prefix !=3D pendingPrefix) { - frames.remove(fd->prefix); - } - delete fd; } = @@ -779,7 +759,6 @@ void FrameSvgPrivate::updateFrameData() // we're the only user of it, let's remove it from the shared keys // we don't want to deref it, however, as we'll still be using it FrameSvgPrivate::s_sharedFrames[fd->theme].remove(oldKey); - frames.remove(fd->prefix); } else { // others are using it, but we wish to change its size. so deref i= t, // then create a copy of it (we're automatically ref'd via the cto= r), @@ -788,7 +767,7 @@ void FrameSvgPrivate::updateFrameData() fd =3D new FrameData(*fd, q); } = - frames.insert(pendingPrefix, fd); + frame =3D fd; prefix =3D pendingPrefix; fd->prefix =3D pendingPrefix; //updateSizes(); @@ -877,8 +856,6 @@ void FrameSvgPrivate::cacheFrame(const QString &prefixT= oSave, const QPixmap &bac } = //insert background - FrameData *frame =3D frames.value(prefixToSave); - if (!frame) { return; } @@ -898,7 +875,6 @@ void FrameSvgPrivate::cacheFrame(const QString &prefixT= oSave, const QPixmap &bac void FrameSvgPrivate::updateSizes() const { //qCDebug(LOG_PLASMA) << "!!!!!!!!!!!!!!!!!!!!!! updating sizes" << pr= efix; - FrameData *frame =3D frames[prefix]; Q_ASSERT(frame); = QSize s =3D q->size(); diff --git a/src/plasma/private/framesvg_p.h b/src/plasma/private/framesvg_= p.h index 9956b3b80..0ed086daa 100644 --- a/src/plasma/private/framesvg_p.h +++ b/src/plasma/private/framesvg_p.h @@ -173,8 +173,8 @@ public: = QPoint overlayPos; = - QHash frames; - //FrameData *frame; + FrameData *frame; + FrameData *maskFrame; = //those can differ from frame->enabledBorders if we are in a transition FrameSvg::EnabledBorders pendingEnabledBorders;