https://bugs.webkit.org/show_bug.cgi?id=66683
This changes requestAnimationFrame's animationStartTime argument
to be a high resolution DOM timestamp, per disucssion here:
http://lists.w3.org/Archives/Public/public-web-perf/2012Apr/0004.html
Reviewed by James Robinson.
Source/WebCore:
Covered by existing requestAnimationFrame tests.
* dom/Document.cpp:
(WebCore::Document::serviceScriptedAnimations):
* dom/Document.h:
(Document):
* dom/ScriptedAnimationController.cpp:
(WebCore::ScriptedAnimationController::ScriptedAnimationController):
(WebCore::ScriptedAnimationController::serviceScriptedAnimations):
(WebCore):
(WebCore::ScriptedAnimationController::windowScreenDidChange):
(WebCore::ScriptedAnimationController::scheduleAnimation):
(WebCore::ScriptedAnimationController::animationTimerFired):
(WebCore::ScriptedAnimationController::displayRefreshFired):
* dom/ScriptedAnimationController.h:
(ScriptedAnimationController):
* page/FrameView.cpp:
(WebCore::FrameView::serviceScriptedAnimations):
* page/FrameView.h:
(FrameView):
* platform/graphics/DisplayRefreshMonitor.cpp:
(WebCore::DisplayRefreshMonitor::DisplayRefreshMonitor):
(WebCore::DisplayRefreshMonitor::notifyClients):
* platform/graphics/DisplayRefreshMonitor.h:
(DisplayRefreshMonitor):
* platform/graphics/blackberry/DisplayRefreshMonitorBlackBerry.cpp:
(WebCore::DisplayRefreshMonitor::displayLinkFired):
* platform/graphics/mac/DisplayRefreshMonitorMac.cpp:
(WebCore):
(WebCore::DisplayRefreshMonitor::requestRefreshCallback):
(WebCore::DisplayRefreshMonitor::displayLinkFired):
Source/WebKit/chromium:
* src/PageWidgetDelegate.cpp:
(WebKit::PageWidgetDelegate::animate):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::updateAnimations):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@115525
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2012-04-27 Nat Duca <nduca@chromium.org>
+
+ Expose high-resolution on requestAnimationFrame callback
+ https://bugs.webkit.org/show_bug.cgi?id=66683
+
+ This changes requestAnimationFrame's animationStartTime argument
+ to be a high resolution DOM timestamp, per disucssion here:
+ http://lists.w3.org/Archives/Public/public-web-perf/2012Apr/0004.html
+
+ Reviewed by James Robinson.
+
+ Covered by existing requestAnimationFrame tests.
+
+ * dom/Document.cpp:
+ (WebCore::Document::serviceScriptedAnimations):
+ * dom/Document.h:
+ (Document):
+ * dom/ScriptedAnimationController.cpp:
+ (WebCore::ScriptedAnimationController::ScriptedAnimationController):
+ (WebCore::ScriptedAnimationController::serviceScriptedAnimations):
+ (WebCore):
+ (WebCore::ScriptedAnimationController::windowScreenDidChange):
+ (WebCore::ScriptedAnimationController::scheduleAnimation):
+ (WebCore::ScriptedAnimationController::animationTimerFired):
+ (WebCore::ScriptedAnimationController::displayRefreshFired):
+ * dom/ScriptedAnimationController.h:
+ (ScriptedAnimationController):
+ * page/FrameView.cpp:
+ (WebCore::FrameView::serviceScriptedAnimations):
+ * page/FrameView.h:
+ (FrameView):
+ * platform/graphics/DisplayRefreshMonitor.cpp:
+ (WebCore::DisplayRefreshMonitor::DisplayRefreshMonitor):
+ (WebCore::DisplayRefreshMonitor::notifyClients):
+ * platform/graphics/DisplayRefreshMonitor.h:
+ (DisplayRefreshMonitor):
+ * platform/graphics/blackberry/DisplayRefreshMonitorBlackBerry.cpp:
+ (WebCore::DisplayRefreshMonitor::displayLinkFired):
+ * platform/graphics/mac/DisplayRefreshMonitorMac.cpp:
+ (WebCore):
+ (WebCore::DisplayRefreshMonitor::requestRefreshCallback):
+ (WebCore::DisplayRefreshMonitor::displayLinkFired):
+
2012-04-27 Kentaro Hara <haraken@chromium.org>
[V8] Implement a helper method V8Proxy::throwNotEnoughArgumentsError()
#endif
#if ENABLE(REQUEST_ANIMATION_FRAME)
-__ZN7WebCore9FrameView25serviceScriptedAnimationsEy
+__ZN7WebCore9FrameView25serviceScriptedAnimationsEd
#endif
#if ENABLE(VIDEO)
namespace WebCore {
-bool JSRequestAnimationFrameCallback::handleEvent(DOMTimeStamp time)
+bool JSRequestAnimationFrameCallback::handleEvent(double highResNowMs)
{
if (!canInvokeCallback())
return true;
JSLock lock(SilenceAssertionsOnly);
MarkedArgumentBuffer args;
- args.append(jsNumber(time));
+ args.append(jsNumber(highResNowMs));
bool raisedException = false;
m_data->invokeCallback(args, &raisedException);
m_scriptedAnimationController->cancelCallback(id);
}
-void Document::serviceScriptedAnimations(DOMTimeStamp time)
+void Document::serviceScriptedAnimations(double monotonicAnimationStartTime)
{
if (!m_scriptedAnimationController)
return;
- m_scriptedAnimationController->serviceScriptedAnimations(time);
+ m_scriptedAnimationController->serviceScriptedAnimations(monotonicAnimationStartTime);
}
#endif
#if ENABLE(REQUEST_ANIMATION_FRAME)
int webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>);
void webkitCancelAnimationFrame(int id);
- void serviceScriptedAnimations(DOMTimeStamp);
+ void serviceScriptedAnimations(double monotonicAnimationStartTime);
#endif
virtual EventTarget* errorEventTarget();
#ifndef RequestAnimationFrameCallback_h
#define RequestAnimationFrameCallback_h
-#include "DOMTimeStamp.h"
#include <wtf/RefCounted.h>
namespace WebCore {
class RequestAnimationFrameCallback : public RefCounted<RequestAnimationFrameCallback> {
public:
virtual ~RequestAnimationFrameCallback() { }
- virtual bool handleEvent(DOMTimeStamp) = 0;
+ virtual bool handleEvent(double highResTimeMs) = 0;
int m_id;
bool m_firedOrCancelled;
}
#endif // RequestAnimationFrameCallback_h
-
Callback,
Conditional=REQUEST_ANIMATION_FRAME,
] RequestAnimationFrameCallback{
+ // highResTime is passed as high resolution timestamp, see
+ // http://www.w3.org/TR/hr-time/ for details.
#if defined(V8_BINDING) && V8_BINDING
- boolean handleEvent(in DOMTimeStamp time);
+ boolean handleEvent(in double highResTime);
#else
- [Custom] boolean handleEvent(in DOMTimeStamp time);
+ [Custom] boolean handleEvent(in double highResTime);
#endif
-
+
};
}
#if ENABLE(REQUEST_ANIMATION_FRAME)
#include "Document.h"
+#include "DocumentLoader.h"
#include "FrameView.h"
#include "InspectorInstrumentation.h"
#include "RequestAnimationFrameCallback.h"
, m_suspendCount(0)
#if USE(REQUEST_ANIMATION_FRAME_TIMER)
, m_animationTimer(this, &ScriptedAnimationController::animationTimerFired)
- , m_lastAnimationFrameTime(0)
+ , m_lastAnimationFrameTimeMonotonic(0)
#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
, m_useTimer(false)
#endif
}
}
-void ScriptedAnimationController::serviceScriptedAnimations(DOMTimeStamp time)
+void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTimeNow)
{
if (!m_callbacks.size() || m_suspendCount)
return;
+ double highResNowMs = 1000.0 * m_document->loader()->timing()->convertMonotonicTimeToZeroBasedDocumentTime(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.
CallbackList callbacks(m_callbacks);
if (!callback->m_firedOrCancelled) {
callback->m_firedOrCancelled = true;
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireAnimationFrame(m_document, callback->m_id);
- callback->handleEvent(time);
+ callback->handleEvent(highResNowMs);
InspectorInstrumentation::didFireAnimationFrame(cookie);
}
}
if (m_callbacks.size())
scheduleAnimation();
}
-
+
void ScriptedAnimationController::windowScreenDidChange(PlatformDisplayID displayID)
{
#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
DisplayRefreshMonitorManager::sharedManager()->windowScreenDidChange(displayID, this);
#else
UNUSED_PARAM(displayID);
-#endif
+#endif
}
void ScriptedAnimationController::scheduleAnimation()
if (!m_useTimer) {
if (DisplayRefreshMonitorManager::sharedManager()->scheduleAnimation(this))
return;
-
+
m_useTimer = true;
}
#endif
if (m_animationTimer.isActive())
return;
-
- double scheduleDelay = max<double>(MinimumAnimationInterval - (currentTime() - m_lastAnimationFrameTime), 0);
+
+ double scheduleDelay = max<double>(MinimumAnimationInterval - (monotonicallyIncreasingTime() - m_lastAnimationFrameTimeMonotonic), 0);
m_animationTimer.startOneShot(scheduleDelay);
#else
if (FrameView* frameView = m_document->view())
#if USE(REQUEST_ANIMATION_FRAME_TIMER)
void ScriptedAnimationController::animationTimerFired(Timer<ScriptedAnimationController>*)
{
- m_lastAnimationFrameTime = currentTime();
- serviceScriptedAnimations(convertSecondsToDOMTimeStamp(m_lastAnimationFrameTime));
+ m_lastAnimationFrameTimeMonotonic = monotonicallyIncreasingTime();
+ serviceScriptedAnimations(m_lastAnimationFrameTimeMonotonic);
+}
+#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
+void ScriptedAnimationController::displayRefreshFired(double monotonicTimeNow)
+{
+ serviceScriptedAnimations(monotonicTimeNow);
}
#endif
+#endif
+
+
}
#endif
-
CallbackId registerCallback(PassRefPtr<RequestAnimationFrameCallback>);
void cancelCallback(CallbackId);
- void serviceScriptedAnimations(DOMTimeStamp);
+ void serviceScriptedAnimations(double monotonicTimeNow);
void suspend();
void resume();
private:
ScriptedAnimationController(Document*, PlatformDisplayID);
-
+
typedef Vector<RefPtr<RequestAnimationFrameCallback> > CallbackList;
CallbackList m_callbacks;
#if USE(REQUEST_ANIMATION_FRAME_TIMER)
void animationTimerFired(Timer<ScriptedAnimationController>*);
Timer<ScriptedAnimationController> m_animationTimer;
- double m_lastAnimationFrameTime;
+ double m_lastAnimationFrameTimeMonotonic;
#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
// Override for DisplayRefreshMonitorClient
- virtual void displayRefreshFired(double timestamp) { serviceScriptedAnimations(convertSecondsToDOMTimeStamp(timestamp)); }
+ virtual void displayRefreshFired(double timestamp);
bool m_useTimer;
#endif
#endif // ENABLE(REQUEST_ANIMATION_FRAME)
#endif // ScriptedAnimationController_h
-
}
#if ENABLE(REQUEST_ANIMATION_FRAME)
-void FrameView::serviceScriptedAnimations(DOMTimeStamp time)
+void FrameView::serviceScriptedAnimations(double monotonicAnimationStartTime)
{
for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext()) {
frame->view()->serviceScrollAnimations();
documents.append(frame->document());
for (size_t i = 0; i < documents.size(); ++i)
- documents[i]->serviceScriptedAnimations(time);
+ documents[i]->serviceScriptedAnimations(monotonicAnimationStartTime);
}
#endif
bool needsFullRepaint() const { return m_doFullRepaint; }
#if ENABLE(REQUEST_ANIMATION_FRAME)
- void serviceScriptedAnimations(DOMTimeStamp);
+ void serviceScriptedAnimations(double monotonicAnimationStartTime);
#endif
#if USE(ACCELERATED_COMPOSITING)
}
DisplayRefreshMonitor::DisplayRefreshMonitor(PlatformDisplayID displayID)
- : m_timestamp(0)
+ : m_monotonicAnimationStartTime(0)
, m_active(true)
, m_scheduled(false)
, m_previousFrameDone(true)
void DisplayRefreshMonitor::notifyClients()
{
- double timestamp;
+ double monotonicAnimationStartTime;
{
MutexLocker lock(m_mutex);
m_scheduled = false;
- timestamp = m_timestamp;
+ monotonicAnimationStartTime = m_monotonicAnimationStartTime;
}
for (size_t i = 0; i < m_clients.size(); ++i)
- m_clients[i]->fireDisplayRefreshIfNeeded(timestamp);
+ m_clients[i]->fireDisplayRefreshIfNeeded(monotonicAnimationStartTime);
{
MutexLocker lock(m_mutex);
void notifyClients();
static void refreshDisplayOnMainThread(void* data);
- double m_timestamp;
+ double m_monotonicAnimationStartTime;
bool m_active;
bool m_scheduled;
bool m_previousFrameDone;
m_previousFrameDone = false;
- m_timestamp = currentTime();
+ m_monotonicAnimationStartTime = monotonicallyIncreasingTime();
callOnMainThread(refreshDisplayOnMainThread, this);
}
return kCVReturnSuccess;
}
-
+
DisplayRefreshMonitor::~DisplayRefreshMonitor()
{
if (m_displayLink) {
{
if (!m_active)
return false;
-
+
if (!m_displayLink) {
m_active = false;
CVReturn error = CVDisplayLinkCreateWithCGDisplay(m_displayID, &m_displayLink);
m_active = true;
}
-
+
MutexLocker lock(m_mutex);
m_scheduled = true;
return true;
m_previousFrameDone = false;
- double webKitNow = currentTime();
- m_timestamp = webKitNow - nowSeconds + outputTimeSeconds;
-
+ double webKitMonotonicNow = monotonicallyIncreasingTime();
+ double timeUntilOutput = outputTimeSeconds - nowSeconds;
+ // FIXME: Should this be using webKitMonotonicNow?
+ m_monotonicAnimationStartTime = webKitMonotonicNow + timeUntilOutput;
+
callOnMainThread(refreshDisplayOnMainThread, this);
}
+2012-04-27 Nat Duca <nduca@chromium.org>
+
+ Expose high-resolution on requestAnimationFrame callback
+ https://bugs.webkit.org/show_bug.cgi?id=66683
+
+ This changes requestAnimationFrame's animationStartTime argument
+ to be a high resolution DOM timestamp, per disucssion here:
+ http://lists.w3.org/Archives/Public/public-web-perf/2012Apr/0004.html
+
+ Reviewed by James Robinson.
+
+ * src/PageWidgetDelegate.cpp:
+ (WebKit::PageWidgetDelegate::animate):
+ * src/WebViewImpl.cpp:
+ (WebKit::WebViewImpl::updateAnimations):
+
2012-04-27 Mark Pilgrim <pilgrim@chromium.org>
[Chromium] Call lowMemoryUsageMB directly
FrameView* view = mainFrameView(page);
if (!view)
return;
- double timeShift = currentTime() - monotonicallyIncreasingTime();
- view->serviceScriptedAnimations(convertSecondsToDOMTimeStamp(monotonicFrameBeginTime + timeShift));
+ view->serviceScriptedAnimations(monotonicFrameBeginTime);
#endif
}
#if ENABLE(REQUEST_ANIMATION_FRAME)
TRACE_EVENT("WebViewImpl::updateAnimations", this, 0);
- WebFrameImpl* webframe = mainFrameImpl();
- if (!webframe)
- return;
- FrameView* view = webframe->frameView();
- if (!view)
- return;
-
// Create synthetic wheel events as necessary for fling.
if (m_gestureAnimation) {
if (m_gestureAnimation->animate(monotonicFrameBeginTime))
m_gestureAnimation.clear();
}
+ if (!m_page)
+ return;
+
PageWidgetDelegate::animate(m_page.get(), monotonicFrameBeginTime);
#endif
}