This source file includes following definitions.
- SetLayerPropertiesForTestingInternal
- SetLayerPropertiesForTesting
- SetLayerPropertiesForTesting
- ExecuteCalculateDrawProperties
- ExecuteCalculateDrawProperties
- ExecuteCalculateDrawProperties
- ExecuteCalculateDrawProperties
- ExecuteCalculateDrawProperties
- render_surface_layer_list
- PaintContents
- DidChangeLayerCanUseLCDText
- FillsBoundsCompletely
- CreateDrawableContentLayer
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- Create
- CalculateContentsScale
- CreateNoScaleDrawableContentLayer
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- SetUp
- TEST_P
- TEST_P
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- EmptyCopyOutputCallback
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "cc/trees/layer_tree_host_common.h"
#include <set>
#include "cc/animation/layer_animation_controller.h"
#include "cc/base/math_util.h"
#include "cc/layers/content_layer.h"
#include "cc/layers/content_layer_client.h"
#include "cc/layers/heads_up_display_layer_impl.h"
#include "cc/layers/layer.h"
#include "cc/layers/layer_client.h"
#include "cc/layers/layer_impl.h"
#include "cc/layers/render_surface.h"
#include "cc/layers/render_surface_impl.h"
#include "cc/output/copy_output_request.h"
#include "cc/output/copy_output_result.h"
#include "cc/test/animation_test_common.h"
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/geometry_test_utils.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/proxy.h"
#include "cc/trees/single_thread_proxy.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/quad_f.h"
#include "ui/gfx/size_conversions.h"
#include "ui/gfx/transform.h"
namespace cc {
namespace {
class LayerTreeHostCommonTestBase {
protected:
template <typename LayerType>
void SetLayerPropertiesForTestingInternal(
LayerType* 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);
}
void SetLayerPropertiesForTesting(Layer* layer,
const gfx::Transform& transform,
const gfx::PointF& anchor,
const gfx::PointF& position,
const gfx::Size& bounds,
bool flatten_transform,
bool is_3d_sorted) {
SetLayerPropertiesForTestingInternal<Layer>(layer,
transform,
anchor,
position,
bounds,
flatten_transform,
is_3d_sorted);
}
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) {
SetLayerPropertiesForTestingInternal<LayerImpl>(layer,
transform,
anchor,
position,
bounds,
flatten_transform,
is_3d_sorted);
layer->SetContentBounds(bounds);
}
void ExecuteCalculateDrawProperties(Layer* root_layer,
float device_scale_factor,
float page_scale_factor,
Layer* page_scale_application_layer,
bool can_use_lcd_text) {
EXPECT_TRUE(page_scale_application_layer || (page_scale_factor == 1.f));
gfx::Transform identity_matrix;
gfx::Size device_viewport_size =
gfx::Size(root_layer->bounds().width() * device_scale_factor,
root_layer->bounds().height() * device_scale_factor);
render_surface_layer_list_.reset(new RenderSurfaceLayerList);
DCHECK(!root_layer->bounds().IsEmpty());
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root_layer, device_viewport_size, render_surface_layer_list_.get());
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;
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
}
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;
LayerImplList dummy_render_surface_layer_list;
gfx::Size device_viewport_size =
gfx::Size(root_layer->bounds().width() * device_scale_factor,
root_layer->bounds().height() * device_scale_factor);
DCHECK(!root_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;
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
}
template <class LayerType>
void ExecuteCalculateDrawProperties(LayerType* root_layer) {
LayerType* page_scale_application_layer = NULL;
ExecuteCalculateDrawProperties(
root_layer, 1.f, 1.f, page_scale_application_layer, false);
}
template <class LayerType>
void ExecuteCalculateDrawProperties(LayerType* root_layer,
float device_scale_factor) {
LayerType* page_scale_application_layer = NULL;
ExecuteCalculateDrawProperties(root_layer,
device_scale_factor,
1.f,
page_scale_application_layer,
false);
}
template <class LayerType>
void ExecuteCalculateDrawProperties(LayerType* root_layer,
float device_scale_factor,
float page_scale_factor,
LayerType* page_scale_application_layer) {
ExecuteCalculateDrawProperties(root_layer,
device_scale_factor,
page_scale_factor,
page_scale_application_layer,
false);
}
RenderSurfaceLayerList* render_surface_layer_list() const {
return render_surface_layer_list_.get();
}
private:
scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_;
};
class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
public testing::Test {
};
class LayerWithForcedDrawsContent : public Layer {
public:
LayerWithForcedDrawsContent() : Layer() {}
virtual bool DrawsContent() const OVERRIDE;
private:
virtual ~LayerWithForcedDrawsContent() {}
};
bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
class MockContentLayerClient : public ContentLayerClient {
public:
MockContentLayerClient() {}
virtual ~MockContentLayerClient() {}
virtual void PaintContents(SkCanvas* canvas,
const gfx::Rect& clip,
gfx::RectF* opaque) OVERRIDE {}
virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
};
scoped_refptr<ContentLayer> CreateDrawableContentLayer(
ContentLayerClient* delegate) {
scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate);
to_return->SetIsDrawable(true);
return to_return;
}
#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
do { \
EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
} while (false)
TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<Layer> grand_child = Layer::Create();
parent->AddChild(child);
child->AddChild(grand_child);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(),
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(),
true,
false);
ExecuteCalculateDrawProperties(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
child->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
grand_child->screen_space_transform());
}
TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
gfx::Transform identity_matrix;
scoped_refptr<Layer> layer = Layer::Create();
scoped_refptr<Layer> root = Layer::Create();
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(1, 2),
true,
false);
root->AddChild(layer);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform translation_to_center;
translation_to_center.Translate(5.0, 6.0);
SetLayerPropertiesForTesting(layer.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 12),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
layer->screen_space_transform());
SetLayerPropertiesForTesting(layer.get(),
identity_matrix,
gfx::PointF(0.25f, 0.25f),
gfx::PointF(),
gfx::Size(10, 12),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
layer->screen_space_transform());
gfx::Transform position_transform;
position_transform.Translate(0.f, 1.2f);
SetLayerPropertiesForTesting(layer.get(),
identity_matrix,
gfx::PointF(0.25f, 0.25f),
gfx::PointF(0.f, 1.2f),
gfx::Size(10, 12),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
layer->screen_space_transform());
gfx::Transform layer_transform;
layer_transform.Scale3d(2.0, 2.0, 1.0);
SetLayerPropertiesForTesting(layer.get(),
layer_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 12),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
layer->screen_space_transform());
gfx::Transform translation_to_anchor;
translation_to_anchor.Translate(5.0, 0.0);
gfx::Transform expected_result =
translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
SetLayerPropertiesForTesting(layer.get(),
layer_transform,
gfx::PointF(0.5f, 0.f),
gfx::PointF(),
gfx::Size(10, 12),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
layer->screen_space_transform());
expected_result = position_transform * translation_to_anchor *
layer_transform * Inverse(translation_to_anchor);
SetLayerPropertiesForTesting(layer.get(),
layer_transform,
gfx::PointF(0.5f, 0.f),
gfx::PointF(0.f, 1.2f),
gfx::Size(10, 12),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
layer->screen_space_transform());
}
TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
const gfx::Vector2d kScrollOffset(50, 100);
const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
const gfx::Vector2d kMaxScrollOffset(200, 200);
const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
-kScrollOffset.y());
const float kPageScale = 0.888f;
const float kDeviceScale = 1.666f;
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
gfx::Transform identity_matrix;
scoped_ptr<LayerImpl> sublayer_scoped_ptr(
LayerImpl::Create(host_impl.active_tree(), 1));
LayerImpl* sublayer = sublayer_scoped_ptr.get();
sublayer->SetContentsScale(kPageScale * kDeviceScale,
kPageScale * kDeviceScale);
SetLayerPropertiesForTesting(sublayer,
identity_matrix,
gfx::Point(),
gfx::PointF(),
gfx::Size(500, 500),
true,
false);
scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
LayerImpl::Create(host_impl.active_tree(), 2));
LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
SetLayerPropertiesForTesting(scroll_layer,
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 20),
true,
false);
scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
LayerImpl::Create(host_impl.active_tree(), 4));
LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
scroll_layer->SetScrollClipLayer(clip_layer->id());
clip_layer->SetBounds(
gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
scroll_layer->bounds().height() + kMaxScrollOffset.y()));
scroll_layer->SetScrollClipLayer(clip_layer->id());
scroll_layer->SetScrollDelta(kScrollDelta);
gfx::Transform impl_transform;
scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
clip_layer->AddChild(scroll_layer_scoped_ptr.Pass());
scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset);
scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(3, 4),
true,
false);
root->AddChild(clip_layer_scoped_ptr.Pass());
ExecuteCalculateDrawProperties(
root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
gfx::Transform expected_transform = identity_matrix;
gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
sub_layer_screen_position.Scale(kPageScale * kDeviceScale);
expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()),
MathUtil::Round(sub_layer_screen_position.y()));
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
sublayer->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
sublayer->screen_space_transform());
gfx::Transform arbitrary_translate;
const float kTranslateX = 10.6f;
const float kTranslateY = 20.6f;
arbitrary_translate.Translate(kTranslateX, kTranslateY);
SetLayerPropertiesForTesting(scroll_layer,
arbitrary_translate,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 20),
true,
false);
ExecuteCalculateDrawProperties(
root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
expected_transform.MakeIdentity();
expected_transform.Translate(
MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
sub_layer_screen_position.x()),
MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
sub_layer_screen_position.y()));
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
sublayer->draw_transform());
}
TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
gfx::Transform identity_matrix;
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<Layer> grand_child = Layer::Create();
root->AddChild(parent);
parent->AddChild(child);
child->AddChild(grand_child);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(1, 2),
true,
false);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(0.25f, 0.25f),
gfx::PointF(),
gfx::Size(10, 12),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(16, 18),
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(76, 78),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
child->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
grand_child->screen_space_transform());
gfx::Transform parent_position_transform;
parent_position_transform.Translate(0.f, 1.2f);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(0.25f, 0.25f),
gfx::PointF(0.f, 1.2f),
gfx::Size(10, 12),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(16, 18),
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(76, 78),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
child->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
grand_child->screen_space_transform());
gfx::Transform parent_layer_transform;
parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
gfx::Transform parent_translation_to_anchor;
parent_translation_to_anchor.Translate(2.5, 3.0);
gfx::Transform parent_composite_transform =
parent_translation_to_anchor * parent_layer_transform *
Inverse(parent_translation_to_anchor);
SetLayerPropertiesForTesting(parent.get(),
parent_layer_transform,
gfx::PointF(0.25f, 0.25f),
gfx::PointF(),
gfx::Size(10, 12),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(16, 18),
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(76, 78),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
child->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
grand_child->screen_space_transform());
}
TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> grand_child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
root->AddChild(parent);
parent->AddChild(child);
child->AddChild(grand_child);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(1, 2),
true,
false);
child->SetOpacity(0.5f);
child->SetForceRenderSurface(true);
gfx::Transform parent_layer_transform;
parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
gfx::Transform parent_translation_to_anchor;
parent_translation_to_anchor.Translate(25.0, 30.0);
gfx::Transform parent_composite_transform =
parent_translation_to_anchor * parent_layer_transform *
Inverse(parent_translation_to_anchor);
gfx::Vector2dF parent_composite_scale =
MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
1.f);
gfx::Transform surface_sublayer_transform;
surface_sublayer_transform.Scale(parent_composite_scale.x(),
parent_composite_scale.y());
gfx::Transform surface_sublayer_composite_transform =
parent_composite_transform * Inverse(surface_sublayer_transform);
ASSERT_FALSE(child->render_surface());
SetLayerPropertiesForTesting(parent.get(),
parent_layer_transform,
gfx::PointF(0.25f, 0.25f),
gfx::PointF(),
gfx::Size(100, 120),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(16, 18),
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(8, 10),
true,
false);
ExecuteCalculateDrawProperties(root.get());
ASSERT_TRUE(child->render_surface());
ASSERT_EQ(child, child->render_target());
EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
child->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
surface_sublayer_composite_transform,
child->render_target()->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
surface_sublayer_composite_transform,
child->render_target()->render_surface()->screen_space_transform());
}
TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<Layer> child_replica = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> grand_child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
root->AddChild(parent);
parent->AddChild(child);
child->AddChild(grand_child);
child->SetReplicaLayer(child_replica.get());
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(1, 2),
true,
false);
child->SetOpacity(0.5f);
gfx::Transform parent_layer_transform;
parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
gfx::Transform parent_translation_to_anchor;
parent_translation_to_anchor.Translate(2.5, 3.0);
gfx::Transform parent_composite_transform =
parent_translation_to_anchor * parent_layer_transform *
Inverse(parent_translation_to_anchor);
gfx::Transform replica_layer_transform;
replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
gfx::Vector2dF parent_composite_scale =
MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
1.f);
gfx::Transform surface_sublayer_transform;
surface_sublayer_transform.Scale(parent_composite_scale.x(),
parent_composite_scale.y());
gfx::Transform replica_composite_transform =
parent_composite_transform * replica_layer_transform *
Inverse(surface_sublayer_transform);
ASSERT_FALSE(child->render_surface());
SetLayerPropertiesForTesting(parent.get(),
parent_layer_transform,
gfx::PointF(0.25f, 0.25f),
gfx::PointF(),
gfx::Size(10, 12),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(16, 18),
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(-0.5f, -0.5f),
gfx::Size(1, 1),
true,
false);
SetLayerPropertiesForTesting(child_replica.get(),
replica_layer_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(),
true,
false);
ExecuteCalculateDrawProperties(root.get());
ASSERT_TRUE(child->render_surface());
ASSERT_EQ(child, child->render_target());
EXPECT_TRANSFORMATION_MATRIX_EQ(
replica_composite_transform,
child->render_target()->render_surface()->replica_draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
child->render_target()
->render_surface()
->replica_screen_space_transform());
}
TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<Layer> render_surface2 = Layer::Create();
scoped_refptr<Layer> child_of_root = Layer::Create();
scoped_refptr<Layer> child_of_rs1 = Layer::Create();
scoped_refptr<Layer> child_of_rs2 = Layer::Create();
scoped_refptr<Layer> replica_of_rs1 = Layer::Create();
scoped_refptr<Layer> replica_of_rs2 = Layer::Create();
scoped_refptr<Layer> grand_child_of_root = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
root->AddChild(parent);
parent->AddChild(render_surface1);
parent->AddChild(child_of_root);
render_surface1->AddChild(child_of_rs1);
render_surface1->AddChild(render_surface2);
render_surface2->AddChild(child_of_rs2);
child_of_root->AddChild(grand_child_of_root);
child_of_rs1->AddChild(grand_child_of_rs1);
child_of_rs2->AddChild(grand_child_of_rs2);
render_surface1->SetReplicaLayer(replica_of_rs1.get());
render_surface2->SetReplicaLayer(replica_of_rs2.get());
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
render_surface1->SetOpacity(0.5f);
render_surface2->SetOpacity(0.33f);
gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(1, 2),
true,
false);
gfx::Transform translation_to_anchor;
translation_to_anchor.Translate(2.5, 0.0);
gfx::Transform layer_transform;
layer_transform.Translate(1.0, 1.0);
gfx::Transform replica_layer_transform;
replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
gfx::Transform A =
translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
Inverse(translation_to_anchor);
gfx::Vector2dF surface1_parent_transform_scale =
MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
gfx::Transform surface1_sublayer_transform;
surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
surface1_parent_transform_scale.y());
gfx::Transform SS1 = surface1_sublayer_transform;
gfx::Transform S1 = Inverse(surface1_sublayer_transform);
gfx::Vector2dF surface2_parent_transform_scale =
MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
gfx::Transform surface2_sublayer_transform;
surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
surface2_parent_transform_scale.y());
gfx::Transform SS2 = surface2_sublayer_transform;
gfx::Transform S2 = Inverse(surface2_sublayer_transform);
SetLayerPropertiesForTesting(parent.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(render_surface2.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(child_of_root.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(child_of_rs1.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(child_of_rs2.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child_of_root.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(replica_of_rs1.get(),
replica_layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(),
gfx::Size(),
true,
false);
SetLayerPropertiesForTesting(replica_of_rs2.get(),
replica_layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(),
gfx::Size(),
true,
false);
ExecuteCalculateDrawProperties(root.get());
ASSERT_TRUE(root->render_surface());
ASSERT_FALSE(child_of_root->render_surface());
ASSERT_FALSE(grand_child_of_root->render_surface());
ASSERT_TRUE(render_surface1->render_surface());
ASSERT_FALSE(child_of_rs1->render_surface());
ASSERT_FALSE(grand_child_of_rs1->render_surface());
ASSERT_TRUE(render_surface2->render_surface());
ASSERT_FALSE(child_of_rs2->render_surface());
ASSERT_FALSE(grand_child_of_rs2->render_surface());
EXPECT_EQ(root, parent->render_target());
EXPECT_EQ(root, child_of_root->render_target());
EXPECT_EQ(root, grand_child_of_root->render_target());
EXPECT_EQ(render_surface1, render_surface1->render_target());
EXPECT_EQ(render_surface1, child_of_rs1->render_target());
EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
EXPECT_EQ(render_surface2, render_surface2->render_target());
EXPECT_EQ(render_surface2, child_of_rs2->render_target());
EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
grand_child_of_root->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
grand_child_of_rs1->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
grand_child_of_rs2->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
child_of_root->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
A * A * A, grand_child_of_root->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
render_surface1->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
child_of_rs1->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
grand_child_of_rs1->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
render_surface2->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
child_of_rs2->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
grand_child_of_rs2->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
A * A * S1, render_surface1->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
A * R * S1, render_surface1->render_surface()->replica_draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
A * A * S1, render_surface1->render_surface()->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
A * R * S1,
render_surface1->render_surface()->replica_screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
SS1 * A * S2, render_surface2->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
SS1 * R * S2,
render_surface2->render_surface()->replica_draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
A * A * A * S2,
render_surface2->render_surface()->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
A * A * R * S2,
render_surface2->render_surface()->replica_screen_space_transform());
EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(2.0,
child_of_root->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(
3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(2.0,
render_surface1->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(3.0,
child_of_rs1->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(
4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(3.0,
render_surface2->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(4.0,
child_of_rs2->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(
5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
}
TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> grand_child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
gfx::Transform rotation_about_y_axis;
rotation_about_y_axis.RotateAboutYAxis(30.0);
const gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child.get(),
rotation_about_y_axis,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
rotation_about_y_axis,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
root->AddChild(child);
child->AddChild(grand_child);
child->SetForceRenderSurface(true);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
ASSERT_TRUE(root->should_flatten_transform());
ASSERT_TRUE(child->should_flatten_transform());
ASSERT_TRUE(grand_child->should_flatten_transform());
gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
gfx::Transform expected_grand_child_draw_transform =
rotation_about_y_axis;
gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
flattened_rotation_about_y.FlattenTo2d();
gfx::Transform expected_grand_child_screen_space_transform =
flattened_rotation_about_y * rotation_about_y_axis;
ExecuteCalculateDrawProperties(root.get());
ASSERT_TRUE(child->render_surface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
child->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_child_screen_space_transform,
child->render_surface()->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
child->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
grand_child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
grand_child->screen_space_transform());
}
TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> grand_child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
const gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 0),
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
root->AddChild(child);
child->AddChild(grand_child);
child->SetForceRenderSurface(true);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
ExecuteCalculateDrawProperties(root.get());
ASSERT_TRUE(child->render_surface());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
child->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
grand_child->draw_transform());
}
TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
const gfx::Transform identity_matrix;
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
child->SetScrollClipLayerId(root->id());
root->AddChild(child);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
gfx::Transform translate;
translate.Translate(50, 50);
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), translate, &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_EQ(translate, root->draw_properties().target_space_transform);
EXPECT_EQ(translate, child->draw_properties().target_space_transform);
EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
}
gfx::Transform scale;
scale.Scale(2, 2);
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), scale, &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_EQ(scale, root->draw_properties().target_space_transform);
EXPECT_EQ(scale, child->draw_properties().target_space_transform);
EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
}
gfx::Transform rotate;
rotate.Rotate(2);
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), rotate, &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
}
gfx::Transform composite;
composite.ConcatTransform(translate);
composite.ConcatTransform(scale);
composite.ConcatTransform(rotate);
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), composite, &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_EQ(composite, root->draw_properties().target_space_transform);
EXPECT_EQ(composite, child->draw_properties().target_space_transform);
EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
}
float device_scale_factor = 1.5f;
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), translate, &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
gfx::Transform device_scaled_translate = translate;
device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
EXPECT_EQ(device_scaled_translate,
root->draw_properties().target_space_transform);
EXPECT_EQ(device_scaled_translate,
child->draw_properties().target_space_transform);
EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
}
float page_scale_factor = 2.f;
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), translate, &render_surface_layer_list);
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = root.get();
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
gfx::Transform page_scaled_translate = translate;
page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
EXPECT_EQ(translate, root->draw_properties().target_space_transform);
EXPECT_EQ(page_scaled_translate,
child->draw_properties().target_space_transform);
EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
}
root->SetTransform(composite);
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), composite, &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
gfx::Transform compositeSquared = composite;
compositeSquared.ConcatTransform(composite);
EXPECT_TRANSFORMATION_MATRIX_EQ(
compositeSquared, root->draw_properties().target_space_transform);
EXPECT_TRANSFORMATION_MATRIX_EQ(
compositeSquared, child->draw_properties().target_space_transform);
EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
}
}
TEST_F(LayerTreeHostCommonTest,
RenderSurfaceListForRenderSurfaceWithClippedLayer) {
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
const gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(30.f, 30.f),
gfx::Size(10, 10),
true,
false);
parent->AddChild(render_surface1);
parent->SetMasksToBounds(true);
render_surface1->AddChild(child);
render_surface1->SetForceRenderSurface(true);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(),
parent->bounds(),
gfx::Transform(),
&render_surface_layer_list);
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_TRUE(parent->render_surface());
ASSERT_FALSE(render_surface1->render_surface());
EXPECT_EQ(1U, render_surface_layer_list.size());
}
TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
const gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(render_surface1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
parent->AddChild(render_surface1);
render_surface1->AddChild(child);
render_surface1->SetForceRenderSurface(true);
render_surface1->SetOpacity(0.f);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_TRUE(parent->render_surface());
EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
EXPECT_EQ(1U, render_surface_layer_list.size());
EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
}
TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
render_surface1->SetForceRenderSurface(true);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
const gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
parent->AddChild(render_surface1);
render_surface1->AddChild(child);
EXPECT_FALSE(parent->render_surface());
EXPECT_FALSE(render_surface1->render_surface());
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_TRUE(parent->render_surface());
EXPECT_TRUE(render_surface1->render_surface());
EXPECT_EQ(2U, render_surface_layer_list.size());
}
{
RenderSurfaceLayerList render_surface_layer_list;
render_surface1->SetForceRenderSurface(false);
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_TRUE(parent->render_surface());
EXPECT_FALSE(render_surface1->render_surface());
EXPECT_EQ(1U, render_surface_layer_list.size());
}
}
TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
const gfx::Transform identity_matrix;
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<Layer> grand_child = Layer::Create();
scoped_refptr<Layer> great_grand_child = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
parent->AddChild(child);
child->AddChild(grand_child);
grand_child->AddChild(great_grand_child);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
child->AddChild(leaf_node1);
great_grand_child->AddChild(leaf_node2);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(500, 500),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(45.f, 45.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(great_grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(leaf_node1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(500, 500),
true,
false);
SetLayerPropertiesForTesting(leaf_node2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
child->SetMasksToBounds(true);
child->SetOpacity(0.4f);
child->SetForceRenderSurface(true);
grand_child->SetOpacity(0.5f);
great_grand_child->SetOpacity(0.4f);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(2U, render_surface_layer_list.size());
EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
}
TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
const gfx::Transform identity_matrix;
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<Layer> grand_child = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
make_scoped_refptr(new LayerWithForcedDrawsContent());
parent->AddChild(child);
child->AddChild(grand_child);
grand_child->AddChild(leaf_node);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(200.f, 200.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(leaf_node.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
parent->SetMasksToBounds(true);
child->SetOpacity(0.4f);
child->SetForceRenderSurface(true);
grand_child->SetOpacity(0.4f);
grand_child->SetForceRenderSurface(true);
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1U, render_surface_layer_list.size());
EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
}
AddAnimatedTransformToController(
child->layer_animation_controller(), 10.0, 30, 0);
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(3U, render_surface_layer_list.size());
EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
}
}
TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
const gfx::Transform identity_matrix;
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> child1 = Layer::Create();
scoped_refptr<Layer> child2 = Layer::Create();
scoped_refptr<Layer> grand_child = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
root->AddChild(parent);
parent->AddChild(child1);
parent->AddChild(child2);
child1->AddChild(grand_child);
child2->AddChild(leaf_node2);
grand_child->AddChild(leaf_node1);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
child2->SetForceRenderSurface(true);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(leaf_node1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(leaf_node2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_TRUE(root->render_surface());
ASSERT_TRUE(child2->render_surface());
EXPECT_FALSE(root->is_clipped());
EXPECT_TRUE(root->render_surface()->is_clipped());
EXPECT_FALSE(parent->is_clipped());
EXPECT_FALSE(child1->is_clipped());
EXPECT_FALSE(child2->is_clipped());
EXPECT_FALSE(child2->render_surface()->is_clipped());
EXPECT_FALSE(grand_child->is_clipped());
EXPECT_FALSE(leaf_node1->is_clipped());
EXPECT_FALSE(leaf_node2->is_clipped());
}
{
RenderSurfaceLayerList render_surface_layer_list;
parent->SetMasksToBounds(true);
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_TRUE(root->render_surface());
ASSERT_TRUE(child2->render_surface());
EXPECT_FALSE(root->is_clipped());
EXPECT_TRUE(root->render_surface()->is_clipped());
EXPECT_TRUE(parent->is_clipped());
EXPECT_TRUE(child1->is_clipped());
EXPECT_FALSE(child2->is_clipped());
EXPECT_TRUE(child2->render_surface()->is_clipped());
EXPECT_TRUE(grand_child->is_clipped());
EXPECT_TRUE(leaf_node1->is_clipped());
EXPECT_FALSE(leaf_node2->is_clipped());
}
{
RenderSurfaceLayerList render_surface_layer_list;
parent->SetMasksToBounds(false);
child2->SetMasksToBounds(true);
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_TRUE(root->render_surface());
ASSERT_TRUE(child2->render_surface());
EXPECT_FALSE(root->is_clipped());
EXPECT_TRUE(root->render_surface()->is_clipped());
EXPECT_FALSE(parent->is_clipped());
EXPECT_FALSE(child1->is_clipped());
EXPECT_TRUE(child2->is_clipped());
EXPECT_FALSE(child2->render_surface()->is_clipped());
EXPECT_FALSE(grand_child->is_clipped());
EXPECT_FALSE(leaf_node1->is_clipped());
EXPECT_TRUE(leaf_node2->is_clipped());
}
}
TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
const gfx::Transform identity_matrix;
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<Layer> grand_child1 = Layer::Create();
scoped_refptr<Layer> grand_child2 = Layer::Create();
scoped_refptr<Layer> grand_child3 = Layer::Create();
scoped_refptr<Layer> grand_child4 = Layer::Create();
parent->AddChild(child);
child->AddChild(grand_child1);
child->AddChild(grand_child2);
child->AddChild(grand_child3);
child->AddChild(grand_child4);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(500, 500),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
SetLayerPropertiesForTesting(grand_child1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(5.f, 5.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(15.f, 15.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child3.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(15.f, 15.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child4.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(45.f, 45.f),
gfx::Size(10, 10),
true,
false);
child->SetMasksToBounds(true);
grand_child3->SetMasksToBounds(true);
child->SetOpacity(0.4f);
grand_child1->SetOpacity(0.5f);
grand_child2->SetOpacity(0.5f);
grand_child3->SetOpacity(0.5f);
grand_child4->SetOpacity(0.5f);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
grand_child1->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
grand_child3->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
grand_child3->drawable_content_rect());
EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
}
TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
const gfx::Transform identity_matrix;
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<Layer> grand_child1 = Layer::Create();
scoped_refptr<Layer> grand_child2 = Layer::Create();
scoped_refptr<Layer> grand_child3 = Layer::Create();
scoped_refptr<Layer> grand_child4 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
parent->AddChild(child);
child->AddChild(grand_child1);
child->AddChild(grand_child2);
child->AddChild(grand_child3);
child->AddChild(grand_child4);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
grand_child1->AddChild(leaf_node1);
grand_child2->AddChild(leaf_node2);
grand_child3->AddChild(leaf_node3);
grand_child4->AddChild(leaf_node4);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(500, 500),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
SetLayerPropertiesForTesting(grand_child1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(5.f, 5.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(15.f, 15.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child3.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(15.f, 15.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child4.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(45.f, 45.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(leaf_node1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(leaf_node2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(leaf_node3.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(leaf_node4.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
child->SetMasksToBounds(true);
grand_child3->SetMasksToBounds(true);
grand_child4->SetMasksToBounds(true);
child->SetOpacity(0.4f);
child->SetForceRenderSurface(true);
grand_child1->SetOpacity(0.5f);
grand_child1->SetForceRenderSurface(true);
grand_child2->SetOpacity(0.5f);
grand_child2->SetForceRenderSurface(true);
grand_child3->SetOpacity(0.5f);
grand_child3->SetForceRenderSurface(true);
grand_child4->SetOpacity(0.5f);
grand_child4->SetForceRenderSurface(true);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_TRUE(grand_child1->render_surface());
ASSERT_TRUE(grand_child2->render_surface());
ASSERT_TRUE(grand_child3->render_surface());
EXPECT_FALSE(grand_child4->render_surface());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
grand_child1->render_surface()->clip_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
grand_child2->render_surface()->clip_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
grand_child3->render_surface()->clip_rect());
}
TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<Layer> render_surface2 = Layer::Create();
scoped_refptr<Layer> child_of_root = Layer::Create();
scoped_refptr<Layer> child_of_rs1 = Layer::Create();
scoped_refptr<Layer> child_of_rs2 = Layer::Create();
scoped_refptr<Layer> grand_child_of_root = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
parent->AddChild(render_surface1);
parent->AddChild(child_of_root);
render_surface1->AddChild(child_of_rs1);
render_surface1->AddChild(render_surface2);
render_surface2->AddChild(child_of_rs2);
child_of_root->AddChild(grand_child_of_root);
child_of_rs1->AddChild(grand_child_of_rs1);
child_of_rs2->AddChild(grand_child_of_rs2);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
render_surface1->SetForceRenderSurface(true);
render_surface2->SetForceRenderSurface(true);
gfx::Transform layer_transform;
layer_transform.Translate(1.0, 1.0);
SetLayerPropertiesForTesting(parent.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(2.5f, 0.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(2.5f, 0.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(render_surface2.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(2.5f, 0.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(child_of_root.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(2.5f, 0.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(child_of_rs1.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(2.5f, 0.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(child_of_rs2.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(2.5f, 0.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child_of_root.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(2.5f, 0.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(2.5f, 0.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
layer_transform,
gfx::PointF(0.25f, 0.f),
gfx::PointF(2.5f, 0.f),
gfx::Size(10, 10),
true,
false);
AddOpacityTransitionToController(
render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
AddOpacityTransitionToController(
grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
AddAnimatedTransformToController(
render_surface2->layer_animation_controller(), 10.0, 30, 0);
AddAnimatedTransformToController(
grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
AddAnimatedTransformToController(
grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
ExecuteCalculateDrawProperties(parent.get());
ASSERT_TRUE(parent->render_surface());
ASSERT_FALSE(child_of_root->render_surface());
ASSERT_FALSE(grand_child_of_root->render_surface());
ASSERT_TRUE(render_surface1->render_surface());
ASSERT_FALSE(child_of_rs1->render_surface());
ASSERT_FALSE(grand_child_of_rs1->render_surface());
ASSERT_TRUE(render_surface2->render_surface());
ASSERT_FALSE(child_of_rs2->render_surface());
ASSERT_FALSE(grand_child_of_rs2->render_surface());
EXPECT_EQ(parent, parent->render_target());
EXPECT_EQ(parent, child_of_root->render_target());
EXPECT_EQ(parent, grand_child_of_root->render_target());
EXPECT_EQ(render_surface1, render_surface1->render_target());
EXPECT_EQ(render_surface1, child_of_rs1->render_target());
EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
EXPECT_EQ(render_surface2, render_surface2->render_target());
EXPECT_EQ(render_surface2, child_of_rs2->render_target());
EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
EXPECT_FALSE(parent->draw_opacity_is_animating());
EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
EXPECT_FALSE(parent->draw_transform_is_animating());
EXPECT_FALSE(child_of_root->draw_transform_is_animating());
EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
EXPECT_FALSE(render_surface1->draw_transform_is_animating());
EXPECT_FALSE(render_surface1->render_surface()
->target_surface_transforms_are_animating());
EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
EXPECT_FALSE(render_surface2->draw_transform_is_animating());
EXPECT_TRUE(render_surface2->render_surface()
->target_surface_transforms_are_animating());
EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
EXPECT_FALSE(parent->screen_space_transform_is_animating());
EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
EXPECT_FALSE(render_surface1->render_surface()
->screen_space_transforms_are_animating());
EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
EXPECT_TRUE(render_surface2->render_surface()
->screen_space_transforms_are_animating());
EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(2.0,
child_of_root->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(
3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(2.0,
render_surface1->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(3.0,
child_of_rs1->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(
4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(3.0,
render_surface2->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(4.0,
child_of_rs2->screen_space_transform().matrix().get(1, 3));
EXPECT_FLOAT_EQ(
5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
}
TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
gfx::Transform layer_to_surface_transform;
gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
layer_content_rect = gfx::Rect(120, 120, 30, 30);
actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_TRUE(actual.IsEmpty());
layer_content_rect = gfx::Rect(80, 80, 30, 30);
expected = gfx::Rect(80, 80, 20, 20);
actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
}
TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
gfx::Transform layer_to_surface_transform;
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.Translate(10.0, 10.0);
gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.Translate(120.0, 120.0);
actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_TRUE(actual.IsEmpty());
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.Translate(80.0, 80.0);
expected = gfx::Rect(0, 0, 20, 20);
actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
}
TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
gfx::Transform layer_to_surface_transform;
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.Translate(50.0, 50.0);
layer_to_surface_transform.Rotate(45.0);
gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.Translate(-50.0, 0.0);
layer_to_surface_transform.Rotate(45.0);
actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_TRUE(actual.IsEmpty());
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.Rotate(45.0);
expected = gfx::Rect(0, 0, 30, 30);
actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
layer_to_surface_transform.Rotate(45.0);
expected = gfx::Rect(15, 0, 15, 30);
actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
}
TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
gfx::Transform layer_to_surface_transform;
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.RotateAboutYAxis(45.0);
gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
SkMScalar half_width_of_rotated_layer =
SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
layer_to_surface_transform.RotateAboutYAxis(45.0);
expected = gfx::Rect(50, 0, 50, 100);
actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
}
TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
gfx::Transform layer_to_surface_transform;
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.Translate(50.0, 50.0);
layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
layer_to_surface_transform.Translate(-50.0, -50.0);
layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
expected = gfx::Rect(gfx::Point(50, -50),
gfx::Size(100, 200));
actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
}
TEST_F(LayerTreeHostCommonTest,
VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
gfx::Transform layer_to_surface_transform;
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.Translate(50.0, 0.0);
layer_to_surface_transform.RotateAboutYAxis(45.0);
layer_to_surface_transform.Translate(-50.0, 0.0);
gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
}
TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
gfx::Transform layer_to_surface_transform;
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
layer_to_surface_transform.RotateAboutYAxis(45.0);
bool clipped;
MathUtil::MapQuad(layer_to_surface_transform,
gfx::QuadF(gfx::RectF(layer_content_rect)),
&clipped);
ASSERT_TRUE(clipped);
int expected_x_position = 0;
int expected_width = 10;
gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_EQ(expected_x_position, actual.x());
EXPECT_EQ(expected_width, actual.width());
}
TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
gfx::Transform layer_to_surface_transform;
layer_to_surface_transform.MakeIdentity();
layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
layer_to_surface_transform.RotateAboutYAxis(45.0);
layer_to_surface_transform.RotateAboutXAxis(80.0);
bool clipped;
gfx::RectF clipped_rect =
MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
MathUtil::ProjectQuad(
Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
ASSERT_TRUE(clipped);
gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
target_surface_rect, layer_content_rect, layer_to_surface_transform);
EXPECT_RECT_EQ(expected, actual);
}
TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> child2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> child3 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
root->AddChild(child1);
root->AddChild(child2);
root->AddChild(child3);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(child2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(75.f, 75.f),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(child3.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(125.f, 125.f),
gfx::Size(50, 50),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
root->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
}
TEST_F(LayerTreeHostCommonTest,
DrawableAndVisibleContentRectsForLayersClippedByLayer) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
root->AddChild(child);
child->AddChild(grand_child1);
child->AddChild(grand_child2);
child->AddChild(grand_child3);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(grand_child1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(5.f, 5.f),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(grand_child2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(75.f, 75.f),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(grand_child3.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(125.f, 125.f),
gfx::Size(50, 50),
true,
false);
child->SetMasksToBounds(true);
ExecuteCalculateDrawProperties(root.get());
ASSERT_FALSE(child->render_surface());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
root->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
grand_child1->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
grand_child2->drawable_content_rect());
EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
}
TEST_F(LayerTreeHostCommonTest,
DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> child2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> child3 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
root->AddChild(render_surface1);
render_surface1->AddChild(child1);
render_surface1->AddChild(child2);
render_surface1->AddChild(child3);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(3, 4),
true,
false);
SetLayerPropertiesForTesting(child1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(5.f, 5.f),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(child2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(75.f, 75.f),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(child3.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(125.f, 125.f),
gfx::Size(50, 50),
true,
false);
render_surface1->SetForceRenderSurface(true);
ExecuteCalculateDrawProperties(root.get());
ASSERT_TRUE(render_surface1->render_surface());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
root->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
render_surface1->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
render_surface1->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
}
TEST_F(LayerTreeHostCommonTest,
DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
root->AddChild(child);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform identity_matrix;
gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
ASSERT_FALSE(uninvertible_matrix.IsInvertible());
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child.get(),
uninvertible_matrix,
gfx::PointF(),
gfx::PointF(5.f, 5.f),
gfx::Size(50, 50),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRUE(child->visible_content_rect().IsEmpty());
EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
uninvertible_matrix.MakeIdentity();
uninvertible_matrix.matrix().set(2, 2, 0.0);
ASSERT_FALSE(uninvertible_matrix.IsInvertible());
SetLayerPropertiesForTesting(child.get(),
uninvertible_matrix,
gfx::PointF(),
gfx::PointF(5.f, 5.f),
gfx::Size(50, 50),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child->drawable_content_rect());
uninvertible_matrix.MakeIdentity();
uninvertible_matrix.Translate(500.0, 0.0);
uninvertible_matrix.matrix().set(2, 2, 0.0);
ASSERT_FALSE(uninvertible_matrix.IsInvertible());
SetLayerPropertiesForTesting(child.get(),
uninvertible_matrix,
gfx::PointF(),
gfx::PointF(5.f, 5.f),
gfx::Size(50, 50),
true,
false);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRUE(child->visible_content_rect().IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(505, 5, 50, 50), child->drawable_content_rect());
}
TEST_F(LayerTreeHostCommonTest,
DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> child2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> child3 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
root->AddChild(render_surface1);
render_surface1->AddChild(child1);
render_surface1->AddChild(child2);
render_surface1->AddChild(child3);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(3, 4),
true,
false);
SetLayerPropertiesForTesting(child1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(5.f, 5.f),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(child2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(75.f, 75.f),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(child3.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(125.f, 125.f),
gfx::Size(50, 50),
true,
false);
root->SetMasksToBounds(true);
render_surface1->SetForceRenderSurface(true);
ExecuteCalculateDrawProperties(root.get());
ASSERT_TRUE(render_surface1->render_surface());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
root->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
render_surface1->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
render_surface1->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
}
TEST_F(LayerTreeHostCommonTest,
DrawableAndVisibleContentRectsForSurfaceHierarchy) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<Layer> render_surface2 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> child2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> child3 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
root->AddChild(render_surface1);
render_surface1->AddChild(render_surface2);
render_surface2->AddChild(child1);
render_surface2->AddChild(child2);
render_surface2->AddChild(child3);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(3, 4),
true,
false);
SetLayerPropertiesForTesting(render_surface2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(7, 13),
true,
false);
SetLayerPropertiesForTesting(child1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(5.f, 5.f),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(child2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(75.f, 75.f),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(child3.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(125.f, 125.f),
gfx::Size(50, 50),
true,
false);
root->SetMasksToBounds(true);
render_surface1->SetForceRenderSurface(true);
render_surface2->SetForceRenderSurface(true);
ExecuteCalculateDrawProperties(root.get());
ASSERT_TRUE(render_surface1->render_surface());
ASSERT_TRUE(render_surface2->render_surface());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
root->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
render_surface1->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
render_surface2->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
render_surface1->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
render_surface2->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
}
TEST_F(LayerTreeHostCommonTest,
DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
root->AddChild(render_surface1);
render_surface1->AddChild(child1);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform identity_matrix;
gfx::Transform child_rotation;
child_rotation.Rotate(45.0);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(3, 4),
true,
false);
SetLayerPropertiesForTesting(child1.get(),
child_rotation,
gfx::PointF(0.5f, 0.5f),
gfx::PointF(25.f, 25.f),
gfx::Size(50, 50),
true,
false);
render_surface1->SetForceRenderSurface(true);
ExecuteCalculateDrawProperties(root.get());
ASSERT_TRUE(render_surface1->render_surface());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
root->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
render_surface1->visible_content_rect());
int diagonal_radius = ceil(sqrt(2.0) * 25.0);
gfx::Rect expected_surface_drawable_content =
gfx::Rect(50 - diagonal_radius,
50 - diagonal_radius,
diagonal_radius * 2,
diagonal_radius * 2);
EXPECT_RECT_EQ(expected_surface_drawable_content,
render_surface1->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
EXPECT_RECT_EQ(expected_surface_drawable_content,
child1->drawable_content_rect());
}
TEST_F(LayerTreeHostCommonTest,
DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
root->AddChild(render_surface1);
render_surface1->AddChild(child1);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform identity_matrix;
gfx::Transform child_rotation;
child_rotation.Rotate(45.0);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(3, 4),
true,
false);
SetLayerPropertiesForTesting(child1.get(),
child_rotation,
gfx::PointF(0.5f, 0.5f),
gfx::PointF(25.f, 25.f),
gfx::Size(50, 50),
true,
false);
root->SetMasksToBounds(true);
render_surface1->SetForceRenderSurface(true);
ExecuteCalculateDrawProperties(root.get());
ASSERT_TRUE(render_surface1->render_surface());
int diagonal_radius = ceil(sqrt(2.0) * 25.0);
gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
50 - diagonal_radius,
diagonal_radius * 2,
diagonal_radius * 2);
gfx::Rect expected_surface_drawable_content =
gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
EXPECT_RECT_EQ(expected_surface_drawable_content,
render_surface1->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
}
TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
MockContentLayerClient client;
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<ContentLayer> render_surface1 =
CreateDrawableContentLayer(&client);
scoped_refptr<ContentLayer> render_surface2 =
CreateDrawableContentLayer(&client);
scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client);
scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client);
scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client);
root->AddChild(render_surface1);
render_surface1->AddChild(render_surface2);
render_surface2->AddChild(child1);
render_surface2->AddChild(child2);
render_surface2->AddChild(child3);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(5.f, 5.f),
gfx::Size(3, 4),
true,
false);
SetLayerPropertiesForTesting(render_surface2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(5.f, 5.f),
gfx::Size(7, 13),
true,
false);
SetLayerPropertiesForTesting(child1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(5.f, 5.f),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(child2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(75.f, 75.f),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(child3.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(125.f, 125.f),
gfx::Size(50, 50),
true,
false);
float device_scale_factor = 2.f;
root->SetMasksToBounds(true);
render_surface1->SetForceRenderSurface(true);
render_surface2->SetForceRenderSurface(true);
ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
ASSERT_TRUE(render_surface1->render_surface());
ASSERT_TRUE(render_surface2->render_surface());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
root->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
render_surface1->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
render_surface2->render_surface()->DrawableContentRect());
EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
child2->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
child3->drawable_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8),
render_surface1->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26),
render_surface2->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect());
}
TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
const gfx::Transform identity_matrix;
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent>
front_facing_child_of_front_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent>
back_facing_child_of_front_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent>
front_facing_child_of_back_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent>
back_facing_child_of_back_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
parent->AddChild(front_facing_child);
parent->AddChild(back_facing_child);
parent->AddChild(front_facing_surface);
parent->AddChild(back_facing_surface);
front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
front_facing_child->SetDoubleSided(false);
back_facing_child->SetDoubleSided(false);
front_facing_surface->SetDoubleSided(false);
back_facing_surface->SetDoubleSided(false);
front_facing_child_of_front_facing_surface->SetDoubleSided(false);
back_facing_child_of_front_facing_surface->SetDoubleSided(false);
front_facing_child_of_back_facing_surface->SetDoubleSided(false);
back_facing_child_of_back_facing_surface->SetDoubleSided(false);
gfx::Transform backface_matrix;
backface_matrix.Translate(50.0, 50.0);
backface_matrix.RotateAboutYAxis(180.0);
backface_matrix.Translate(-50.0, -50.0);
front_facing_surface->SetOpacity(0.5f);
back_facing_surface->SetOpacity(0.5f);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(front_facing_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(back_facing_child.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(front_facing_surface.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(back_facing_surface.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_FALSE(front_facing_child->render_surface());
EXPECT_FALSE(back_facing_child->render_surface());
EXPECT_TRUE(front_facing_surface->render_surface());
EXPECT_TRUE(back_facing_surface->render_surface());
EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
ASSERT_EQ(3u, render_surface_layer_list.size());
EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
ASSERT_EQ(
3u,
render_surface_layer_list.at(0)->render_surface()->layer_list().size());
EXPECT_EQ(front_facing_child->id(),
render_surface_layer_list.at(0)
->render_surface()
->layer_list()
.at(0)
->id());
EXPECT_EQ(front_facing_surface->id(),
render_surface_layer_list.at(0)
->render_surface()
->layer_list()
.at(1)
->id());
EXPECT_EQ(back_facing_surface->id(),
render_surface_layer_list.at(0)
->render_surface()
->layer_list()
.at(2)
->id());
ASSERT_EQ(
2u,
render_surface_layer_list.at(1)->render_surface()->layer_list().size());
EXPECT_EQ(front_facing_surface->id(),
render_surface_layer_list.at(1)
->render_surface()
->layer_list()
.at(0)
->id());
EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
render_surface_layer_list.at(1)
->render_surface()
->layer_list()
.at(1)
->id());
ASSERT_EQ(
1u,
render_surface_layer_list.at(2)->render_surface()->layer_list().size());
EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
render_surface_layer_list.at(2)
->render_surface()
->layer_list()
.at(0)
->id());
}
TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
const gfx::Transform identity_matrix;
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent>
front_facing_child_of_front_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent>
back_facing_child_of_front_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent>
front_facing_child_of_back_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent>
back_facing_child_of_back_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
parent->AddChild(front_facing_child);
parent->AddChild(back_facing_child);
parent->AddChild(front_facing_surface);
parent->AddChild(back_facing_surface);
front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
front_facing_child->SetDoubleSided(false);
back_facing_child->SetDoubleSided(false);
front_facing_surface->SetDoubleSided(false);
back_facing_surface->SetDoubleSided(false);
front_facing_child_of_front_facing_surface->SetDoubleSided(false);
back_facing_child_of_front_facing_surface->SetDoubleSided(false);
front_facing_child_of_back_facing_surface->SetDoubleSided(false);
back_facing_child_of_back_facing_surface->SetDoubleSided(false);
gfx::Transform backface_matrix;
backface_matrix.Translate(50.0, 50.0);
backface_matrix.RotateAboutYAxis(180.0);
backface_matrix.Translate(-50.0, -50.0);
front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(front_facing_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(back_facing_child.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(front_facing_surface.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
false,
true);
SetLayerPropertiesForTesting(back_facing_surface.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
false,
true);
SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
true);
SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
true);
SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
true);
SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
true);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_FALSE(front_facing_child->render_surface());
EXPECT_FALSE(back_facing_child->render_surface());
EXPECT_TRUE(front_facing_surface->render_surface());
EXPECT_FALSE(back_facing_surface->render_surface());
EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
ASSERT_EQ(2u, render_surface_layer_list.size());
EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
ASSERT_EQ(
2u,
render_surface_layer_list.at(0)->render_surface()->layer_list().size());
EXPECT_EQ(front_facing_child->id(),
render_surface_layer_list.at(0)
->render_surface()->layer_list().at(0)->id());
EXPECT_EQ(front_facing_surface->id(),
render_surface_layer_list.at(0)
->render_surface()->layer_list().at(1)->id());
ASSERT_EQ(
2u,
render_surface_layer_list.at(1)->render_surface()->layer_list().size());
EXPECT_EQ(front_facing_surface->id(),
render_surface_layer_list.at(1)
->render_surface()->layer_list().at(0)->id());
EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
render_surface_layer_list.at(1)
->render_surface()->layer_list().at(1)->id());
}
TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
const gfx::Transform identity_matrix;
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> animating_child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> child2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
parent->AddChild(child);
parent->AddChild(animating_surface);
animating_surface->AddChild(child_of_animating_surface);
parent->AddChild(animating_child);
parent->AddChild(child2);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
child->SetDoubleSided(false);
child2->SetDoubleSided(false);
animating_surface->SetDoubleSided(false);
child_of_animating_surface->SetDoubleSided(false);
animating_child->SetDoubleSided(false);
gfx::Transform backface_matrix;
backface_matrix.Translate(50.0, 50.0);
backface_matrix.RotateAboutYAxis(180.0);
backface_matrix.Translate(-50.0, -50.0);
animating_surface->SetForceRenderSurface(true);
AddAnimatedTransformToController(
animating_surface->layer_animation_controller(), 10.0, 30, 0);
AddAnimatedTransformToController(
animating_child->layer_animation_controller(), 10.0, 30, 0);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(animating_surface.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child_of_animating_surface.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(animating_child.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_FALSE(child->render_surface());
EXPECT_TRUE(animating_surface->render_surface());
EXPECT_FALSE(child_of_animating_surface->render_surface());
EXPECT_FALSE(animating_child->render_surface());
EXPECT_FALSE(child2->render_surface());
ASSERT_EQ(2u, render_surface_layer_list.size());
EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
ASSERT_EQ(
3u,
render_surface_layer_list.at(0)->render_surface()->layer_list().size());
EXPECT_EQ(animating_surface->id(),
render_surface_layer_list.at(0)
->render_surface()->layer_list().at(0)->id());
EXPECT_EQ(animating_child->id(),
render_surface_layer_list.at(0)
->render_surface()->layer_list().at(1)->id());
EXPECT_EQ(child2->id(),
render_surface_layer_list.at(0)
->render_surface()->layer_list().at(2)->id());
ASSERT_EQ(
2u,
render_surface_layer_list.at(1)->render_surface()->layer_list().size());
EXPECT_EQ(animating_surface->id(),
render_surface_layer_list.at(1)
->render_surface()->layer_list().at(0)->id());
EXPECT_EQ(child_of_animating_surface->id(),
render_surface_layer_list.at(1)
->render_surface()->layer_list().at(1)->id());
EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
EXPECT_EQ(animating_child->visible_content_rect(),
gfx::Rect(animating_child->content_bounds()));
EXPECT_EQ(animating_surface->visible_content_rect(),
gfx::Rect(animating_surface->content_bounds()));
EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
gfx::Rect(child_of_animating_surface->content_bounds()));
}
TEST_F(LayerTreeHostCommonTest,
BackFaceCullingWithPreserves3dForFlatteningSurface) {
const gfx::Transform identity_matrix;
scoped_refptr<Layer> parent = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> child1 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> child2 =
make_scoped_refptr(new LayerWithForcedDrawsContent());
parent->AddChild(front_facing_surface);
parent->AddChild(back_facing_surface);
front_facing_surface->AddChild(child1);
back_facing_surface->AddChild(child2);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
front_facing_surface->SetDoubleSided(false);
back_facing_surface->SetDoubleSided(false);
gfx::Transform backface_matrix;
backface_matrix.Translate(50.0, 50.0);
backface_matrix.RotateAboutYAxis(180.0);
backface_matrix.Translate(-50.0, -50.0);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
false,
true);
SetLayerPropertiesForTesting(front_facing_surface.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
true);
SetLayerPropertiesForTesting(back_facing_surface.get(),
backface_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
true);
SetLayerPropertiesForTesting(child1.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child2.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
front_facing_surface->SetIs3dSorted(true);
back_facing_surface->SetIs3dSorted(true);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_TRUE(front_facing_surface->render_surface());
EXPECT_FALSE(
back_facing_surface->render_surface());
EXPECT_FALSE(child1->render_surface());
EXPECT_FALSE(child2->render_surface());
ASSERT_EQ(2u, render_surface_layer_list.size());
EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
ASSERT_EQ(
1u,
render_surface_layer_list.at(0)->render_surface()->layer_list().size());
EXPECT_EQ(front_facing_surface->id(),
render_surface_layer_list.at(0)
->render_surface()->layer_list().at(0)->id());
ASSERT_EQ(
2u,
render_surface_layer_list.at(1)->render_surface()->layer_list().size());
EXPECT_EQ(front_facing_surface->id(),
render_surface_layer_list.at(1)
->render_surface()->layer_list().at(0)->id());
EXPECT_EQ(child1->id(),
render_surface_layer_list.at(1)
->render_surface()->layer_list().at(1)->id());
}
TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayerList) {
LayerImplList render_surface_layer_list;
gfx::Point test_point(0, 0);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(10, 20);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
}
TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayer) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl.active_tree(), 12345);
gfx::Transform identity_matrix;
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
gfx::Point test_point(101, 101);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(-1, -1);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(1, 1);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
test_point = gfx::Point(99, 99);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerAndHud) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl.active_tree(), 12345);
scoped_ptr<HeadsUpDisplayLayerImpl> hud =
HeadsUpDisplayLayerImpl::Create(host_impl.active_tree(), 11111);
gfx::Transform identity_matrix;
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
gfx::Size hud_bounds(200, 200);
SetLayerPropertiesForTesting(hud.get(),
identity_matrix,
anchor,
position,
hud_bounds,
true,
false);
hud->SetDrawsContent(true);
host_impl.active_tree()->set_hud_layer(hud.get());
root->AddChild(hud.PassAs<LayerImpl>());
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), hud_bounds, &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(2u, root->render_surface()->layer_list().size());
gfx::Point test_point(101, 101);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(-1, -1);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(1, 1);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
test_point = gfx::Point(99, 99);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl.active_tree(), 12345);
gfx::Transform uninvertible_transform;
uninvertible_transform.matrix().set(0, 0, 0.0);
uninvertible_transform.matrix().set(1, 1, 0.0);
uninvertible_transform.matrix().set(2, 2, 0.0);
uninvertible_transform.matrix().set(3, 3, 0.0);
ASSERT_FALSE(uninvertible_transform.IsInvertible());
gfx::Transform identity_matrix;
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
uninvertible_transform,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
ASSERT_FALSE(root->screen_space_transform().IsInvertible());
gfx::Point test_point(1, 1);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(10, 10);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(10, 30);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(50, 50);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(67, 48);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(99, 99);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(-1, -1);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
}
TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePositionedLayer) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl.active_tree(), 12345);
gfx::Transform identity_matrix;
gfx::PointF anchor;
gfx::PointF position(50.f, 50.f);
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
gfx::Point test_point(49, 49);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(101, 101);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(51, 51);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
test_point = gfx::Point(99, 99);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest, HitTestingForSingleRotatedLayer) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl.active_tree(), 12345);
gfx::Transform identity_matrix;
gfx::Transform rotation45_degrees_about_center;
rotation45_degrees_about_center.Translate(50.0, 50.0);
rotation45_degrees_about_center.RotateAboutZAxis(45.0);
rotation45_degrees_about_center.Translate(-50.0, -50.0);
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
rotation45_degrees_about_center,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
gfx::Point test_point(99, 99);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(1, 1);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(1, 50);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
test_point = gfx::Point(50, -1);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_FALSE(result_layer);
test_point = gfx::Point(-1, 50);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_FALSE(result_layer);
}
TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePerspectiveLayer) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl.active_tree(), 12345);
gfx::Transform identity_matrix;
gfx::Transform perspective_projection_about_center;
perspective_projection_about_center.Translate(50.0, 50.0);
perspective_projection_about_center.ApplyPerspectiveDepth(1.0);
perspective_projection_about_center.Translate(-50.0, -50.0);
gfx::Transform translation_by_z;
translation_by_z.Translate3d(0.0, 0.0, -1.0);
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(
root.get(),
perspective_projection_about_center * translation_by_z,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
gfx::Point test_point(24, 24);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(76, 76);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(26, 26);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
test_point = gfx::Point(74, 74);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerWithScaledContents) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
gfx::Transform identity_matrix;
gfx::PointF anchor;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
{
gfx::PointF position(25.f, 25.f);
gfx::Size bounds(50, 50);
scoped_ptr<LayerImpl> test_layer =
LayerImpl::Create(host_impl.active_tree(), 12345);
SetLayerPropertiesForTesting(test_layer.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
test_layer->SetContentBounds(gfx::Size(100, 100));
test_layer->SetContentsScale(2, 2);
test_layer->SetDrawsContent(true);
root->AddChild(test_layer.Pass());
}
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
LayerImpl* test_layer = root->children()[0];
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
test_layer->visible_content_rect());
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
gfx::Point test_point(101, 101);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(24, 24);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(76, 76);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(26, 26);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
test_point = gfx::Point(74, 74);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest, HitTestingForSimpleClippedLayer) {
gfx::Transform identity_matrix;
gfx::PointF anchor;
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
{
scoped_ptr<LayerImpl> clipping_layer =
LayerImpl::Create(host_impl.active_tree(), 123);
gfx::PointF position(25.f, 25.f);
gfx::Size bounds(50, 50);
SetLayerPropertiesForTesting(clipping_layer.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
clipping_layer->SetMasksToBounds(true);
scoped_ptr<LayerImpl> child =
LayerImpl::Create(host_impl.active_tree(), 456);
position = gfx::PointF(-50.f, -50.f);
bounds = gfx::Size(300, 300);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
child->SetDrawsContent(true);
clipping_layer->AddChild(child.Pass());
root->AddChild(clipping_layer.Pass());
}
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
gfx::Point test_point(24, 24);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(76, 76);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(26, 26);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(456, result_layer->id());
test_point = gfx::Point(74, 74);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(456, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest, HitTestingForMultiClippedRotatedLayer) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 123);
gfx::Transform identity_matrix;
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
root->SetMasksToBounds(true);
{
scoped_ptr<LayerImpl> child =
LayerImpl::Create(host_impl.active_tree(), 456);
scoped_ptr<LayerImpl> grand_child =
LayerImpl::Create(host_impl.active_tree(), 789);
scoped_ptr<LayerImpl> rotated_leaf =
LayerImpl::Create(host_impl.active_tree(), 2468);
position = gfx::PointF(10.f, 10.f);
bounds = gfx::Size(80, 80);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
child->SetMasksToBounds(true);
gfx::Transform rotation45_degrees_about_corner;
rotation45_degrees_about_corner.RotateAboutZAxis(45.0);
position = gfx::PointF();
bounds =
gfx::Size(200, 200);
SetLayerPropertiesForTesting(grand_child.get(),
rotation45_degrees_about_corner,
anchor,
position,
bounds,
true,
false);
grand_child->SetMasksToBounds(true);
gfx::Transform rotated_leaf_transform;
rotated_leaf_transform.Translate(
-10.0, -10.0);
rotated_leaf_transform.RotateAboutZAxis(
-45.0);
rotated_leaf_transform.Translate(50.0, 50.0);
rotated_leaf_transform.RotateAboutZAxis(45.0);
rotated_leaf_transform.Translate(-50.0, -50.0);
position = gfx::PointF();
bounds = gfx::Size(100, 100);
SetLayerPropertiesForTesting(rotated_leaf.get(),
rotated_leaf_transform,
anchor,
position,
bounds,
true,
false);
rotated_leaf->SetDrawsContent(true);
grand_child->AddChild(rotated_leaf.Pass());
child->AddChild(grand_child.Pass());
root->AddChild(child.Pass());
}
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(2u, render_surface_layer_list.size());
ASSERT_EQ(
1u,
render_surface_layer_list.at(0)->render_surface()->layer_list().size());
ASSERT_EQ(789,
render_surface_layer_list.at(0)->render_surface()->layer_list().at(
0)->id());
ASSERT_EQ(
1u,
render_surface_layer_list.at(1)->render_surface()->layer_list().size());
ASSERT_EQ(
2468,
render_surface_layer_list[1]->render_surface()->layer_list().at(0)->id());
gfx::Point test_point(11, 89);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(25, 75);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(2468, result_layer->id());
test_point = gfx::Point(4, 50);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(11, 50);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(2468, result_layer->id());
test_point = gfx::Point(51, 49);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(49, 51);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(2468, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest, HitTestingForNonClippingIntermediateLayer) {
gfx::Transform identity_matrix;
gfx::PointF anchor;
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
{
scoped_ptr<LayerImpl> intermediate_layer =
LayerImpl::Create(host_impl.active_tree(), 123);
gfx::PointF position(10.f, 10.f);
gfx::Size bounds(50, 50);
SetLayerPropertiesForTesting(intermediate_layer.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
ASSERT_FALSE(intermediate_layer->masks_to_bounds());
ASSERT_FALSE(intermediate_layer->mask_layer());
scoped_ptr<LayerImpl> child =
LayerImpl::Create(host_impl.active_tree(), 456);
position = gfx::PointF(60.f, 60.f);
bounds = gfx::Size(20, 20);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
child->SetDrawsContent(true);
intermediate_layer->AddChild(child.Pass());
root->AddChild(intermediate_layer.Pass());
}
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
gfx::Point test_point(69, 69);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(91, 91);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(71, 71);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(456, result_layer->id());
test_point = gfx::Point(89, 89);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(456, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayers) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
gfx::Transform identity_matrix;
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
{
scoped_ptr<LayerImpl> child1 =
LayerImpl::Create(host_impl.active_tree(), 2);
scoped_ptr<LayerImpl> child2 =
LayerImpl::Create(host_impl.active_tree(), 3);
scoped_ptr<LayerImpl> grand_child1 =
LayerImpl::Create(host_impl.active_tree(), 4);
position = gfx::PointF(10.f, 10.f);
bounds = gfx::Size(50, 50);
SetLayerPropertiesForTesting(child1.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
child1->SetDrawsContent(true);
position = gfx::PointF(50.f, 10.f);
bounds = gfx::Size(50, 50);
SetLayerPropertiesForTesting(child2.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
child2->SetDrawsContent(true);
position = gfx::PointF(0.f, 40.f);
bounds = gfx::Size(100, 50);
SetLayerPropertiesForTesting(grand_child1.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
grand_child1->SetDrawsContent(true);
child1->AddChild(grand_child1.Pass());
root->AddChild(child1.Pass());
root->AddChild(child2.Pass());
}
LayerImpl* child1 = root->children()[0];
LayerImpl* child2 = root->children()[1];
LayerImpl* grand_child1 = child1->children()[0];
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_TRUE(child1);
ASSERT_TRUE(child2);
ASSERT_TRUE(grand_child1);
ASSERT_EQ(1u, render_surface_layer_list.size());
RenderSurfaceImpl* root_render_surface = root->render_surface();
ASSERT_EQ(4u, root_render_surface->layer_list().size());
ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id());
ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id());
ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id());
ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id());
gfx::Point test_point = gfx::Point(1, 1);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(1, result_layer->id());
test_point = gfx::Point(15, 15);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(2, result_layer->id());
test_point = gfx::Point(51, 20);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(3, result_layer->id());
test_point = gfx::Point(80, 51);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(3, result_layer->id());
test_point = gfx::Point(51, 51);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(3, result_layer->id());
test_point = gfx::Point(20, 51);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(4, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayerLists) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
gfx::Transform identity_matrix;
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
{
scoped_ptr<LayerImpl> child1 =
LayerImpl::Create(host_impl.active_tree(), 2);
scoped_ptr<LayerImpl> child2 =
LayerImpl::Create(host_impl.active_tree(), 3);
scoped_ptr<LayerImpl> grand_child1 =
LayerImpl::Create(host_impl.active_tree(), 4);
position = gfx::PointF(10.f, 10.f);
bounds = gfx::Size(50, 50);
SetLayerPropertiesForTesting(child1.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
child1->SetDrawsContent(true);
child1->SetForceRenderSurface(true);
position = gfx::PointF(50.f, 10.f);
bounds = gfx::Size(50, 50);
SetLayerPropertiesForTesting(child2.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
child2->SetDrawsContent(true);
child2->SetForceRenderSurface(true);
position = gfx::PointF(0.f, 40.f);
bounds = gfx::Size(100, 50);
SetLayerPropertiesForTesting(grand_child1.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
grand_child1->SetDrawsContent(true);
grand_child1->SetForceRenderSurface(true);
child1->AddChild(grand_child1.Pass());
root->AddChild(child1.Pass());
root->AddChild(child2.Pass());
}
LayerImpl* child1 = root->children()[0];
LayerImpl* child2 = root->children()[1];
LayerImpl* grand_child1 = child1->children()[0];
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_TRUE(child1);
ASSERT_TRUE(child2);
ASSERT_TRUE(grand_child1);
ASSERT_TRUE(child1->render_surface());
ASSERT_TRUE(child2->render_surface());
ASSERT_TRUE(grand_child1->render_surface());
ASSERT_EQ(4u, render_surface_layer_list.size());
ASSERT_EQ(3u, root->render_surface()->layer_list().size());
ASSERT_EQ(2u, child1->render_surface()->layer_list().size());
ASSERT_EQ(1u, child2->render_surface()->layer_list().size());
ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size());
ASSERT_EQ(1, render_surface_layer_list.at(0)->id());
ASSERT_EQ(2, render_surface_layer_list[1]->id());
ASSERT_EQ(4, render_surface_layer_list.at(2)->id());
ASSERT_EQ(3, render_surface_layer_list[3]->id());
gfx::Point test_point = gfx::Point(1, 1);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(1, result_layer->id());
test_point = gfx::Point(15, 15);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(2, result_layer->id());
test_point = gfx::Point(51, 20);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(3, result_layer->id());
test_point = gfx::Point(80, 51);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(3, result_layer->id());
test_point = gfx::Point(51, 51);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(3, result_layer->id());
test_point = gfx::Point(20, 51);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(4, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayers) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl.active_tree(), 1);
gfx::Transform identity_matrix;
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
{
gfx::PointF position(10.f, 10.f);
gfx::Size bounds(30, 30);
scoped_ptr<LayerImpl> empty_layer =
LayerImpl::Create(host_impl.active_tree(), 2);
SetLayerPropertiesForTesting(empty_layer.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
empty_layer->SetDrawsContent(false);
root->AddChild(empty_layer.Pass());
}
{
gfx::PointF position(10.f, 60.f);
gfx::Size bounds(30, 30);
scoped_ptr<LayerImpl> test_layer =
LayerImpl::Create(host_impl.active_tree(), 3);
SetLayerPropertiesForTesting(test_layer.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
test_layer->SetDrawsContent(false);
Region touch_handler_region(gfx::Rect(10, 10, 10, 10));
test_layer->SetTouchEventHandlerRegion(touch_handler_region);
root->AddChild(test_layer.Pass());
}
{
gfx::PointF position(60.f, 60.f);
gfx::Size bounds(30, 30);
scoped_ptr<LayerImpl> test_layer =
LayerImpl::Create(host_impl.active_tree(), 4);
SetLayerPropertiesForTesting(test_layer.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
test_layer->SetDrawsContent(false);
test_layer->SetHaveWheelEventHandlers(true);
root->AddChild(test_layer.Pass());
}
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
EXPECT_EQ(1, render_surface_layer_list[0]->id());
ASSERT_EQ(3u, root->render_surface()->layer_list().size());
EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
EXPECT_EQ(3, root->render_surface()->layer_list().at(1)->id());
EXPECT_EQ(4, root->render_surface()->layer_list().at(2)->id());
gfx::Point test_point = gfx::Point(15, 15);
LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(1, result_layer->id());
test_point = gfx::Point(15, 75);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(3, result_layer->id());
test_point = gfx::Point(75, 75);
result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(4, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest,
HitCheckingTouchHandlerRegionsForEmptyLayerList) {
LayerImplList render_surface_layer_list;
gfx::Point test_point(0, 0);
LayerImpl* result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(10, 20);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
}
TEST_F(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForSingleLayer) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl.active_tree(), 12345);
gfx::Transform identity_matrix;
Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
gfx::Point test_point(11, 11);
LayerImpl* result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
root->SetTouchEventHandlerRegion(touch_handler_region);
test_point = gfx::Point(101, 101);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(-1, -1);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(1, 1);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(99, 99);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(11, 11);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
test_point = gfx::Point(59, 59);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest,
HitCheckingTouchHandlerRegionsForUninvertibleTransform) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl.active_tree(), 12345);
gfx::Transform uninvertible_transform;
uninvertible_transform.matrix().set(0, 0, 0.0);
uninvertible_transform.matrix().set(1, 1, 0.0);
uninvertible_transform.matrix().set(2, 2, 0.0);
uninvertible_transform.matrix().set(3, 3, 0.0);
ASSERT_FALSE(uninvertible_transform.IsInvertible());
gfx::Transform identity_matrix;
Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
uninvertible_transform,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
root->SetTouchEventHandlerRegion(touch_handler_region);
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
ASSERT_FALSE(root->screen_space_transform().IsInvertible());
gfx::Point test_point(1, 1);
LayerImpl* result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(10, 10);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(10, 30);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(50, 50);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(67, 48);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(99, 99);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(-1, -1);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
}
TEST_F(LayerTreeHostCommonTest,
HitCheckingTouchHandlerRegionsForSinglePositionedLayer) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl.active_tree(), 12345);
gfx::Transform identity_matrix;
Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
gfx::PointF anchor;
gfx::PointF position(50.f, 50.f);
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
root->SetTouchEventHandlerRegion(touch_handler_region);
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
gfx::Point test_point(49, 49);
LayerImpl* result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(101, 101);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(51, 51);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(61, 61);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
test_point = gfx::Point(99, 99);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest,
HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
gfx::Transform identity_matrix;
gfx::PointF anchor;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
{
Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
gfx::PointF position(25.f, 25.f);
gfx::Size bounds(50, 50);
scoped_ptr<LayerImpl> test_layer =
LayerImpl::Create(host_impl.active_tree(), 12345);
SetLayerPropertiesForTesting(test_layer.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
test_layer->SetContentBounds(gfx::Size(100, 100));
test_layer->SetContentsScale(2, 2);
test_layer->SetDrawsContent(true);
test_layer->SetTouchEventHandlerRegion(touch_handler_region);
root->AddChild(test_layer.Pass());
}
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
LayerImpl* test_layer = root->children()[0];
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer->visible_content_rect());
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
gfx::Point test_point(76, 76);
LayerImpl* result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(26, 26);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(34, 34);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(65, 65);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(74, 74);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(35, 35);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
test_point = gfx::Point(64, 64);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest,
HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
gfx::Transform identity_matrix;
gfx::PointF anchor;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
{
Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
gfx::PointF position(25.f, 25.f);
gfx::Size bounds(50, 50);
scoped_ptr<LayerImpl> test_layer =
LayerImpl::Create(host_impl.active_tree(), 12345);
SetLayerPropertiesForTesting(test_layer.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
test_layer->SetDrawsContent(true);
test_layer->SetTouchEventHandlerRegion(touch_handler_region);
root->AddChild(test_layer.Pass());
}
LayerImplList render_surface_layer_list;
float device_scale_factor = 3.f;
float page_scale_factor = 5.f;
gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize(
gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor));
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), scaled_bounds_for_root, &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = root.get();
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
LayerImpl* test_layer = root->children()[0];
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()),
test_layer->visible_content_rect());
gfx::PointF test_point(76.f, 76.f);
test_point =
gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
LayerImpl* result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(26, 26);
test_point =
gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(34, 34);
test_point =
gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(65, 65);
test_point =
gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(74, 74);
test_point =
gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(35, 35);
test_point =
gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
test_point = gfx::Point(64, 64);
test_point =
gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(12345, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest,
HitCheckingTouchHandlerRegionsForSimpleClippedLayer) {
gfx::Transform identity_matrix;
gfx::PointF anchor;
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
{
scoped_ptr<LayerImpl> clipping_layer =
LayerImpl::Create(host_impl.active_tree(), 123);
gfx::PointF position(25.f, 25.f);
gfx::Size bounds(50, 50);
SetLayerPropertiesForTesting(clipping_layer.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
clipping_layer->SetMasksToBounds(true);
scoped_ptr<LayerImpl> child =
LayerImpl::Create(host_impl.active_tree(), 456);
Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
position = gfx::PointF(-50.f, -50.f);
bounds = gfx::Size(300, 300);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
child->SetDrawsContent(true);
child->SetTouchEventHandlerRegion(touch_handler_region);
clipping_layer->AddChild(child.Pass());
root->AddChild(clipping_layer.Pass());
}
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
gfx::Point test_point(24, 24);
LayerImpl* result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(35, 35);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(74, 74);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(25, 25);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(456, result_layer->id());
test_point = gfx::Point(34, 34);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(456, result_layer->id());
}
TEST_F(LayerTreeHostCommonTest,
HitCheckingTouchHandlerOverlappingRegions) {
gfx::Transform identity_matrix;
gfx::PointF anchor;
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
{
scoped_ptr<LayerImpl> touch_layer =
LayerImpl::Create(host_impl.active_tree(), 123);
gfx::PointF position;
gfx::Size bounds(50, 50);
SetLayerPropertiesForTesting(touch_layer.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
touch_layer->SetDrawsContent(true);
touch_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50));
root->AddChild(touch_layer.Pass());
}
{
scoped_ptr<LayerImpl> notouch_layer =
LayerImpl::Create(host_impl.active_tree(), 1234);
gfx::PointF position(0, 25);
gfx::Size bounds(50, 50);
SetLayerPropertiesForTesting(notouch_layer.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
notouch_layer->SetDrawsContent(true);
root->AddChild(notouch_layer.Pass());
}
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(2u, root->render_surface()->layer_list().size());
ASSERT_EQ(123, root->render_surface()->layer_list().at(0)->id());
ASSERT_EQ(1234, root->render_surface()->layer_list().at(1)->id());
gfx::Point test_point(35, 35);
LayerImpl* result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
test_point = gfx::Point(35, 15);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
ASSERT_TRUE(result_layer);
EXPECT_EQ(123, result_layer->id());
test_point = gfx::Point(35, 65);
result_layer =
LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
test_point, render_surface_layer_list);
EXPECT_FALSE(result_layer);
}
class NoScaleContentLayer : public ContentLayer {
public:
static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
return make_scoped_refptr(new NoScaleContentLayer(client));
}
virtual void CalculateContentsScale(float ideal_contents_scale,
float device_scale_factor,
float page_scale_factor,
bool animating_transform_to_screen,
float* contents_scale_x,
float* contents_scale_y,
gfx::Size* content_bounds) OVERRIDE {
Layer::CalculateContentsScale(ideal_contents_scale,
device_scale_factor,
page_scale_factor,
animating_transform_to_screen,
contents_scale_x,
contents_scale_y,
content_bounds);
}
protected:
explicit NoScaleContentLayer(ContentLayerClient* client)
: ContentLayer(client) {}
virtual ~NoScaleContentLayer() {}
};
scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
ContentLayerClient* delegate) {
scoped_refptr<NoScaleContentLayer> to_return =
NoScaleContentLayer::Create(delegate);
to_return->SetIsDrawable(true);
return to_return;
}
TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
MockContentLayerClient delegate;
gfx::Transform identity_matrix;
scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
false,
true);
scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(10, 10),
false,
true);
scoped_refptr<ContentLayer> child_empty =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child_empty.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(),
false,
true);
scoped_refptr<NoScaleContentLayer> child_no_scale =
CreateNoScaleDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child_no_scale.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(10, 10),
false,
true);
parent->AddChild(child);
parent->AddChild(child_empty);
parent->AddChild(child_no_scale);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
float device_scale_factor = 2.5f;
float page_scale_factor = 1.f;
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
child_empty);
EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
EXPECT_EQ(1u, render_surface_layer_list.size());
gfx::Transform expected_parent_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
parent->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
parent->draw_transform());
gfx::RectF parent_content_bounds(parent->content_bounds());
gfx::RectF parent_draw_rect =
MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
parent->screen_space_transform(), parent_content_bounds);
gfx::RectF expected_parent_draw_rect(parent->bounds());
expected_parent_draw_rect.Scale(device_scale_factor);
EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
gfx::Transform expected_child_transform;
expected_child_transform.Translate(
device_scale_factor * child->position().x(),
device_scale_factor * child->position().y());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child_empty->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child_empty->screen_space_transform());
gfx::RectF child_content_bounds(child->content_bounds());
gfx::RectF child_draw_rect =
MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
child->screen_space_transform(), child_content_bounds);
gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
child_empty->draw_transform(), child_content_bounds);
gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
child_empty->screen_space_transform(), child_content_bounds);
gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
expected_child_draw_rect.Scale(device_scale_factor);
EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
gfx::Transform expected_child_no_scale_transform = child->draw_transform();
expected_child_no_scale_transform.Scale(device_scale_factor,
device_scale_factor);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
child_no_scale->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
child_no_scale->screen_space_transform());
}
TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
MockContentLayerClient delegate;
gfx::Transform identity_matrix;
gfx::Transform perspective_matrix;
perspective_matrix.ApplyPerspectiveDepth(2.0);
gfx::Transform scale_small_matrix;
scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
false,
true);
scoped_refptr<ContentLayer> perspective_surface =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(perspective_surface.get(),
perspective_matrix * scale_small_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(10, 10),
false,
true);
scoped_refptr<ContentLayer> scale_surface =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(scale_surface.get(),
scale_small_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(10, 10),
false,
true);
perspective_surface->SetForceRenderSurface(true);
scale_surface->SetForceRenderSurface(true);
parent->AddChild(perspective_surface);
parent->AddChild(scale_surface);
root->AddChild(parent);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
float device_scale_factor = 2.5f;
float page_scale_factor = 3.f;
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), parent->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = root;
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
perspective_surface);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
scale_surface);
EXPECT_EQ(3u, render_surface_layer_list.size());
gfx::Transform expected_parent_draw_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
parent->draw_transform());
gfx::Transform expected_scale_surface_draw_transform;
expected_scale_surface_draw_transform.Translate(
device_scale_factor * page_scale_factor * scale_surface->position().x(),
device_scale_factor * page_scale_factor * scale_surface->position().y());
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_scale_surface_draw_transform,
scale_surface->render_surface()->draw_transform());
gfx::Transform expected_scale_surface_layer_draw_transform =
scale_small_matrix;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform,
scale_surface->draw_transform());
gfx::Transform expected_perspective_surface_draw_transform;
expected_perspective_surface_draw_transform.Translate(
device_scale_factor * page_scale_factor *
perspective_surface->position().x(),
device_scale_factor * page_scale_factor *
perspective_surface->position().y());
expected_perspective_surface_draw_transform.PreconcatTransform(
perspective_matrix);
expected_perspective_surface_draw_transform.PreconcatTransform(
scale_small_matrix);
gfx::Transform expected_perspective_surface_layer_draw_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_perspective_surface_draw_transform,
perspective_surface->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_perspective_surface_layer_draw_transform,
perspective_surface->draw_transform());
}
TEST_F(LayerTreeHostCommonTest,
LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
MockContentLayerClient delegate;
gfx::Transform identity_matrix;
scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(133, 133),
false,
true);
scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(13, 13),
false,
true);
scoped_refptr<NoScaleContentLayer> child_no_scale =
CreateNoScaleDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child_no_scale.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(13, 13),
false,
true);
parent->AddChild(child);
parent->AddChild(child_no_scale);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
float device_scale_factor = 1.7f;
float page_scale_factor = 1.f;
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = parent.get();
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
EXPECT_EQ(1u, render_surface_layer_list.size());
gfx::Transform expected_parent_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
parent->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
parent->draw_transform());
gfx::RectF parent_content_bounds(parent->content_bounds());
gfx::RectF parent_draw_rect =
MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
parent->screen_space_transform(), parent_content_bounds);
gfx::RectF expected_parent_draw_rect(parent->bounds());
expected_parent_draw_rect.Scale(device_scale_factor);
expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
expected_parent_draw_rect.set_height(
ceil(expected_parent_draw_rect.height()));
EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
gfx::Transform expected_child_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
child->screen_space_transform());
gfx::RectF child_content_bounds(child->content_bounds());
gfx::RectF child_draw_rect =
MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
child->screen_space_transform(), child_content_bounds);
gfx::RectF expected_child_draw_rect(child->bounds());
expected_child_draw_rect.Scale(device_scale_factor);
expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
gfx::Transform expected_child_no_scale_transform = child->draw_transform();
expected_child_no_scale_transform.Scale(device_scale_factor,
device_scale_factor);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
child_no_scale->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
child_no_scale->screen_space_transform());
}
TEST_F(LayerTreeHostCommonTest, ContentsScale) {
MockContentLayerClient delegate;
gfx::Transform identity_matrix;
gfx::Transform parent_scale_matrix;
SkMScalar initial_parent_scale = 1.75;
parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
gfx::Transform child_scale_matrix;
SkMScalar initial_child_scale = 1.25;
child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(gfx::Size(100, 100));
scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(parent.get(),
parent_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
false,
true);
scoped_refptr<ContentLayer> child_scale =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(10, 10),
false,
true);
scoped_refptr<ContentLayer> child_empty =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child_empty.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(),
false,
true);
scoped_refptr<NoScaleContentLayer> child_no_scale =
CreateNoScaleDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child_no_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(12.f, 12.f),
gfx::Size(10, 10),
false,
true);
root->AddChild(parent);
parent->AddChild(child_scale);
parent->AddChild(child_empty);
parent->AddChild(child_no_scale);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
float device_scale_factor = 2.5f;
float page_scale_factor = 1.f;
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = root.get();
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale, parent);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale * initial_child_scale,
child_scale);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale * initial_child_scale,
child_empty);
EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale * initial_child_scale,
child_no_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale * initial_child_scale,
child_no_scale->draw_transform().matrix().get(1, 1));
}
device_scale_factor = 2.25f;
page_scale_factor = 1.25f;
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = root.get();
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(
device_scale_factor * page_scale_factor * initial_parent_scale, parent);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale * initial_child_scale,
child_scale);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale * initial_child_scale,
child_empty);
EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
}
SkMScalar second_child_scale = 1.75;
child_scale_matrix.Scale(second_child_scale / initial_child_scale,
second_child_scale / initial_child_scale);
child_scale->SetTransform(child_scale_matrix);
child_empty->SetTransform(child_scale_matrix);
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = root.get();
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale,
parent);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
child_scale);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
child_empty);
EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
}
device_scale_factor = 2.75f;
page_scale_factor = 1.75f;
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = root.get();
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale,
parent);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
child_scale);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
child_empty);
EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
}
}
TEST_F(LayerTreeHostCommonTest,
ContentsScale_LayerTransformsDontAffectContentsScale) {
MockContentLayerClient delegate;
gfx::Transform identity_matrix;
gfx::Transform parent_scale_matrix;
SkMScalar initial_parent_scale = 1.75;
parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
gfx::Transform child_scale_matrix;
SkMScalar initial_child_scale = 1.25;
child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(gfx::Size(100, 100));
scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(parent.get(),
parent_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
false,
true);
scoped_refptr<ContentLayer> child_scale =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(10, 10),
false,
true);
scoped_refptr<ContentLayer> child_empty =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child_empty.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(),
false,
true);
scoped_refptr<NoScaleContentLayer> child_no_scale =
CreateNoScaleDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child_no_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(12.f, 12.f),
gfx::Size(10, 10),
false,
true);
root->AddChild(parent);
parent->AddChild(child_scale);
parent->AddChild(child_empty);
parent->AddChild(child_no_scale);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
RenderSurfaceLayerList render_surface_layer_list;
float device_scale_factor = 2.5f;
float page_scale_factor = 1.f;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = root.get(),
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
child_scale);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
child_empty);
EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
EXPECT_FLOAT_EQ(initial_parent_scale,
parent->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(initial_parent_scale,
parent->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
child_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
child_scale->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
child_empty->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
child_empty->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale * initial_child_scale,
child_no_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale * initial_child_scale,
child_no_scale->draw_transform().matrix().get(1, 1));
}
TEST_F(LayerTreeHostCommonTest, SmallContentsScale) {
MockContentLayerClient delegate;
gfx::Transform identity_matrix;
gfx::Transform parent_scale_matrix;
SkMScalar initial_parent_scale = 1.75;
parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
gfx::Transform child_scale_matrix;
SkMScalar initial_child_scale = 0.25;
child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(gfx::Size(100, 100));
scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(parent.get(),
parent_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
false,
true);
scoped_refptr<ContentLayer> child_scale =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(10, 10),
false,
true);
root->AddChild(parent);
parent->AddChild(child_scale);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
float device_scale_factor = 2.5f;
float page_scale_factor = 0.01f;
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = root.get();
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale,
parent);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1,
child_scale);
}
child_scale_matrix.MakeIdentity();
SkMScalar final_child_scale = 0.75;
child_scale_matrix.Scale(final_child_scale, final_child_scale);
child_scale->SetTransform(child_scale_matrix);
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = root.get();
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale,
parent);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale * final_child_scale,
child_scale);
}
}
TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
MockContentLayerClient delegate;
gfx::Transform identity_matrix;
gfx::Transform parent_scale_matrix;
SkMScalar initial_parent_scale = 2.0;
parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
gfx::Transform child_scale_matrix;
SkMScalar initial_child_scale = 3.0;
child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(gfx::Size(100, 100));
scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(parent.get(),
parent_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
false,
true);
scoped_refptr<ContentLayer> surface_scale =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(surface_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(10, 10),
false,
true);
scoped_refptr<ContentLayer> surface_scale_child_scale =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
false,
true);
scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
CreateNoScaleDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
false,
true);
scoped_refptr<NoScaleContentLayer> surface_no_scale =
CreateNoScaleDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(surface_no_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(12.f, 12.f),
gfx::Size(10, 10),
false,
true);
scoped_refptr<ContentLayer> surface_no_scale_child_scale =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
false,
true);
scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
CreateNoScaleDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
false,
true);
root->AddChild(parent);
parent->AddChild(surface_scale);
parent->AddChild(surface_no_scale);
surface_scale->SetForceRenderSurface(true);
surface_scale->AddChild(surface_scale_child_scale);
surface_scale->AddChild(surface_scale_child_no_scale);
surface_no_scale->SetForceRenderSurface(true);
surface_no_scale->AddChild(surface_no_scale_child_scale);
surface_no_scale->AddChild(surface_no_scale_child_no_scale);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
SkMScalar device_scale_factor = 5;
SkMScalar page_scale_factor = 7;
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = root.get();
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(
device_scale_factor * page_scale_factor * initial_parent_scale, parent);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale * initial_child_scale,
surface_scale);
EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
EXPECT_CONTENTS_SCALE_EQ(
device_scale_factor * page_scale_factor * initial_parent_scale *
initial_child_scale * initial_child_scale,
surface_scale_child_scale);
EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
EXPECT_CONTENTS_SCALE_EQ(
device_scale_factor * page_scale_factor * initial_parent_scale *
initial_child_scale * initial_child_scale,
surface_no_scale_child_scale);
EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(
1.0,
surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(
1.0,
surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(
1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(
1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(
device_scale_factor * page_scale_factor * initial_parent_scale *
initial_child_scale * initial_child_scale,
surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(
device_scale_factor * page_scale_factor * initial_parent_scale *
initial_child_scale * initial_child_scale,
surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(
1.0,
surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(
1.0,
surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale * initial_child_scale,
surface_no_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
initial_parent_scale * initial_child_scale,
surface_no_scale->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(
1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(
1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(
device_scale_factor * page_scale_factor * initial_parent_scale *
initial_child_scale * initial_child_scale,
surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(
device_scale_factor * page_scale_factor * initial_parent_scale *
initial_child_scale * initial_child_scale,
surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
}
TEST_F(LayerTreeHostCommonTest,
ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
MockContentLayerClient delegate;
gfx::Transform identity_matrix;
gfx::Transform parent_scale_matrix;
SkMScalar initial_parent_scale = 2.0;
parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
gfx::Transform child_scale_matrix;
SkMScalar initial_child_scale = 3.0;
child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(gfx::Size(100, 100));
scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(parent.get(),
parent_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
false,
true);
scoped_refptr<ContentLayer> surface_scale =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(surface_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(10, 10),
false,
true);
scoped_refptr<ContentLayer> surface_scale_child_scale =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
false,
true);
scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
CreateNoScaleDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
false,
true);
scoped_refptr<NoScaleContentLayer> surface_no_scale =
CreateNoScaleDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(surface_no_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(12.f, 12.f),
gfx::Size(10, 10),
false,
true);
scoped_refptr<ContentLayer> surface_no_scale_child_scale =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
false,
true);
scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
CreateNoScaleDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
false,
true);
root->AddChild(parent);
parent->AddChild(surface_scale);
parent->AddChild(surface_no_scale);
surface_scale->SetForceRenderSurface(true);
surface_scale->AddChild(surface_scale_child_scale);
surface_scale->AddChild(surface_scale_child_no_scale);
surface_no_scale->SetForceRenderSurface(true);
surface_no_scale->AddChild(surface_no_scale_child_scale);
surface_no_scale->AddChild(surface_no_scale_child_no_scale);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
RenderSurfaceLayerList render_surface_layer_list;
SkMScalar device_scale_factor = 5.0;
SkMScalar page_scale_factor = 7.0;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.page_scale_factor = page_scale_factor;
inputs.page_scale_application_layer = root.get();
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
parent);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
surface_scale);
EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
surface_scale_child_scale);
EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
surface_no_scale_child_scale);
EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
EXPECT_FLOAT_EQ(initial_parent_scale,
parent->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(initial_parent_scale,
parent->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(
initial_parent_scale * initial_child_scale,
surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(
initial_parent_scale * initial_child_scale,
surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(
initial_child_scale,
surface_scale_child_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(
initial_child_scale,
surface_scale_child_scale->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(
device_scale_factor * page_scale_factor * initial_child_scale,
surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(
device_scale_factor * page_scale_factor * initial_child_scale,
surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(
initial_parent_scale * initial_child_scale,
surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(
initial_parent_scale * initial_child_scale,
surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
surface_no_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
surface_no_scale->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(
initial_child_scale,
surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(
initial_child_scale,
surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
EXPECT_FLOAT_EQ(
device_scale_factor * page_scale_factor * initial_child_scale,
surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
EXPECT_FLOAT_EQ(
device_scale_factor * page_scale_factor * initial_child_scale,
surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
}
TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) {
MockContentLayerClient delegate;
gfx::Transform identity_matrix;
gfx::Transform parent_scale_matrix;
SkMScalar initial_parent_scale = 1.75;
parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
gfx::Transform child_scale_matrix;
SkMScalar initial_child_scale = 1.25;
child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(gfx::Size(100, 100));
scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(parent.get(),
parent_scale_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
false,
true);
scoped_refptr<ContentLayer> child_scale =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child_scale.get(),
child_scale_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(10, 10),
false,
true);
root->AddChild(parent);
parent->AddChild(child_scale);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
int animation_id = AddAnimatedTransformToController(
child_scale->layer_animation_controller(), 10.0, 30, 0);
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
EXPECT_CONTENTS_SCALE_EQ(1, child_scale);
}
child_scale->layer_animation_controller()->RemoveAnimation(animation_id);
{
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale,
child_scale);
}
}
TEST_F(LayerTreeHostCommonTest,
ChangeInContentBoundsOrScaleTriggersPushProperties) {
MockContentLayerClient delegate;
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate);
root->AddChild(child);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
root->reset_needs_push_properties_for_testing();
child->reset_needs_push_properties_for_testing();
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRUE(root->needs_push_properties());
EXPECT_TRUE(child->needs_push_properties());
root->reset_needs_push_properties_for_testing();
child->reset_needs_push_properties_for_testing();
ExecuteCalculateDrawProperties(root.get(), 2.f);
EXPECT_FALSE(root->needs_push_properties());
EXPECT_TRUE(child->needs_push_properties());
root->reset_needs_push_properties_for_testing();
child->reset_needs_push_properties_for_testing();
ExecuteCalculateDrawProperties(root.get(), 2.f);
EXPECT_FALSE(root->needs_push_properties());
EXPECT_FALSE(child->needs_push_properties());
}
TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
MockContentLayerClient delegate;
gfx::Transform identity_matrix;
scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
false,
true);
scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(10, 10),
false,
true);
gfx::Transform replica_transform;
replica_transform.Scale(1.0, -1.0);
scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(replica.get(),
replica_transform,
gfx::PointF(),
gfx::PointF(2.f, 2.f),
gfx::Size(10, 10),
false,
true);
scoped_refptr<ContentLayer> duplicate_child_non_owner =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
false,
true);
parent->AddChild(child);
child->AddChild(duplicate_child_non_owner);
child->SetReplicaLayer(replica.get());
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
RenderSurfaceLayerList render_surface_layer_list;
float device_scale_factor = 1.5f;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_EQ(2u, render_surface_layer_list.size());
gfx::Transform expected_parent_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
parent->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
parent->draw_transform());
gfx::Transform expected_draw_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
child->draw_transform());
gfx::Transform expected_screen_space_transform;
expected_screen_space_transform.Translate(
device_scale_factor * child->position().x(),
device_scale_factor * child->position().y());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
child->screen_space_transform());
gfx::Transform expected_duplicate_child_draw_transform =
child->draw_transform();
EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
duplicate_child_non_owner->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
child->screen_space_transform(),
duplicate_child_non_owner->screen_space_transform());
EXPECT_RECT_EQ(child->drawable_content_rect(),
duplicate_child_non_owner->drawable_content_rect());
EXPECT_EQ(child->content_bounds(),
duplicate_child_non_owner->content_bounds());
gfx::Transform expected_render_surface_draw_transform;
expected_render_surface_draw_transform.Translate(
device_scale_factor * child->position().x(),
device_scale_factor * child->position().y());
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
child->render_surface()->draw_transform());
gfx::Transform expected_surface_draw_transform;
expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
device_scale_factor * 2.f);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
child->render_surface()->draw_transform());
gfx::Transform expected_surface_screen_space_transform;
expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
device_scale_factor * 2.f);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_surface_screen_space_transform,
child->render_surface()->screen_space_transform());
gfx::Transform expected_replica_draw_transform;
expected_replica_draw_transform.matrix().set(1, 1, -1.0);
expected_replica_draw_transform.matrix().set(0, 3, 6.0);
expected_replica_draw_transform.matrix().set(1, 3, 6.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_replica_draw_transform,
child->render_surface()->replica_draw_transform());
gfx::Transform expected_replica_screen_space_transform;
expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_replica_screen_space_transform,
child->render_surface()->replica_screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_replica_screen_space_transform,
child->render_surface()->replica_screen_space_transform());
}
TEST_F(LayerTreeHostCommonTest,
RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
MockContentLayerClient delegate;
gfx::Transform identity_matrix;
scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(33, 31),
false,
true);
scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(13, 11),
false,
true);
gfx::Transform replica_transform;
replica_transform.Scale(1.0, -1.0);
scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(replica.get(),
replica_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(13, 11),
false,
true);
scoped_refptr<ContentLayer> duplicate_child_non_owner =
CreateDrawableContentLayer(&delegate);
SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(13, 11),
false,
true);
parent->AddChild(child);
child->AddChild(duplicate_child_non_owner);
child->SetReplicaLayer(replica.get());
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(parent);
float device_scale_factor = 1.7f;
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
parent.get(), parent->bounds(), &render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_EQ(2u, render_surface_layer_list.size());
gfx::Transform identity_transform;
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
parent->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
child->screen_space_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
duplicate_child_non_owner->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
identity_transform, duplicate_child_non_owner->screen_space_transform());
EXPECT_RECT_EQ(child->drawable_content_rect(),
duplicate_child_non_owner->drawable_content_rect());
EXPECT_EQ(child->content_bounds(),
duplicate_child_non_owner->content_bounds());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
child->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
child->render_surface()->draw_transform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
identity_transform, child->render_surface()->screen_space_transform());
gfx::Transform expected_replica_draw_transform;
expected_replica_draw_transform.matrix().set(1, 1, -1.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_replica_draw_transform,
child->render_surface()->replica_draw_transform());
gfx::Transform expected_replica_screen_space_transform;
expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected_replica_screen_space_transform,
child->render_surface()->replica_screen_space_transform());
}
TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<Layer> grand_child = Layer::Create();
scoped_refptr<Layer> mask_layer = Layer::Create();
scoped_refptr<Layer> replica_layer = Layer::Create();
grand_child->SetReplicaLayer(replica_layer.get());
child->AddChild(grand_child.get());
child->SetMaskLayer(mask_layer.get());
root->AddChild(child.get());
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
int nonexistent_id = -1;
EXPECT_EQ(root,
LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
EXPECT_EQ(child,
LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
EXPECT_EQ(
grand_child,
LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
EXPECT_EQ(
mask_layer,
LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
EXPECT_EQ(
replica_layer,
LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
EXPECT_EQ(
0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
}
TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> child = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> grand_child =
make_scoped_refptr(new LayerWithForcedDrawsContent());
const gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
root->AddChild(child);
child->AddChild(grand_child);
child->SetOpacity(0.5f);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
ExecuteCalculateDrawProperties(root.get());
EXPECT_FALSE(child->render_surface());
}
TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
host_impl.CreatePendingTree();
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
const gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
true,
false);
root->SetDrawsContent(true);
scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
child->SetDrawsContent(true);
child->SetOpacity(0.0f);
AddOpacityTransitionToController(
child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
root->AddChild(child.Pass());
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(2u, root->render_surface()->layer_list().size());
}
typedef std::tr1::tuple<bool, bool> LCDTextTestParam;
class LCDTextTest
: public LayerTreeHostCommonTestBase,
public testing::TestWithParam<LCDTextTestParam> {
protected:
virtual void SetUp() {
can_use_lcd_text_ = std::tr1::get<0>(GetParam());
root_ = Layer::Create();
child_ = Layer::Create();
grand_child_ = Layer::Create();
child_->AddChild(grand_child_.get());
root_->AddChild(child_.get());
gfx::Transform identity_matrix;
SetLayerPropertiesForTesting(root_.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(1, 1),
true,
false);
SetLayerPropertiesForTesting(child_.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(1, 1),
true,
false);
SetLayerPropertiesForTesting(grand_child_.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(1, 1),
true,
false);
child_->SetForceRenderSurface(std::tr1::get<1>(GetParam()));
host_ = FakeLayerTreeHost::Create();
host_->SetRootLayer(root_);
}
bool can_use_lcd_text_;
scoped_ptr<FakeLayerTreeHost> host_;
scoped_refptr<Layer> root_;
scoped_refptr<Layer> child_;
scoped_refptr<Layer> grand_child_;
};
TEST_P(LCDTextTest, CanUseLCDText) {
gfx::Transform identity_matrix;
ExecuteCalculateDrawProperties(
root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
gfx::Transform integral_translation;
integral_translation.Translate(1.0, 2.0);
child_->SetTransform(integral_translation);
ExecuteCalculateDrawProperties(
root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
gfx::Transform non_integral_translation;
non_integral_translation.Translate(1.5, 2.5);
child_->SetTransform(non_integral_translation);
ExecuteCalculateDrawProperties(
root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
EXPECT_FALSE(child_->can_use_lcd_text());
EXPECT_FALSE(grand_child_->can_use_lcd_text());
gfx::Transform rotation;
rotation.Rotate(10.0);
child_->SetTransform(rotation);
ExecuteCalculateDrawProperties(
root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
EXPECT_FALSE(child_->can_use_lcd_text());
EXPECT_FALSE(grand_child_->can_use_lcd_text());
gfx::Transform scale;
scale.Scale(2.0, 2.0);
child_->SetTransform(scale);
ExecuteCalculateDrawProperties(
root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
EXPECT_FALSE(child_->can_use_lcd_text());
EXPECT_FALSE(grand_child_->can_use_lcd_text());
gfx::Transform skew;
skew.SkewX(10.0);
child_->SetTransform(skew);
ExecuteCalculateDrawProperties(
root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
EXPECT_FALSE(child_->can_use_lcd_text());
EXPECT_FALSE(grand_child_->can_use_lcd_text());
child_->SetTransform(identity_matrix);
child_->SetOpacity(0.5f);
ExecuteCalculateDrawProperties(
root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
EXPECT_FALSE(child_->can_use_lcd_text());
EXPECT_FALSE(grand_child_->can_use_lcd_text());
child_->SetTransform(identity_matrix);
child_->SetOpacity(1.f);
ExecuteCalculateDrawProperties(
root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
}
TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
ExecuteCalculateDrawProperties(
root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
child_->SetOpacity(0.9f);
AddOpacityTransitionToController(
child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
ExecuteCalculateDrawProperties(
root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
}
INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
LCDTextTest,
testing::Combine(testing::Bool(), testing::Bool()));
TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
host_impl.CreatePendingTree();
const gfx::Transform identity_matrix;
scoped_refptr<Layer> root = Layer::Create();
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
root->SetIsDrawable(true);
scoped_refptr<Layer> child = Layer::Create();
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
child->SetIsDrawable(true);
scoped_refptr<Layer> grand_child = Layer::Create();
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
true,
false);
grand_child->SetIsDrawable(true);
grand_child->SetHideLayerAndSubtree(true);
child->AddChild(grand_child);
root->AddChild(child);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(2u, root->render_surface()->layer_list().size());
EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
}
TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
host_impl.CreatePendingTree();
const gfx::Transform identity_matrix;
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
root->SetDrawsContent(true);
scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
child->SetDrawsContent(true);
scoped_ptr<LayerImpl> grand_child =
LayerImpl::Create(host_impl.pending_tree(), 3);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
true,
false);
grand_child->SetDrawsContent(true);
grand_child->SetHideLayerAndSubtree(true);
child->AddChild(grand_child.Pass());
root->AddChild(child.Pass());
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(2u, root->render_surface()->layer_list().size());
EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
}
TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
host_impl.CreatePendingTree();
const gfx::Transform identity_matrix;
scoped_refptr<Layer> root = Layer::Create();
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
root->SetIsDrawable(true);
scoped_refptr<Layer> child = Layer::Create();
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
child->SetIsDrawable(true);
child->SetHideLayerAndSubtree(true);
scoped_refptr<Layer> grand_child = Layer::Create();
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
true,
false);
grand_child->SetIsDrawable(true);
child->AddChild(grand_child);
root->AddChild(child);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
}
TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
host_impl.CreatePendingTree();
const gfx::Transform identity_matrix;
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
root->SetDrawsContent(true);
scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
SetLayerPropertiesForTesting(child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
child->SetDrawsContent(true);
child->SetHideLayerAndSubtree(true);
scoped_ptr<LayerImpl> grand_child =
LayerImpl::Create(host_impl.pending_tree(), 3);
SetLayerPropertiesForTesting(grand_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
true,
false);
grand_child->SetDrawsContent(true);
child->AddChild(grand_child.Pass());
root->AddChild(child.Pass());
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
}
void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
host_impl.CreatePendingTree();
const gfx::Transform identity_matrix;
scoped_refptr<Layer> root = Layer::Create();
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
root->SetIsDrawable(true);
scoped_refptr<Layer> copy_grand_parent = Layer::Create();
SetLayerPropertiesForTesting(copy_grand_parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
copy_grand_parent->SetIsDrawable(true);
scoped_refptr<Layer> copy_parent = Layer::Create();
SetLayerPropertiesForTesting(copy_parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
true,
false);
copy_parent->SetIsDrawable(true);
copy_parent->SetForceRenderSurface(true);
scoped_refptr<Layer> copy_layer = Layer::Create();
SetLayerPropertiesForTesting(copy_layer.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
copy_layer->SetIsDrawable(true);
scoped_refptr<Layer> copy_child = Layer::Create();
SetLayerPropertiesForTesting(copy_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
copy_child->SetIsDrawable(true);
scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
copy_grand_parent_sibling_before->SetIsDrawable(true);
scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
copy_grand_parent_sibling_after->SetIsDrawable(true);
copy_layer->AddChild(copy_child);
copy_parent->AddChild(copy_layer);
copy_grand_parent->AddChild(copy_parent);
root->AddChild(copy_grand_parent_sibling_before);
root->AddChild(copy_grand_parent);
root->AddChild(copy_grand_parent_sibling_after);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
copy_grand_parent->SetHideLayerAndSubtree(true);
copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
base::Bind(&EmptyCopyOutputCallback)));
EXPECT_TRUE(copy_layer->HasCopyRequest());
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
EXPECT_TRUE(copy_grand_parent->draw_properties().
layer_or_descendant_has_copy_request);
EXPECT_TRUE(copy_parent->draw_properties().
layer_or_descendant_has_copy_request);
EXPECT_TRUE(copy_layer->draw_properties().
layer_or_descendant_has_copy_request);
EXPECT_FALSE(copy_child->draw_properties().
layer_or_descendant_has_copy_request);
EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
layer_or_descendant_has_copy_request);
EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
layer_or_descendant_has_copy_request);
ASSERT_EQ(3u, render_surface_layer_list.size());
EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
ASSERT_EQ(2u, root->render_surface()->layer_list().size());
EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
EXPECT_EQ(copy_parent->id(),
root->render_surface()->layer_list().at(1)->id());
ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
EXPECT_EQ(copy_layer->id(),
copy_parent->render_surface()->layer_list().at(0)->id());
ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
EXPECT_EQ(copy_layer->id(),
copy_layer->render_surface()->layer_list().at(0)->id());
EXPECT_EQ(copy_child->id(),
copy_layer->render_surface()->layer_list().at(1)->id());
}
TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
host_impl.CreatePendingTree();
const gfx::Transform identity_matrix;
scoped_refptr<Layer> root = Layer::Create();
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
root->SetIsDrawable(true);
scoped_refptr<Layer> copy_parent = Layer::Create();
SetLayerPropertiesForTesting(copy_parent.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(),
true,
false);
copy_parent->SetIsDrawable(true);
copy_parent->SetMasksToBounds(true);
scoped_refptr<Layer> copy_layer = Layer::Create();
SetLayerPropertiesForTesting(copy_layer.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
true,
false);
copy_layer->SetIsDrawable(true);
scoped_refptr<Layer> copy_child = Layer::Create();
SetLayerPropertiesForTesting(copy_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
copy_child->SetIsDrawable(true);
copy_layer->AddChild(copy_child);
copy_parent->AddChild(copy_layer);
root->AddChild(copy_parent);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
base::Bind(&EmptyCopyOutputCallback)));
EXPECT_TRUE(copy_layer->HasCopyRequest());
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ASSERT_EQ(1u, render_surface_layer_list.size());
EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
ASSERT_EQ(1u, root->render_surface()->layer_list().size());
EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
}
TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
host_impl.CreatePendingTree();
const gfx::Transform identity_matrix;
scoped_refptr<Layer> root = Layer::Create();
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
root->SetIsDrawable(true);
scoped_refptr<Layer> surface = Layer::Create();
SetLayerPropertiesForTesting(surface.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(-10, -20),
gfx::Size(),
true,
false);
surface->SetForceRenderSurface(true);
scoped_refptr<Layer> surface_child = Layer::Create();
SetLayerPropertiesForTesting(surface_child.get(),
identity_matrix,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
surface_child->SetIsDrawable(true);
surface->AddChild(surface_child);
root->AddChild(surface);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_adjust_raster_scales = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_EQ(gfx::Rect(50, 50).ToString(),
surface_child->visible_content_rect().ToString());
}
TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> render_surface = Layer::Create();
scoped_refptr<Layer> clip_parent = Layer::Create();
scoped_refptr<Layer> intervening = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> clip_child =
make_scoped_refptr(new LayerWithForcedDrawsContent);
root->AddChild(render_surface);
render_surface->AddChild(clip_parent);
clip_parent->AddChild(intervening);
intervening->AddChild(clip_child);
clip_child->SetClipParent(clip_parent.get());
intervening->SetMasksToBounds(true);
clip_parent->SetMasksToBounds(true);
render_surface->SetForceRenderSurface(true);
gfx::Transform scale_transform;
scale_transform.Scale(2, 2);
gfx::Transform identity_transform;
SetLayerPropertiesForTesting(root.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(render_surface.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(clip_parent.get(),
scale_transform,
gfx::PointF(),
gfx::PointF(1.f, 1.f),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(intervening.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(1.f, 1.f),
gfx::Size(5, 5),
true,
false);
SetLayerPropertiesForTesting(clip_child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(1.f, 1.f),
gfx::Size(10, 10),
true,
false);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
ExecuteCalculateDrawProperties(root.get());
ASSERT_TRUE(root->render_surface());
ASSERT_TRUE(render_surface->render_surface());
ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
clip_parent->clip_rect().ToString());
ASSERT_EQ(clip_parent->clip_rect().ToString(),
clip_child->clip_rect().ToString());
ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
intervening->clip_rect().ToString());
ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
render_surface->render_surface()->content_rect().ToString());
ASSERT_TRUE(clip_parent->clip_rect().Contains(
render_surface->render_surface()->content_rect()));
ASSERT_FALSE(intervening->clip_rect().Contains(
render_surface->render_surface()->content_rect()));
}
TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> clip_parent = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<Layer> intervening = Layer::Create();
scoped_refptr<Layer> render_surface2 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> clip_child =
make_scoped_refptr(new LayerWithForcedDrawsContent);
root->AddChild(clip_parent);
clip_parent->AddChild(render_surface1);
render_surface1->AddChild(intervening);
intervening->AddChild(render_surface2);
render_surface2->AddChild(clip_child);
clip_child->SetClipParent(clip_parent.get());
intervening->SetMasksToBounds(true);
clip_parent->SetMasksToBounds(true);
render_surface1->SetForceRenderSurface(true);
render_surface2->SetForceRenderSurface(true);
gfx::Transform translation_transform;
translation_transform.Translate(2, 2);
gfx::Transform identity_transform;
SetLayerPropertiesForTesting(root.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(clip_parent.get(),
translation_transform,
gfx::PointF(),
gfx::PointF(1.f, 1.f),
gfx::Size(40, 40),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(intervening.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(1.f, 1.f),
gfx::Size(5, 5),
true,
false);
SetLayerPropertiesForTesting(render_surface2.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(clip_child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(-10.f, -10.f),
gfx::Size(60, 60),
true,
false);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRUE(root->render_surface());
EXPECT_TRUE(render_surface1->render_surface());
EXPECT_TRUE(render_surface2->render_surface());
EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
render_surface1->render_surface()->clip_rect().ToString());
EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
render_surface2->render_surface()->clip_rect().ToString());
EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
render_surface1->clip_rect().ToString());
EXPECT_TRUE(render_surface1->is_clipped());
EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
render_surface2->clip_rect().ToString());
EXPECT_TRUE(render_surface2->is_clipped());
EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
render_surface1->render_surface()->content_rect().ToString());
EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
render_surface2->render_surface()->content_rect().ToString());
EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
clip_child->clip_rect().ToString());
EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
clip_child->visible_content_rect().ToString());
EXPECT_TRUE(clip_child->is_clipped());
}
TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> clip_parent = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<Layer> intervening = Layer::Create();
scoped_refptr<Layer> render_surface2 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> clip_child =
make_scoped_refptr(new LayerWithForcedDrawsContent);
root->AddChild(clip_parent);
clip_parent->AddChild(render_surface1);
render_surface1->AddChild(intervening);
intervening->AddChild(render_surface2);
render_surface2->AddChild(clip_child);
clip_child->SetClipParent(clip_parent.get());
intervening->SetMasksToBounds(true);
clip_parent->SetMasksToBounds(true);
intervening->SetScrollClipLayerId(clip_parent->id());
intervening->SetScrollOffset(gfx::Vector2d(3, 3));
render_surface1->SetForceRenderSurface(true);
render_surface2->SetForceRenderSurface(true);
gfx::Transform translation_transform;
translation_transform.Translate(2, 2);
gfx::Transform identity_transform;
SetLayerPropertiesForTesting(root.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(clip_parent.get(),
translation_transform,
gfx::PointF(),
gfx::PointF(1.f, 1.f),
gfx::Size(40, 40),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(intervening.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(1.f, 1.f),
gfx::Size(5, 5),
true,
false);
SetLayerPropertiesForTesting(render_surface2.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(clip_child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(-10.f, -10.f),
gfx::Size(60, 60),
true,
false);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRUE(root->render_surface());
EXPECT_TRUE(render_surface1->render_surface());
EXPECT_TRUE(render_surface2->render_surface());
EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
render_surface1->render_surface()->clip_rect().ToString());
EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
render_surface2->render_surface()->clip_rect().ToString());
EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
render_surface1->clip_rect().ToString());
EXPECT_TRUE(render_surface1->is_clipped());
EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
render_surface2->clip_rect().ToString());
EXPECT_TRUE(render_surface2->is_clipped());
EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
render_surface1->render_surface()->content_rect().ToString());
EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
render_surface2->render_surface()->content_rect().ToString());
EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
clip_child->clip_rect().ToString());
EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
clip_child->visible_content_rect().ToString());
EXPECT_TRUE(clip_child->is_clipped());
}
TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> clip_parent = Layer::Create();
scoped_refptr<Layer> intervening = Layer::Create();
scoped_refptr<Layer> clip_child = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child =
make_scoped_refptr(new LayerWithForcedDrawsContent);
root->AddChild(clip_parent);
clip_parent->AddChild(intervening);
intervening->AddChild(clip_child);
clip_child->AddChild(child);
clip_child->SetClipParent(clip_parent.get());
intervening->SetMasksToBounds(true);
clip_parent->SetMasksToBounds(true);
gfx::Transform identity_transform;
SetLayerPropertiesForTesting(root.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(clip_parent.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
SetLayerPropertiesForTesting(intervening.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(5, 5),
true,
false);
SetLayerPropertiesForTesting(clip_child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(60, 60),
true,
false);
SetLayerPropertiesForTesting(child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(60, 60),
true,
false);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRUE(root->render_surface());
EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
clip_child->clip_rect().ToString());
EXPECT_TRUE(clip_child->is_clipped());
EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
child->visible_content_rect().ToString());
EXPECT_TRUE(child->is_clipped());
}
TEST_F(LayerTreeHostCommonTest,
SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> clip_parent = Layer::Create();
scoped_refptr<Layer> render_surface1 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> clip_child =
make_scoped_refptr(new LayerWithForcedDrawsContent);
scoped_refptr<Layer> render_surface2 = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
make_scoped_refptr(new LayerWithForcedDrawsContent);
root->AddChild(clip_parent);
clip_parent->AddChild(render_surface1);
render_surface1->AddChild(clip_child);
clip_parent->AddChild(render_surface2);
render_surface2->AddChild(non_clip_child);
clip_child->SetClipParent(clip_parent.get());
clip_parent->SetMasksToBounds(true);
render_surface1->SetMasksToBounds(true);
gfx::Transform identity_transform;
SetLayerPropertiesForTesting(root.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(15, 15),
true,
false);
SetLayerPropertiesForTesting(clip_parent.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(5, 5),
gfx::Size(5, 5),
true,
false);
SetLayerPropertiesForTesting(render_surface2.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(5, 5),
true,
false);
SetLayerPropertiesForTesting(clip_child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(-1, 1),
gfx::Size(10, 10),
true,
false);
SetLayerPropertiesForTesting(non_clip_child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(5, 5),
true,
false);
render_surface1->SetForceRenderSurface(true);
render_surface2->SetForceRenderSurface(true);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRUE(root->render_surface());
EXPECT_TRUE(render_surface1->render_surface());
EXPECT_TRUE(render_surface2->render_surface());
EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
render_surface1->clip_rect().ToString());
EXPECT_TRUE(render_surface1->is_clipped());
EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
render_surface1->render_surface()->clip_rect().ToString());
EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
render_surface1->render_surface()->content_rect().ToString());
EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
render_surface2->clip_rect().ToString());
EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
render_surface2->render_surface()->content_rect().ToString());
EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
}
TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl.active_tree(), 12345);
scoped_ptr<LayerImpl> child1 =
LayerImpl::Create(host_impl.active_tree(), 123456);
scoped_ptr<LayerImpl> child2 =
LayerImpl::Create(host_impl.active_tree(), 1234567);
scoped_ptr<LayerImpl> child3 =
LayerImpl::Create(host_impl.active_tree(), 12345678);
gfx::Transform identity_matrix;
gfx::PointF anchor;
gfx::PointF position;
gfx::Size bounds(100, 100);
SetLayerPropertiesForTesting(root.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
root->SetDrawsContent(true);
SetLayerPropertiesForTesting(child1.get(),
identity_matrix,
anchor,
position,
bounds,
false,
true);
child1->SetDrawsContent(true);
SetLayerPropertiesForTesting(child2.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
child2->SetDrawsContent(true);
SetLayerPropertiesForTesting(child3.get(),
identity_matrix,
anchor,
position,
bounds,
true,
false);
child3->SetDrawsContent(true);
child2->SetIs3dSorted(true);
child3->SetIs3dSorted(true);
child2->AddChild(child3.Pass());
child1->AddChild(child2.Pass());
root->AddChild(child1.Pass());
{
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_render_to_separate_surface = true;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_EQ(2u, render_surface_layer_list.size());
}
{
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
inputs.can_render_to_separate_surface = false;
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_EQ(1u, render_surface_layer_list.size());
}
}
TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> render_surface = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child =
make_scoped_refptr(new LayerWithForcedDrawsContent);
root->AddChild(render_surface);
render_surface->AddChild(child);
gfx::Transform identity_transform;
SetLayerPropertiesForTesting(root.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(render_surface.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
false,
true);
SetLayerPropertiesForTesting(child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
root->SetShouldFlattenTransform(false);
root->SetIs3dSorted(true);
render_surface->SetDoubleSided(false);
render_surface->SetForceRenderSurface(true);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
ExecuteCalculateDrawProperties(root.get());
EXPECT_EQ(2u, render_surface_layer_list()->size());
EXPECT_EQ(1u,
render_surface_layer_list()->at(0)
->render_surface()->layer_list().size());
EXPECT_EQ(1u,
render_surface_layer_list()->at(1)
->render_surface()->layer_list().size());
gfx::Transform rotation_transform = identity_transform;
rotation_transform.RotateAboutXAxis(180.0);
render_surface->SetTransform(rotation_transform);
ExecuteCalculateDrawProperties(root.get());
EXPECT_EQ(1u, render_surface_layer_list()->size());
EXPECT_EQ(0u,
render_surface_layer_list()->at(0)
->render_surface()->layer_list().size());
}
TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> scroll_parent_border = Layer::Create();
scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
make_scoped_refptr(new LayerWithForcedDrawsContent);
scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
make_scoped_refptr(new LayerWithForcedDrawsContent);
root->AddChild(scroll_child);
root->AddChild(scroll_parent_border);
scroll_parent_border->AddChild(scroll_parent_clip);
scroll_parent_clip->AddChild(scroll_parent);
scroll_parent_clip->SetMasksToBounds(true);
scroll_child->SetScrollParent(scroll_parent.get());
gfx::Transform identity_transform;
SetLayerPropertiesForTesting(root.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(scroll_parent_border.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
SetLayerPropertiesForTesting(scroll_parent_clip.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
true,
false);
SetLayerPropertiesForTesting(scroll_parent.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(scroll_child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRUE(root->render_surface());
EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
scroll_child->clip_rect().ToString());
EXPECT_TRUE(scroll_child->is_clipped());
}
TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> scroll_parent_border = Layer::Create();
scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
make_scoped_refptr(new LayerWithForcedDrawsContent);
scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
make_scoped_refptr(new LayerWithForcedDrawsContent);
root->AddChild(scroll_parent_border);
scroll_parent_border->AddChild(scroll_parent_clip);
scroll_parent_clip->AddChild(scroll_parent);
root->AddChild(scroll_child);
scroll_parent_clip->SetMasksToBounds(true);
scroll_child->SetScrollParent(scroll_parent.get());
gfx::Transform identity_transform;
SetLayerPropertiesForTesting(root.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(scroll_parent_border.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
SetLayerPropertiesForTesting(scroll_parent_clip.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
true,
false);
SetLayerPropertiesForTesting(scroll_parent.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(scroll_child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRUE(root->render_surface());
EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
scroll_child->clip_rect().ToString());
EXPECT_TRUE(scroll_child->is_clipped());
}
TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> scroll_parent_border = Layer::Create();
scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
make_scoped_refptr(new LayerWithForcedDrawsContent);
scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
make_scoped_refptr(new LayerWithForcedDrawsContent);
scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
make_scoped_refptr(new LayerWithForcedDrawsContent);
root->AddChild(scroll_child);
root->AddChild(scroll_parent_border);
scroll_parent_border->AddChild(scroll_parent_clip);
scroll_parent_clip->AddChild(scroll_parent);
root->AddChild(scroll_grandparent_border);
scroll_grandparent_border->AddChild(scroll_grandparent_clip);
scroll_grandparent_clip->AddChild(scroll_grandparent);
scroll_parent_clip->SetMasksToBounds(true);
scroll_grandparent_clip->SetMasksToBounds(true);
scroll_child->SetScrollParent(scroll_parent.get());
scroll_parent_border->SetScrollParent(scroll_grandparent.get());
gfx::Transform identity_transform;
SetLayerPropertiesForTesting(root.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
SetLayerPropertiesForTesting(scroll_grandparent.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(scroll_parent_border.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
SetLayerPropertiesForTesting(scroll_parent_clip.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
true,
false);
SetLayerPropertiesForTesting(scroll_parent.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(scroll_child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
ExecuteCalculateDrawProperties(root.get());
EXPECT_TRUE(root->render_surface());
EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
scroll_child->clip_rect().ToString());
EXPECT_TRUE(scroll_child->is_clipped());
EXPECT_EQ(3u, root->render_surface()->layer_list().size());
EXPECT_EQ(scroll_child.get(),
root->render_surface()->layer_list().at(0));
EXPECT_EQ(scroll_parent.get(),
root->render_surface()->layer_list().at(1));
EXPECT_EQ(scroll_grandparent.get(),
root->render_surface()->layer_list().at(2));
}
TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
scoped_refptr<LayerWithForcedDrawsContent> root =
make_scoped_refptr(new LayerWithForcedDrawsContent);
scoped_refptr<Layer> scroll_parent_border = Layer::Create();
scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
make_scoped_refptr(new LayerWithForcedDrawsContent);
scoped_refptr<LayerWithForcedDrawsContent> render_surface1 =
make_scoped_refptr(new LayerWithForcedDrawsContent);
scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
make_scoped_refptr(new LayerWithForcedDrawsContent);
scoped_refptr<LayerWithForcedDrawsContent> render_surface2 =
make_scoped_refptr(new LayerWithForcedDrawsContent);
scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
make_scoped_refptr(new LayerWithForcedDrawsContent);
root->AddChild(scroll_child);
root->AddChild(scroll_parent_border);
scroll_parent_border->AddChild(scroll_parent_clip);
scroll_parent_clip->AddChild(scroll_parent);
scroll_parent->AddChild(render_surface2);
root->AddChild(scroll_grandparent_border);
scroll_grandparent_border->AddChild(scroll_grandparent_clip);
scroll_grandparent_clip->AddChild(scroll_grandparent);
scroll_grandparent->AddChild(render_surface1);
scroll_parent_clip->SetMasksToBounds(true);
scroll_grandparent_clip->SetMasksToBounds(true);
scroll_child->SetScrollParent(scroll_parent.get());
scroll_parent_border->SetScrollParent(scroll_grandparent.get());
render_surface1->SetForceRenderSurface(true);
render_surface2->SetForceRenderSurface(true);
gfx::Transform identity_transform;
SetLayerPropertiesForTesting(root.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(20, 20),
true,
false);
SetLayerPropertiesForTesting(scroll_grandparent.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(render_surface1.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(scroll_parent_border.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
SetLayerPropertiesForTesting(scroll_parent_clip.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
true,
false);
SetLayerPropertiesForTesting(scroll_parent.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(render_surface2.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(scroll_child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
host->SetRootLayer(root);
RenderSurfaceLayerList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
root.get(),
root->bounds(),
identity_transform,
&render_surface_layer_list);
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_TRUE(root->render_surface());
EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
scroll_child->clip_rect().ToString());
EXPECT_TRUE(scroll_child->is_clipped());
EXPECT_EQ(3u, render_surface_layer_list.size());
EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
}
TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
host_impl.CreatePendingTree();
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
scoped_ptr<LayerImpl> scroll_parent_border =
LayerImpl::Create(host_impl.active_tree(), 2);
scoped_ptr<LayerImpl> scroll_parent_clip =
LayerImpl::Create(host_impl.active_tree(), 3);
scoped_ptr<LayerImpl> scroll_parent =
LayerImpl::Create(host_impl.active_tree(), 4);
scoped_ptr<LayerImpl> scroll_child =
LayerImpl::Create(host_impl.active_tree(), 5);
scoped_ptr<LayerImpl> bottom_content =
LayerImpl::Create(host_impl.active_tree(), 6);
scoped_ptr<LayerImpl> top_content =
LayerImpl::Create(host_impl.active_tree(), 7);
scroll_parent_clip->SetMasksToBounds(true);
scroll_child->SetScrollParent(scroll_parent.get());
scoped_ptr<std::set<LayerImpl*> > scroll_children(new std::set<LayerImpl*>);
scroll_children->insert(scroll_child.get());
scroll_parent->SetScrollChildren(scroll_children.release());
scroll_child->SetDrawsContent(true);
scroll_parent->SetDrawsContent(true);
top_content->SetDrawsContent(true);
bottom_content->SetDrawsContent(true);
gfx::Transform identity_transform;
gfx::Transform top_transform;
top_transform.Translate3d(0.0, 0.0, 5.0);
gfx::Transform bottom_transform;
bottom_transform.Translate3d(0.0, 0.0, 3.0);
SetLayerPropertiesForTesting(root.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(scroll_parent_border.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
SetLayerPropertiesForTesting(scroll_parent_clip.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
true,
false);
SetLayerPropertiesForTesting(scroll_parent.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(scroll_child.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(top_content.get(),
top_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
false,
true);
SetLayerPropertiesForTesting(bottom_content.get(),
bottom_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
false,
true);
scroll_child->SetShouldFlattenTransform(false);
scroll_child->SetIs3dSorted(true);
scroll_child->AddChild(top_content.Pass());
scroll_child->AddChild(bottom_content.Pass());
root->AddChild(scroll_child.Pass());
scroll_parent_clip->AddChild(scroll_parent.Pass());
scroll_parent_border->AddChild(scroll_parent_clip.Pass());
root->AddChild(scroll_parent_border.Pass());
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_TRUE(root->render_surface());
EXPECT_EQ(4u, root->render_surface()->layer_list().size());
EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id());
EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id());
EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id());
EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
}
TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
host_impl.CreatePendingTree();
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
scoped_ptr<LayerImpl> container =
LayerImpl::Create(host_impl.active_tree(), 2);
LayerImpl* container_layer = container.get();
scoped_ptr<LayerImpl> scroller =
LayerImpl::Create(host_impl.active_tree(), 3);
LayerImpl* scroll_layer = scroller.get();
scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
LayerImpl* fixed_layer = fixed.get();
container->SetIsContainerForFixedPositionLayers(true);
LayerPositionConstraint constraint;
constraint.set_is_fixed_position(true);
fixed->SetPositionConstraint(constraint);
scroller->SetScrollClipLayer(container->id());
gfx::Transform identity_transform;
gfx::Transform container_transform;
container_transform.Translate3d(10.0, 20.0, 0.0);
gfx::Vector2dF container_offset = container_transform.To2dTranslation();
SetLayerPropertiesForTesting(root.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
SetLayerPropertiesForTesting(container.get(),
container_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(40, 40),
true,
false);
SetLayerPropertiesForTesting(scroller.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(30, 30),
true,
false);
SetLayerPropertiesForTesting(fixed.get(),
identity_transform,
gfx::PointF(),
gfx::PointF(),
gfx::Size(50, 50),
true,
false);
scroller->AddChild(fixed.Pass());
container->AddChild(scroller.Pass());
root->AddChild(container.Pass());
{
gfx::Vector2dF scroll_delta(3.0, 5.0);
scroll_layer->SetScrollDelta(scroll_delta);
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_TRANSFORMATION_MATRIX_EQ(
container_layer->draw_properties().screen_space_transform,
fixed_layer->draw_properties().screen_space_transform);
EXPECT_VECTOR_EQ(
fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
container_offset);
EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
.screen_space_transform.To2dTranslation(),
container_offset - scroll_delta);
}
{
gfx::Vector2dF scroll_delta(4.1f, 8.1f);
scroll_layer->SetScrollDelta(scroll_delta);
gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_TRANSFORMATION_MATRIX_EQ(
container_layer->draw_properties().screen_space_transform,
fixed_layer->draw_properties().screen_space_transform);
EXPECT_VECTOR_EQ(
fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
container_offset);
EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
.screen_space_transform.To2dTranslation(),
container_offset - rounded_scroll_delta);
}
{
gfx::Transform scaled_container_transform = container_transform;
scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
container_layer->SetTransform(scaled_container_transform);
gfx::Vector2dF scroll_delta(4.5f, 8.5f);
scroll_layer->SetScrollDelta(scroll_delta);
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_TRANSFORMATION_MATRIX_EQ(
container_layer->draw_properties().screen_space_transform,
fixed_layer->draw_properties().screen_space_transform);
EXPECT_VECTOR_EQ(
fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
container_offset);
container_layer->SetTransform(container_transform);
}
{
gfx::Transform scale_transform;
scale_transform.Scale3d(3.0, 3.0, 1.0);
scroll_layer->SetTransform(scale_transform);
gfx::Vector2dF scroll_delta(4.5f, 8.5f);
scroll_layer->SetScrollDelta(scroll_delta);
LayerImplList render_surface_layer_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root.get(), root->bounds(), &render_surface_layer_list);
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
EXPECT_VECTOR_EQ(
fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
container_offset);
scroll_layer->SetTransform(identity_transform);
}
}
}
}