CCLayerTreeHostCommonTest.cpp [plain text]
#include "config.h"
#include "cc/CCLayerTreeHostCommon.h"
#include "CCAnimationTestCommon.h"
#include "CCLayerTreeTestCommon.h"
#include "LayerChromium.h"
#include "TransformationMatrix.h"
#include "TranslateTransformOperation.h"
#include "cc/CCLayerAnimationController.h"
#include "cc/CCMathUtil.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
using namespace WebCore;
using namespace WebKitTests;
namespace {
void setLayerPropertiesForTesting(LayerChromium* layer, const TransformationMatrix& transform, const TransformationMatrix& sublayerTransform, const FloatPoint& anchor, const FloatPoint& position, const IntSize& bounds, bool preserves3D)
{
layer->setTransform(transform);
layer->setSublayerTransform(sublayerTransform);
layer->setAnchorPoint(anchor);
layer->setPosition(position);
layer->setBounds(bounds);
layer->setPreserves3D(preserves3D);
}
void executeCalculateDrawTransformsAndVisibility(LayerChromium* rootLayer)
{
TransformationMatrix identityMatrix;
Vector<RefPtr<LayerChromium> > dummyRenderSurfaceLayerList;
Vector<RefPtr<LayerChromium> > dummyLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(rootLayer, rootLayer, identityMatrix, identityMatrix, dummyRenderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
}
TransformationMatrix remove3DComponentOfMatrix(const TransformationMatrix& mat)
{
TransformationMatrix ret = mat;
ret.setM13(0);
ret.setM23(0);
ret.setM31(0);
ret.setM32(0);
ret.setM33(1);
ret.setM34(0);
ret.setM43(0);
return ret;
}
class LayerChromiumWithForcedDrawsContent : public LayerChromium {
public:
LayerChromiumWithForcedDrawsContent()
: LayerChromium()
{
}
virtual bool drawsContent() const OVERRIDE { return true; }
};
TEST(CCLayerTreeHostCommonTest, verifyTransformsForNoOpLayer)
{
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromium> grandChild = LayerChromium::create();
parent->createRenderSurface();
parent->addChild(child);
child->addChild(grandChild);
TransformationMatrix identityMatrix;
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(0, 0), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(0, 0), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(0, 0), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, parent->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, parent->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForSingleLayer)
{
TransformationMatrix identityMatrix;
RefPtr<LayerChromium> layer = LayerChromium::create();
layer->createRenderSurface();
TransformationMatrix arbitraryTranslation;
arbitraryTranslation.translate(10.0, 20.0);
setLayerPropertiesForTesting(layer.get(), identityMatrix, arbitraryTranslation, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(0, 0), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform());
TransformationMatrix translationToCenter;
translationToCenter.translate(5.0, 6.0);
setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(translationToCenter, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform());
setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0.25f, 0.25f), FloatPoint(2.5f, 3.0f), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(translationToCenter, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform());
TransformationMatrix positionTransform;
positionTransform.translate(0.0, 1.2);
setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0.25f, 0.25f), FloatPoint(2.5f, 4.2f), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform * translationToCenter, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->screenSpaceTransform());
TransformationMatrix layerTransform;
layerTransform.scale3d(2.0, 2.0, 1.0);
setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform * translationToCenter, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->screenSpaceTransform());
TransformationMatrix translationToAnchor;
translationToAnchor.translate(5.0, 0.0);
TransformationMatrix expectedResult = translationToAnchor * layerTransform * translationToAnchor.inverse();
setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0.5f, 0.0f), FloatPoint(5.0f, 0.0f), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult * translationToCenter, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform());
expectedResult = positionTransform * translationToAnchor * layerTransform * translationToAnchor.inverse();
setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0.5f, 0.0f), FloatPoint(5.0f, 1.2f), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult * translationToCenter, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
{
TransformationMatrix identityMatrix;
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromium> grandChild = LayerChromium::create();
parent->createRenderSurface();
parent->addChild(child);
child->addChild(grandChild);
TransformationMatrix childTranslationToCenter, grandChildTranslationToCenter;
childTranslationToCenter.translate(8.0, 9.0);
grandChildTranslationToCenter.translate(38.0, 39.0);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0.25f, 0.25f), FloatPoint(2.5f, 3.0f), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(childTranslationToCenter, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(grandChildTranslationToCenter, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTransform());
TransformationMatrix parentPositionTransform;
parentPositionTransform.translate(0.0, 1.2);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0.25f, 0.25f), FloatPoint(2.5f, 4.2f), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform * childTranslationToCenter, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform * grandChildTranslationToCenter, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->screenSpaceTransform());
TransformationMatrix parentLayerTransform;
parentLayerTransform.scale3d(2.0, 2.0, 1.0);
TransformationMatrix parentTranslationToAnchor;
parentTranslationToAnchor.translate(2.5, 3.0);
TransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse();
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, identityMatrix, FloatPoint(0.25f, 0.25f), FloatPoint(2.5f, 3.0f), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform * childTranslationToCenter, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform * grandChildTranslationToCenter, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screenSpaceTransform());
TransformationMatrix parentSublayerMatrix;
parentSublayerMatrix.scale3d(10.0, 10.0, 3.3);
TransformationMatrix parentTranslationToCenter;
parentTranslationToCenter.translate(5.0, 6.0);
parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
* parentTranslationToCenter * parentSublayerMatrix * parentTranslationToCenter.inverse();
TransformationMatrix flattenedCompositeTransform = remove3DComponentOfMatrix(parentCompositeTransform);
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25f, 0.25f), FloatPoint(2.5f, 3.0f), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform * childTranslationToCenter, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform * grandChildTranslationToCenter, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->screenSpaceTransform());
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25f, 0.25f), FloatPoint(2.5f, 3.0f), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(16, 18), true);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform * childTranslationToCenter, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform * grandChildTranslationToCenter, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface)
{
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> grandChild = adoptRef(new LayerChromiumWithForcedDrawsContent());
parent->createRenderSurface();
parent->addChild(child);
child->addChild(grandChild);
child->setOpacity(0.5f);
TransformationMatrix identityMatrix;
TransformationMatrix parentLayerTransform;
parentLayerTransform.scale3d(2.0, 2.0, 1.0);
TransformationMatrix parentTranslationToAnchor;
parentTranslationToAnchor.translate(2.5, 3.0);
TransformationMatrix parentSublayerMatrix;
parentSublayerMatrix.scale3d(10.0, 10.0, 3.3);
TransformationMatrix parentTranslationToCenter;
parentTranslationToCenter.translate(5.0, 6.0);
TransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
* parentTranslationToCenter * parentSublayerMatrix * parentTranslationToCenter.inverse();
TransformationMatrix childTranslationToCenter;
childTranslationToCenter.translate(8.0, 9.0);
ASSERT_FALSE(child->renderSurface());
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25f, 0.25f), FloatPoint(2.5f, 3.0f), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(-0.5f, -0.5f), IntSize(1, 1), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
ASSERT_TRUE(child->renderSurface());
ASSERT_EQ(child->renderSurface(), child->targetRenderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(childTranslationToCenter, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->targetRenderSurface()->originTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->targetRenderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->targetRenderSurface()->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForReplica)
{
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromium> childReplica = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> grandChild = adoptRef(new LayerChromiumWithForcedDrawsContent());
parent->createRenderSurface();
parent->addChild(child);
child->addChild(grandChild);
child->setReplicaLayer(childReplica.get());
child->setOpacity(0.5f);
TransformationMatrix identityMatrix;
TransformationMatrix parentLayerTransform;
parentLayerTransform.scale3d(2.0, 2.0, 1.0);
TransformationMatrix parentTranslationToAnchor;
parentTranslationToAnchor.translate(2.5, 3.0);
TransformationMatrix parentSublayerMatrix;
parentSublayerMatrix.scale3d(10.0, 10.0, 3.3);
TransformationMatrix parentTranslationToCenter;
parentTranslationToCenter.translate(5.0, 6.0);
TransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
* parentTranslationToCenter * parentSublayerMatrix * parentTranslationToCenter.inverse();
TransformationMatrix childTranslationToCenter;
childTranslationToCenter.translate(8.0, 9.0);
TransformationMatrix replicaLayerTransform;
replicaLayerTransform.scale3d(3.0, 3.0, 1.0);
TransformationMatrix replicaCompositeTransform = parentCompositeTransform * replicaLayerTransform;
ASSERT_FALSE(child->renderSurface());
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25f, 0.25f), FloatPoint(2.5f, 3.0f), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(-0.5f, -0.5f), IntSize(1, 1), false);
setLayerPropertiesForTesting(childReplica.get(), replicaLayerTransform, identityMatrix, FloatPoint(0.0f, 0.0f), FloatPoint(0.0f, 0.0f), IntSize(0, 0), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
ASSERT_TRUE(child->renderSurface());
ASSERT_EQ(child->renderSurface(), child->targetRenderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->targetRenderSurface()->replicaOriginTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->targetRenderSurface()->replicaScreenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy)
{
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
RefPtr<LayerChromium> renderSurface2 = LayerChromium::create();
RefPtr<LayerChromium> childOfRoot = LayerChromium::create();
RefPtr<LayerChromium> childOfRS1 = LayerChromium::create();
RefPtr<LayerChromium> childOfRS2 = LayerChromium::create();
RefPtr<LayerChromium> replicaOfRS1 = LayerChromium::create();
RefPtr<LayerChromium> replicaOfRS2 = LayerChromium::create();
RefPtr<LayerChromium> grandChildOfRoot = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> grandChildOfRS1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> grandChildOfRS2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
parent->createRenderSurface();
parent->addChild(renderSurface1);
parent->addChild(childOfRoot);
renderSurface1->addChild(childOfRS1);
renderSurface1->addChild(renderSurface2);
renderSurface2->addChild(childOfRS2);
childOfRoot->addChild(grandChildOfRoot);
childOfRS1->addChild(grandChildOfRS1);
childOfRS2->addChild(grandChildOfRS2);
renderSurface1->setReplicaLayer(replicaOfRS1.get());
renderSurface2->setReplicaLayer(replicaOfRS2.get());
renderSurface1->setOpacity(0.5f);
renderSurface2->setOpacity(0.33f);
TransformationMatrix translationToAnchor;
translationToAnchor.translate(2.5, 0.0);
TransformationMatrix translationToCenter;
translationToCenter.translate(5.0, 5.0);
TransformationMatrix layerTransform;
layerTransform.translate(1.0, 1.0);
TransformationMatrix sublayerTransform;
sublayerTransform.scale3d(10.0, 1.0, 1.0);
TransformationMatrix replicaLayerTransform;
replicaLayerTransform.scale3d(-2.0, 5.0, 1.0);
TransformationMatrix A = translationToAnchor * layerTransform * translationToAnchor.inverse();
TransformationMatrix B = translationToCenter * sublayerTransform * translationToCenter.inverse();
TransformationMatrix R = A * translationToAnchor * replicaLayerTransform * translationToAnchor.inverse();
setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(replicaOfRS1.get(), replicaLayerTransform, sublayerTransform, FloatPoint(), FloatPoint(2.5f, 0.0f), IntSize(), false);
setLayerPropertiesForTesting(replicaOfRS2.get(), replicaLayerTransform, sublayerTransform, FloatPoint(), FloatPoint(2.5f, 0.0f), IntSize(), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
ASSERT_TRUE(parent->renderSurface());
ASSERT_FALSE(childOfRoot->renderSurface());
ASSERT_FALSE(grandChildOfRoot->renderSurface());
ASSERT_TRUE(renderSurface1->renderSurface());
ASSERT_FALSE(childOfRS1->renderSurface());
ASSERT_FALSE(grandChildOfRS1->renderSurface());
ASSERT_TRUE(renderSurface2->renderSurface());
ASSERT_FALSE(childOfRS2->renderSurface());
ASSERT_FALSE(grandChildOfRS2->renderSurface());
EXPECT_EQ(parent->renderSurface(), parent->targetRenderSurface());
EXPECT_EQ(parent->renderSurface(), childOfRoot->targetRenderSurface());
EXPECT_EQ(parent->renderSurface(), grandChildOfRoot->targetRenderSurface());
EXPECT_EQ(renderSurface1->renderSurface(), renderSurface1->targetRenderSurface());
EXPECT_EQ(renderSurface1->renderSurface(), childOfRS1->targetRenderSurface());
EXPECT_EQ(renderSurface1->renderSurface(), grandChildOfRS1->targetRenderSurface());
EXPECT_EQ(renderSurface2->renderSurface(), renderSurface2->targetRenderSurface());
EXPECT_EQ(renderSurface2->renderSurface(), childOfRS2->targetRenderSurface());
EXPECT_EQ(renderSurface2->renderSurface(), grandChildOfRS2->targetRenderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * translationToCenter, parent->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * translationToCenter, childOfRoot->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * translationToCenter, grandChildOfRoot->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(translationToCenter, renderSurface1->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A * translationToCenter, childOfRS1->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A * B * A * translationToCenter, grandChildOfRS1->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(translationToCenter, renderSurface2->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A * translationToCenter, childOfRS2->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A * B * A * translationToCenter, grandChildOfRS2->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, childOfRoot->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, grandChildOfRoot->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, renderSurface1->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, childOfRS1->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A, grandChildOfRS1->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, renderSurface2->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A, childOfRS2->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A * B * A, grandChildOfRS2->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, renderSurface1->renderSurface()->originTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * R, renderSurface1->renderSurface()->replicaOriginTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, renderSurface1->renderSurface()->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * R, renderSurface1->renderSurface()->replicaScreenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A, renderSurface2->renderSurface()->originTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * R, renderSurface2->renderSurface()->replicaOriginTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, renderSurface2->renderSurface()->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * R, renderSurface2->renderSurface()->replicaScreenSpaceTransform());
EXPECT_FLOAT_EQ(1.0, parent->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(2.0, childOfRoot->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3.0, grandChildOfRoot->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(2.0, renderSurface1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3.0, childOfRS1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(4.0, grandChildOfRS1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3.0, renderSurface2->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(4.0, childOfRS2->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(5.0, grandChildOfRS2->screenSpaceTransform().m42());
}
TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceListForClipLayer)
{
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> child = adoptRef(new LayerChromiumWithForcedDrawsContent());
renderSurface1->setOpacity(0.9f);
const TransformationMatrix identityMatrix;
setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint(30, 30), IntSize(10, 10), false);
parent->createRenderSurface();
parent->setClipRect(IntRect(0, 0, 10, 10));
parent->addChild(renderSurface1);
renderSurface1->createRenderSurface();
renderSurface1->addChild(child);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
Vector<RefPtr<LayerChromium> > dummyLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
ASSERT_FALSE(renderSurface1->renderSurface());
EXPECT_EQ(renderSurfaceLayerList.size(), 0U);
}
TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceListForTransparentChild)
{
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> child = adoptRef(new LayerChromiumWithForcedDrawsContent());
renderSurface1->setOpacity(0);
const TransformationMatrix identityMatrix;
setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
parent->createRenderSurface();
parent->addChild(renderSurface1);
renderSurface1->createRenderSurface();
renderSurface1->addChild(child);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
Vector<RefPtr<LayerChromium> > dummyLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
EXPECT_EQ(parent->renderSurface()->layerList().size(), 0U);
EXPECT_EQ(renderSurfaceLayerList.size(), 0U);
EXPECT_EQ(parent->drawableContentRect(), IntRect());
}
TEST(CCLayerTreeHostCommonTest, verifyClipRectCullsRenderSurfaces)
{
const TransformationMatrix identityMatrix;
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromium> grandChild = LayerChromium::create();
RefPtr<LayerChromium> greatGrandChild = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> leafNode1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> leafNode2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
parent->createRenderSurface();
parent->addChild(child);
child->addChild(grandChild);
grandChild->addChild(greatGrandChild);
child->addChild(leafNode1);
greatGrandChild->addChild(leafNode2);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false);
setLayerPropertiesForTesting(greatGrandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false);
setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false);
child->setMasksToBounds(true);
child->setOpacity(0.4f);
grandChild->setOpacity(0.5f);
greatGrandChild->setOpacity(0.4f);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
Vector<RefPtr<LayerChromium> > dummyLayerList;
int dummyMaxTextureSize = 512;
parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
renderSurfaceLayerList.append(parent.get());
CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
ASSERT_EQ(2U, renderSurfaceLayerList.size());
EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
EXPECT_EQ(child->id(), renderSurfaceLayerList[1]->id());
}
TEST(CCLayerTreeHostCommonTest, verifyClipRectCullsRenderSurfacesCrashRepro)
{
const TransformationMatrix identityMatrix;
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromium> grandChild = LayerChromium::create();
RefPtr<LayerChromium> greatGrandChild = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> leafNode1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> leafNode2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
parent->createRenderSurface();
parent->addChild(child);
child->addChild(grandChild);
grandChild->addChild(greatGrandChild);
child->addChild(leafNode1);
greatGrandChild->addChild(leafNode2);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false);
setLayerPropertiesForTesting(greatGrandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false);
setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false);
child->setMasksToBounds(true);
child->setOpacity(0.4f);
grandChild->setOpacity(0.5f);
greatGrandChild->setOpacity(0.4f);
child->setClipRect(IntRect(IntPoint::zero(), IntSize(20, 20)));
greatGrandChild->setClipRect(IntRect(IntPoint::zero(), IntSize(1234, 1234)));
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
Vector<RefPtr<LayerChromium> > dummyLayerList;
int dummyMaxTextureSize = 512;
parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
renderSurfaceLayerList.append(parent.get());
CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
ASSERT_EQ(2U, renderSurfaceLayerList.size());
EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
EXPECT_EQ(child->id(), renderSurfaceLayerList[1]->id());
}
TEST(CCLayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToLayers)
{
const TransformationMatrix identityMatrix;
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromium> grandChild1 = LayerChromium::create();
RefPtr<LayerChromium> grandChild2 = LayerChromium::create();
RefPtr<LayerChromium> grandChild3 = LayerChromium::create();
RefPtr<LayerChromium> grandChild4 = LayerChromium::create();
parent->createRenderSurface();
parent->addChild(child);
child->addChild(grandChild1);
child->addChild(grandChild2);
child->addChild(grandChild3);
child->addChild(grandChild4);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false);
setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChild4.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false);
child->setMasksToBounds(true);
grandChild3->setMasksToBounds(true);
grandChild4->setMasksToBounds(true);
child->setOpacity(0.4f);
grandChild1->setOpacity(0.5f);
grandChild2->setOpacity(0.5f);
grandChild3->setOpacity(0.5f);
grandChild4->setOpacity(0.5f);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
Vector<RefPtr<LayerChromium> > dummyLayerList;
int dummyMaxTextureSize = 512;
parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
renderSurfaceLayerList.append(parent.get());
CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
EXPECT_INT_RECT_EQ(IntRect(IntPoint::zero(), IntSize(20, 20)), grandChild1->clipRect());
EXPECT_INT_RECT_EQ(IntRect(IntPoint::zero(), IntSize(20, 20)), grandChild2->clipRect());
EXPECT_INT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->clipRect());
EXPECT_TRUE(grandChild4->clipRect().isEmpty());
}
TEST(CCLayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToSurfaces)
{
const TransformationMatrix identityMatrix;
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromium> grandChild1 = LayerChromium::create();
RefPtr<LayerChromium> grandChild2 = LayerChromium::create();
RefPtr<LayerChromium> grandChild3 = LayerChromium::create();
RefPtr<LayerChromium> grandChild4 = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> leafNode1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> leafNode2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> leafNode3 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> leafNode4 = adoptRef(new LayerChromiumWithForcedDrawsContent());
parent->createRenderSurface();
parent->addChild(child);
child->addChild(grandChild1);
child->addChild(grandChild2);
child->addChild(grandChild3);
child->addChild(grandChild4);
grandChild1->addChild(leafNode1);
grandChild2->addChild(leafNode2);
grandChild3->addChild(leafNode3);
grandChild4->addChild(leafNode4);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false);
setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChild4.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false);
setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(leafNode3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(leafNode4.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
child->setMasksToBounds(true);
grandChild3->setMasksToBounds(true);
grandChild4->setMasksToBounds(true);
child->setOpacity(0.4f);
grandChild1->setOpacity(0.5f);
grandChild2->setOpacity(0.5f);
grandChild3->setOpacity(0.5f);
grandChild4->setOpacity(0.5f);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
Vector<RefPtr<LayerChromium> > dummyLayerList;
int dummyMaxTextureSize = 512;
parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
renderSurfaceLayerList.append(parent.get());
CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
ASSERT_TRUE(grandChild1->renderSurface());
ASSERT_TRUE(grandChild2->renderSurface());
ASSERT_TRUE(grandChild3->renderSurface());
EXPECT_FALSE(grandChild4->renderSurface());
EXPECT_INT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild1->renderSurface()->clipRect());
EXPECT_INT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild2->renderSurface()->clipRect());
EXPECT_INT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild3->renderSurface()->clipRect());
EXPECT_FALSE(grandChild1->usesLayerClipping());
EXPECT_FALSE(grandChild2->usesLayerClipping());
EXPECT_TRUE(grandChild3->usesLayerClipping());
EXPECT_TRUE(grandChild4->usesLayerClipping());
}
TEST(CCLayerTreeHostCommonTest, verifyAnimationsForRenderSurfaceHierarchy)
{
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
RefPtr<LayerChromium> renderSurface2 = LayerChromium::create();
RefPtr<LayerChromium> childOfRoot = LayerChromium::create();
RefPtr<LayerChromium> childOfRS1 = LayerChromium::create();
RefPtr<LayerChromium> childOfRS2 = LayerChromium::create();
RefPtr<LayerChromium> grandChildOfRoot = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> grandChildOfRS1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> grandChildOfRS2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
parent->createRenderSurface();
parent->addChild(renderSurface1);
parent->addChild(childOfRoot);
renderSurface1->addChild(childOfRS1);
renderSurface1->addChild(renderSurface2);
renderSurface2->addChild(childOfRS2);
childOfRoot->addChild(grandChildOfRoot);
childOfRS1->addChild(grandChildOfRS1);
childOfRS2->addChild(grandChildOfRS2);
addOpacityTransitionToController(*renderSurface1->layerAnimationController(), 10, 1, 0, false);
addOpacityTransitionToController(*grandChildOfRoot->layerAnimationController(), 10, 1, 0, false);
TransformationMatrix layerTransform;
layerTransform.translate(1.0, 1.0);
TransformationMatrix sublayerTransform;
sublayerTransform.scale3d(10.0, 1.0, 1.0);
addAnimatedTransformToController(*renderSurface2->layerAnimationController(), 10, 30, 0);
addAnimatedTransformToController(*grandChildOfRoot->layerAnimationController(), 10, 30, 0);
addAnimatedTransformToController(*grandChildOfRS2->layerAnimationController(), 10, 30, 0);
setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayerTransform, FloatPoint(0.25f, 0.0f), FloatPoint(2.5f, 0.0f), IntSize(10, 10), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
ASSERT_TRUE(parent->renderSurface());
ASSERT_FALSE(childOfRoot->renderSurface());
ASSERT_FALSE(grandChildOfRoot->renderSurface());
ASSERT_TRUE(renderSurface1->renderSurface());
ASSERT_FALSE(childOfRS1->renderSurface());
ASSERT_FALSE(grandChildOfRS1->renderSurface());
ASSERT_TRUE(renderSurface2->renderSurface());
ASSERT_FALSE(childOfRS2->renderSurface());
ASSERT_FALSE(grandChildOfRS2->renderSurface());
EXPECT_EQ(parent->renderSurface(), parent->targetRenderSurface());
EXPECT_EQ(parent->renderSurface(), childOfRoot->targetRenderSurface());
EXPECT_EQ(parent->renderSurface(), grandChildOfRoot->targetRenderSurface());
EXPECT_EQ(renderSurface1->renderSurface(), renderSurface1->targetRenderSurface());
EXPECT_EQ(renderSurface1->renderSurface(), childOfRS1->targetRenderSurface());
EXPECT_EQ(renderSurface1->renderSurface(), grandChildOfRS1->targetRenderSurface());
EXPECT_EQ(renderSurface2->renderSurface(), renderSurface2->targetRenderSurface());
EXPECT_EQ(renderSurface2->renderSurface(), childOfRS2->targetRenderSurface());
EXPECT_EQ(renderSurface2->renderSurface(), grandChildOfRS2->targetRenderSurface());
EXPECT_FALSE(parent->drawOpacityIsAnimating());
EXPECT_FALSE(childOfRoot->drawOpacityIsAnimating());
EXPECT_TRUE(grandChildOfRoot->drawOpacityIsAnimating());
EXPECT_FALSE(renderSurface1->drawOpacityIsAnimating());
EXPECT_TRUE(renderSurface1->renderSurface()->drawOpacityIsAnimating());
EXPECT_FALSE(childOfRS1->drawOpacityIsAnimating());
EXPECT_FALSE(grandChildOfRS1->drawOpacityIsAnimating());
EXPECT_FALSE(renderSurface2->drawOpacityIsAnimating());
EXPECT_FALSE(renderSurface2->renderSurface()->drawOpacityIsAnimating());
EXPECT_FALSE(childOfRS2->drawOpacityIsAnimating());
EXPECT_FALSE(grandChildOfRS2->drawOpacityIsAnimating());
EXPECT_FALSE(parent->drawTransformIsAnimating());
EXPECT_FALSE(childOfRoot->drawTransformIsAnimating());
EXPECT_TRUE(grandChildOfRoot->drawTransformIsAnimating());
EXPECT_FALSE(renderSurface1->drawTransformIsAnimating());
EXPECT_FALSE(renderSurface1->renderSurface()->targetSurfaceTransformsAreAnimating());
EXPECT_FALSE(childOfRS1->drawTransformIsAnimating());
EXPECT_FALSE(grandChildOfRS1->drawTransformIsAnimating());
EXPECT_FALSE(renderSurface2->drawTransformIsAnimating());
EXPECT_TRUE(renderSurface2->renderSurface()->targetSurfaceTransformsAreAnimating());
EXPECT_FALSE(childOfRS2->drawTransformIsAnimating());
EXPECT_TRUE(grandChildOfRS2->drawTransformIsAnimating());
EXPECT_FALSE(parent->screenSpaceTransformIsAnimating());
EXPECT_FALSE(childOfRoot->screenSpaceTransformIsAnimating());
EXPECT_TRUE(grandChildOfRoot->screenSpaceTransformIsAnimating());
EXPECT_FALSE(renderSurface1->screenSpaceTransformIsAnimating());
EXPECT_FALSE(renderSurface1->renderSurface()->screenSpaceTransformsAreAnimating());
EXPECT_FALSE(childOfRS1->screenSpaceTransformIsAnimating());
EXPECT_FALSE(grandChildOfRS1->screenSpaceTransformIsAnimating());
EXPECT_TRUE(renderSurface2->screenSpaceTransformIsAnimating());
EXPECT_TRUE(renderSurface2->renderSurface()->screenSpaceTransformsAreAnimating());
EXPECT_TRUE(childOfRS2->screenSpaceTransformIsAnimating());
EXPECT_TRUE(grandChildOfRS2->screenSpaceTransformIsAnimating());
EXPECT_FLOAT_EQ(1.0, parent->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(2.0, childOfRoot->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3.0, grandChildOfRoot->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(2.0, renderSurface1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3.0, childOfRS1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(4.0, grandChildOfRS1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3.0, renderSurface2->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(4.0, childOfRS2->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(5.0, grandChildOfRS2->screenSpaceTransform().m42());
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectForIdentityTransform)
{
IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100));
TransformationMatrix layerToSurfaceTransform;
IntRect layerContentRect = IntRect(IntPoint(10, 10), IntSize(30, 30));
IntRect expected = IntRect(IntPoint(10, 10), IntSize(30, 30));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
layerContentRect = IntRect(IntPoint(120, 120), IntSize(30, 30));
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_TRUE(actual.isEmpty());
layerContentRect = IntRect(IntPoint(80, 80), IntSize(30, 30));
expected = IntRect(IntPoint(80, 80), IntSize(20, 20));
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectForTranslations)
{
IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100));
IntRect layerContentRect = IntRect(IntPoint(0, 0), IntSize(30, 30));
TransformationMatrix layerToSurfaceTransform;
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.translate(10, 10);
IntRect expected = IntRect(IntPoint(0, 0), IntSize(30, 30));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.translate(120, 120);
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_TRUE(actual.isEmpty());
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.translate(80, 80);
expected = IntRect(IntPoint(0, 0), IntSize(20, 20));
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor2DRotations)
{
IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100));
IntRect layerContentRect = IntRect(IntPoint(0, 0), IntSize(30, 30));
TransformationMatrix layerToSurfaceTransform;
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.translate(50, 50);
layerToSurfaceTransform.rotate(45);
IntRect expected = IntRect(IntPoint(0, 0), IntSize(30, 30));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.translate(-50, 0);
layerToSurfaceTransform.rotate(45);
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_TRUE(actual.isEmpty());
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.rotate(45);
expected = IntRect(IntPoint(0, 0), IntSize(30, 30));
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.translate(0, -sqrt(2.0) * 15);
layerToSurfaceTransform.rotate(45);
expected = IntRect(IntPoint(15, 0), IntSize(15, 30)); actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicTransform)
{
IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100));
IntRect layerContentRect = IntRect(IntPoint(0, 0), IntSize(100, 100));
TransformationMatrix layerToSurfaceTransform;
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.rotate3d(0, 45, 0);
IntRect expected = IntRect(IntPoint(0, 0), IntSize(100, 100));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
double halfWidthOfRotatedLayer = (100.0 / sqrt(2.0)) * 0.5; layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.translate(-halfWidthOfRotatedLayer, 0);
layerToSurfaceTransform.rotate3d(0, 45, 0); expected = IntRect(IntPoint(50, 0), IntSize(50, 100)); actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveTransform)
{
IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100));
IntRect layerContentRect = IntRect(IntPoint(-50, -50), IntSize(200, 200));
TransformationMatrix layerToSurfaceTransform;
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.translate(50, 50);
layerToSurfaceTransform.applyPerspective(9);
layerToSurfaceTransform.translate(-50, -50);
layerToSurfaceTransform.translate3d(0, 0, -27);
IntRect expected = IntRect(IntPoint(-50, -50), IntSize(200, 200));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
layerToSurfaceTransform.translate3d(-200, 0, 0);
expected = IntRect(IntPoint(50, -50), IntSize(100, 200)); actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dOrthographicIsNotClippedBehindSurface)
{
IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100));
IntRect layerContentRect = IntRect(IntPoint(0, 0), IntSize(100, 100));
TransformationMatrix layerToSurfaceTransform;
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.translate(50, 0);
layerToSurfaceTransform.rotate3d(0, 45, 0);
layerToSurfaceTransform.translate(-50, 0);
IntRect expected = IntRect(IntPoint(0, 0), IntSize(100, 100));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveIsClipped)
{
IntRect targetSurfaceRect = IntRect(IntPoint(-50, -50), IntSize(100, 100));
IntRect layerContentRect = IntRect(IntPoint(-10, -1), IntSize(20, 2));
TransformationMatrix layerToSurfaceTransform;
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.applyPerspective(1);
layerToSurfaceTransform.translate3d(0, 0, 1);
layerToSurfaceTransform.rotate3d(0, 45, 0);
bool clipped = false;
CCMathUtil::mapQuad(layerToSurfaceTransform, FloatQuad(FloatRect(layerContentRect)), clipped);
ASSERT_TRUE(clipped);
int expectedXPosition = -10;
int expectedWidth = 10;
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_EQ(expectedXPosition, actual.x());
EXPECT_EQ(expectedWidth, actual.width());
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectForPerspectiveUnprojection)
{
IntRect targetSurfaceRect = IntRect(IntPoint(-50, -50), IntSize(100, 100));
IntRect layerContentRect = IntRect(IntPoint(-10, -10), IntSize(20, 20));
TransformationMatrix layerToSurfaceTransform;
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.applyPerspective(1);
layerToSurfaceTransform.translate3d(0, 0, -5);
layerToSurfaceTransform.rotate3d(0, 45, 0);
layerToSurfaceTransform.rotate3d(80, 0, 0);
bool clipped = false;
FloatRect clippedRect = CCMathUtil::mapClippedRect(layerToSurfaceTransform, layerContentRect);
CCMathUtil::projectQuad(layerToSurfaceTransform.inverse(), FloatQuad(clippedRect), clipped);
ASSERT_TRUE(clipped);
IntRect expected = IntRect(IntPoint(-10, -10), IntSize(20, 20));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_INT_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyBackFaceCulling)
{
const TransformationMatrix identityMatrix;
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> child = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> animatingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> childOfAnimatingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> animatingChild = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> child2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
parent->createRenderSurface();
parent->addChild(child);
parent->addChild(animatingSurface);
animatingSurface->addChild(childOfAnimatingSurface);
parent->addChild(animatingChild);
parent->addChild(child2);
child->setDoubleSided(false);
child2->setDoubleSided(false);
animatingSurface->setDoubleSided(false);
childOfAnimatingSurface->setDoubleSided(false);
animatingChild->setDoubleSided(false);
TransformationMatrix backfaceMatrix;
backfaceMatrix.translate(50, 50);
backfaceMatrix.rotate3d(0, 1, 0, 180);
backfaceMatrix.translate(-50, -50);
addAnimatedTransformToController(*animatingSurface->layerAnimationController(), 10, 30, 0);
addAnimatedTransformToController(*animatingChild->layerAnimationController(), 10, 30, 0);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true);
setLayerPropertiesForTesting(child.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(animatingSurface.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(childOfAnimatingSurface.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(animatingChild.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
Vector<RefPtr<LayerChromium> > dummyLayerList;
int dummyMaxTextureSize = 512;
parent->renderSurface()->setContentRect(IntRect(IntPoint(), parent->bounds()));
parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
renderSurfaceLayerList.append(parent.get());
CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
EXPECT_FALSE(child->renderSurface());
EXPECT_TRUE(animatingSurface->renderSurface());
EXPECT_FALSE(childOfAnimatingSurface->renderSurface());
EXPECT_FALSE(animatingChild->renderSurface());
EXPECT_FALSE(child2->renderSurface());
ASSERT_EQ(2u, renderSurfaceLayerList.size());
EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[1]->id());
ASSERT_EQ(3u, renderSurfaceLayerList[0]->renderSurface()->layerList().size());
EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[0]->renderSurface()->layerList()[0]->id());
EXPECT_EQ(animatingChild->id(), renderSurfaceLayerList[0]->renderSurface()->layerList()[1]->id());
EXPECT_EQ(child2->id(), renderSurfaceLayerList[0]->renderSurface()->layerList()[2]->id());
ASSERT_EQ(2u, renderSurfaceLayerList[1]->renderSurface()->layerList().size());
EXPECT_EQ(animatingSurface->id(), renderSurfaceLayerList[1]->renderSurface()->layerList()[0]->id());
EXPECT_EQ(childOfAnimatingSurface->id(), renderSurfaceLayerList[1]->renderSurface()->layerList()[1]->id());
EXPECT_FALSE(child2->visibleLayerRect().isEmpty());
EXPECT_TRUE(animatingChild->visibleLayerRect().isEmpty());
EXPECT_TRUE(animatingSurface->visibleLayerRect().isEmpty());
EXPECT_TRUE(childOfAnimatingSurface->visibleLayerRect().isEmpty());
}
}