Title: [115696] trunk/Source/WebKit2
Revision
115696
Author
yael.aha...@nokia.com
Date
2012-04-30 18:10:35 -0700 (Mon, 30 Apr 2012)

Log Message

[Qt][WK2] Fixed layers are shaking when zoom level is not 1.0 due to a rounding error.
https://bugs.webkit.org/show_bug.cgi?id=84306

Reviewed by Noam Rosenthal.

When zooming, we need to be careful about how to convert the visible rect from float to int.
Using toAlignedRect can produce inconsistent width and height when we are scrolling.
This patch carefully modifies each piece of the visible rect, to avoid such rounding errors.
In addition, the TransformationMatrix we use for painting, needs to be adjusted for the same rounding error.

* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::visibleContentsRect):
(QQuickWebViewFlickablePrivate::_q_contentViewportChanged):
* UIProcess/DrawingAreaProxy.h:
(WebCore):
(WebKit::DrawingAreaProxy::setVisibleContentsRect):
* UIProcess/DrawingAreaProxyImpl.cpp:
(WebKit::DrawingAreaProxyImpl::setVisibleContentsRect):
* UIProcess/DrawingAreaProxyImpl.h:
(DrawingAreaProxyImpl):
* UIProcess/LayerTreeHostProxy.cpp:
(WebKit::LayerTreeHostProxy::setVisibleContentsRect):
* UIProcess/LayerTreeHostProxy.h:
(LayerTreeHostProxy):
* UIProcess/WebLayerTreeRenderer.cpp:
(WebKit::WebLayerTreeRenderer::paintToCurrentGLContext):
(WebKit::WebLayerTreeRenderer::setVisibleContentsRect):
* UIProcess/WebLayerTreeRenderer.h:
(WebLayerTreeRenderer):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (115695 => 115696)


--- trunk/Source/WebKit2/ChangeLog	2012-05-01 00:52:01 UTC (rev 115695)
+++ trunk/Source/WebKit2/ChangeLog	2012-05-01 01:10:35 UTC (rev 115696)
@@ -1,3 +1,35 @@
+2012-04-30  Yael Aharon  <yael.aha...@nokia.com>
+
+        [Qt][WK2] Fixed layers are shaking when zoom level is not 1.0 due to a rounding error.
+        https://bugs.webkit.org/show_bug.cgi?id=84306
+
+        Reviewed by Noam Rosenthal.
+
+        When zooming, we need to be careful about how to convert the visible rect from float to int.
+        Using toAlignedRect can produce inconsistent width and height when we are scrolling.
+        This patch carefully modifies each piece of the visible rect, to avoid such rounding errors.
+        In addition, the TransformationMatrix we use for painting, needs to be adjusted for the same rounding error.
+
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::visibleContentsRect):
+        (QQuickWebViewFlickablePrivate::_q_contentViewportChanged):
+        * UIProcess/DrawingAreaProxy.h:
+        (WebCore):
+        (WebKit::DrawingAreaProxy::setVisibleContentsRect):
+        * UIProcess/DrawingAreaProxyImpl.cpp:
+        (WebKit::DrawingAreaProxyImpl::setVisibleContentsRect):
+        * UIProcess/DrawingAreaProxyImpl.h:
+        (DrawingAreaProxyImpl):
+        * UIProcess/LayerTreeHostProxy.cpp:
+        (WebKit::LayerTreeHostProxy::setVisibleContentsRect):
+        * UIProcess/LayerTreeHostProxy.h:
+        (LayerTreeHostProxy):
+        * UIProcess/WebLayerTreeRenderer.cpp:
+        (WebKit::WebLayerTreeRenderer::paintToCurrentGLContext):
+        (WebKit::WebLayerTreeRenderer::setVisibleContentsRect):
+        * UIProcess/WebLayerTreeRenderer.h:
+        (WebLayerTreeRenderer):
+
 2012-04-30  Anders Carlsson  <ander...@apple.com>
 
         ScrollingCoordinator::requestScrollPositionUpdate should not update the main frame scroll position

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp (115695 => 115696)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2012-05-01 00:52:01 UTC (rev 115695)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2012-05-01 01:10:35 UTC (rev 115696)
@@ -545,7 +545,9 @@
     Q_Q(const QQuickWebView);
     const QRectF visibleRect(q->boundingRect().intersected(pageView->boundingRect()));
 
-    return q->mapRectToWebContent(visibleRect).toAlignedRect();
+    // We avoid using toAlignedRect() because it produces inconsistent width and height.
+    QRectF mappedRect(q->mapRectToWebContent(visibleRect));
+    return QRect(floor(mappedRect.x()), floor(mappedRect.y()), floor(mappedRect.width()), floor(mappedRect.height()));
 }
 
 WebCore::IntSize QQuickWebViewPrivate::viewSize() const
@@ -780,7 +782,9 @@
     const QRect visibleRect(visibleContentsRect());
     float scale = pageView->contentsScale();
 
-    drawingArea->setVisibleContentsRect(visibleRect, scale, trajectoryVector);
+    QRectF accurateVisibleRect(q->boundingRect());
+    accurateVisibleRect.translate(contentPos());
+    drawingArea->setVisibleContentsRect(visibleRect, scale, trajectoryVector, FloatPoint(accurateVisibleRect.x(), accurateVisibleRect.y()));
 
     // Ensure that updatePaintNode is always called before painting.
     pageView->update();

Modified: trunk/Source/WebKit2/UIProcess/DrawingAreaProxy.h (115695 => 115696)


--- trunk/Source/WebKit2/UIProcess/DrawingAreaProxy.h	2012-05-01 00:52:01 UTC (rev 115695)
+++ trunk/Source/WebKit2/UIProcess/DrawingAreaProxy.h	2012-05-01 01:10:35 UTC (rev 115696)
@@ -29,6 +29,7 @@
 
 #include "BackingStore.h"
 #include "DrawingAreaInfo.h"
+#include <WebCore/FloatPoint.h>
 #include <WebCore/IntRect.h>
 #include <WebCore/IntSize.h>
 #include <stdint.h>
@@ -47,7 +48,6 @@
 }
 
 namespace WebCore {
-    class FloatPoint;
     class TransformationMatrix;
 }
 
@@ -92,7 +92,7 @@
     virtual WebCore::IntRect contentsRect() const;
     virtual bool isBackingStoreReady() const { return true; }
     LayerTreeHostProxy* layerTreeHostProxy() const { return m_layerTreeHostProxy.get(); }
-    virtual void setVisibleContentsRect(const WebCore::IntRect& visibleContentsRect, float scale, const WebCore::FloatPoint& trajectoryVector) { }
+    virtual void setVisibleContentsRect(const WebCore::IntRect& visibleContentsRect, float scale, const WebCore::FloatPoint& trajectoryVector, const WebCore::FloatPoint& accurateVisibleContentsPosition = WebCore::FloatPoint()) { }
     virtual void createTileForLayer(int layerID, int tileID, const WebKit::UpdateInfo&) { }
     virtual void updateTileForLayer(int layerID, int tileID, const WebKit::UpdateInfo&) { }
     virtual void removeTileForLayer(int layerID, int tileID) { }

Modified: trunk/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp (115695 => 115696)


--- trunk/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp	2012-05-01 00:52:01 UTC (rev 115695)
+++ trunk/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp	2012-05-01 01:10:35 UTC (rev 115696)
@@ -353,10 +353,10 @@
         m_layerTreeHostProxy->didReceiveLayerTreeHostProxyMessage(connection, messageID, arguments);
 }
 
-void DrawingAreaProxyImpl::setVisibleContentsRect(const WebCore::IntRect& visibleContentsRect, float scale, const WebCore::FloatPoint& trajectoryVector)
+void DrawingAreaProxyImpl::setVisibleContentsRect(const WebCore::IntRect& visibleContentsRect, float scale, const WebCore::FloatPoint& trajectoryVector, const WebCore::FloatPoint& accurateVisibleContentsPosition)
 {
     if (m_layerTreeHostProxy)
-        m_layerTreeHostProxy->setVisibleContentsRect(visibleContentsRect, scale, trajectoryVector);
+        m_layerTreeHostProxy->setVisibleContentsRect(visibleContentsRect, scale, trajectoryVector, accurateVisibleContentsPosition);
 }
 
 #endif

Modified: trunk/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.h (115695 => 115696)


--- trunk/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.h	2012-05-01 00:52:01 UTC (rev 115695)
+++ trunk/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.h	2012-05-01 01:10:35 UTC (rev 115696)
@@ -80,7 +80,7 @@
     bool isInAcceleratedCompositingMode() const { return !m_layerTreeContext.isEmpty(); }
 
 #if USE(UI_SIDE_COMPOSITING)
-    virtual void setVisibleContentsRect(const WebCore::IntRect& visibleContentsRect, float scale, const WebCore::FloatPoint& trajectory);
+    virtual void setVisibleContentsRect(const WebCore::IntRect& visibleContentsRect, float scale, const WebCore::FloatPoint& trajectory, const WebCore::FloatPoint& accurateVisibleContentsPosition = WebCore::FloatPoint());
     void didReceiveLayerTreeHostProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
 #endif
 #else

Modified: trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.cpp (115695 => 115696)


--- trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.cpp	2012-05-01 00:52:01 UTC (rev 115695)
+++ trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.cpp	2012-05-01 01:10:35 UTC (rev 115696)
@@ -127,9 +127,9 @@
     m_renderer->setContentsSize(contentsSize);
 }
 
-void LayerTreeHostProxy::setVisibleContentsRect(const IntRect& rect, float scale, const FloatPoint& trajectoryVector)
+void LayerTreeHostProxy::setVisibleContentsRect(const IntRect& rect, float scale, const FloatPoint& trajectoryVector, const WebCore::FloatPoint& accurateVisibleContentsPosition)
 {
-    dispatchUpdate(bind(&WebLayerTreeRenderer::setVisibleContentsRect, m_renderer.get(), rect, scale));
+    dispatchUpdate(bind(&WebLayerTreeRenderer::setVisibleContentsRect, m_renderer.get(), rect, scale, accurateVisibleContentsPosition));
     m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeHost::SetVisibleContentsRect(rect, scale, trajectoryVector), m_drawingAreaProxy->page()->pageID());
 }
 

Modified: trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.h (115695 => 115696)


--- trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.h	2012-05-01 00:52:01 UTC (rev 115695)
+++ trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.h	2012-05-01 01:10:35 UTC (rev 115696)
@@ -55,7 +55,7 @@
     void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
     void purgeGLResources();
     void setContentsSize(const WebCore::FloatSize&);
-    void setVisibleContentsRect(const WebCore::IntRect&, float scale, const WebCore::FloatPoint& trajectory);
+    void setVisibleContentsRect(const WebCore::IntRect&, float scale, const WebCore::FloatPoint& trajectory, const WebCore::FloatPoint& accurateVisibleContentsPosition);
     void didRenderFrame();
     void createTileForLayer(int layerID, int tileID, const WebCore::IntRect&, const SurfaceUpdateInfo&);
     void updateTileForLayer(int layerID, int tileID, const WebCore::IntRect&, const SurfaceUpdateInfo&);

Modified: trunk/Source/WebKit2/UIProcess/WebLayerTreeRenderer.cpp (115695 => 115696)


--- trunk/Source/WebKit2/UIProcess/WebLayerTreeRenderer.cpp	2012-05-01 00:52:01 UTC (rev 115695)
+++ trunk/Source/WebKit2/UIProcess/WebLayerTreeRenderer.cpp	2012-05-01 01:10:35 UTC (rev 115696)
@@ -109,6 +109,12 @@
         m_textureMapper = TextureMapper::create(TextureMapper::OpenGLMode);
     ASSERT(m_textureMapper->accelerationMode() == TextureMapper::OpenGLMode);
 
+    // We need to compensate for the rounding error that happens due to m_visibleContentsRect being
+    // int and not float. We do that by moving the TransformationMatrix by the delta between the
+    // position of m_visibleContentsRect and the position it would have if it wasn't rounded.
+ 
+    TransformationMatrix newMatrix = matrix;
+    newMatrix.translate(m_accurateVisibleContentsPosition.x() / m_contentsScale - m_visibleContentsRect.x(), m_accurateVisibleContentsPosition.y() / m_contentsScale - m_visibleContentsRect.y());
     adjustPositionForFixedLayers();
     GraphicsLayer* currentRootLayer = rootLayer();
     if (!currentRootLayer)
@@ -123,9 +129,9 @@
     m_textureMapper->beginPainting(PaintFlags);
     m_textureMapper->beginClip(TransformationMatrix(), clipRect);
 
-    if (currentRootLayer->opacity() != opacity || currentRootLayer->transform() != matrix) {
+    if (currentRootLayer->opacity() != opacity || currentRootLayer->transform() != newMatrix) {
         currentRootLayer->setOpacity(opacity);
-        currentRootLayer->setTransform(matrix);
+        currentRootLayer->setTransform(newMatrix);
         currentRootLayer->syncCompositingStateForThisLayerOnly();
     }
 
@@ -158,10 +164,11 @@
     m_contentsSize = contentsSize;
 }
 
-void WebLayerTreeRenderer::setVisibleContentsRect(const IntRect& rect, float scale)
+void WebLayerTreeRenderer::setVisibleContentsRect(const IntRect& rect, float scale, const WebCore::FloatPoint& accurateVisibleContentsPosition)
 {
     m_visibleContentsRect = rect;
     m_contentsScale = scale;
+    m_accurateVisibleContentsPosition = accurateVisibleContentsPosition;
 }
 
 void WebLayerTreeRenderer::updateViewport()

Modified: trunk/Source/WebKit2/UIProcess/WebLayerTreeRenderer.h (115695 => 115696)


--- trunk/Source/WebKit2/UIProcess/WebLayerTreeRenderer.h	2012-05-01 00:52:01 UTC (rev 115695)
+++ trunk/Source/WebKit2/UIProcess/WebLayerTreeRenderer.h	2012-05-01 01:10:35 UTC (rev 115696)
@@ -65,7 +65,7 @@
     void paintToGraphicsContext(BackingStore::PlatformGraphicsContext);
     void syncRemoteContent();
     void setContentsSize(const WebCore::FloatSize&);
-    void setVisibleContentsRect(const WebCore::IntRect&, float scale);
+    void setVisibleContentsRect(const WebCore::IntRect&, float scale, const WebCore::FloatPoint& accurateVisibleContentsPosition);
     void didChangeScrollPosition(const WebCore::IntPoint& position);
 
     void detach();
@@ -102,6 +102,7 @@
     typedef HashMap<WebLayerID, WebCore::GraphicsLayer*> LayerMap;
     WebCore::FloatSize m_contentsSize;
     WebCore::IntRect m_visibleContentsRect;
+    WebCore::FloatPoint m_accurateVisibleContentsPosition;
     float m_contentsScale;
 
     // Render queue can be accessed ony from main thread or updatePaintNode call stack!
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to