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 {
PassRef<ViewUpdateDispatcher> ViewUpdateDispatcher::create()
{
return adoptRef(*new ViewUpdateDispatcher);
}
ViewUpdateDispatcher::ViewUpdateDispatcher()
: m_queue(WorkQueue::create("com.apple.WebKit.ViewUpdateDispatcher"))
, m_dataMutex(SPINLOCK_INITIALIZER)
{
}
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)
RunLoop::main().dispatch(bind(&ViewUpdateDispatcher::dispatchVisibleContentRectUpdate, this));
}
void ViewUpdateDispatcher::dispatchVisibleContentRectUpdate()
{
HashMap<uint64_t, UpdateData> localCopy;
{
SpinLockHolder locker(&m_dataMutex);
localCopy.swap(m_latestUpdate);
}
for (auto& slot : localCopy) {
if (WebPage* webPage = WebProcess::shared().webPage(slot.key))
webPage->updateVisibleContentRects(slot.value.visibleContentRectUpdateInfo, slot.value.oldestTimestamp);
}
}
}
#endif // PLATFORM(IOS)