#include "config.h"
#include "CCLayerTreeHostCommon.h"
#include "CCAnimationTestCommon.h"
#include "CCGeometryTestUtils.h"
#include "CCLayerAnimationController.h"
#include "CCLayerImpl.h"
#include "CCLayerSorter.h"
#include "CCMathUtil.h"
#include "CCProxy.h"
#include "CCSingleThreadProxy.h"
#include "CCThread.h"
#include "ContentLayerChromium.h"
#include "ContentLayerChromiumClient.h"
#include "LayerChromium.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <public/WebTransformationMatrix.h>
using namespace cc;
using namespace WebKitTests;
using WebKit::WebTransformationMatrix;
namespace {
template<typename LayerType>
void setLayerPropertiesForTesting(LayerType* layer, const WebTransformationMatrix& transform, const WebTransformationMatrix& 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 setLayerPropertiesForTesting(LayerChromium* layer, const WebTransformationMatrix& transform, const WebTransformationMatrix& sublayerTransform, const FloatPoint& anchor, const FloatPoint& position, const IntSize& bounds, bool preserves3D)
{
setLayerPropertiesForTesting<LayerChromium>(layer, transform, sublayerTransform, anchor, position, bounds, preserves3D);
}
void setLayerPropertiesForTesting(CCLayerImpl* layer, const WebTransformationMatrix& transform, const WebTransformationMatrix& sublayerTransform, const FloatPoint& anchor, const FloatPoint& position, const IntSize& bounds, bool preserves3D)
{
setLayerPropertiesForTesting<CCLayerImpl>(layer, transform, sublayerTransform, anchor, position, bounds, preserves3D);
layer->setContentBounds(bounds);
}
void executeCalculateDrawTransformsAndVisibility(LayerChromium* rootLayer, float deviceScaleFactor = 1)
{
WebTransformationMatrix identityMatrix;
Vector<RefPtr<LayerChromium> > dummyRenderSurfaceLayerList;
int dummyMaxTextureSize = 512;
IntSize deviceViewportSize = IntSize(rootLayer->bounds().width() * deviceScaleFactor, rootLayer->bounds().height() * deviceScaleFactor);
ASSERT(!rootLayer->bounds().isEmpty());
CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, dummyMaxTextureSize, dummyRenderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(dummyRenderSurfaceLayerList);
}
void executeCalculateDrawTransformsAndVisibility(CCLayerImpl* rootLayer, float deviceScaleFactor = 1)
{
WebTransformationMatrix identityMatrix;
Vector<CCLayerImpl*> dummyRenderSurfaceLayerList;
int dummyMaxTextureSize = 512;
IntSize deviceViewportSize = IntSize(rootLayer->bounds().width() * deviceScaleFactor, rootLayer->bounds().height() * deviceScaleFactor);
ASSERT(!rootLayer->bounds().isEmpty());
CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, 0, dummyMaxTextureSize, dummyRenderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(dummyRenderSurfaceLayerList);
}
WebTransformationMatrix remove3DComponentOfMatrix(const WebTransformationMatrix& mat)
{
WebTransformationMatrix 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;
}
PassOwnPtr<CCLayerImpl> createTreeForFixedPositionTests()
{
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(1);
OwnPtr<CCLayerImpl> child = CCLayerImpl::create(2);
OwnPtr<CCLayerImpl> grandChild = CCLayerImpl::create(3);
OwnPtr<CCLayerImpl> greatGrandChild = CCLayerImpl::create(4);
WebTransformationMatrix IdentityMatrix;
FloatPoint anchor(0, 0);
FloatPoint position(0, 0);
IntSize bounds(100, 100);
setLayerPropertiesForTesting(root.get(), IdentityMatrix, IdentityMatrix, anchor, position, bounds, false);
setLayerPropertiesForTesting(child.get(), IdentityMatrix, IdentityMatrix, anchor, position, bounds, false);
setLayerPropertiesForTesting(grandChild.get(), IdentityMatrix, IdentityMatrix, anchor, position, bounds, false);
setLayerPropertiesForTesting(greatGrandChild.get(), IdentityMatrix, IdentityMatrix, anchor, position, bounds, false);
grandChild->addChild(greatGrandChild.release());
child->addChild(grandChild.release());
root->addChild(child.release());
return root.release();
}
class LayerChromiumWithForcedDrawsContent : public LayerChromium {
public:
LayerChromiumWithForcedDrawsContent()
: LayerChromium()
{
}
virtual bool drawsContent() const OVERRIDE { return true; }
};
class MockContentLayerChromiumClient : public ContentLayerChromiumClient {
public:
MockContentLayerChromiumClient() { }
virtual ~MockContentLayerChromiumClient() { }
virtual void paintContents(SkCanvas*, const IntRect& clip, FloatRect& opaque) OVERRIDE { }
};
PassRefPtr<ContentLayerChromium> createDrawableContentLayerChromium(ContentLayerChromiumClient* delegate)
{
RefPtr<ContentLayerChromium> toReturn = ContentLayerChromium::create(delegate);
toReturn->setIsDrawable(true);
return toReturn.release();
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForNoOpLayer)
{
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromium> grandChild = LayerChromium::create();
parent->addChild(child);
child->addChild(grandChild);
WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
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)
{
WebTransformationMatrix identityMatrix;
RefPtr<LayerChromium> layer = LayerChromium::create();
WebTransformationMatrix arbitraryTranslation;
arbitraryTranslation.translate(10, 20);
setLayerPropertiesForTesting(layer.get(), identityMatrix, arbitraryTranslation, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
WebTransformationMatrix expectedDrawTransform = identityMatrix;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform());
WebTransformationMatrix translationToCenter;
translationToCenter.translate(5, 6);
setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform());
setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform());
WebTransformationMatrix positionTransform;
positionTransform.translate(0, 1.2);
setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->screenSpaceTransform());
WebTransformationMatrix layerTransform;
layerTransform.scale3d(2, 2, 1);
setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->screenSpaceTransform());
WebTransformationMatrix translationToAnchor;
translationToAnchor.translate(5, 0);
WebTransformationMatrix expectedResult = translationToAnchor * layerTransform * translationToAnchor.inverse();
setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0.5, 0), FloatPoint(0, 0), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform());
expectedResult = positionTransform * translationToAnchor * layerTransform * translationToAnchor.inverse();
setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0.5, 0), FloatPoint(0, 1.2f), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
{
WebTransformationMatrix identityMatrix;
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromium> grandChild = LayerChromium::create();
parent->addChild(child);
child->addChild(grandChild);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
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());
WebTransformationMatrix parentPositionTransform;
parentPositionTransform.translate(0, 1.2);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->screenSpaceTransform());
WebTransformationMatrix parentLayerTransform;
parentLayerTransform.scale3d(2, 2, 1);
WebTransformationMatrix parentTranslationToAnchor;
parentTranslationToAnchor.translate(2.5, 3);
WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse();
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screenSpaceTransform());
WebTransformationMatrix parentSublayerMatrix;
parentSublayerMatrix.scale3d(10, 10, 3.3);
WebTransformationMatrix parentTranslationToCenter;
parentTranslationToCenter.translate(5, 6);
parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
* parentTranslationToCenter * parentSublayerMatrix * parentTranslationToCenter.inverse();
WebTransformationMatrix flattenedCompositeTransform = remove3DComponentOfMatrix(parentCompositeTransform);
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->screenSpaceTransform());
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), true);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, 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->addChild(child);
child->addChild(grandChild);
child->setOpacity(0.5);
WebTransformationMatrix identityMatrix;
WebTransformationMatrix parentLayerTransform;
parentLayerTransform.scale3d(1, 0.9, 1);
WebTransformationMatrix parentTranslationToAnchor;
parentTranslationToAnchor.translate(25, 30);
WebTransformationMatrix parentSublayerMatrix;
parentSublayerMatrix.scale3d(0.9, 1, 3.3);
WebTransformationMatrix parentTranslationToCenter;
parentTranslationToCenter.translate(50, 60);
WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
* parentTranslationToCenter * parentSublayerMatrix * parentTranslationToCenter.inverse();
ASSERT_FALSE(child->renderSurface());
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(100, 120), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(8, 10), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
ASSERT_TRUE(child->renderSurface());
ASSERT_EQ(child, child->renderTarget());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->renderTarget()->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->renderTarget()->renderSurface()->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->addChild(child);
child->addChild(grandChild);
child->setReplicaLayer(childReplica.get());
child->setOpacity(0.5);
WebTransformationMatrix identityMatrix;
WebTransformationMatrix parentLayerTransform;
parentLayerTransform.scale3d(2, 2, 1);
WebTransformationMatrix parentTranslationToAnchor;
parentTranslationToAnchor.translate(2.5, 3);
WebTransformationMatrix parentSublayerMatrix;
parentSublayerMatrix.scale3d(10, 10, 3.3);
WebTransformationMatrix parentTranslationToCenter;
parentTranslationToCenter.translate(5, 6);
WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
* parentTranslationToCenter * parentSublayerMatrix * parentTranslationToCenter.inverse();
WebTransformationMatrix childTranslationToCenter;
childTranslationToCenter.translate(8, 9);
WebTransformationMatrix replicaLayerTransform;
replicaLayerTransform.scale3d(3, 3, 1);
WebTransformationMatrix replicaCompositeTransform = parentCompositeTransform * replicaLayerTransform;
ASSERT_FALSE(child->renderSurface());
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(-0.5, -0.5), IntSize(1, 1), false);
setLayerPropertiesForTesting(childReplica.get(), replicaLayerTransform, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
ASSERT_TRUE(child->renderSurface());
ASSERT_EQ(child, child->renderTarget());
EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarget()->renderSurface()->replicaDrawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarget()->renderSurface()->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->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.5);
renderSurface2->setOpacity(0.33f);
WebTransformationMatrix translationToAnchor;
translationToAnchor.translate(2.5, 0);
WebTransformationMatrix translationToCenter;
translationToCenter.translate(5, 5);
WebTransformationMatrix layerTransform;
layerTransform.translate(1, 1);
WebTransformationMatrix sublayerTransform;
sublayerTransform.scale3d(10, 1, 1);
WebTransformationMatrix replicaLayerTransform;
replicaLayerTransform.scale3d(-2, 5, 1);
WebTransformationMatrix A = translationToAnchor * layerTransform * translationToAnchor.inverse();
WebTransformationMatrix B = translationToCenter * sublayerTransform * translationToCenter.inverse();
WebTransformationMatrix R = A * translationToAnchor * replicaLayerTransform * translationToAnchor.inverse();
WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(replicaOfRS1.get(), replicaLayerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false);
setLayerPropertiesForTesting(replicaOfRS2.get(), replicaLayerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), 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, parent->renderTarget());
EXPECT_EQ(parent, childOfRoot->renderTarget());
EXPECT_EQ(parent, grandChildOfRoot->renderTarget());
EXPECT_EQ(renderSurface1, renderSurface1->renderTarget());
EXPECT_EQ(renderSurface1, childOfRS1->renderTarget());
EXPECT_EQ(renderSurface1, grandChildOfRS1->renderTarget());
EXPECT_EQ(renderSurface2, renderSurface2->renderTarget());
EXPECT_EQ(renderSurface2, childOfRS2->renderTarget());
EXPECT_EQ(renderSurface2, grandChildOfRS2->renderTarget());
EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, childOfRoot->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, grandChildOfRoot->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, renderSurface1->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A, childOfRS1->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A * B * A, grandChildOfRS1->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, renderSurface2->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A, childOfRS2->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A * B * A, 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()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * R, renderSurface1->renderSurface()->replicaDrawTransform());
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()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * R, renderSurface2->renderSurface()->replicaDrawTransform());
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, parent->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(2, childOfRoot->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3, grandChildOfRoot->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(2, renderSurface1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3, childOfRS1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(4, grandChildOfRS1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3, renderSurface2->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(4, childOfRS2->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(5, grandChildOfRS2->screenSpaceTransform().m42());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForFlatteningLayer)
{
RefPtr<LayerChromium> root = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> grandChild = adoptRef(new LayerChromiumWithForcedDrawsContent());
WebTransformationMatrix rotationAboutYAxis;
rotationAboutYAxis.rotate3d(0, 30, 0);
const WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(100, 100), false);
setLayerPropertiesForTesting(child.get(), rotationAboutYAxis, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChild.get(), rotationAboutYAxis, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
root->addChild(child);
child->addChild(grandChild);
child->setForceRenderSurface(true);
ASSERT_FALSE(root->preserves3D());
ASSERT_FALSE(child->preserves3D());
ASSERT_FALSE(grandChild->preserves3D());
WebTransformationMatrix expectedChildDrawTransform = rotationAboutYAxis;
WebTransformationMatrix expectedChildScreenSpaceTransform = rotationAboutYAxis;
WebTransformationMatrix expectedGrandChildDrawTransform = rotationAboutYAxis;
WebTransformationMatrix expectedGrandChildScreenSpaceTransform = rotationAboutYAxis.to2dTransform() * rotationAboutYAxis;
executeCalculateDrawTransformsAndVisibility(root.get());
ASSERT_TRUE(child->renderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildDrawTransform, child->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->renderSurface()->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildDrawTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildScreenSpaceTransform, grandChild->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForDegenerateIntermediateLayer)
{
RefPtr<LayerChromium> root = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> grandChild = adoptRef(new LayerChromiumWithForcedDrawsContent());
const WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(100, 100), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 0), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
root->addChild(child);
child->addChild(grandChild);
child->setForceRenderSurface(true);
executeCalculateDrawTransformsAndVisibility(root.get());
ASSERT_TRUE(child->renderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceListForRenderSurfaceWithClippedLayer)
{
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> child = adoptRef(new LayerChromiumWithForcedDrawsContent());
const WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
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->addChild(renderSurface1);
parent->setMasksToBounds(true);
renderSurface1->addChild(child);
renderSurface1->setForceRenderSurface(true);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_TRUE(parent->renderSurface());
ASSERT_FALSE(renderSurface1->renderSurface());
EXPECT_EQ(1U, renderSurfaceLayerList.size());
}
TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceListForTransparentChild)
{
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> child = adoptRef(new LayerChromiumWithForcedDrawsContent());
const WebTransformationMatrix 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->addChild(renderSurface1);
renderSurface1->addChild(child);
renderSurface1->setForceRenderSurface(true);
renderSurface1->setOpacity(0);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_TRUE(parent->renderSurface());
EXPECT_EQ(0U, parent->renderSurface()->layerList().size());
EXPECT_EQ(1U, renderSurfaceLayerList.size());
EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
EXPECT_EQ(IntRect(), parent->drawableContentRect());
}
TEST(CCLayerTreeHostCommonTest, verifyForceRenderSurface)
{
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> child = adoptRef(new LayerChromiumWithForcedDrawsContent());
renderSurface1->setForceRenderSurface(true);
const WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
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->addChild(renderSurface1);
renderSurface1->addChild(child);
EXPECT_FALSE(parent->renderSurface());
EXPECT_FALSE(renderSurface1->renderSurface());
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
EXPECT_TRUE(parent->renderSurface());
EXPECT_TRUE(renderSurface1->renderSurface());
EXPECT_EQ(2U, renderSurfaceLayerList.size());
renderSurfaceLayerList.clear();
renderSurface1->setForceRenderSurface(false);
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
EXPECT_TRUE(parent->renderSurface());
EXPECT_FALSE(renderSurface1->renderSurface());
EXPECT_EQ(1U, renderSurfaceLayerList.size());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithDirectContainer)
{
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
child->setIsContainerForFixedPositionLayers(true);
grandChild->setFixedToContainerLayer(true);
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
WebTransformationMatrix expectedGrandChildTransform = expectedChildTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
child->setScrollDelta(IntSize(10, 10));
executeCalculateDrawTransformsAndVisibility(root.get());
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, -10);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithTransformedDirectContainer)
{
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
WebTransformationMatrix nonUniformScale;
nonUniformScale.scaleNonUniform(2, 8);
child->setTransform(nonUniformScale);
child->setIsContainerForFixedPositionLayers(true);
grandChild->setFixedToContainerLayer(true);
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
expectedChildTransform.multiply(nonUniformScale);
WebTransformationMatrix expectedGrandChildTransform = expectedChildTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
child->setScrollDelta(IntSize(10, 20));
executeCalculateDrawTransformsAndVisibility(root.get());
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, -20);
expectedChildTransform.multiply(nonUniformScale);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithDistantContainer)
{
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
CCLayerImpl* greatGrandChild = grandChild->children()[0];
child->setIsContainerForFixedPositionLayers(true);
grandChild->setPosition(FloatPoint(8, 6));
greatGrandChild->setFixedToContainerLayer(true);
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
WebTransformationMatrix expectedGrandChildTransform;
expectedGrandChildTransform.translate(8, 6);
WebTransformationMatrix expectedGreatGrandChildTransform = expectedGrandChildTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
child->setScrollDelta(IntSize(10, 10));
executeCalculateDrawTransformsAndVisibility(root.get());
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, -10);
expectedGrandChildTransform.makeIdentity();
expectedGrandChildTransform.translate(-2, -4);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithDistantContainerAndTransforms)
{
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
CCLayerImpl* greatGrandChild = grandChild->children()[0];
WebTransformationMatrix rotationAboutZ;
rotationAboutZ.rotate3d(0, 0, 90);
child->setIsContainerForFixedPositionLayers(true);
child->setTransform(rotationAboutZ);
grandChild->setPosition(FloatPoint(8, 6));
grandChild->setTransform(rotationAboutZ);
greatGrandChild->setFixedToContainerLayer(true);
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
expectedChildTransform.multiply(rotationAboutZ);
WebTransformationMatrix expectedGrandChildTransform;
expectedGrandChildTransform.multiply(rotationAboutZ);
expectedGrandChildTransform.translate(8, 6);
expectedGrandChildTransform.multiply(rotationAboutZ);
WebTransformationMatrix expectedGreatGrandChildTransform = expectedGrandChildTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
child->setScrollDelta(IntSize(10, 20));
executeCalculateDrawTransformsAndVisibility(root.get());
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, -20);
expectedChildTransform.multiply(rotationAboutZ);
expectedGrandChildTransform.makeIdentity();
expectedGrandChildTransform.translate(-10, -20);
expectedGrandChildTransform.multiply(rotationAboutZ);
expectedGrandChildTransform.translate(8, 6);
expectedGrandChildTransform.multiply(rotationAboutZ);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithMultipleScrollDeltas)
{
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
CCLayerImpl* greatGrandChild = grandChild->children()[0];
WebTransformationMatrix rotationAboutZ;
rotationAboutZ.rotate3d(0, 0, 90);
child->setIsContainerForFixedPositionLayers(true);
child->setTransform(rotationAboutZ);
grandChild->setPosition(FloatPoint(8, 6));
grandChild->setTransform(rotationAboutZ);
greatGrandChild->setFixedToContainerLayer(true);
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
expectedChildTransform.multiply(rotationAboutZ);
WebTransformationMatrix expectedGrandChildTransform;
expectedGrandChildTransform.multiply(rotationAboutZ);
expectedGrandChildTransform.translate(8, 6);
expectedGrandChildTransform.multiply(rotationAboutZ);
WebTransformationMatrix expectedGreatGrandChildTransform = expectedGrandChildTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
child->setScrollDelta(IntSize(10, 0));
grandChild->setScrollDelta(IntSize(5, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, 0);
expectedChildTransform.multiply(rotationAboutZ);
expectedGrandChildTransform.makeIdentity();
expectedGrandChildTransform.translate(-10, 0);
expectedGrandChildTransform.multiply(rotationAboutZ);
expectedGrandChildTransform.translate(-5, 0);
expectedGrandChildTransform.translate(8, 6);
expectedGrandChildTransform.multiply(rotationAboutZ);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithIntermediateSurfaceAndTransforms)
{
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
CCLayerImpl* greatGrandChild = grandChild->children()[0];
child->setIsContainerForFixedPositionLayers(true);
grandChild->setPosition(FloatPoint(8, 6));
grandChild->setForceRenderSurface(true);
greatGrandChild->setFixedToContainerLayer(true);
greatGrandChild->setDrawsContent(true);
WebTransformationMatrix rotationAboutZ;
rotationAboutZ.rotate3d(0, 0, 90);
grandChild->setTransform(rotationAboutZ);
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
WebTransformationMatrix expectedSurfaceDrawTransform;
expectedSurfaceDrawTransform.translate(8, 6);
expectedSurfaceDrawTransform.multiply(rotationAboutZ);
WebTransformationMatrix expectedGrandChildTransform;
WebTransformationMatrix expectedGreatGrandChildTransform;
ASSERT_TRUE(grandChild->renderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, grandChild->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
child->setScrollDelta(IntSize(10, 30));
executeCalculateDrawTransformsAndVisibility(root.get());
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, -30);
expectedSurfaceDrawTransform.makeIdentity();
expectedSurfaceDrawTransform.translate(-10, -30);
expectedSurfaceDrawTransform.translate(8, 6);
expectedSurfaceDrawTransform.multiply(rotationAboutZ);
expectedGreatGrandChildTransform.makeIdentity();
expectedGreatGrandChildTransform.multiply(rotationAboutZ.inverse());
expectedGreatGrandChildTransform.translate(10, 30);
expectedGreatGrandChildTransform.multiply(rotationAboutZ);
ASSERT_TRUE(grandChild->renderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, grandChild->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithMultipleIntermediateSurfaces)
{
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
CCLayerImpl* greatGrandChild = grandChild->children()[0];
{
WebTransformationMatrix identity;
OwnPtr<CCLayerImpl> fixedPositionChild = CCLayerImpl::create(5);
setLayerPropertiesForTesting(fixedPositionChild.get(), identity, identity, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
greatGrandChild->addChild(fixedPositionChild.release());
}
CCLayerImpl* fixedPositionChild = greatGrandChild->children()[0];
child->setIsContainerForFixedPositionLayers(true);
grandChild->setPosition(FloatPoint(8, 6));
grandChild->setForceRenderSurface(true);
greatGrandChild->setPosition(FloatPoint(40, 60));
greatGrandChild->setForceRenderSurface(true);
fixedPositionChild->setFixedToContainerLayer(true);
fixedPositionChild->setDrawsContent(true);
WebTransformationMatrix rotationAboutZ;
rotationAboutZ.translate(50, 50);
rotationAboutZ.rotate3d(0, 0, 90);
rotationAboutZ.translate(-50, -50);
grandChild->setTransform(rotationAboutZ);
greatGrandChild->setTransform(rotationAboutZ);
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
WebTransformationMatrix expectedGrandChildSurfaceDrawTransform;
expectedGrandChildSurfaceDrawTransform.translate(8, 6);
expectedGrandChildSurfaceDrawTransform.multiply(rotationAboutZ);
WebTransformationMatrix expectedGrandChildTransform;
WebTransformationMatrix expectedGreatGrandChildSurfaceDrawTransform;
expectedGreatGrandChildSurfaceDrawTransform.translate(40, 60);
expectedGreatGrandChildSurfaceDrawTransform.multiply(rotationAboutZ);
WebTransformationMatrix expectedGreatGrandChildTransform;
WebTransformationMatrix expectedFixedPositionChildTransform;
ASSERT_TRUE(grandChild->renderSurface());
ASSERT_TRUE(greatGrandChild->renderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildSurfaceDrawTransform, grandChild->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildSurfaceDrawTransform, greatGrandChild->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedFixedPositionChildTransform, fixedPositionChild->drawTransform());
child->setScrollDelta(IntSize(10, 30));
executeCalculateDrawTransformsAndVisibility(root.get());
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, -30);
expectedGrandChildSurfaceDrawTransform.makeIdentity();
expectedGrandChildSurfaceDrawTransform.translate(-10, -30);
expectedGrandChildSurfaceDrawTransform.translate(8, 6);
expectedGrandChildSurfaceDrawTransform.multiply(rotationAboutZ);
WebTransformationMatrix compoundDrawTransform;
compoundDrawTransform.translate(8, 6);
compoundDrawTransform.multiply(rotationAboutZ);
compoundDrawTransform.translate(40, 60);
compoundDrawTransform.multiply(rotationAboutZ);
expectedFixedPositionChildTransform.makeIdentity();
expectedFixedPositionChildTransform.multiply(compoundDrawTransform.inverse());
expectedFixedPositionChildTransform.translate(10, 30);
expectedFixedPositionChildTransform.multiply(compoundDrawTransform);
ASSERT_TRUE(grandChild->renderSurface());
ASSERT_TRUE(greatGrandChild->renderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildSurfaceDrawTransform, grandChild->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildSurfaceDrawTransform, greatGrandChild->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedFixedPositionChildTransform, fixedPositionChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithContainerLayerThatHasSurface)
{
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
child->setIsContainerForFixedPositionLayers(true);
child->setForceRenderSurface(true);
grandChild->setFixedToContainerLayer(true);
grandChild->setDrawsContent(true);
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedSurfaceDrawTransform;
expectedSurfaceDrawTransform.translate(0, 0);
WebTransformationMatrix expectedChildTransform;
WebTransformationMatrix expectedGrandChildTransform;
ASSERT_TRUE(child->renderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, child->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
child->setScrollDelta(IntSize(10, 10));
executeCalculateDrawTransformsAndVisibility(root.get());
expectedSurfaceDrawTransform.makeIdentity();
expectedSurfaceDrawTransform.translate(-10, -10);
expectedGrandChildTransform.makeIdentity();
expectedGrandChildTransform.translate(10, 10);
ASSERT_TRUE(child->renderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, child->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerThatIsAlsoFixedPositionContainer)
{
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
child->setIsContainerForFixedPositionLayers(true);
grandChild->setFixedToContainerLayer(true);
grandChild->setIsContainerForFixedPositionLayers(true);
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
WebTransformationMatrix expectedGrandChildTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
child->setScrollDelta(IntSize(10, 10));
executeCalculateDrawTransformsAndVisibility(root.get());
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, -10);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerThatHasNoContainer)
{
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
WebTransformationMatrix rotationByZ;
rotationByZ.rotate3d(0, 0, 90);
root->setTransform(rotationByZ);
grandChild->setFixedToContainerLayer(true);
root->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
expectedChildTransform.multiply(rotationByZ);
WebTransformationMatrix expectedGrandChildTransform;
expectedGrandChildTransform.multiply(rotationByZ);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
root->setScrollDelta(IntSize(10, 10));
executeCalculateDrawTransformsAndVisibility(root.get());
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, -10);
expectedChildTransform.multiply(rotationByZ);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyClipRectCullsRenderSurfaces)
{
const WebTransformationMatrix 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->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.5);
greatGrandChild->setOpacity(0.4f);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_EQ(2U, renderSurfaceLayerList.size());
EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
EXPECT_EQ(child->id(), renderSurfaceLayerList[1]->id());
}
TEST(CCLayerTreeHostCommonTest, verifyClipRectCullsSurfaceWithoutVisibleContent)
{
const WebTransformationMatrix identityMatrix;
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromium> grandChild = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> leafNode = adoptRef(new LayerChromiumWithForcedDrawsContent());
parent->addChild(child);
child->addChild(grandChild);
grandChild->addChild(leafNode);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), 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(200, 200), IntSize(10, 10), false);
setLayerPropertiesForTesting(leafNode.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
parent->setMasksToBounds(true);
child->setOpacity(0.4f);
grandChild->setOpacity(0.4f);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
ASSERT_EQ(1U, renderSurfaceLayerList.size());
EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
addAnimatedTransformToController(*child->layerAnimationController(), 10, 30, 0);
parent->clearRenderSurface();
child->clearRenderSurface();
grandChild->clearRenderSurface();
renderSurfaceLayerList.clear();
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
ASSERT_EQ(3U, renderSurfaceLayerList.size());
EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
EXPECT_EQ(child->id(), renderSurfaceLayerList[1]->id());
EXPECT_EQ(grandChild->id(), renderSurfaceLayerList[2]->id());
}
TEST(CCLayerTreeHostCommonTest, verifyDrawableContentRectForLayers)
{
const WebTransformationMatrix 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->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);
child->setOpacity(0.4f);
grandChild1->setOpacity(0.5);
grandChild2->setOpacity(0.5);
grandChild3->setOpacity(0.5);
grandChild4->setOpacity(0.5);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
EXPECT_RECT_EQ(IntRect(IntPoint(5, 5), IntSize(10, 10)), grandChild1->drawableContentRect());
EXPECT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->drawableContentRect());
EXPECT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->drawableContentRect());
EXPECT_TRUE(grandChild4->drawableContentRect().isEmpty());
}
TEST(CCLayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToSurfaces)
{
const WebTransformationMatrix 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->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.5);
grandChild2->setOpacity(0.5);
grandChild3->setOpacity(0.5);
grandChild4->setOpacity(0.5);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_TRUE(grandChild1->renderSurface());
ASSERT_TRUE(grandChild2->renderSurface());
ASSERT_TRUE(grandChild3->renderSurface());
EXPECT_FALSE(grandChild4->renderSurface());
EXPECT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild1->renderSurface()->clipRect());
EXPECT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild2->renderSurface()->clipRect());
EXPECT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild3->renderSurface()->clipRect());
}
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->addChild(renderSurface1);
parent->addChild(childOfRoot);
renderSurface1->addChild(childOfRS1);
renderSurface1->addChild(renderSurface2);
renderSurface2->addChild(childOfRS2);
childOfRoot->addChild(grandChildOfRoot);
childOfRS1->addChild(grandChildOfRS1);
childOfRS2->addChild(grandChildOfRS2);
renderSurface1->setForceRenderSurface(true);
renderSurface2->setForceRenderSurface(true);
addOpacityTransitionToController(*renderSurface1->layerAnimationController(), 10, 1, 0, false);
addOpacityTransitionToController(*grandChildOfRoot->layerAnimationController(), 10, 1, 0, false);
WebTransformationMatrix layerTransform;
layerTransform.translate(1, 1);
WebTransformationMatrix sublayerTransform;
sublayerTransform.scale3d(10, 1, 1);
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.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(2.5, 0), 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, parent->renderTarget());
EXPECT_EQ(parent, childOfRoot->renderTarget());
EXPECT_EQ(parent, grandChildOfRoot->renderTarget());
EXPECT_EQ(renderSurface1, renderSurface1->renderTarget());
EXPECT_EQ(renderSurface1, childOfRS1->renderTarget());
EXPECT_EQ(renderSurface1, grandChildOfRS1->renderTarget());
EXPECT_EQ(renderSurface2, renderSurface2->renderTarget());
EXPECT_EQ(renderSurface2, childOfRS2->renderTarget());
EXPECT_EQ(renderSurface2, grandChildOfRS2->renderTarget());
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, parent->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(2, childOfRoot->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3, grandChildOfRoot->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(2, renderSurface1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3, childOfRS1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(4, grandChildOfRS1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3, renderSurface2->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(4, childOfRS2->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(5, grandChildOfRS2->screenSpaceTransform().m42());
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectForIdentityTransform)
{
IntRect targetSurfaceRect = IntRect(IntPoint(0, 0), IntSize(100, 100));
WebTransformationMatrix 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_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_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));
WebTransformationMatrix layerToSurfaceTransform;
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.translate(10, 10);
IntRect expected = IntRect(IntPoint(0, 0), IntSize(30, 30));
IntRect actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_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_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));
WebTransformationMatrix 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_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_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_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));
WebTransformationMatrix 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_RECT_EQ(expected, actual);
double halfWidthOfRotatedLayer = (100 / 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_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));
WebTransformationMatrix 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_RECT_EQ(expected, actual);
layerToSurfaceTransform.translate3d(-200, 0, 0);
expected = IntRect(IntPoint(50, -50), IntSize(100, 200));
actual = CCLayerTreeHostCommon::calculateVisibleRect(targetSurfaceRect, layerContentRect, layerToSurfaceTransform);
EXPECT_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));
WebTransformationMatrix 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_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyVisibleRectFor3dPerspectiveWhenClippedByW)
{
IntRect targetSurfaceRect = IntRect(IntPoint(-50, -50), IntSize(100, 100));
IntRect layerContentRect = IntRect(IntPoint(-10, -1), IntSize(20, 2));
WebTransformationMatrix layerToSurfaceTransform;
layerToSurfaceTransform.makeIdentity();
layerToSurfaceTransform.applyPerspective(1);
layerToSurfaceTransform.translate3d(-2, 0, 1);
layerToSurfaceTransform.rotate3d(0, 45, 0);
bool clipped = false;
CCMathUtil::mapQuad(layerToSurfaceTransform, FloatQuad(FloatRect(layerContentRect)), clipped);
ASSERT_TRUE(clipped);
int expectedXPosition = 0;
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));
WebTransformationMatrix 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_RECT_EQ(expected, actual);
}
TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSimpleLayers)
{
RefPtr<LayerChromium> root = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> child2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> child3 = adoptRef(new LayerChromiumWithForcedDrawsContent());
root->addChild(child1);
root->addChild(child2);
root->addChild(child3);
WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(50, 50), false);
setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false);
setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false);
executeCalculateDrawTransformsAndVisibility(root.get());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 25, 25), child2->visibleContentRect());
EXPECT_TRUE(child3->visibleContentRect().isEmpty());
EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->drawableContentRect());
EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect());
EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect());
}
TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersClippedByLayer)
{
RefPtr<LayerChromium> root = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> grandChild1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> grandChild2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> grandChild3 = adoptRef(new LayerChromiumWithForcedDrawsContent());
root->addChild(child);
child->addChild(grandChild1);
child->addChild(grandChild2);
child->addChild(grandChild3);
WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false);
setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false);
setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false);
child->setMasksToBounds(true);
executeCalculateDrawTransformsAndVisibility(root.get());
ASSERT_FALSE(child->renderSurface());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), child->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), grandChild1->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 25, 25), grandChild2->visibleContentRect());
EXPECT_TRUE(grandChild3->visibleContentRect().isEmpty());
EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), grandChild1->drawableContentRect());
EXPECT_RECT_EQ(IntRect(75, 75, 25, 25), grandChild2->drawableContentRect());
EXPECT_TRUE(grandChild3->drawableContentRect().isEmpty());
}
TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface)
{
RefPtr<LayerChromium> root = LayerChromium::create();
RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> child2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> child3 = adoptRef(new LayerChromiumWithForcedDrawsContent());
root->addChild(renderSurface1);
renderSurface1->addChild(child1);
renderSurface1->addChild(child2);
renderSurface1->addChild(child3);
WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false);
setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false);
setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false);
setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false);
renderSurface1->setForceRenderSurface(true);
executeCalculateDrawTransformsAndVisibility(root.get());
ASSERT_TRUE(renderSurface1->renderSurface());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect());
EXPECT_RECT_EQ(IntRect(5, 5, 170, 170), renderSurface1->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child2->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child3->visibleContentRect());
EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), child1->drawableContentRect());
EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect());
EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect());
}
TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForLayersInClippedRenderSurface)
{
RefPtr<LayerChromium> root = LayerChromium::create();
RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> child2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> child3 = adoptRef(new LayerChromiumWithForcedDrawsContent());
root->addChild(renderSurface1);
renderSurface1->addChild(child1);
renderSurface1->addChild(child2);
renderSurface1->addChild(child3);
WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false);
setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false);
setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false);
setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false);
root->setMasksToBounds(true);
renderSurface1->setForceRenderSurface(true);
executeCalculateDrawTransformsAndVisibility(root.get());
ASSERT_TRUE(renderSurface1->renderSurface());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect());
EXPECT_RECT_EQ(IntRect(5, 5, 95, 95), renderSurface1->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 25, 25), child2->visibleContentRect());
EXPECT_TRUE(child3->visibleContentRect().isEmpty());
EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), child1->drawableContentRect());
EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect());
EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect());
}
TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsForSurfaceHierarchy)
{
RefPtr<LayerChromium> root = LayerChromium::create();
RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
RefPtr<LayerChromium> renderSurface2 = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> child2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> child3 = adoptRef(new LayerChromiumWithForcedDrawsContent());
root->addChild(renderSurface1);
renderSurface1->addChild(renderSurface2);
renderSurface2->addChild(child1);
renderSurface2->addChild(child2);
renderSurface2->addChild(child3);
WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false);
setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(7, 13), false);
setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false);
setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false);
setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false);
root->setMasksToBounds(true);
renderSurface1->setForceRenderSurface(true);
renderSurface2->setForceRenderSurface(true);
executeCalculateDrawTransformsAndVisibility(root.get());
ASSERT_TRUE(renderSurface1->renderSurface());
ASSERT_TRUE(renderSurface2->renderSurface());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface2->visibleContentRect());
EXPECT_RECT_EQ(IntRect(5, 5, 95, 95), renderSurface1->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(5, 5, 170, 170), renderSurface2->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child2->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child3->visibleContentRect());
EXPECT_RECT_EQ(IntRect(5, 5, 50, 50), child1->drawableContentRect());
EXPECT_RECT_EQ(IntRect(75, 75, 50, 50), child2->drawableContentRect());
EXPECT_RECT_EQ(IntRect(125, 125, 50, 50), child3->drawableContentRect());
}
TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsWithTransformOnUnclippedSurface)
{
RefPtr<LayerChromium> root = LayerChromium::create();
RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
root->addChild(renderSurface1);
renderSurface1->addChild(child1);
WebTransformationMatrix identityMatrix;
WebTransformationMatrix childRotation;
childRotation.rotate(45);
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false);
setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, FloatPoint(0.5, 0.5), FloatPoint(25, 25), IntSize(50, 50), false);
renderSurface1->setForceRenderSurface(true);
executeCalculateDrawTransformsAndVisibility(root.get());
ASSERT_TRUE(renderSurface1->renderSurface());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), root->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), renderSurface1->visibleContentRect());
int diagonalRadius = ceil(sqrt(2.0) * 25);
IntRect expectedSurfaceDrawableContent = IntRect(50 - diagonalRadius, 50 - diagonalRadius, diagonalRadius * 2, diagonalRadius * 2);
EXPECT_RECT_EQ(expectedSurfaceDrawableContent, renderSurface1->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 50, 50), child1->visibleContentRect());
EXPECT_RECT_EQ(expectedSurfaceDrawableContent, child1->drawableContentRect());
}
TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsWithTransformOnClippedSurface)
{
RefPtr<LayerChromium> root = LayerChromium::create();
RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
root->addChild(renderSurface1);
renderSurface1->addChild(child1);
WebTransformationMatrix identityMatrix;
WebTransformationMatrix childRotation;
childRotation.rotate(45);
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(50, 50), false);
setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(3, 4), false);
setLayerPropertiesForTesting(child1.get(), childRotation, identityMatrix, FloatPoint(0.5, 0.5), FloatPoint(25, 25), IntSize(50, 50), false);
root->setMasksToBounds(true);
renderSurface1->setForceRenderSurface(true);
executeCalculateDrawTransformsAndVisibility(root.get());
ASSERT_TRUE(renderSurface1->renderSurface());
int diagonalRadius = ceil(sqrt(2.0) * 25);
IntRect unclippedSurfaceContent = IntRect(50 - diagonalRadius, 50 - diagonalRadius, diagonalRadius * 2, diagonalRadius * 2);
IntRect expectedSurfaceDrawableContent = intersection(unclippedSurfaceContent, IntRect(0, 0, 50, 50));
EXPECT_RECT_EQ(expectedSurfaceDrawableContent, renderSurface1->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 26, 50), child1->visibleContentRect());
EXPECT_RECT_EQ(unclippedSurfaceContent, child1->drawableContentRect());
}
TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsInHighDPI)
{
MockContentLayerChromiumClient client;
RefPtr<LayerChromium> root = LayerChromium::create();
RefPtr<ContentLayerChromium> renderSurface1 = createDrawableContentLayerChromium(&client);
RefPtr<ContentLayerChromium> renderSurface2 = createDrawableContentLayerChromium(&client);
RefPtr<ContentLayerChromium> child1 = createDrawableContentLayerChromium(&client);
RefPtr<ContentLayerChromium> child2 = createDrawableContentLayerChromium(&client);
RefPtr<ContentLayerChromium> child3 = createDrawableContentLayerChromium(&client);
root->addChild(renderSurface1);
renderSurface1->addChild(renderSurface2);
renderSurface2->addChild(child1);
renderSurface2->addChild(child2);
renderSurface2->addChild(child3);
WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(3, 4), false);
setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(7, 13), false);
setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false);
setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false);
setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false);
const double deviceScaleFactor = 2;
root->setContentsScale(deviceScaleFactor);
renderSurface1->setContentsScale(deviceScaleFactor);
renderSurface2->setContentsScale(deviceScaleFactor);
child1->setContentsScale(deviceScaleFactor);
child2->setContentsScale(deviceScaleFactor);
child3->setContentsScale(deviceScaleFactor);
root->setMasksToBounds(true);
renderSurface1->setForceRenderSurface(true);
renderSurface2->setForceRenderSurface(true);
executeCalculateDrawTransformsAndVisibility(root.get(), deviceScaleFactor);
ASSERT_TRUE(renderSurface1->renderSurface());
ASSERT_TRUE(renderSurface2->renderSurface());
EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), root->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), root->drawableContentRect());
EXPECT_RECT_EQ(IntRect(10, 10, 190, 190), renderSurface1->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(10, 10, 350, 350), renderSurface2->renderSurface()->drawableContentRect());
EXPECT_RECT_EQ(IntRect(10, 10, 100, 100), child1->drawableContentRect());
EXPECT_RECT_EQ(IntRect(150, 150, 100, 100), child2->drawableContentRect());
EXPECT_RECT_EQ(IntRect(250, 250, 100, 100), child3->drawableContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 6, 8), renderSurface1->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 14, 26), renderSurface2->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), child1->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), child2->visibleContentRect());
EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), child3->visibleContentRect());
}
TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithoutPreserves3d)
{
const WebTransformationMatrix identityMatrix;
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> frontFacingChild = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> backFacingChild = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> frontFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> backFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> frontFacingChildOfFrontFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> backFacingChildOfFrontFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> frontFacingChildOfBackFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> backFacingChildOfBackFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
parent->addChild(frontFacingChild);
parent->addChild(backFacingChild);
parent->addChild(frontFacingSurface);
parent->addChild(backFacingSurface);
frontFacingSurface->addChild(frontFacingChildOfFrontFacingSurface);
frontFacingSurface->addChild(backFacingChildOfFrontFacingSurface);
backFacingSurface->addChild(frontFacingChildOfBackFacingSurface);
backFacingSurface->addChild(backFacingChildOfBackFacingSurface);
frontFacingChild->setDoubleSided(false);
backFacingChild->setDoubleSided(false);
frontFacingSurface->setDoubleSided(false);
backFacingSurface->setDoubleSided(false);
frontFacingChildOfFrontFacingSurface->setDoubleSided(false);
backFacingChildOfFrontFacingSurface->setDoubleSided(false);
frontFacingChildOfBackFacingSurface->setDoubleSided(false);
backFacingChildOfBackFacingSurface->setDoubleSided(false);
WebTransformationMatrix backfaceMatrix;
backfaceMatrix.translate(50, 50);
backfaceMatrix.rotate3d(0, 1, 0, 180);
backfaceMatrix.translate(-50, -50);
frontFacingSurface->setOpacity(0.5);
backFacingSurface->setOpacity(0.5);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(frontFacingChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(backFacingChild.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(frontFacingChildOfFrontFacingSurface.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(backFacingChildOfFrontFacingSurface.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(frontFacingChildOfBackFacingSurface.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(backFacingChildOfBackFacingSurface.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
EXPECT_FALSE(frontFacingChild->renderSurface());
EXPECT_FALSE(backFacingChild->renderSurface());
EXPECT_TRUE(frontFacingSurface->renderSurface());
EXPECT_TRUE(backFacingSurface->renderSurface());
EXPECT_FALSE(frontFacingChildOfFrontFacingSurface->renderSurface());
EXPECT_FALSE(backFacingChildOfFrontFacingSurface->renderSurface());
EXPECT_FALSE(frontFacingChildOfBackFacingSurface->renderSurface());
EXPECT_FALSE(backFacingChildOfBackFacingSurface->renderSurface());
ASSERT_EQ(3u, renderSurfaceLayerList.size());
EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[1]->id());
EXPECT_EQ(backFacingSurface->id(), renderSurfaceLayerList[2]->id());
ASSERT_EQ(3u, renderSurfaceLayerList[0]->renderSurface()->layerList().size());
EXPECT_EQ(frontFacingChild->id(), renderSurfaceLayerList[0]->renderSurface()->layerList()[0]->id());
EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[0]->renderSurface()->layerList()[1]->id());
EXPECT_EQ(backFacingSurface->id(), renderSurfaceLayerList[0]->renderSurface()->layerList()[2]->id());
ASSERT_EQ(2u, renderSurfaceLayerList[1]->renderSurface()->layerList().size());
EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[1]->renderSurface()->layerList()[0]->id());
EXPECT_EQ(frontFacingChildOfFrontFacingSurface->id(), renderSurfaceLayerList[1]->renderSurface()->layerList()[1]->id());
ASSERT_EQ(1u, renderSurfaceLayerList[2]->renderSurface()->layerList().size());
EXPECT_EQ(frontFacingChildOfBackFacingSurface->id(), renderSurfaceLayerList[2]->renderSurface()->layerList()[0]->id());
}
TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3d)
{
const WebTransformationMatrix identityMatrix;
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> frontFacingChild = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> backFacingChild = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> frontFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> backFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> frontFacingChildOfFrontFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> backFacingChildOfFrontFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> frontFacingChildOfBackFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> backFacingChildOfBackFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> dummyReplicaLayer1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> dummyReplicaLayer2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
parent->addChild(frontFacingChild);
parent->addChild(backFacingChild);
parent->addChild(frontFacingSurface);
parent->addChild(backFacingSurface);
frontFacingSurface->addChild(frontFacingChildOfFrontFacingSurface);
frontFacingSurface->addChild(backFacingChildOfFrontFacingSurface);
backFacingSurface->addChild(frontFacingChildOfBackFacingSurface);
backFacingSurface->addChild(backFacingChildOfBackFacingSurface);
frontFacingChild->setDoubleSided(false);
backFacingChild->setDoubleSided(false);
frontFacingSurface->setDoubleSided(false);
backFacingSurface->setDoubleSided(false);
frontFacingChildOfFrontFacingSurface->setDoubleSided(false);
backFacingChildOfFrontFacingSurface->setDoubleSided(false);
frontFacingChildOfBackFacingSurface->setDoubleSided(false);
backFacingChildOfBackFacingSurface->setDoubleSided(false);
WebTransformationMatrix backfaceMatrix;
backfaceMatrix.translate(50, 50);
backfaceMatrix.rotate3d(0, 1, 0, 180);
backfaceMatrix.translate(-50, -50);
frontFacingSurface->setReplicaLayer(dummyReplicaLayer1.get());
backFacingSurface->setReplicaLayer(dummyReplicaLayer2.get());
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(frontFacingChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(backFacingChild.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true);
setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true);
setLayerPropertiesForTesting(frontFacingChildOfFrontFacingSurface.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(backFacingChildOfFrontFacingSurface.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(frontFacingChildOfBackFacingSurface.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(backFacingChildOfBackFacingSurface.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
EXPECT_FALSE(frontFacingChild->renderSurface());
EXPECT_FALSE(backFacingChild->renderSurface());
EXPECT_TRUE(frontFacingSurface->renderSurface());
EXPECT_FALSE(backFacingSurface->renderSurface());
EXPECT_FALSE(frontFacingChildOfFrontFacingSurface->renderSurface());
EXPECT_FALSE(backFacingChildOfFrontFacingSurface->renderSurface());
EXPECT_FALSE(frontFacingChildOfBackFacingSurface->renderSurface());
EXPECT_FALSE(backFacingChildOfBackFacingSurface->renderSurface());
ASSERT_EQ(2u, renderSurfaceLayerList.size());
EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[1]->id());
ASSERT_EQ(2u, renderSurfaceLayerList[0]->renderSurface()->layerList().size());
EXPECT_EQ(frontFacingChild->id(), renderSurfaceLayerList[0]->renderSurface()->layerList()[0]->id());
EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[0]->renderSurface()->layerList()[1]->id());
ASSERT_EQ(2u, renderSurfaceLayerList[1]->renderSurface()->layerList().size());
EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[1]->renderSurface()->layerList()[0]->id());
EXPECT_EQ(frontFacingChildOfFrontFacingSurface->id(), renderSurfaceLayerList[1]->renderSurface()->layerList()[1]->id());
}
TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithAnimatingTransforms)
{
const WebTransformationMatrix 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->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);
WebTransformationMatrix backfaceMatrix;
backfaceMatrix.translate(50, 50);
backfaceMatrix.rotate3d(0, 1, 0, 180);
backfaceMatrix.translate(-50, -50);
animatingSurface->setForceRenderSurface(true);
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), false);
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(), backfaceMatrix, 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;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
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->visibleContentRect().isEmpty());
EXPECT_EQ(animatingChild->visibleContentRect(), IntRect(IntPoint(), animatingChild->contentBounds()));
EXPECT_EQ(animatingSurface->visibleContentRect(), IntRect(IntPoint(), animatingSurface->contentBounds()));
EXPECT_EQ(childOfAnimatingSurface->visibleContentRect(), IntRect(IntPoint(), childOfAnimatingSurface->contentBounds()));
}
TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3dForFlatteningSurface)
{
const WebTransformationMatrix identityMatrix;
RefPtr<LayerChromium> parent = LayerChromium::create();
RefPtr<LayerChromiumWithForcedDrawsContent> frontFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> backFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
RefPtr<LayerChromiumWithForcedDrawsContent> child2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
parent->addChild(frontFacingSurface);
parent->addChild(backFacingSurface);
frontFacingSurface->addChild(child1);
backFacingSurface->addChild(child2);
frontFacingSurface->setDoubleSided(false);
backFacingSurface->setDoubleSided(false);
WebTransformationMatrix backfaceMatrix;
backfaceMatrix.translate(50, 50);
backfaceMatrix.rotate3d(0, 1, 0, 180);
backfaceMatrix.translate(-50, -50);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true);
setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(backFacingSurface.get(), backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(child1.get(), identityMatrix, 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;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
EXPECT_TRUE(frontFacingSurface->renderSurface());
EXPECT_FALSE(backFacingSurface->renderSurface());
EXPECT_FALSE(child1->renderSurface());
EXPECT_FALSE(child2->renderSurface());
ASSERT_EQ(2u, renderSurfaceLayerList.size());
EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[1]->id());
ASSERT_EQ(1u, renderSurfaceLayerList[0]->renderSurface()->layerList().size());
EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[0]->renderSurface()->layerList()[0]->id());
ASSERT_EQ(2u, renderSurfaceLayerList[1]->renderSurface()->layerList().size());
EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[1]->renderSurface()->layerList()[0]->id());
EXPECT_EQ(child1->id(), renderSurfaceLayerList[1]->renderSurface()->layerList()[1]->id());
}
TEST(CCLayerTreeHostCommonTest, verifyHitTestingForEmptyLayerList)
{
DebugScopedSetImplThread thisScopeIsOnImplThread;
Vector<CCLayerImpl*> renderSurfaceLayerList;
IntPoint testPoint(0, 0);
CCLayerImpl* resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(10, 20);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
}
TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSingleLayer)
{
DebugScopedSetImplThread thisScopeIsOnImplThread;
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(12345);
WebTransformationMatrix identityMatrix;
FloatPoint anchor(0, 0);
FloatPoint position(0, 0);
IntSize bounds(100, 100);
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
root->setDrawsContent(true);
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_EQ(1u, renderSurfaceLayerList.size());
ASSERT_EQ(1u, root->renderSurface()->layerList().size());
IntPoint testPoint(101, 101);
CCLayerImpl* resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(-1, -1);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(1, 1);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(12345, resultLayer->id());
testPoint = IntPoint(99, 99);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(12345, resultLayer->id());
}
TEST(CCLayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform)
{
DebugScopedSetImplThread thisScopeIsOnImplThread;
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(12345);
WebTransformationMatrix uninvertibleTransform;
uninvertibleTransform.setM11(0);
uninvertibleTransform.setM22(0);
uninvertibleTransform.setM33(0);
uninvertibleTransform.setM44(0);
ASSERT_FALSE(uninvertibleTransform.isInvertible());
WebTransformationMatrix identityMatrix;
FloatPoint anchor(0, 0);
FloatPoint position(0, 0);
IntSize bounds(100, 100);
setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatrix, anchor, position, bounds, false);
root->setDrawsContent(true);
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_EQ(1u, renderSurfaceLayerList.size());
ASSERT_EQ(1u, root->renderSurface()->layerList().size());
ASSERT_FALSE(root->screenSpaceTransform().isInvertible());
IntPoint testPoint(1, 1);
CCLayerImpl* resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(10, 10);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(10, 30);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(50, 50);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(67, 48);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(99, 99);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(-1, -1);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
}
TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer)
{
DebugScopedSetImplThread thisScopeIsOnImplThread;
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(12345);
WebTransformationMatrix identityMatrix;
FloatPoint anchor(0, 0);
FloatPoint position(50, 50);
IntSize bounds(100, 100);
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
root->setDrawsContent(true);
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_EQ(1u, renderSurfaceLayerList.size());
ASSERT_EQ(1u, root->renderSurface()->layerList().size());
IntPoint testPoint(49, 49);
CCLayerImpl* resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(101, 101);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(51, 51);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(12345, resultLayer->id());
testPoint = IntPoint(99, 99);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(12345, resultLayer->id());
}
TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer)
{
DebugScopedSetImplThread thisScopeIsOnImplThread;
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(12345);
WebTransformationMatrix identityMatrix;
WebTransformationMatrix rotation45DegreesAboutCenter;
rotation45DegreesAboutCenter.translate(50, 50);
rotation45DegreesAboutCenter.rotate3d(0, 0, 45);
rotation45DegreesAboutCenter.translate(-50, -50);
FloatPoint anchor(0, 0);
FloatPoint position(0, 0);
IntSize bounds(100, 100);
setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, identityMatrix, anchor, position, bounds, false);
root->setDrawsContent(true);
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_EQ(1u, renderSurfaceLayerList.size());
ASSERT_EQ(1u, root->renderSurface()->layerList().size());
IntPoint testPoint(99, 99);
CCLayerImpl* resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(1, 1);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(1, 50);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(12345, resultLayer->id());
testPoint = IntPoint(50, -1);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_FALSE(resultLayer);
testPoint = IntPoint(-1, 50);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_FALSE(resultLayer);
}
TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer)
{
DebugScopedSetImplThread thisScopeIsOnImplThread;
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(12345);
WebTransformationMatrix identityMatrix;
WebTransformationMatrix perspectiveProjectionAboutCenter;
perspectiveProjectionAboutCenter.translate(50, 50);
perspectiveProjectionAboutCenter.applyPerspective(1);
perspectiveProjectionAboutCenter.translate(-50, -50);
WebTransformationMatrix translationByZ;
translationByZ.translate3d(0, 0, -1);
FloatPoint anchor(0, 0);
FloatPoint position(0, 0);
IntSize bounds(100, 100);
setLayerPropertiesForTesting(root.get(), perspectiveProjectionAboutCenter * translationByZ, identityMatrix, anchor, position, bounds, false);
root->setDrawsContent(true);
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_EQ(1u, renderSurfaceLayerList.size());
ASSERT_EQ(1u, root->renderSurface()->layerList().size());
IntPoint testPoint(24, 24);
CCLayerImpl* resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(76, 76);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(26, 26);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(12345, resultLayer->id());
testPoint = IntPoint(74, 74);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(12345, resultLayer->id());
}
TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents)
{
DebugScopedSetImplThread thisScopeIsOnImplThread;
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(1);
WebTransformationMatrix identityMatrix;
FloatPoint anchor(0, 0);
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, FloatPoint(0, 0), IntSize(100, 100), false);
{
FloatPoint position(25, 25);
IntSize bounds(50, 50);
OwnPtr<CCLayerImpl> testLayer = CCLayerImpl::create(12345);
setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
testLayer->setContentBounds(IntSize(100, 100));
testLayer->setDrawsContent(true);
root->addChild(testLayer.release());
}
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
CCLayerImpl* testLayer = root->children()[0];
EXPECT_RECT_EQ(IntRect(IntPoint::zero(), IntSize(100, 100)), testLayer->visibleContentRect());
ASSERT_EQ(1u, renderSurfaceLayerList.size());
ASSERT_EQ(1u, root->renderSurface()->layerList().size());
IntPoint testPoint(101, 101);
CCLayerImpl* resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(24, 24);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(76, 76);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(26, 26);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(12345, resultLayer->id());
testPoint = IntPoint(74, 74);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(12345, resultLayer->id());
}
TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer)
{
DebugScopedSetImplThread thisScopeIsOnImplThread;
WebTransformationMatrix identityMatrix;
FloatPoint anchor(0, 0);
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(1);
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, FloatPoint(0, 0), IntSize(100, 100), false);
{
OwnPtr<CCLayerImpl> clippingLayer = CCLayerImpl::create(123);
FloatPoint position(25, 25);
IntSize bounds(50, 50);
setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
clippingLayer->setMasksToBounds(true);
OwnPtr<CCLayerImpl> child = CCLayerImpl::create(456);
position = FloatPoint(-50, -50);
bounds = IntSize(300, 300);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
child->setDrawsContent(true);
clippingLayer->addChild(child.release());
root->addChild(clippingLayer.release());
}
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_EQ(1u, renderSurfaceLayerList.size());
ASSERT_EQ(1u, root->renderSurface()->layerList().size());
ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id());
IntPoint testPoint(24, 24);
CCLayerImpl* resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(76, 76);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(26, 26);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(456, resultLayer->id());
testPoint = IntPoint(74, 74);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(456, resultLayer->id());
}
TEST(CCLayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer)
{
DebugScopedSetImplThread thisScopeIsOnImplThread;
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(123);
WebTransformationMatrix identityMatrix;
FloatPoint anchor(0, 0);
FloatPoint position(0, 0);
IntSize bounds(100, 100);
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
root->setMasksToBounds(true);
{
OwnPtr<CCLayerImpl> child = CCLayerImpl::create(456);
OwnPtr<CCLayerImpl> grandChild = CCLayerImpl::create(789);
OwnPtr<CCLayerImpl> rotatedLeaf = CCLayerImpl::create(2468);
position = FloatPoint(10, 10);
bounds = IntSize(80, 80);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
child->setMasksToBounds(true);
WebTransformationMatrix rotation45DegreesAboutCorner;
rotation45DegreesAboutCorner.rotate3d(0, 0, 45);
position = FloatPoint(0, 0);
bounds = IntSize(200, 200);
setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCorner, identityMatrix, anchor, position, bounds, false);
grandChild->setMasksToBounds(true);
WebTransformationMatrix rotatedLeafTransform;
rotatedLeafTransform.translate(-10, -10);
rotatedLeafTransform.rotate3d(0, 0, -45);
rotatedLeafTransform.translate(50, 50);
rotatedLeafTransform.rotate3d(0, 0, 45);
rotatedLeafTransform.translate(-50, -50);
position = FloatPoint(0, 0);
bounds = IntSize(100, 100);
setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, identityMatrix, anchor, position, bounds, false);
rotatedLeaf->setDrawsContent(true);
grandChild->addChild(rotatedLeaf.release());
child->addChild(grandChild.release());
root->addChild(child.release());
}
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_EQ(2u, renderSurfaceLayerList.size());
ASSERT_EQ(1u, renderSurfaceLayerList[0]->renderSurface()->layerList().size());
ASSERT_EQ(789, renderSurfaceLayerList[0]->renderSurface()->layerList()[0]->id());
ASSERT_EQ(1u, renderSurfaceLayerList[1]->renderSurface()->layerList().size());
ASSERT_EQ(2468, renderSurfaceLayerList[1]->renderSurface()->layerList()[0]->id());
IntPoint testPoint(11, 89);
CCLayerImpl* resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(25, 75);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(2468, resultLayer->id());
testPoint = IntPoint(4, 50);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(11, 50);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(2468, resultLayer->id());
testPoint = IntPoint(51, 51);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(49, 51);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(2468, resultLayer->id());
}
TEST(CCLayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer)
{
DebugScopedSetImplThread thisScopeIsOnImplThread;
WebTransformationMatrix identityMatrix;
FloatPoint anchor(0, 0);
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(1);
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, FloatPoint(0, 0), IntSize(100, 100), false);
{
OwnPtr<CCLayerImpl> intermediateLayer = CCLayerImpl::create(123);
FloatPoint position(10, 10);
IntSize bounds(50, 50);
setLayerPropertiesForTesting(intermediateLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
ASSERT_FALSE(intermediateLayer->masksToBounds());
ASSERT_FALSE(intermediateLayer->maskLayer());
OwnPtr<CCLayerImpl> child = CCLayerImpl::create(456);
position = FloatPoint(60, 60);
bounds = IntSize(20, 20);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
child->setDrawsContent(true);
intermediateLayer->addChild(child.release());
root->addChild(intermediateLayer.release());
}
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_EQ(1u, renderSurfaceLayerList.size());
ASSERT_EQ(1u, root->renderSurface()->layerList().size());
ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id());
IntPoint testPoint(69, 69);
CCLayerImpl* resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(91, 91);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
EXPECT_FALSE(resultLayer);
testPoint = IntPoint(71, 71);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(456, resultLayer->id());
testPoint = IntPoint(89, 89);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(456, resultLayer->id());
}
TEST(CCLayerTreeHostCommonTest, verifyHitTestingForMultipleLayers)
{
DebugScopedSetImplThread thisScopeIsOnImplThread;
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(1);
WebTransformationMatrix identityMatrix;
FloatPoint anchor(0, 0);
FloatPoint position(0, 0);
IntSize bounds(100, 100);
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
root->setDrawsContent(true);
{
OwnPtr<CCLayerImpl> child1 = CCLayerImpl::create(2);
OwnPtr<CCLayerImpl> child2 = CCLayerImpl::create(3);
OwnPtr<CCLayerImpl> grandChild1 = CCLayerImpl::create(4);
position = FloatPoint(10, 10);
bounds = IntSize(50, 50);
setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
child1->setDrawsContent(true);
position = FloatPoint(50, 10);
bounds = IntSize(50, 50);
setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
child2->setDrawsContent(true);
position = FloatPoint(0, 40);
bounds = IntSize(100, 50);
setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
grandChild1->setDrawsContent(true);
child1->addChild(grandChild1.release());
root->addChild(child1.release());
root->addChild(child2.release());
}
CCLayerImpl* child1 = root->children()[0];
CCLayerImpl* child2 = root->children()[1];
CCLayerImpl* grandChild1 = child1->children()[0];
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_TRUE(child1);
ASSERT_TRUE(child2);
ASSERT_TRUE(grandChild1);
ASSERT_EQ(1u, renderSurfaceLayerList.size());
ASSERT_EQ(4u, root->renderSurface()->layerList().size());
ASSERT_EQ(1, root->renderSurface()->layerList()[0]->id());
ASSERT_EQ(2, root->renderSurface()->layerList()[1]->id());
ASSERT_EQ(4, root->renderSurface()->layerList()[2]->id());
ASSERT_EQ(3, root->renderSurface()->layerList()[3]->id());
IntPoint testPoint = IntPoint(1, 1);
CCLayerImpl* resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(1, resultLayer->id());
testPoint = IntPoint(15, 15);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(2, resultLayer->id());
testPoint = IntPoint(51, 20);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(3, resultLayer->id());
testPoint = IntPoint(80, 51);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(3, resultLayer->id());
testPoint = IntPoint(51, 51);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(3, resultLayer->id());
testPoint = IntPoint(20, 51);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(4, resultLayer->id());
}
TEST(CCLayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists)
{
DebugScopedSetImplThread thisScopeIsOnImplThread;
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(1);
WebTransformationMatrix identityMatrix;
FloatPoint anchor(0, 0);
FloatPoint position(0, 0);
IntSize bounds(100, 100);
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
root->setDrawsContent(true);
{
OwnPtr<CCLayerImpl> child1 = CCLayerImpl::create(2);
OwnPtr<CCLayerImpl> child2 = CCLayerImpl::create(3);
OwnPtr<CCLayerImpl> grandChild1 = CCLayerImpl::create(4);
position = FloatPoint(10, 10);
bounds = IntSize(50, 50);
setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
child1->setDrawsContent(true);
child1->setForceRenderSurface(true);
position = FloatPoint(50, 10);
bounds = IntSize(50, 50);
setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
child2->setDrawsContent(true);
child2->setForceRenderSurface(true);
position = FloatPoint(0, 40);
bounds = IntSize(100, 50);
setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
grandChild1->setDrawsContent(true);
grandChild1->setForceRenderSurface(true);
child1->addChild(grandChild1.release());
root->addChild(child1.release());
root->addChild(child2.release());
}
CCLayerImpl* child1 = root->children()[0];
CCLayerImpl* child2 = root->children()[1];
CCLayerImpl* grandChild1 = child1->children()[0];
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_TRUE(child1);
ASSERT_TRUE(child2);
ASSERT_TRUE(grandChild1);
ASSERT_TRUE(child1->renderSurface());
ASSERT_TRUE(child2->renderSurface());
ASSERT_TRUE(grandChild1->renderSurface());
ASSERT_EQ(4u, renderSurfaceLayerList.size());
ASSERT_EQ(3u, root->renderSurface()->layerList().size());
ASSERT_EQ(2u, child1->renderSurface()->layerList().size());
ASSERT_EQ(1u, child2->renderSurface()->layerList().size());
ASSERT_EQ(1u, grandChild1->renderSurface()->layerList().size());
ASSERT_EQ(1, renderSurfaceLayerList[0]->id());
ASSERT_EQ(2, renderSurfaceLayerList[1]->id());
ASSERT_EQ(4, renderSurfaceLayerList[2]->id());
ASSERT_EQ(3, renderSurfaceLayerList[3]->id());
IntPoint testPoint = IntPoint(1, 1);
CCLayerImpl* resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(1, resultLayer->id());
testPoint = IntPoint(15, 15);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(2, resultLayer->id());
testPoint = IntPoint(51, 20);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(3, resultLayer->id());
testPoint = IntPoint(80, 51);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(3, resultLayer->id());
testPoint = IntPoint(51, 51);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(3, resultLayer->id());
testPoint = IntPoint(20, 51);
resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
ASSERT_TRUE(resultLayer);
EXPECT_EQ(4, resultLayer->id());
}
TEST(CCLayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
{
MockContentLayerChromiumClient delegate;
WebTransformationMatrix identityMatrix;
RefPtr<ContentLayerChromium> parent = createDrawableContentLayerChromium(&delegate);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true);
RefPtr<ContentLayerChromium> child = createDrawableContentLayerChromium(&delegate);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true);
RefPtr<ContentLayerChromium> childNoScale = createDrawableContentLayerChromium(&delegate);
setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true);
parent->addChild(child);
parent->addChild(childNoScale);
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
const double deviceScaleFactor = 2.5;
parent->setContentsScale(deviceScaleFactor);
child->setContentsScale(deviceScaleFactor);
EXPECT_EQ(childNoScale->contentsScale(), 1);
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList);
EXPECT_EQ(1u, renderSurfaceLayerList.size());
WebTransformationMatrix expectedParentTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransform());
FloatRect parentContentBounds(FloatPoint(), FloatSize(parent->contentBounds()));
FloatRect parentDrawRect = CCMathUtil::mapClippedRect(parent->drawTransform(), parentContentBounds);
FloatRect parentScreenSpaceRect = CCMathUtil::mapClippedRect(parent->screenSpaceTransform(), parentContentBounds);
FloatRect expectedParentDrawRect(FloatPoint(), parent->bounds());
expectedParentDrawRect.scale(deviceScaleFactor);
EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect);
EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect);
WebTransformationMatrix expectedChildTransform;
expectedChildTransform.translate(deviceScaleFactor * child->position().x(), deviceScaleFactor * child->position().y());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTransform());
FloatRect childContentBounds(FloatPoint(), FloatSize(child->contentBounds()));
FloatRect childDrawRect = CCMathUtil::mapClippedRect(child->drawTransform(), childContentBounds);
FloatRect childScreenSpaceRect = CCMathUtil::mapClippedRect(child->screenSpaceTransform(), childContentBounds);
FloatRect expectedChildDrawRect(FloatPoint(), child->bounds());
expectedChildDrawRect.move(child->position().x(), child->position().y());
expectedChildDrawRect.scale(deviceScaleFactor);
EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect);
EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect);
WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform();
expectedChildNoScaleTransform.scale(deviceScaleFactor);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI)
{
MockContentLayerChromiumClient delegate;
WebTransformationMatrix identityMatrix;
RefPtr<ContentLayerChromium> parent = createDrawableContentLayerChromium(&delegate);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(30, 30), true);
RefPtr<ContentLayerChromium> child = createDrawableContentLayerChromium(&delegate);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true);
WebTransformationMatrix replicaTransform;
replicaTransform.scaleNonUniform(1, -1);
RefPtr<ContentLayerChromium> replica = createDrawableContentLayerChromium(&delegate);
setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true);
RefPtr<ContentLayerChromium> duplicateChildNonOwner = createDrawableContentLayerChromium(&delegate);
setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true);
parent->addChild(child);
child->addChild(duplicateChildNonOwner);
child->setReplicaLayer(replica.get());
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
const double deviceScaleFactor = 1.5;
parent->setContentsScale(deviceScaleFactor);
child->setContentsScale(deviceScaleFactor);
duplicateChildNonOwner->setContentsScale(deviceScaleFactor);
replica->setContentsScale(deviceScaleFactor);
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList);
EXPECT_EQ(2u, renderSurfaceLayerList.size());
WebTransformationMatrix expectedParentTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransform());
WebTransformationMatrix expectedDrawTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, child->drawTransform());
WebTransformationMatrix expectedScreenSpaceTransform;
expectedScreenSpaceTransform.translate(deviceScaleFactor * child->position().x(), deviceScaleFactor * child->position().y());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedScreenSpaceTransform, child->screenSpaceTransform());
WebTransformationMatrix expectedDuplicateChildDrawTransform = child->drawTransform();
EXPECT_TRANSFORMATION_MATRIX_EQ(child->drawTransform(), duplicateChildNonOwner->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(child->screenSpaceTransform(), duplicateChildNonOwner->screenSpaceTransform());
EXPECT_RECT_EQ(child->drawableContentRect(), duplicateChildNonOwner->drawableContentRect());
EXPECT_EQ(child->contentBounds(), duplicateChildNonOwner->contentBounds());
WebTransformationMatrix expectedRenderSurfaceDrawTransform;
expectedRenderSurfaceDrawTransform.translate(deviceScaleFactor * child->position().x(), deviceScaleFactor * child->position().y());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedRenderSurfaceDrawTransform, child->renderSurface()->drawTransform());
WebTransformationMatrix expectedSurfaceDrawTransform;
expectedSurfaceDrawTransform.translate(deviceScaleFactor * 2, deviceScaleFactor * 2);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceDrawTransform, child->renderSurface()->drawTransform());
WebTransformationMatrix expectedSurfaceScreenSpaceTransform;
expectedSurfaceScreenSpaceTransform.translate(deviceScaleFactor * 2, deviceScaleFactor * 2);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedSurfaceScreenSpaceTransform, child->renderSurface()->screenSpaceTransform());
WebTransformationMatrix expectedReplicaDrawTransform;
expectedReplicaDrawTransform.setM22(-1);
expectedReplicaDrawTransform.setM41(6);
expectedReplicaDrawTransform.setM42(6);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaDrawTransform, child->renderSurface()->replicaDrawTransform());
WebTransformationMatrix expectedReplicaScreenSpaceTransform;
expectedReplicaScreenSpaceTransform.setM22(-1);
expectedReplicaScreenSpaceTransform.setM41(6);
expectedReplicaScreenSpaceTransform.setM42(6);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child->renderSurface()->replicaScreenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifySubtreeSearch)
{
RefPtr<LayerChromium> root = LayerChromium::create();
RefPtr<LayerChromium> child = LayerChromium::create();
RefPtr<LayerChromium> grandChild = LayerChromium::create();
RefPtr<LayerChromium> maskLayer = LayerChromium::create();
RefPtr<LayerChromium> replicaLayer = LayerChromium::create();
grandChild->setReplicaLayer(replicaLayer.get());
child->addChild(grandChild.get());
child->setMaskLayer(maskLayer.get());
root->addChild(child.get());
int nonexistentId = -1;
EXPECT_EQ(root, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), root->id()));
EXPECT_EQ(child, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), child->id()));
EXPECT_EQ(grandChild, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), grandChild->id()));
EXPECT_EQ(maskLayer, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), maskLayer->id()));
EXPECT_EQ(replicaLayer, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id()));
EXPECT_EQ(0, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistentId));
}
}