Coordinated Graphics: Remove tiles of a layer when they are off the viewport.

https://bugs.webkit.org/show_bug.cgi?id=102313

Patch by Huang Dongsung <luxtella@company100.net> on 2012-11-19
Reviewed by Noam Rosenthal.

Source/WebKit2:

Currently, we don't remove tiles of the layer with the special properties: a
transform animation and non affine transform. If a page has a lot of layers with
a transform animation, we will encounter OOM. So this patch removes the
privilege of the layer.

There are two changes.
1. computeTransformedVisibleRect() calculates a layer transform using the
current local transform which a transform animation applied.
2. tiledBackingStoreVisibleRect() calculates a visible
rect of all layers, even if the layer includes the property: a transform
animation or non affine transform.

Test: animations/animation-offscreen-to-onscreen.html

* WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp:
(WebCore::CoordinatedGraphicsLayer::effectiveContentsScale):
(WebCore::CoordinatedGraphicsLayer::tiledBackingStoreVisibleRect):
(WebCore::CoordinatedGraphicsLayer::hasPendingVisibleChanges):
(WebCore::CoordinatedGraphicsLayer::computeTransformedVisibleRect):
(WebCore::CoordinatedGraphicsLayer::selfOrAncestorHasActiveTransformAnimation):
(WebCore):
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h:
(CoordinatedGraphicsLayer):

LayoutTests:

This test checks that a compositing layer is rendered if the layer is
originally transformed off the viewport.

* animations/animation-offscreen-to-onscreen-expected.png: Added.
* animations/animation-offscreen-to-onscreen-expected.txt: Added.
* animations/animation-offscreen-to-onscreen.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@135212 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 276d0b45
2012-11-19 Huang Dongsung <luxtella@company100.net>
Coordinated Graphics: Remove tiles of a layer when they are off the viewport.
https://bugs.webkit.org/show_bug.cgi?id=102313
Reviewed by Noam Rosenthal.
This test checks that a compositing layer is rendered if the layer is
originally transformed off the viewport.
* animations/animation-offscreen-to-onscreen-expected.png: Added.
* animations/animation-offscreen-to-onscreen-expected.txt: Added.
* animations/animation-offscreen-to-onscreen.html: Added.
2012-11-19 Jian Li <jianli@chromium.org>
Unreviewed. Mark 2 tests as failed on chromium.
PASS - "webkitTransform" property for "box" element at 0.5s saw something close to: 1,0,0,1,100,0
<html>
<head>
<style type="text/css" media="screen">
body {
margin: 0;
}
#box {
position: absolute;
left: 0px;
top: 100px;
height: 100px;
width: 100px;
margin: 0;
background-color: red;
-webkit-transform: translate(-2000px, 0px);
-webkit-animation-duration: 1s;
-webkit-animation-direction: normal;
-webkit-animation-timing-function: linear;
-webkit-animation-name: "anim";
}
@-webkit-keyframes "anim" {
0% { -webkit-transform: translate(100px, 0px); }
100% { -webkit-transform: translate(100px, 0px); }
}
#result {
color: white; /* hide from pixel results */
}
</style>
<script src="resources/animation-test-helpers.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
if (window.testRunner) {
window.testRunner.dumpAsText(true);
}
const expectedValues = [
// [time, element-id, property, expected-value, tolerance]
["anim", 0.5, "box", "webkitTransform", [1, 0, 0, 1, 100, 0], 0.002],
];
const doPixelTest = true;
const disablePauseAnimationAPI = false;
runAnimationTest(expectedValues, null, null, disablePauseAnimationAPI, doPixelTest);
</script>
</head>
<body>
<!-- This test checks that a compositing layer is rendered if the layer is originally transformed off the viewport. You should see red boxes. -->
<div id="box"></div>
<div id="result"></div>
</body>
</html>
2012-11-19 Huang Dongsung <luxtella@company100.net>
Coordinated Graphics: Remove tiles of a layer when they are off the viewport.
https://bugs.webkit.org/show_bug.cgi?id=102313
Reviewed by Noam Rosenthal.
Currently, we don't remove tiles of the layer with the special properties: a
transform animation and non affine transform. If a page has a lot of layers with
a transform animation, we will encounter OOM. So this patch removes the
privilege of the layer.
There are two changes.
1. computeTransformedVisibleRect() calculates a layer transform using the
current local transform which a transform animation applied.
2. tiledBackingStoreVisibleRect() calculates a visible
rect of all layers, even if the layer includes the property: a transform
animation or non affine transform.
Test: animations/animation-offscreen-to-onscreen.html
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.cpp:
(WebCore::CoordinatedGraphicsLayer::effectiveContentsScale):
(WebCore::CoordinatedGraphicsLayer::tiledBackingStoreVisibleRect):
(WebCore::CoordinatedGraphicsLayer::hasPendingVisibleChanges):
(WebCore::CoordinatedGraphicsLayer::computeTransformedVisibleRect):
(WebCore::CoordinatedGraphicsLayer::selfOrAncestorHasActiveTransformAnimation):
(WebCore):
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedGraphicsLayer.h:
(CoordinatedGraphicsLayer):
2012-11-19 Huang Dongsung <luxtella@company100.net>
Coordinated Graphics: Remove a texture if an direct composited image is off the viewport.
......
......@@ -644,7 +644,7 @@ void CoordinatedGraphicsLayer::setContentsScale(float scale)
float CoordinatedGraphicsLayer::effectiveContentsScale()
{
return shouldUseTiledBackingStore() ? m_contentsScale : 1;
return selfOrAncestorHaveNonAffineTransforms() ? 1 : m_contentsScale;
}
void CoordinatedGraphicsLayer::adjustContentsScale()
......@@ -697,16 +697,8 @@ IntRect CoordinatedGraphicsLayer::tiledBackingStoreContentsRect()
return IntRect(0, 0, size().width(), size().height());
}
bool CoordinatedGraphicsLayer::shouldUseTiledBackingStore()
{
return !selfOrAncestorHaveNonAffineTransforms();
}
IntRect CoordinatedGraphicsLayer::tiledBackingStoreVisibleRect()
{
if (!shouldUseTiledBackingStore())
return tiledBackingStoreContentsRect();
// Non-invertible layers are not visible.
if (!m_layerTransform.combined().isInvertible())
return IntRect();
......@@ -807,17 +799,21 @@ bool CoordinatedGraphicsLayer::hasPendingVisibleChanges()
if (!m_shouldSyncLayerState && !m_shouldSyncChildren && !m_shouldSyncFilters && !m_shouldSyncImageBacking && !m_shouldSyncAnimations && !m_canvasNeedsDisplay)
return false;
return selfOrAncestorHaveNonAffineTransforms() || !tiledBackingStoreVisibleRect().isEmpty();
return tiledBackingStoreVisibleRect().intersects(tiledBackingStoreContentsRect());
}
void CoordinatedGraphicsLayer::computeTransformedVisibleRect()
{
if (!m_shouldUpdateVisibleRect)
// When we have a transform animation, we need to update visible rect every frame to adjust the visible rect of a backing store.
bool hasActiveTransformAnimation = selfOrAncestorHasActiveTransformAnimation();
if (!m_shouldUpdateVisibleRect && !hasActiveTransformAnimation)
return;
m_shouldUpdateVisibleRect = false;
m_layerTransform.setLocalTransform(transform());
TransformationMatrix currentTransform = transform();
if (hasActiveTransformAnimation)
client()->getCurrentTransform(this, currentTransform);
m_layerTransform.setLocalTransform(currentTransform);
m_layerTransform.setPosition(position());
m_layerTransform.setAnchorPoint(anchorPoint());
m_layerTransform.setSize(size());
......@@ -841,6 +837,17 @@ void CoordinatedGraphicsLayer::initFactory()
GraphicsLayer::setGraphicsLayerFactory(createCoordinatedGraphicsLayer);
}
bool CoordinatedGraphicsLayer::selfOrAncestorHasActiveTransformAnimation() const
{
if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
return true;
if (!parent())
return false;
return toCoordinatedGraphicsLayer(parent())->selfOrAncestorHasActiveTransformAnimation();
}
bool CoordinatedGraphicsLayer::selfOrAncestorHaveNonAffineTransforms()
{
if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
......
......@@ -196,8 +196,8 @@ private:
void destroyCanvasIfNeeded();
void createCanvasIfNeeded();
bool selfOrAncestorHasActiveTransformAnimation() const;
bool selfOrAncestorHaveNonAffineTransforms();
bool shouldUseTiledBackingStore();
void adjustContentsScale();
void setShouldUpdateVisibleRect();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment