LayerFlushSchedulerMac.cpp [plain text]
#include "config.h"
#if USE(ACCELERATED_COMPOSITING)
#include "LayerFlushScheduler.h"
#include "AutodrainedPool.h"
namespace WebCore {
static const CFIndex CoreAnimationRunLoopOrder = 2000000;
static const CFIndex LayerFlushRunLoopOrder = CoreAnimationRunLoopOrder - 1;
LayerFlushScheduler::LayerFlushScheduler(LayerFlushSchedulerClient* client)
: m_isSuspended(false)
, m_client(client)
{
ASSERT_ARG(client, client);
}
LayerFlushScheduler::~LayerFlushScheduler()
{
ASSERT(!m_runLoopObserver);
}
void LayerFlushScheduler::runLoopObserverCallback(CFRunLoopObserverRef, CFRunLoopActivity, void* context)
{
static_cast<LayerFlushScheduler*>(context)->runLoopObserverCallback();
}
void LayerFlushScheduler::runLoopObserverCallback()
{
ASSERT(m_runLoopObserver);
ASSERT(!m_isSuspended);
AutodrainedPool pool;
if (m_client->flushLayers())
invalidate();
}
void LayerFlushScheduler::schedule()
{
if (m_isSuspended)
return;
CFRunLoopRef currentRunLoop = CFRunLoopGetCurrent();
CFRunLoopWakeUp(currentRunLoop);
if (m_runLoopObserver)
return;
CFRunLoopObserverContext context = { 0, this, 0, 0, 0 };
m_runLoopObserver.adoptCF(CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting | kCFRunLoopExit, true, LayerFlushRunLoopOrder, runLoopObserverCallback, &context));
CFRunLoopAddObserver(currentRunLoop, m_runLoopObserver.get(), kCFRunLoopCommonModes);
}
void LayerFlushScheduler::invalidate()
{
if (m_runLoopObserver) {
CFRunLoopObserverInvalidate(m_runLoopObserver.get());
m_runLoopObserver = nullptr;
}
}
}
#endif // USE(ACCELERATED_COMPOSITING)