ViewUpdateDispatcher.cpp [plain text]
#include "config.h"
#include "ViewUpdateDispatcher.h"
#if PLATFORM(IOS)
#include "ViewUpdateDispatcherMessages.h"
#include "WebPage.h"
#include "WebProcess.h"
#include <wtf/RunLoop.h>
namespace WebKit {
Ref<ViewUpdateDispatcher> ViewUpdateDispatcher::create()
{
return adoptRef(*new ViewUpdateDispatcher);
}
ViewUpdateDispatcher::ViewUpdateDispatcher()
: m_queue(WorkQueue::create("com.apple.WebKit.ViewUpdateDispatcher"))
{
}
ViewUpdateDispatcher::~ViewUpdateDispatcher()
{
}
void ViewUpdateDispatcher::initializeConnection(IPC::Connection* connection)
{
connection->addWorkQueueMessageReceiver(Messages::ViewUpdateDispatcher::messageReceiverName(), &m_queue.get(), this);
}
void ViewUpdateDispatcher::visibleContentRectUpdate(uint64_t pageID, const VisibleContentRectUpdateInfo& visibleContentRectUpdateInfo)
{
bool updateListWasEmpty;
{
SpinLockHolder locker(&m_dataMutex);
updateListWasEmpty = m_latestUpdate.isEmpty();
auto iterator = m_latestUpdate.find(pageID);
if (iterator == m_latestUpdate.end())
m_latestUpdate.set<UpdateData>(pageID, { visibleContentRectUpdateInfo, visibleContentRectUpdateInfo.timestamp() });
else
iterator->value.visibleContentRectUpdateInfo = visibleContentRectUpdateInfo;
}
if (updateListWasEmpty) {
RefPtr<ViewUpdateDispatcher> protector(this);
RunLoop::main().dispatch([protector] {
protector->dispatchVisibleContentRectUpdate();
});
}
}
void ViewUpdateDispatcher::dispatchVisibleContentRectUpdate()
{
HashMap<uint64_t, UpdateData> update;
{
SpinLockHolder locker(&m_dataMutex);
update = WTF::move(m_latestUpdate);
}
for (auto& slot : update) {
if (WebPage* webPage = WebProcess::singleton().webPage(slot.key))
webPage->updateVisibleContentRects(slot.value.visibleContentRectUpdateInfo, slot.value.oldestTimestamp);
}
}
}
#endif // PLATFORM(IOS)