void ScriptedAnimationController::executeCallbacks(double monotonicTimeNow)
{
    // dispatchEvents() runs script which can cause the document to be destroyed.
    if (!m_document)
        return;

    double highResNowMs = 1000.0 * m_document->loader()->timing()->monotonicTimeToZeroBasedDocumentTime(monotonicTimeNow);
    double legacyHighResNowMs = 1000.0 * m_document->loader()->timing()->monotonicTimeToPseudoWallTime(monotonicTimeNow);

    // First, generate a list of callbacks to consider.  Callbacks registered from this point
    // on are considered only for the "next" frame, not this one.
    ASSERT(m_callbacksToInvoke.isEmpty());
    m_callbacksToInvoke.swap(m_callbacks);

    for (size_t i = 0; i < m_callbacksToInvoke.size(); ++i) {
        RequestAnimationFrameCallback* callback = m_callbacksToInvoke[i].get();
        if (!callback->m_cancelled) {
            TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "FireAnimationFrame", "data", InspectorAnimationFrameEvent::data(m_document, callback->m_id));
            // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeline migrates to tracing.
            InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireAnimationFrame(m_document, callback->m_id);
            if (callback->m_useLegacyTimeBase)
                callback->handleEvent(legacyHighResNowMs);
            else
                callback->handleEvent(highResNowMs);
            InspectorInstrumentation::didFireAnimationFrame(cookie);
            TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "UpdateCounters", "data", InspectorUpdateCountersEvent::data());
        }
    }

    m_callbacksToInvoke.clear();
}
Example #2
0
// CAPPFIX_WEB_HTML5: Request Animation Frame
void ScriptedAnimationController::serviceScriptedAnimations(DOMTimeStamp time)
{
    if (!m_callbacks.size() || m_suspendCount)
        return;

    // First, generate a list of callbacks to consider.  Callbacks registered from this point
    // on are considered only for the "next" frame, not this one.
    CallbackList callbacks(m_callbacks);

    // Invoking callbacks may detach elements from our document, which clears the document's
    // reference to us, so take a defensive reference.
    RefPtr<ScriptedAnimationController> protector(this);

    for (size_t i = 0; i < callbacks.size(); ++i) {
        RequestAnimationFrameCallback* callback = callbacks[i].get();
        if (!callback->m_firedOrCancelled) {
            callback->m_firedOrCancelled = true;
            callback->handleEvent(time);
         }
    }

    // Remove any callbacks we fired from the list of pending callbacks.
    for (size_t i = 0; i < m_callbacks.size();) {
        if (m_callbacks[i]->m_firedOrCancelled)
            m_callbacks.remove(i);
        else
            ++i;
    }

    if (m_callbacks.size())
        scheduleAnimation();
}
Example #3
0
void ScriptedAnimationController::serviceScriptedAnimations(DOMTimeStamp time)
{
    if (!m_callbacks.size() || m_suspendCount)
        return;
    // We want to run the callback for all elements in the document that have registered
    // for a callback and that are visible.  Running the callbacks can cause new callbacks
    // to be registered, existing callbacks to be cancelled, and elements to gain or lose
    // visibility so this code has to iterate carefully.

    // FIXME: Currently, this code doesn't do any visibility tests beyond checking display:

    // First, generate a list of callbacks to consider.  Callbacks registered from this point
    // on are considered only for the "next" frame, not this one.
    CallbackList callbacks(m_callbacks);

    // Firing the callback may cause the visibility of other elements to change.  To avoid
    // missing any callbacks, we keep iterating through the list of candiate callbacks and firing
    // them until nothing new becomes visible.
    bool firedCallback;

    // Invoking callbacks may detach elements from our document, which clear's the document's
    // reference to us, so take a defensive reference.
    RefPtr<ScriptedAnimationController> protector(this);
    do {
        firedCallback = false;
        // A previous iteration may have detached this Document from the DOM tree.
        // If so, then we do not need to process any more callbacks.
        if (!m_document)
            continue;

        // A previous iteration may have invalidated style (or layout).  Update styles for each iteration
        // for now since all we check is the existence of a renderer.
        m_document->updateStyleIfNeeded();
        for (size_t i = 0; i < callbacks.size(); ++i) {
            RequestAnimationFrameCallback* callback = callbacks[i].get();
            if (!callback->m_firedOrCancelled && (!callback->m_element || callback->m_element->renderer())) {
                callback->m_firedOrCancelled = true;
                InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireAnimationFrame(m_document, callback->m_id);
                callback->handleEvent(time);
                InspectorInstrumentation::didFireAnimationFrame(cookie);
                firedCallback = true;
                callbacks.remove(i);
                break;
            }
        }
    } while (firedCallback);

    // Remove any callbacks we fired from the list of pending callbacks.
    for (size_t i = 0; i < m_callbacks.size();) {
        if (m_callbacks[i]->m_firedOrCancelled)
            m_callbacks.remove(i);
        else
            ++i;
    }

    if (m_callbacks.size())
        scheduleAnimation();
}
void ScriptedAnimationController::serviceScriptedAnimations(DOMTimeStamp time)
{
    if (!m_callbacks.size() || m_suspendCount)
        return;
    // We want to run the callback for all elements in the document that have registered
    // for a callback and that are visible.  Running the callbacks can cause new callbacks
    // to be registered, existing callbacks to be cancelled, and elements to gain or lose
    // visibility so this code has to iterate carefully.

    // FIXME: Currently, this code doesn't do any visibility tests beyond checking display:

    // First, generate a list of callbacks to consider.  Callbacks registered from this point
    // on are considered only for the "next" frame, not this one.
    CallbackList callbacks(m_callbacks);

    // Firing the callback may cause the visibility of other elements to change.  To avoid
    // missing any callbacks, we keep iterating through the list of candiate callbacks and firing
    // them until nothing new becomes visible.
    bool firedCallback;
    do {
        firedCallback = false;
        // A previous iteration may have invalidated style (or layout).  Update styles for each iteration
        // for now since all we check is the existence of a renderer.
        m_document->updateStyleIfNeeded();
        for (size_t i = 0; i < callbacks.size(); ++i) {
            RequestAnimationFrameCallback* callback = callbacks[i].get();
            if (!callback->m_firedOrCancelled && (!callback->m_element || callback->m_element->renderer())) {
                callback->m_firedOrCancelled = true;
                callback->handleEvent(time);
                firedCallback = true;
                callbacks.remove(i);
                break;
            }
        }
    } while (firedCallback);

    // Remove any callbacks we fired from the list of pending callbacks.
    for (size_t i = 0; i < m_callbacks.size();) {
        if (m_callbacks[i]->m_firedOrCancelled)
            m_callbacks.remove(i);
        else
            ++i;
    }

    if (m_callbacks.size())
        scheduleAnimation(); //SAMSUNG CHANGES HTML5 REQUEST ANIMATION 
}
void ScriptedAnimationController::executeCallbacks(double monotonicTimeNow)
{
    // dispatchEvents() runs script which can cause the document to be destroyed.
    if (!m_document)
        return;

    double highResNowMs = 1000.0 * monotonicTimeNow;

    // First, generate a list of callbacks to consider.  Callbacks registered from this point
    // on are considered only for the "next" frame, not this one.
    ASSERT(m_callbacksToInvoke.isEmpty());
    m_callbacksToInvoke.swap(m_callbacks);

    for (size_t i = 0; i < m_callbacksToInvoke.size(); ++i) {
        RequestAnimationFrameCallback* callback = m_callbacksToInvoke[i].get();
        if (!callback->m_cancelled)
            callback->handleEvent(highResNowMs);
    }

    m_callbacksToInvoke.clear();
}