Skip to content

Instantly share code, notes, and snippets.

@balazs
Created April 1, 2013 20:15
Show Gist options
  • Save balazs/5287393 to your computer and use it in GitHub Desktop.
Save balazs/5287393 to your computer and use it in GitHub Desktop.
diff --git a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp
index eddb612..63fc33b 100644
--- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp
+++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp
@@ -83,7 +83,7 @@ CoordinatedLayerTreeHost::CoordinatedLayerTreeHost(WebPage* webPage)
, m_isValid(true)
, m_isPurging(false)
, m_isFlushingLayerChanges(false)
- , m_waitingForUIProcess(true)
+ , m_numFramesReadyForUIProcess(0)
, m_isSuspended(false)
, m_shouldSyncFrame(false)
, m_didInitializeRootCompositingLayer(false)
@@ -283,9 +283,15 @@ void CoordinatedLayerTreeHost::setPageOverlayOpacity(PageOverlay*, float value)
scheduleLayerFlush();
}
+bool CoordinatedLayerTreeHost::shouldFlushLayerChanges() const
+{
+ // We allow one frame to be prerendered before the UI process ask for it.
+ return m_numFramesReadyForUIProcess < 2;
+}
+
bool CoordinatedLayerTreeHost::flushPendingLayerChanges()
{
- if (m_waitingForUIProcess)
+ if (!shouldFlushLayerChanges())
return false;
TemporaryChange<bool> protector(m_isFlushingLayerChanges, true);
@@ -305,21 +311,13 @@ bool CoordinatedLayerTreeHost::flushPendingLayerChanges()
deleteCompositingLayers();
- if (m_shouldSyncFrame) {
- didSync = true;
-
- m_state.contentsSize = roundedIntSize(m_nonCompositedContentLayer->size());
- m_state.coveredRect = toCoordinatedGraphicsLayer(m_nonCompositedContentLayer.get())->coverRect();
- m_state.scrollPosition = m_visibleContentsRect.location();
-
- m_webPage->send(Messages::CoordinatedLayerTreeHostProxy::CommitCoordinatedGraphicsState(m_state));
+ didSync = m_shouldSyncFrame;
- m_state.layersToUpdate.clear();
- m_state.imagesToUpdate.clear();
-
- m_waitingForUIProcess = true;
- m_shouldSyncFrame = false;
- } else
+ if (m_shouldSyncFrame) {
+ ++m_numFramesReadyForUIProcess;
+ if (m_numFramesReadyForUIProcess == 1)
+ commitFrame();
+ } else if (!m_numFramesReadyForUIProcess)
unlockAnimations();
if (m_forceRepaintAsyncCallbackID) {
@@ -330,6 +328,23 @@ bool CoordinatedLayerTreeHost::flushPendingLayerChanges()
return didSync;
}
+void CoordinatedLayerTreeHost::commitFrame()
+{
+ m_state.contentsSize = roundedIntSize(m_nonCompositedContentLayer->size());
+ m_state.coveredRect = toCoordinatedGraphicsLayer(m_nonCompositedContentLayer.get())->coverRect();
+ m_state.scrollPosition = m_visibleContentsRect.location();
+
+ m_webPage->send(Messages::CoordinatedLayerTreeHostProxy::CommitCoordinatedGraphicsState(m_state));
+
+ m_state.layersToUpdate.clear();
+ m_state.imagesToUpdate.clear();
+
+ m_shouldSyncFrame = false;
+
+ for (size_t i = 0; i < m_updateAtlases.size(); ++i)
+ m_updateAtlases[i]->didCommitBuffers();
+}
+
void CoordinatedLayerTreeHost::createCompositingLayers()
{
if (m_layersToCreate.isEmpty())
@@ -481,12 +496,14 @@ void CoordinatedLayerTreeHost::unlockAnimations()
void CoordinatedLayerTreeHost::performScheduledLayerFlush()
{
- if (m_isSuspended || m_waitingForUIProcess)
+ if (m_isSuspended || !shouldFlushLayerChanges())
return;
// We lock the animations while performing layout, to avoid flickers caused by animations continuing in the UI process while
// the web process layout wants to cancel them.
- lockAnimations();
+ if (!m_numFramesReadyForUIProcess)
+ lockAnimations();
+
syncDisplayState();
// We can unlock the animations before flushing if there are no visible changes, for example if there are content updates
@@ -730,10 +747,17 @@ void CoordinatedLayerTreeHost::animationFrameReady()
void CoordinatedLayerTreeHost::renderNextFrame()
{
- m_waitingForUIProcess = false;
- scheduleLayerFlush();
for (unsigned i = 0; i < m_updateAtlases.size(); ++i)
m_updateAtlases[i]->didSwapBuffers();
+
+ bool hasPrerenderedFrame = m_numFramesReadyForUIProcess > 1;
+ m_numFramesReadyForUIProcess = 0;
+ if (hasPrerenderedFrame && m_shouldSyncFrame) {
+ commitFrame();
+ ++m_numFramesReadyForUIProcess;
+ }
+
+ scheduleLayerFlush();
}
void CoordinatedLayerTreeHost::purgeBackingStores()
diff --git a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h
index 19d07f9..24416e3 100644
--- a/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h
+++ b/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h
@@ -144,6 +144,8 @@ private:
void syncDisplayState();
void lockAnimations();
void unlockAnimations();
+ void commitFrame();
+ bool shouldFlushLayerChanges() const;
void layerFlushTimerFired(WebCore::Timer<CoordinatedLayerTreeHost>*);
@@ -193,8 +195,9 @@ private:
bool m_isPurging;
bool m_isFlushingLayerChanges;
- bool m_waitingForUIProcess;
+ unsigned m_numFramesReadyForUIProcess;
bool m_isSuspended;
+
WebCore::FloatRect m_visibleContentsRect;
LayerTreeContext m_layerTreeContext;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment