CCDamageTrackerTest.cpp [plain text]
#include "config.h"
#include "cc/CCDamageTracker.h"
#include "CCLayerTreeTestCommon.h"
#include "cc/CCLayerImpl.h"
#include "cc/CCLayerSorter.h"
#include "cc/CCLayerTreeHostCommon.h"
#include "cc/CCMathUtil.h"
#include "cc/CCSingleThreadProxy.h"
#include <gtest/gtest.h>
using namespace WebCore;
using namespace WTF;
using namespace WebKitTests;
namespace {
void executeCalculateDrawTransformsAndVisibility(CCLayerImpl* root, Vector<CCLayerImpl*>& renderSurfaceLayerList)
{
CCLayerSorter layerSorter;
TransformationMatrix identityMatrix;
Vector<CCLayerImpl*> dummyLayerList;
int dummyMaxTextureSize = 512;
ASSERT_TRUE(root->renderSurface());
ASSERT_FALSE(renderSurfaceLayerList.size());
root->renderSurface()->clearLayerList();
renderSurfaceLayerList.append(root);
CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(root, root, identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, &layerSorter, dummyMaxTextureSize);
}
void emulateDrawingOneFrame(CCLayerImpl* root)
{
Vector<CCLayerImpl*> renderSurfaceLayerList;
executeCalculateDrawTransformsAndVisibility(root, renderSurfaceLayerList);
for (int i = renderSurfaceLayerList.size() - 1; i >= 0; --i) {
CCRenderSurface* targetSurface = renderSurfaceLayerList[i]->renderSurface();
targetSurface->damageTracker()->updateDamageTrackingState(targetSurface->layerList(), targetSurface->owningLayerId(), targetSurface->surfacePropertyChangedOnlyFromDescendant(), targetSurface->contentRect(), renderSurfaceLayerList[i]->maskLayer(), renderSurfaceLayerList[i]->filters());
}
root->resetAllChangeTrackingForSubtree();
}
PassOwnPtr<CCLayerImpl> createTestTreeWithOneSurface()
{
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(1);
OwnPtr<CCLayerImpl> child = CCLayerImpl::create(2);
root->setPosition(FloatPoint::zero());
root->setAnchorPoint(FloatPoint::zero());
root->setBounds(IntSize(500, 500));
root->setDrawsContent(true);
root->createRenderSurface();
root->renderSurface()->setContentRect(IntRect(IntPoint(), IntSize(500, 500)));
child->setPosition(FloatPoint(100, 100));
child->setAnchorPoint(FloatPoint::zero());
child->setBounds(IntSize(30, 30));
child->setDrawsContent(true);
root->addChild(child.release());
return root.release();
}
PassOwnPtr<CCLayerImpl> createTestTreeWithTwoSurfaces()
{
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(1);
OwnPtr<CCLayerImpl> child1 = CCLayerImpl::create(2);
OwnPtr<CCLayerImpl> child2 = CCLayerImpl::create(3);
OwnPtr<CCLayerImpl> grandChild1 = CCLayerImpl::create(4);
OwnPtr<CCLayerImpl> grandChild2 = CCLayerImpl::create(5);
root->setPosition(FloatPoint::zero());
root->setAnchorPoint(FloatPoint::zero());
root->setBounds(IntSize(500, 500));
root->setDrawsContent(true);
root->createRenderSurface();
root->renderSurface()->setContentRect(IntRect(IntPoint(), IntSize(500, 500)));
child1->setPosition(FloatPoint(100, 100));
child1->setAnchorPoint(FloatPoint::zero());
child1->setBounds(IntSize(30, 30));
child1->setOpacity(0.5); child1->setDrawsContent(false);
child2->setPosition(FloatPoint(11, 11));
child2->setAnchorPoint(FloatPoint::zero());
child2->setBounds(IntSize(18, 18));
child2->setDrawsContent(true);
grandChild1->setPosition(FloatPoint(200, 200));
grandChild1->setAnchorPoint(FloatPoint::zero());
grandChild1->setBounds(IntSize(6, 8));
grandChild1->setDrawsContent(true);
grandChild2->setPosition(FloatPoint(190, 190));
grandChild2->setAnchorPoint(FloatPoint::zero());
grandChild2->setBounds(IntSize(6, 8));
grandChild2->setDrawsContent(true);
child1->addChild(grandChild1.release());
child1->addChild(grandChild2.release());
root->addChild(child1.release());
root->addChild(child2.release());
return root.release();
}
PassOwnPtr<CCLayerImpl> createAndSetUpTestTreeWithOneSurface()
{
OwnPtr<CCLayerImpl> root = createTestTreeWithOneSurface();
emulateDrawingOneFrame(root.get());
return root.release();
}
PassOwnPtr<CCLayerImpl> createAndSetUpTestTreeWithTwoSurfaces()
{
OwnPtr<CCLayerImpl> root = createTestTreeWithTwoSurfaces();
emulateDrawingOneFrame(root.get());
return root.release();
}
class CCDamageTrackerTest : public testing::Test {
private:
DebugScopedSetImplThread setImplThread;
};
TEST_F(CCDamageTrackerTest, sanityCheckTestTreeWithOneSurface)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface();
EXPECT_EQ(2u, root->renderSurface()->layerList().size());
EXPECT_EQ(1, root->renderSurface()->layerList()[0]->id());
EXPECT_EQ(2, root->renderSurface()->layerList()[1]->id());
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect);
}
TEST_F(CCDamageTrackerTest, sanityCheckTestTreeWithTwoSurfaces)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
CCLayerImpl* child1 = root->children()[0].get();
CCLayerImpl* child2 = root->children()[1].get();
FloatRect childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
ASSERT_TRUE(child1->renderSurface());
EXPECT_FALSE(child2->renderSurface());
EXPECT_EQ(3u, root->renderSurface()->layerList().size());
EXPECT_EQ(2u, child1->renderSurface()->layerList().size());
EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 16, 18), childDamageRect);
EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForUpdateRects)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface();
CCLayerImpl* child = root->children()[0].get();
child->setUpdateRect(FloatRect(10, 11, 12, 13));
emulateDrawingOneFrame(root.get());
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(110, 111, 12, 13), rootDamageRect);
child->setUpdateRect(FloatRect(10, 11, 12, 13));
emulateDrawingOneFrame(root.get());
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(110, 111, 12, 13), rootDamageRect);
child->setUpdateRect(FloatRect(20, 25, 1, 2));
emulateDrawingOneFrame(root.get());
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(120, 125, 1, 2), rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForPropertyChanges)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface();
CCLayerImpl* child = root->children()[0].get();
child->setUpdateRect(FloatRect(10, 11, 12, 13));
child->setOpacity(0.5);
emulateDrawingOneFrame(root.get());
ASSERT_FALSE(child->renderSurface());
ASSERT_EQ(2u, root->renderSurface()->layerList().size());
FloatRect expectedRect = FloatRect(100, 100, 30, 30);
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect);
emulateDrawingOneFrame(root.get());
EXPECT_TRUE(root->renderSurface()->damageTracker()->currentDamageRect().isEmpty());
child->setPosition(FloatPoint(200, 230));
emulateDrawingOneFrame(root.get());
expectedRect.uniteIfNonZero(FloatRect(200, 230, 30, 30));
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForTransformedLayer)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface();
CCLayerImpl* child = root->children()[0].get();
TransformationMatrix rotation;
rotation.rotate(45);
child->setAnchorPoint(FloatPoint(0.5, 0.5));
emulateDrawingOneFrame(root.get());
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(85, 85, 45, 45), rootDamageRect);
child->setTransform(rotation);
emulateDrawingOneFrame(root.get());
double expectedWidth = 30.0 * sqrt(2.0);
double expectedPosition = 100.0 - 0.5 * expectedWidth;
FloatRect expectedRect(expectedPosition, expectedPosition, expectedWidth, expectedWidth);
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(expectedRect, rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForPerspectiveClippedLayer)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface();
CCLayerImpl* child = root->children()[0].get();
TransformationMatrix transform;
transform.applyPerspective(1);
transform.translate3d(-150, -50, 0);
transform.rotate3d(0, 45, 0);
transform.translate3d(-50, -50, 0);
child->setPosition(FloatPoint(0, 0));
child->setBounds(IntSize(100, 100));
child->setTransform(transform);
emulateDrawingOneFrame(root.get());
FloatQuad testQuad(FloatRect(FloatPoint::zero(), FloatSize(100, 100)));
bool clipped = false;
CCMathUtil::mapQuad(transform, testQuad, clipped);
EXPECT_TRUE(clipped);
child->setOpacity(0.5);
emulateDrawingOneFrame(root.get());
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_GE(rootDamageRect.width(), 500);
EXPECT_GE(rootDamageRect.height(), 500);
}
TEST_F(CCDamageTrackerTest, verifyDamageForBlurredSurface)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface();
CCLayerImpl* child = root->children()[0].get();
FilterOperations filters;
filters.operations().append(BlurFilterOperation::create(Length(5, WebCore::Fixed), FilterOperation::BLUR));
int outsetTop, outsetRight, outsetBottom, outsetLeft;
filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
root->setFilters(filters);
emulateDrawingOneFrame(root.get());
child->setUpdateRect(FloatRect(10, 11, 12, 13));
emulateDrawingOneFrame(root.get());
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
FloatRect expectedDamageRect = FloatRect(110, 111, 12, 13);
expectedDamageRect.move(-outsetLeft, -outsetTop);
expectedDamageRect.expand(outsetLeft + outsetRight, outsetTop + outsetBottom);
EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForBackgroundBlurredChild)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
CCLayerImpl* child1 = root->children()[0].get();
CCLayerImpl* child2 = root->children()[1].get();
FilterOperations filters;
filters.operations().append(BlurFilterOperation::create(Length(2, WebCore::Fixed), FilterOperation::BLUR));
int outsetTop, outsetRight, outsetBottom, outsetLeft;
filters.getOutsets(outsetTop, outsetRight, outsetBottom, outsetLeft);
child1->setBackgroundFilters(filters);
emulateDrawingOneFrame(root.get());
root->setUpdateRect(FloatRect(297, 297, 2, 2));
emulateDrawingOneFrame(root.get());
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
FloatRect expectedDamageRect = FloatRect(297, 297, 2, 2);
expectedDamageRect.move(-outsetLeft, -outsetTop);
expectedDamageRect.expand(outsetLeft + outsetRight, outsetTop + outsetBottom);
EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect);
root->setUpdateRect(FloatRect(297, 297, 30, 30));
emulateDrawingOneFrame(root.get());
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
expectedDamageRect = FloatRect(297, 297, 30, 30);
expectedDamageRect.move(-outsetLeft, -outsetTop);
expectedDamageRect.expand(outsetLeft, outsetTop);
EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect);
root->setUpdateRect(FloatRect(30, 30, 2, 2));
emulateDrawingOneFrame(root.get());
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
expectedDamageRect = FloatRect(30, 30, 2, 2);
EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect);
child2->setUpdateRect(FloatRect(0, 0, 1, 1));
emulateDrawingOneFrame(root.get());
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
expectedDamageRect = FloatRect(11, 11, 1, 1);
EXPECT_FLOAT_RECT_EQ(expectedDamageRect, rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForAddingAndRemovingLayer)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface();
CCLayerImpl* child1 = root->children()[0].get();
{
OwnPtr<CCLayerImpl> child2 = CCLayerImpl::create(3);
child2->setPosition(FloatPoint(400, 380));
child2->setAnchorPoint(FloatPoint::zero());
child2->setBounds(IntSize(6, 8));
child2->setDrawsContent(true);
root->addChild(child2.release());
}
emulateDrawingOneFrame(root.get());
ASSERT_EQ(3u, root->renderSurface()->layerList().size());
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(400, 380, 6, 8), rootDamageRect);
emulateDrawingOneFrame(root.get());
EXPECT_TRUE(root->renderSurface()->damageTracker()->currentDamageRect().isEmpty());
child1->removeFromParent();
emulateDrawingOneFrame(root.get());
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(100, 100, 30, 30), rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForNewUnchangedLayer)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface();
{
OwnPtr<CCLayerImpl> child2 = CCLayerImpl::create(3);
child2->setPosition(FloatPoint(400, 380));
child2->setAnchorPoint(FloatPoint::zero());
child2->setBounds(IntSize(6, 8));
child2->setDrawsContent(true);
child2->resetAllChangeTrackingForSubtree();
ASSERT_FALSE(child2->layerPropertyChanged());
ASSERT_TRUE(child2->updateRect().isEmpty());
root->addChild(child2.release());
}
emulateDrawingOneFrame(root.get());
ASSERT_EQ(3u, root->renderSurface()->layerList().size());
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(400, 380, 6, 8), rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForMultipleLayers)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface();
CCLayerImpl* child1 = root->children()[0].get();
{
OwnPtr<CCLayerImpl> child2 = CCLayerImpl::create(3);
child2->setPosition(FloatPoint(400, 380));
child2->setAnchorPoint(FloatPoint::zero());
child2->setBounds(IntSize(6, 8));
child2->setDrawsContent(true);
root->addChild(child2.release());
}
CCLayerImpl* child2 = root->children()[1].get();
emulateDrawingOneFrame(root.get());
child1->setUpdateRect(FloatRect(0, 0, 1, 2));
child2->setUpdateRect(FloatRect(0, 0, 3, 4));
emulateDrawingOneFrame(root.get());
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(100, 100, 303, 284), rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForNestedSurfaces)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
CCLayerImpl* child1 = root->children()[0].get();
CCLayerImpl* child2 = root->children()[1].get();
CCLayerImpl* grandChild1 = root->children()[0]->children()[0].get();
FloatRect childDamageRect;
FloatRect rootDamageRect;
grandChild1->setOpacity(0.5);
emulateDrawingOneFrame(root.get());
childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(200, 200, 6, 8), childDamageRect);
EXPECT_FLOAT_RECT_EQ(FloatRect(300, 300, 6, 8), rootDamageRect);
grandChild1->setOpacity(0.7f);
child2->setOpacity(0.7f);
emulateDrawingOneFrame(root.get());
childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(200, 200, 6, 8), childDamageRect);
EXPECT_FLOAT_RECT_EQ(FloatRect(11, 11, 295, 297), rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForSurfaceChangeFromDescendantLayer)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
CCLayerImpl* child1 = root->children()[0].get();
CCLayerImpl* grandChild1 = root->children()[0]->children()[0].get();
FloatRect childDamageRect;
FloatRect rootDamageRect;
grandChild1->setPosition(FloatPoint(195, 205));
emulateDrawingOneFrame(root.get());
childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 11, 23), childDamageRect);
EXPECT_FLOAT_RECT_EQ(FloatRect(290, 290, 16, 23), rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForSurfaceChangeFromAncestorLayer)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
CCLayerImpl* child1 = root->children()[0].get();
FloatRect childDamageRect;
FloatRect rootDamageRect;
child1->setPosition(FloatPoint(50, 50));
emulateDrawingOneFrame(root.get());
childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 16, 18), childDamageRect);
EXPECT_FLOAT_RECT_EQ(FloatRect(240, 240, 66, 68), rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForAddingAndRemovingRenderSurfaces)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
CCLayerImpl* child1 = root->children()[0].get();
FloatRect childDamageRect;
FloatRect rootDamageRect;
child1->setOpacity(1);
emulateDrawingOneFrame(root.get());
ASSERT_FALSE(child1->renderSurface());
ASSERT_EQ(4u, root->renderSurface()->layerList().size());
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(290, 290, 16, 18), rootDamageRect);
emulateDrawingOneFrame(root.get());
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_TRUE(rootDamageRect.isEmpty());
child1->setOpacity(0.5);
emulateDrawingOneFrame(root.get());
ASSERT_TRUE(child1->renderSurface());
EXPECT_EQ(3u, root->renderSurface()->layerList().size());
EXPECT_EQ(2u, child1->renderSurface()->layerList().size());
childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(190, 190, 16, 18), childDamageRect);
EXPECT_FLOAT_RECT_EQ(FloatRect(290, 290, 16, 18), rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyNoDamageWhenNothingChanged)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
CCLayerImpl* child1 = root->children()[0].get();
FloatRect childDamageRect;
FloatRect rootDamageRect;
emulateDrawingOneFrame(root.get());
childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_TRUE(childDamageRect.isEmpty());
EXPECT_TRUE(rootDamageRect.isEmpty());
emulateDrawingOneFrame(root.get());
childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_TRUE(childDamageRect.isEmpty());
EXPECT_TRUE(rootDamageRect.isEmpty());
}
TEST_F(CCDamageTrackerTest, verifyNoDamageForUpdateRectThatDoesNotDrawContent)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
CCLayerImpl* child1 = root->children()[0].get();
FloatRect childDamageRect;
FloatRect rootDamageRect;
child1->setUpdateRect(FloatRect(0, 0, 1, 2));
emulateDrawingOneFrame(root.get());
childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_TRUE(childDamageRect.isEmpty());
EXPECT_TRUE(rootDamageRect.isEmpty());
}
TEST_F(CCDamageTrackerTest, verifyDamageForReplica)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
CCLayerImpl* child1 = root->children()[0].get();
CCLayerImpl* grandChild1 = child1->children()[0].get();
CCLayerImpl* grandChild2 = child1->children()[1].get();
grandChild2->setPosition(FloatPoint(180, 180));
{
OwnPtr<CCLayerImpl> grandChild3 = CCLayerImpl::create(6);
grandChild3->setPosition(FloatPoint(240, 240));
grandChild3->setAnchorPoint(FloatPoint::zero());
grandChild3->setBounds(IntSize(10, 10));
grandChild3->setDrawsContent(true);
child1->addChild(grandChild3.release());
}
child1->setOpacity(0.5);
emulateDrawingOneFrame(root.get());
{
OwnPtr<CCLayerImpl> grandChild1Replica = CCLayerImpl::create(7);
grandChild1Replica->setPosition(FloatPoint::zero());
grandChild1Replica->setAnchorPoint(FloatPoint::zero());
TransformationMatrix reflection;
reflection.scale3d(-1.0, 1.0, 1.0);
grandChild1Replica->setTransform(reflection);
grandChild1->setReplicaLayer(grandChild1Replica.release());
}
emulateDrawingOneFrame(root.get());
FloatRect grandChildDamageRect = grandChild1->renderSurface()->damageTracker()->currentDamageRect();
FloatRect childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 6, 8), grandChildDamageRect);
EXPECT_FLOAT_RECT_EQ(FloatRect(194, 200, 12, 8), childDamageRect);
EXPECT_FLOAT_RECT_EQ(FloatRect(294, 300, 12, 8), rootDamageRect);
IntRect oldContentRect = child1->renderSurface()->contentRect();
grandChild1->setPosition(FloatPoint(195.0, 205.0));
emulateDrawingOneFrame(root.get());
ASSERT_EQ(oldContentRect.width(), child1->renderSurface()->contentRect().width());
ASSERT_EQ(oldContentRect.height(), child1->renderSurface()->contentRect().height());
grandChildDamageRect = grandChild1->renderSurface()->damageTracker()->currentDamageRect();
childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 6, 8), grandChildDamageRect);
EXPECT_FLOAT_RECT_EQ(FloatRect(189, 200, 17, 13), childDamageRect);
EXPECT_FLOAT_RECT_EQ(FloatRect(289, 300, 17, 13), rootDamageRect);
grandChild1->setReplicaLayer(nullptr);
emulateDrawingOneFrame(root.get());
ASSERT_EQ(oldContentRect.width(), child1->renderSurface()->contentRect().width());
ASSERT_EQ(oldContentRect.height(), child1->renderSurface()->contentRect().height());
EXPECT_FALSE(grandChild1->renderSurface());
childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(189, 205, 12, 8), childDamageRect);
EXPECT_FLOAT_RECT_EQ(FloatRect(289, 305, 12, 8), rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForMask)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface();
CCLayerImpl* child = root->children()[0].get();
{
OwnPtr<CCLayerImpl> maskLayer = CCLayerImpl::create(3);
maskLayer->setPosition(child->position());
maskLayer->setAnchorPoint(FloatPoint::zero());
maskLayer->setBounds(child->bounds());
child->setMaskLayer(maskLayer.release());
}
CCLayerImpl* maskLayer = child->maskLayer();
child->setOpacity(0.5);
{
OwnPtr<CCLayerImpl> grandChild = CCLayerImpl::create(4);
grandChild->setPosition(FloatPoint(2.0, 2.0));
grandChild->setAnchorPoint(FloatPoint::zero());
grandChild->setBounds(IntSize(2, 2));
grandChild->setDrawsContent(true);
child->addChild(grandChild.release());
}
emulateDrawingOneFrame(root.get());
ASSERT_TRUE(child->renderSurface());
maskLayer->setUpdateRect(FloatRect(1, 2, 3, 4));
emulateDrawingOneFrame(root.get());
FloatRect childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 30), childDamageRect);
emulateDrawingOneFrame(root.get());
childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_TRUE(childDamageRect.isEmpty());
maskLayer->setOpacity(0.5);
emulateDrawingOneFrame(root.get());
childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 30), childDamageRect);
emulateDrawingOneFrame(root.get());
childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_TRUE(childDamageRect.isEmpty());
child->setMaskLayer(nullptr);
ASSERT_TRUE(child->layerPropertyChanged());
emulateDrawingOneFrame(root.get());
ASSERT_TRUE(child->renderSurface());
childDamageRect = child->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 30), childDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForReplicaMask)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
CCLayerImpl* child1 = root->children()[0].get();
CCLayerImpl* grandChild1 = child1->children()[0].get();
{
OwnPtr<CCLayerImpl> grandChild1Replica = CCLayerImpl::create(6);
grandChild1Replica->setPosition(FloatPoint::zero());
grandChild1Replica->setAnchorPoint(FloatPoint::zero());
TransformationMatrix reflection;
reflection.scale3d(-1.0, 1.0, 1.0);
grandChild1Replica->setTransform(reflection);
grandChild1->setReplicaLayer(grandChild1Replica.release());
}
CCLayerImpl* grandChild1Replica = grandChild1->replicaLayer();
{
OwnPtr<CCLayerImpl> replicaMaskLayer = CCLayerImpl::create(7);
replicaMaskLayer->setPosition(FloatPoint::zero());
replicaMaskLayer->setAnchorPoint(FloatPoint::zero());
replicaMaskLayer->setBounds(grandChild1->bounds());
grandChild1Replica->setMaskLayer(replicaMaskLayer.release());
}
CCLayerImpl* replicaMaskLayer = grandChild1Replica->maskLayer();
emulateDrawingOneFrame(root.get());
ASSERT_TRUE(grandChild1->renderSurface());
replicaMaskLayer->setOpacity(0.6f);
emulateDrawingOneFrame(root.get());
FloatRect grandChildDamageRect = grandChild1->renderSurface()->damageTracker()->currentDamageRect();
FloatRect childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_TRUE(grandChildDamageRect.isEmpty());
EXPECT_FLOAT_RECT_EQ(FloatRect(194, 200, 6, 8), childDamageRect);
grandChild1Replica->setMaskLayer(nullptr);
emulateDrawingOneFrame(root.get());
grandChildDamageRect = grandChild1->renderSurface()->damageTracker()->currentDamageRect();
childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_TRUE(grandChildDamageRect.isEmpty());
EXPECT_FLOAT_RECT_EQ(FloatRect(194, 200, 6, 8), childDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForReplicaMaskWithAnchor)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithTwoSurfaces();
CCLayerImpl* child1 = root->children()[0].get();
CCLayerImpl* grandChild1 = child1->children()[0].get();
grandChild1->setAnchorPoint(FloatPoint(1.0, 0.0));
{
OwnPtr<CCLayerImpl> grandChild1Replica = CCLayerImpl::create(6);
grandChild1Replica->setPosition(FloatPoint::zero());
grandChild1Replica->setAnchorPoint(FloatPoint::zero()); TransformationMatrix reflection;
reflection.scale3d(-1.0, 1.0, 1.0);
grandChild1Replica->setTransform(reflection);
grandChild1->setReplicaLayer(grandChild1Replica.release());
}
CCLayerImpl* grandChild1Replica = grandChild1->replicaLayer();
{
OwnPtr<CCLayerImpl> replicaMaskLayer = CCLayerImpl::create(7);
replicaMaskLayer->setPosition(FloatPoint::zero());
replicaMaskLayer->setAnchorPoint(FloatPoint::zero()); replicaMaskLayer->setBounds(grandChild1->bounds());
grandChild1Replica->setMaskLayer(replicaMaskLayer.release());
}
CCLayerImpl* replicaMaskLayer = grandChild1Replica->maskLayer();
emulateDrawingOneFrame(root.get());
ASSERT_TRUE(grandChild1->renderSurface());
replicaMaskLayer->setOpacity(0.6f);
emulateDrawingOneFrame(root.get());
FloatRect childDamageRect = child1->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(194, 200, 6, 8), childDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageWhenForcedFullDamage)
{
OwnPtr<CCLayerImpl> root = createAndSetUpTestTreeWithOneSurface();
CCLayerImpl* child = root->children()[0].get();
child->setUpdateRect(FloatRect(10, 11, 12, 13));
root->renderSurface()->damageTracker()->forceFullDamageNextUpdate();
emulateDrawingOneFrame(root.get());
FloatRect rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect);
root->renderSurface()->damageTracker()->forceFullDamageNextUpdate();
emulateDrawingOneFrame(root.get());
rootDamageRect = root->renderSurface()->damageTracker()->currentDamageRect();
EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 500, 500), rootDamageRect);
}
TEST_F(CCDamageTrackerTest, verifyDamageForEmptyLayerList)
{
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(1);
root->createRenderSurface();
ASSERT_TRUE(root->renderSurface() == root->targetRenderSurface());
CCRenderSurface* targetSurface = root->renderSurface();
targetSurface->clearLayerList();
targetSurface->damageTracker()->updateDamageTrackingState(targetSurface->layerList(), targetSurface->owningLayerId(), false, IntRect(), 0, FilterOperations());
FloatRect damageRect = targetSurface->damageTracker()->currentDamageRect();
EXPECT_TRUE(damageRect.isEmpty());
}
}