<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[191854] trunk/Source/WebKit2</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/191854">191854</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2015-11-01 01:31:16 -0700 (Sun, 01 Nov 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>[GTK] Use a RunLoop::Timer to schedule rendering frames in accelerated compositing mode
https://bugs.webkit.org/show_bug.cgi?id=150756
Reviewed by Darin Adler.
Use a RunLoop::Timer instead of a GMainLoopSource for the
accelerated compositing render loop to improve the performance,
since RunLoop::Timer uses a persistent source.
All the logic to schedule rames has been moved to a helper
internal class RenderFrameScheduler.
* WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp:
(WebKit::LayerTreeHostGtk::RenderFrameScheduler::RenderFrameScheduler):
(WebKit::LayerTreeHostGtk::RenderFrameScheduler::~RenderFrameScheduler):
(WebKit::LayerTreeHostGtk::RenderFrameScheduler::start):
(WebKit::LayerTreeHostGtk::RenderFrameScheduler::stop):
(WebKit::shouldSkipNextFrameBecauseOfContinousImmediateFlushes):
(WebKit::LayerTreeHostGtk::RenderFrameScheduler::nextFrame):
(WebKit::LayerTreeHostGtk::RenderFrameScheduler::renderFrame):
(WebKit::LayerTreeHostGtk::LayerTreeHostGtk):
(WebKit::LayerTreeHostGtk::renderFrame):
(WebKit::LayerTreeHostGtk::scheduleLayerFlush):
(WebKit::LayerTreeHostGtk::cancelPendingLayerFlush):
(WebKit::LayerTreeHostGtk::layerFlushTimerFired): Deleted.
* WebProcess/WebPage/gtk/LayerTreeHostGtk.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPagegtkLayerTreeHostGtkcpp">trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPagegtkLayerTreeHostGtkh">trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (191853 => 191854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-11-01 08:26:46 UTC (rev 191853)
+++ trunk/Source/WebKit2/ChangeLog        2015-11-01 08:31:16 UTC (rev 191854)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2015-11-01 Carlos Garcia Campos <cgarcia@igalia.com>
+
+ [GTK] Use a RunLoop::Timer to schedule rendering frames in accelerated compositing mode
+ https://bugs.webkit.org/show_bug.cgi?id=150756
+
+ Reviewed by Darin Adler.
+
+ Use a RunLoop::Timer instead of a GMainLoopSource for the
+ accelerated compositing render loop to improve the performance,
+ since RunLoop::Timer uses a persistent source.
+ All the logic to schedule rames has been moved to a helper
+ internal class RenderFrameScheduler.
+
+ * WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp:
+ (WebKit::LayerTreeHostGtk::RenderFrameScheduler::RenderFrameScheduler):
+ (WebKit::LayerTreeHostGtk::RenderFrameScheduler::~RenderFrameScheduler):
+ (WebKit::LayerTreeHostGtk::RenderFrameScheduler::start):
+ (WebKit::LayerTreeHostGtk::RenderFrameScheduler::stop):
+ (WebKit::shouldSkipNextFrameBecauseOfContinousImmediateFlushes):
+ (WebKit::LayerTreeHostGtk::RenderFrameScheduler::nextFrame):
+ (WebKit::LayerTreeHostGtk::RenderFrameScheduler::renderFrame):
+ (WebKit::LayerTreeHostGtk::LayerTreeHostGtk):
+ (WebKit::LayerTreeHostGtk::renderFrame):
+ (WebKit::LayerTreeHostGtk::scheduleLayerFlush):
+ (WebKit::LayerTreeHostGtk::cancelPendingLayerFlush):
+ (WebKit::LayerTreeHostGtk::layerFlushTimerFired): Deleted.
+ * WebProcess/WebPage/gtk/LayerTreeHostGtk.h:
+
</ins><span class="cx"> 2015-10-31 Andreas Kling <akling@apple.com>
</span><span class="cx">
</span><span class="cx"> Add a debug overlay with information about web process resource usage.
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPagegtkLayerTreeHostGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp (191853 => 191854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp        2015-11-01 08:26:46 UTC (rev 191853)
+++ trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp        2015-11-01 08:31:16 UTC (rev 191854)
</span><span class="lines">@@ -61,6 +61,71 @@
</span><span class="cx">
</span><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><ins>+LayerTreeHostGtk::RenderFrameScheduler::RenderFrameScheduler(std::function<bool()> renderer)
+ : m_renderer(WTF::move(renderer))
+ , m_timer(RunLoop::main(), this, &LayerTreeHostGtk::RenderFrameScheduler::renderFrame)
+{
+ // We use a RunLoop timer because otherwise GTK+ event handling during dragging can starve WebCore timers, which have a lower priority.
+ // Use a higher priority than WebCore timers.
+ m_timer.setPriority(GDK_PRIORITY_REDRAW - 1);
+}
+
+LayerTreeHostGtk::RenderFrameScheduler::~RenderFrameScheduler()
+{
+}
+
+void LayerTreeHostGtk::RenderFrameScheduler::start()
+{
+ if (m_timer.isActive())
+ return;
+ m_fireTime = 0;
+ nextFrame();
+}
+
+void LayerTreeHostGtk::RenderFrameScheduler::stop()
+{
+ m_timer.stop();
+}
+
+static inline bool shouldSkipNextFrameBecauseOfContinousImmediateFlushes(double current, double lastImmediateFlushTime)
+{
+ // 100ms is about a perceptable delay in UI, so when scheduling layer flushes immediately for more than 100ms,
+ // we skip the next frame to ensure pending timers have a change to be fired.
+ static const double maxDurationOfImmediateFlushes = 0.100;
+ if (!lastImmediateFlushTime)
+ return false;
+ return lastImmediateFlushTime + maxDurationOfImmediateFlushes < current;
+}
+
+void LayerTreeHostGtk::RenderFrameScheduler::nextFrame()
+{
+ static const double targetFramerate = 1 / 60.0;
+ // When rendering layers takes more time than the target delay (0.016), we end up scheduling layer flushes
+ // immediately. Since the layer flush timer has a higher priority than WebCore timers, these are never
+ // fired while we keep scheduling layer flushes immediately.
+ double current = monotonicallyIncreasingTime();
+ double timeToNextFlush = std::max(targetFramerate - (current - m_fireTime), 0.0);
+ if (timeToNextFlush)
+ m_lastImmediateFlushTime = 0;
+ else if (!m_lastImmediateFlushTime)
+ m_lastImmediateFlushTime = current;
+
+ if (shouldSkipNextFrameBecauseOfContinousImmediateFlushes(current, m_lastImmediateFlushTime)) {
+ timeToNextFlush = targetFramerate;
+ m_lastImmediateFlushTime = 0;
+ }
+
+ m_timer.startOneShot(timeToNextFlush);
+}
+
+void LayerTreeHostGtk::RenderFrameScheduler::renderFrame()
+{
+ m_fireTime = monotonicallyIncreasingTime();
+ if (!m_renderer() || m_timer.isActive())
+ return;
+ nextFrame();
+}
+
</ins><span class="cx"> PassRefPtr<LayerTreeHostGtk> LayerTreeHostGtk::create(WebPage* webPage)
</span><span class="cx"> {
</span><span class="cx"> RefPtr<LayerTreeHostGtk> host = adoptRef(new LayerTreeHostGtk(webPage));
</span><span class="lines">@@ -72,9 +137,9 @@
</span><span class="cx"> : LayerTreeHost(webPage)
</span><span class="cx"> , m_isValid(true)
</span><span class="cx"> , m_notifyAfterScheduledLayerFlush(false)
</span><del>- , m_lastImmediateFlushTime(0)
</del><span class="cx"> , m_layerFlushSchedulingEnabled(true)
</span><span class="cx"> , m_viewOverlayRootLayer(nullptr)
</span><ins>+ , m_renderFrameScheduler(std::bind(&LayerTreeHostGtk::renderFrame, this))
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -237,44 +302,10 @@
</span><span class="cx"> return m_webPage->pageScaleFactor();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static inline bool shouldSkipNextFrameBecauseOfContinousImmediateFlushes(double current, double lastImmediateFlushTime)
</del><ins>+bool LayerTreeHostGtk::renderFrame()
</ins><span class="cx"> {
</span><del>- // 100ms is about a perceptable delay in UI, so when scheduling layer flushes immediately for more than 100ms,
- // we skip the next frame to ensure pending timers have a change to be fired.
- static const double maxDurationOfImmediateFlushes = 0.100;
- if (!lastImmediateFlushTime)
- return false;
- return lastImmediateFlushTime + maxDurationOfImmediateFlushes < current;
-}
-
-// Use a higher priority than WebCore timers.
-static const int layerFlushTimerPriority = GDK_PRIORITY_REDRAW - 1;
-
-void LayerTreeHostGtk::layerFlushTimerFired()
-{
- double fireTime = monotonicallyIncreasingTime();
</del><span class="cx"> flushAndRenderLayers();
</span><del>- if (m_layerFlushTimerCallback.isScheduled() || !downcast<GraphicsLayerTextureMapper>(*m_rootLayer).layer().descendantsOrSelfHaveRunningAnimations())
- return;
-
- static const double targetFramerate = 1 / 60.0;
- // When rendering layers takes more time than the target delay (0.016), we end up scheduling layer flushes
- // immediately. Since the layer flush timer has a higher priority than WebCore timers, these are never
- // fired while we keep scheduling layer flushes immediately.
- double current = monotonicallyIncreasingTime();
- double timeToNextFlush = std::max(targetFramerate - (current - fireTime), 0.0);
- if (timeToNextFlush)
- m_lastImmediateFlushTime = 0;
- else if (!m_lastImmediateFlushTime)
- m_lastImmediateFlushTime = current;
-
- if (shouldSkipNextFrameBecauseOfContinousImmediateFlushes(current, m_lastImmediateFlushTime)) {
- timeToNextFlush = targetFramerate;
- m_lastImmediateFlushTime = 0;
- }
-
- m_layerFlushTimerCallback.scheduleAfterDelay("[WebKit] layerFlushTimer", std::bind(&LayerTreeHostGtk::layerFlushTimerFired, this),
- std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(timeToNextFlush)), layerFlushTimerPriority);
</del><ins>+ return downcast<GraphicsLayerTextureMapper>(*m_rootLayer).layer().descendantsOrSelfHaveRunningAnimations();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool LayerTreeHostGtk::flushPendingLayerChanges()
</span><span class="lines">@@ -348,9 +379,7 @@
</span><span class="cx"> if (!m_layerFlushSchedulingEnabled || !m_textureMapper)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- // We use a GLib timer because otherwise GTK+ event handling during dragging can starve WebCore timers, which have a lower priority.
- if (!m_layerFlushTimerCallback.isScheduled())
- m_layerFlushTimerCallback.schedule("[WebKit] layerFlushTimer", std::bind(&LayerTreeHostGtk::layerFlushTimerFired, this), layerFlushTimerPriority);
</del><ins>+ m_renderFrameScheduler.start();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void LayerTreeHostGtk::setLayerFlushSchedulingEnabled(bool layerFlushingEnabled)
</span><span class="lines">@@ -375,7 +404,7 @@
</span><span class="cx">
</span><span class="cx"> void LayerTreeHostGtk::cancelPendingLayerFlush()
</span><span class="cx"> {
</span><del>- m_layerFlushTimerCallback.cancel();
</del><ins>+ m_renderFrameScheduler.stop();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void LayerTreeHostGtk::setViewOverlayRootLayer(WebCore::GraphicsLayer* viewOverlayRootLayer)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPagegtkLayerTreeHostGtkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.h (191853 => 191854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.h        2015-11-01 08:26:46 UTC (rev 191853)
+++ trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.h        2015-11-01 08:31:16 UTC (rev 191854)
</span><span class="lines">@@ -35,7 +35,7 @@
</span><span class="cx"> #include <WebCore/GLContext.h>
</span><span class="cx"> #include <WebCore/GraphicsLayerClient.h>
</span><span class="cx"> #include <WebCore/TransformationMatrix.h>
</span><del>-#include <wtf/glib/GMainLoopSource.h>
</del><ins>+#include <wtf/RunLoop.h>
</ins><span class="cx">
</span><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><span class="lines">@@ -65,6 +65,25 @@
</span><span class="cx"> virtual void setNativeSurfaceHandleForCompositing(uint64_t) override;
</span><span class="cx">
</span><span class="cx"> private:
</span><ins>+
+ class RenderFrameScheduler {
+ public:
+ RenderFrameScheduler(std::function<bool()>);
+ ~RenderFrameScheduler();
+
+ void start();
+ void stop();
+
+ private:
+ void renderFrame();
+ void nextFrame();
+
+ std::function<bool()> m_renderer;
+ RunLoop::Timer<RenderFrameScheduler> m_timer;
+ double m_fireTime { 0 };
+ double m_lastImmediateFlushTime { 0 };
+ };
+
</ins><span class="cx"> // LayerTreeHost
</span><span class="cx"> virtual const LayerTreeContext& layerTreeContext() override;
</span><span class="cx"> virtual void setShouldNotifyAfterNextScheduledLayerFlush(bool) override;
</span><span class="lines">@@ -87,7 +106,7 @@
</span><span class="cx"> void flushAndRenderLayers();
</span><span class="cx"> void cancelPendingLayerFlush();
</span><span class="cx">
</span><del>- void layerFlushTimerFired();
</del><ins>+ bool renderFrame();
</ins><span class="cx">
</span><span class="cx"> bool makeContextCurrent();
</span><span class="cx">
</span><span class="lines">@@ -100,9 +119,9 @@
</span><span class="cx"> std::unique_ptr<WebCore::GLContext> m_context;
</span><span class="cx"> double m_lastImmediateFlushTime;
</span><span class="cx"> bool m_layerFlushSchedulingEnabled;
</span><del>- GMainLoopSource m_layerFlushTimerCallback;
</del><span class="cx"> WebCore::GraphicsLayer* m_viewOverlayRootLayer;
</span><span class="cx"> WebCore::TransformationMatrix m_scaleMatrix;
</span><ins>+ RenderFrameScheduler m_renderFrameScheduler;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace WebKit
</span></span></pre>
</div>
</div>
</body>
</html>