Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
2011-03-11 Anders Carlsson <andersca@apple.com>
        Reviewed by Dan Bernstein.

        Don't paint more than 60 times per second
        https://bugs.webkit.org/show_bug.cgi?id=56206
        <rdar://problem/9085989>

        * WebProcess/WebPage/DrawingAreaImpl.cpp:
        (WebKit::DrawingAreaImpl::DrawingAreaImpl):
        Initialize m_lastDisplayTime to 0. Change the display timer to call displayTimerFired.

        (WebKit::DrawingAreaImpl::didUpdate):
        Call displayTimerFired instead of display.

        (WebKit::DrawingAreaImpl::displayTimerFired):
        If we're asked to paint again less than 1/60th of a second after we've already painted,
        defer painting.

        (WebKit::DrawingAreaImpl::display):
        Update m_lastDisplayTime.


Canonical link: https://commits.webkit.org/70760@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@80875 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Anders Carlsson committed Mar 11, 2011
1 parent 8027933 commit 1a0c4aa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
22 changes: 22 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -1,3 +1,25 @@
2011-03-11 Anders Carlsson <andersca@apple.com>

Reviewed by Dan Bernstein.

Don't paint more than 60 times per second
https://bugs.webkit.org/show_bug.cgi?id=56206
<rdar://problem/9085989>

* WebProcess/WebPage/DrawingAreaImpl.cpp:
(WebKit::DrawingAreaImpl::DrawingAreaImpl):
Initialize m_lastDisplayTime to 0. Change the display timer to call displayTimerFired.

(WebKit::DrawingAreaImpl::didUpdate):
Call displayTimerFired instead of display.

(WebKit::DrawingAreaImpl::displayTimerFired):
If we're asked to paint again less than 1/60th of a second after we've already painted,
defer painting.

(WebKit::DrawingAreaImpl::display):
Update m_lastDisplayTime.

2011-03-11 Mark Rowe <mrowe@apple.com>

Reviewed by Alice Liu.
Expand Down
24 changes: 21 additions & 3 deletions Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp
Expand Up @@ -64,7 +64,8 @@ DrawingAreaImpl::DrawingAreaImpl(WebPage* webPage, const WebPageCreationParamete
, m_isWaitingForDidUpdate(false)
, m_isPaintingSuspended(!parameters.isVisible)
, m_alwaysUseCompositing(false)
, m_displayTimer(WebProcess::shared().runLoop(), this, &DrawingAreaImpl::display)
, m_lastDisplayTime(0)
, m_displayTimer(WebProcess::shared().runLoop(), this, &DrawingAreaImpl::displayTimerFired)
, m_exitCompositingTimer(WebProcess::shared().runLoop(), this, &DrawingAreaImpl::exitAcceleratedCompositingMode)
{
if (webPage->corePage()->settings()->acceleratedDrawingEnabled())
Expand Down Expand Up @@ -327,8 +328,8 @@ void DrawingAreaImpl::didUpdate()

m_isWaitingForDidUpdate = false;

// Display if needed.
display();
// Display if needed. We call displayTimerFired here since it will throttle updates to 60fps.
displayTimerFired();
}

void DrawingAreaImpl::suspendPainting()
Expand Down Expand Up @@ -428,6 +429,21 @@ void DrawingAreaImpl::scheduleDisplay()
m_displayTimer.startOneShot(0);
}

void DrawingAreaImpl::displayTimerFired()
{
static const double minimumFrameInterval = 1.0 / 60.0;

double timeSinceLastDisplay = currentTime() - m_lastDisplayTime;
double timeUntilNextDisplay = minimumFrameInterval - timeSinceLastDisplay;

if (timeUntilNextDisplay > 0) {
m_displayTimer.startOneShot(timeUntilNextDisplay);
return;
}

display();
}

void DrawingAreaImpl::display()
{
ASSERT(!m_layerTreeHost);
Expand Down Expand Up @@ -534,6 +550,8 @@ void DrawingAreaImpl::display(UpdateInfo& updateInfo)
// Layout can trigger more calls to setNeedsDisplay and we don't want to process them
// until the UI process has painted the update, so we stop the timer here.
m_displayTimer.stop();

m_lastDisplayTime = currentTime();
}


Expand Down
3 changes: 3 additions & 0 deletions Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.h
Expand Up @@ -72,6 +72,7 @@ class DrawingAreaImpl : public DrawingArea {
void exitAcceleratedCompositingMode();

void scheduleDisplay();
void displayTimerFired();
void display();
void display(UpdateInfo&);

Expand All @@ -97,6 +98,8 @@ class DrawingAreaImpl : public DrawingArea {
bool m_isPaintingSuspended;
bool m_alwaysUseCompositing;

double m_lastDisplayTime;

RunLoop::Timer<DrawingAreaImpl> m_displayTimer;
RunLoop::Timer<DrawingAreaImpl> m_exitCompositingTimer;

Expand Down

0 comments on commit 1a0c4aa

Please sign in to comment.