diff options
author | Andras Becsi <andras.becsi@digia.com> | 2013-01-16 08:57:21 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-16 09:24:58 +0100 |
commit | c2c595293e376b2609d8176e86b6f2ad86b45223 (patch) | |
tree | f84a1ce8fe9a0127dd3a63658c2afb02610786ef /Source/WebKit2/UIProcess | |
parent | c03f448e170e91ef00dd1846a99e2f094b5919d8 (diff) | |
download | qtwebkit-c2c595293e376b2609d8176e86b6f2ad86b45223.tar.gz |
[Qt][EFL][WK2] Remove redundant device pixel ratio adjustment from PageViewportController
https://bugs.webkit.org/show_bug.cgi?id=106355
Reviewed by Kenneth Rohde Christiansen.
This is a backport of http://trac.webkit.org/changeset/139189.
Since r137597 Qt uses the device pixel ratio of the underlying
platform window as the device pixel ratio in WebCore.
The tiles are rendered with the effective scale (scale adjusted with
the device scale factor) and the projection matrix is also adjusted
with the device pixel ratio when painting.
As a result we can follow the same approach as QtQuick and all the
coordinates in PageViewportController need to be in device independent
pixels (UI pixels) thus we do no longer need to adjust with the device
pixel ratio when calculating the viewport attributes.
This simplifies the logic significantly and increases robustness,
but does not allow to set a custom device pixel ratio different from
the factor of the underlying platform (eg. for testing purposes).
This patch is conceptually a follow-up of r137597 and fixes layout
and canvas size on retina display.
Change-Id: I2485ef0a4aa18726238bacddaa5176cf5869659e
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'Source/WebKit2/UIProcess')
4 files changed, 36 insertions, 35 deletions
diff --git a/Source/WebKit2/UIProcess/PageViewportController.cpp b/Source/WebKit2/UIProcess/PageViewportController.cpp index c345d03eb..05ff8b98a 100644 --- a/Source/WebKit2/UIProcess/PageViewportController.cpp +++ b/Source/WebKit2/UIProcess/PageViewportController.cpp @@ -47,9 +47,9 @@ PageViewportController::PageViewportController(WebKit::WebPageProxy* proxy, Page , m_initiallyFitToViewport(true) , m_hasSuspendedContent(false) , m_hadUserInteraction(false) - , m_effectiveScale(1) + , m_pageScaleFactor(1) , m_viewportPosIsLocked(false) - , m_effectiveScaleIsLocked(false) + , m_pageScaleFactorIsLocked(false) { // Initializing Viewport Raw Attributes to avoid random negative or infinity scale factors // if there is a race condition between the first layout and setting the viewport attributes for the first time. @@ -68,15 +68,15 @@ PageViewportController::PageViewportController(WebKit::WebPageProxy* proxy, Page float PageViewportController::innerBoundedViewportScale(float viewportScale) const { - return clampTo(viewportScale, toViewportScale(m_minimumScaleToFit), toViewportScale(m_rawAttributes.maximumScale)); + return clampTo(viewportScale, m_minimumScaleToFit, m_rawAttributes.maximumScale); } float PageViewportController::outerBoundedViewportScale(float viewportScale) const { if (m_allowsUserScaling) { // Bounded by [0.1, 10.0] like the viewport meta code in WebCore. - float hardMin = toViewportScale(std::max<float>(0.1, 0.5 * m_minimumScaleToFit)); - float hardMax = toViewportScale(std::min<float>(10, 2 * m_rawAttributes.maximumScale)); + float hardMin = std::max<float>(0.1, 0.5 * m_minimumScaleToFit); + float hardMax = std::min<float>(10, 2 * m_rawAttributes.maximumScale); return clampTo(viewportScale, hardMin, hardMax); } return innerBoundedViewportScale(viewportScale); @@ -145,12 +145,12 @@ void PageViewportController::didRenderFrame(const IntSize& contentsSize, const I // All position and scale changes resulting from a web process event should // go through here to be applied on the viewport to avoid showing incomplete // tiles to the user during a few milliseconds. - if (m_effectiveScaleIsLocked) { - m_client->setContentsScale(m_effectiveScale, false); - m_effectiveScaleIsLocked = false; + if (m_pageScaleFactorIsLocked) { + m_client->setContentsScale(m_pageScaleFactor, false); + m_pageScaleFactorIsLocked = false; } if (m_viewportPosIsLocked) { - FloatPoint clampedPos = clampViewportToContents(m_viewportPos, m_effectiveScale); + FloatPoint clampedPos = clampViewportToContents(m_viewportPos, m_pageScaleFactor); // There might be rendered frames not covering our requested position yet, wait for it. if (FloatRect(clampedPos, viewportSizeInContentsCoordinates()).intersects(coveredRect)) { m_client->setViewportPosition(clampedPos); @@ -164,7 +164,7 @@ void PageViewportController::pageTransitionViewportReady() if (!m_rawAttributes.layoutSize.isEmpty()) { m_hadUserInteraction = false; float initialScale = m_initiallyFitToViewport ? m_minimumScaleToFit : m_rawAttributes.initialScale; - applyScaleAfterRenderingContents(innerBoundedViewportScale(toViewportScale(initialScale))); + applyScaleAfterRenderingContents(innerBoundedViewportScale(initialScale)); } // At this point we should already have received the first viewport arguments and the requested scroll @@ -180,7 +180,7 @@ void PageViewportController::pageDidRequestScroll(const IntPoint& cssPosition) if (m_hasSuspendedContent) return; - FloatRect endVisibleContentRect(clampViewportToContents(cssPosition, m_effectiveScale), viewportSizeInContentsCoordinates()); + FloatRect endVisibleContentRect(clampViewportToContents(cssPosition, m_pageScaleFactor), viewportSizeInContentsCoordinates()); if (m_lastFrameCoveredRect.intersects(endVisibleContentRect)) m_client->setViewportPosition(endVisibleContentRect.location()); else @@ -204,8 +204,8 @@ void PageViewportController::didChangeContentsVisibility(const FloatPoint& viewp { if (!m_viewportPosIsLocked) m_viewportPos = viewportPos; - if (!m_effectiveScaleIsLocked) - m_effectiveScale = viewportScale; + if (!m_pageScaleFactorIsLocked) + m_pageScaleFactor = viewportScale; syncVisibleContents(trajectoryVector); } @@ -216,9 +216,9 @@ void PageViewportController::syncVisibleContents(const FloatPoint& trajectoryVec if (!drawingArea || m_viewportSize.isEmpty() || m_contentsSize.isEmpty()) return; - FloatRect visibleContentsRect(clampViewportToContents(m_viewportPos, m_effectiveScale), viewportSizeInContentsCoordinates()); + FloatRect visibleContentsRect(clampViewportToContents(m_viewportPos, m_pageScaleFactor), viewportSizeInContentsCoordinates()); visibleContentsRect.intersect(FloatRect(FloatPoint::zero(), m_contentsSize)); - drawingArea->setVisibleContentsRect(visibleContentsRect, m_effectiveScale, trajectoryVector); + drawingArea->setVisibleContentsRect(visibleContentsRect, m_pageScaleFactor, trajectoryVector); m_client->didChangeVisibleContents(); } @@ -243,7 +243,7 @@ void PageViewportController::didChangeViewportAttributes(const WebCore::Viewport WebCore::FloatSize PageViewportController::viewportSizeInContentsCoordinates() const { - return WebCore::FloatSize(m_viewportSize.width() / m_effectiveScale, m_viewportSize.height() / m_effectiveScale); + return WebCore::FloatSize(m_viewportSize.width() / m_pageScaleFactor, m_viewportSize.height() / m_pageScaleFactor); } void PageViewportController::suspendContent() @@ -268,8 +268,8 @@ void PageViewportController::resumeContent() void PageViewportController::applyScaleAfterRenderingContents(float scale) { - m_effectiveScale = scale; - m_effectiveScaleIsLocked = true; + m_pageScaleFactor = scale; + m_pageScaleFactorIsLocked = true; syncVisibleContents(); } @@ -285,9 +285,9 @@ bool PageViewportController::updateMinimumScaleToFit(bool userInitiatedUpdate) if (m_viewportSize.isEmpty() || m_contentsSize.isEmpty()) return false; - bool currentlyScaledToFit = fuzzyCompare(m_effectiveScale, toViewportScale(m_minimumScaleToFit), 0.001); + bool currentlyScaledToFit = fuzzyCompare(m_pageScaleFactor, m_minimumScaleToFit, 0.001); - float minimumScale = WebCore::computeMinimumScaleFactorForContentContained(m_rawAttributes, WebCore::roundedIntSize(m_viewportSize), WebCore::roundedIntSize(m_contentsSize), devicePixelRatio()); + float minimumScale = WebCore::computeMinimumScaleFactorForContentContained(m_rawAttributes, WebCore::roundedIntSize(m_viewportSize), WebCore::roundedIntSize(m_contentsSize), 1); if (minimumScale <= 0) return false; @@ -297,11 +297,11 @@ bool PageViewportController::updateMinimumScaleToFit(bool userInitiatedUpdate) if (!hasSuspendedContent()) { if (!m_hadUserInteraction || (userInitiatedUpdate && currentlyScaledToFit)) - applyScaleAfterRenderingContents(toViewportScale(m_minimumScaleToFit)); + applyScaleAfterRenderingContents(m_minimumScaleToFit); else { // Ensure the effective scale stays within bounds. - float boundedScale = innerBoundedViewportScale(m_effectiveScale); - if (!fuzzyCompare(boundedScale, m_effectiveScale, 0.001)) + float boundedScale = innerBoundedViewportScale(m_pageScaleFactor); + if (!fuzzyCompare(boundedScale, m_pageScaleFactor, 0.001)) applyScaleAfterRenderingContents(boundedScale); } } diff --git a/Source/WebKit2/UIProcess/PageViewportController.h b/Source/WebKit2/UIProcess/PageViewportController.h index 029228dde..dadbbbefe 100644 --- a/Source/WebKit2/UIProcess/PageViewportController.h +++ b/Source/WebKit2/UIProcess/PageViewportController.h @@ -62,7 +62,7 @@ public: float devicePixelRatio() const; float minimumContentsScale() const { return m_minimumScaleToFit; } float maximumContentsScale() const { return m_rawAttributes.maximumScale; } - float currentContentsScale() const { return fromViewportScale(m_effectiveScale); } + float currentContentsScale() const { return m_pageScaleFactor; } void setHadUserInteraction(bool didUserInteract) { m_hadUserInteraction = didUserInteract; } @@ -79,8 +79,6 @@ public: void pageDidRequestScroll(const WebCore::IntPoint& cssPosition); private: - float fromViewportScale(float scale) const { return scale / devicePixelRatio(); } - float toViewportScale(float scale) const { return scale * devicePixelRatio(); } void syncVisibleContents(const WebCore::FloatPoint &trajectoryVector = WebCore::FloatPoint::zero()); void applyScaleAfterRenderingContents(float scale); void applyPositionAfterRenderingContents(const WebCore::FloatPoint& pos); @@ -103,10 +101,10 @@ private: WebCore::FloatSize m_viewportSize; WebCore::FloatSize m_contentsSize; WebCore::IntSize m_clientContentsSize; - float m_effectiveScale; // Should always be cssScale * devicePixelRatio. + float m_pageScaleFactor; bool m_viewportPosIsLocked; - bool m_effectiveScaleIsLocked; + bool m_pageScaleFactorIsLocked; WebCore::FloatRect m_lastFrameCoveredRect; }; diff --git a/Source/WebKit2/UIProcess/qt/PageViewportControllerClientQt.cpp b/Source/WebKit2/UIProcess/qt/PageViewportControllerClientQt.cpp index b8ccd977b..a8ba76cdb 100644 --- a/Source/WebKit2/UIProcess/qt/PageViewportControllerClientQt.cpp +++ b/Source/WebKit2/UIProcess/qt/PageViewportControllerClientQt.cpp @@ -182,12 +182,12 @@ void PageViewportControllerClientQt::focusEditableArea(const QRectF& caretArea, // This can only happen as a result of a user interaction. ASSERT(m_controller->hadUserInteraction()); - const float editingFixedScale = 2 * m_controller->devicePixelRatio(); + const float editingFixedScale = 2; float targetScale = m_controller->innerBoundedViewportScale(editingFixedScale); const QRectF viewportRect = m_viewportItem->boundingRect(); qreal x; - const qreal borderOffset = 10 * m_controller->devicePixelRatio(); + const qreal borderOffset = 10; if ((targetArea.width() + borderOffset) * targetScale <= viewportRect.width()) { // Center the input field in the middle of the view, if it is smaller than // the view at the scale target. @@ -221,12 +221,12 @@ void PageViewportControllerClientQt::zoomToAreaGestureEnded(const QPointF& touch if (m_controller->hasSuspendedContent()) return; - const float margin = 10 * m_controller->devicePixelRatio(); // We want at least a little bit of margin. + const float margin = 10; // We want at least a little bit of margin. QRectF endArea = targetArea.adjusted(-margin, -margin, margin, margin); const QRectF viewportRect = m_viewportItem->boundingRect(); - qreal minViewportScale = qreal(2.5) * m_controller->devicePixelRatio(); + qreal minViewportScale = qreal(2.5); qreal targetScale = viewportRect.size().width() / endArea.size().width(); targetScale = m_controller->innerBoundedViewportScale(qMin(minViewportScale, targetScale)); qreal currentScale = m_pageItem->contentsScale(); @@ -268,7 +268,7 @@ void PageViewportControllerClientQt::zoomToAreaGestureEnded(const QPointF& touch break; case ZoomBack: { if (m_scaleStack.isEmpty()) { - targetScale = m_controller->minimumContentsScale() * m_controller->devicePixelRatio(); + targetScale = m_controller->minimumContentsScale(); endPosition.setY(hotspot.y() - viewportHotspot.y() / targetScale); endPosition.setX(0); m_zoomOutScale = 0; diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageSGNode.cpp b/Source/WebKit2/UIProcess/qt/QtWebPageSGNode.cpp index d72980c05..146462ade 100644 --- a/Source/WebKit2/UIProcess/qt/QtWebPageSGNode.cpp +++ b/Source/WebKit2/UIProcess/qt/QtWebPageSGNode.cpp @@ -87,9 +87,12 @@ private: for (const QSGClipNode* clip = clipList(); clip; clip = clip->clipList()) { QMatrix4x4 clipMatrix; - if (clip->matrix()) + if (pageNode()->devicePixelRatio() != 1.0) { + clipMatrix.scale(pageNode()->devicePixelRatio()); + if (clip->matrix()) + clipMatrix *= (*clip->matrix()); + } else if (clip->matrix()) clipMatrix = *clip->matrix(); - clipMatrix.scale(pageNode()->devicePixelRatio()); QRectF currentClip; |