diff options
author | Armin Berres <armin.berres@basyskom.de> | 2010-07-13 13:43:05 +0200 |
---|---|---|
committer | Sergiy Dubovik <sergiy.dubovik@nokia.com> | 2010-07-20 14:11:51 +0300 |
commit | 86fa0df092dd1f541f114a02586d0f6a6d3b0fe4 (patch) | |
tree | db725c00c035f14331fe4c22f86472ea45c9368d /mthemedaemon | |
parent | 68bca5c5188e721ce55f508409d276190beb910e (diff) |
Changes: themedaemon sends most used pixmap handles to the clients
RevBy: Peter Penz
Details:
The themedaemon keeps internally a list of most used pixmaps which
are always hold in memory. When a client requests a pixmap from this
list the pixmap can be returned faster. Ideally the client would
not have to query the themedaemon at all but just know about the
handles if the most used pixmaps. With this commit the themedaemon
sends the handles of the most used pixmaps to the clients when they
register and keeps them up to date if the list of most used pixmaps
changes.
If a client uses one of these pixmaps it notifies the themedaemon so
it can keep statistics about most used pixmaps up to date.
Diffstat (limited to 'mthemedaemon')
-rw-r--r-- | mthemedaemon/mthemedaemonserver.cpp | 59 | ||||
-rw-r--r-- | mthemedaemon/mthemedaemonserver.h | 16 |
2 files changed, 72 insertions, 3 deletions
diff --git a/mthemedaemon/mthemedaemonserver.cpp b/mthemedaemon/mthemedaemonserver.cpp index a17323f1..849dec4c 100644 --- a/mthemedaemon/mthemedaemonserver.cpp +++ b/mthemedaemon/mthemedaemonserver.cpp @@ -35,7 +35,8 @@ MThemeDaemonServer::MThemeDaemonServer() : currentTheme("/meegotouch/theme/name"), currentLocale("/meegotouch/i18n/language"), defaultTheme(M_THEME_DEFAULT), - delayedThemeChange(false) + delayedThemeChange(false), + sequenceCounter(0) { // 1) make sure that gconf has some value for the current theme if (currentTheme.value().isNull() || currentTheme.value().toString().isEmpty() ) @@ -85,6 +86,7 @@ MThemeDaemonServer::MThemeDaemonServer() : processQueueTimer.setInterval(0); processQueueTimer.setSingleShot(false); connect(&processQueueTimer, SIGNAL(timeout()), SLOT(processOneQueueItem())); + connect(&daemon.mostUsedPixmaps, SIGNAL(mostUsedPixmapsChanged(M::MThemeDaemonProtocol::MostUsedPixmaps)), this, SLOT(handleUpdatedMostUsedPixmaps(M::MThemeDaemonProtocol::MostUsedPixmaps))); } MThemeDaemonServer::~MThemeDaemonServer() @@ -189,6 +191,8 @@ void MThemeDaemonServer::clientDataAvailable() daemon.addClient(client); client->stream() << Packet(Packet::ThemeChangedPacket, packet.sequenceNumber(), new ThemeChangeInfo(daemon.themeInheritanceChain(), daemon.themeLibraryNames())); + client->stream() << Packet(Packet::MostUsedPixmapsPacket, ++sequenceCounter, + new MostUsedPixmaps(daemon.mostUsedPixmaps.mostUsedPixmapHandles(), QList<PixmapIdentifier>())); break; } } @@ -211,6 +215,12 @@ void MThemeDaemonServer::clientDataAvailable() new ThemeChangeInfo(daemon.themeInheritanceChain(), daemon.themeLibraryNames())); } break; + case Packet::PixmapUsedPacket: { + // client wants to use a pixmap + const PixmapIdentifier *id = static_cast<const PixmapIdentifier *>(packet.data()); + pixmapUsed(client, *id, packet.sequenceNumber()); + } break; + case Packet::RequestPixmapPacket: { // client requested a pixmap const PixmapIdentifier *id = static_cast<const PixmapIdentifier *>(packet.data()); @@ -236,6 +246,10 @@ void MThemeDaemonServer::clientDataAvailable() themeChangeApplied(client, packet.sequenceNumber()); } break; + case Packet::AckMostUsedPixmapsPacket: { + ackMostUsedPixmaps(client, packet.sequenceNumber()); + } break; + case Packet::QueryThemeDaemonStatusPacket: { themeDaemonStatus(client, packet.sequenceNumber()); } break; @@ -398,6 +412,34 @@ void MThemeDaemonServer::processOneQueueItem() } } +void MThemeDaemonServer::handleUpdatedMostUsedPixmaps(const M::MThemeDaemonProtocol::MostUsedPixmaps& mostUsed) +{ + quint64 sequenceNumber = ++sequenceCounter; + + foreach(MThemeDaemonClient * c, registeredClients) { + c->stream() << Packet(Packet::MostUsedPixmapsPacket, sequenceNumber, new MostUsedPixmaps(mostUsed)); + if (!mostUsed.removedIdentifiers.empty()) { + clientsThatHaveNotYetUpdatedMostUsed[sequenceNumber].append(c); + } + } + if (!mostUsed.removedIdentifiers.empty()) { + pixmapsToDeleteWhenUpdatedMostUsed[sequenceNumber] = mostUsed.removedIdentifiers; + } +} + +void MThemeDaemonServer::pixmapUsed(MThemeDaemonClient *client, + const PixmapIdentifier &id, quint64 sequenceNumber) +{ + Q_UNUSED(sequenceNumber) + // if the client has requested a release for this pixmap, we'll remove the + // release request, otherwise we increase the reference count + const QueueItem item (client, id, sequenceNumber); + if (!releasePixmapsQueue.removeOne(item)) { + Qt::HANDLE handle; + daemon.pixmap(item.client, item.pixmapId, handle); + } +} + void MThemeDaemonServer::pixmapRequested(MThemeDaemonClient *client, const PixmapIdentifier &id, quint64 sequenceNumber) { @@ -471,6 +513,21 @@ void MThemeDaemonServer::themeChangeApplied(MThemeDaemonClient *client, } } +void MThemeDaemonServer::ackMostUsedPixmaps(MThemeDaemonClient *client, + quint64 sequenceNumber) +{ + if(!clientsThatHaveNotYetUpdatedMostUsed[sequenceNumber].removeOne(client)) { + mWarning("MThemeDaemonServer") << "Client" << client->name() << "has already acked most used pixmaps packet!"; + return; + } + + if (clientsThatHaveNotYetUpdatedMostUsed.empty()) { + foreach(const PixmapIdentifier& id, pixmapsToDeleteWhenUpdatedMostUsed[sequenceNumber]) { + pixmapReleaseRequested(client, id, sequenceNumber); + } + } +} + void MThemeDaemonServer::themeDaemonStatus(MThemeDaemonClient *client, quint64 sequenceNumber) const { diff --git a/mthemedaemon/mthemedaemonserver.h b/mthemedaemon/mthemedaemonserver.h index 346e504c..8114c1b8 100644 --- a/mthemedaemon/mthemedaemonserver.h +++ b/mthemedaemon/mthemedaemonserver.h @@ -52,16 +52,23 @@ private slots: void processOneQueueItem(); + void handleUpdatedMostUsedPixmaps(const M::MThemeDaemonProtocol::MostUsedPixmaps& mostUsed); + private: + void pixmapUsed(MThemeDaemonClient *client, + const M::MThemeDaemonProtocol::PixmapIdentifier &id, + quint64 sequenceNumber); void pixmapRequested(MThemeDaemonClient *client, - const M::MThemeDaemonProtocol::PixmapIdentifier &id, - quint64 sequenceNumber); + const M::MThemeDaemonProtocol::PixmapIdentifier &id, + quint64 sequenceNumber); void pixmapReleaseRequested(MThemeDaemonClient *client, const M::MThemeDaemonProtocol::PixmapIdentifier &id, quint64 sequenceNumber); void themeChangeApplied(MThemeDaemonClient *client, quint64 sequenceNumber); + void ackMostUsedPixmaps(MThemeDaemonClient *client, quint64 sequenceNumber); + void themeDaemonStatus(MThemeDaemonClient *client, quint64 sequenceNumber) const; private: @@ -97,6 +104,11 @@ private: QList<MThemeDaemonClient*> clientsThatHaveNotYetAppliedThemeChange; QList<QPixmap*> pixmapsToDeleteWhenThemeChangeHasCompleted; + + QHash<quint64, QList<MThemeDaemonClient*> > clientsThatHaveNotYetUpdatedMostUsed; + QHash<quint64, QList<M::MThemeDaemonProtocol::PixmapIdentifier> > pixmapsToDeleteWhenUpdatedMostUsed; + + quint64 sequenceCounter; }; //! \internal_end #endif |