This source file includes following definitions.
- SetLayerPropertiesForTesting
- ExecuteCalculateDrawProperties
- ExecuteCalculateDrawProperties
- CreateTreeForTest
- SetFixedContainerSizeDelta
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "cc/layers/layer_position_constraint.h"
#include <vector>
#include "cc/layers/layer_impl.h"
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/geometry_test_utils.h"
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/trees/layer_tree_host_common.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
namespace {
void SetLayerPropertiesForTesting(LayerImpl* layer,
const gfx::Transform& transform,
const gfx::PointF& anchor,
const gfx::PointF& position,
const gfx::Size& bounds,
bool flatten_transform,
bool is_3d_sorted) {
layer->SetTransform(transform);
layer->SetAnchorPoint(anchor);
layer->SetPosition(position);
layer->SetBounds(bounds);
layer->SetShouldFlattenTransform(flatten_transform);
layer->SetIs3dSorted(is_3d_sorted);
layer->SetContentBounds(bounds);
}
void ExecuteCalculateDrawProperties(LayerImpl* root_layer,
float device_scale_factor,
float page_scale_factor,
LayerImpl* page_scale_application_layer,
bool can_use_lcd_text) {
gfx::Transform identity_matrix;
std::vector<LayerImpl*> dummy_render_surface_layer_list;
LayerImpl* scroll_layer = root_layer->children()[0];
gfx::Size device_viewport_size =
gfx::Size(root_layer->bounds().width() * device_scale_factor,
root_layer->bounds().height() * device_scale_factor);
DCHECK(!scroll_layer->bounds().IsEmpty());
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root_layer, device_viewport_size, &dummy_render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = page_scale_application_layer;
inputs.can_use_lcd_text = can_use_lcd_text;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
}
void ExecuteCalculateDrawProperties(LayerImpl* root_layer) {
LayerImpl* page_scale_application_layer = NULL;
ExecuteCalculateDrawProperties(
root_layer, 1.f, 1.f, page_scale_application_layer, false);
}
class LayerPositionConstraintTest : public testing::Test {
public:
LayerPositionConstraintTest() : host_impl_(&proxy_, &shared_bitmap_manager_) {
root_ = CreateTreeForTest();
scroll_ = root_->children()[0];
fixed_to_top_left_.set_is_fixed_position(true);
fixed_to_bottom_right_.set_is_fixed_position(true);
fixed_to_bottom_right_.set_is_fixed_to_right_edge(true);
fixed_to_bottom_right_.set_is_fixed_to_bottom_edge(true);
}
scoped_ptr<LayerImpl> CreateTreeForTest() {
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl_.active_tree(), 42);
scoped_ptr<LayerImpl> scroll_layer =
LayerImpl::Create(host_impl_.active_tree(), 1);
scoped_ptr<LayerImpl> child =
LayerImpl::Create(host_impl_.active_tree(), 2);
scoped_ptr<LayerImpl> grand_child =
LayerImpl::Create(host_impl_.active_tree(), 3);
scoped_ptr<LayerImpl> great_grand_child =
LayerImpl::Create(host_impl_.active_tree(), 4);
gfx::Transform IdentityMatrix;
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(200, 200);
gfx::Size clip_bounds(100, 100);
SetLayerPropertiesForTesting(scroll_layer.get(),
IdentityMatrix,
anchor,
position,
bounds,
true,
false);
SetLayerPropertiesForTesting(child.get(),
IdentityMatrix,
anchor,
position,
bounds,
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
IdentityMatrix,
anchor,
position,
bounds,
true,
false);
SetLayerPropertiesForTesting(great_grand_child.get(),
IdentityMatrix,
anchor,
position,
bounds,
true,
false);
root->SetBounds(clip_bounds);
scroll_layer->SetScrollClipLayer(root->id());
child->SetScrollClipLayer(root->id());
grand_child->SetScrollClipLayer(root->id());
grand_child->AddChild(great_grand_child.Pass());
child->AddChild(grand_child.Pass());
scroll_layer->AddChild(child.Pass());
root->AddChild(scroll_layer.Pass());
return root.Pass();
}
protected:
FakeImplProxy proxy_;
TestSharedBitmapManager shared_bitmap_manager_;
FakeLayerTreeHostImpl host_impl_;
scoped_ptr<LayerImpl> root_;
LayerImpl* scroll_;
LayerPositionConstraint fixed_to_top_left_;
LayerPositionConstraint fixed_to_bottom_right_;
};
namespace {
void SetFixedContainerSizeDelta(LayerImpl* scroll_layer,
const gfx::Vector2d& delta) {
DCHECK(scroll_layer);
DCHECK(scroll_layer->scrollable());
LayerImpl* container_layer = scroll_layer->scroll_clip_layer();
gfx::Size container_size(container_layer->bounds());
gfx::Size new_container_size(container_size.width() + delta.x(),
container_size.height() + delta.y());
container_layer->SetTemporaryImplBounds(new_container_size);
}
}
TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedPositionLayerWithDirectContainer) {
LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
child->SetIsContainerForFixedPositionLayers(true);
grand_child->SetPositionConstraint(fixed_to_top_left_);
child->SetScrollDelta(gfx::Vector2d(0, 0));
ExecuteCalculateDrawProperties(root_.get());
gfx::Transform expected_child_transform;
gfx::Transform expected_grand_child_transform = expected_child_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
child->SetScrollDelta(gfx::Vector2d(10, 10));
ExecuteCalculateDrawProperties(root_.get());
expected_child_transform.MakeIdentity();
expected_child_transform.Translate(-10.0, -10.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
grand_child->SetPositionConstraint(fixed_to_bottom_right_);
ExecuteCalculateDrawProperties(root_.get());
expected_grand_child_transform.MakeIdentity();
expected_grand_child_transform.Translate(20.0, 20.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
}
TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedPositionLayerWithTransformedDirectContainer) {
LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
gfx::Transform non_uniform_scale;
non_uniform_scale.Scale(2.0, 8.0);
child->SetTransform(non_uniform_scale);
child->SetIsContainerForFixedPositionLayers(true);
grand_child->SetPositionConstraint(fixed_to_top_left_);
child->SetScrollDelta(gfx::Vector2d(0, 0));
ExecuteCalculateDrawProperties(root_.get());
gfx::Transform expected_child_transform;
expected_child_transform.PreconcatTransform(non_uniform_scale);
gfx::Transform expected_grand_child_transform = expected_child_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
child->SetScrollDelta(gfx::Vector2d(10, 20));
ExecuteCalculateDrawProperties(root_.get());
expected_child_transform.MakeIdentity();
expected_child_transform.Translate(-10.0, -20.0);
expected_child_transform.PreconcatTransform(non_uniform_scale);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
grand_child->SetPositionConstraint(fixed_to_bottom_right_);
ExecuteCalculateDrawProperties(root_.get());
expected_grand_child_transform.MakeIdentity();
expected_grand_child_transform.PreconcatTransform(non_uniform_scale);
expected_grand_child_transform.Translate(20.0, 20.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
}
TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedPositionLayerWithDistantContainer) {
LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
LayerImpl* great_grand_child = grand_child->children()[0];
child->SetIsContainerForFixedPositionLayers(true);
grand_child->SetPosition(gfx::PointF(8.f, 6.f));
great_grand_child->SetPositionConstraint(fixed_to_top_left_);
child->SetScrollDelta(gfx::Vector2d(0, 0));
ExecuteCalculateDrawProperties(root_.get());
gfx::Transform expected_child_transform;
gfx::Transform expected_grand_child_transform;
expected_grand_child_transform.Translate(8.0, 6.0);
gfx::Transform expected_great_grand_child_transform =
expected_grand_child_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
child->SetScrollDelta(gfx::Vector2d(10, 10));
ExecuteCalculateDrawProperties(root_.get());
expected_child_transform.MakeIdentity();
expected_child_transform.Translate(-10.0, -10.0);
expected_grand_child_transform.MakeIdentity();
expected_grand_child_transform.Translate(-2.0, -4.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
great_grand_child->SetPositionConstraint(fixed_to_bottom_right_);
ExecuteCalculateDrawProperties(root_.get());
expected_great_grand_child_transform.MakeIdentity();
expected_great_grand_child_transform.Translate(20.0, 20.0);
expected_great_grand_child_transform.Translate(8.0, 6.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
}
TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedPositionLayerWithDistantContainerAndTransforms) {
LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
LayerImpl* great_grand_child = grand_child->children()[0];
gfx::Transform rotation_about_z;
rotation_about_z.RotateAboutZAxis(90.0);
child->SetIsContainerForFixedPositionLayers(true);
child->SetTransform(rotation_about_z);
grand_child->SetPosition(gfx::PointF(8.f, 6.f));
grand_child->SetTransform(rotation_about_z);
great_grand_child->SetPositionConstraint(fixed_to_top_left_);
child->SetScrollDelta(gfx::Vector2d(0, 0));
ExecuteCalculateDrawProperties(root_.get());
gfx::Transform expected_child_transform;
expected_child_transform.PreconcatTransform(rotation_about_z);
gfx::Transform expected_grand_child_transform;
expected_grand_child_transform.PreconcatTransform(
rotation_about_z);
expected_grand_child_transform.Translate(8.0, 6.0);
expected_grand_child_transform.PreconcatTransform(
rotation_about_z);
gfx::Transform expected_great_grand_child_transform =
expected_grand_child_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
child->SetScrollDelta(gfx::Vector2d(10, 20));
ExecuteCalculateDrawProperties(root_.get());
expected_child_transform.MakeIdentity();
expected_child_transform.Translate(-10.0, -20.0);
expected_child_transform.PreconcatTransform(rotation_about_z);
expected_grand_child_transform.MakeIdentity();
expected_grand_child_transform.Translate(
-10.0, -20.0);
expected_grand_child_transform.PreconcatTransform(
rotation_about_z);
expected_grand_child_transform.Translate(8.0, 6.0);
expected_grand_child_transform.PreconcatTransform(
rotation_about_z);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
great_grand_child->SetPositionConstraint(fixed_to_bottom_right_);
ExecuteCalculateDrawProperties(root_.get());
expected_great_grand_child_transform.MakeIdentity();
expected_great_grand_child_transform.PreconcatTransform(rotation_about_z);
expected_great_grand_child_transform.Translate(20.0, 20.0);
expected_great_grand_child_transform.Translate(8.0, 6.0);
expected_great_grand_child_transform.PreconcatTransform(rotation_about_z);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
}
TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedPositionLayerWithMultipleScrollDeltas) {
LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
LayerImpl* great_grand_child = grand_child->children()[0];
gfx::Transform rotation_about_z;
rotation_about_z.RotateAboutZAxis(90.0);
child->SetIsContainerForFixedPositionLayers(true);
child->SetTransform(rotation_about_z);
grand_child->SetPosition(gfx::PointF(8.f, 6.f));
grand_child->SetTransform(rotation_about_z);
great_grand_child->SetPositionConstraint(fixed_to_top_left_);
child->SetScrollDelta(gfx::Vector2d(0, 0));
ExecuteCalculateDrawProperties(root_.get());
gfx::Transform expected_child_transform;
expected_child_transform.PreconcatTransform(rotation_about_z);
gfx::Transform expected_grand_child_transform;
expected_grand_child_transform.PreconcatTransform(
rotation_about_z);
expected_grand_child_transform.Translate(8.0, 6.0);
expected_grand_child_transform.PreconcatTransform(
rotation_about_z);
gfx::Transform expected_great_grand_child_transform =
expected_grand_child_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
child->SetScrollDelta(gfx::Vector2d(10, 0));
grand_child->SetScrollDelta(gfx::Vector2d(5, 0));
ExecuteCalculateDrawProperties(root_.get());
expected_child_transform.MakeIdentity();
expected_child_transform.Translate(-10.0, 0.0);
expected_child_transform.PreconcatTransform(rotation_about_z);
expected_grand_child_transform.MakeIdentity();
expected_grand_child_transform.Translate(
-10.0, 0.0);
expected_grand_child_transform.PreconcatTransform(
rotation_about_z);
expected_grand_child_transform.Translate(-5.0,
0.0);
expected_grand_child_transform.Translate(8.0, 6.0);
expected_grand_child_transform.PreconcatTransform(
rotation_about_z);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
great_grand_child->SetPositionConstraint(fixed_to_bottom_right_);
ExecuteCalculateDrawProperties(root_.get());
expected_great_grand_child_transform.MakeIdentity();
expected_great_grand_child_transform.PreconcatTransform(rotation_about_z);
expected_great_grand_child_transform.Translate(20.0, 20.0);
expected_great_grand_child_transform.Translate(8.0, 6.0);
expected_great_grand_child_transform.PreconcatTransform(rotation_about_z);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
}
TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedPositionWithIntermediateSurfaceAndTransforms) {
LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
LayerImpl* great_grand_child = grand_child->children()[0];
child->SetIsContainerForFixedPositionLayers(true);
grand_child->SetPosition(gfx::PointF(8.f, 6.f));
grand_child->SetForceRenderSurface(true);
great_grand_child->SetPositionConstraint(fixed_to_top_left_);
great_grand_child->SetDrawsContent(true);
gfx::Transform rotation_about_z;
rotation_about_z.RotateAboutZAxis(90.0);
grand_child->SetTransform(rotation_about_z);
child->SetScrollDelta(gfx::Vector2d(0, 0));
ExecuteCalculateDrawProperties(root_.get());
gfx::Transform expected_child_transform;
gfx::Transform expected_surface_draw_transform;
expected_surface_draw_transform.Translate(8.0, 6.0);
expected_surface_draw_transform.PreconcatTransform(rotation_about_z);
gfx::Transform expected_grand_child_transform;
gfx::Transform expected_great_grand_child_transform;
ASSERT_TRUE(grand_child->render_surface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_surface_draw_transform,
grand_child->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
child->SetScrollDelta(gfx::Vector2d(10, 30));
ExecuteCalculateDrawProperties(root_.get());
expected_child_transform.MakeIdentity();
expected_child_transform.Translate(-10.0, -30.0);
expected_surface_draw_transform.MakeIdentity();
expected_surface_draw_transform.Translate(-10.0, -30.0);
expected_surface_draw_transform.Translate(8.0, 6.0);
expected_surface_draw_transform.PreconcatTransform(rotation_about_z);
expected_great_grand_child_transform.MakeIdentity();
expected_great_grand_child_transform.PreconcatTransform(
Inverse(rotation_about_z));
expected_great_grand_child_transform.Translate(10.0, 30.0);
expected_great_grand_child_transform.PreconcatTransform(rotation_about_z);
ASSERT_TRUE(grand_child->render_surface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_surface_draw_transform,
grand_child->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
great_grand_child->SetPositionConstraint(fixed_to_bottom_right_);
ExecuteCalculateDrawProperties(root_.get());
expected_great_grand_child_transform.MakeIdentity();
expected_great_grand_child_transform.PreconcatTransform(
Inverse(rotation_about_z));
expected_great_grand_child_transform.Translate(10.0, 30.0);
expected_great_grand_child_transform.Translate(20.0, 20.0);
expected_great_grand_child_transform.PreconcatTransform(rotation_about_z);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
}
TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedPositionLayerWithMultipleIntermediateSurfaces) {
LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
LayerImpl* great_grand_child = grand_child->children()[0];
{
gfx::Transform identity;
scoped_ptr<LayerImpl> fixed_position_child =
LayerImpl::Create(host_impl_.active_tree(), 5);
SetLayerPropertiesForTesting(fixed_position_child.get(),
identity,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
great_grand_child->AddChild(fixed_position_child.Pass());
}
LayerImpl* fixed_position_child = great_grand_child->children()[0];
child->SetIsContainerForFixedPositionLayers(true);
grand_child->SetPosition(gfx::PointF(8.f, 6.f));
grand_child->SetForceRenderSurface(true);
great_grand_child->SetPosition(gfx::PointF(40.f, 60.f));
great_grand_child->SetForceRenderSurface(true);
fixed_position_child->SetPositionConstraint(fixed_to_top_left_);
fixed_position_child->SetDrawsContent(true);
gfx::Transform rotation_about_z;
rotation_about_z.Translate(50.0, 50.0);
rotation_about_z.RotateAboutZAxis(90.0);
rotation_about_z.Translate(-50.0, -50.0);
grand_child->SetTransform(rotation_about_z);
great_grand_child->SetTransform(rotation_about_z);
child->SetScrollDelta(gfx::Vector2d(0, 0));
ExecuteCalculateDrawProperties(root_.get());
gfx::Transform expected_child_transform;
gfx::Transform expected_grand_child_surface_draw_transform;
expected_grand_child_surface_draw_transform.Translate(8.0, 6.0);
expected_grand_child_surface_draw_transform.PreconcatTransform(
rotation_about_z);
gfx::Transform expected_grand_child_transform;
gfx::Transform expected_great_grand_child_surface_draw_transform;
expected_great_grand_child_surface_draw_transform.Translate(40.0, 60.0);
expected_great_grand_child_surface_draw_transform.PreconcatTransform(
rotation_about_z);
gfx::Transform expected_great_grand_child_transform;
gfx::Transform expected_fixed_position_child_transform;
ASSERT_TRUE(grand_child->render_surface());
ASSERT_TRUE(great_grand_child->render_surface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_grand_child_surface_draw_transform,
grand_child->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_great_grand_child_surface_draw_transform,
great_grand_child->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform,
fixed_position_child->draw_transform());
child->SetScrollDelta(gfx::Vector2d(10, 30));
ExecuteCalculateDrawProperties(root_.get());
expected_child_transform.MakeIdentity();
expected_child_transform.Translate(-10.0, -30.0);
expected_grand_child_surface_draw_transform.MakeIdentity();
expected_grand_child_surface_draw_transform.Translate(-10.0,
-30.0);
expected_grand_child_surface_draw_transform.Translate(8.0, 6.0);
expected_grand_child_surface_draw_transform.PreconcatTransform(
rotation_about_z);
gfx::Transform compound_draw_transform;
compound_draw_transform.Translate(8.0,
6.0);
compound_draw_transform.PreconcatTransform(
rotation_about_z);
compound_draw_transform.Translate(
40.0, 60.0);
compound_draw_transform.PreconcatTransform(
rotation_about_z);
expected_fixed_position_child_transform.MakeIdentity();
expected_fixed_position_child_transform.PreconcatTransform(
Inverse(compound_draw_transform));
expected_fixed_position_child_transform.Translate(10.0, 30.0);
expected_fixed_position_child_transform.PreconcatTransform(
compound_draw_transform);
ASSERT_TRUE(grand_child->render_surface());
ASSERT_TRUE(great_grand_child->render_surface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_grand_child_surface_draw_transform,
grand_child->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_great_grand_child_surface_draw_transform,
great_grand_child->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform,
fixed_position_child->draw_transform());
SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform,
fixed_position_child->draw_transform());
fixed_position_child->SetPositionConstraint(fixed_to_bottom_right_);
ExecuteCalculateDrawProperties(root_.get());
expected_fixed_position_child_transform.MakeIdentity();
expected_fixed_position_child_transform.PreconcatTransform(
Inverse(compound_draw_transform));
expected_fixed_position_child_transform.Translate(10.0, 30.0);
expected_fixed_position_child_transform.Translate(20.0, 20.0);
expected_fixed_position_child_transform.PreconcatTransform(
compound_draw_transform);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform,
fixed_position_child->draw_transform());
}
TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedPositionLayerWithContainerLayerThatHasSurface) {
LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
child->SetIsContainerForFixedPositionLayers(true);
child->SetForceRenderSurface(true);
grand_child->SetPositionConstraint(fixed_to_top_left_);
grand_child->SetDrawsContent(true);
child->SetScrollDelta(gfx::Vector2d(0, 0));
ExecuteCalculateDrawProperties(root_.get());
gfx::Transform expected_surface_draw_transform;
expected_surface_draw_transform.Translate(0.0, 0.0);
gfx::Transform expected_child_transform;
gfx::Transform expected_grand_child_transform;
ASSERT_TRUE(child->render_surface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
child->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
child->SetScrollDelta(gfx::Vector2d(10, 10));
ExecuteCalculateDrawProperties(root_.get());
expected_surface_draw_transform.MakeIdentity();
expected_surface_draw_transform.Translate(-10.0, -10.0);
expected_grand_child_transform.MakeIdentity();
expected_grand_child_transform.Translate(10.0, 10.0);
ASSERT_TRUE(child->render_surface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
child->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
grand_child->SetPositionConstraint(fixed_to_bottom_right_);
ExecuteCalculateDrawProperties(root_.get());
expected_grand_child_transform.MakeIdentity();
expected_grand_child_transform.Translate(10.0, 10.0);
expected_grand_child_transform.Translate(20.0, 20.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
}
TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedPositionLayerThatIsAlsoFixedPositionContainer) {
LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
child->SetIsContainerForFixedPositionLayers(true);
grand_child->SetPositionConstraint(fixed_to_top_left_);
grand_child->SetIsContainerForFixedPositionLayers(true);
child->SetScrollDelta(gfx::Vector2d(0, 0));
ExecuteCalculateDrawProperties(root_.get());
gfx::Transform expected_child_transform;
gfx::Transform expected_grand_child_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
child->SetScrollDelta(gfx::Vector2d(10, 10));
ExecuteCalculateDrawProperties(root_.get());
expected_child_transform.MakeIdentity();
expected_child_transform.Translate(-10.0, -10.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
grand_child->SetPositionConstraint(fixed_to_bottom_right_);
ExecuteCalculateDrawProperties(root_.get());
expected_grand_child_transform.MakeIdentity();
expected_grand_child_transform.Translate(20.0, 20.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
}
TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedWithinFixedWithSameContainer) {
LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
LayerImpl* great_grand_child = grand_child->children()[0];
child->SetIsContainerForFixedPositionLayers(true);
grand_child->SetPositionConstraint(fixed_to_top_left_);
great_grand_child->SetPositionConstraint(fixed_to_bottom_right_);
child->SetScrollDelta(gfx::Vector2d(10, 10));
ExecuteCalculateDrawProperties(root_.get());
gfx::Transform expected_child_transform;
expected_child_transform.Translate(-10.0, -10.0);
gfx::Transform expected_grand_child_transform;
gfx::Transform expected_great_grand_child_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
child->SetScrollDelta(gfx::Vector2d(0, 0));
SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
expected_child_transform.MakeIdentity();
expected_grand_child_transform.MakeIdentity();
expected_great_grand_child_transform.MakeIdentity();
expected_great_grand_child_transform.Translate(20.0, 20.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
great_grand_child->draw_transform());
}
TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedWithinFixedWithInterveningContainer) {
LayerImpl* container1 = scroll_->children()[0];
LayerImpl* fixed_to_container1 = container1->children()[0];
LayerImpl* container2 = fixed_to_container1->children()[0];
{
scoped_ptr<LayerImpl> fixed_to_container2_ptr =
LayerImpl::Create(host_impl_.active_tree(), 5);
container2->AddChild(fixed_to_container2_ptr.Pass());
}
LayerImpl* fixed_to_container2 = container2->children()[0];
container1->SetIsContainerForFixedPositionLayers(true);
fixed_to_container1->SetPositionConstraint(fixed_to_top_left_);
container2->SetIsContainerForFixedPositionLayers(true);
fixed_to_container2->SetPositionConstraint(fixed_to_top_left_);
container1->SetScrollDelta(gfx::Vector2d(0, 15));
container2->SetScrollDelta(gfx::Vector2d(30, 0));
ExecuteCalculateDrawProperties(root_.get());
gfx::Transform expected_container1_transform;
expected_container1_transform.Translate(0.0, -15.0);
gfx::Transform expected_fixed_to_container1_transform;
gfx::Transform expected_container2_transform;
expected_container2_transform.Translate(-30.0, 0.0);
gfx::Transform expected_fixed_to_container2_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_container1_transform,
container1->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_to_container1_transform,
fixed_to_container1->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_container2_transform,
container2->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_to_container2_transform,
fixed_to_container2->draw_transform());
}
}
}