<!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>[37725] trunk/WebKit/gtk</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/37725">37725</a></dd>
<dt>Author</dt> <dd>alp@webkit.org</dd>
<dt>Date</dt> <dd>2008-10-20 08:39:59 -0700 (Mon, 20 Oct 2008)</dd>
</dl>

<h3>Log Message</h3>
<pre>2008-10-20  Alp Toker  &lt;alp@nuanti.com&gt;

        Reviewed by Dave Hyatt.

        https://bugs.webkit.org/show_bug.cgi?id=21303
        [GTK] Scrolling glitches

        Implement a buffering scheme to avoid full repaints when scrolling
        views or subframes significantly improving scrolling performance.

        Improve rendering performance by coalescing large numbers of small
        repaints.

        Also fixes long-running issues with scrollbar positioning and frame
        invalidation.

        Rendering in the GTK+ port should be more similar to other ports after
        these changes.

        * WebCoreSupport/ChromeClientGtk.cpp:
        (WebKit::ChromeClient::repaint):
        (WebKit::ChromeClient::scroll):
        * WebCoreSupport/FrameLoaderClientGtk.cpp:
        (WebKit::FrameLoaderClient::forceLayout):
        * webkit/webkitwebview.cpp:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebKitgtkChangeLog">trunk/WebKit/gtk/ChangeLog</a></li>
<li><a href="#trunkWebKitgtkWebCoreSupportChromeClientGtkcpp">trunk/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp</a></li>
<li><a href="#trunkWebKitgtkWebCoreSupportFrameLoaderClientGtkcpp">trunk/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp</a></li>
<li><a href="#trunkWebKitgtkwebkitwebkitwebviewcpp">trunk/WebKit/gtk/webkit/webkitwebview.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebKitgtkChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebKit/gtk/ChangeLog (37724 => 37725)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKit/gtk/ChangeLog        2008-10-20 15:29:04 UTC (rev 37724)
+++ trunk/WebKit/gtk/ChangeLog        2008-10-20 15:39:59 UTC (rev 37725)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2008-10-20  Alp Toker  &lt;alp@nuanti.com&gt;
+
+        Reviewed by Dave Hyatt.
+
+        https://bugs.webkit.org/show_bug.cgi?id=21303
+        [GTK] Scrolling glitches
+
+        Implement a buffering scheme to avoid full repaints when scrolling
+        views or subframes significantly improving scrolling performance.
+
+        Improve rendering performance by coalescing large numbers of small
+        repaints.
+
+        Also fixes long-running issues with scrollbar positioning and frame
+        invalidation.
+
+        Rendering in the GTK+ port should be more similar to other ports after
+        these changes.
+
+        * WebCoreSupport/ChromeClientGtk.cpp:
+        (WebKit::ChromeClient::repaint):
+        (WebKit::ChromeClient::scroll):
+        * WebCoreSupport/FrameLoaderClientGtk.cpp:
+        (WebKit::FrameLoaderClient::forceLayout):
+        * webkit/webkitwebview.cpp:
+
</ins><span class="cx"> 2008-10-17  Luke Kenneth Casson Leighton  &lt;lkcl@lkcl.net&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Mark Rowe. Landed by Jan Alonzo.
</span></span></pre></div>
<a id="trunkWebKitgtkWebCoreSupportChromeClientGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp (37724 => 37725)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp        2008-10-20 15:29:04 UTC (rev 37724)
+++ trunk/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp        2008-10-20 15:39:59 UTC (rev 37725)
</span><span class="lines">@@ -1,6 +1,7 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2007 Holger Hans Peter Freyther
</span><span class="cx">  * Copyright (C) 2007, 2008 Christian Dywan &lt;christian@imendio.com&gt;
</span><ins>+ * Copyright (C) 2008 Nuanti Ltd.
</ins><span class="cx">  *
</span><span class="cx">  *  This library is free software; you can redistribute it and/or
</span><span class="cx">  *  modify it under the terms of the GNU Lesser General Public
</span><span class="lines">@@ -259,25 +260,51 @@
</span><span class="cx">     return IntRect();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ChromeClient::repaint(const IntRect&amp; windowRect, bool, bool immediate, bool repaintContentOnly)
</del><ins>+void ChromeClient::repaint(const IntRect&amp; windowRect, bool contentChanged, bool immediate, bool repaintContentOnly)
</ins><span class="cx"> {
</span><del>-    if (!m_webView || repaintContentOnly)
</del><ins>+    if (!m_webView)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     GdkRectangle rect = windowRect;
</span><span class="cx">     GdkWindow* window = GTK_WIDGET(m_webView)-&gt;window;
</span><span class="cx"> 
</span><span class="cx">     if (window) {
</span><del>-        // No double buffer.  Just always assume we need to invalidate.
-        gdk_window_invalidate_rect(window, &amp;rect, true);
-        if (immediate)
-            gdk_window_process_updates(window, true);
</del><ins>+        if (contentChanged)
+            gdk_window_invalidate_rect(window, &amp;rect, FALSE);
+        // We don't currently do immediate updates since they delay other UI elements.
+        //if (immediate)
+        //    gdk_window_process_updates(window, FALSE);
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ChromeClient::scroll(const IntSize&amp; delta, const IntRect&amp; scrollViewRect, const IntRect&amp; clipRect)
</del><ins>+void ChromeClient::scroll(const IntSize&amp; delta, const IntRect&amp; rectToScroll, const IntRect&amp; clipRect)
</ins><span class="cx"> {
</span><del>-    notImplemented();
</del><ins>+    if (!m_webView)
+        return;
+
+    GdkWindow* window = GTK_WIDGET(m_webView)-&gt;window;
+    if (!window)
+        return;
+
+    GdkRectangle area = clipRect;
+    GdkRectangle moveRect;
+
+    GdkRectangle sourceRect = area;
+    sourceRect.x -= delta.width();
+    sourceRect.y -= delta.height();
+
+    GdkRegion* invalidRegion = gdk_region_rectangle(&amp;area);
+
+    if (gdk_rectangle_intersect(&amp;area, &amp;sourceRect, &amp;moveRect)) {
+        GdkRegion* moveRegion = gdk_region_rectangle(&amp;moveRect);
+        gdk_window_move_region(window, moveRegion, delta.width(), delta.height());
+        gdk_region_offset(moveRegion, delta.width(), delta.height());
+        gdk_region_subtract(invalidRegion, moveRegion);
+        gdk_region_destroy(moveRegion);
+    }
+
+    gdk_window_invalidate_region(window, invalidRegion, FALSE);
+    gdk_region_destroy(invalidRegion);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> IntRect ChromeClient::windowToScreen(const IntRect&amp; rect) const
</span></span></pre></div>
<a id="trunkWebKitgtkWebCoreSupportFrameLoaderClientGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp (37724 => 37725)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp        2008-10-20 15:29:04 UTC (rev 37724)
+++ trunk/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp        2008-10-20 15:39:59 UTC (rev 37725)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- *  Copyright (C) 2007 Alp Toker &lt;alp@atoker.com&gt;
</del><ins>+ *  Copyright (C) 2007, 2008 Alp Toker &lt;alp@atoker.com&gt;
</ins><span class="cx">  *  Copyright (C) 2007, 2008 Holger Hans Peter Freyther
</span><span class="cx">  *  Copyright (C) 2007 Christian Dywan &lt;christian@twotoasts.de&gt;
</span><span class="cx">  *  Copyright (C) 2008 Collabora Ltd.  All rights reserved.
</span><span class="lines">@@ -436,7 +436,7 @@
</span><span class="cx"> 
</span><span class="cx"> void FrameLoaderClient::forceLayout()
</span><span class="cx"> {
</span><del>-    notImplemented();
</del><ins>+    core(m_frame)-&gt;forceLayout(true);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void FrameLoaderClient::forceLayoutForNonHTML()
</span></span></pre></div>
<a id="trunkWebKitgtkwebkitwebkitwebviewcpp"></a>
<div class="modfile"><h4>Modified: trunk/WebKit/gtk/webkit/webkitwebview.cpp (37724 => 37725)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKit/gtk/webkit/webkitwebview.cpp        2008-10-20 15:29:04 UTC (rev 37724)
+++ trunk/WebKit/gtk/webkit/webkitwebview.cpp        2008-10-20 15:39:59 UTC (rev 37725)
</span><span class="lines">@@ -2,7 +2,7 @@
</span><span class="cx">  *  Copyright (C) 2007 Holger Hans Peter Freyther
</span><span class="cx">  *  Copyright (C) 2007, 2008 Christian Dywan &lt;christian@imendio.com&gt;
</span><span class="cx">  *  Copyright (C) 2007 Xan Lopez &lt;xan@gnome.org&gt;
</span><del>- *  Copyright (C) 2007 Alp Toker &lt;alp@atoker.com&gt;
</del><ins>+ *  Copyright (C) 2007, 2008 Alp Toker &lt;alp@atoker.com&gt;
</ins><span class="cx">  *  Copyright (C) 2008 Jan Alonzo &lt;jmalonzo@unpluggable.com&gt;
</span><span class="cx">  *  Copyright (C) 2008 Nuanti Ltd.
</span><span class="cx">  *  Copyright (C) 2008 Collabora Ltd.
</span><span class="lines">@@ -58,6 +58,7 @@
</span><span class="cx"> #include &quot;PlatformWheelEvent.h&quot;
</span><span class="cx"> #include &quot;Scrollbar.h&quot;
</span><span class="cx"> #include &quot;SubstituteData.h&quot;
</span><ins>+#include &lt;wtf/GOwnPtr.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> #include &lt;gdk/gdkkeysyms.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -276,30 +277,65 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static bool shouldCoalesce(GdkRectangle rect, GdkRectangle* rects, int count)
+{
+    const int cRectThreshold = 10;
+    const float cWastedSpaceThreshold = 0.75f;
+    bool useUnionedRect = (count &lt;= 1) || (count &gt; cRectThreshold);
+    if (!useUnionedRect) {
+        // Attempt to guess whether or not we should use the unioned rect or the individual rects.
+        // We do this by computing the percentage of &quot;wasted space&quot; in the union.  If that wasted space
+        // is too large, then we will do individual rect painting instead.
+        float unionPixels = (rect.width * rect.height);
+        float singlePixels = 0;
+        for (int i = 0; i &lt; count; ++i)
+            singlePixels += rects[i].width * rects[i].height;
+        float wastedSpace = 1 - (singlePixels / unionPixels);
+        if (wastedSpace &lt;= cWastedSpaceThreshold)
+            useUnionedRect = true;
+    }
+    return useUnionedRect;
+}
+
</ins><span class="cx"> static gboolean webkit_web_view_expose_event(GtkWidget* widget, GdkEventExpose* event)
</span><span class="cx"> {
</span><span class="cx">     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
</span><span class="cx">     WebKitWebViewPrivate* priv = webView-&gt;priv;
</span><span class="cx"> 
</span><span class="cx">     Frame* frame = core(webView)-&gt;mainFrame();
</span><del>-    GdkRectangle clip;
-    gdk_region_get_clipbox(event-&gt;region, &amp;clip);
-    cairo_t* cr = gdk_cairo_create(event-&gt;window);
-    GraphicsContext ctx(cr);
-    ctx.setGdkExposeEvent(event);
</del><span class="cx">     if (frame-&gt;contentRenderer() &amp;&amp; frame-&gt;view()) {
</span><span class="cx">         frame-&gt;view()-&gt;layoutIfNeededRecursive();
</span><span class="cx"> 
</span><del>-        if (priv-&gt;transparent) {
-            cairo_save(cr);
-            cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
-            cairo_paint(cr);
-            cairo_restore(cr);
</del><ins>+        cairo_t* cr = gdk_cairo_create(event-&gt;window);
+        GraphicsContext ctx(cr);
+        cairo_destroy(cr);
+        ctx.setGdkExposeEvent(event);
+
+        GOwnPtr&lt;GdkRectangle&gt; rects;
+        int rectCount;
+        gdk_region_get_rectangles(event-&gt;region, &amp;rects.outPtr(), &amp;rectCount);
+
+        // Avoid recursing into the render tree excessively
+        bool coalesce = shouldCoalesce(event-&gt;area, rects.get(), rectCount);
+
+        if (coalesce) {
+            IntRect rect = event-&gt;area;
+            ctx.clip(rect);
+            if (priv-&gt;transparent)
+                ctx.clearRect(rect);
+            frame-&gt;view()-&gt;paint(&amp;ctx, rect);
+        } else {
+            for (int i = 0; i &lt; rectCount; i++) {
+                IntRect rect = rects.get()[i];
+                ctx.save();
+                ctx.clip(rect);
+                if (priv-&gt;transparent)
+                    ctx.clearRect(rect);
+                frame-&gt;view()-&gt;paint(&amp;ctx, rect);
+                ctx.restore();
+            }
</ins><span class="cx">         }
</span><del>-
-        frame-&gt;view()-&gt;paint(&amp;ctx, clip);
</del><span class="cx">     }
</span><del>-    cairo_destroy(cr);
</del><span class="cx"> 
</span><span class="cx">     return FALSE;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>