This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "cc/trees/layer_sorter.h"
#include "cc/base/math_util.h"
#include "cc/layers/layer_impl.h"
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/trees/single_thread_proxy.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/transform.h"
namespace cc {
namespace {
TEST(LayerSorterTest, BasicOverlap) {
LayerSorter::ABCompareResult overlap_result;
const float z_threshold = 0.1f;
float weight = 0.f;
gfx::Transform neg4_translate;
neg4_translate.Translate3d(0.0, 0.0, -4.0);
LayerShape front(2.f, 2.f, neg4_translate);
gfx::Transform neg5_translate;
neg5_translate.Translate3d(0.0, 0.0, -5.0);
LayerShape back(2.f, 2.f, neg5_translate);
overlap_result =
LayerSorter::CheckOverlap(&front, &back, z_threshold, &weight);
EXPECT_EQ(LayerSorter::BBeforeA, overlap_result);
EXPECT_EQ(1.f, weight);
overlap_result =
LayerSorter::CheckOverlap(&back, &front, z_threshold, &weight);
EXPECT_EQ(LayerSorter::ABeforeB, overlap_result);
EXPECT_EQ(1.f, weight);
gfx::Transform right_translate;
right_translate.Translate3d(10.0, 0.0, -5.0);
LayerShape back_right(2.f, 2.f, right_translate);
overlap_result =
LayerSorter::CheckOverlap(&front, &back_right, z_threshold, &weight);
EXPECT_EQ(LayerSorter::None, overlap_result);
overlap_result =
LayerSorter::CheckOverlap(&front, &front, z_threshold, &weight);
EXPECT_EQ(0.f, weight);
}
TEST(LayerSorterTest, RightAngleOverlap) {
LayerSorter::ABCompareResult overlap_result;
const float z_threshold = 0.1f;
float weight = 0.f;
gfx::Transform perspective_matrix;
perspective_matrix.ApplyPerspectiveDepth(1000.0);
gfx::Transform left_face_matrix;
left_face_matrix.Translate3d(-1.0, 0.0, -5.0);
left_face_matrix.RotateAboutYAxis(-90.0);
left_face_matrix.Translate(-1.0, -1.0);
LayerShape left_face(2.f, 2.f, perspective_matrix * left_face_matrix);
gfx::Transform front_face_matrix;
front_face_matrix.Translate3d(0.0, 0.0, -4.0);
front_face_matrix.Translate(-1.0, -1.0);
LayerShape front_face(2.f, 2.f, perspective_matrix * front_face_matrix);
overlap_result =
LayerSorter::CheckOverlap(&front_face, &left_face, z_threshold, &weight);
EXPECT_EQ(LayerSorter::BBeforeA, overlap_result);
}
TEST(LayerSorterTest, IntersectingLayerOverlap) {
LayerSorter::ABCompareResult overlap_result;
const float z_threshold = 0.1f;
float weight = 0.f;
gfx::Transform perspective_matrix;
perspective_matrix.ApplyPerspectiveDepth(1000.0);
gfx::Transform front_face_matrix;
front_face_matrix.Translate3d(0.0, 0.0, -4.0);
front_face_matrix.Translate(-1.0, -1.0);
LayerShape front_face(2.f, 2.f, perspective_matrix * front_face_matrix);
gfx::Transform through_matrix;
through_matrix.Translate3d(0.0, 0.0, -4.0);
through_matrix.RotateAboutYAxis(45.0);
through_matrix.Translate(-1.0, -1.0);
LayerShape rotated_face(2.f, 2.f, perspective_matrix * through_matrix);
overlap_result = LayerSorter::CheckOverlap(&front_face,
&rotated_face,
z_threshold,
&weight);
EXPECT_NE(LayerSorter::None, overlap_result);
EXPECT_EQ(0.f, weight);
}
TEST(LayerSorterTest, LayersAtAngleOverlap) {
LayerSorter::ABCompareResult overlap_result;
const float z_threshold = 0.1f;
float weight = 0.f;
gfx::Transform transform_a;
transform_a.Translate3d(-6.0, 0.0, 1.0);
transform_a.Translate(-4.0, -10.0);
LayerShape layer_a(8.f, 20.f, transform_a);
gfx::Transform transform_b;
transform_b.Translate3d(6.0, 0.0, -1.0);
transform_b.Translate(-4.0, -10.0);
LayerShape layer_b(8.f, 20.f, transform_b);
gfx::Transform transform_c;
transform_c.RotateAboutYAxis(40.0);
transform_c.Translate(-4.0, -10.0);
LayerShape layer_c(8.f, 20.f, transform_c);
overlap_result =
LayerSorter::CheckOverlap(&layer_a, &layer_c, z_threshold, &weight);
EXPECT_EQ(LayerSorter::ABeforeB, overlap_result);
overlap_result =
LayerSorter::CheckOverlap(&layer_c, &layer_b, z_threshold, &weight);
EXPECT_EQ(LayerSorter::ABeforeB, overlap_result);
overlap_result =
LayerSorter::CheckOverlap(&layer_a, &layer_b, z_threshold, &weight);
EXPECT_EQ(LayerSorter::None, overlap_result);
}
TEST(LayerSorterTest, LayersUnderPathologicalPerspectiveTransform) {
LayerSorter::ABCompareResult overlap_result;
const float z_threshold = 0.1f;
float weight = 0.f;
gfx::Transform perspective_matrix;
perspective_matrix.ApplyPerspectiveDepth(1);
gfx::Transform transform_a;
transform_a.Translate3d(-15.0, 0.0, -2.0);
transform_a.Translate(-5.0, -5.0);
LayerShape layer_a(10.f, 10.f, perspective_matrix * transform_a);
gfx::Transform transform_b;
transform_b.Translate3d(0.f, 0.f, 0.7f);
transform_b.RotateAboutYAxis(45.0);
transform_b.Translate(-5.0, -5.0);
LayerShape layer_b(10.f, 10.f, perspective_matrix * transform_b);
gfx::QuadF test_quad = gfx::QuadF(gfx::RectF(-0.5f, -0.5f, 1.f, 1.f));
bool clipped = false;
MathUtil::MapQuad(perspective_matrix * transform_b, test_quad, &clipped);
ASSERT_TRUE(clipped);
overlap_result =
LayerSorter::CheckOverlap(&layer_a, &layer_b, z_threshold, &weight);
EXPECT_EQ(LayerSorter::ABeforeB, overlap_result);
}
TEST(LayerSorterTest, VerifyExistingOrderingPreservedWhenNoZDiff) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1);
scoped_ptr<LayerImpl> layer2 = LayerImpl::Create(host_impl.active_tree(), 2);
scoped_ptr<LayerImpl> layer3 = LayerImpl::Create(host_impl.active_tree(), 3);
scoped_ptr<LayerImpl> layer4 = LayerImpl::Create(host_impl.active_tree(), 4);
scoped_ptr<LayerImpl> layer5 = LayerImpl::Create(host_impl.active_tree(), 5);
gfx::Transform BehindMatrix;
BehindMatrix.Translate3d(0.0, 0.0, 2.0);
gfx::Transform FrontMatrix;
FrontMatrix.Translate3d(0.0, 0.0, 1.0);
layer1->SetBounds(gfx::Size(10, 10));
layer1->SetContentBounds(gfx::Size(10, 10));
layer1->draw_properties().target_space_transform = BehindMatrix;
layer1->SetDrawsContent(true);
layer2->SetBounds(gfx::Size(20, 20));
layer2->SetContentBounds(gfx::Size(20, 20));
layer2->draw_properties().target_space_transform = BehindMatrix;
layer2->SetDrawsContent(true);
layer3->SetBounds(gfx::Size(30, 30));
layer3->SetContentBounds(gfx::Size(30, 30));
layer3->draw_properties().target_space_transform = FrontMatrix;
layer3->SetDrawsContent(true);
layer4->SetBounds(gfx::Size(40, 40));
layer4->SetContentBounds(gfx::Size(40, 40));
layer4->draw_properties().target_space_transform = FrontMatrix;
layer4->SetDrawsContent(true);
layer5->SetBounds(gfx::Size(50, 50));
layer5->SetContentBounds(gfx::Size(50, 50));
layer5->draw_properties().target_space_transform = BehindMatrix;
layer5->SetDrawsContent(true);
LayerImplList layer_list;
layer_list.push_back(layer1.get());
layer_list.push_back(layer2.get());
layer_list.push_back(layer3.get());
layer_list.push_back(layer4.get());
layer_list.push_back(layer5.get());
ASSERT_EQ(5u, layer_list.size());
EXPECT_EQ(1, layer_list[0]->id());
EXPECT_EQ(2, layer_list[1]->id());
EXPECT_EQ(3, layer_list[2]->id());
EXPECT_EQ(4, layer_list[3]->id());
EXPECT_EQ(5, layer_list[4]->id());
LayerSorter layer_sorter;
layer_sorter.Sort(layer_list.begin(), layer_list.end());
ASSERT_EQ(5u, layer_list.size());
EXPECT_EQ(3, layer_list[0]->id());
EXPECT_EQ(4, layer_list[1]->id());
EXPECT_EQ(1, layer_list[2]->id());
EXPECT_EQ(2, layer_list[3]->id());
EXPECT_EQ(5, layer_list[4]->id());
}
TEST(LayerSorterTest, VerifyConcidentLayerPrecisionLossResultsInDocumentOrder) {
FakeImplProxy proxy;
TestSharedBitmapManager shared_bitmap_manager;
FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1);
scoped_ptr<LayerImpl> layer2 = LayerImpl::Create(host_impl.active_tree(), 2);
gfx::Transform BehindMatrix;
BehindMatrix.Translate3d(0.f, 0.f, 0.999999f);
BehindMatrix.RotateAboutXAxis(38.5);
BehindMatrix.RotateAboutYAxis(77.0);
gfx::Transform FrontMatrix;
FrontMatrix.Translate3d(0, 0, 1.0);
FrontMatrix.RotateAboutXAxis(38.5);
FrontMatrix.RotateAboutYAxis(77.0);
layer1->SetBounds(gfx::Size(10, 10));
layer1->SetContentBounds(gfx::Size(10, 10));
layer1->draw_properties().target_space_transform = BehindMatrix;
layer1->SetDrawsContent(true);
layer2->SetBounds(gfx::Size(10, 10));
layer2->SetContentBounds(gfx::Size(10, 10));
layer2->draw_properties().target_space_transform = FrontMatrix;
layer2->SetDrawsContent(true);
LayerImplList layer_list;
layer_list.push_back(layer1.get());
layer_list.push_back(layer2.get());
ASSERT_EQ(2u, layer_list.size());
EXPECT_EQ(1, layer_list[0]->id());
EXPECT_EQ(2, layer_list[1]->id());
LayerSorter layer_sorter;
layer_sorter.Sort(layer_list.begin(), layer_list.end());
ASSERT_EQ(2u, layer_list.size());
EXPECT_EQ(1, layer_list[0]->id());
EXPECT_EQ(2, layer_list[1]->id());
}
}
}